void MainDeferredRenderer::render()
{
	//printf("Deferred rendering.\n");

	static const GLuint uint_zeros[] = { 0, 0, 0, 0 };
	static const GLfloat float_zeros[] = { 0.0f, 0.0f, 0.0f, 0.0f };
	static const GLfloat float_ones[] = { 1.0f, 1.0f, 1.0f, 1.0f };
	static const GLenum draw_buffers[] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1 };

	glBindFramebuffer(GL_FRAMEBUFFER, gbuffer);
	glViewport(0, 0, 1280, 720); //Menos hardcoded
	glDrawBuffers(2, draw_buffers);
	glClearBufferuiv(GL_COLOR, 0, uint_zeros);
	glClearBufferuiv(GL_COLOR, 1, uint_zeros);
	glClearBufferfv(GL_DEPTH, 0, float_ones);


	GLuint pID = deferred_pass->getProgramID();

	//NOTIFY
	for (int i = 0; i < renderers.size(); i++)
	{
		if (renderers[i]->enabled)
			renderers[i]->deferred_render(pID);
	}

	glBindFramebuffer(GL_FRAMEBUFFER, 0);
	glViewport(0, 0, 1280, 720); //Menos hardcoded
	glDrawBuffer(GL_BACK);


	//2nd pass:
	glActiveTexture(GL_TEXTURE0);
	glBindTexture(GL_TEXTURE_2D, gbuffer_tex[0]);

	glActiveTexture(GL_TEXTURE1);
	glBindTexture(GL_TEXTURE_2D, gbuffer_tex[1]);
	
	GLuint second = second_pass->getProgramID();
	glUseProgram(second);

	glDisable(GL_DEPTH_TEST);

	glBindVertexArray(fs_quad_vao);
	glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);

	glBindTexture(GL_TEXTURE_2D, 0);
	glActiveTexture(GL_TEXTURE0);
	glBindTexture(GL_TEXTURE_2D, 0);
}
void renderFBO(GLuint Framebuffer)
{
	glm::mat4 Perspective = glm::perspective(45.0f, float(FRAMEBUFFER_SIZE.x) / FRAMEBUFFER_SIZE.y, 0.1f, 100.0f);
	glm::mat4 ViewFlip = glm::scale(glm::mat4(1.0f), glm::vec3(1.0f,-1.0f, 1.0f));
	glm::mat4 ViewTranslate = glm::translate(ViewFlip, glm::vec3(0.0f, 0.0f, -Window.TranlationCurrent.y * 2.0));
	glm::mat4 View = glm::rotate(ViewTranslate,-15.f, glm::vec3(0.f, 0.f, 1.f));
	glm::mat4 Model = glm::mat4(1.0f);
	glm::mat4 MVP = Perspective * View * Model;

	glUseProgram(ProgramName[program::RENDER]);
	glUniform1i(UniformDiffuse[program::RENDER], 0);
	glUniformMatrix4fv(UniformMVP[program::RENDER], 1, GL_FALSE, &MVP[0][0]);

	glViewport(0, 0, FRAMEBUFFER_SIZE.x, FRAMEBUFFER_SIZE.y);
	glBindFramebuffer(GL_FRAMEBUFFER, Framebuffer);
	glClearBufferuiv(GL_COLOR, 0, &glm::uvec4(0, 128, 255, 255)[0]);

	glActiveTexture(GL_TEXTURE0);
	glBindTexture(GL_TEXTURE_2D, TextureName[texture::DIFFUSE]);
	glBindVertexArray(VertexArrayName);

	glDrawArraysInstanced(GL_TRIANGLES, 0, VertexCount, 1);

	glf::checkError("renderFBO");
}
Beispiel #3
0
    bool RenderTargetFBO::beginRendering()
    {
      makeCurrent();

      glViewport( m_x, m_y, m_width, m_height );
      
      unsigned int colorBufferMask = m_clearMask & TBM_COLOR_BUFFER_MASK;
      unsigned int i = 0;
      while ( colorBufferMask )
      {
        if ( colorBufferMask & 1 )
        {
          glClearBufferfv(GL_COLOR, i, &m_attachmentsClearColor[ getStereoTargetId( m_stereoTarget ) ][i][0] );
        }
        colorBufferMask >>= 1;
        ++i; 
      }

      if ( m_clearMask & TBM_DEPTH_BUFFER )
      {
        float clearDepth = float(m_clearDepth);
        glClearBufferfv( GL_DEPTH, 0, &clearDepth );
      }

      if ( m_clearMask & TBM_STENCIL_BUFFER )
      {
        glClearBufferuiv( GL_STENCIL, 0, &m_clearStencil );
      }

      return true;
    }
Beispiel #4
0
void kit::PixelBuffer::clearAttachment(uint32_t attachment, glm::uvec4 clearcolor)
{
    this->bind();
  if (attachment >= this->m_colorAttachments.size())
  {
    KIT_THROW("Cant clear attachment, index out of range.");
  }

  GLuint color[4] = { clearcolor.x, clearcolor.y, clearcolor.z, clearcolor.w };
  KIT_GL(glClearBufferuiv(GL_COLOR, attachment, &color[0]));

}
Beispiel #5
0
void TextureData::clear(const GLubyte *const data)
{
    const TextureData::Format *const format = &FORMATS[(int)this->format];
    GLuint buffer[format->size];

    for (int i = 0; i < format->size; i++) {
        buffer[i] = data[i];
    }

    glBindFramebuffer(GL_DRAW_FRAMEBUFFER, framebuffer);
    glClearBufferuiv(GL_COLOR, format->outputBuffer, buffer);
}
	bool render()
	{
		glm::ivec2 WindowSize(this->getWindowSize());

		// Pass 1
		{
			glViewport(0, 0, WindowSize.x / FRAMEBUFFER_SIZE, WindowSize.y / FRAMEBUFFER_SIZE);
			glBindFramebuffer(GL_FRAMEBUFFER, FramebufferName);
			glClearBufferuiv(GL_COLOR, 0, &glm::uvec4(0, 128, 255, 255)[0]);

			glm::mat4 Projection = glm::ortho(-2.0f, 2.0f, 2.0f,-2.0f, 2.0f, -2.0f);
			glm::mat4 View = glm::mat4(1.0f);
			glm::mat4 Model = glm::rotate(glm::mat4(1.0f), -0.3f, glm::vec3(0.f, 0.f, 1.f));
			glm::mat4 MVP = Projection * View * Model;

			glUseProgram(ProgramName[program::RENDER]);
			glUniform1i(UniformDiffuse[program::RENDER], 0);
			glUniformMatrix4fv(UniformMVP[program::RENDER], 1, GL_FALSE, &MVP[0][0]);

			glActiveTexture(GL_TEXTURE0);
			glBindTexture(GL_TEXTURE_2D, TextureName[texture::DIFFUSE]);
			glBindVertexArray(VertexArrayName);

			glDrawArraysInstanced(GL_TRIANGLES, 0, VertexCount, 1);
		}

		// Pass 2
		{
			glm::mat4 Perspective = glm::perspective(glm::pi<float>() * 0.25f, float(WindowSize.x) / WindowSize.y, 0.1f, 100.0f);
			glm::mat4 Model = glm::mat4(1.0f);
			glm::mat4 MVP = Perspective * this->view() * Model;

			glUseProgram(ProgramName[program::SPLASH]);
			glUniform1i(UniformDiffuse[program::SPLASH], 0);
			glUniformMatrix4fv(UniformMVP[program::SPLASH], 1, GL_FALSE, &MVP[0][0]);

			glViewport(0, 0, WindowSize.x, WindowSize.y);
			glBindFramebuffer(GL_FRAMEBUFFER, 0);
			glClearBufferfv(GL_COLOR, 0, &glm::vec4(1.0f, 0.5f, 0.0f, 1.0f)[0]);

			glActiveTexture(GL_TEXTURE0);
			glBindTexture(GL_TEXTURE_2D, TextureName[texture::RENDERBUFFER]);
			glBindVertexArray(VertexArrayName);

			glDrawArraysInstanced(GL_TRIANGLES, 0, VertexCount, 1);
		}

		return this->checkError("render");;
	}
Beispiel #7
0
void Framebuffer::clearBufferuiv(const GLenum buffer, const GLint drawBuffer, const GLuint * value)
{
    bind();

    glClearBufferuiv(buffer, drawBuffer, value);
}
	bool render()
	{
		glm::ivec2 WindowSize(this->getWindowSize());

		// Pass 1
		{
			glViewport(0, 0,
				WindowSize.x / FRAMEBUFFER_SIZE,
				WindowSize.y / FRAMEBUFFER_SIZE);
			glBindFramebuffer(GL_FRAMEBUFFER, FramebufferName[framebuffer::RENDER]);
			glClearBufferuiv(GL_COLOR, 0, &glm::uvec4(0, 128, 255, 255)[0]);

			glm::mat4 Perspective = glm::perspective(glm::pi<float>() * 0.25f, float(WindowSize.x) / WindowSize.y, 0.1f, 100.0f);
			glm::mat4 ViewFlip = glm::scale(glm::mat4(1.0f), glm::vec3(1.0f, 1.0f, 1.0f));
			glm::mat4 ViewTranslate = glm::translate(ViewFlip, glm::vec3(0.0f, 0.0f, -this->cameraDistance() * 2.0f));
			glm::mat4 View = glm::rotate(ViewTranslate,-15.f, glm::vec3(0.f, 0.f, 1.f));
			glm::mat4 Model = glm::mat4(1.0f);
			glm::mat4 MVP = Perspective * View * Model;

			glUseProgram(ProgramName[program::RENDER]);
			glUniform1i(UniformDiffuse[program::RENDER], 0);
			glUniformMatrix4fv(UniformMVP[program::RENDER], 1, GL_FALSE, &MVP[0][0]);

			glActiveTexture(GL_TEXTURE0);
			glBindTexture(GL_TEXTURE_2D, TextureName[texture::DIFFUSE]);
			glBindVertexArray(VertexArrayName);

			glDrawArraysInstanced(GL_TRIANGLES, 0, VertexCount, 1);
		}

		// Resolved multisampling
		{
			glBindFramebuffer(GL_READ_FRAMEBUFFER, FramebufferName[framebuffer::RENDER]);
			glBindFramebuffer(GL_DRAW_FRAMEBUFFER, FramebufferName[framebuffer::RESOLVE]);
			glBlitFramebuffer(
				0, 0,
				WindowSize.x / FRAMEBUFFER_SIZE,
				WindowSize.y / FRAMEBUFFER_SIZE,
				0, 0,
				WindowSize.x / FRAMEBUFFER_SIZE,
				WindowSize.y / FRAMEBUFFER_SIZE,
				GL_COLOR_BUFFER_BIT, GL_NEAREST);
			glBindFramebuffer(GL_FRAMEBUFFER, 0);
		}

		// Pass 2
		{
			glm::mat4 Perspective = glm::perspective(glm::pi<float>() * 0.25f, float(WindowSize.x) / WindowSize.y, 0.1f, 100.0f);
			glm::mat4 Model = glm::mat4(1.0f);
			glm::mat4 MVP = Perspective * this->view() * Model;

			glUseProgram(ProgramName[program::SPLASH]);
			glUniform1i(UniformDiffuse[program::SPLASH], 0);
			glUniformMatrix4fv(UniformMVP[program::SPLASH], 1, GL_FALSE, &MVP[0][0]);

			glViewport(0, 0, WindowSize.x, WindowSize.y);
			glBindFramebuffer(GL_FRAMEBUFFER, 0);
			glClearBufferfv(GL_COLOR, 0, &glm::vec4(1.0f, 0.5f, 0.0f, 1.0f)[0]);

			glActiveTexture(GL_TEXTURE0);
			glBindTexture(GL_TEXTURE_2D, TextureName[texture::SPLASHBUFFER]);
			glBindVertexArray(VertexArrayName);

			glDrawArraysInstanced(GL_TRIANGLES, 0, VertexCount, 1);
		}

		return this->checkError("render");;
	}
Beispiel #9
0
//! glClearBufferuiv wrapper. May throw.
inline void clearBufferuiv(GLenum const buf,
                           GLint const drawbuffer,
                           GLuint const* value) {
  glClearBufferuiv(buf, drawbuffer, value);
  checkError("glClearBufferuiv");
}
void FramebufferImplementation_Legacy::clearBufferuiv(const Framebuffer *fbo, const GLenum buffer, const GLint drawBuffer, const GLuint * value) const
{
    fbo->bind(GL_DRAW_FRAMEBUFFER);

    glClearBufferuiv(buffer, drawBuffer, value);
}