gpt4 book ai didi

c++ - nVidia 和 ATI 之间的 OpenGL 渲染差异

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:46:43 25 4
gpt4 key购买 nike

最近我将 ATI 驱动程序(我使用的是 HD7970)更新为最新版本,但我的一些 OpenGL 项目的对象停止工作。更重要的是他们在 nVidia 最新的驱动程序上工作(在 960m 上测试)。我应该知道 ATI 和 nVidia 渲染管道之间有什么区别吗?

附加信息:

  • glGetError() 没有错误,
  • 正确编译和链接着色器,
  • 其他渲染对象工作正常,但 VBO 填充和绘图命令不同。工作一个是从 *.obj 文件加载并由 glDrawArrays() 绘制。 Broken one 的 VBO 由 polygonizator(计算着色器)填充,它从用于存储的 image2D 中获取顶点,并通过 glDrawElements() 绘制,
  • 我使用最简单的 gpu 调试器检查了顶点和片段着色器是否正在启动。

当我尝试用三角形绘制时,我什么也看不到,但是当我切换到 GL_POINTS 时,我看到绿点(片段着色器的输出是纯绿色 channel ),它们正在按预期移动。这可能表明顶点着色器正在启动,因为正在发生 MVP 乘法。这些是带有一个大 VBO 的行星 LOD 对象,所以我使用一个函数来绑定(bind)所有缓冲区,并使用另一个函数来绘制必要的高度图。 VBO大小为128MB

初始化:

glGenBuffers(1, &VBO);
glBindBuffer(GL_SHADER_STORAGE_BUFFER, VBO);
glBufferData(GL_SHADER_STORAGE_BUFFER, size * sizeof(vec4), NULL, GL_DYNAMIC_COPY);

glGenBuffers(1, &IndexBuffer);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, IndexBuffer);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, indexSize * sizeof(unsigned int), NULL, GL_DYNAMIC_DRAW);

glGenBuffers(1, &Normals);
glBindBuffer(GL_SHADER_STORAGE_BUFFER, Normals);
glBufferData(GL_SHADER_STORAGE_BUFFER, size * sizeof(vec4), NULL, GL_DYNAMIC_COPY);

通过多边形化器(计算着色器)填充 VBO:

    #version 430 core
layout( std430, binding=1 ) buffer ParamsBuffer
{
float size;
uint index;
int parentIndex;
uint textureSize;
vec4 upVector;
vec4 Position;
vec4 quadrant;
};
layout( std430, binding=2 ) buffer VertBuffer
{
vec4 VBO[ ];
};

layout( std430, binding=3 ) buffer NormalsBuffer
{
vec4 Normals[ ];
};

layout(std430, binding = 4) buffer IndexBuffer
{
uint Index[];
};

layout( std430, binding=10 ) buffer DebugBuffer
{
vec4 debug;
};
layout (rgba32f) uniform image2D HeightMap;
layout (rgba32f) uniform image2D NormalMap;
layout( local_size_x = 1, local_size_y = 1, local_size_z = 1) in;

void main(void)
{
uint WGidY=(gl_WorkGroupID.y);
uint WGidX=(gl_WorkGroupID.x);
uint mapVBOOffset=index*textureSize*textureSize;
uint indexOffset=6*index*textureSize*textureSize;
VBO[WGidY*textureSize+WGidX+mapVBOOffset]=imageLoad(HeightMap, ivec2(WGidX, WGidY));
Normals[WGidY*textureSize+WGidX+mapVBOOffset]=imageLoad(NormalMap, ivec2(WGidX, WGidY));
// debug=VBO[0];
if(WGidX==textureSize-1 || WGidY==textureSize-1)
return;

uint localIndex = 6*(WGidY*textureSize+WGidX)+indexOffset;
Index[localIndex+0]=(WGidY+1)*textureSize+WGidX +mapVBOOffset;
Index[localIndex+1]=WGidY*textureSize +WGidX+1+mapVBOOffset;
Index[localIndex+2]=WGidY*textureSize +WGidX +mapVBOOffset;
Index[localIndex+3]=WGidY*textureSize +WGidX+1+mapVBOOffset;
Index[localIndex+4]=(WGidY+1)*textureSize+WGidX +mapVBOOffset;
Index[localIndex+5]=(WGidY+1)*textureSize+WGidX+1+mapVBOOffset;

}

绑定(bind):

    glUseProgram(RenderProgram);
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 4, PerFrameBuffer);
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 5, ConstantBuffer);

glEnableVertexAttribArray(2);
glBindBuffer(GL_ARRAY_BUFFER, Normals);
glVertexAttribPointer(
2,
4,
GL_FLOAT,
GL_FALSE,
0,
(void*)0
);


glEnableVertexAttribArray(0);
glBindBuffer(GL_ARRAY_BUFFER, VBO);
glVertexAttribPointer(
0,
4,
GL_FLOAT,
GL_FALSE,
0,
(void*)0
);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, IndexBuffer);

绘图:

float discardFactor = 0;
GLint drawMode;
if(renderMode==0)
drawMode = GL_TRIANGLES;
if (renderMode == 1)
{
drawMode = GL_PATCHES;
GLint vert= 3;
glPatchParameteri(GL_PATCH_VERTICES, 3);
}
if (tile->quadrant_x == nullptr)
{
HeightMap hp = tile->quadrantX;
if (CornersInFrustum(hp.Corners))
{
int mapOffset = tile->quadrantX.index * 6 * heightMapSize*heightMapSize * sizeof(unsigned int);
glDrawElements(drawMode, 6 * heightMapSize*heightMapSize, GL_UNSIGNED_INT, (void*)mapOffset);
}

}

if (tile->quadrant_y == nullptr)
{
HeightMap hp = tile->quadrantY;
if ( CornersInFrustum(hp.Corners))
{
int mapOffset = tile->quadrantY.index * 6 * heightMapSize*heightMapSize * sizeof(unsigned int);
glDrawElements(drawMode, 6 * heightMapSize*heightMapSize, GL_UNSIGNED_INT, (void*)mapOffset);


}
}

if (tile->quadrant_z == nullptr)
{
HeightMap hp = tile->quadrantZ;
if (CornersInFrustum(hp.Corners))
{
int mapOffset = tile->quadrantZ.index * 6 * heightMapSize*heightMapSize * sizeof(unsigned int);
glDrawElements(drawMode, 6 * heightMapSize*heightMapSize, GL_UNSIGNED_INT, (void*)mapOffset);
}


}

if (tile->quadrant_w == nullptr)
{
HeightMap hp = tile->quadrantW;
if (CornersInFrustum(hp.Corners))
{
int mapOffset = tile->quadrantW.index * 6 * heightMapSize*heightMapSize * sizeof(unsigned int);
glDrawElements(drawMode, 6 * heightMapSize*heightMapSize, GL_UNSIGNED_INT, (void*)mapOffset);
}


}

顶点着色器:

#version 430 //core
layout(location = 0) in vec4 vertexPosition_modelspace;
layout(location = 2) in vec4 vertexNormal_modelspace;

layout(std430, binding = 4) buffer PerFrame
{
mat4 ViewMatrix;
vec4 CameraPosition;
vec4 CameraForward;
mat4 ModelMatrix;
float time;
float perFrametab[3];
};

layout(std430, binding = 5) buffer Constant
{
mat4 ProjectionMatrix;
vec4 SeedBuffer;
vec2 screenSize;
};
layout( std430, binding=10 ) buffer DebugBuffer
{
vec4 debug;
};


out vec3 Position_worldspace;
out vec3 Normal_cameraspace;
out vec3 EyeDirection_cameraspace;
out vec3 LightDirection_cameraspace;
out vec3 LightPosition_worldspace;
out vec3 NormalWorldSpace;

void main()
{
gl_Position =ProjectionMatrix*
ViewMatrix*ModelMatrix*
vec4(vertexPosition_modelspace.xyz,1);

float C = 1,
near = 0.1,
far = 10000000.0f;
gl_Position.z = (2*log2(C*gl_Position.w + 1) / log2(C*far + 1) - 1) * gl_Position.w;
Position_worldspace = (ModelMatrix*vec4(vertexPosition_modelspace.xyz,1)).xyz;
Normal_cameraspace = ( ViewMatrix *(vec4(vertexNormal_modelspace.xyz,0))).xyz;
vec4 normalTemp=ModelMatrix*vertexNormal_modelspace;
NormalWorldSpace=normalize(normalTemp.xyz);
}

最佳答案

好的,我找到了解决方案。问题出在计算着色器的 imageStore() 和 imageLoad() 中。即使我将 image2D 用于存储目的,我也需要添加

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);

生成纹理后。这就是 ATI 和 nVidia 之间的区别。

关于c++ - nVidia 和 ATI 之间的 OpenGL 渲染差异,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46160723/

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