简体   繁体   English

C ++ Opengl Glsl着色器性能问题

[英]C++ Opengl Glsl Shader Performance Issue

So recently I have been programming an fps game on my laptop but when I tried to run the game on my stationary computer which should perform better it runs slower?? 所以最近我一直在我的笔记本电脑上编写一个fps游戏,但是当我试图在我的固定电脑上运行游戏时应该运行得更好它运行得更慢?

Here is a couple of screenshots comparing a simple test scene with and without skybox. 这里有一些屏幕截图,比较了一个简单的测试场景,有无天空盒。 ( Stationary computer - Top, Laptop - Bottom) (固定电脑 - 顶部,笔记本电脑 - 底部)

没有Skybox固定计算机

没有Skybox笔记本电脑

As you can see so far this is what I would excpect, but when I add the same skybox rendering code + shader code ( Stationary computer - Top, Laptop - Bottom) 正如你所看到的那样,这是我想要的,但当我添加相同的天空盒渲染代码+着色器代码(固定计算机 - 顶部,笔记本电脑 - 底部)

使用Skybox固定式计算机

使用Skybox笔记本电脑

As you can see now the results are the complete opposite and I have no clue why infact if I look up or back with skybox on my stationary computer I get an fps of about 5. 你现在可以看到结果是完全相反的,我不知道为什么如果我在我的固定电脑上查看或返回天空盒我得到大约5的fps。

Here is the shader code for the skybox: 这是天空盒的着色器代码:

#version 120
varying vec3 pl;
uniform mat4 gWM;
void main()
{
    pl = vec3(gl_Vertex);
    gl_Position = (gWM * gl_Vertex).xyww; // I have also tried with gl_ModelViewProjectionMatrix instead of gWM.
}

Fragment shader: 片段着色器:

#version 120
varying vec3 pl;
uniform samplerCube cubeMap;
void main()
{
    gl_FragData[1] = textureCube(cubeMap, -pl);
}

The actual mesh rendered is a sphere. 渲染的实际网格是一个球体。

And another thing is that my laptop can also handle my lighting calculations with 100+ fps left, but if I add those to my stationary then I get about 15. 另一件事是我的笔记本电脑也可以处理我的照明计算,剩下100 + fps,但如果我将它们添加到我的静止处,那么我大约15。

If my stationary would perform worse in the beginning I wouldn't care about why but since it doesn't I really want to know where the fps is lost! 如果我的静止在开始时表现更差我不会在意为什么但是因为它不是我真的想知道fps在哪里丢失!

stationary computer specs: 固定电脑规格:

CPU: Intel Core i5 @ 2.80GHz CPU:Intel Core i5 @ 2.80GHz

RAM: 4,00GB Dual-Channel RAM:4,00GB双通道

Graphics: ATI Radeon HD 4800 Series 图形:ATI Radeon HD 4800系列

laptop specs: 笔记本电脑规格:

CPU: Intel Core i7 @2.00GHz CPU:Intel Core i7 @ 2.00GHz

RAM: 8,00GB Dual-Channel RAM:8,00GB双通道

Graphics: Intel HD Graphics 4000 图形:Intel HD Graphics 4000

Rendering (Updated) For rendering I use a G-Buffer that is setup like this ( from a tutorial in deffered lighting ): 渲染(更新)为了渲染,我使用了这样设置的G-Buffer(来自deffered照明中的教程):

        glGenFramebuffers(1, &m_fbo);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, m_fbo);

glGenTextures(ARRAY_ELEMENTS(m_textures), m_textures);
glGenRenderbuffers(1, &m_depthBuffer);
glGenTextures(1, &m_finalTexture);

for(unsigned int i = 0; i < ARRAY_ELEMENTS(m_textures); i++){
    glBindTexture(GL_TEXTURE_2D, m_textures[i]);
    glTexImage2D(GL_TEXTURE_2D, 0, i == 0 ? GL_RGBA32F : GL_RGB8, WindowWidth, WindowHeight, 0, GL_RGB, GL_FLOAT, NULL);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
    glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i, GL_TEXTURE_2D, m_textures[i], 0);
}

glBindRenderbuffer(GL_RENDERBUFFER, m_depthBuffer);
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8_EXT, WindowWidth, WindowHeight);
glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, m_depthBuffer);

glBindTexture(GL_TEXTURE_2D, m_finalTexture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, WindowWidth, WindowHeight, 0, GL_RGB, GL_FLOAT, NULL);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT4, GL_TEXTURE_2D, m_finalTexture, 0);

GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
if(status != GL_FRAMEBUFFER_COMPLETE){
    printf("[Error ] Framebuffer status: 0x%x\n", status);
    return false;
}
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
mWidth = WindowWidth;
mHeight = WindowHeight;
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
return true;

So My Question: What could be causing this? 所以我的问题:可能是什么导致了这个? And is there a solution? 有解决方案吗?

When I was working on my deferred renderer I was just using a texture for depth and stencil developing on an Nividia 560ti and I had no problems.But On my HD 4650 I would not show anything just a black screen so I switched to RenderBuffers for depth and stencil, and that fixed my problems.The only down side of this is that they can't be sampled in shaders. 当我在延迟渲染器上工作时,我只是在Nividia 560ti上使用纹理进行深度和模板开发而我没有任何问题。但在我的HD 4650上,我不会显示任何黑屏,所以我切换到RenderBuffers深度和模板,这解决了我的问题。唯一的缺点是它们无法在着色器中采样。 I hope this helps. 我希望这有帮助。

好吧所以我得到它的工作问题很简单我忘了在球体的渲染代码中除以sizeof(float)所以它渲染得太多甚至没有想要渲染!,但它已经修复了,所以谢谢为了帮助我获得更好的表现!

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM