iOS:如何在GLES2中渲染到1通道纹理
经过数小时的抨击,我现在非常确定这是不可能做到的 这是我到目前为止(以下)渲染到纹理的代码;它确实起作用,但非常浪费。我只想要一个8位通道,可能是16位灰度。我不想要一个无用的R G和B频道 但如果我尝试在glTexImage2D中切换GL_RGBA/*GL_ALPHA*/时,glCheckFramebufferStatus会捕获“帧缓冲区未完成”错误:36054 0x8CD6 GL_FRAMEBUFFER_未完成\u附件 IRC上的人建议使用GL\u R,但Xcode不提供自动完成功能,所以看起来它可能是gle从GL中删去的功能之一 但这似乎真的很奇怪!这是一个移动设备。可以肯定的是,它将执行一个操作所需的比特量减少了四倍。。。毫无疑问,这将是最后一件要带走的东西 有人能彻底埋葬这个吗?是否可以在GLES2.0中渲染到单个通道纹理上iOS:如何在GLES2中渲染到1通道纹理,ios,alpha,opengl-es-2.0,render-to-texture,Ios,Alpha,Opengl Es 2.0,Render To Texture,经过数小时的抨击,我现在非常确定这是不可能做到的 这是我到目前为止(以下)渲染到纹理的代码;它确实起作用,但非常浪费。我只想要一个8位通道,可能是16位灰度。我不想要一个无用的R G和B频道 但如果我尝试在glTexImage2D中切换GL_RGBA/*GL_ALPHA*/时,glCheckFramebufferStatus会捕获“帧缓冲区未完成”错误:36054 0x8CD6 GL_FRAMEBUFFER_未完成\u附件 IRC上的人建议使用GL\u R,但Xcode不提供自动完成功能,所以看
+ (void) blurTexture: (GLuint) in_texId
POTWidth: (GLuint) in_W
POTHeight: (GLuint) in_H
returningTexId: (GLuint*) out_pTexId
{
// search HELP: 'Using a Framebuffer Object as a Texture'
// http://stackoverflow.com/questions/3613889/gl-framebuffer-incomplete-attachment-when-trying-to-attach-texture
// Create the destination texture, and attach it to the framebuffer’s color attachment point.
// create the texture
GLuint id_texDest;
{
// fragshader will use 0
glActiveTexture( GL_TEXTURE0 );
// Ask GL to give us a texture-ID for us to use
glGenTextures( 1, & id_texDest );
glBindTexture( GL_TEXTURE_2D, id_texDest );
// actually allocate memory for this texture
GLuint pixCount = in_W * in_H;
typedef struct { uint8_t r, g, b, a } rgba;
rgba * alphas = calloc( pixCount, sizeof( rgba ) );
// XOR texture
int pix=0;
for ( int x = 0; x < in_W; x++ )
{
for ( int y = 0; y < in_H; y++ )
{
//alphas[ pix ].r = (y < 256) ? x^y : 0;
//alphas[ pix ].g = (y < 512) ? 127 : 0;
//alphas[ pix ].b = (y < 768) ? 127 : 0;
alphas[ pix ].a = (y < 512) ? x^y : 0; // half mottled, half black
pix++;
}
}
// set some params on the ACTIVE texture
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR/*_MIPMAP_LINEAR*/ );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
// WRITE/COPY from P into active texture
glTexImage2D( GL_TEXTURE_2D, 0,
GL_RGBA /*GL_ALPHA*/, in_W, in_H, 0,
GL_RGBA /*GL_ALPHA*/,
GL_UNSIGNED_BYTE,
(void *) alphas );
//glGenerateMipmap( GL_TEXTURE_2D );
free( alphas );
glLogAndFlushErrors();
}
GLuint textureFrameBuffer;
{
GLint oldFBO;
glGetIntegerv( GL_FRAMEBUFFER_BINDING, & oldFBO );
// create framebuffer
glGenFramebuffers( 1, & textureFrameBuffer );
glBindFramebuffer( GL_FRAMEBUFFER, textureFrameBuffer );
// attach renderbuffer
glFramebufferTexture2D( GL_FRAMEBUFFER,
GL_COLOR_ATTACHMENT0,
GL_TEXTURE_2D,
id_texDest,
0 );
//glDisable( GL_DEPTH_TEST );
// Test the framebuffer for completeness. This test only needs to be performed when the framebuffer’s configuration changes.
GLenum status = glCheckFramebufferStatus( GL_FRAMEBUFFER ) ;
NSAssert1( status == GL_FRAMEBUFFER_COMPLETE, @"failed to make complete framebuffer object %x", status );
// 36054 0x8CD6 GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT
// unbind frame buffer
glBindFramebuffer( GL_FRAMEBUFFER, oldFBO );
}
glLogAndFlushErrors();
// clear texture bitmap to backcolor
{
GLint oldFBO;
glGetIntegerv( GL_FRAMEBUFFER_BINDING, & oldFBO );
glBindFramebuffer( GL_FRAMEBUFFER, textureFrameBuffer );
glLogAndFlushErrors();
{
float j = 0.1f;
glClearColor( j, j, j, j );
glLogAndFlushErrors();
glClear( GL_COLOR_BUFFER_BIT );
glLogAndFlushErrors();
}
glBindFramebuffer( GL_FRAMEBUFFER, oldFBO );
}
glDeleteFramebuffers( 1, & textureFrameBuffer );
* out_pTexId = id_texDest;
glLogAndFlushErrors();
}
+(void)模糊纹理:(GLuint)in_texId
槽宽:(胶合)英寸
壶高:(GLuint)英寸
returningTexId:(GLuint*)out\u pTexId
{
//搜索帮助:“使用帧缓冲区对象作为纹理”
// http://stackoverflow.com/questions/3613889/gl-framebuffer-incomplete-attachment-when-trying-to-attach-texture
//创建目标纹理,并将其附着到帧缓冲区的颜色附着点。
//创建纹理
胶合id_texDest;
{
//fragshader将使用0
玻璃纹理(GL_纹理0);
//让GL给我们一个纹理ID供我们使用
glGenTextures(1和id_texDest);
glBindTexture(GL_TEXTURE_2D,id_texDest);
//实际上为这个纹理分配内存
GLuint pixCount=英寸W*英寸H;
typedef结构{uint8_t r,g,b,a}rgba;
rgba*alphas=calloc(pixCount,sizeof(rgba));
//异或结构
int-pix=0;
对于(int x=0;x
不,OpenGL ES 2.0没有任何可渲染的单通道纹理格式。GL_ALPHA和GL_亮度不可渲染,因此它们对RTT没有用处。自iOS 5.0以来,您可以使用GL_EXT_texture_rg渲染到1通道和2通道纹理
编辑:我已经测试过了,它可以工作,但只在A5及以上版本(iPad2/3/4/mini、iPhone4S/5、iPodtouch第五代)上。不幸的是,它不能在A4及更老版本的最需要它的设备上使用(iPhone4、iPodtouch第四代、3GS、iPad1)。我认为可以渲染成RGBA纹理,然后使用glTexSubImage2D构建一个子纹理,每四个字节一次。。。我不知道是否有任何简单的方法将其保存为一个单独的纹理(在这种情况下,可以删除原始纹理)此扩展在OpenGL for Mac OS X上也可用吗?