Horde3D

Next-Generation Graphics Engine
It is currently 29.03.2024, 11:24

All times are UTC + 1 hour




Post new topic Reply to topic  [ 6 posts ] 
Author Message
PostPosted: 21.12.2011, 01:49 
Offline

Joined: 21.12.2011, 01:10
Posts: 15
I want to make this happen with Horde3D. In essence it boils down to writing data to a texture while it is assigned to a model. But how? Awesomium includes examples that work like this:
Code:
      const Awesomium::RenderBuffer* buffer =
      myobject->webView->render();
      
      memcpy(myobject->buffer, buffer->buffer, myobject->width * myobject->height * 4);
      
      glBindTexture(GL_TEXTURE_2D, myobject->textureID);
      glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, myobject->width, myobject->height,
                  myobject->bpp == 3 ? GL_RGB : GL_BGRA, GL_UNSIGNED_BYTE,
                  myobject->buffer);
Pretty straightforward in OpenGL. But how would I do this operation with Horde3D? I am stuck implementing this because of a lack of reading material. ;) Here are my ideas, but I have no idea if they go in the right direction at all:
    A) Create a h3dUpdateResource() that does: h3dUnloadResource(); create a new h3dRes from a buffer; h3dLoadResource() with the same name. Isn't this slow?
    B) Use the h3dMapResStream() stuff? I couldn't find any examples for this.
    C) It doesn't work like that at all because.

Any guidance is appreciated.

Semi-unrelated extra question: In an older thread I read that it is slow to switch between normal OpenGL and Horde3D to draw a GUI on top of Horde3D. Does that still apply, or has that changed with h3dutReleaseOpenGL() (and does this still only work with Windows?)?


Top
 Profile  
Reply with quote  
PostPosted: 21.12.2011, 10:38 
Offline
Tool Developer

Joined: 13.11.2007, 11:07
Posts: 1150
Location: Germany
Based on this and this wiki entry the following simple code example shows how to change the knight's albedo map to a red texture:

Code:
   
   H3DRes texRes = h3dCreateTexture( "myTexRes", 64, 64, H3DFormats::TEX_RGBA16F, H3DResFlags::NoTexMipmaps );
   float *data = static_cast<float*>( h3dMapResStream( texRes, H3DTexRes::ImageElem, 0, H3DTexRes::ImgPixelStream, false, true ) );
   for( int row=0; row<64; ++row )
   {
      float *rowPtr = data + row*64*4;
      for( int col=0; col<64; ++col )
      {
         float *sample = rowPtr + col*4;
         sample[0] = 1.0f; // R
         sample[1] = 0.0f; // G
         sample[2] = 0.0f; // B
         sample[3] = 1.0f; // A
      }
   }
   h3dUnmapResStream( texRes );   
   H3DNode knightMatRes = h3dFindResource( H3DResTypes::Material, "models/knight/knight.material.xml" );
   h3dSetResParamI( knightMatRes, H3DMatRes::SamplerElem, 0, H3DMatRes::SampTexResI, texRes );


Shouldn't be to difficult to adjust it to your needs. Take note, that updating a res stream does not allow you to change the texture's parameters. So if you want to upload a new texture with different size or type you have to unload the previous texture resource first.

There's also a flash integration to Horde made by jimbo available here


Top
 Profile  
Reply with quote  
PostPosted: 21.12.2011, 12:47 
Offline

Joined: 21.12.2011, 01:10
Posts: 15
I love you. Thanks!


Top
 Profile  
Reply with quote  
PostPosted: 03.01.2012, 02:23 
Offline

Joined: 21.12.2011, 01:10
Posts: 15
The basics work fine with Horde3D thanks to your help, but I hit a snag on this. I want to dynamically resize the texture I use for Awesomium.

Here is how I think it should work, but doesn't:
Code:
    H3DRes _awsmTextureRes = -1;
    int w = 512;
    int h = 512;

    // Allocate the texture for awesomium
    _awsmTextureRes = h3dCreateTexture("$GuiTexture",
                                    w,h,
                                    H3DFormats::TEX_BGRA8,
                                    H3DResFlags::NoTexMipmaps
                                    );
    // _awsmTextureRes==9 (works perfectly)

    // Deallocate the texture (This must be where I make a mistake)
    int references = h3dRemoveResource(_awsmTextureRes); // returns 0
    h3dUnloadResource(_awsmTextureRes);
    h3dReleaseUnusedResources();
    _awsmTextureRes=-1;

    // Allocate the texture again with half the size in this example (size doesn't matter here)
    _awsmTextureRes = h3dCreateTexture("$GuiTexture",
                                    w/2,h,
                                    H3DFormats::TEX_BGRA8,
                                    H3DResFlags::NoTexMipmaps
                                    );
    // _awsmTextureRes==0 Meaning failure. Why?


What is wrong?


Top
 Profile  
Reply with quote  
PostPosted: 05.01.2012, 11:11 
Offline
Tool Developer

Joined: 13.11.2007, 11:07
Posts: 1150
Location: Germany
I just pasted your code into the knight's app.cpp and it does work without problems. The new texture resource ID was equal to the previous one and not 0 ( because no other resource was added between the calls the ID is equal).
By the way, the call of h3dReleaseUnusedResource() does an unload of the resource anyway so a separate h3dUnloadResource call is not necessary.
The reason why h3dCreateTexture returns 0 probably is that another resource with the same name already exists (forgot to call h3dReleaseUnusedResources after removing the resource?). That error should be written into the log, so if you check the log messages, you may find the reason for the error.


Top
 Profile  
Reply with quote  
PostPosted: 06.01.2012, 00:39 
Offline

Joined: 21.12.2011, 01:10
Posts: 15
Thank you again. I generated my material ("$GuiMaterial") using the texture ("$GuiTexture") procedurally like this:

Code:
    _awsmMaterial = __hordeHandler.CreateMaterial("$GuiMaterial",
                                                  "<Material>"
                                                  "<Shader source=\"base/shaders/overlay.shader\"/>"
                                                  "<Sampler name=\"albedoMap\" map=\"$GuiTexture\" />"
                                                  "</Material>"
                                                  );


And apparently that reference to "$GuiTexture" is enough to make it impossible to remove "$GuiTexture". I didn't expect that. I fixed it now with that knowledge.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 51 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group