0
iOS에서 OpenGL ES 2.0을 사용하고 있습니다.OpenGL ES 2.0에서 텍스처가 아닌 다른 텍스처로 복사
더 작은 텍스처에서 더 큰 텍스처로 복사하는 데 다음 코드가 있습니다. 모든 것이 끝나고 glGetError()가 없습니다. 그러나 픽셀을 다시 읽을 때 아무 것도 쓰지 않고 원래 텍스처가 수정되지 않은 것처럼 보입니다.
그래서 텍스쳐 유닛 0을 사용하여 복사본을 만들 수 있는지 궁금합니다. 또는 텍스처 버퍼를 텍스처로 사용하도록 요청할 때 암시 적으로 텍스처 유닛 0을 사용하는 프레임 버퍼입니까? 다른 말로 glFramebufferTexture2D가 텍스처 유닛 0을 묶는가? fromTexture 대신에 texture unit 1을 사용해야합니까?
또는 여행을 유발할 수있는 코드에 다른 문제가 있습니까?
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, toTextureImage.name);
// Set the texture parameters for a non power of 2;
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glBindTexture(GL_TEXTURE_2D, 0);
// Generate a new FBO. It will contain the texture as the color render buffer (color attachment).
GLuint offscreenFrameBuffer;
glGenFramebuffers(1, &offscreenFrameBuffer);
glBindFramebuffer(GL_FRAMEBUFFER, offscreenFrameBuffer);
// Bind the texture to the FBO; Question ? With this use the texture unit 0?
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, toTextureImage.texture.name, 0);
// Test if everything failed
GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
if(status != GL_FRAMEBUFFER_COMPLETE)
{
DebugLog(@"failed to make complete framebuffer object %x", status);
return ;
}
// Bind the FBO; it is already bound;
// glBindFramebuffer(GL_FRAMEBUFFER, offscreenFrameBuffer);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, fromTextureImage.name);
BoundingBox uvBounds;
uvBounds.xmin = 0.0;
uvBounds.xmax = 1.0;
uvBounds.ymin = 0.0;
uvBounds.ymax = 1.0;
Vector2 renderUVs[6];
quadsFromBoundingBox(&uvBounds, renderUVs);
BoundingBox verticesBounds;
verticesBounds.xmin = toPos->v[0];
verticesBounds.xmax = toPos->v[0] + fromTextureImage.imageSize->v[0];
verticesBounds.ymin = toPos->v[1];
verticesBounds.ymax = toPos->v[1] + fromTextureImage.imageSize->v[1];
Vector2 renderVertices[6];
quadVerticesFromBoundingBox(&verticesBounds, renderVertices);
[ self prepareToDraw ];
// Tell the shader what the UVs are ...
[ self setTexture0UVs:renderUVs ];
// use linear filtering for non power of 2
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
// set the default color to use
[ self setColor4b:&colorRGB_White ];
// Tell the shader what the vertices are;
[ self setVerticesVector2s:renderVertices ];
glEnable(GL_BLEND);
glBlendFunc(GL_ONE, GL_ZERO);
glDrawArrays(GL_TRIANGLES, 0, 6);
glDisable(GL_BLEND);
// Unbind the framebuffer;
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glDeleteFramebuffers(1, &offscreenFrameBuffer);