ok
My project is experemental. Basic project is RenderToTexture from Urho3d samples.
Java code:
native void setTexture();
@Override
public void onClick(View view) {
setTexture();
}
C++ code:
class EngineGateway {
protected:
Urho3D::Application* application;
public:
Urho3D::Application *getApplication() const;
void setApplication(Urho3D::Application *application);
};
/////////////////////////////////////
EngineGateway *engineGateway;
/////////////////////////////////////
extern "C"{
JNIEXPORT void JNICALL
Java_com_mydomen_test2_BasicFragment_setTexture(JNIEnv *env, jobject instance) {
RenderToTexture *app = dynamic_cast<RenderToTexture*>(engineGateway->getApplication());
app->setTexture();
}
}
/////////////////////////////////////
void RenderToTexture::CreateScene() {
...
StaticModel *boxObject = screenNode->CreateComponent<StaticModel>();
boxObject->SetModel(cache->GetResource<Model>("Models/Plane.mdl"));
SharedPtr<Material> renderMaterial(new Material(context_));
renderMaterial->SetTechnique(0, cache->GetResource<Technique>("Techniques/Diff.xml"));
renderTexture = SharedPtr<Texture2D>(new Texture2D(context_));
renderTexture->SetNumLevels(1);
renderTexture->SetSize(1024, 768, Graphics::GetRGBFormat(), TEXTURE_DYNAMIC);
int textureWidth = renderTexture->GetWidth();
int textureHeight = renderTexture->GetHeight();
SharedPtr<Image> texImg = SharedPtr<Image>(new Image(context_));
texImg->SetSize(textureWidth, textureHeight, 3);
for (int i = 0; i < width; ++i) {
for (int j = 0; j < height; ++j) {
texImg->SetPixel(i, j, Color(0, 0, 1));
}
}
renderTexture->SetData(texImg);
renderMaterial->SetTexture(TU_DIFFUSE, renderTexture);
boxObject->SetMaterial(renderMaterial); // It works, so it is colled in engine main thread
...
}
void RenderToTexture::setImage() {
const int width = renderTexture->GetWidth();
const int height = renderTexture->GetHeight();
Image* texImg = new Image(context_);
texImg->SetSize(width, height, 3);
for (int i = 0; i < width; ++i) {
for (int j = 0; j < height; ++j) {
texImg->SetPixel(i, j, Color(1, 1, 1));
}
}
renderTexture->SetData(texImg); // It dosn't work, so it is colled in Android MainUI thread
}