direct acces to texture data

 

The DX texture you are creating may be wider than what you
requested.  This is usually a power of 2 and relates to the
way different video cards optimise things.
This is called the "pitch" (Cronus3D mentioned this.)
The pitch may be (probably will be) different for the all various
different graphics card chipsets.  The pitch can also differ on the
same graphics card when you change resolution.

You need to do a row, by row copy, adjusting the pointer to the
DirectX Texture at the end of each row.

+---------------------+---------------------+
|                                 |                                  |
| Raw data                 |     DXSurface            |
|                                 |                                 |
+--------------------+                                 |
|                                                                   |
+-------------------------------------------+

The pseudo code is as follows:
(Assumes you have 24bit R8G8B8 rawdata and
32bit A8R8G8B8 texture.)

Create new DX texture
Clean contents (zero) new DX texture
Create a D3DLOCKED_RECT structure
Call ->LockRect() on the texture
D3DLOCKED_RECT.Pitch now holds the width of the DX Surface
Store the pointer to DX Surface in a variable
BYTE *lpbDXSurfCurrent = (BYTE *)D3DLOCKED_RECT.pBits

Store a pointer to the start of the rawdata
BYTE *lpbRawDataCurrent = (BYTE *)start of rawdata

*lpbDXTexCurrent = 255;  // set first byte of DXSurface (alpha
channel 255 = fully solid)
lpbDXTexCurrent ++;  // move to second byte of DXSurface (first Red)

for (i=0 to height)
{
  for (j=0 to width of rawdata)
 {
    memcpy(lpbDXSurfCurrent, lpbRawDataCurrent, sizeof (BYTE) *3);
    // Copy the RGB from raw to RGB of DXSurface
    lpbDXSurfCurrent+=3;  // Move to A value of next destination pixel
    *lpbDXSurfCurrent = 255;  // set to solid alpha
    lpbDXSurfCurrent++;  // Move to R value of next destination pixel
    lpbRawDataCurrent+=3;   // Move to R value of next source pixel
  }
  lpbDXSurfCurrent += (D3DLOCKED_RECT.pitch - width of rawdata);
  // Move to start of next row of DXSurface

}

->Unlock() texture.
lpbDXSurfCurrent = NULL;
lpbRawDataCurrent = NULL;

I am assuming that the "raw RGB bits" are actually "raw."
If this was originally a BMP you probably have another
issue with the "raw data" actually being "padded" to a
32bit boundary.  BMP's have header fields which must
be skipped. BMP's are also "upside down" if the height
field is positive.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值