【发布时间】:2015-05-20 12:07:49
【问题描述】:
我有一个大小为 3750x1407 的位图,它作为位图加载到内存中,填充为 2 个字节,因此它在内存中的长度为 (3752*1407) 字节。当使用 PixelUnpackBuffer 填充我的纹理时,我是否需要复制填充字节或者我可以跳过它们?
GL.BindTexture(TextureTarget.Texture2D, texId);
GL.BindBuffer(BufferTarget.PixelUnpackBuffer, pboId[currentIndex]);
GL.TexSubImage2D(TextureTarget.Texture2D, 0, 0, 0, bitmap.Width, bitmap.Height, PixelFormat.Luminance,
PixelType.UnsignedByte, IntPtr.Zero);
GL.BindBuffer(BufferTarget.PixelUnpackBuffer, pboId[nextIndex]);
BitmapData bitmapData = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height),
ImageLockMode.ReadOnly, bitmap.PixelFormat);
GL.ColorTable(ColorTableTarget.ColorTable, PixelInternalFormat.Luminance, _colorTable.Length, PixelFormat.Luminance, PixelType.Byte, new IntPtr(_colorTable[0]));
IntPtr buf = GL.MapBuffer(BufferTarget.PixelUnpackBuffer, BufferAccess.WriteOnly);
if (buf != IntPtr.Zero)
{
//---------------------------------------- Currently copying padding bytes--------------------------------------------- //
memcpy(buf, bitmapData.Scan0, new UIntPtr((uint)(bitmapData.Stride * bitmap.Height)));
GL.UnmapBuffer(BufferTarget.PixelUnpackBuffer);
}
bitmap.UnlockBits(bitmapData);
GL.BindBuffer(BufferTarget.PixelUnpackBuffer, 0);
【问题讨论】:
-
你的纹理格式是什么? RGBA,即每像素 4 个字节?
-
@RetoKoradi 不,它是每个像素一个字节。 8bpp 索引灰度。