From ce92ba70d1dd3f0041d2367a22a02d90bec28630 Mon Sep 17 00:00:00 2001 From: baldurk Date: Wed, 15 May 2019 10:56:20 +0100 Subject: [PATCH] Revert accidental change to GL_Simple_Triangle test --- util/test/demos/gl/gl_simple_triangle.cpp | 264 ++-------------------- 1 file changed, 18 insertions(+), 246 deletions(-) diff --git a/util/test/demos/gl/gl_simple_triangle.cpp b/util/test/demos/gl/gl_simple_triangle.cpp index 7844b3d24..928295e42 100644 --- a/util/test/demos/gl/gl_simple_triangle.cpp +++ b/util/test/demos/gl/gl_simple_triangle.cpp @@ -49,10 +49,6 @@ layout(location = 0) in vec3 Position; layout(location = 1) in vec4 Color; layout(location = 2) in vec2 UV; -out gl_PerVertex { - vec4 gl_Position; -}; - out v2f vertOut; void main() @@ -71,23 +67,9 @@ in v2f vertIn; layout(location = 0, index = 0) out vec4 Color; -layout(binding = 0) uniform sampler2D checker; -layout(binding = 1) uniform sampler2D smiley; - -layout(binding = 0, std140) uniform constsbuf -{ - vec4 flags; -}; - void main() { - if(flags.x != 1.0f || flags.y != 2.0f || flags.z != 4.0f || flags.w != 8.0f) - { - Color = vec4(1.0f, 0.0f, 1.0f, 1.0f); - return; - } - - Color = vertIn.col * texture(smiley, vertIn.uv.xy * 2.0f) * texture(checker, vertIn.uv.xy * 5.0f); + Color = vertIn.col; } )EOSHADER"; @@ -98,251 +80,41 @@ void main() if(!Init(argc, argv)) return 3; + GLuint vao = MakeVAO(); + glBindVertexArray(vao); + GLuint vb = MakeBuffer(); glBindBuffer(GL_ARRAY_BUFFER, vb); glBufferStorage(GL_ARRAY_BUFFER, sizeof(DefaultTri), DefaultTri, 0); - uint16_t indices[] = {0, 1, 2}; - GLuint ib = MakeBuffer(); - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ib); - glBufferStorage(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, 0); + glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(DefaultA2V), (void *)(0)); + glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, sizeof(DefaultA2V), (void *)(sizeof(Vec3f))); + glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, sizeof(DefaultA2V), + (void *)(sizeof(Vec3f) + sizeof(Vec4f))); - Texture rgba8; - LoadXPM(SmileyTexture, rgba8); + glEnableVertexAttribArray(0); + glEnableVertexAttribArray(1); + glEnableVertexAttribArray(2); - GLuint offscreen = MakeTexture(); - glBindTexture(GL_TEXTURE_2D, offscreen); - glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 128, 128); + GLuint program = MakeProgram(common + vertex, common + pixel); + glObjectLabel(GL_PROGRAM, program, -1, "Full program"); - GLuint smiley = MakeTexture(); - glBindTexture(GL_TEXTURE_2D, smiley); - glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA8, rgba8.width, rgba8.height); - glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, rgba8.width, rgba8.height, GL_RGBA, GL_UNSIGNED_BYTE, - rgba8.data.data()); - - glActiveTexture(GL_TEXTURE1); - glBindTexture(GL_TEXTURE_2D, smiley); - - glActiveTexture(GL_TEXTURE0); - glBindTexture(GL_TEXTURE_2D, 0); - - GLuint vsprog = MakeProgram(common + vertex, ""); - GLuint fsprog = MakeProgram("", common + pixel); - - // function to set up a VAO - auto SetupVAO = [ib]() { - GLuint vao = 0; - glGenVertexArrays(1, &vao); - glBindVertexArray(vao); - - glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(DefaultA2V), (void *)(0)); - glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, sizeof(DefaultA2V), (void *)(sizeof(Vec3f))); - glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, sizeof(DefaultA2V), - (void *)(sizeof(Vec3f) + sizeof(Vec4f))); - - glEnableVertexAttribArray(0); - glEnableVertexAttribArray(1); - glEnableVertexAttribArray(2); - - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ib); - - return vao; - }; - - // function to trash it again afterwards so that we are forced to reset the state to properly - // replay - auto TrashVAO = [](GLuint vao) { - glDisableVertexAttribArray(0); - glDisableVertexAttribArray(1); - glDisableVertexAttribArray(2); - - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); - - glDeleteVertexArrays(1, &vao); - }; - - // Sampler setup and trashing - auto SetupSampler = []() { - GLuint sampler = 0; - glGenSamplers(1, &sampler); - glBindSampler(1, sampler); - - glSamplerParameteri(sampler, GL_TEXTURE_WRAP_R, GL_REPEAT); - glSamplerParameteri(sampler, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - - return sampler; - }; - - auto TrashSampler = [](GLuint sampler) { - glSamplerParameteri(sampler, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE); - glSamplerParameteri(sampler, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - - glDeleteSamplers(1, &sampler); - }; - - // Program pipeline setup and trashing - auto SetupPipe = [vsprog, fsprog]() { - GLuint pipe = 0; - glGenProgramPipelines(1, &pipe); - glBindProgramPipeline(pipe); - - glUseProgramStages(pipe, GL_VERTEX_SHADER_BIT, vsprog); - glUseProgramStages(pipe, GL_FRAGMENT_SHADER_BIT, fsprog); - - return pipe; - }; - - auto TrashPipe = [](GLuint pipe) { - glUseProgramStages(pipe, GL_VERTEX_SHADER_BIT, 0); - glUseProgramStages(pipe, GL_FRAGMENT_SHADER_BIT, 0); - - glDeleteProgramPipelines(1, &pipe); - }; - - auto SetupFBO = [offscreen]() { - GLuint fbo = 0; - glGenFramebuffers(1, &fbo); - glBindFramebuffer(GL_FRAMEBUFFER, fbo); - - glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, offscreen, 0); - GLenum col0 = GL_COLOR_ATTACHMENT0; - glDrawBuffers(1, &col0); - - return fbo; - }; - - auto TrashFBO = [](GLuint fbo) { - glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, 0, 0); - - GLenum col0 = GL_NONE; - glDrawBuffers(1, &col0); - - glDeleteFramebuffers(1, &fbo); - }; - - auto SetupTex = []() { - const uint32_t checker[4 * 4] = { - // X X O O - 0xffffffff, 0xffffffff, 0, 0, - // X X O O - 0xffffffff, 0xffffffff, 0, 0, - // O O X X - 0, 0, 0xffffffff, 0xffffffff, - // O O X X - 0, 0, 0xffffffff, 0xffffffff, - }; - - GLuint tex = 0; - glGenTextures(1, &tex); - glBindTexture(GL_TEXTURE_2D, tex); - glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 4, 4); - glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 4, 4, GL_RGBA, GL_UNSIGNED_BYTE, checker); - - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_R, GL_REPEAT); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); - - return tex; - }; - - auto TrashTex = [](GLuint tex) { - const uint32_t empty[4 * 4] = {}; - glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 4, 4, GL_RGBA, GL_UNSIGNED_BYTE, empty); - - glDeleteTextures(1, &tex); - }; - - auto SetupBuf = []() { - const float empty = {}; - const Vec4f flags = {1.0f, 2.0f, 4.0f, 8.0f}; - - GLuint buf = 0; - glGenBuffers(1, &buf); - glBindBuffer(GL_UNIFORM_BUFFER, buf); - glBufferData(GL_UNIFORM_BUFFER, sizeof(empty), &empty, GL_STATIC_DRAW); - - glBufferData(GL_UNIFORM_BUFFER, sizeof(flags), &flags, GL_STATIC_DRAW); - - glBindBufferBase(GL_UNIFORM_BUFFER, 0, buf); - - return buf; - }; - - auto TrashBuf = [](GLuint buf) { - const float empty = {}; - glBufferData(GL_UNIFORM_BUFFER, sizeof(empty), &empty, GL_STATIC_DRAW); - - glDeleteBuffers(1, &buf); - }; - - glUseProgram(0); - glViewport(0, 0, 128, 128); - - GLuint fbo = SetupFBO(); - GLuint vao = SetupVAO(); - GLuint sampler = SetupSampler(); - GLuint pipe = SetupPipe(); - GLuint tex = SetupTex(); - GLuint buf = SetupBuf(); while(Running()) { float col[] = {0.4f, 0.5f, 0.6f, 1.0f}; - glClearNamedFramebufferfv(0, GL_COLOR, 0, col); + glClearBufferfv(GL_COLOR, 0, col); - // render with last frame's resources - float col1[] = {0.5f, 0.1f, 0.1f, 1.0f}; - glClearBufferfv(GL_COLOR, 0, col1); + glBindVertexArray(vao); - glDrawElements(GL_TRIANGLES, 3, GL_UNSIGNED_SHORT, NULL); - glBlitNamedFramebuffer(fbo, 0, 0, 0, 128, 128, 0, 0, 128, 128, GL_COLOR_BUFFER_BIT, GL_NEAREST); + glUseProgram(program); - // trash last frame's resources - TrashFBO(fbo); - TrashVAO(vao); - TrashSampler(sampler); - TrashPipe(pipe); - TrashTex(tex); - TrashBuf(buf); + glViewport(0, 0, GLsizei(screenWidth), GLsizei(screenHeight)); - // create resources mid-frame and use then trash them - fbo = SetupFBO(); - vao = SetupVAO(); - sampler = SetupSampler(); - pipe = SetupPipe(); - tex = SetupTex(); - buf = SetupBuf(); - float col2[] = {0.1f, 0.1f, 0.5f, 1.0f}; - glClearBufferfv(GL_COLOR, 0, col2); - - glDrawElements(GL_TRIANGLES, 3, GL_UNSIGNED_SHORT, NULL); - glBlitNamedFramebuffer(fbo, 0, 0, 0, 128, 128, 128, 0, 256, 128, GL_COLOR_BUFFER_BIT, - GL_NEAREST); - TrashFBO(fbo); - TrashVAO(vao); - TrashSampler(sampler); - TrashPipe(pipe); - TrashTex(tex); - TrashBuf(buf); - - // set up resources for next frame - fbo = SetupFBO(); - vao = SetupVAO(); - sampler = SetupSampler(); - pipe = SetupPipe(); - tex = SetupTex(); - buf = SetupBuf(); + glDrawArrays(GL_TRIANGLES, 0, 3); Present(); } - // destroy resources - TrashFBO(fbo); - TrashVAO(vao); - TrashSampler(sampler); - TrashPipe(pipe); - TrashBuf(buf); - return 0; } };