Jump to content

Awesomium in C#


Raz
 Share

Recommended Posts

Hey there!

A member of our team just informed me that someone had a chat with him about using Awesomium in combination with Leadwerks and C#. He mentioned he was going to release the code some time this week. Unfortunately, it seems that he couldn't remember who it was. So if you're the one who sent us the message, it'd be awesome if you could quickly send us a PM or post in here, cause I'd really like to get in touch with you.

 

Best Regards,

Philipp

Link to comment
Share on other sites

hi,

 

it was me who was contacting you. I'm currently working on some Extensions to the LE.Net Wrapper including a class which handle Awesomium. Some details can be found in my blog here:

 

http://www.leadwerks.com/werkspace/blog/16/entry-672-extending-lenet/

 

And here is a newer screenshot which shows a small test app with interactive Awesomium on a cube. (Mouse and Keyboard input is working)

 

post-4-0-03983500-1308834940_thumb.png

 

Feel free to contact me via MSN/ICQ or Mail.

  • Windows 10 Pro 64-Bit-Version
  • NVIDIA Geforce 1080 TI
Link to comment
Share on other sites

Very, very nice :huh: I'll be sure to come back to you about it! Switching from DirectX to OpenGL, I was stunned at how horribly different things are handled in OpenGL. In DirectX it was a matter of minutes to figure out how to use Awesomium with the (now obviously deprecated) MDX wrapper, but OpenGL and things like TAO, OpenTK... damn xD

 

Greets,

Philipp

Link to comment
Share on other sites

To be honest, i have the same problem with directx :huh:

 

It just was a matter of 2 minutes to get awesomium working with LE. Of course you need some knowledge about handling Leadwerks textures with raw opengl, but than it is really simple.

 

  public void Render()
       {
           if (m_webView.IsDirty() && !m_loading)
           {
               Rect r = m_webView.GetDirtyBounds();
               RenderBuffer buffer = m_webView.Render();
               UploadToTexture(buffer,r);
           }
       }

       private void UploadToTexture(RenderBuffer buffer, Rect rect)
       {
           LE.BindTexture(m_rendertarget);

           int size =buffer.GetRowspan() /  LE.TextureWidth(m_rendertarget);
           int ptr = (int)buffer.GetBuffer() + (rect.x) * size + (rect.y) * buffer.GetRowspan();

           Gl.glTexSubImage2D(Gl.GL_TEXTURE_2D, 0, rect.x, rect.y,rect.width ,rect.height,
               Gl.GL_BGRA, Gl.GL_UNSIGNED_BYTE, (IntPtr)ptr);
       }

 

As you see there is no real magic behind it ;)

  • Windows 10 Pro 64-Bit-Version
  • NVIDIA Geforce 1080 TI
Link to comment
Share on other sites

No really, its pretty much the same operation in DirectX :huh:

I assume you're using TAO to handle the raw OpenGL commands, right?

 

[EDIT]

Yea, apparently its TAO. Unfortunately the whole program crashes with no error (just says "has stopped working"). I haven't changed much in the UploadToTexture function, but I wasn't sure where you got your m_rendertarget from, so I just used 0 for texunit 0.

 

private void UploadToTexture(RenderBuffer buffer, AwesomiumSharp.Rect rect)
       {
           webTexture.Bind(0);

           int size = buffer.GetRowspan() / webTexture.Width;
           int ptr = (int)buffer.GetBuffer() + (rect.x) * size + (rect.y) * buffer.GetRowspan();

           Gl.glTexSubImage2D(Gl.GL_TEXTURE_2D, 0, rect.x, rect.y, rect.width, rect.height,
               Gl.GL_BGRA, Gl.GL_UNSIGNED_BYTE, (IntPtr)ptr);
       }

 

[EDIT 2]

 

Narrowed it down to two issues I suppose will be fixed when understanding what exactly Texture.Bind() does. When first calling UploadToTexture, everything's working just fine. Upon calling it a second time, it makes the program crash. I suppose it has to do with the way you write data to the texture. I think I'm supposed to somehow "revert" webTexture.BInd() after the call to glTexSubImage2D(), but I'm not sure on how to do that...

 

Greets,

Philipp

Link to comment
Share on other sites

the webTexture needs to be the same size as the WebView and this part:

 

if (m_webView.IsDirty() && !m_loading)
           {
               Rect r = m_webView.GetDirtyBounds();
               RenderBuffer buffer = m_webView.Render();
               UploadToTexture(buffer,r);
           }

 

is important, otherwise the rect maybe undefined if the view isn't dirty, alternatively you can leave the rect out of the code and upload the whole renderbuffer to the texture.

 

  Gl.glTexSubImage2D(Gl.GL_TEXTURE_2D, 0, 0, 0, webTexture.Width, webTexture.Height,
               Gl.GL_BGRA, Gl.GL_UNSIGNED_BYTE, Buffer.GetBuffer());

  • Windows 10 Pro 64-Bit-Version
  • NVIDIA Geforce 1080 TI
Link to comment
Share on other sites

Hm, okay, now I'm a bit stuck with handling input.. I'm currently trying to hack around Leadwerk's system by using a low-level hook with "SetWindowsHookEx()", but that doesn't yield too good results..

Would you mind posting the code you used to receive input and reroute it to Awesomium?

 

Greets,

Philipp

Link to comment
Share on other sites

Hm, okay, so basically you're doing the same thing I originally intended to do to handle input events - that is, polling each key each Update().

Idk if that's such a good idea performance-wise. I read up a lot on the message loop of windows and thought that might've been a better solution, but if you think there's no huge trade-off in performance, that's fine.

Link to comment
Share on other sites

  • 4 weeks later...

this is a shader bug i postet a short time before in the bugtracker.

 

Open the shader.pak and edit the 'Mesh/mesh_diffuse_fullbright.frag' and remove the line which defines texture 2 so that the file looks like this:

#define LW_DIFFUSE texture0
#define LW_FULLBRIGHT

include "mesh.frag"

 

Also you need to copy the dlls and AwesomiumProcess.exe from Awsomium SDK into your output folder.

Once the official .NET part is finished i will release a full Package with working Samples.

  • Windows 10 Pro 64-Bit-Version
  • NVIDIA Geforce 1080 TI
Link to comment
Share on other sites

this is a shader bug i postet a short time before in the bugtracker.

 

Open the shader.pak and edit the 'Mesh/mesh_diffuse_fullbright.frag' and remove the line which defines texture 2 so that the file looks like this:

#define LW_DIFFUSE texture0
#define LW_FULLBRIGHT

include "mesh.frag"

 

Also you need to copy the dlls and AwesomiumProcess.exe from Awsomium SDK into your output folder.

Once the official .NET part is finished i will release a full Package with working Samples.

 

Thanks for this hint but now my cube is black <_<

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...