Results 1 to 6 of 6

Thread: Render targets and pixels

  1. #1
    Legendary Member NecroDOME's Avatar
    Join Date
    Mar 2004
    Location
    The Netherlands, Eindhoven
    Posts
    1,059

    Render targets and pixels

    Hi there,

    I'm stuck again. I try to get a pixel (just one per frame) from a render target. How can I do that without much overhead.

    What I do now is (every frame):
    - Create new texture
    - Copy render target surface to that texture
    - Get pixel from copied textured
    - Destroy texture
    (Yes it works, but is slow as hell)

    A normal texture can just be locked and get some data out of out, but a render target is a different story...

    So is there a better way to just get one pixel? (I cannot render my scene to a 1x1 texture!!... well I can, but I don't want to end up looking at one big-ass pixel)

    ps. I'm using DirectX 9 and shaders.
    NecroSOFT - End of line -

  2. #2

    Re: Render targets and pixels

    Can't you use some sort of mip mapping feature to make the RT texture 1x1 pixel and then just copy that?

    Why is it that you can't lock the RT texture btw?
    Peregrinus, expectavi pedes meos in cymbalis
    Nullus norvegicorum sole urinat

  3. #3
    Legendary Member NecroDOME's Avatar
    Join Date
    Mar 2004
    Location
    The Netherlands, Eindhoven
    Posts
    1,059

    Re: Render targets and pixels

    Render targets are somehow "special". I also stumbled upon this one: http://www.gamedev.net/community/for...opic_id=351396
    Create a new render target. Render the rectangle you need to this new render target, and copy it to system memory.
    I can copy it to 1x1 texture, but I was wondering if there was a better approach.
    NecroSOFT - End of line -

  4. #4

    Re: Render targets and pixels

    You dont really need to copy your render target to a texture, just copy it to an offscreen surface and read a pixel from there, that might be just a bit faster.

    Another approach - you can create a lockable backbuffer, then draw a rectangle with your texture, lock the backbuffer and read your pixel.

    Why would you want to read a pixel of a render target anyway? Perhaps there is another high level approach?

  5. #5
    Legendary Member NecroDOME's Avatar
    Join Date
    Mar 2004
    Location
    The Netherlands, Eindhoven
    Posts
    1,059

    Re: Render targets and pixels

    Well, I use it for picking. And this way I don't have to cast a ray, don't have to iterate trough every triangle etc. etc., but I simply use an off screen render target for lookups. And I have it this way pixel-perfect!
    NecroSOFT - End of line -

  6. #6

    Re: Render targets and pixels

    Don't know about reading pixels, but here is old function i have in libs that can be used to pick a specified object from OpenGL screen. It is pixel perfect, doesn't make a ray and is as fast as your RenderProc which renders single triangle or a full object on screen. You can do this test after or during flipping main screen and draw unflipped and without any textures and lighting.

    Code:
    type
     TRenderProc = procedure(index: integer);
    ...
    // Returns render index if cursor points it
    // or -1 if no match
    function MousePick(mx, my, PickRadius: double;
     Count: integer; RenderProc: TRenderProc): integer;
    var SelBuffer: array[0..511] of TGLUint;
      i,hits: integer; viewport: TGLVectori4;
      d1: double;
    begin
     result:=-1;
     if count<1 then exit;
     glGetIntegerv(GL_VIEWPORT,@viewPort);
    
     glSelectBuffer(512, @SelBuffer);
     glRenderMode(GL_SELECT);
     glInitNames; glPushName(0);
     glMatrixMode(GL_PROJECTION);
     glPushMatrix; glLoadIdentity;
     gluPickMatrix(mx,my,PickRadius,PickRadius,viewport);
     gluPerspective(45, AspectRatio, TGL_NEARZ, TGL_FARZ);
     glMatrixMode(GL_MODELVIEW);
    
     for i:=0 to Count-1 do begin
      glLoadName(i);
      RenderProc(i);
     end;
    
     glMatrixMode(GL_PROJECTION);
     glPopMatrix;
     glMatrixMode(GL_MODELVIEW);
    
     hits:=glRenderMode(GL_RENDER);
     if hits>0 then begin
      d1:=selBuffer[1]; result:=selBuffer[3];
      for i:=1 to hits-1 do
       if selBuffer[i*4+1]<d1 then begin
        result:=selBuffer[i*4+3]; d1:=selBuffer[i*4+1];
       end;
     end;
    end;

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •