gpt4 book ai didi

ios - 在 OpenGL ES 2.0 中从一个非 2 的幂纹理复制到另一个纹理

转载 作者:行者123 更新时间:2023-11-29 00:42:18 26 4
gpt4 key购买 nike

我在 iOS 上使用 OpenGL ES 2.0。

我有以下代码可以从较小的纹理复制到较大的纹理中;一切顺利,没有 glGetError() 。然而,当我读回像素时,似乎什么都没写,原始纹理也没有修改。

所以我想知道是否可以使用 Texture Unit 0 进行复制;或者当我要求它为其颜色渲染缓冲区使用纹理时,帧缓冲区是否隐式使用纹理单元 0?换句话说,glFramebufferTexture2D 是否占用了纹理单元 0?我是否需要为 fromTexture 使用纹理单元 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 );

最佳答案

Framebuffer 附件绑定(bind)与纹理单元无关;它们在 API 中是完全独立的概念。

关于ios - 在 OpenGL ES 2.0 中从一个非 2 的幂纹理复制到另一个纹理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39148388/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com