Eric Tuvesson's picture

Awesomium

Okey, I have been trying all-day to draw Awesomium in OpenTK. But everytime it just lagg. I don't want lagg and stuff like that, duh! So I wonder if there is anyone who know how to draw it without lagg? I am not really sure how to draw it. but I thing you use buffers. Anyone help? just a exemple would be awsome! Going to make something like Overgrowth have. but inventory typeish. :)

Best Regards Eric.


Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Eric Tuvesson's picture

GL.DrawPixels(600, 800, OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte, webView.Render().GetBuffer());

But I cant get it right, it just say "Attempted to read or write protected memory. This is often an indication that other memory is corrupt.".

Inertia's picture

Hello Eric,

it is likely that you get the Exception because - at the point of time GL.DrawPixels executes - the GC has already cleaned up due to a missing reference. Do it like this:

IntPtr ptr = webView.Render().GetBuffer();
// exception may also be thrown because your image data is smaller than the hardcoded 800x600. This is better practice:
int w = webView.Render().GetWidth(); 
int h = webView.Render().GetHeight();
GL.DrawPixels(w, h, OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte, ptr); 
// the following line may not be required, since the pinned data is likely >80.000 Bytes and will not be moved by GC. But it could still be cleaned up before GL has processed it, so keep this as Plan B.
GL.Finish();

In the long run, you'll want to take a look at OpenGL's Texture objects: using GL.TexImage2D you can conveniently cache the page for rendering with OpenGL and only do update the texture object if the webview IsDirty.

Eric Tuvesson's picture

Long Way To Draw? Can't still draw it... Just nothing. but I can draw on the screen but not Awesom...

IntPtr ptr = webView.Render().GetBuffer();
                int w = webView.Render().GetWidth();
                int h = webView.Render().GetHeight();
 
                GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (float)OpenTK.Graphics.OpenGL.All.Clamp);
                GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (float)OpenTK.Graphics.OpenGL.All.Clamp);
                GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (float)OpenTK.Graphics.OpenGL.All.Linear);
                GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (float)OpenTK.Graphics.OpenGL.All.Linear);
                GL.TexEnv(TextureEnvTarget.TextureEnv, TextureEnvParameter.TextureEnvMode, (float)TextureEnvModeCombine.Replace);
 
                GL.RasterPos2(-1,-1);
 
                GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Alpha, w, h, 0, OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte, ptr);
 
                GL.DrawPixels(w, h, OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte, ptr);
                //GL.Finish();
Jase's picture

The way I'm doing it, is to generate a texture the same size as the WebView, and update it with GLTexSubImage2D every frame if the WebView.IsDirty() == true.

Call to update:
GL.TexSubImage2D(TextureTarget.Texture2D, 0,0,0, Width, Height, OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte,RenderBuffer.GetBuffer());

Then just render the texture as a full-screen quad. Using this method you will only take a hit for uploading a texture to OpenGL if the view changes (takes about 2ms on my GTX285)

There's a bug in Awesomium 1.6 where WebView.GetDirtyBounds() returns an empty rectangle, so for now I'm updating the entire texture whenever the WebView is dirty.

Don't ever call WebView.Render() more than once. Call it, keep the renderbuffer somewhere for use later on.

An example of Awesomium in my game, everything except FPS and Version number are coming from Awesomium : http://yfrog.com/z/h4lymrp

opcon's picture

I have awesomium rendering the way Jase described, but I was wondering, now that WebView.GetDirtyBounds() does return the bounding rectangle, how would go you about offsetting the buffer pointer to the start of those bounds?