• Advertisement
Sign in to follow this  

IDirect3DTexture9 the same as IDirect3DSurface9?

This topic is 4705 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I found this code:
hr = D3DXCreateTexture(
          _device,
          texWidth, texHeight,  // dimensions
          0,                    // create a complete mipmap chain
          0,                    // usage - none
          D3DFMT_X8R8G8B8,      // 32-bit XRGB format
          D3DPOOL_MANAGED,      // memory pool
          &_tex);
D3DLOCKED_RECT lockedRect;
     _tex->LockRect(0/*lock top surface*/, &lockedRect,
           0 /* lock entire tex*/, 0/*flags*/);

     // fill the texture
     DWORD* imageData = (DWORD*)lockedRect.pBits;
     for(int i = 0; i < texHeight; i++)
     {
          for(int j = 0; j < texWidth; j++)
          {
          D3DXCOLOR c;

          // get height of upper-left vertex of quad.
          float height = (float)getHeightmapEntry(i, j)/_heightScale;

          // set the color of the texel based on the height
          // of the quad it corresponds to.
          if( (height) < 42.5f )       c = d3d::BEACH SAND;
          else if( (height) < 85.0f )  c = d3d::LIGHT YELLOW GREEN;
          else if( (height) < 127.5f ) c = d3d::PUREGREEN;
          else if( (height) < 170.0f ) c = d3d::DARK YELLOW GREEN;
          else if( (height) < 212.5f ) c = d3d::DARKBROWN;
          else                         c = d3d::WHITE;

          // fill locked data, note we divide the pitch by four
          // because the pitch is given in bytes and there are
          // 4 bytes per DWORD.
          imageData[i * lockedRect.Pitch / 4 + j] = (D3DCOLOR)c;
          }
     }

Share this post


Link to post
Share on other sites
Advertisement
No, they are not the same. It is observant of you to notice that they both share the same Lock/UnlockRect() functions, but they are not the same thing. Surfaces are generally used as getting specific parts of a texture map, usually individual mip-map levels or the faces of a cube map. So, you could think of IDirect3DSurface9 as being a sort-of more primitive part of what makes up an IDirect3DTexture9. Also, a notable feature of IDirect3DSurface9 is that you can get a HDC to it (if that matters to you at all).

Share this post


Link to post
Share on other sites
Garland is correct. Remember, textures are (generally) made up of multiple levels of detail, referred to as mip-maps. Each of these mip-maps is a surface. By definition, a surface is just a set of pixels, residing in vidoe or system memory.

So, just think of a texture as a collection of surfaces. Most people don't really recognize this, because Direct3D really handles all of the mipmap management for you, which is really nice.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement