bool render()
	{
		glm::vec2 WindowSize(this->getWindowSize());

		{
			glm::mat4 ProjectionA = glm::scale(glm::perspective(glm::pi<float>() * 0.25f, float(FRAMEBUFFER_SIZE.x) / FRAMEBUFFER_SIZE.y, 0.1f, 100.0f), glm::vec3(1, -1, 1));
			*reinterpret_cast<glm::mat4*>(this->UniformPointer + 0) = ProjectionA * this->view() * glm::mat4(1);

			glm::mat4 ProjectionB = glm::perspective(glm::pi<float>() * 0.25f, WindowSize.x / WindowSize.y, 0.1f, 100.0f);
			*reinterpret_cast<glm::mat4*>(this->UniformPointer + this->UniformBlockSize) = ProjectionB * this->view() * glm::scale(glm::mat4(1), glm::vec3(2));
		}

		// Step 1, render the scene in a multisampled framebuffer
		glBindProgramPipeline(PipelineName);

		renderFBO();

		// Step 2: blit
		glBlitNamedFramebuffer(FramebufferName[framebuffer::RENDER], FramebufferName[framebuffer::RESOLVE],
			0, 0, FRAMEBUFFER_SIZE.x, FRAMEBUFFER_SIZE.y,
			0, 0, FRAMEBUFFER_SIZE.x, FRAMEBUFFER_SIZE.y,
			GL_COLOR_BUFFER_BIT, GL_NEAREST);

		GLenum MaxColorAttachment = GL_COLOR_ATTACHMENT0;
		glInvalidateNamedFramebufferData(FramebufferName[framebuffer::RENDER], 1, &MaxColorAttachment);

		// Step 3, render the colorbuffer from the multisampled framebuffer
		renderFB();

		return true;
	}
Esempio n. 2
0
void blitColor(const GLFramebuffer& source, int src_attachment, const GLFramebuffer* destination, int dst_attachment)
{
   int destination_id = destination ? destination->id() : 0;
   
   glNamedFramebufferReadBuffer(source.id(), GL_COLOR_ATTACHMENT0 + src_attachment);
   if (destination)
      glNamedFramebufferDrawBuffer(destination_id, GL_COLOR_ATTACHMENT0 + dst_attachment);
   glBlitNamedFramebuffer(source.id(), destination_id, 0, 0, source.width(), source.height(), 0, 0, source.width(), source.height(), GL_COLOR_BUFFER_BIT, GL_NEAREST);
}
Esempio n. 3
0
void kit::DoubleBuffer::blitFrom(kit::DoubleBuffer::Ptr source)
{
  
  KIT_GL(glBlitNamedFramebuffer(
    source->getFrontBuffer()->getHandle(),
    this->getBackBuffer()->getHandle(),
    0, 0, source->getResolution().x, source->getResolution().y,
    0, 0, this->getResolution().x, this->getResolution().y,
    GL_COLOR_BUFFER_BIT, GL_LINEAR
  ));
}
Esempio n. 4
0
void kit::PixelBuffer::blitFrom(kit::PixelBuffer::Ptr source, bool colorMask, std::vector<std::array<bool, 4>> componentMask, bool depthMask, bool stencilMask)
{
  bool clearColorMask = false;
  GLbitfield mask = 0;

  if (colorMask)
  {
    mask |= GL_COLOR_BUFFER_BIT;
    if (this->m_colorAttachments.size() != source->getNumColorAttachments())
    {
      KIT_THROW("source: color attachment count mismatch");
      return;
    }
  }

  if (depthMask)
  {
    mask |= GL_DEPTH_BUFFER_BIT;
  }

  if (stencilMask)
  {
    mask |= GL_STENCIL_BUFFER_BIT;
  }

  if (componentMask.size() != 0 && colorMask)
  {
    if (componentMask.size() != this->m_colorAttachments.size())
    {
      KIT_ERR("componentMask: color attachment count mismatch");
      return;
    }

    for (int i = 0; i < this->m_colorAttachments.size(); i++)
    {
      KIT_GL(glColorMaski(i, componentMask[i][0], componentMask[i][1], componentMask[i][2], componentMask[i][3]));
    }

    clearColorMask = true;
  }

  KIT_GL(glBlitNamedFramebuffer(source->getHandle(), this->getHandle(), 0, 0, source->getResolution().x, source->getResolution().y, 0, 0, this->getResolution().x, this->getResolution().y, mask, GL_LINEAR));

  if (clearColorMask)
  {
    for (int i = 0; i < this->m_colorAttachments.size(); i++)
    {
      KIT_GL(glColorMaski(i, true, true, true, true));
    }
  }
}
Esempio n. 5
0
void GL45Backend::do_blit(const Batch& batch, size_t paramOffset) {
    auto srcframebuffer = batch._framebuffers.get(batch._params[paramOffset]._uint);
    Vec4i srcvp;
    for (auto i = 0; i < 4; ++i) {
        srcvp[i] = batch._params[paramOffset + 1 + i]._int;
    }

    auto dstframebuffer = batch._framebuffers.get(batch._params[paramOffset + 5]._uint);
    Vec4i dstvp;
    for (auto i = 0; i < 4; ++i) {
        dstvp[i] = batch._params[paramOffset + 6 + i]._int;
    }

    // Assign dest framebuffer if not bound already
    auto destFbo = getFramebufferID(dstframebuffer);
    auto srcFbo = getFramebufferID(srcframebuffer);
    glBlitNamedFramebuffer(srcFbo, destFbo,
        srcvp.x, srcvp.y, srcvp.z, srcvp.w,
        dstvp.x, dstvp.y, dstvp.z, dstvp.w,
        GL_COLOR_BUFFER_BIT, GL_LINEAR);
    (void) CHECK_GL_ERROR();
}
void AbstractFramebuffer::blitImplementationDSA(AbstractFramebuffer& source, AbstractFramebuffer& destination, const Range2Di& sourceRectangle, const Range2Di& destinationRectangle, const FramebufferBlitMask mask, const FramebufferBlitFilter filter) {
    glBlitNamedFramebuffer(source._id, destination._id, sourceRectangle.left(), sourceRectangle.bottom(), sourceRectangle.right(), sourceRectangle.top(), destinationRectangle.left(), destinationRectangle.bottom(), destinationRectangle.right(), destinationRectangle.top(), GLbitfield(mask), GLenum(filter));
}