Page 1 of 1

Webkit / Render to texture

Posted: Fri Nov 24, 2017 12:24 pm
by nev9n
I'm working on getting QtWebkit working with the development branch of Torque3D. The webkit code works by drawing to a texture that can then be rendered on an object in game. I'm currently having problems getting the render to texture working.

This is the code that is creating the textures:

Code: Select all

       mTextureObjectA.set(mTexSize, mTexSize, GFXFormatR8G8B8X8, &GFXDynamicTextureProfile, avar("%s() -  (line %d)", __FUNCTION__, __LINE__), 0); // was GFXDefaultStaticDiffuseProfile
         mTextureObjectB.set(mTexSize, mTexSize, GFXFormatR8G8B8X8, &GFXDynamicTextureProfile, avar("%s() -  (line %d)", __FUNCTION__, __LINE__), 0); // was GFXDefaultStaticDiffuseProfile


The previous working webkit code used 'GFXDefaultStaticDiffuseProfile', which has been renamed in development to'GFXStaticTextureProfile'. However when I try to use that I get a crash when the code tries to lock the texture. Locking the texture calls ID3D11DeviceContext::Map, which throws this error:

Code: Select all

D3D11 ERROR: ID3D11DeviceContext::Map: Map cannot be called with MAP_WRITE_DISCARD access, because the Resource was not created with the D3D11_CPU_ACCESS_WRITE flag. [ RESOURCE_MANIPULATION ERROR #2097210: RESOURCE_MAP_INVALIDMAPTYPE] 
D:\Torque\Torque3D\Engine\source\gfx\D3D11\gfxD3D11TextureObject.cpp(114,0): {Fatal} - GFXD3D11TextureObject::lock - Failed to map subresource. 


Having had a look through the D3D11 documentation I think I need the texture to be dynamic since webkit will be updating it. Hence why I've updated the texture profile to GFXDynamicTextureProfile.

In GFXD3D11TextureManager::_innerCreateTexture() I'm now getting these errors when the texture is created:
E_INVALIDARG One or more arguments are invalid
D3D11 ERROR: ID3D11Device::CreateTexture2D: A D3D11_USAGE_DYNAMIC Resource must have MipLevels equal to 1. [ STATE_CREATION ERROR #102: CREATETEXTURE2D_INVALIDMIPLEVELS]
D3D11 ERROR: ID3D11Device::CreateTexture2D: A D3D11_USAGE_DYNAMIC Resource cannot be bound to certain parts of the graphics pipeline, but must have at least one BindFlags bit set. The following BindFlags bits (0x28) cannot be set in this case: D3D11_BIND_STREAM_OUTPUT (0), D3D11_BIND_RENDER_TARGET (1), D3D11_BIND_DEPTH_STENCIL (0), D3D11_BIND_UNORDERED_ACCESS (0). [ STATE_CREATION ERROR #99: CREATETEXTURE2D_INVALIDBINDFLAGS]


This is the D3D11_TEXTURE3D_DESC that has been created:
Image

Re: Webkit / Render to texture

Posted: Fri Nov 24, 2017 4:02 pm
by nev9n
OK I have render to texture drawing to the texture now, but the draw updates aren't being made to the right part of the texture. You can see here how it's loaded the google homepage and redrawn a rectangle in the top left...

Image

I fixed the previous render to texture issue by using the following texture profile:

Code: Select all

GFX_ImplementTextureProfile(GFXWebTextureProfile,
   GFXTextureProfile::DiffuseMap,
   GFXTextureProfile::NoMipmap | GFXTextureProfile::Dynamic,
   GFXTextureProfile::NONE);

Re: Webkit / Render to texture

Posted: Mon Dec 04, 2017 2:20 pm
by nev9n
The problem with updating the wrong part of the texture is related to the code that is handling dirty rectangle updating between webkit and the texture.

Since this code hasn't changed since the original release of webkit for Torque3D I'm not sure why it's broken.

We are mainly using webkit for showing video, so I've just bypassed the dirty rectangle code and am redrawing the whole texture each frame.

Re: Webkit / Render to texture

Posted: Thu Dec 07, 2017 5:59 pm
by chriscalef
Cool, glad you're working on this! I was an awesomium user back in the day, would still love to have a solid T3D browser to texture solution. Great work!