void EndPatchRenderer::prerenderSetup(int level, std::function<void (const glm::vec4 &)> setDrawColor)
{
	assert(indexBufferGenerated);
	assert(ibo != std::numeric_limits<GLuint>::max());
	assert(vboRef == controlMesh->vbo);

	setDrawColor(glm::vec4(0.f, 1.f, 1.f, 1.f)); // Debug

	glUseProgram(program);
	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo);
	glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 0, controlMesh->vbo);
	glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, ovbo);
	glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 2, nibo);
	glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 9, uvBuffer);
	if (controlMesh->hasTexture)
	{
		glBindTextureUnit(4, controlMesh->diffuseMap);
	}
	if (controlMesh->hasDisplacementMap)
	{
		glBindTextureUnit(5, controlMesh->displacementMap);
	}
	glPatchParameteri(GL_PATCH_VERTICES, 3);

}
Esempio n. 2
1
static void glnvg__setUniforms(GLNVGcontext* gl, int uniformOffset, int image)
{
    glBindBufferRange(GL_UNIFORM_BUFFER, GFX_NVG_BINDING_FRAG_UBO, gfx::dynBuffer, uniformOffset, sizeof(GLNVGfragUniforms));

    if (image != 0) {
        GLNVGtexture* tex = glnvg__findTexture(gl, image);
        glBindTextureUnit(0, tex ? tex->tex : 0);
    } else {
        glBindTextureUnit(0, 0);
    }
}
void PartialPatchNoSharpRenderer::renderLevel(int level, std::function<void(const glm::vec4 &)> setDrawColor)
{
	prerenderSetup(level, setDrawColor);

	for (int i = 0; i < partialCases.size(); ++i)
	{
		//setDrawColor(ppDebugColorTable[i]); // Debug

		std::shared_ptr<PartialPatchNoSharpCaseX> pc = partialCases[i];

		if (pc->numIndices[level] > 0)
		{
			glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, pc->ibos[level]);
			glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 9, pc->uvBuffers[level]);

			std::vector<GLuint> &programs = pc->programs;
			for (int j = 0; j < programs.size(); ++j)
			{
				glUseProgram(programs[j]);
				if (controlMesh->hasTexture)
				{
					glBindTextureUnit(4, controlMesh->diffuseMap);
				}
				if (controlMesh->hasDisplacementMap)
				{
					glBindTextureUnit(5, controlMesh->displacementMap);
				}
				glDrawElements(GL_PATCHES, pc->numIndices[level], GL_UNSIGNED_INT, 0);
			}
		}
	}
}
Esempio n. 4
0
static bool
test_cube_array_texture(void)
{
	const GLint width = 16, height = 16;
	const GLenum target = GL_TEXTURE_CUBE_MAP_ARRAY;
	GLuint tex;
	bool pass = true;

	/* Test valid cube array dimensions */
	glCreateTextures(target, 1, &tex);
	glBindTextureUnit(0, tex);
	glTextureStorage3D(tex, 1, GL_RGBA8, width, height, 12);
	pass = piglit_check_gl_error(GL_NO_ERROR) && pass;
	glDeleteTextures(1, &tex);

	if (!piglit_khr_no_error) {
		/* Test invalid cube array width, height dimensions */
		glCreateTextures(target, 1, &tex);
		glBindTextureUnit(0, tex);
		glTextureStorage3D(tex, 1, GL_RGBA8, width, height+3, 12);
		pass = piglit_check_gl_error(GL_INVALID_VALUE) && pass;
		glDeleteTextures(1, &tex);

		/* Test invalid cube array depth */
		glCreateTextures(target, 1, &tex);
		glBindTextureUnit(0, tex);
		glTextureStorage3D(tex, 1, GL_RGBA8, width, height, 12+2);
		pass = piglit_check_gl_error(GL_INVALID_VALUE) && pass;
		glDeleteTextures(1, &tex);
	}

	return pass;
}
Esempio n. 5
0
enum piglit_result
piglit_display(void)
{
	bool pass = true;
	GLuint name = 3;
	GLint nunits;

	/* Throw some invalid inputs at BindTextureUnit. */


	/* Section 8.1. of the OpenGL 4.5 Core Profile spec says:
	 *
	 *     "An INVALID_OPERATION error is generated by BindTextureUnit if
	 *     texture is not zero or the name of an existing texture object."
	 */

	/* Texture name doesn't exist */
	glBindTextureUnit(0, name);
	pass = piglit_check_gl_error(GL_INVALID_OPERATION) && pass;

	/* Texture name exists, but texture object does not */
	glGenTextures(1, &name);
	glBindTextureUnit(0, name);
	pass = piglit_check_gl_error(GL_INVALID_OPERATION) && pass;

	/* Section 8.1. of the OpenGL 4.5 Core Profile spec says for
	 * BindTextures:
	 *
	 *     "An INVALID_OPERATION error is generated if first + count is
	 *     greater than the number of texture image units supported by the
	 *     implementation."
	 *
	 * However, it doesn't say the same about BindTextureUnit. Table 2.3
	 * implies that a numeric argument out of range yields INVALID_VALUE,
	 * not INVALID_OPERATION.
	 */

	/* Texture unit doesn't exist */
	glDeleteTextures(1, &name);
	glCreateTextures(GL_TEXTURE_2D, 1, &name);
	glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &nunits);
	glBindTextureUnit(nunits, name); /* Too High */
	pass = piglit_check_gl_error(GL_INVALID_VALUE) && pass;

	/* Trivial, but should work. */
	glBindTextureUnit(1, name);
	pass = piglit_check_gl_error(GL_NO_ERROR) && pass;

	return pass ? PIGLIT_PASS : PIGLIT_FAIL;
}
void PartialPatchSharpRenderer::renderLevel(int level, std::function<void(const glm::vec4 &)> setDrawColor)
{
	prerenderSetup(level, setDrawColor);

	for (int i = 0; i < partialCases.size(); ++i)
	{
		std::shared_ptr<PartialPatchSharpCaseX> pc = partialCases[i];

		if (pc->ibos[level] != std::numeric_limits<GLuint>::max())
		{
			glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, pc->ibos[level]);
			glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 9, pc->sbos[level]);
			glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 10, pc->uvBuffers[level]);

			//setDrawColor(ppDebugColorTable[i]); // Debug

			std::vector<GLuint> &programs = pc->programs;
			for (int j = 0; j < programs.size(); ++j)
			{
				glUseProgram(programs[j]);
				if (controlMesh->hasTexture)
				{
					glBindTextureUnit(4, controlMesh->diffuseMap);
				}
				if (controlMesh->hasDisplacementMap)
				{
					glBindTextureUnit(5, controlMesh->displacementMap);
				}

				for (unsigned k = 0; k < 4; ++k)
				{
					int ibOffset = pc->indexBufferOffsetSizes[level][2 * k];
					int numIndices = pc->indexBufferOffsetSizes[level][2 * k + 1];
					int sbOffset = pc->sharpnessBufferOffsets[level][k];
					int uvbOffset = pc->uvBufferOffsets[level][k];

					if (numIndices > 0)
					{
						glUniformSubroutinesuiv(GL_TESS_EVALUATION_SHADER, 1, &k);
						glUniform1i(0, sbOffset);
						glUniform1i(1, uvbOffset);
						glDrawElements(GL_PATCHES, numIndices, GL_UNSIGNED_INT, (const void *)(ibOffset * sizeof(unsigned)));
					}
				}
			}
		}
	}
}
Esempio n. 7
0
/* GL_INVALID_ENUM is generated if the effective target is GL_TEXTURE_RECTANGLE
 * and either of pnames GL_TEXTURE_WRAP_S or GL_TEXTURE_WRAP_T is set to either
 * GL_MIRROR_CLAMP_TO_EDGE, GL_MIRRORED_REPEAT or GL_REPEAT.
 */
static bool
test_texture_rec(void)
{
	bool pass = true;
	GLuint name;

	/* GL_TEXTURE_2D_MULTISAMPLE_ARRAY */
	glCreateTextures(GL_TEXTURE_RECTANGLE, 1, &name);
	glBindTextureUnit(0, name);	/* Since next command isn't bindless. */

	glTextureParameteri(name, GL_TEXTURE_WRAP_S, GL_MIRROR_CLAMP_TO_EDGE);
	pass = piglit_check_gl_error(GL_INVALID_ENUM) && pass;

	glTextureParameteri(name, GL_TEXTURE_WRAP_T, GL_MIRROR_CLAMP_TO_EDGE);
	pass = piglit_check_gl_error(GL_INVALID_ENUM) && pass;

	glTextureParameteri(name, GL_TEXTURE_WRAP_S, GL_MIRRORED_REPEAT);
	pass = piglit_check_gl_error(GL_INVALID_ENUM) && pass;

	glTextureParameteri(name, GL_TEXTURE_WRAP_T, GL_MIRRORED_REPEAT);
	pass = piglit_check_gl_error(GL_INVALID_ENUM) && pass;

	glTextureParameteri(name, GL_TEXTURE_WRAP_S, GL_REPEAT);
	pass = piglit_check_gl_error(GL_INVALID_ENUM) && pass;

	glTextureParameteri(name, GL_TEXTURE_WRAP_T, GL_REPEAT);
	pass = piglit_check_gl_error(GL_INVALID_ENUM) && pass;

	piglit_report_subtest_result(pass ? PIGLIT_PASS : PIGLIT_FAIL,
				     "glTextureParameter: GL_INVALID_ENUM in "
				     "texture_rectangle case");
	return pass;
}
void ReplayRenderWidget::paintGL()
{
   // Set up some needed GL state
   glColorMaski(0, GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
   glDisablei(GL_BLEND, 0);
   glDisable(GL_DEPTH_TEST);
   glDisable(GL_STENCIL_TEST);
   glDisable(GL_SCISSOR_TEST);
   glDisable(GL_CULL_FACE);

   // Clear screen
   glClearColor(0.6f, 0.2f, 0.2f, 1.0f);
   glClear(GL_COLOR_BUFFER_BIT);

   // Draw displays

   // Setup screen draw shader
   glBindVertexArray(mVertArray);
   glBindVertexBuffer(0, mVertBuffer, 0, 4 * sizeof(GLfloat));
   glBindProgramPipeline(mPipeline);

   // Draw screen quad
   glBindSampler(0, mSampler);
   glBindTextureUnit(0, mTvBuffer);

   glDrawArrays(GL_TRIANGLES, 0, 6);
}
Esempio n. 9
0
static bool
test_pname(void)
{
	GLuint name;
	const static GLfloat f = 1.0;
	const static GLuint u = 1;
	const static GLint i = -5;
	bool pass = true;

	/* Setup dsa. */
	glCreateTextures(GL_TEXTURE_2D, 1, &name);
	glBindTextureUnit(0, name);	/* Since next command isn't bindless. */

	glTextureParameterfv(name, GL_TEXTURE_1D, &f);
	pass = piglit_check_gl_error(GL_INVALID_ENUM) && pass;

	glTextureParameteriv(name, GL_TEXTURE_1D, &i);
	pass = piglit_check_gl_error(GL_INVALID_ENUM) && pass;

	glTextureParameterIiv(name, GL_TEXTURE_1D, &i);
	pass = piglit_check_gl_error(GL_INVALID_ENUM) && pass;

	glTextureParameterIuiv(name, GL_TEXTURE_1D, &u);
	pass = piglit_check_gl_error(GL_INVALID_ENUM) && pass;

	piglit_report_subtest_result(pass ? PIGLIT_PASS : PIGLIT_FAIL,
				     "glTextureParameter: GL_INVALID_ENUM on "
				     "bad pname");
	return pass;
}
	bool render()
	{
		glm::vec2 WindowSize(this->getWindowSize());

		{
			glm::mat4* Pointer = reinterpret_cast<glm::mat4*>(glMapNamedBufferRange(BufferName[buffer::TRANSFORM], 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;

			glUnmapNamedBuffer(BufferName[buffer::TRANSFORM]);
		}

		// Render
		glClearTexImage(TextureName[texture::COLORBUFFER], 0, GL_RGBA, GL_FLOAT, &glm::vec4(1.0f, 0.5f, 0.0f, 1.0f)[0]);

		glViewportIndexedf(0, 0, 0, WindowSize.x * this->Supersampling, WindowSize.y * this->Supersampling);
		glBindFramebuffer(GL_FRAMEBUFFER, FramebufferName);
		glBindVertexArray(this->VertexArrayName[pipeline::RENDER]);

		glBindProgramPipeline(PipelineName[pipeline::RENDER]);
		glBindTextureUnit(0, 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]);
		glBindTextureUnit(0, TextureName[texture::COLORBUFFER]);

		glDrawArraysInstancedBaseInstance(GL_TRIANGLES, 0, 3, 1, 0);

		return true;
	}
Esempio n. 11
0
GLsizei Tex2DArray::bind(GLsizei unit) const
{
	// RN_CHECK(glActiveTexture(GL_TEXTURE0 + unit));
	// RN_CHECK(glBindTexture(GL_TEXTURE_2D_ARRAY, id));

	RN_CHECK(glBindTextureUnit(unit, id));

	return unit;
}
Esempio n. 12
0
void FullPatchSharpRenderer::prerenderSetup(int level, std::function<void (const glm::vec4 &)> setDrawColor)
{
	setDrawColor(glm::vec4(1.f, .5f, 1.f, 1.f)); // Debug

	glUseProgram(program);
	if (controlMesh->hasTexture)
	{
		glBindTextureUnit(4, controlMesh->diffuseMap);
	}
	if (controlMesh->hasDisplacementMap)
	{
		glBindTextureUnit(5, controlMesh->displacementMap);
	}
	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibos[level]);
	glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 8, sbos[level]);
	glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 9, uvBuffers[level]);
	glPolygonMode(GL_FRONT_AND_BACK, g_shadingMode);
	glPatchParameteri(GL_PATCH_VERTICES, 16);
}
	bool render()
	{
		glm::vec2 WindowSize(this->getWindowSize());

		{
			glm::mat4* Pointer = static_cast<glm::mat4*>(glMapNamedBufferRange(BufferName[buffer::TRANSFORM],
				0, sizeof(glm::mat4), GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT));

			//glm::mat4 Projection = glm::perspectiveFov(glm::pi<float>() * 0.25f, 640.f, 480.f, 0.1f, 100.0f);
			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
			glUnmapNamedBuffer(BufferName[buffer::TRANSFORM]);
		}

		glBindFramebuffer(GL_FRAMEBUFFER, FramebufferName);
		glViewportIndexedf(0, 0, 0, WindowSize.x / 16.0f, WindowSize.y / 16.0f);

		glClearBufferfv(GL_COLOR, 0, &glm::vec4(1.0f)[0]);

		// Bind rendering objects
		glViewportIndexedf(0, 0, 0, WindowSize.x / 16.0f, WindowSize.y / 16.0f);
		glBindProgramPipeline(PipelineName[pipeline::TEXTURE]);
		glBindVertexArray(VertexArrayName[pipeline::TEXTURE]);
		glBindBufferBase(GL_UNIFORM_BUFFER, semantic::uniform::TRANSFORM0, BufferName[buffer::TRANSFORM]);

		glBindBufferBase(GL_UNIFORM_BUFFER, semantic::uniform::MATERIAL, BufferName[buffer::MATERIAL0]);

		//glSubpixelPrecisionBiasNV(-8, -8);
		glEnable(GL_CONSERVATIVE_RASTERIZATION_NV);
		glDrawElementsInstancedBaseVertexBaseInstance(GL_TRIANGLES, ElementCount, GL_UNSIGNED_SHORT, 0, 1, 0, 0);

		glBindBufferBase(GL_UNIFORM_BUFFER, semantic::uniform::MATERIAL, BufferName[buffer::MATERIAL1]);

		glDisable(GL_CONSERVATIVE_RASTERIZATION_NV);
		glDrawElementsInstancedBaseVertexBaseInstance(GL_TRIANGLES, ElementCount, GL_UNSIGNED_SHORT, 0, 1, 0, 0);

		glBindFramebuffer(GL_FRAMEBUFFER, 0);
		glViewportIndexedf(0, 0, 0, WindowSize.x, WindowSize.y);

		glBindProgramPipeline(PipelineName[pipeline::SPLASH]);
		glBindVertexArray(VertexArrayName[pipeline::SPLASH]);
		glBindTextureUnit(0, TextureName[texture::COLORBUFFER]);

		glDrawArraysInstancedBaseInstance(GL_TRIANGLES, 0, 3, 1, 0);

		return true;
	}
Esempio n. 14
0
/* GL_INVALID_OPERATION is generated if the effective target is either
 * GL_TEXTURE_2D_MULTISAMPLE or GL_TEXTURE_2D_MULTISAMPLE_ARRAY, and pname
 * GL_TEXTURE_BASE_LEVEL is set to a value other than zero.
 */
static bool
test_multisample_texture_base(void)
{
	bool pass = true;
	GLuint name;

	glCreateTextures(GL_TEXTURE_2D_MULTISAMPLE, 1, &name);
	glBindTextureUnit(0, name);	/* Since next command isn't bindless. */

	glTextureParameteri(name, GL_TEXTURE_BASE_LEVEL, 1);
	pass = piglit_check_gl_error(GL_INVALID_OPERATION) && pass;

	glCreateTextures(GL_TEXTURE_2D_MULTISAMPLE_ARRAY, 1, &name);
	glBindTextureUnit(0, name);	/* Since next command isn't bindless. */

	glTextureParameteri(name, GL_TEXTURE_BASE_LEVEL, 1);
	pass = piglit_check_gl_error(GL_INVALID_OPERATION) && pass;

	piglit_report_subtest_result(pass ? PIGLIT_PASS : PIGLIT_FAIL,
				     "glTextureParameter: GL_INVALID_OPERATION "
				     "for multisample+texture_base");
	return pass;
}
	void renderFB()
	{
		glm::vec2 WindowSize(this->getWindowSize());

		glClipControl(GL_LOWER_LEFT, GL_NEGATIVE_ONE_TO_ONE);
		glViewportIndexedf(0, 0, 0, WindowSize.x, WindowSize.y);
		glClearNamedFramebufferfv(0, GL_COLOR, 0, &glm::vec4(0.0f, 0.5f, 1.0f, 1.0f)[0]);

		glBindFramebuffer(GL_FRAMEBUFFER, 0);
		glBindBufferRange(GL_UNIFORM_BUFFER, semantic::uniform::TRANSFORM0, BufferName[buffer::TRANSFORM], this->UniformBlockSize, this->UniformBlockSize);
		glBindTextureUnit(0, TextureName[texture::COLORBUFFER]);
		glBindVertexArray(VertexArrayName);

		glDrawElementsInstancedBaseVertexBaseInstance(GL_TRIANGLES, ElementCount, GL_UNSIGNED_SHORT, nullptr, 1, 0, 0);
	}
Esempio n. 16
0
/* GL_INVALID_OPERATION is generated if the effective target is
 * GL_TEXTURE_RECTANGLE and pname GL_TEXTURE_BASE_LEVEL is set to any value
 * other than zero.
 */
static bool
test_texture_rec_texture_base(void)
{
	bool pass = true;
	GLuint name;

	glCreateTextures(GL_TEXTURE_RECTANGLE, 1, &name);
	glBindTextureUnit(0, name);	/* Since next command isn't bindless. */

	glTextureParameteri(name, GL_TEXTURE_BASE_LEVEL, 1);
	pass = piglit_check_gl_error(GL_INVALID_OPERATION) && pass;

	piglit_report_subtest_result(pass ? PIGLIT_PASS : PIGLIT_FAIL,
				     "glTextureParameter: GL_INVALID_OPERATION "
				     "for texture_rectangle+min_filter");
	return pass;
}
Esempio n. 17
0
enum piglit_result
piglit_display(void)
{
	int pass;

	glClearColor(0.0, 0.0, 0.0, 1.0);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	glEnable(GL_TEXTURE_2D);
	glBindTextureUnit(0, name);
	piglit_draw_rect_tex(0, 0, 1, 1, 0, 0, 1, 1);

	piglit_present_results();

	pass = test_getteximage();

	return pass ? PIGLIT_PASS : PIGLIT_FAIL;
}
Esempio n. 18
0
static bool
test_immutablity(GLenum target)
{
	GLuint tex;
	GLint level;
	GLint immutable_format;

	bool pass = true;

	glCreateTextures(target, 1, &tex);
	glBindTextureUnit(0, tex);

	glTextureStorage2D(tex, 3, GL_RGBA8, 256, 256);
	glTextureParameteri(tex, GL_TEXTURE_MAX_LEVEL, 4);
	glGetTextureParameteriv(tex, GL_TEXTURE_MAX_LEVEL, &level);
	glGetTextureParameteriv(tex, GL_TEXTURE_IMMUTABLE_FORMAT,
			    &immutable_format);

	if (immutable_format != GL_TRUE) {
		printf("%s: GL_TEXTURE_IMMUTABLE_FORMAT was not set to "
		       "GL_TRUE after glTextureStorage2D\n", TestName);
		pass = false;
	}
	if (level != 2) {
		/* The ARB_texture_storage spec says:
		 *
		 *     "However, if TEXTURE_IMMUTABLE_FORMAT is TRUE, then
		 *     level_base is clamped to the range [0, <levels> - 1]
		 *     and level_max is then clamped to the range [level_base,
		 *     <levels> - 1], where <levels> is the parameter passed
		 *     the call to TexStorage* for the texture object"
		 */
		printf("%s: GL_TEXTURE_MAX_LEVEL changed to %d, which is "
		       "outside the clamp range for immutables\n",
		       TestName, level);
		pass = false;
	}

	/* Other immutable tests happen per-format above */

	glDeleteTextures(1, &tex);
	return pass;
}
	void renderFBO()
	{
		glEnable(GL_MULTISAMPLE);
		glEnable(GL_SAMPLE_SHADING);
		glMinSampleShading(4.0f);

		glClipControl(GL_LOWER_LEFT, GL_NEGATIVE_ONE_TO_ONE);
		glViewportIndexedf(0, 0, 0, static_cast<float>(FRAMEBUFFER_SIZE.x), static_cast<float>(FRAMEBUFFER_SIZE.y));
		glClearNamedFramebufferfv(FramebufferName[framebuffer::RENDER], GL_COLOR, 0, &glm::vec4(0.0f, 0.5f, 1.0f, 1.0f)[0]);

		glBindFramebuffer(GL_FRAMEBUFFER, FramebufferName[framebuffer::RENDER]);
		glBindBufferRange(GL_UNIFORM_BUFFER, semantic::uniform::TRANSFORM0, BufferName[buffer::TRANSFORM], 0, this->UniformBlockSize);
		glBindSamplers(0, 1, &SamplerName);
		glBindTextureUnit(0, TextureName[texture::TEXTURE]);
		glBindVertexArray(VertexArrayName);

		glDrawElementsInstancedBaseVertexBaseInstance(GL_TRIANGLES, ElementCount, GL_UNSIGNED_SHORT, nullptr, 1, 0, 0);

		glDisable(GL_MULTISAMPLE);
	}
Esempio n. 20
0
/* GL_INVALID_VALUE is generated if pname is GL_TEXTURE_BASE_LEVEL or
 * GL_TEXTURE_MAX_LEVEL, and param or params is negative.
 */
static bool
test_texture_level_negative(void)
{
	bool pass = true;
	GLuint name;

	glCreateTextures(GL_TEXTURE_2D, 1, &name);
	glBindTextureUnit(0, name);	/* Since next command isn't bindless. */

	glTextureParameteri(name, GL_TEXTURE_BASE_LEVEL, -1);
	pass = piglit_check_gl_error(GL_INVALID_VALUE) && pass;

	glTextureParameteri(name, GL_TEXTURE_MAX_LEVEL, -1);
	pass = piglit_check_gl_error(GL_INVALID_VALUE) && pass;

	piglit_report_subtest_result(pass ? PIGLIT_PASS : PIGLIT_FAIL,
				     "glTextureParameter: GL_INVALID_VALUE for "
				     "negative tex_*_level");
	return pass;
}
Esempio n. 21
0
/* GL_INVALID_ENUM is generated if glTextureParamter{if} is called for a
 * non-scalar parameter
 */
static bool
test_scalar_vector(void)
{
	bool pass = true;
	const static GLfloat f = 1.0;
	const static GLint i = -1;
	GLuint name;

	/* Setup dsa. */
	glCreateTextures(GL_TEXTURE_2D, 1, &name);
	glBindTextureUnit(0, name);	/* Since next command isn't bindless. */

	glTextureParameteri(name, GL_TEXTURE_BORDER_COLOR, i);
	pass = piglit_check_gl_error(GL_INVALID_ENUM) && pass;

	glTextureParameterf(name, GL_TEXTURE_BORDER_COLOR, f);
	pass = piglit_check_gl_error(GL_INVALID_ENUM) && pass;

	piglit_report_subtest_result(pass ? PIGLIT_PASS : PIGLIT_FAIL,
				     "glTextureParameter{if}: GL_INVALID_ENUM "
				     "for non-scalars");
	return pass;
}
	bool render()
	{
		glm::vec2 WindowSize(this->getWindowSize());

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

			*UniformPointer = MVP;
		}

		glViewportIndexedf(0, 0, 0, WindowSize.x, WindowSize.y);
		glClearBufferfv(GL_COLOR, 0, &glm::vec4(1.0f)[0]);

		glBindProgramPipeline(PipelineName);
		glBindTextureUnit(semantic::sampler::DIFFUSE, TextureName);
		glBindVertexArray(VertexArrayName);
		glBindBufferBase(GL_UNIFORM_BUFFER, semantic::uniform::TRANSFORM0, BufferName[buffer::TRANSFORM]);
		glBindBufferBase(GL_SHADER_STORAGE_BUFFER, semantic::storage::VERTEX, BufferName[buffer::VERTEX]);

		glDrawElementsInstancedBaseVertexBaseInstance(GL_TRIANGLES, ElementCount, GL_UNSIGNED_SHORT, 0, 1, 0, 0);

		return true;
	}
Esempio n. 23
0
			void bind(GLuint i) const{
				glBindTextureUnit(i, texture_);
			}
Esempio n. 24
0
/**
 * Do error-check tests for a non-mipmapped texture.
 */
static bool
test_one_level_errors(GLenum target)
{
	const GLint width = 64, height = 4, depth = 8;
	GLuint tex;
	GLint v;

	assert(target == GL_TEXTURE_1D ||
	       target == GL_TEXTURE_2D ||
	       target == GL_TEXTURE_3D);

	glCreateTextures(target, 1, &tex);
	glBindTextureUnit(0, tex);

	if (target == GL_TEXTURE_1D) {
		glTextureStorage1D(tex, 1, GL_RGBA8, width);
	} else if (target == GL_TEXTURE_2D) {
		glTextureStorage2D(tex, 1, GL_RGBA8, width, height);
	} else if (target == GL_TEXTURE_3D) {
		glTextureStorage3D(tex, 1, GL_RGBA8, width, height, depth);
	}

	piglit_check_gl_error(GL_NO_ERROR);

	glGetTextureLevelParameteriv(tex, 0, GL_TEXTURE_WIDTH, &v);
	if (v != width) {
		printf("%s: bad width: %d, should be %d\n", TestName, v, width);
		return false;
	}

	if (target != GL_TEXTURE_1D) {
		glGetTextureLevelParameteriv(tex, 0, GL_TEXTURE_HEIGHT, &v);
		if (v != height) {
			printf("%s: bad height: %d, should be %d\n", TestName,
			       v, height);
			return false;
		}
	}

	if (target == GL_TEXTURE_3D) {
		glGetTextureLevelParameteriv(tex, 0, GL_TEXTURE_DEPTH, &v);
		if (v != depth) {
			printf("%s: bad depth: %d, should be %d\n", TestName,
			       v, depth);
			return false;
		}
	}

	/* The ARB_texture_storage spec says:
	 *
	 *     "Using any of the following commands with the same texture will
	 *     result in the error INVALID_OPERATION being generated, even if
	 *     it does not affect the dimensions or format:
	 *
	 *         - TexImage*
	 *         - CompressedTexImage*
	 *         - CopyTexImage*
	 *         - TexStorage*"
	 */
	if (!piglit_khr_no_error && target == GL_TEXTURE_2D) {
		glTexImage2D(target, 0, GL_RGBA, width, height, 0,
			     GL_RGBA, GL_UNSIGNED_BYTE, NULL);
		if (glGetError() != GL_INVALID_OPERATION) {
			printf("%s: glTexImage2D failed to generate error\n",
			       TestName);
			return false;
		}

		glTextureStorage2D(tex, 1, GL_RGBA8, width, height);
		if (glGetError() != GL_INVALID_OPERATION) {
			printf("%s: glTextureStorage2D() failed to generate "
			       "error\n", TestName);
			return false;
		}

		glCopyTexImage2D(target, 0, GL_RGBA, 0, 0, width, height, 0);
		if (glGetError() != GL_INVALID_OPERATION) {
			printf("%s: glCopyTexImage2D() failed to generate "
			       "error\n", TestName);
			return false;
		}
	}

	glDeleteTextures(1, &tex);

	return true;
}
Esempio n. 25
0
enum piglit_result
piglit_display(void)
{
	GLuint tex, tex_src;
	bool pass;
	int level;
	unsigned bw, bh, bs;

	piglit_get_compressed_block_size(format->token, &bw, &bh, &bs);
	glClearColor(0.5, 0.5, 0.5, 0.5);
	glClear(GL_COLOR_BUFFER_BIT);

	tex_src = piglit_rgbw_texture(format->token, SIZE, SIZE,
				      true, false,
				      GL_UNSIGNED_NORMALIZED);
	glCreateTextures(GL_TEXTURE_2D, 1, &tex);

	for (level = 0; (SIZE >> level) > 0; level++) {
		int w, h;
		int expected_size, size;
		void *compressed;

		w = SIZE >> level;
		h = SIZE >> level;
		expected_size = piglit_compressed_image_size(format->token, w, h);

		glBindTexture(GL_TEXTURE_2D, tex_src);
		glGetTexLevelParameteriv(GL_TEXTURE_2D, level,
					 GL_TEXTURE_COMPRESSED_IMAGE_SIZE,
					 &size);

		if (size != expected_size) {
			fprintf(stderr, "Format %s level %d (%dx%d) size %d "
				"doesn't match expected size %d\n",
				piglit_get_gl_enum_name(format->token),
				level, w, h, size, expected_size);
			piglit_report_result(PIGLIT_FAIL);
		}

		compressed = malloc(size);

		glGetCompressedTextureImage(tex_src, level, size, compressed);

		glBindTexture(GL_TEXTURE_2D, tex);
		glCompressedTexImage2D(GL_TEXTURE_2D, level, format->token,
				       w, h, 0, size, compressed);
		if (!piglit_check_gl_error(GL_NO_ERROR))
			piglit_report_result(PIGLIT_FAIL);

		free(compressed);
	}

	glDeleteTextures(1, &tex_src);
	glBindTextureUnit(tex, 0);

	display_mipmaps(10, 10);
	pass = check_resulting_mipmaps(10, 10);

	piglit_present_results();

	return pass ? PIGLIT_PASS : PIGLIT_FAIL;
}
Esempio n. 26
0
PIGLIT_GL_TEST_CONFIG_END

/** Test texture size errors and subtexture position errors */
static bool
test_pos_and_sizes(void)
{
	bool pass = true;
	GLuint name;

	/* all of these should generate GL_INVALID_VALUE */
	glTexImage1D(GL_TEXTURE_1D, 0, GL_RGBA, -16, 0, GL_RGBA, GL_FLOAT, NULL);
	pass = piglit_check_gl_error(GL_INVALID_VALUE) && pass;

	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, -6, -5, 0, GL_RGBA, GL_FLOAT, NULL);
	pass = piglit_check_gl_error(GL_INVALID_VALUE) && pass;

	glTexImage2D(GL_TEXTURE_2D, -2, GL_RGBA, 16, 16, 0, GL_RGBA, GL_FLOAT, NULL);
	pass = piglit_check_gl_error(GL_INVALID_VALUE) && pass;

	glTexImage2D(GL_TEXTURE_2D, 2000, GL_RGBA, 16, 16, 0, GL_RGBA, GL_FLOAT, NULL);
	pass = piglit_check_gl_error(GL_INVALID_VALUE) && pass;

	/* Setup dsa. */
	glCreateTextures(GL_TEXTURE_2D, 1, &name);
	glBindTextureUnit(0, name);	/* Since next command isn't bindless. */

	/* setup valid 2D texture for subsequent TexSubImage calls */
	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_FLOAT, NULL);

	glTextureSubImage2D(name, 0, 6, 6, 100, 100, GL_RGBA, GL_FLOAT, NULL);
	pass = piglit_check_gl_error(GL_INVALID_VALUE) && pass;

	glTextureSubImage2D(name, 0, -6, -6, 10, 10, GL_RGBA, GL_FLOAT, NULL);
	pass = piglit_check_gl_error(GL_INVALID_VALUE) && pass;

	glCopyTextureSubImage2D(name, 0, -6, -6, 2, 2, 10, 10);
	pass = piglit_check_gl_error(GL_INVALID_VALUE) && pass;

	glCopyTextureSubImage2D(name, 0, 6, 6, 2, 2, 200, 200);
	pass = piglit_check_gl_error(GL_INVALID_VALUE) && pass;

	/* mipmap level 1 doesn't exist */
	glTextureSubImage2D(name, 1, 0, 0, 8, 8, GL_RGBA, GL_FLOAT, NULL);
	pass = piglit_check_gl_error(GL_INVALID_OPERATION) && pass;

	/* mipmap level 2 doesn't exist */
	glCopyTextureSubImage2D(name, 2, 0, 0, 0, 0, 4, 4);
	pass = piglit_check_gl_error(GL_INVALID_OPERATION) && pass;

	/* To test 1D and 3D entry points, let's try using the wrong functions. */
	glTextureSubImage1D(name, 0, 0, 4, GL_RGBA, GL_FLOAT, NULL);
	pass = piglit_check_gl_error(GL_INVALID_ENUM) && pass;

	glTextureSubImage3D(name, 0, 0, 0, 0, 4, 4, 4, GL_RGBA, GL_FLOAT, NULL);
	pass = piglit_check_gl_error(GL_INVALID_ENUM) && pass;

	glCopyTextureSubImage1D(name, 0, 0, 0, 0, 4);
	pass = piglit_check_gl_error(GL_INVALID_ENUM) && pass;

	glCopyTextureSubImage3D(name, 0, 0, 0, 0, 0, 0, 4, 4);
	pass = piglit_check_gl_error(GL_INVALID_ENUM) && pass;

	return pass;
}
Esempio n. 27
0
File: uv.cpp Progetto: dormon/FitGL
int main(int /*argc*/, char ** /*argv*/) {
	BaseApp app;
	ProgramObject programEnv, program;

	auto mainWindow = app.getMainWindow();

	PerspectiveCamera cam;
	OrbitManipulator manipulator(&cam);
	manipulator.setupCallbacks(app);
	manipulator.setZoom(3);
	
	GLuint diffuseTexture;
	GLuint specularTexture;

	GLuint vao;
	GLuint vaoEmpty;
	GLuint vbo;

	int32_t sphereSizeX = 20;
	int32_t sphereSizeY = 20;

	app.addInitCallback([&]() {
		std::string prefix = app.getResourceDir() + "Shaders/Tutorial/";
		auto vs = compileShader(GL_VERTEX_SHADER,
			"#version 450\n",
			Loader::text(prefix + "uv.vp"));
		auto fs = compileShader(GL_FRAGMENT_SHADER,
			"#version 450\n",
			Loader::text(prefix + "lighting.vp"),
			Loader::text(prefix + "uv.fp"));
		program = createProgram(vs, fs);
		
		std::string texPrefix = app.getResourceDir() + "Textures/Tutorial/";
		diffuseTexture = Loader::texture(texPrefix + "earth.png");
		specularTexture = Loader::texture(texPrefix + "earth_s.png");

		glCreateBuffers(1, &vbo);
		const uint32_t floatsPerVertex = 6;
		const uint32_t vertiesPerFace = 6;
		float*vertices = new float[sphereSizeX*sphereSizeY*vertiesPerFace*floatsPerVertex];
		for (int32_t y = 0; y<sphereSizeY; ++y) {
			for (int32_t x = 0; x<sphereSizeX; ++x) {
				for (uint32_t k = 0; k<vertiesPerFace; ++k) {
					const int32_t xOffset[] = { 0,1,0,0,1,1 };
					const int32_t yOffset[] = { 0,0,1,1,0,1 };
					float u = (float)(x + xOffset[k]) / sphereSizeX;
					float v = (float)(y + yOffset[k]) / sphereSizeY;
					float xAngle = -u*glm::two_pi<float>();
					float yAngle = v*glm::pi<float>();
					uint32_t faceId = y*sphereSizeX + x;
					uint32_t faceVertex = faceId*vertiesPerFace + k;
					vertices[faceVertex*floatsPerVertex + 0] = glm::cos(xAngle)*glm::sin(yAngle);
					vertices[faceVertex*floatsPerVertex + 1] = -glm::cos(yAngle);
					vertices[faceVertex*floatsPerVertex + 2] = glm::sin(xAngle)*glm::sin(yAngle);
					vertices[faceVertex*floatsPerVertex + 3] = 1;
					vertices[faceVertex*floatsPerVertex + 4] = u;
					vertices[faceVertex*floatsPerVertex + 5] = v;
				}
			}
		}
		glNamedBufferData(vbo, sizeof(float)*sphereSizeX*sphereSizeY*vertiesPerFace*floatsPerVertex, vertices, GL_STATIC_DRAW);
		delete[]vertices;

		glCreateVertexArrays(1, &vao);
		glEnableVertexArrayAttrib(vao, 0); 
		glVertexArrayAttribFormat(vao, 0, 4, GL_FLOAT, 0, 0); 
		glVertexArrayVertexBuffer(vao, 0, vbo, 0, sizeof(float)*floatsPerVertex);
		glEnableVertexArrayAttrib(vao, 1);
		glVertexArrayAttribFormat(vao, 1, 2, GL_FLOAT, 0, 0);
		glVertexArrayVertexBuffer(vao, 1, vbo, sizeof(float) * 4, sizeof(float)*floatsPerVertex);
		
		glClearColor(0, 0, 0, 1);
		glDisable(GL_CULL_FACE);
		glEnable(GL_DEPTH_TEST);
		glDepthFunc(GL_LEQUAL);
		glEnable(GL_TEXTURE_CUBE_MAP_SEAMLESS);
	});

	app.addResizeCallback([&](int w, int h) {
		glViewport(0, 0, w, h);
		cam.setAspect(float(w) / float(h));
	});

	app.addDrawCallback([&]() {
		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
		program.use();
		glBindTextureUnit(0, diffuseTexture);
		glBindTextureUnit(1, specularTexture);

		program.setMatrix4fv("p", value_ptr(cam.getProjection()));
		program.setMatrix4fv("v", value_ptr(cam.getView()));

		glBindVertexArray(vao);
		glDrawArrays(GL_TRIANGLES, 0, sphereSizeX*sphereSizeY * 6);
		glBindVertexArray(0);
	});
	return app.run();
}
Esempio n. 28
0
void Texture::bind(int unit) const {
	glBindTextureUnit(unit, name);
}
Esempio n. 29
0
/* XXX: Is this actually a valid implementation? */
static bool
test_multisample(void)
{
	bool pass = true;
	static const GLfloat f = 1.0;
	static const GLint i = -1;
	static const GLfloat fvec[2] = { 1.0, -1.0 };
	static const GLint ivec[2] = { 1, -1 };
	static const GLuint uvec[2] = { 1, 4 };
	GLuint name;

	/* GL_TEXTURE_2D_MULTISAMPLE_ARRAY */
	glCreateTextures(GL_TEXTURE_2D_MULTISAMPLE_ARRAY, 1, &name);
	glBindTextureUnit(0, name);	/* Since next command isn't bindless. */

	glTextureParameteri(name, GL_TEXTURE_WRAP_R, i);
	pass = piglit_check_gl_error(GL_INVALID_ENUM) && pass;

	glTextureParameterf(name, GL_TEXTURE_WRAP_R, f);
	pass = piglit_check_gl_error(GL_INVALID_ENUM) && pass;

	glTextureParameterfv(name, GL_TEXTURE_WRAP_R, fvec);
	pass = piglit_check_gl_error(GL_INVALID_ENUM) && pass;

	glTextureParameteriv(name, GL_TEXTURE_WRAP_R, ivec);
	pass = piglit_check_gl_error(GL_INVALID_ENUM) && pass;

	glTextureParameterIiv(name, GL_TEXTURE_WRAP_R, ivec);
	pass = piglit_check_gl_error(GL_INVALID_ENUM) && pass;

	glTextureParameterIuiv(name, GL_TEXTURE_WRAP_R, uvec);
	pass = piglit_check_gl_error(GL_INVALID_ENUM) && pass;

	/* GL_TEXTURE_2D_MULTISAMPLE */
	glDeleteTextures(1, &name);
	glCreateTextures(GL_TEXTURE_2D_MULTISAMPLE, 1, &name);
	glBindTextureUnit(0, name);	/* Since next command isn't bindless. */

	glTextureParameteri(name, GL_TEXTURE_WRAP_R, i);
	pass = piglit_check_gl_error(GL_INVALID_ENUM) && pass;

	glTextureParameterf(name, GL_TEXTURE_WRAP_R, f);
	pass = piglit_check_gl_error(GL_INVALID_ENUM) && pass;

	glTextureParameterfv(name, GL_TEXTURE_WRAP_R, fvec);
	pass = piglit_check_gl_error(GL_INVALID_ENUM) && pass;

	glTextureParameteriv(name, GL_TEXTURE_WRAP_R, ivec);
	pass = piglit_check_gl_error(GL_INVALID_ENUM) && pass;

	glTextureParameterIiv(name, GL_TEXTURE_WRAP_R, ivec);
	pass = piglit_check_gl_error(GL_INVALID_ENUM) && pass;

	glTextureParameterIuiv(name, GL_TEXTURE_WRAP_R, uvec);
	pass = piglit_check_gl_error(GL_INVALID_ENUM) && pass;

	piglit_report_subtest_result(pass ? PIGLIT_PASS : PIGLIT_FAIL,
				     "glTextureParameter: GL_INVALID_ENUM if "
				     "multisample+sampler state");
	return pass;
}
Esempio n. 30
0
/**
 * Per issue 27 of the spec, only sized internalFormat values are allowed.
 * Ex: GL_RGBA8 is OK but GL_RGBA is illegal.
 * Check some common formats here.  These lists aren't exhaustive since
 * there are many extensions/versions that could effect the lists (ex:
 * integer formats, etc.)
 */
static bool
test_internal_formats(void)
{
	const GLenum target = GL_TEXTURE_2D;
	static const GLenum legal_formats[] = {
		GL_RGB4,
		GL_RGB5,
		GL_RGB8,
		GL_RGBA2,
		GL_RGBA4,
		GL_RGBA8,
		GL_DEPTH_COMPONENT16,
		GL_DEPTH_COMPONENT32
	};
	static const GLenum illegal_formats[] = {
		GL_ALPHA,
		GL_LUMINANCE,
		GL_LUMINANCE_ALPHA,
		GL_INTENSITY,
		GL_RGB,
		GL_RGBA,
		GL_DEPTH_COMPONENT,
		GL_COMPRESSED_ALPHA,
		GL_COMPRESSED_LUMINANCE_ALPHA,
		GL_COMPRESSED_LUMINANCE,
		GL_COMPRESSED_INTENSITY,
		GL_COMPRESSED_RGB,
		GL_COMPRESSED_RGBA,
		GL_COMPRESSED_RGBA,
		GL_COMPRESSED_SRGB,
		GL_COMPRESSED_SRGB_ALPHA,
		GL_COMPRESSED_SLUMINANCE,
		GL_COMPRESSED_SLUMINANCE_ALPHA
	};
	GLuint tex;
	bool pass = true;
	int i;

	for (i = 0; i < ARRAY_SIZE(legal_formats); i++) {
		glCreateTextures(target, 1, &tex);
		glBindTextureUnit(0, tex);

		glTextureStorage2D(tex, 1, legal_formats[i], 32, 32);

		if (!piglit_check_gl_error(GL_NO_ERROR)) {
			printf("%s: internal format %s should be legal"
			       " but raised an error.",
			       TestName,
			       piglit_get_gl_enum_name(legal_formats[i]));
			pass = false;
		}

		glDeleteTextures(1, &tex);
	}

	/* Return early if KHR_no_error is enabled */
	if (piglit_khr_no_error)
		return pass;

	for (i = 0; i < ARRAY_SIZE(illegal_formats); i++) {
		glCreateTextures(target, 1, &tex);
		glBindTextureUnit(0, tex);

		glTextureStorage2D(tex, 1, illegal_formats[i], 32, 32);

		if (!piglit_check_gl_error(GL_INVALID_ENUM)) {
			printf("%s: internal format %s should be illegal"
			       " but didn't raised an error.",
			       TestName,
			       piglit_get_gl_enum_name(illegal_formats[i]));
			pass = false;
		}

		glDeleteTextures(1, &tex);
	}

	return pass;
}