bool render() { glm::vec2 WindowSize(this->getWindowSize()); glClearBufferfv(GL_COLOR, 0, &glm::vec4(1.0f, 0.5f, 0.0f, 1.0f)[0]); { glBindBuffer(GL_UNIFORM_BUFFER, BufferName[buffer::TRANSFORM]); glm::mat4* Pointer = (glm::mat4*)glMapBufferRange( GL_UNIFORM_BUFFER, 0, sizeof(glm::mat4), GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT); glm::mat4 Projection = glm::ortho(0.f, 256.f, 0.f, 256.f, 0.f, 16.f); glm::mat4 Model = glm::mat4(1.0f); *Pointer = Projection * this->view() * Model; // Make sure the uniform buffer is uploaded glUnmapBuffer(GL_UNIFORM_BUFFER); } glBindBufferBase(GL_UNIFORM_BUFFER, semantic::uniform::TRANSFORM0, BufferName[buffer::TRANSFORM]); glBindVertexArray(VertexArrayName); glActiveTexture(GL_TEXTURE0); glBindProgramPipeline(PipelineName[program::UINT]); { glViewportIndexedfv(0, &glm::vec4(Viewport[texture::RGBA8UI])[0]); glBindTexture(GL_TEXTURE_2D, TextureName[texture::RGBA8UI]); glDrawElementsInstancedBaseVertexBaseInstance(GL_TRIANGLES, ElementCount, GL_UNSIGNED_SHORT, 0, 1, 0, 0); } glBindProgramPipeline(PipelineName[program::NORM]); { glViewportIndexedfv(0, &glm::vec4(Viewport[texture::RGBA32F])[0]); glBindTexture(GL_TEXTURE_2D, TextureName[texture::RGBA32F]); glDrawElementsInstancedBaseVertexBaseInstance(GL_TRIANGLES, ElementCount, GL_UNSIGNED_SHORT, 0, 1, 0, 0); glViewportIndexedfv(0, &glm::vec4(Viewport[texture::RGBA8])[0]); glBindTexture(GL_TEXTURE_2D, TextureName[texture::RGBA8]); glDrawElementsInstancedBaseVertexBaseInstance(GL_TRIANGLES, ElementCount, GL_UNSIGNED_SHORT, 0, 1, 0, 0); glViewportIndexedfv(0, &glm::vec4(Viewport[texture::RGBA8_SNORM])[0]); glBindTexture(GL_TEXTURE_2D, TextureName[texture::RGBA8_SNORM]); glDrawElementsInstancedBaseVertexBaseInstance(GL_TRIANGLES, ElementCount, GL_UNSIGNED_SHORT, 0, 1, 0, 0); } return true; }
bool render() { glm::vec2 WindowSize(this->getWindowSize()); glm::mat4 Projection = glm::ortho(-1.0f, 1.0f, 1.0f,-1.0f, 1.0f, -1.0f); glm::mat4 View = glm::mat4(1.0f); glm::mat4 Model = glm::mat4(1.0f); glm::mat4 MVP = Projection * View * Model; glProgramUniformMatrix4fv(ProgramName[LAYERING], UniformMVP[LAYERING], 1, GL_FALSE, &MVP[0][0]); glProgramUniformMatrix4fv(ProgramName[VIEWPORT], UniformMVP[VIEWPORT], 1, GL_FALSE, &MVP[0][0]); glProgramUniform1i(ProgramName[VIEWPORT], UniformDiffuse, 0); // Pass 1 { glBindFramebuffer(GL_FRAMEBUFFER, FramebufferName); glViewportIndexedfv(0, &glm::vec4(0, 0, FRAMEBUFFER_SIZE)[0]); glUseProgram(ProgramName[LAYERING]); glBindVertexArray(VertexArrayName[LAYERING]); glDrawElementsInstancedBaseVertex(GL_TRIANGLES, ElementCount, GL_UNSIGNED_SHORT, NULL, 1, 0); } // Pass 2 { GLint Border = 2; glBindFramebuffer(GL_FRAMEBUFFER, 0); glClearBufferfv(GL_COLOR, 0, &glm::vec4(0)[0]); glViewportIndexedfv(0, &glm::vec4(Border, Border, WindowSize * 0.5f - 2.0f * Border)[0]); glViewportIndexedfv(1, &glm::vec4((WindowSize.x * 0.5f) + Border, Border, WindowSize * 0.5f - 2.0f * Border)[0]); glViewportIndexedfv(2, &glm::vec4((WindowSize.x * 0.5f) + Border, (WindowSize.y * 0.5f) + 1, WindowSize * 0.5f - 2.0f * Border)[0]); glViewportIndexedfv(3, &glm::vec4(Border, (WindowSize.y * 0.5f) + Border, WindowSize * 0.5f - 2.0f * Border)[0]); glUseProgram(ProgramName[VIEWPORT]); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D_ARRAY, TextureColorbufferName); glBindSampler(0, SamplerName); glBindVertexArray(VertexArrayName[VIEWPORT]); glDrawElementsInstancedBaseVertex(GL_TRIANGLES, ElementCount, GL_UNSIGNED_SHORT, nullptr, 1, 0); } return true; }
bool render() { glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); glm::vec2 WindowSize(this->getWindowSize()); { glBindBuffer(GL_UNIFORM_BUFFER, BufferName[buffer::TRANSFORM]); glm::mat4* Pointer = (glm::mat4*)glMapBufferRange( GL_UNIFORM_BUFFER, 0, sizeof(glm::mat4), GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT); glm::mat4 Projection = glm::perspective(glm::pi<float>() * 0.25f, WindowSize.x / WindowSize.y, 0.1f, 100.0f); *Pointer = Projection * this->view() * glm::mat4(1.0f); // Make sure the uniform buffer is uploaded glUnmapBuffer(GL_UNIFORM_BUFFER); } glViewportIndexedfv(0, &glm::vec4(0, 0, WindowSize)[0]); glClearBufferfv(GL_COLOR, 0, &glm::vec4(0.0f)[0]); glBindProgramPipeline(PipelineName); glBindBufferBase(GL_UNIFORM_BUFFER, semantic::uniform::TRANSFORM0, BufferName[buffer::TRANSFORM]); glBindVertexArray(VertexArrayName); glPatchParameteri(GL_PATCH_VERTICES, VertexCount); assert(!validate(ProgramName[program::VERT])); glDrawArraysInstancedBaseInstance(GL_PATCHES, 0, VertexCount, 1, 0); return true; }
void display() { { // Compute the MVP (Model View Projection matrix) glm::mat4 Projection = glm::perspective(45.0f, 4.0f / 3.0f, 0.1f, 100.0f); glm::mat4 ViewTranslate = glm::translate(glm::mat4(1.0f), glm::vec3(0.0f, 0.0f, -Window.TranlationCurrent.y)); glm::mat4 ViewRotateX = glm::rotate(ViewTranslate, Window.RotationCurrent.y, glm::vec3(1.f, 0.f, 0.f)); glm::mat4 View = glm::rotate(ViewRotateX, Window.RotationCurrent.x, glm::vec3(0.f, 1.f, 0.f)); glm::mat4 Model = glm::mat4(1.0f); glm::mat4 MVP = Projection * View * Model; glBindBuffer(GL_UNIFORM_BUFFER, BufferName[buffer::TRANSFORM]); glm::mat4* Pointer = (glm::mat4*)glMapBufferRange(GL_UNIFORM_BUFFER, 0, sizeof(MVP), GL_MAP_WRITE_BIT); *Pointer = MVP; glUnmapBuffer(GL_UNIFORM_BUFFER); } glViewportIndexedfv(0, &glm::vec4(0, 0, Window.Size.x, Window.Size.y)[0]); glClearBufferfv(GL_COLOR, 0, &glm::vec4(1.0f, 0.5f, 0.0f, 1.0f)[0]); glBindProgramPipeline(PipelineName); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, Texture2DName); glBindBufferBase(GL_UNIFORM_BUFFER, glf::semantic::uniform::TRANSFORM0, BufferName[buffer::TRANSFORM]); glBindVertexArray(VertexArrayName); glBufferAddressRangeNV(GL_VERTEX_ATTRIB_ARRAY_ADDRESS_NV, glf::semantic::attr::POSITION, Address, VertexSize); glBufferAddressRangeNV(GL_VERTEX_ATTRIB_ARRAY_ADDRESS_NV, glf::semantic::attr::TEXCOORD, Address + sizeof(glm::vec2), VertexSize - sizeof(glm::vec2)); glDrawArraysInstancedBaseInstance(GL_TRIANGLES, 0, VertexCount, 1, 0); glf::swapBuffers(); }
void renderFB(GLuint Texture2DName) { glm::mat4 Perspective = glm::perspective(45.0f, float(Window.Size.x) / Window.Size.y, 0.1f, 100.0f); glm::mat4 ViewTranslate = glm::translate(glm::mat4(1.0f), glm::vec3(0.0f, 0.0f, -Window.TranlationCurrent.y * 2.0)); glm::mat4 ViewRotateX = glm::rotate(ViewTranslate, Window.RotationCurrent.y, glm::vec3(1.f, 0.f, 0.f)); glm::mat4 View = glm::rotate(ViewRotateX, Window.RotationCurrent.x, glm::vec3(0.f, 1.f, 0.f)); glm::mat4 Model = glm::mat4(1.0f); glm::mat4 MVP = Perspective * View * Model; glProgramUniformMatrix4fv(ProgramName[program::VERTEX], UniformMVP, 1, GL_FALSE, &MVP[0][0]); glViewportIndexedfv(0, &glm::vec4(0, 0, Window.Size.x, Window.Size.y)[0]); glBindFramebuffer(GL_FRAMEBUFFER, 0); glClearBufferfv(GL_COLOR, 0, &glm::vec4(0.0f, 0.0f, 0.0f, 1.0f)[0]); glBindMultiTextureEXT(GL_TEXTURE0, GL_TEXTURE_2D, Texture2DName); glBindSampler(0, SamplerName); glBindVertexArray(VertexArrayName); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, BufferName[buffer::ELEMENT]); glDrawElementsInstancedBaseVertex(GL_TRIANGLES, ElementCount, GL_UNSIGNED_SHORT, NULL, 1, 0); glf::checkError("renderFB"); }
bool render() { glm::vec2 WindowSize(this->getWindowSize()); glm::mat4 Projection = glm::perspective(glm::pi<float>() * 0.25f, 4.0f / 3.0f, 0.1f, 100.0f); glm::mat4 Model = glm::mat4(1.0f); glm::mat4 MVP = Projection * this->view() * Model; glProgramUniformMatrix4fv(ProgramName[program::VERT], UniformMVP, 1, GL_FALSE, &MVP[0][0]); glProgramUniform1i(ProgramName[program::FRAG], UniformDiffuse, 0); glViewportIndexedfv(0, &glm::vec4(0, 0, WindowSize.x, WindowSize.y)[0]); glClearBufferfv(GL_COLOR, 0, &glm::vec4(0.0f)[0]); glBindProgramPipeline(PipelineName); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, Texture2DName); glBindVertexArray(VertexArrayName); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, BufferName[buffer::ELEMENT]); //!\ Need to be called after glBindVertexArray glDrawElementsInstancedBaseVertex(GL_TRIANGLES, ElementCount, GL_UNSIGNED_INT, nullptr, 1, 0); return true; }
void display() { glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); glm::mat4 Projection = glm::perspective(45.0f, 4.0f / 3.0f, 0.1f, 100.0f); glm::mat4 ViewTranslate = glm::translate(glm::mat4(1.0f), glm::vec3(0.0f, 0.0f, -Window.TranlationCurrent.y)); glm::mat4 ViewRotateX = glm::rotate(ViewTranslate, Window.RotationCurrent.y, glm::vec3(1.f, 0.f, 0.f)); glm::mat4 View = glm::rotate(ViewRotateX, Window.RotationCurrent.x, glm::vec3(0.f, 1.f, 0.f)); glm::mat4 Model = glm::mat4(1.0f); glm::mat4 MVP = Projection * View * Model; glProgramUniformMatrix4fv(ProgramName[program::VERT], UniformMVP, 1, GL_FALSE, &MVP[0][0]); glViewportIndexedfv(0, &glm::vec4(0, 0, Window.Size)[0]); glClearBufferfv(GL_COLOR, 0, &glm::vec4(0.0f)[0]); glBindProgramPipeline(PipelineName); glBindVertexArray(VertexArrayName); glPatchParameteri(GL_PATCH_VERTICES, VertexCount); glDrawArraysInstanced(GL_PATCHES, 0, VertexCount, 1); glf::checkError("display"); glf::swapBuffers(); }
void display() { // Compute the MVP (Model View Projection matrix) glm::mat4 Projection = glm::perspective(45.0f, 4.0f / 3.0f, 0.1f, 100.0f); glm::mat4 ViewTranslate = glm::translate(glm::mat4(1.0f), glm::vec3(0.0f, 0.0f, -Window.TranlationCurrent.y)); glm::mat4 ViewRotateX = glm::rotate(ViewTranslate, Window.RotationCurrent.y, glm::vec3(1.f, 0.f, 0.f)); glm::mat4 View = glm::rotate(ViewRotateX, Window.RotationCurrent.x, glm::vec3(0.f, 1.f, 0.f)); glm::mat4 Model = glm::mat4(1.0f); glm::mat4 MVP = Projection * View * Model; // Set the value of uniforms glProgramUniformMatrix4fv(ProgramName[program::VERT], UniformMVP, 1, GL_FALSE, &MVP[0][0]); glProgramUniform4fv(ProgramName[program::FRAG], UniformDiffuse, 1, &glm::vec4(1.0f, 0.5f, 0.0f, 1.0f)[0]); // Set the display viewport glViewportIndexedfv(0, &glm::vec4(0, 0, Window.Size.x, Window.Size.y)[0]); // Clear color buffer with white float Depth(1.0f); glClearBufferfv(GL_DEPTH, 0, &Depth); glClearBufferfv(GL_COLOR, 0, &glm::vec4(1.0f)[0]); // Bind program glBindProgramPipeline(PipelineName); // Bind vertex array & draw glBindVertexArray(VertexArrayName); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, BufferName[buffer::ELEMENT]); // Must be called after glBindVertexArray glDrawElementsInstancedBaseVertex(GL_TRIANGLES, ElementCount, GL_UNSIGNED_SHORT, NULL, 1, 0); glf::checkError("display"); glf::swapBuffers(); }
bool render() { glm::vec2 WindowSize(this->getWindowSize()); glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); glm::mat4 Projection = glm::perspective(glm::pi<float>() * 0.25f, WindowSize.x / WindowSize.y, 0.1f, 100.0f); glm::mat4 Model = glm::mat4(1.0f); glm::mat4 MVP = Projection * this->view() * Model; glProgramUniformMatrix4fv(ProgramName[program::VERT], UniformMVP, 1, GL_FALSE, &MVP[0][0]); glViewportIndexedfv(0, &glm::vec4(0, 0, WindowSize)[0]); glClearBufferfv(GL_COLOR, 0, &glm::vec4(0.0f)[0]); glBindProgramPipeline(PipelineName); glBindVertexArray(VertexArrayName); glPatchParameteri(GL_PATCH_VERTICES, VertexCount); assert(!validate(ProgramName[program::VERT])); glDrawArraysInstancedBaseInstance(GL_PATCHES, 0, VertexCount, 1, 0); return true; }
bool begin() { bool Success(true); // Validate OpenGL support Success = Success && glf::checkGLVersion(SAMPLE_MAJOR_VERSION, SAMPLE_MINOR_VERSION); Success = Success && glf::checkExtension("GL_ARB_multi_draw_indirect"); // Create and initialize objects if(Success && glf::checkExtension("GL_ARB_debug_output")) Success = initDebugOutput(); if(Success) Success = initProgram(); if(Success) Success = initBuffer(); if(Success) Success = initVertexArray(); if(Success) Success = initTexture(); // Set initial rendering states glEnable(GL_DEPTH_TEST); glViewportIndexedfv(0, &glm::vec4(0, 0, Window.Size.x, Window.Size.y)[0]); glBindProgramPipeline(PipelineName); glBindVertexArray(VertexArrayName); glBindBufferBase(GL_UNIFORM_BUFFER, glf::semantic::uniform::TRANSFORM0, BufferName[buffer::TRANSFORM]); glBindBufferBase(GL_UNIFORM_BUFFER, glf::semantic::uniform::INDIRECTION, BufferName[buffer::VERTEX_INDIRECTION]); glProvokingVertex(GL_FIRST_VERTEX_CONVENTION); return Success; }
void display() { // Compute the MVP (Model View Projection matrix) glm::mat4 Projection = glm::perspective(45.0f, 4.0f / 3.0f, 0.1f, 100.0f); glm::mat4 ViewTranslateZ = glm::translate(glm::mat4(1.0), glm::vec3(0.0f, 0.0f, -Window.TranlationCurrent.y)); glm::mat4 ViewRotateX = glm::rotate(ViewTranslateZ, float(Window.RotationCurrent.y), glm::vec3(1.f, 0.f, 0.f)); glm::mat4 ViewRotateY = glm::rotate(ViewRotateX, float(Window.RotationCurrent.x), glm::vec3(0.f, 1.f, 0.f)); glm::mat4 View = ViewRotateY; glm::mat4 Model = glm::mat4(1.0f); glm::mat4 MVP = Projection * View * Model; glProgramUniformMatrix4fv(ProgramName[program::VERT], UniformMVP, 1, GL_FALSE, &MVP[0][0]); glProgramUniform1i(ProgramName[program::FRAG], UniformDiffuse, 0); glViewportIndexedfv(0, &glm::vec4(0, 0, Window.Size.x, Window.Size.y)[0]); glClearBufferfv(GL_COLOR, 0, &glm::vec4(0.0f)[0]); glBindProgramPipeline(PipelineName); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, Texture2DName); glBindVertexArray(VertexArrayName); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, BufferName[buffer::ELEMENT]); //!\ Need to be called after glBindVertexArray glDrawElementsInstancedBaseVertex(GL_TRIANGLES, ElementCount, GL_UNSIGNED_INT, NULL, 1, 0); glf::checkError("display"); glf::swapBuffers(); }
bool render() { glm::vec2 WindowSize(this->getWindowSize()); { glm::mat4 Model = glm::mat4(1.0f); glm::mat4 Projection = glm::perspective(glm::pi<float>() * 0.25f, WindowSize.x / WindowSize.y, 0.1f, 100.0f); glm::mat4 MVP = Projection * this->view() * Model; glBindBuffer(GL_UNIFORM_BUFFER, BufferName[buffer::TRANSFORM]); glm::mat4* Pointer = (glm::mat4*)glMapBufferRange(GL_UNIFORM_BUFFER, 0, sizeof(MVP), GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT); *Pointer = MVP; glUnmapBuffer(GL_UNIFORM_BUFFER); } glViewportIndexedfv(0, &glm::vec4(0, 0, WindowSize.x, WindowSize.y)[0]); glClearBufferfv(GL_COLOR, 0, &glm::vec4(1.0f, 0.5f, 0.0f, 1.0f)[0]); glBindProgramPipeline(PipelineName); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, TextureName[texture::COPY]); glBindBufferBase(GL_UNIFORM_BUFFER, semantic::uniform::TRANSFORM0, BufferName[buffer::TRANSFORM]); glBindVertexArray(VertexArrayName); glDrawArraysInstancedBaseInstance(GL_TRIANGLES, 0, VertexCount, 1, 0); return true; }
static bool generate_fb(const struct grid_info grid, unsigned idx) { if (!fb[idx]) { glGenFramebuffers(1, &fb[idx]); glGenRenderbuffers(1, &cb[idx]); glGenRenderbuffers(1, &zb[idx]); } glBindFramebuffer(GL_FRAMEBUFFER, fb[idx]); glBindRenderbuffer(GL_RENDERBUFFER, cb[idx]); glRenderbufferStorage(GL_RENDERBUFFER, grid.format->format, grid.size.x, grid.size.y); glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, cb[idx]); glBindRenderbuffer(GL_RENDERBUFFER, zb[idx]); glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT32F, grid.size.x, grid.size.y); glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, zb[idx]); vp[idx][0] = 0; vp[idx][1] = 0; vp[idx][2] = grid.size.x; vp[idx][3] = grid.size.y; glViewportIndexedfv(0, vp[idx]); return piglit_check_gl_error(GL_NO_ERROR); }
void display() { glm::dmat4 Projection = glm::perspective(45.0, 4.0 / 3.0, 0.1, 100.0); glm::dmat4 ViewTranslateZ = glm::translate(glm::dmat4(1.0), glm::dvec3(0.0f, 0.0f, -Window.TranlationCurrent.y)); glm::dmat4 ViewRotateX = glm::rotate(ViewTranslateZ, double(Window.RotationCurrent.y), glm::dvec3(1.f, 0.f, 0.f)); glm::dmat4 ViewRotateY = glm::rotate(ViewRotateX, double(Window.RotationCurrent.x), glm::dvec3(0.f, 1.f, 0.f)); glm::dmat4 View = ViewRotateY; glm::dmat4 Model = glm::dmat4(1.0f); glm::dmat4 MVP = Projection * View * Model; glProgramUniformMatrix4dv(ProgramName[program::VERT], UniformMVP, 1, GL_FALSE, &MVP[0][0]); glProgramUniform4dv(ProgramName[program::FRAG], UniformDiffuse, 1, &glm::dvec4(1.0f, 0.5f, 0.0f, 1.0f)[0]); glViewportIndexedfv(0, &glm::vec4(0, 0, Window.Size.x, Window.Size.y)[0]); glClearBufferfv(GL_COLOR, 0, &glm::vec4(0.0f)[0]); glBindProgramPipeline(PipelineName); glBindVertexArray(VertexArrayName); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, BufferName[buffer::ELEMENT]); glDrawElementsInstancedBaseVertex(GL_TRIANGLES, ElementCount, GL_UNSIGNED_SHORT, NULL, 1, 0); glf::checkError("display"); glf::swapBuffers(); }
bool render() { glm::vec2 WindowSize(this->getWindowSize()); // Compute the MVP (Model View Projection matrix) glm::mat4 Projection = glm::perspective(glm::pi<float>() * 0.25f, WindowSize.x / WindowSize.y, 0.1f, 100.0f); glm::mat4 Model = glm::mat4(1.0f); glm::mat4 MVP = Projection * this->view() * Model; // Set the value of uniforms glProgramUniformMatrix4fv(ProgramName[program::VERT], UniformMVP, 1, GL_FALSE, &MVP[0][0]); glProgramUniform4fv(ProgramName[program::FRAG], UniformDiffuse, 1, &glm::vec4(1.0f, 0.5f, 0.0f, 1.0f)[0]); // Set the display viewport glViewportIndexedfv(0, &glm::vec4(0, 0, WindowSize.x, WindowSize.y)[0]); // Clear color buffer with white float Depth(1.0f); glClearBufferfv(GL_DEPTH, 0, &Depth); glClearBufferfv(GL_COLOR, 0, &glm::vec4(1.0f)[0]); // Bind program glBindProgramPipeline(PipelineName); // Bind vertex array & draw glBindVertexArray(VertexArrayName); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, BufferName[buffer::ELEMENT]); // Must be called after glBindVertexArray glDrawElementsInstancedBaseVertex(GL_TRIANGLES, ElementCount, GL_UNSIGNED_SHORT, nullptr, 1, 0); return true; }
bool render() { glBindFramebuffer(GL_FRAMEBUFFER, 0); glClearBufferfv(GL_COLOR, 0, &glm::vec4(1.0f, 0.5f, 0.0f, 1.0f)[0]); glBindProgramPipeline(PipelineName); // Pass 1, render the scene in a multisampled framebuffer glEnable(GL_MULTISAMPLE); glEnable(GL_SAMPLE_SHADING); glMinSampleShading(4.0f); //glEnable(GL_SAMPLE_MASK); //glSampleMaski(0, 0xFF); renderFBO(); glDisable(GL_MULTISAMPLE); // Resolved multisampling glBindFramebuffer(GL_READ_FRAMEBUFFER, FramebufferRenderName); glBindFramebuffer(GL_DRAW_FRAMEBUFFER, FramebufferResolveName); glBlitFramebuffer( 0, 0, FRAMEBUFFER_SIZE.x, FRAMEBUFFER_SIZE.y, 0, 0, FRAMEBUFFER_SIZE.x, FRAMEBUFFER_SIZE.y, GL_COLOR_BUFFER_BIT, GL_NEAREST); glBindFramebuffer(GL_FRAMEBUFFER, 0); // Pass 2, render the colorbuffer from the multisampled framebuffer glm::vec2 WindowSize(this->getWindowSize()); glViewportIndexedfv(0, &glm::vec4(0, 0, WindowSize)[0]); renderFB(); return true; }
bool testDrawArrays::render() { glm::vec2 const WindowSize(this->getWindowSize()); float Depth(1.0f); glClearBufferfv(GL_DEPTH, 0, &Depth); glClearBufferfv(GL_COLOR, 0, &glm::vec4(1.0f)[0]); { glBindBuffer(GL_UNIFORM_BUFFER, this->BufferName[buffer::BUFFER_FRAME]); glm::mat4* Pointer = reinterpret_cast<glm::mat4*>(glMapBufferRange(GL_UNIFORM_BUFFER, 0, sizeof(glm::mat4), GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT)); glm::mat4 Projection = glm::perspective(glm::pi<float>() * 0.25f, WindowSize.x / WindowSize.y, 0.1f, 1000.0f); glm::mat4 View = this->view(); glm::mat4 Model = glm::mat4(1.0f); glm::mat4 MVP = Projection * View * Model; *Pointer = Projection * View * Model; glUnmapBuffer(GL_UNIFORM_BUFFER); } glViewportIndexedfv(0, &glm::vec4(0, 0, WindowSize)[0]); this->beginTimer(); switch(this->DrawType) { case INSTANCED: glDrawArraysInstancedBaseInstance(GL_TRIANGLES, 0, VertexCount, static_cast<GLsizei>(DrawCount), 0); break; case MULTI_DISCARD: case MULTI_DRAW: for(int i = 0; i < 2; ++i) glMultiDrawArraysIndirect(GL_TRIANGLES, 0, static_cast<GLsizei>(DrawCount / 2), 0); break; case DRAW_PACKED: for(std::size_t DrawIndex(0); DrawIndex < DrawCount; ++DrawIndex) { if(this->UniformUpdate != testDrawArrays::CONSTANT_UNIFORM && this->UniformUpdate != testDrawArrays::NO_UNIFORM) ::updateUniform(this->ProgramName, DrawIndex, this->UniformUpdate); glDrawArrays(GL_TRIANGLES, static_cast<GLint>(this->VertexDataType == SEPARATED_VERTEX_DATA ? VertexCount * DrawIndex : 0), VertexCount); } break; case DRAW_PARAMS: for(std::size_t DrawIndex(0); DrawIndex < DrawCount; ++DrawIndex) { if(this->UniformUpdate != testDrawArrays::CONSTANT_UNIFORM && this->UniformUpdate != testDrawArrays::NO_UNIFORM) ::updateUniform(this->ProgramName, DrawIndex, this->UniformUpdate); glDrawArraysInstancedBaseInstance(GL_TRIANGLES, static_cast<GLint>(this->VertexDataType == SEPARATED_VERTEX_DATA ? VertexCount * DrawIndex : 0), VertexCount, 1, 0); } break; default: assert(0); break; } this->endTimer(); return true; }
void CascadedShadowMappingRenderer::updateLightProjAndViewports() { // Find a bounding box of whole camera frustum in light view space. nv::vec4f frustumMin(std::numeric_limits<float>::max()); nv::vec4f frustumMax(std::numeric_limits<float>::lowest()); frustumBoundingBoxLightViewSpace(m_nearPlane, m_farPlane, frustumMin, frustumMax); // Update light projection matrix to only cover the area viewable by the camera nv::ortho3D(m_lightProjMatrix, frustumMin.x, frustumMax.x, frustumMin.y, frustumMax.y, 0.0f, frustumMin.z); // Find a bounding box of segment in light view space. float nearSegmentPlane = 0.0f; for (unsigned int i = 0; i < m_frustumSegmentCount; ++i) { nv::vec4f segmentMin(std::numeric_limits<float>::max()); nv::vec4f segmentMax(std::numeric_limits<float>::lowest()); frustumBoundingBoxLightViewSpace(nearSegmentPlane, m_farPlanes[i], segmentMin, segmentMax); // Update viewports. nv::vec2f frustumSize(frustumMax.x - frustumMin.x, frustumMax.y - frustumMin.y); const float segmentSizeX = segmentMax.x - segmentMin.x; const float segmentSizeY = segmentMax.y - segmentMin.y; const float segmentSize = segmentSizeX < segmentSizeY ? segmentSizeY : segmentSizeX; const nv::vec2f offsetBottomLeft(segmentMin.x - frustumMin.x, segmentMin.y - frustumMin.y); const nv::vec2f offsetSegmentSizeRatio(offsetBottomLeft.x / segmentSize, offsetBottomLeft.y / segmentSize); const nv::vec2f frustumSegmentSizeRatio(frustumSize.x / segmentSize, frustumSize.y / segmentSize); nv::vec2f pixelOffsetTopLeft(offsetSegmentSizeRatio * LIGHT_TEXTURE_SIZE); nv::vec2f pixelFrustumSize(frustumSegmentSizeRatio * LIGHT_TEXTURE_SIZE); // Scale factor that helps if frustum size is supposed to be bigger // than maximum viewport size. nv::vec2f scaleFactor( m_viewportDims[0] < pixelFrustumSize.x ? m_viewportDims[0] / pixelFrustumSize.x : 1.0f, m_viewportDims[1] < pixelFrustumSize.y ? m_viewportDims[1] / pixelFrustumSize.y : 1.0f); pixelOffsetTopLeft *= scaleFactor; pixelFrustumSize *= scaleFactor; m_lightViewports[i] = nv::vec4f(-pixelOffsetTopLeft.x, -pixelOffsetTopLeft.y, pixelFrustumSize.x, pixelFrustumSize.y); glViewportIndexedfv(i, m_lightViewports[i]._array); // Update light view-projection matrices per segment. nv::matrix4f lightProj; nv::ortho3D(lightProj, segmentMin.x, segmentMin.x + segmentSize, segmentMin.y, segmentMin.y + segmentSize, 0.0f, frustumMin.z); nv::matrix4f lightScale; lightScale.set_scale(nv::vec3f(0.5f * scaleFactor.x, 0.5f * scaleFactor.y, 0.5f)); nv::matrix4f lightBias; lightBias.set_translate(nv::vec3f(0.5f * scaleFactor.x, 0.5f * scaleFactor.y, 0.5f)); m_lightSegmentVPSBMatrices[i] = lightBias * lightScale * lightProj * m_lightViewMatrix; nearSegmentPlane = m_normalizedFarPlanes[i]; } // Set remaining viewports to some kind of standard state. for (unsigned int i = m_frustumSegmentCount; i < MAX_CAMERA_FRUSTUM_SPLIT_COUNT; ++i) { glViewportIndexedf(i, 0, 0, LIGHT_TEXTURE_SIZE, LIGHT_TEXTURE_SIZE); } }
bool render() { glm::vec2 WindowSize(this->getWindowSize()); glm::mat4 Projection = glm::ortho(-1.0f, 1.0f, 1.0f,-1.0f, 1.0f, -1.0f); glm::mat4 View = glm::mat4(1.0f); glm::mat4 Model = glm::mat4(1.0f); glm::mat4 MVP = Projection * View * Model; glProgramUniformMatrix4fv(ProgramName[LAYERING], UniformMVP[LAYERING], 1, GL_FALSE, &MVP[0][0]); glProgramUniformMatrix4fv(ProgramName[VIEWPORT], UniformMVP[VIEWPORT], 1, GL_FALSE, &MVP[0][0]); // Pass 1 { glBindFramebuffer(GL_FRAMEBUFFER, FramebufferName); // glBindFramebuffer(GL_FRAMEBUFFER, 0); glViewportIndexedfv(0, &glm::vec4(0, 0, FRAMEBUFFER_SIZE)[0]); glBindProgramPipeline(PipelineName[LAYERING]); glBindVertexArray(VertexArrayName[LAYERING]); glDrawArraysInstancedBaseInstance(GL_TRIANGLES, 0, VertexCount, 4, 0); } // Pass 2 { GLint Border = 2; glBindFramebuffer(GL_FRAMEBUFFER, 0); glViewportIndexedfv(0, &glm::vec4(Border, Border, WindowSize * 0.5f - 2.0f * Border)[0]); glViewportIndexedfv(1, &glm::vec4((WindowSize.x * 0.5f) + Border, Border, WindowSize * 0.5f - 2.0f * Border)[0]); glViewportIndexedfv(2, &glm::vec4((WindowSize.x * 0.5f) + Border, (WindowSize.y * 0.5f) + 1, WindowSize * 0.5f - 2.0f * Border)[0]); glViewportIndexedfv(3, &glm::vec4(Border, (WindowSize.y * 0.5f) + Border, WindowSize * 0.5f - 2.0f * Border)[0]); glBindProgramPipeline(PipelineName[VIEWPORT]); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D_ARRAY, TextureColorbufferName); glBindSampler(0, SamplerName); glBindVertexArray(VertexArrayName[VIEWPORT]); glDrawArraysInstancedBaseInstance(GL_TRIANGLES, 0, VertexCount, 4, 0); } return true; }
bool render() { glm::vec2 WindowSize(this->getWindowSize()); { glBindBuffer(GL_UNIFORM_BUFFER, BufferName[buffer::TRANSFORM]); glm::mat4* Pointer = (glm::mat4*)glMapBufferRange( GL_UNIFORM_BUFFER, 0, sizeof(glm::mat4), GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT); glm::mat4 Projection = glm::perspectiveFov(glm::pi<float>() * 0.25f, WindowSize.x, WindowSize.y, 0.1f, 100.0f); glm::mat4 Model = glm::mat4(1.0f); *Pointer = Projection * this->view() * Model; glUnmapBuffer(GL_UNIFORM_BUFFER); } // Clear glBindFramebuffer(GL_FRAMEBUFFER, FramebufferName[framebuffer::CLEAR]); glClearBufferfv(GL_COLOR, 0, &glm::vec4(1.0f, 0.5f, 0.0f, 1.0f)[0]); // Render glViewportIndexedf(0, 0, 0, WindowSize.x * this->Supersampling, WindowSize.y * this->Supersampling); glBindFramebuffer(GL_FRAMEBUFFER, FramebufferName[framebuffer::BLEND]); glBindVertexArray(this->VertexArrayName[pipeline::RENDER]); glBindProgramPipeline(PipelineName[pipeline::RENDER]); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, TextureName[texture::DIFFUSE]); glBindImageTexture(semantic::image::DIFFUSE, TextureName[texture::COLORBUFFER], 0, GL_FALSE, 0, GL_WRITE_ONLY, GL_RGBA8); glBindBufferBase(GL_UNIFORM_BUFFER, semantic::uniform::TRANSFORM0, BufferName[buffer::TRANSFORM]); glBindBufferBase(GL_SHADER_STORAGE_BUFFER, semantic::storage::VERTEX, BufferName[buffer::VERTEX]); for (std::size_t i = 0; i < this->Viewports.size(); ++i) { glViewportIndexedfv(0, &this->Viewports[i][0]); glDrawElementsInstancedBaseVertexBaseInstance(GL_TRIANGLES, ElementCount, GL_UNSIGNED_SHORT, 0, 1, 0, 0); } // Splash glViewportIndexedf(0, 0, 0, WindowSize.x, WindowSize.y); glBindFramebuffer(GL_FRAMEBUFFER, 0); glBindVertexArray(this->VertexArrayName[pipeline::SPLASH]); glBindProgramPipeline(PipelineName[pipeline::SPLASH]); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, TextureName[texture::COLORBUFFER]); glDrawArraysInstancedBaseInstance(GL_TRIANGLES, 0, 3, 1, 0); return true; }
bool render() { glm::vec2 WindowSize(this->getWindowSize()); { glBindBuffer(GL_UNIFORM_BUFFER, BufferName[buffer::TRANSFORM]); glm::mat4* Pointer = (glm::mat4*)glMapBufferRange( GL_UNIFORM_BUFFER, 0, sizeof(glm::mat4), GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT); glm::mat4 Projection = glm::perspective(glm::pi<float>() * 0.25f, WindowSize.x / WindowSize.y, 0.1f, 100.0f); glm::mat4 Model = glm::mat4(1.0f); *Pointer = Projection * this->view() * Model; // Make sure the uniform buffer is uploaded glUnmapBuffer(GL_UNIFORM_BUFFER); } glClearTexImage(TextureName[texture::COLORBUFFER], 0, GL_RGBA, GL_FLOAT, &glm::vec4(1.0f, 0.5f, 0.0f, 1.0f)[0]); glBindFramebuffer(GL_FRAMEBUFFER, FramebufferName); // Bind rendering objects glBindProgramPipeline(PipelineName[pipeline::TEXTURE]); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, TextureName[texture::DIFFUSE]); glActiveTexture(GL_TEXTURE1); glBindTexture(GL_TEXTURE_2D, TextureName[texture::COLORBUFFER]); glBindVertexArray(VertexArrayName[pipeline::TEXTURE]); glBindBufferBase(GL_UNIFORM_BUFFER, semantic::uniform::TRANSFORM0, BufferName[buffer::TRANSFORM]); for (std::size_t i = 0; i < this->Viewports.size(); ++i) { glViewportIndexedfv(0, &this->Viewports[i][0]); glDrawElementsInstancedBaseVertexBaseInstance(GL_TRIANGLES, ElementCount, GL_UNSIGNED_SHORT, 0, 1, 0, 0); glTextureBarrier(); } glBindFramebuffer(GL_FRAMEBUFFER, 0); glViewportIndexedf(0, 0, 0, WindowSize.x, WindowSize.y); glBindProgramPipeline(PipelineName[pipeline::SPLASH]); glActiveTexture(GL_TEXTURE0); glBindVertexArray(VertexArrayName[pipeline::SPLASH]); glBindTexture(GL_TEXTURE_2D, TextureName[texture::COLORBUFFER]); glDrawArraysInstancedBaseInstance(GL_TRIANGLES, 0, 3, 1, 0); return true; }
void testScreenspaceCoherence::render() { float Depth(1.0f); glClearBufferfv(GL_DEPTH, 0, &Depth); glClearBufferfv(GL_COLOR, 0, &glm::vec4(0.0f)[0]); glViewportIndexedfv(0, &glm::vec4(0, 0, this->getWindowSize())[0]); this->beginTimer(); glDrawArraysInstancedBaseInstance(GL_TRIANGLES, 0, this->DrawVertexCount, 1, 0); //glDrawArraysInstancedBaseInstance(GL_TRIANGLES, 0, ::VertexCount, 1, 0); this->endTimer(); }
void display() { glm::mat4 ViewTranslate = glm::translate(glm::mat4(1.0f), glm::vec3(0.0f, 0.0f, -Window.TranlationCurrent.y)); glm::mat4 ViewRotateX = glm::rotate(ViewTranslate, Window.RotationCurrent.y, glm::vec3(1.f, 0.f, 0.f)); glm::mat4 View = glm::rotate(ViewRotateX, Window.RotationCurrent.x, glm::vec3(0.f, 1.f, 0.f)); glm::mat4 Model = glm::mat4(1.0f); glEnable(GL_SCISSOR_TEST); glDisable(GL_FRAMEBUFFER_SRGB); glScissorIndexed(0, 0, 0, Window.Size.x, Window.Size.y); glClearBufferfv(GL_COLOR, 0, &glm::vec4(1.0f, 0.5f, 0.0f, 1.0f)[0]); { glm::mat4 Projection = glm::perspective(45.0f, float(FRAMEBUFFER_SIZE.x) / float(FRAMEBUFFER_SIZE.y), 0.1f, 100.0f); glm::mat4 MVP = Projection * View * Model; glViewportIndexedf(0, 0, 0, float(FRAMEBUFFER_SIZE.x), float(FRAMEBUFFER_SIZE.y)); glDisable(GL_FRAMEBUFFER_SRGB); glBindFramebuffer(GL_FRAMEBUFFER, FramebufferName); glClearBufferfv(GL_COLOR, 0, &glm::vec4(0.0f, 0.0f, 0.0f, 1.0f)[0]); renderScene(glm::vec4(0.0f, 0.0f, 0.0f, 1.0f), MVP, Texture2DName); glBindFramebuffer(GL_FRAMEBUFFER, 0); } { glm::mat4 Projection = glm::perspective(45.0f, float(Window.Size.x) / float(Window.Size.y), 0.1f, 100.0f); glm::mat4 MVP = Projection * View * Model; glViewportIndexedfv(0, &glm::vec4(0, 0, Window.Size.x, Window.Size.y)[0]); // Correct display glScissorIndexed(0, 0, Window.Size.y / 2 - 1, Window.Size.x, Window.Size.y / 2); glEnable(GL_FRAMEBUFFER_SRGB); glSamplerParameteri(SamplerName, GL_TEXTURE_SRGB_DECODE_EXT, GL_SKIP_DECODE_EXT); // GL_DECODE_EXT renderScene(glm::vec4(1.0f, 0.5f, 0.0f, 1.0f), MVP, ColorbufferName); glDisable(GL_FRAMEBUFFER_SRGB); // Incorrected display glScissorIndexed(0, 0, 0, Window.Size.x, Window.Size.y / 2); glEnable(GL_FRAMEBUFFER_SRGB); glSamplerParameteri(SamplerName, GL_TEXTURE_SRGB_DECODE_EXT, GL_DECODE_EXT); // GL_DECODE_EXT renderScene(glm::vec4(1.0f, 0.5f, 0.0f, 1.0f), MVP, ColorbufferName); glDisable(GL_FRAMEBUFFER_SRGB); } glf::swapBuffers(); glf::checkError("display"); }
void renderFBO() { static int SamplesPositionsIndex = 0; ++SamplesPositionsIndex; SamplesPositionsIndex %= 2; { glm::mat4 Perspective = glm::perspective(glm::pi<float>() * 0.25f, float(FRAMEBUFFER_SIZE.x) / FRAMEBUFFER_SIZE.y, 0.1f, 100.0f); glm::mat4 Model = glm::mat4(1.0f); glm::mat4 MVP = Perspective * this->view() * Model; glBindBuffer(GL_UNIFORM_BUFFER, BufferName[buffer::TRANSFORM]); glm::mat4* Pointer = (glm::mat4*)glMapBufferRange(GL_UNIFORM_BUFFER, 0, sizeof(MVP), GL_MAP_WRITE_BIT); *Pointer = MVP; glUnmapBuffer(GL_UNIFORM_BUFFER); } glViewportIndexedfv(0, &glm::vec4(0, 0, FRAMEBUFFER_SIZE.x, FRAMEBUFFER_SIZE.y)[0]); glBindFramebuffer(GL_FRAMEBUFFER, FramebufferRenderName); glm::vec2 SamplesPositions[2][4] = { { glm::vec2(0.75f, 0.25f), glm::vec2(1.00f, 0.75f), glm::vec2(0.25f, 1.00f), glm::vec2(0.00f, 0.25f) }, { glm::vec2(0.25f, 0.25f), glm::vec2(1.00f, 0.25f), glm::vec2(0.75f, 1.00f), glm::vec2(0.00f, 0.75f) } }; glSetMultisamplefvAMD(GL_SAMPLE_POSITION, 0, &SamplesPositions[SamplesPositionsIndex][0][0]); glSetMultisamplefvAMD(GL_SAMPLE_POSITION, 1, &SamplesPositions[SamplesPositionsIndex][1][0]); glSetMultisamplefvAMD(GL_SAMPLE_POSITION, 2, &SamplesPositions[SamplesPositionsIndex][2][0]); glSetMultisamplefvAMD(GL_SAMPLE_POSITION, 3, &SamplesPositions[SamplesPositionsIndex][3][0]); glClearBufferfv(GL_COLOR, 0, &glm::vec4(0.0f, 0.5f, 1.0f, 1.0f)[0]); glBindTextures(0, 1, &TextureName); glBindVertexArray(VertexArrayName); glDrawElementsInstancedBaseVertex(GL_TRIANGLES, ElementCount, GL_UNSIGNED_SHORT, NULL, 1, 0); }
void display() { glm::mat4 Projection = glm::ortho(-1.0f, 1.0f, 1.0f,-1.0f, 1.0f, -1.0f); glm::mat4 View = glm::mat4(1.0f); glm::mat4 Model = glm::mat4(1.0f); glm::mat4 MVP = Projection * View * Model; glProgramUniformMatrix4fv(ProgramName[LAYERING], UniformMVP[LAYERING], 1, GL_FALSE, &MVP[0][0]); glProgramUniformMatrix4fv(ProgramName[IMAGE_2D], UniformMVP[IMAGE_2D], 1, GL_FALSE, &MVP[0][0]); glProgramUniform1i(ProgramName[IMAGE_2D], UniformDiffuse, 0); // Pass 1 { glBindSampler(0, 0); glBindFramebuffer(GL_FRAMEBUFFER, FramebufferName); glViewportIndexedf(0, 0, 0, float(FRAMEBUFFER_SIZE.x), float(FRAMEBUFFER_SIZE.y)); glUseProgram(ProgramName[LAYERING]); glBindVertexArray(VertexArrayName[LAYERING]); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, BufferName[BUFFER_ELEMENT]); glDrawElementsInstancedBaseVertex(GL_TRIANGLES, ElementCount, GL_UNSIGNED_SHORT, NULL, 1, 0); } // Pass 2 { glBindFramebuffer(GL_FRAMEBUFFER, 0); glUseProgram(ProgramName[IMAGE_2D]); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D_ARRAY, TextureColorbufferName); glBindSampler(0, SamplerName); glBindVertexArray(VertexArrayName[IMAGE_2D]); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, BufferName[BUFFER_ELEMENT]); for(int i = 0; i < 4; ++i) { glProgramUniform1i(ProgramName[IMAGE_2D], UniformLayer, i); glViewportIndexedfv(0, &glm::vec4(Viewport[i])[0]); glDrawElementsInstancedBaseVertex(GL_TRIANGLES, ElementCount, GL_UNSIGNED_SHORT, NULL, 1, 0); } } glf::checkError("display"); glf::swapBuffers(); }
void GLFrameBuffer::End() { Unbind(); // Generate mipmap if needed for (size_t i = 0; i < p->renderTargets.size(); i++) { p->renderTargets[i]->Bind(); p->renderTargets[i]->GenerateMipmap(); p->renderTargets[i]->Unbind(); } // Restore glDrawBuffer(GL_BACK_LEFT); glViewportIndexedfv( 0, glm::value_ptr(glm::vec4( (float)p->viewport[0], (float)p->viewport[1], (float)p->viewport[2], (float)p->viewport[3]))); }
void GLFrameBuffer::Begin() { // Save current viewport glGetIntegerv(GL_VIEWPORT, &p->viewport.x); Bind(); // Enable buffers glDrawBuffers((int)p->colorAttachmentList.size(), &p->colorAttachmentList[0]); float depth = 1.0f; glClearBufferfv(GL_DEPTH, 0, &depth); for (int i = 0; i < (int)p->colorAttachmentList.size(); i++) { // Second argument of glClearBufferfv is not GL_COLOR_ATTACHMENTi values // but the buffer index specified by glDrawBuffers // cf. https://www.opengl.org/wiki/Framebuffer#Buffer_clearing glClearBufferfv(GL_COLOR, i, glm::value_ptr(p->clearColor)); } glViewportIndexedfv(0, glm::value_ptr(glm::vec4(0.0f, 0.0f, (float)p->width, (float)p->height))); }
bool render() { glm::dvec2 WindowSize(this->getWindowSize()); glm::dmat4 Projection = glm::perspective(glm::pi<double>() * 0.25, WindowSize.x / WindowSize.y, 0.1, 100.0); glm::dmat4 View(this->view()); glm::dmat4 Model = glm::dmat4(1.0f); glm::dmat4 MVP = Projection * View * Model; glProgramUniformMatrix4dv(ProgramName[program::VERT], UniformMVP, 1, GL_FALSE, &MVP[0][0]); glProgramUniform4dv(ProgramName[program::FRAG], UniformDiffuse, 1, &glm::dvec4(1.0f, 0.5f, 0.0f, 1.0f)[0]); glViewportIndexedfv(0, &glm::vec4(0, 0, WindowSize)[0]); glClearBufferfv(GL_COLOR, 0, &glm::vec4(0.0f)[0]); glBindProgramPipeline(PipelineName); glBindVertexArray(VertexArrayName); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, BufferName[buffer::ELEMENT]); glDrawElementsInstancedBaseVertex(GL_TRIANGLES, ElementCount, GL_UNSIGNED_SHORT, nullptr, 1, 0); return true; }
void display() { glm::mat4 Projection = glm::perspective(45.0f, 4.0f / 3.0f, 0.1f, 100.0f); glm::mat4 ViewTranslate = glm::translate(glm::mat4(1.0f), glm::vec3(0.0f, 0.0f, -Window.TranlationCurrent.y)); glm::mat4 ViewRotateX = glm::rotate(ViewTranslate, Window.RotationCurrent.y, glm::vec3(1.f, 0.f, 0.f)); glm::mat4 View = glm::rotate(ViewRotateX, Window.RotationCurrent.x, glm::vec3(0.f, 1.f, 0.f)); glm::mat4 Model = glm::mat4(1.0f); glm::mat4 MVP = Projection * View * Model; glViewportIndexedfv(0, &glm::vec4(0, 0, Window.Size.x, Window.Size.y)[0]); glClearBufferfv(GL_COLOR, 0, &glm::vec4(0.0f)[0]); glUseProgram(ProgramName); glUniformMatrix4fv(UniformMVP, 1, GL_FALSE, &MVP[0][0]); glUniform4fv(UniformDiffuse, 1, &glm::vec4(1.0f, 0.5f, 0.0f, 1.0f)[0]); glBindVertexArray(VertexArrayName); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ElementBufferName); //!\ Need to be called after glBindVertexArray... glBindBuffer(GL_DRAW_INDIRECT_BUFFER, IndirectBufferName); glMultiDrawElementsIndirectAMD(GL_TRIANGLES, GL_UNSIGNED_INT, 0, 2, sizeof(DrawElementsIndirectCommand)); glf::checkError("display"); glf::swapBuffers(); }
void display() { // Compute the MVP (Model View Projection matrix) glm::mat4 Projection = glm::perspective(45.0f, 4.0f / 3.0f, 0.1f, 100.0f); glm::mat4 ViewTranslate = glm::translate(glm::mat4(1.0f), glm::vec3(0.0f, 0.0f, -Window.TranlationCurrent.y)); glm::mat4 ViewRotateX = glm::rotate(ViewTranslate, Window.RotationCurrent.y, glm::vec3(1.f, 0.f, 0.f)); glm::mat4 View = glm::rotate(ViewRotateX, Window.RotationCurrent.x, glm::vec3(0.f, 1.f, 0.f)); glm::mat4 Model = glm::mat4(1.0f); glm::mat4 MVP = Projection * View * Model; glf::checkError("display 4"); glProgramUniformMatrix4fv(ProgramName[program::VERTEX], UniformMVP, 1, GL_FALSE, &MVP[0][0]); glProgramUniform1i(ProgramName[program::FRAGMENT], UniformDiffuse, 0); glf::checkError("display 5"); glViewportIndexedfv(0, &glm::vec4(0, 0, Window.Size.x, Window.Size.y)[0]); glClearBufferfv(GL_COLOR, 0, &glm::vec4(0.0f, 0.0f, 0.0f, 1.0f)[0]); glf::checkError("display 6"); glBindProgramPipeline(PipelineName); glf::checkError("display 7"); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, Texture2DName); glBindVertexArray(VertexArrayName); glf::checkError("display 8"); glBufferAddressRangeNV(GL_VERTEX_ATTRIB_ARRAY_ADDRESS_NV, glf::semantic::attr::POSITION, Address, VertexSize); glBufferAddressRangeNV(GL_VERTEX_ATTRIB_ARRAY_ADDRESS_NV, glf::semantic::attr::TEXCOORD, Address + sizeof(glm::vec2), VertexSize - sizeof(glm::vec2)); glf::checkError("display 9"); glDrawArraysInstanced(GL_TRIANGLES, 0, VertexCount, 1); glf::checkError("display"); glf::swapBuffers(); }