DirectX and Awesomium

oneprotect's Avatar

oneprotect

22 Nov, 2010 08:30 AM via web

How would I get an Awesomium::RenderBuffer* drawn using DirectX most efficiently?

I don't think DirectX has something like glDrawPixels, so I'm kinda stuck on how.

Thanks for your help.

  1. Support Staff 2 Posted by Adam Simmons on 30 Nov, 2010 07:46 AM

    Adam Simmons's Avatar

    Hi oneprotect,

    The best way would be to use a dynamic texture wrapped to some screen-projected rectangle in Direct3D.

    For example, to update the contents of a texture (IDirect3DTexture) from a RenderBuffer instance:

    const RenderBuffer* rBuffer = webView->render();
    
    D3DLOCKED_RECT lockedRect;
    myTexture->LockRect(0, &locked, NULL, D3DLOCK_DISCARD);
    memcpy(locked.pBits, rBuffer->buffer, rBuffer->rowSpan * rBuffer->height);
    myTexture->UnlockRect(0);
    
  2. 3 Posted by Jonathan on 10 Jan, 2012 02:14 AM

    Jonathan's Avatar

    Thanks for replying. I got the texture to come up, but it comes out black.

    Here's the rendering code.

    const awe_renderbuffer *renderBuffer = awe_webview_render(webView);
    
    if (renderBuffer)
    {
        unsigned char *myBuffer;
        myBuffer = new unsigned char[512 * 512 * 4];
        awe_renderbuffer_copy_to(renderBuffer, myBuffer, 512 * 4, 4, true, false);
    
        D3DLOCKED_RECT lockedRect;
        texture->LockRect(0, &lockedRect, NULL, D3DLOCK_DISCARD);
        memcpy(lockedRect.pBits, myBuffer, sizeof(myBuffer));
        texture->UnlockRect(0); 
        delete myBuffer;
    }
    

    Just in case, here's my code that loads up the google url:

    // Create our URL string
    awe_string* url_str = awe_string_create_from_ascii(URL, strlen(URL));
    
    // Load a certain URL into our WebView instance
    awe_webview_load_url(webView, url_str, awe_string_empty(), awe_string_empty(), awe_string_empty());
    
    // Destroy our URL string
    awe_string_destroy(url_str);
    

    Thanks, Jonathan.

  3. 4 Posted by Jonathan on 10 Jan, 2012 02:56 AM

    Jonathan's Avatar

    LOL! Oops. I replied on the wrong discussion. But I guess this is a relevant question and if someone wants to answer that would be great. :)

  4. 5 Posted by Jonathan on 10 Jan, 2012 03:33 AM

    Jonathan's Avatar

    Got it!

    Pretty much I was loading the buffer size wrong

    //This is how I was doing it
    memcpy(lockedRect.pBits, myBuffer, sizeof(myBuffer));
    //But it's supposed to be width * height * rowspan
    memcpy(lockedRect.pBits, myBuffer, 512*512*4);
    

Reply to this discussion

Internal reply

Formatting help or Preview

Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.