我正在尝试在OpenGL中使用累积缓冲区,但由于某种原因缓冲区似乎没有填充 . 我构建了一个简单的测试应用程序,一个2D平面被渲染,没有别的 . 这很好 . 然后我尝试做我能想到的最简单的累积缓冲操作,将渲染帧加载到累积缓冲区,清除屏幕然后将累积缓冲区返回到屏幕 . 当我这样做时,看起来累积缓冲区根本不包含任何信息,图像只是屏幕被清除的颜色,就好像累积缓冲区根本就没有返回 . 我还尝试过做一个更传统的运动模糊设置,在返回之前对场景和缓冲区进行多次更新并获得相同的结果 .
这是简单测试的主循环:
SDL_Event eve;
while (true)
{
//Normal stuff
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);
//Accumulation///////////////////////
glAccum(GL_LOAD, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glAccum(GL_RETURN, 1.0f);
//Accumulation///////////////////////
SDL_GL_SwapWindow(window);
SDL_PollEvent(&eve);
}
这是运动模糊测试的主要循环:
float x = 0.0f;
int step = 0;
int steps = 4;
SDL_Event eve;
while (true)
{
//Test stuff
x += 0.005f;
GLfloat newVerts[] = {
-0.5f + x, 0.5f,
0.5f + x, 0.5f,
0.5f + x, -0.5f,
-0.5f + x, -0.5f,
};
glBufferData(GL_ARRAY_BUFFER, sizeof(newVerts), newVerts, GL_STATIC_DRAW);
//Normal stuff
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);
//Accumulation///////////////////////
if (step == 0)
{
glAccum(GL_LOAD, 1.0f / steps);
}
else
{
glAccum(GL_ACCUM, 1.0f / steps);
}
step++;
if (step < steps)
{
continue;
}
step = 0;
glAccum(GL_RETURN, 1.0f);
//Accumulation///////////////////////
SDL_GL_SwapWindow(window);
SDL_PollEvent(&eve);
}
这是完整的应用程序源(它's only about 100 lines, I' m包括它只是因为我的 glEnable
或 SDL_GL_SetAttribute
调用出错了):
#include "tools.h"
static string vertexSource = getFile("D:/test.vsh");
static string fragmentSource = getFile("D:/test.fsh");
int main(int argc, char *argv[])
{
//SDL///////////////////////////////////////////////
SDL_Init(SDL_INIT_EVERYTHING);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 4);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 5);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_ACCUM_RED_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_ACCUM_GREEN_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_ACCUM_BLUE_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_ACCUM_ALPHA_SIZE, 8);
SDL_Window *window = SDL_CreateWindow("Test", 50, 50, 1600, 900, SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE);
SDL_GLContext context = SDL_GL_CreateContext(window);
//GLEW///////////////////////////////////////////////
glewExperimental = GL_TRUE;
GLint result = glewInit();
if (result != GLEW_OK)
{
cout << glewGetErrorString(result) << "\n";
cout << "GLEW initialization failed.\n";
}
//OpenGL///////////////////////////////////////////////
glEnable(GL_DEPTH);
glDepthFunc(GL_LEQUAL);
glEnable(GL_DEPTH_TEST);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glClearColor(1.0f, 1.0f, 0.0f, 1.0f);
glClearDepth(1.0f);
//Object///////////////////////////////////////////
//Vertex Array
GLuint vao;
glGenVertexArrays(1, &vao);
glBindVertexArray(vao);
//Vertex Buffer
GLuint vbo;
glGenBuffers(1, &vbo);
GLfloat vertices[] = {
-0.5f, 0.5f,
0.5f, 0.5f,
0.5f, -0.5f,
-0.5f, -0.5f,
};
glBindBuffer(GL_ARRAY_BUFFER, vbo);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
//Element Buffer
GLuint ebo;
glGenBuffers(1, &ebo);
GLuint elements[] = {
0, 1, 2,
2, 3, 0
};
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ebo);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(elements), elements, GL_STATIC_DRAW);
//Shader
GLuint shaderProgram = createShader(vertexSource, fragmentSource);
glUseProgram(shaderProgram);
GLint posAttrib = glGetAttribLocation(shaderProgram, "position");
glEnableVertexAttribArray(posAttrib);
glVertexAttribPointer(posAttrib, 2, GL_FLOAT, GL_FALSE, 0, 0);
//Loop///////////////////////////////////////////////
float x = 0.0f;
int step = 0;
int steps = 4;
SDL_Event eve;
while (true)
{
//Test stuff
x += 0.005f;
GLfloat newVerts[] = {
-0.5f + x, 0.5f,
0.5f + x, 0.5f,
0.5f + x, -0.5f,
-0.5f + x, -0.5f,
};
glBufferData(GL_ARRAY_BUFFER, sizeof(newVerts), newVerts, GL_STATIC_DRAW);
//Normal stuff
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);
//Accumulation///////////////////////
if (step == 0)
{
glAccum(GL_LOAD, 1.0f / steps);
}
else
{
glAccum(GL_ACCUM, 1.0f / steps);
}
step++;
if (step < steps)
{
continue;
}
step = 0;
glAccum(GL_RETURN, 1.0f);
//Accumulation///////////////////////
SDL_GL_SwapWindow(window);
SDL_PollEvent(&eve);
}
}
我正在使用GLEW来访问OpenGL调用,我正在使用SDL进行上下文创建和窗口管理 .
平台的一般规格我正在运行:
-
OpenGL 4.5(也尝试过4.3和3.3,没有区别) .
-
Windows 10 64位
-
AMD FX-9590 @ 4.7 GHz
-
NVIDIA GTX 970 SC
-
华硕Sabertooth 990FX
-
16GB DDR3内存
1 回答
删除的功能(如累积缓冲区)在Core上下文中不起作用 .
OpenGL 3.2 Core spec, appendix E, page 329 & 333: