请选择 进入手机版 | 继续访问电脑版

开源计算机图形学社区(Open Source Computer Graphics Community) |OpenGPU Forum (2007-2013)| OpenGPU Project

 找回密码
 注册
搜索
查看: 1036|回复: 3

RBO绘制问题 [复制链接]

Rank: 4

注册时间
2012-7-13
积分
31
发表于 2017-8-23 11:39:52 |显示全部楼层
各位高手:
       本人工程中使用RBO绘制过程中,遇到一个奇怪的问题,当调用视口设置glViewPort(x0,y0,width,height)函数时,若想绘制到整个窗口的某个区域内时,如glViewPort(0.2*w,0,0.8*w,1*h),其中w,h分别为窗口宽度和高度,当移动对象位置超过了窗口的0.8w时,采用RBO绘制贴纹理出现纹理拉伸丢失现象。
      RBO机制如下:
      RBO初始化:
float quadVertices[] = {   // Vertex attributes for a quad that fills the entire screen in Normalized Device Coordinates.
                // Positions   // TexCoords
                -1.0f, 1.0f, 0.0f, 1.0f,
                -1.0f, -1.0f, 0.0f, 0.0f,
                1.0f, -1.0f, 1.0f, 0.0f,

                -1.0f, 1.0f, 0.0f, 1.0f,
                1.0f, -1.0f, 1.0f, 0.0f,
                1.0f, 1.0f, 1.0f, 1.0f
        };

               glGenVertexArrays(1, &quadVAO);
                glGenBuffers(1, &quadVBO);
                glBindVertexArray(quadVAO);
                glBindBuffer(GL_ARRAY_BUFFER, quadVBO);
                glBufferData(GL_ARRAY_BUFFER, sizeof(quadVertices), &quadVertices, GL_STATIC_DRAW);
                //bind vertices attributes, for location 0 and location 1
                glEnableVertexAttribArray(0);
                glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(GLfloat), (GLvoid*)0);//position
                glEnableVertexAttribArray(1);
                glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(GLfloat), (GLvoid*)(2 * sizeof(GLfloat)));//texcoords
                glBindVertexArray(0);

                // Framebuffers
                glGenFramebuffers(1, &framebuffer);
                glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
                // Create a color attachment texture
                textureColorbuffer = GenerateAttachmentTexture(false, false);
                glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textureColorbuffer, 0);

                // Create a renderbuffer object for depth and stencil attachment (we won't be sampling these)
                GLuint rbo;
                glGenRenderbuffers(1, &rbo);
                glBindRenderbuffer(GL_RENDERBUFFER, rbo);
                glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, (int)m_viewsize[0], (int)m_viewsize[1]); // Use a single renderbuffer object for both a depth AND stencil buffer.
                glBindRenderbuffer(GL_RENDERBUFFER, 0);
                glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, rbo); // Now actually attach it
                // Now that we actually created the framebuffer and added all attachments we want to check if it is actually complete now
                if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
                        std::cout << "ERROR::FRAMEBUFFER:: Framebuffer is not complete!" << std::endl;
                glBindFramebuffer(GL_FRAMEBUFFER, 0);


           // Generates a texture that is suited for attachments to a framebuffer
        GLuint MVKOpaqueStrategy::GenerateAttachmentTexture(GLboolean depth, GLboolean stencil)
        {
                // What enum to use?
                GLenum attachment_type;
                if (!depth && !stencil)
                        attachment_type = GL_RGB;
                else if (depth && !stencil)
                        attachment_type = GL_DEPTH_COMPONENT;
                else if (!depth && stencil)
                        attachment_type = GL_STENCIL_INDEX;

                //Generate texture ID and load texture data
                GLuint textureID;
                glGenTextures(1, &textureID);
                glBindTexture(GL_TEXTURE_2D, textureID);
                if (!depth && !stencil)
                        glTexImage2D(GL_TEXTURE_2D, 0, attachment_type, (int)m_viewsize[0], (int)m_viewsize[1], 0, attachment_type, GL_UNSIGNED_BYTE, NULL);
                else // Using both a stencil and depth test, needs special format arguments
                        glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH24_STENCIL8, (int)m_viewsize[0], (int)m_viewsize[1], 0, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, NULL);
                glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
                glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
                glBindTexture(GL_TEXTURE_2D, 0);

                return textureID;
        }

        RBO绘制机制如下:
        glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
       glEnable(GL_DEPTH_TEST);
        glDisable(GL_BLEND);

       m_currentShader->Use();
       m_currentShader->SetUniform3f()
       ...
       //场景绘制
       Draw()
       //最后贴纹理:
                       glBindFramebuffer(GL_FRAMEBUFFER, 0);
                // Clear all relevant buffers
                //glClearColor(1.0f, 1.0f, 1.0f, 1.0f); // Set clear color to white (not really necessery actually, since we won't be able to see behind the quad anyways)
                glClear(GL_COLOR_BUFFER_BIT);
                glDisable(GL_DEPTH_TEST); // We don't care about depth information when rendering a single quad

                // Draw Screen
                m_currentShader = m_shader2;
                m_currentShader->Use();
                glBindVertexArray(quadVAO);
                glBindTexture(GL_TEXTURE_2D, textureColorbuffer);        // Use the color attachment texture as the texture of the quad plane
                glDrawArrays(GL_TRIANGLES, 0, 6);
                glBindVertexArray(0);

              问题现象效果如图:
              谁能提点建议,谢谢啦!!!!



Rank: 4

注册时间
2012-7-13
积分
31
发表于 2017-8-25 17:05:37 |显示全部楼层
自己先顶一下啊,个人最开始感觉是不是因为切换视口时,需要重新生成相应尺寸的RBO纹理,试了也没有效果;另外纹理尺寸上的问题也排除了;纹理贴图的方式也都试了一遍,问题依然存在。

使用道具 举报

Rank: 21Rank: 21Rank: 21Rank: 21Rank: 21Rank: 21

注册时间
2012-10-31
积分
9111
发表于 2017-9-29 16:42:03 |显示全部楼层
没看懂。
貌似是viewport外部,边缘没有刷新。

使用道具 举报

Rank: 28Rank: 28Rank: 28Rank: 28Rank: 28Rank: 28Rank: 28

注册时间
2007-6-11
积分
29906
发表于 2017-9-29 20:09:31 |显示全部楼层
绘制的时候,设置这两个
GL_TEXTURE_WRAP_S
GL_TEXTURE_WRAP_T

GL_CLAMP_TO_EDGE
试试看。

使用道具 举报

最近看过此主题的会员

您需要登录后才可以回帖 登录 | 注册

‹‹
我的工具栏

关于我们|手机版|Archiver|开源计算机图形学社区(Open Source Computer Graphics Community) | OpenGPU Project | OpenGPU Forum (2007-2013)

GMT+8, 2017-11-20 01:54 , Processed in 0.061593 second(s), 12 queries .

Powered by Discuz! X2

© 2001-2011 Comsenz Inc.

回顶部