我刚开始在项目中使用调试扩展,但glObjectLabel在与GL_BUFFER一起使用时会产生错误。
显卡是带有340.82驱动程序的nVidia Quadro 600
这个简单的测试是使用32位的MSVC 2010构建的:
#include <GL/glew.h>
#include <GLFW/glfw3.h>
#include <iostream>
void GLAPIENTRY ogl_cb(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar* message, const void* userParam)
{
using namespace std;
cout << "message: "<< message << endl;
}
int main()
{
using namespace std;
if (!glfwInit())
{
cerr << "Error initializing GLFW" << endl;
return 1;
}
glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GL_TRUE);
GLFWwindow *window = glfwCreateWindow(1, 1, "", NULL, NULL);
glfwMakeContextCurrent(window);
GLint glew_result = glewInit();
if (GLEW_OK != glew_result)
{
cerr << "Error initializing GLEW : " << (const char*)glewGetErrorString(glew_result) << endl;
return 2;
}
cout << "VENDOR : " << glGetString(GL_VENDOR) << endl;
cout << "RENDERER : " << glGetString(GL_RENDERER) << endl;
cout << "VERSION : " << glGetString(GL_VERSION) << endl;
cout << "GLSL VERSION : " << glGetString(GL_SHADING_LANGUAGE_VERSION) << endl;
glDebugMessageCallback(ogl_cb, NULL);
glEnable(GL_DEBUG_OUTPUT);
glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS);
GLuint progid = glCreateProgram();
glObjectLabel(GL_PROGRAM, progid, -1, "My program");
GLuint bufid;
glGenBuffers(1, &bufid);
glObjectLabel(GL_BUFFER, bufid, -1, "My buffer");
char prog_name[100];
GLsizei prog_name_len = 0;
glGetObjectLabel(GL_PROGRAM, progid, 100, &prog_name_len, prog_name);
cout << "Program name " << prog_name_len << " : " << (prog_name_len ? prog_name : "NULL") << endl;
char buf_name[100];
GLsizei buf_name_len = 0;
glGetObjectLabel(GL_BUFFER, bufid, 100, &buf_name_len, buf_name);
cout << "Buffer name " << buf_name_len << " : " << (buf_name_len ? buf_name : "NULL") << endl;
glfwDestroyWindow(window);
glfwTerminate();
return 0;
}
机器上的输出:
VENDOR : NVIDIA Corporation
RENDERER : Quadro 600/PCIe/SSE2
VERSION : 4.5.0 NVIDIA 340.82
GLSL VERSION : 4.50 NVIDIA
message: GL_INVALID_VALUE error generated. ObjectLabel: unknown buffer object <name>
Program name 10 : My program
message: GL_INVALID_VALUE error generated. GetObjectLabel: unknown buffer object <name>
Buffer name 0 : NULL
程序一切正常,但缓冲区不是...... 看看www.g-truc.net上的样本,以及网上的其他样本,我似乎无法做出我做错的事情......
关于这里发生了什么的任何线索?
答案 0 :(得分:4)
必须已创建指定标签的对象。 glGenBuffers
仅保留名称,而不创建任何内容。相反,glCreateProgram
生成一个新名称并创建程序对象。
绑定缓冲区对象至少一次就足够了。