glDrawElements导致访问冲突异常

时间:2018-06-12 18:27:57

标签: opengl

所以我最近重写了我的业余爱好OpenGL图形引擎的渲染部分,我似乎无法弄清楚为什么我会在glDrawElements上抛出访问冲突异常。

根据我已经研究过的情况,通常是由于错误配置的VAO,但从我所看到的情况来看,一切似乎都很好。

以下是我在收到错误之前所做的OpenGL调用的顺序。不幸的是我无法记录每个参数的值,但是如果有人注意到订单中的错误,请告诉我。

请注意,我在1080 Nvidia显卡上运行OpenGL 4.1并且驱动程序是最新的。

glCreateShaderProgramv(GetShaderType(_desc.ShaderType), 1, &ptr)
glGetProgramiv(_id, GL_INFO_LOG_LENGTH, &logLength)
glGetProgramiv(_id, GL_LINK_STATUS, &linkStatus)
glCreateShaderProgramv(GetShaderType(_desc.ShaderType), 1, &ptr)
glGetProgramiv(_id, GL_INFO_LOG_LENGTH, &logLength)
glGetProgramiv(_id, GL_LINK_STATUS, &linkStatus)
glGenBuffers(1, &_id)
glBindBuffer(target, _id)
glBufferData(target, _desc.ByteCount, 0, GetBufferUsage(_desc.BufferUsage))
glBindBuffer(target, _id)
glMapBufferRange(target, byteOffset, byteCount, access)
glDisable(GL_POLYGON_OFFSET_FILL)
glDisable(GL_POLYGON_OFFSET_POINT)
glDisable(GL_POLYGON_OFFSET_LINE)
glDisable(GL_CULL_FACE)
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)
glDisable(GL_SCISSOR_TEST)
glScissor(0, 0, _desc.RenderWidth, _desc.RenderHeight)
glDisable(GL_MULTISAMPLE)
glDisable(GL_DEPTH_CLAMP)
glDisable(GL_LINE_SMOOTH)
glDisable(GL_STENCIL_TEST)
glStencilOpSeparate(GL_FRONT, GetStencilOp(stencilOperationDesc.FailOp), GetStencilOp(stencilOperationDesc.ZFailOp), GetStencilOp(stencilOperationDesc.PassOp))
glStencilOpSeparate(GL_FRONT, GetStencilOp(stencilOperationDesc.FailOp, true), GetStencilOp(stencilOperationDesc.ZFailOp, true), GetStencilOp(stencilOperationDesc.PassOp, true))
glStencilFuncSeparate(GL_FRONT, GetCompareFunc(comparisonFunc), _stencilRefValue, readMask)
glStencilFuncSeparate(GL_BACK, GetCompareFunc(comparisonFunc), _stencilRefValue, readMask)
glStencilMask(writeMask)
glEnable(GL_DEPTH_TEST)
glDepthMask(GL_FALSE)
glDepthFunc(GetCompareFunc(depthFunc))
glGenBuffers(1, &_id)
glBindBuffer(target, _id)
glBufferData(target, _desc.ByteCount, 0, GetBufferUsage(_desc.BufferUsage))
glBindBuffer(target, _id)
glMapBufferRange(target, byteOffset, byteCount, access)
glGenBuffers(1, &_id)
glBindBuffer(target, _id)
glBufferData(target, _desc.ByteCount, 0, GetBufferUsage(_desc.BufferUsage))
glBindBuffer(target, _id)
glMapBufferRange(target, byteOffset, byteCount, access)
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, glIndexBuffer->GetId())
glGenProgramPipelines(1, &_id)
glUseProgramStages(_id, GL_VERTEX_SHADER_BIT, desc.VertexShaderId)
glUseProgramStages(_id, GL_FRAGMENT_SHADER_BIT, desc.PixelShaderId)
glUseProgramStages(_id, GL_GEOMETRY_SHADER_BIT, desc.GeometryShaderId)
glUseProgramStages(_id, GL_TESS_CONTROL_SHADER_BIT, desc.HullShaderId)
glUseProgramStages(_id, GL_TESS_EVALUATION_SHADER_BIT, desc.DomainShaderId)
glBindProgramPipeline(shaderPipeline->GetId())
glGenVertexArrays(1, &vao)
glBindVertexArray(vao)
glBindBuffer(GL_ARRAY_BUFFER, boundBuffers[inputSlot]->GetId())
glVertexAttribPointer(inputSlot, compSize, compType, GL_FALSE, stride, reinterpret_cast<GLvoid*>(offset))
glEnableVertexAttribArray(inputSlot)
glBindVertexArray(0)
glBindVertexArray(vao->GetId())

1 个答案:

答案 0 :(得分:0)

问题是我在创建VBO时传递的是无效大小。