简体   繁体   English

多维数据集贴图渲染纹理创建在GL 3.2中有效,但在4.3中出现错误

[英]Cube map render texture creation works in GL 3.2 but gives an error in 4.3

I'm using the following code to create a cube map render target: 我正在使用以下代码创建多维数据集贴图渲染目标:

glGenTextures( 1, &id );
glBindTexture( GL_TEXTURE_CUBE_MAP, id );

glTexParameteri( GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
glTexParameteri( GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
glTexParameteri( GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
glTexParameteri( GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
glTexParameteri( GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE );

// Creates a renderbuffer object to store depth info.
GLuint bufferId;
glGenRenderbuffers( 1, &bufferId );

glBindRenderbuffer( GL_RENDERBUFFER, bufferId );
glRenderbufferStorage( GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, width, height );
glBindRenderbuffer( GL_RENDERBUFFER, 0 );

glGenFramebuffers( 1, &fboId );
glBindFramebuffer( GL_FRAMEBUFFER, fboId );

const GLenum externalFormat = GL_RGBA;
const GLenum internalFormat = GL_RGBA8;
const GLenum dataType = GL_UNSIGNED_BYTE;

for (int i = 0; i < 6; ++i)
{
    glTexImage2D( GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, internalFormat,
                 size, size, 0, externalFormat,
                 dataType, nullptr );
    glFramebufferTexture2D( GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, id, 0 );
}

glFramebufferRenderbuffer( GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, bufferId );

It doesn't generate any OpenGL errors in OpenGL 3.2 context but when running the same code under OpenGL 4.3 context, debug output callback gives the following error on glFramebufferTexture2D: 它不会在OpenGL 3.2上下文中生成任何OpenGL错误,但是在OpenGL 4.3上下文中运行相同的代码时,调试输出回调在glFramebufferTexture2D上会产生以下错误:

OpenGL: Framebuffer unsupported. Attachment COLOR_ATTACHMENT0 unsupported because it uses an inconsistent texture due to invalid texture parameters.

I'm running the code on Windows 8.1 with NVIDIA GeForce GT 750M, driver 337.88. 我正在使用NVIDIA GeForce GT 750M,驱动程序337.88在Windows 8.1上运行代码。 Am I creating the render target wrongly? 我是否错误地创建了渲染目标?

I'm not sure what the error is about, but maybe related to a mismatch between size , width and height . 我不确定这是什么错误,但可能与sizewidthheight之间的不匹配有关。

Regardless, there's a few other issues: 无论如何,还有其他一些问题:

  1. Each loop iteration simply overrides GL_COLOR_ATTACHMENT0 . 每个循环迭代仅覆盖GL_COLOR_ATTACHMENT0 Perhaps change to GL_COLOR_ATTACHMENT0 + i . 也许更改为GL_COLOR_ATTACHMENT0 + i

  2. However this means you must write to every layer in the cube when ever a fragment passes the depth test. 但是,这意味着,只要片段通过深度测试,就必须写入多维数据集的每一层。

  3. You also have a single renderbuffer with just one layer which means a single depth test is used for all sides of your cube. 您还只有一个渲染缓冲区,只有一个图层,这意味着对多维数据集的所有面都使用了一个深度测试。

I don't think the above is what you want anyway. 我认为以上并不是您想要的。

  • To render to a cube texture you could bind each layer in turn, rendering the whole scene multiple times each from a new projection. 要渲染为立方体纹理,您可以依次绑定每个图层,从一个新的投影中多次渲染整个场景。 This is the old way of doing it. 这是老方法。

    Example

  • To render to a cube texture with just one rendering pass you can bind the entire cube map (which is really just 6 layers of a regular texture) to GL_COLOR_ATTACHMENT0 . 要仅通过一次渲染就可以渲染为立方体纹理,可以将整个立方体贴图(实际上只是常规纹理的6层)绑定到GL_COLOR_ATTACHMENT0 For depth testing, you create and bind another cube texture (or renderbuffer, but not sure if you can) with GL_DEPTH_COMPONENT to GL_DEPTH_ATTACHMENT . 对于深度测试,您可以使用GL_DEPTH_COMPONENT创建另一个立方体纹理 (或渲染缓冲区,但不确定是否可以绑定)并将其绑定到GL_DEPTH_ATTACHMENT Then in the geometry shader you duplicate everything 6 times, one for each face of your cube. 然后,在几何体着色器中,您将所有内容重复6次,对于立方体的每个面一次。 gl_Layer in the geometry shader is used to set which face in the cube the primitive draws to. 几何着色器中的gl_Layer用于设置基本体将绘制到立方体中的哪个面。 Come to think of it you could also use instancing ( glDrawElementsInstanced / gl_InstanceID ) to duplicate your geometry 6 times which would shift computation from the geometry shader to the vertex shader and may be a little faster if your vertex operations are expensive. 想一想,您还可以使用实例化( glDrawElementsInstanced / gl_InstanceID )将几何图形复制6次,这将使计算从几何图形着色器转移到顶点着色器,并且如果您的顶点操作很昂贵,可能会更快一些。

    Example

In both cases you'll need a 90 degree projection matrix with aspect ration 1 and will need to rotate the view to match the cube faces (this is pretty fiddly so save your code for future use). 在这两种情况下,您都将需要一个长宽比为1的90度投影矩阵,并且需要旋转视图以匹配多维数据集的面(这很奇怪,因此请保存您的代码以备将来使用)。 So create 6 the view matrices and pass them in to either the geometry or vertex shader depending on whether you use instancing or not. 因此,根据您是否使用实例化,创建6个视图矩阵,并将它们传递给几何或顶点着色器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 OpenGL:GL_TEXTURE_CUBE_MAP和GL_REFLECTION_MAP - OpenGL: GL_TEXTURE_CUBE_MAP and GL_REFLECTION_MAP 在GL_TEXTURE_CUBE_MAP中具有不同分辨率的面 - Faces with different resolutions in GL_TEXTURE_CUBE_MAP 在 glUseProgram 中设置 GL_TEXTURE_CUBE_MAP 会导致 GL_INVALID_OPERATION - Setting GL_TEXTURE_CUBE_MAP cause GL_INVALID_OPERATION in glUseProgram 在 OpenGL 中,如何使用 glGetTexImage 获取 GL_TEXTURE_CUBE_MAP_ARRAY 类型纹理面的像素数据? - In OpenGL, how do I use glGetTexImage to get pixel data for a face of a texture of type GL_TEXTURE_CUBE_MAP_ARRAY? 我可以纹理这个在 GL_TRIANGLE_STRIP 模式下渲染的立方体吗? - Can I texture this cube that is rendered in GL_TRIANGLE_STRIP mode? 使用GL_QUADS在侧面立方体上进行OpenGL纹理映射 - OpenGL texture mapping on sides cube using GL_QUADS 渲染到迷你地图dirextX的纹理 - Render to texture for mini map, dirextX glGenerateMipmap中的GL_INVALID_OPERATION(不完整的多维数据集映射) - GL_INVALID_OPERATION in glGenerateMipmap(incomplete cube map) Open gl es - 如何提高性能,渲染纹理,混合 - Open gl es - How to improve performance, render to texture, blending 如何在OpenGL 4.5中从单个立方体贴图纹理创建立方体贴图数组纹理? - How to create a cube map array texture from individual cube map textures in OpenGL 4.5?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM