PXR_NAMESPACE_OPEN_SCOPE


static
void
_ClearBuffer(GLenum buffer, GLint drawBuffer, const VtValue &value)
{
    // XXX: There has to be a better way to handle the different formats.
    if (value.IsHolding<int>()) {
        glClearBufferiv(buffer, drawBuffer, &value.UncheckedGet<int>());
    } else if (value.IsHolding<GfVec2i>()) {
        glClearBufferiv(buffer, drawBuffer, value.UncheckedGet<GfVec2i>().GetArray());
    } else if (value.IsHolding<GfVec3i>()) {
        glClearBufferiv(buffer, drawBuffer, value.UncheckedGet<GfVec3i>().GetArray());
    } else if (value.IsHolding<GfVec4i>()) {
        glClearBufferiv(buffer, drawBuffer, value.UncheckedGet<GfVec4i>().GetArray());
    } else if (value.IsHolding<float>()) {
        glClearBufferfv(buffer, drawBuffer, &value.UncheckedGet<float>());
    } else if (value.IsHolding<GfVec2f>()) {
        glClearBufferfv(buffer, drawBuffer, value.UncheckedGet<GfVec2f>().GetArray());
    } else if (value.IsHolding<GfVec3f>()) {
        glClearBufferfv(buffer, drawBuffer, value.UncheckedGet<GfVec3f>().GetArray());
    } else if (value.IsHolding<GfVec4f>()) {
        glClearBufferfv(buffer, drawBuffer, value.UncheckedGet<GfVec4f>().GetArray());
    } else {
      TF_CODING_ERROR("Unsupported clear value type: %s",
                      value.GetTypeName().c_str());
    }
}
Beispiel #2
0
void kit::PixelBuffer::clearAttachment(uint32_t attachment, glm::ivec4 clearcolor)
{
  this->bind();
  if (attachment >= this->m_colorAttachments.size())
  {
    KIT_THROW("Cant clear attachment, index out of range.");
  }

  GLint color[4] = { clearcolor.x, clearcolor.y, clearcolor.z, clearcolor.w };
  KIT_GL(glClearBufferiv(GL_COLOR, attachment, &color[0]));
  
}
Beispiel #3
0
	void OGLESFrameBuffer::Clear(uint32_t flags, Color const & clr, float depth, int32_t stencil)
	{
		OGLESRenderEngine& re = *checked_cast<OGLESRenderEngine*>(&Context::Instance().RenderFactoryInstance().RenderEngineInstance());

		GLuint old_fbo = re.BindFramebuffer();
		re.BindFramebuffer(fbo_);

		DepthStencilStateDesc const & ds_desc = re.CurDSSObj()->GetDesc();
		BlendStateDesc const & blend_desc = re.CurBSObj()->GetDesc();

		if (flags & CBM_Color)
		{
			if (blend_desc.color_write_mask[0] != CMASK_All)
			{
				glColorMask(true, true, true, true);
			}
		}
		if (flags & CBM_Depth)
		{
			if (!ds_desc.depth_write_mask)
			{
				glDepthMask(GL_TRUE);
			}
		}
		if (flags & CBM_Stencil)
		{
			if (!ds_desc.front_stencil_write_mask)
			{
				glStencilMaskSeparate(GL_FRONT, GL_TRUE);
			}
			if (!ds_desc.back_stencil_write_mask)
			{
				glStencilMaskSeparate(GL_BACK, GL_TRUE);
			}
		}

		if (glloader_GLES_VERSION_3_0())
		{
			if (flags & CBM_Color)
			{
				if (fbo_ != 0)
				{
					for (size_t i = 0; i < clr_views_.size(); ++ i)
					{
						if (clr_views_[i])
						{
							glClearBufferfv(GL_COLOR, static_cast<GLint>(i), &clr[0]);
						}
					}
				}
				else
				{
					glClearBufferfv(GL_COLOR, 0, &clr[0]);
				}
			}

			if ((flags & CBM_Depth) && (flags & CBM_Stencil))
			{
				glClearBufferfi(GL_DEPTH_STENCIL, 0, depth, stencil);
			}
			else
			{
				if (flags & CBM_Depth)
				{
					glClearBufferfv(GL_DEPTH, 0, &depth);
				}
				else
				{
					if (flags & CBM_Stencil)
					{
						GLint s = stencil;
						glClearBufferiv(GL_STENCIL, 0, &s);
					}
				}
			}
		}
		else
		{
			GLbitfield ogl_flags = 0;
			if (flags & CBM_Color)
			{
				ogl_flags |= GL_COLOR_BUFFER_BIT;
				re.ClearColor(clr.r(), clr.g(), clr.b(), clr.a());
			}
			if (flags & CBM_Depth)
			{
				ogl_flags |= GL_DEPTH_BUFFER_BIT;
				re.ClearDepth(depth);
			}
			if (flags & CBM_Stencil)
			{
				ogl_flags |= GL_STENCIL_BUFFER_BIT;
				re.ClearStencil(stencil);
			}

			glClear(ogl_flags);
		}

		if (flags & CBM_Color)
		{
			if (blend_desc.color_write_mask[0] != CMASK_All)
			{
				glColorMask((blend_desc.color_write_mask[0] & CMASK_Red) != 0,
						(blend_desc.color_write_mask[0] & CMASK_Green) != 0,
						(blend_desc.color_write_mask[0] & CMASK_Blue) != 0,
						(blend_desc.color_write_mask[0] & CMASK_Alpha) != 0);
			}
		}
		if (flags & CBM_Depth)
		{
			if (!ds_desc.depth_write_mask)
			{
				glDepthMask(GL_FALSE);
			}
		}
		if (flags & CBM_Stencil)
		{
			if (!ds_desc.front_stencil_write_mask)
			{
				glStencilMaskSeparate(GL_FRONT, GL_FALSE);
			}
			if (!ds_desc.back_stencil_write_mask)
			{
				glStencilMaskSeparate(GL_BACK, GL_FALSE);
			}
		}

		re.BindFramebuffer(old_fbo);
	}
Beispiel #4
0
void Framebuffer::clearBufferiv(const GLenum buffer, const GLint drawBuffer, const GLint * value)
{
    bind();

    glClearBufferiv(buffer, drawBuffer, value);
}
Beispiel #5
0
//! glClearBufferiv wrapper. May throw.
inline void clearBufferiv(GLenum const buf,
                          GLint const drawbuffer,
                          GLint const* value) {
  glClearBufferiv(buf, drawbuffer, value);
  checkError("glClearBufferiv");
}
Beispiel #6
0
void display()
{
	glEnable(GL_DEPTH_TEST);
	glDepthMask(true);
	
	// Update of the uniform buffer
	{

		glBindBuffer(GL_UNIFORM_BUFFER, BufferName[buffer::UNIFORM_UPDATE_EACH_FRAME]);
		UPDATE_EACH_FRAME* uniformBufferUpdatedEachFrame = (UPDATE_EACH_FRAME*)glMapBufferRange(
			GL_UNIFORM_BUFFER, 0, sizeof(UPDATE_EACH_FRAME),
			GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT);

		float yScale = 1.0f / tanf(    (3.14f / 4.0f)   /2.0f);
		float xScale = yScale / (Window.Size.x / Window.Size.y);
		float zNear = 1.0f;
		float zFar = 500.0f;

		//glm::mat4 Projection = glm::perspectiveFov(45.f, (float)Window.Size.x, (float)Window.Size.y, zNear, zFar);

		glm::mat4 Projection;
		Projection[0] = glm::vec4(xScale,      0.0f,       0.0f,                     0.0f);
		Projection[1] = glm::vec4(0.0f,        yScale,     0.0f,                     0.0f);
		Projection[2] = glm::vec4(0.0f,        0.0f,       zFar/(zNear-zFar),        -1.0f);
		Projection[3] = glm::vec4(0.0f,        0.0f,       -zNear*zFar/(zFar-zNear), 0.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 ModelRotate = glm::rotate(glm::mat4(1.0f), rotateModel, glm::vec3(0.0f,1.0f,0.0f));
		glm::mat4 Model = ModelRotate;
		rotateModel += 0.001f;

		uniformBufferUpdatedEachFrame->mMtoS = Projection * View * Model;

		// Make sure the uniform buffer is uploaded
		glUnmapBuffer(GL_UNIFORM_BUFFER);
	}
	
	glViewportIndexedf(0, 0, 0, GLfloat(Window.Size.x), GLfloat(Window.Size.y));
	glClearBufferfv(GL_COLOR, 0, &glm::vec4(0.7f, 0.8f, 1.0f, 1.0f)[0]);

	const GLfloat clearDepthValue = 1.0f;
	glClearBufferfv(GL_DEPTH, 0, &clearDepthValue);
	const GLint clearStencilValue = 0;
	glClearBufferiv(GL_STENCIL, 0, &clearStencilValue);

	// Bind rendering objects
	glBindProgramPipeline(PipelineName);

	glActiveTexture(GL_TEXTURE0);
	glBindTexture(GL_TEXTURE_2D, oglTextureModelDiffuse);

	glBindVertexArray(VertexArrayModel);
	
	glBindBufferBase(GL_UNIFORM_BUFFER, MySemantic::uniform::UNIFORM_UPDATE_EACH_FRAME, BufferName[buffer::UNIFORM_UPDATE_EACH_FRAME]);

	glDrawElements(GL_TRIANGLES, sizeof(indexBuffer) / sizeof(GLushort), GL_UNSIGNED_SHORT, NULL);


	amd::swapBuffers();
}
void FramebufferImplementation_Legacy::clearBufferiv(const Framebuffer *fbo, const GLenum buffer, const GLint drawBuffer, const GLint * value) const
{
    fbo->bind(GL_DRAW_FRAMEBUFFER);

    glClearBufferiv(buffer, drawBuffer, value);
}
Beispiel #8
0
void Application::drawScene() {

	GLenum err;

	glViewport(0, 0, 2048, 2048);
	glBindFramebuffer(GL_FRAMEBUFFER, fbo);

	float back_color[] = { 1, 1, 1, 1 };
	float zero[]       = { 0.0f, 0.0f, 0.0f, -10.0f };
	float one          = 1.0f;
	int   zero_int     = 0;

	glClearBufferfv(GL_COLOR, 0, back_color);
	glClearBufferfv(GL_DEPTH, 0, &one);
	glClearBufferiv(GL_STENCIL, 0, &zero_int);

	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);

	glm::mat4* transform_matrices = nullptr;

	GL_ERROR

		// =====================================================================
		// =====================================================================
		// == Rendering the mirror contents 
		// =====================================================================
		// =====================================================================

#define RENDER_MIRROR
#ifdef RENDER_MIRROR
	glEnable(GL_STENCIL_TEST);
	glStencilFunc(GL_ALWAYS, 1, 1);
	glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);

	GL_ERROR

	// Do Masking
	//glColorMask(0, 0, 0, 0);
	glEnable(GL_STENCIL_TEST);
	glStencilFunc(GL_ALWAYS, 1, 1);
	glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
	glDepthMask(GL_TRUE);
	glEnable(GL_DEPTH_TEST);

	GL_ERROR

	// Apply the mirror
	glBindBufferBase(GL_UNIFORM_BUFFER, 0, m_transformation_buffer);
	transform_matrices = (glm::mat4*)glMapBufferRange(GL_UNIFORM_BUFFER, 0, 3 * sizeof(glm::mat4), GL_MAP_WRITE_BIT);
	transform_matrices[0] = m_projmat;
	transform_matrices[1] = m_viewmat;
	transform_matrices[2] =
		m_worldmat *
		glm::mat4(
			5.0f, 0.0f, 0.0f, 0.0f,
			0.0f, 5.0f, 0.0f, 0.0f,
			0.0f, 0.0f, 5.0f, 0.0f,
			0.0f, 0.0f, 0.0f, 1.0f
		);
	glUnmapBuffer(GL_UNIFORM_BUFFER);

	drawMirror();

	// Render Mirrored Triangle
	glDepthMask(GL_FALSE);
	glEnable(GL_DEPTH_TEST);
	glDepthFunc(GL_GREATER);
	glColorMask(1, 1, 1, 1);
	glStencilFunc(GL_EQUAL, 1, 1);
	glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);

	// Apply the mirror
	glBindBufferBase(GL_UNIFORM_BUFFER, 0, m_transformation_buffer);
	transform_matrices = (glm::mat4*)glMapBufferRange(GL_UNIFORM_BUFFER, 0, 3 * sizeof(glm::mat4), GL_MAP_WRITE_BIT);
	transform_matrices[0] = m_projmat;
	transform_matrices[1] = m_viewmat;
	transform_matrices[2] =
		m_worldmat *
		glm::mat4(
			5.0f, 0.0f, 0.0f, 0.0f,
			0.0f, 5.0f, 0.0f, 0.0f,
			0.0f, 0.0f, -5.0f, 0.0f,
			0.0f, 0.0f, 0.0f, 1.0f
		);
	glUnmapBuffer(GL_UNIFORM_BUFFER);
	drawTriangle();

	GL_ERROR

#endif
	// ===================================================================
	// ===================================================================
	// Render main triangle
	// ===================================================================
	// ===================================================================

	glBindBufferBase(GL_UNIFORM_BUFFER, 0, m_transformation_buffer);
	transform_matrices = (glm::mat4*)glMapBufferRange(GL_UNIFORM_BUFFER, 0, 3 * sizeof(glm::mat4), GL_MAP_WRITE_BIT);
	transform_matrices[0] = m_projmat;
	transform_matrices[1] = m_viewmat;
	transform_matrices[2] =
		m_worldmat *
		glm::mat4(
			5.0f, 0.0f, 0.0f, 0.0f,
			0.0f, 5.0f, 0.0f, 0.0f,
			0.0f, 0.0f, 5.0f, 0.0f,
			0.0f, 0.0f, 0.0f, 1.0f
		);
	glUnmapBuffer(GL_UNIFORM_BUFFER);
	glDepthFunc(GL_LESS);
	glEnable(GL_DEPTH_TEST);
	glDepthMask(GL_TRUE);
	glDisable(GL_STENCIL_TEST);
	drawTriangle();

	GL_ERROR

	glBindBufferBase(GL_UNIFORM_BUFFER, 0, m_transformation_buffer);
	transform_matrices = (glm::mat4*)glMapBufferRange(GL_UNIFORM_BUFFER, 0, 3 * sizeof(glm::mat4), GL_MAP_WRITE_BIT);
	transform_matrices[0] = m_projmat;
	transform_matrices[1] = m_viewmat;
	transform_matrices[2] =	m_worldmat;
	glUnmapBuffer(GL_UNIFORM_BUFFER);

	GL_ERROR
}
Beispiel #9
0
void piglit_init(int argc, char **argv)
{
	static const struct {
		bool color;
		bool stencil;
		bool depth;
		bool packed;
	} test_vectors[] = {
		{ true,  false, false, false },
		{ false, true,  false, false },
		{ true,  true,  false, false },
		{ false, true,  true,  false },
		{ true,  true,  true,  false },
		{ false, true,  true,  true },
		{ true,  true,  true,  true },
	};

	static const int first[4]  = { 0x01, 0x00, 0x00, 0x00 };
	static const int second[4] = { 0xfe, 0x88, 0x88, 0x88 };

	unsigned i;
	bool pass = true;

	piglit_require_gl_version(30);

	for (i = 0; i < ARRAY_SIZE(test_vectors); i++) {
		GLenum err;
		GLuint fb = generate_simple_fbo(test_vectors[i].color,
						test_vectors[i].stencil,
						test_vectors[i].depth,
						test_vectors[i].packed);

		if (fb == 0) {
			if (!piglit_automatic) {
				printf("Skipping framebuffer %s color, "
				       "%s depth, and "
				       "%s stencil (%s).\n",
				       test_vectors[i].color
				       ? "with" : "without",
				       test_vectors[i].depth
				       ? "with" : "without",
				       test_vectors[i].stencil
				       ? "with" : "without",
				       test_vectors[i].packed
				       ? "packed" : "separate");
			}

			continue;
		}

		if (!piglit_automatic) {
			printf("Trying framebuffer %s color, "
			       "%s depth and "
			       "%s stencil (%s)...\n",
			       test_vectors[i].color ? "with" : "without",
			       test_vectors[i].depth ? "with" : "without",
			       test_vectors[i].stencil ? "with" : "without",
			       test_vectors[i].packed ? "packed" : "separate");
		}

		/* The GL spec says nothing about generating an error for
		 * clearing a buffer that does not exist.  Certainly glClear
		 * does not.
		 */
		glClearBufferiv(GL_STENCIL, 0, first);
		err = glGetError();
		if (err != GL_NO_ERROR) {
			fprintf(stderr,
				"First call to glClearBufferiv erroneously "
				"generated a GL error (%s, 0x%04x)\n",
				piglit_get_gl_error_name(err), err);
			pass = false;
		}

		pass = simple_probe(test_vectors[i].color,
				    default_color,
				    test_vectors[i].stencil,
				    first[0],
				    test_vectors[i].depth,
				    default_depth)
			&& pass;

		glClearBufferiv(GL_STENCIL, 0, second);
		err = glGetError();
		if (err != GL_NO_ERROR) {
			fprintf(stderr,
				"Second call to glClearBufferiv erroneously "
				"generated a GL error (%s, 0x%04x)\n",
				piglit_get_gl_error_name(err), err);
			pass = false;
		}

		pass = simple_probe(test_vectors[i].color,
				    default_color,
				    test_vectors[i].stencil,
				    second[0],
				    test_vectors[i].depth,
				    default_depth)
			&& pass;

		glDeleteFramebuffers(1, &fb);
		pass = piglit_check_gl_error(GL_NO_ERROR) && pass;
	}

	piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL);
}