OGRE更新像素缓存

更新像素缓存

这里提供了两种不同的更新像素缓存的方法;其中一种很简单,另外一种稍微有一些难度,不过在某些场合会表现的高效率。不过不管是选择了哪一种方法,都需要借助PixelBox对象来帽徽缓存中的图像数据(可以参照像素盒)。

 

blitFromMemory

从像素缓存中得到图像的简单方法是通过调用HardwarePixelBuffer::blitFromMemory方法。这里获得一个PixelBox对象并帮助你进行所有必要的定点格式转换与缩放。例如,建立一个手动纹理并把一个图片放入里面,你将要采用以下代码:

// Manually loads an image and puts the contents in a manually created texture

Image img;

 img.load("elephant.png", "General");

// Create RGB texture with 5 mipmaps

 TexturePtr tex = TextureManager::getSingleton().createManual( "elephant", "General", TEX_TYPE_2D, img.getWidth(), img.getHeight(), 5, PF_X8R8G8B8);

 // Copy face 0 mipmap 0 of the image to face 0 mipmap 0 of the texture. 

tex->getBuffer(0,0)->blitFromMemory(img.getPixelBox(0,0));

直接对缓存加锁

另外一个高级的方法来从PixelBuffer(像素缓存)中得到图像数据的方法是对缓存加锁。通过对PixelBuffer加锁,你可以不管缓存的具体格式而直接的在GPU中存取其内容。

/// Lock the buffer so we can write to it 

buffer->lock(HardwareBuffer::HBL_DISCARD);

const PixelBox &pb = buffer->getCurrentLock();

/// Update the contents of pb here

/// Image data starts at pb.data and has format pb.format

/// Here we assume data.format is PF_X8R8G8B8 so we can address pixels as uint32.

uint32 *data = static_cast<uint32*>(pb.data);

size_t height = pb.getHeight();

size_t width = pb.getWidth();

size_t pitch = pb.rowPitch;

// Skip between rows of image

for(size_t y=0; y<height; ++y)

{for(size_t x=0; x<width; ++x)

{

// 0xRRGGBB -> fill the buffer with yellow pixels

data[pitch*y + x] = 0x00FFFF00;

}

}

/// Unlock the buffer again (frees it for use by the GPU)

buffer->unlock();

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值