1.显示方式
static const GLubyte texdata1[] = {
0xFF,0x00,
0xFF,0x00
};
static const GLfloat tex_color_data[] = {
1.0f,0.0f,0.0f,1.0f,
1.0f,0.0f,0.0f,1.0f,
1.0f,0.0f,0.0f,1.0f,
1.0f,0.0f,0.0f,1.0f,};
glBindTexture(GL_TEXTURE_2D,texid0);
glTexStorage2D(0,GL_R8,2,2);
glTexSubImage2D(GL_TEXTURE_2D,
0,
0,0,
2,2,
GL_RED,GL_UNSIGNED_BYTE,texdata1
);
GL_RGBA32F
2.使用Pixel Unpack 缓存
glTexSubImage2D 中的参数的两种解释:
1.应用程序内存中存储数据的指针。
2.当做缓存对象的偏移。
glBindBuffer(GL_PIXEL_UNPACK_BUFFER,bufid);
glBufferData(GL_PIXEL_UNPACK_BUFFER,
sizeof(tex_color_data),tex_color_data,GL—STATIC_DRAW);
glBindTexture(GL_TEXTURE_2D,texid);
glTexStorage2D(GL_TEXTURE_2D,0,GL_R8,8,8);
glTexSubImage2D(GL_TEXTURE_2D,
0,
0,0,
2,2,
GL_RGBA,
GL_FLOAT,null);
优点:
没有立即将数据传送到纹理中,传输到纹理的过程是在GPU中进行的。