Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/performance/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/opengl/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Performance OpenGL FBO性能问题_Performance_Opengl_Fbo - Fatal编程技术网

Performance OpenGL FBO性能问题

Performance OpenGL FBO性能问题,performance,opengl,fbo,Performance,Opengl,Fbo,我正在做一个学校项目,我遇到了一个与我的FBO的问题 游戏分两次进行: 1) 我使用FBO渲染到阴影贴图纹理。 2) 我通常将场景渲染为默认FBO 问题是,出于某种原因,当我第一次传球时绑定FBO会使我的比赛速度降低大约200+fps,我真的不知道FBO会出什么问题,因为它尽可能的赤裸裸。 如果我在没有绑定的情况下渲染阴影贴图,那么直接到屏幕,速度会快200 fps,所以这不是渲染的问题,我相信这是绑定FBO的问题 不管怎样,这里是第一个传递函数 //renders to the depth b

我正在做一个学校项目,我遇到了一个与我的FBO的问题

游戏分两次进行: 1) 我使用FBO渲染到阴影贴图纹理。 2) 我通常将场景渲染为默认FBO

问题是,出于某种原因,当我第一次传球时绑定FBO会使我的比赛速度降低大约200+fps,我真的不知道FBO会出什么问题,因为它尽可能的赤裸裸。 如果我在没有绑定的情况下渲染阴影贴图,那么直接到屏幕,速度会快200 fps,所以这不是渲染的问题,我相信这是绑定FBO的问题

不管怎样,这里是第一个传递函数

//renders to the depth buffer texture.
void firstPass()
{
    static GLuint shadowID = Resources::getInstance().shadowShader;

    shadowBuffer->bindForWriting();//make active frame buffer the shadow buffer
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glViewport(0, 0, shadowBuffer->TEXTURE_WIDTH, shadowBuffer->TEXTURE_HEIGHT);

    //render to the shadow map from the point of view of the sunlight.
    glUseProgram(shadowID);

    ... set some uniforms

    scene->render(shadowID);
    shadowBuffer->unBindForWriting();//set frame buffer to default
    glUseProgram(0);
}
这是我的FBO课程的全部内容

ShadowMapFBO()
{
    init();
}

void bindForWriting()
{
    glBindFramebuffer(GL_DRAW_FRAMEBUFFER, FBO);
}

void unBindForWriting()
{
    glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
}

void bindForReading(GLenum TextureUnit, GLuint texture)
{
    glActiveTexture(TextureUnit);
    glBindTexture(GL_TEXTURE_2D, texture);
}

void BindTexture(GLuint textureID, GLuint location)
{
    glUniform1i(textureID, location);
}

void unBindForReading()
{
    glBindTexture(GL_TEXTURE_2D, 0);
}

GLuint shadowTexture;

int TEXTURE_WIDTH = 2048;
int TEXTURE_HEIGHT = 2048;


GLuint FBO;

void init()
{
    glGenFramebuffers(1, &FBO);
    glBindFramebuffer(GL_FRAMEBUFFER, FBO);

    shadowTexture = Util::createTexture(TEXTURE_WIDTH, TEXTURE_HEIGHT, true);

    glFramebufferTexture(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, shadowTexture, 0);

    glDrawBuffer(GL_NONE);
    glReadBuffer(GL_NONE);


    GLenum Status = glCheckFramebufferStatus(GL_FRAMEBUFFER);

    if (Status != GL_FRAMEBUFFER_COMPLETE)
        printf("FB error, status: 0x%x\n", Status);
    else
        printf("Shadow Buffer created successfully.\n");

    glBindFramebuffer(GL_FRAMEBUFFER, 0);
}
下面是我如何创建深度缓冲区纹理的

static GLuint createTexture(int width, int height)
    {
        GLuint textureId;
        glGenTextures(1, &textureId);
        glBindTexture(GL_TEXTURE_2D, textureId);


        glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, width, height, 0, GL_DEPTH_COMPONENT, GL_FLOAT, NULL);
        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);
        glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);

        int i;
        i = glGetError();
        if (i != 0)
        {
            std::cout << "Error happened while loading the texture: " << i << std::endl;
        }
        glBindTexture(GL_TEXTURE_2D, 0);
        return textureId;
    }
static GLuint createTexture(int-width,int-height)
{
胶合蛋白;
glGenTextures(1,&textureId);
glBindTexture(GL_TEXTURE_2D,textureId);
glTexImage2D(GL_纹理_2D,0,GL_深度_分量,宽度,高度,0,GL_深度_分量,GL_浮动,NULL);
glTexParameteri(GL_纹理2D、GL_纹理最小过滤器、GL_线性);
glTexParameteri(GL_纹理2D、GL_纹理MAG_过滤器、GL_线性);
glTexParameterf(GL_纹理2D、GL_纹理包裹、GL_夹具);
glTexParameterf(GL_纹理、GL_纹理、GL_包裹、GL_夹紧);
int i;
i=glGetError();
如果(i!=0)
{

std::你怎么会认为这是帧缓冲区绑定的问题呢?你分析过它吗?好吧,当我仍然做第一遍时,我渲染阴影贴图,当我在屏幕上不绑定时,我得到200 fps,当我绑定时,绘制到文本,我得到-200 fps,所以我知道不是渲染速度慢,这是其他原因,但我会我不知道是什么,-200fps与什么相比?更改帧缓冲区是最慢的GL操作之一,因此如果它从通常以5000fps渲染的内容中减去200fps(关闭vsync)那么,这可能并不奇怪。你需要在总帧渲染时间的百分比中建立这个值,或者更好的是,在绝对毫秒内。考虑使用GLGBACKIORIG/GLDENQUEST来确定执行特定操作以缩短搜索性能问题的实际时间。绑定FBO后会显示颜色缓冲区。显然,FBO没有颜色缓冲区附件,因此这很愚蠢。接下来,请注意,如果没有FBO,深度缓冲区的分辨率几乎肯定小于2048x2048;没有多少GL窗口那么大。最后,您没有为深度纹理请求特定的位深度。如果您担心的话考虑到性能,请按此顺序尝试
GL_DEPTH_component 16
GL_DEPTH_component 24
GL_DEPTH_component 32[F]
。较低的位深度可能不足以进行阴影映射,但会更快。接下来是最后一条语句-您尚未展示
Util::createTexture(…)的实现
,需要使用内部格式创建纹理
GL_DEPTH_COMPONET[16/24/32 | F]
或适当的压缩深度+模具格式。