Ejemplo n.º 1
2
	//[-------------------------------------------------------]
	//[ Public methods                                        ]
	//[-------------------------------------------------------]
	TextureBufferDsa::TextureBufferDsa(OpenGLRenderer &openGLRenderer, uint32_t numberOfBytes, Renderer::TextureFormat::Enum textureFormat, const void *data, Renderer::BufferUsage bufferUsage) :
		TextureBuffer(openGLRenderer)
	{
		if (openGLRenderer.getExtensions().isGL_ARB_direct_state_access())
		{
			{ // Buffer part
				// Create the OpenGL texture buffer
				glCreateBuffers(1, &mOpenGLTextureBuffer);

				// Upload the data
				// -> Usage: These constants directly map to "GL_ARB_vertex_buffer_object" and OpenGL ES 2 constants, do not change them
				glNamedBufferData(mOpenGLTextureBuffer, static_cast<GLsizeiptr>(numberOfBytes), data, static_cast<GLenum>(bufferUsage));
			}

			{ // Texture part
				// Create the OpenGL texture instance
				glCreateTextures(GL_TEXTURE_BUFFER_ARB, 1, &mOpenGLTexture);

				// Attach the storage for the buffer object to the buffer texture
				glTextureBuffer(mOpenGLTexture, Mapping::getOpenGLInternalFormat(textureFormat), mOpenGLTextureBuffer);
			}
		}
		else
		{
			// Create the OpenGL texture buffer
			glGenBuffersARB(1, &mOpenGLTextureBuffer);

			// Create the OpenGL texture instance
			glGenTextures(1, &mOpenGLTexture);

			// Buffer part
			// -> Upload the data
			// -> Usage: These constants directly map to "GL_ARB_vertex_buffer_object" and OpenGL ES 2 constants, do not change them
			glNamedBufferDataEXT(mOpenGLTextureBuffer, static_cast<GLsizeiptr>(numberOfBytes), data, static_cast<GLenum>(bufferUsage));

			{ // Texture part
				#ifndef OPENGLRENDERER_NO_STATE_CLEANUP
					// Backup the currently bound OpenGL texture
					GLint openGLTextureBackup = 0;
					glGetIntegerv(GL_TEXTURE_BINDING_BUFFER_ARB, &openGLTextureBackup);
				#endif

				// Make this OpenGL texture instance to the currently used one
				glBindTexture(GL_TEXTURE_BUFFER_ARB, mOpenGLTexture);

				// Attaches the storage for the buffer object to the active buffer texture
				// -> Sadly, there's no direct state access (DSA) function defined for this in "GL_EXT_direct_state_access"
				glTexBufferARB(GL_TEXTURE_BUFFER_ARB, Mapping::getOpenGLInternalFormat(textureFormat), mOpenGLTextureBuffer);

				#ifndef OPENGLRENDERER_NO_STATE_CLEANUP
					// Be polite and restore the previous bound OpenGL texture
					glBindTexture(GL_TEXTURE_BUFFER_ARB, static_cast<GLuint>(openGLTextureBackup));
				#endif
			}
		}
	}
Ejemplo n.º 2
0
	bool initTexture()
	{
		bool Validated(true);

		gli::gl GL;
		gli::texture2d Texture(gli::load_dds((getDataDirectory() + TEXTURE_DIFFUSE).c_str()));
		gli::gl::format const Format = GL.translate(Texture.format());

		glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

		glCreateTextures(GL_TEXTURE_2D_ARRAY, 1, &TextureName);
		glTextureParameteri(TextureName, GL_TEXTURE_SWIZZLE_R, GL_RED);
		glTextureParameteri(TextureName, GL_TEXTURE_SWIZZLE_G, GL_GREEN);
		glTextureParameteri(TextureName, GL_TEXTURE_SWIZZLE_B, GL_BLUE);
		glTextureParameteri(TextureName, GL_TEXTURE_SWIZZLE_A, GL_ALPHA);
		glTextureParameteri(TextureName, GL_TEXTURE_BASE_LEVEL, 0);
		glTextureParameteri(TextureName, GL_TEXTURE_MAX_LEVEL, static_cast<GLint>(Texture.levels() - 1));
		glTextureParameteri(TextureName, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
		glTextureParameteri(TextureName, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

		glTextureStorage3D(TextureName, static_cast<GLint>(Texture.levels()),
			Format.Internal,
			static_cast<GLsizei>(Texture[0].extent().x), static_cast<GLsizei>(Texture[0].extent().y), static_cast<GLsizei>(1));

		for(gli::texture2d::size_type Level = 0; Level < Texture.levels(); ++Level)
		{
			glTextureSubImage3D(TextureName, static_cast<GLint>(Level),
				0, 0, 0,
				static_cast<GLsizei>(Texture[Level].extent().x), static_cast<GLsizei>(Texture[Level].extent().y), static_cast<GLsizei>(1),
				Format.External, Format.Type,
				Texture[Level].data());
		}
	
		return Validated;
	}
	bool initTexture()
	{
		gli::texture2d Texture(gli::load(getDataDirectory() + TEXTURE_DIFFUSE));
		if(Texture.empty())
			return 0;

		gli::gl GL(gli::gl::PROFILE_GL33);
		gli::gl::format const Format = GL.translate(Texture.format(), Texture.swizzles());
		GLenum const Target = GL.translate(Texture.target());
		glm::tvec2<GLsizei> const Dimensions(Texture.extent());

		glCreateTextures(GL_TEXTURE_2D, 1, &TextureName[texture::TEXTURE]);
		glTextureParameteri(TextureName[texture::TEXTURE], GL_TEXTURE_BASE_LEVEL, 0);
		glTextureParameteri(TextureName[texture::TEXTURE], GL_TEXTURE_MAX_LEVEL, static_cast<GLint>(Texture.levels() - 1));
		glTextureParameteri(TextureName[texture::TEXTURE], GL_TEXTURE_SWIZZLE_R, Format.Swizzles[0]);
		glTextureParameteri(TextureName[texture::TEXTURE], GL_TEXTURE_SWIZZLE_G, Format.Swizzles[1]);
		glTextureParameteri(TextureName[texture::TEXTURE], GL_TEXTURE_SWIZZLE_B, Format.Swizzles[2]);
		glTextureParameteri(TextureName[texture::TEXTURE], GL_TEXTURE_SWIZZLE_A, Format.Swizzles[3]);
		glTextureStorage2D(TextureName[texture::TEXTURE],
			static_cast<GLint>(Texture.levels()), Format.Internal,
			Dimensions.x, Texture.target() == gli::TARGET_2D ? Dimensions.y : static_cast<GLsizei>(Texture.layers() * Texture.faces()));

		for(gli::texture2d::size_type Level = 0; Level < Texture.levels(); ++Level)
		{
			glTextureSubImage2D(TextureName[texture::TEXTURE], static_cast<GLint>(Level),
				0, 0,
				static_cast<GLsizei>(Texture[Level].extent().x), static_cast<GLsizei>(Texture[Level].extent().y),
				Format.External, Format.Type,
				Texture[Level].data());
		}


		glCreateTextures(GL_TEXTURE_2D_MULTISAMPLE, 1, &TextureName[texture::MULTISAMPLE]);
		glTextureParameteri(TextureName[texture::MULTISAMPLE], GL_TEXTURE_BASE_LEVEL, 0);
		glTextureParameteri(TextureName[texture::MULTISAMPLE], GL_TEXTURE_MAX_LEVEL, 0);
		glTextureStorage2DMultisample(TextureName[texture::MULTISAMPLE], 4, GL_RGBA8, FRAMEBUFFER_SIZE.x, FRAMEBUFFER_SIZE.y, GL_FALSE);

		glCreateTextures(GL_TEXTURE_2D, 1, &TextureName[texture::COLORBUFFER]);
		glTextureParameteri(TextureName[texture::COLORBUFFER], GL_TEXTURE_BASE_LEVEL, 0);
		glTextureParameteri(TextureName[texture::COLORBUFFER], GL_TEXTURE_MAX_LEVEL, 0);
		glTextureStorage2D(TextureName[texture::COLORBUFFER], 1, GL_RGBA8, GLsizei(FRAMEBUFFER_SIZE.x), GLsizei(FRAMEBUFFER_SIZE.y));

		return true;
	}
Ejemplo n.º 4
0
kit::Texture::Texture(Type t)
{
#ifndef KIT_SHITTY_INTEL
    glCreateTextures(t, 1, &m_glHandle);
#else
    glGenTextures(1, &m_glHandle);
#endif

    m_type = t;
}
enum piglit_result
piglit_display(void)
{
	bool pass = true;
	GLuint name;

	/* Throw some invalid inputs at glCreateTextures. */

	/* Invalid (not a target) */
	glCreateTextures(GL_INVALID_ENUM, 1, &name);
	pass &= piglit_check_gl_error(GL_INVALID_ENUM);

	/* Invalid (not supported) target */
	glCreateTextures(GL_PROXY_TEXTURE_2D, 1, &name);
	pass &= piglit_check_gl_error(GL_INVALID_ENUM);

	/* n is negative */
	glCreateTextures(GL_TEXTURE_2D, -1, &name);
	pass &= piglit_check_gl_error(GL_INVALID_VALUE);

	/* name is not a valid pointer */
	glCreateTextures(GL_TEXTURE_2D, 1, 0);
	pass &= piglit_check_gl_error(GL_NO_ERROR);
	glCreateTextures(GL_TEXTURE_2D, 1, NULL);
	pass &= piglit_check_gl_error(GL_NO_ERROR);

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

	return pass ? PIGLIT_PASS : PIGLIT_FAIL;
}
Ejemplo n.º 6
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;
}
Ejemplo n.º 7
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;
}
	bool initTexture()
	{
		gli::texture2d Texture(gli::load_dds((getDataDirectory() + TEXTURE_DIFFUSE).c_str()));
		if(Texture.empty())
			return false;

		gli::gl GL;
		gli::gl::format const Format = GL.translate(Texture.format());

		glCreateTextures(GL_TEXTURE_2D, 1, &TextureName[texture::TEXTURE]);
		glTextureParameteri(TextureName[texture::TEXTURE], GL_TEXTURE_BASE_LEVEL, 0);
		glTextureParameteri(TextureName[texture::TEXTURE], GL_TEXTURE_MAX_LEVEL, static_cast<GLint>(Texture.levels() - 1));
		glTextureParameteri(TextureName[texture::TEXTURE], GL_TEXTURE_MIN_FILTER, GL_NEAREST);
		glTextureParameteri(TextureName[texture::TEXTURE], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
		glTextureStorage2D(TextureName[texture::TEXTURE], GLint(Texture.levels()), Format.Internal, GLsizei(Texture[0].extent().x), GLsizei(Texture[0].extent().y));
		for(std::size_t Level = 0; Level < Texture.levels(); ++Level)
		{
			glTextureSubImage2D(TextureName[texture::TEXTURE], GLint(Level),
				0, 0, 
				GLsizei(Texture[Level].extent().x), GLsizei(Texture[Level].extent().y),
				Format.External, Format.Type,
				Texture[Level].data());
		}

		glCreateTextures(GL_TEXTURE_2D_MULTISAMPLE, 1, &TextureName[texture::MULTISAMPLE]);
		glTextureParameteri(TextureName[texture::MULTISAMPLE], GL_TEXTURE_BASE_LEVEL, 0);
		glTextureParameteri(TextureName[texture::MULTISAMPLE], GL_TEXTURE_MAX_LEVEL, 0);
		glTextureStorage2DMultisample(TextureName[texture::MULTISAMPLE], 4, GL_RGBA8, FRAMEBUFFER_SIZE.x, FRAMEBUFFER_SIZE.y, GL_FALSE);

		glCreateTextures(GL_TEXTURE_2D, 1, &TextureName[texture::COLORBUFFER]);
		glTextureParameteri(TextureName[texture::COLORBUFFER], GL_TEXTURE_BASE_LEVEL, 0);
		glTextureParameteri(TextureName[texture::COLORBUFFER], GL_TEXTURE_MAX_LEVEL, 0);
		glTextureStorage2D(TextureName[texture::COLORBUFFER], 1, GL_RGBA8, GLsizei(FRAMEBUFFER_SIZE.x), GLsizei(FRAMEBUFFER_SIZE.y));

		return true;
	}
Ejemplo n.º 9
0
kit::Texture::Texture(Type t)
{
  KIT_GL(glCreateTextures(t, 1, &this->m_glHandle));

  this->m_arraySize = 0;  
  this->m_edgeSamplingModeS = kit::Texture::Repeat;
  this->m_edgeSamplingModeT = kit::Texture::Repeat;
  this->m_edgeSamplingModeR = kit::Texture::Repeat;
  this->m_internalFormat = RGBA8;
  this->m_magFilteringMode = kit::Texture::Linear;
  this->m_minFilteringMode = kit::Texture::LinearMipmapLinear;
  this->m_resolution = glm::uvec3(0, 0, 0);
  this->m_type = t;
  this->m_anisotropicLevel = 8.0f;
}
	bool initTexture()
	{
		gli::texture2d Texture(gli::load_dds((getDataDirectory() + TEXTURE_DIFFUSE).c_str()));
		assert(!Texture.empty());

		glm::uvec2 FramebufferSize(this->getWindowSize() / 16u);

		glCreateTextures(GL_TEXTURE_2D_ARRAY, texture::MAX, &TextureName[0]);
		glTextureParameteri(TextureName[0], GL_TEXTURE_BASE_LEVEL, 0);
		glTextureParameteri(TextureName[0], GL_TEXTURE_MAX_LEVEL, 0);
		glTextureParameteri(TextureName[0], GL_TEXTURE_MIN_FILTER, GL_NEAREST);
		glTextureParameteri(TextureName[0], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
		glTextureStorage3D(TextureName[0], GLint(1), GL_RGBA8, GLsizei(FramebufferSize.x), GLsizei(FramebufferSize.y), 1);

		return true;
	}
Ejemplo n.º 11
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;
}
	bool initTexture()
	{
		bool Validated(true);

		gli::gl GL(gli::gl::PROFILE_GL33);
		gli::texture2d Texture(gli::load_dds((getDataDirectory() + TEXTURE_DIFFUSE).c_str()));
		assert(!Texture.empty());
		gli::gl::format const Format = GL.translate(Texture.format(), Texture.swizzles());

		glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

		glCreateTextures(GL_TEXTURE_2D, texture::MAX, &TextureName[0]);
		glTextureParameteri(TextureName[texture::DIFFUSE], GL_TEXTURE_BASE_LEVEL, 0);
		glTextureParameteri(TextureName[texture::DIFFUSE], GL_TEXTURE_MAX_LEVEL, GLint(Texture.levels() - 1));
		glTextureParameteri(TextureName[texture::DIFFUSE], GL_TEXTURE_SWIZZLE_R, GL_RED);
		glTextureParameteri(TextureName[texture::DIFFUSE], GL_TEXTURE_SWIZZLE_G, GL_GREEN);
		glTextureParameteri(TextureName[texture::DIFFUSE], GL_TEXTURE_SWIZZLE_B, GL_BLUE);
		glTextureParameteri(TextureName[texture::DIFFUSE], GL_TEXTURE_SWIZZLE_A, GL_ALPHA);
		glTextureParameteri(TextureName[texture::DIFFUSE], GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
		glTextureParameteri(TextureName[texture::DIFFUSE], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
		glTextureStorage2D(TextureName[texture::DIFFUSE], static_cast<GLint>(Texture.levels()), Format.Internal,
			static_cast<GLsizei>(Texture.extent().x), static_cast<GLsizei>(Texture.extent().y));

		for(std::size_t Level = 0; Level < Texture.levels(); ++Level)
		{
			glTextureSubImage2D(TextureName[texture::DIFFUSE], static_cast<GLint>(Level),
				0, 0,
				static_cast<GLsizei>(Texture[Level].extent().x), static_cast<GLsizei>(Texture[Level].extent().y),
				Format.External, Format.Type,
				Texture[Level].data());
		}
	
		glm::ivec2 WindowSize(this->getWindowSize());

		glTextureParameteri(TextureName[texture::COLORBUFFER], GL_TEXTURE_BASE_LEVEL, 0);
		glTextureParameteri(TextureName[texture::COLORBUFFER], GL_TEXTURE_MAX_LEVEL, 0);
		glTextureParameteri(TextureName[texture::COLORBUFFER], GL_TEXTURE_MIN_FILTER, GL_NEAREST);
		glTextureParameteri(TextureName[texture::COLORBUFFER], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
		glTextureStorage2D(TextureName[texture::COLORBUFFER], static_cast<GLint>(1), GL_RGBA8,
			static_cast<GLsizei>(WindowSize.x * this->Supersampling), static_cast<GLsizei>(WindowSize.y * this->Supersampling));

		return Validated;
	}
Ejemplo n.º 13
0
void
piglit_init(int argc, char **argv)
{
	int i;
	piglit_require_extension("GL_ARB_direct_state_access");
	piglit_require_extension("GL_ARB_texture_storage");

	for(i = 0; i < 4096; ++i)
		data[i] = rand() & 0xff;

	glCreateTextures(GL_TEXTURE_2D, 1, &name);
	glTextureParameteri(name, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	glTextureParameteri(name, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	glTextureStorage2D(name, 1, GL_RGBA8, 64, 16);
	glTextureSubImage2D(name, 0, 0, 0, 64, 16, GL_RGBA, GL_UNSIGNED_BYTE,
			    data);

	piglit_gen_ortho_projection(0.0, 1.0, 0.0, 1.0, -2.0, 6.0, GL_FALSE);
}
Ejemplo n.º 14
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;
}
Ejemplo n.º 15
0
GLuint LoadTexture(WORD resourceId)
{
    HRSRC hrsrc = FindResource(
        nullptr, MAKEINTRESOURCE(resourceId), RT_BITMAP);
    HGLOBAL hglobal = LoadResource(nullptr, hrsrc);
    const GLbyte *data = static_cast<const GLbyte *>(LockResource(hglobal));

    const int width = *reinterpret_cast<const int *>(data + 4);
    const int height = *reinterpret_cast<const int *>(data + 8);

    GLuint texture;
    glCreateTextures(GL_TEXTURE_2D, 1, &texture);
    glTextureStorage2D(texture, 1, GL_RGB8, width, height);
    glTextureSubImage2D(texture, 0, 0, 0, width, height, GL_BGR, GL_UNSIGNED_BYTE, data + 40);

    glTextureParameteri(texture, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTextureParameteri(texture, GL_TEXTURE_MIN_FILTER, GL_LINEAR);

    return texture;
}
Ejemplo n.º 16
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;
}
	bool initTexture()
	{
		bool Validated(true);

		gli::gl GL(gli::gl::PROFILE_GL33);

		gli::texture2d Texture(gli::load_dds((getDataDirectory() + TEXTURE_DIFFUSE).c_str()));
		assert(!Texture.empty());

		gli::gl::format const Format = GL.translate(Texture.format(), Texture.swizzles());

		glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
		glCreateTextures(GL_TEXTURE_2D_ARRAY, 1, &TextureName);
		glTextureParameteri(TextureName, GL_TEXTURE_SWIZZLE_R, Format.Swizzles[0]);
		glTextureParameteri(TextureName, GL_TEXTURE_SWIZZLE_G, Format.Swizzles[1]);
		glTextureParameteri(TextureName, GL_TEXTURE_SWIZZLE_B, Format.Swizzles[2]);
		glTextureParameteri(TextureName, GL_TEXTURE_SWIZZLE_A, Format.Swizzles[3]);
		glTextureParameteri(TextureName, GL_TEXTURE_BASE_LEVEL, 0);
		glTextureParameteri(TextureName, GL_TEXTURE_MAX_LEVEL, GLint(Texture.levels() - 1));
		glTextureParameteri(TextureName, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
		glTextureParameteri(TextureName, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
		glTextureStorage3D(TextureName, static_cast<GLint>(Texture.levels()), Format.Internal,
			static_cast<GLsizei>(Texture.extent().x), static_cast<GLsizei>(Texture.extent().y), 1);

		for(gli::texture2d::size_type Level(0); Level < Texture.levels(); ++Level)
		{
			glTextureSubImage3D(TextureName, static_cast<GLint>(Level),
				0, 0, 0,
				static_cast<GLsizei>(Texture[Level].extent().x), static_cast<GLsizei>(Texture[Level].extent().y), 1,
				Format.External, Format.Type,
				Texture[Level].data());
		}

		glPixelStorei(GL_UNPACK_ALIGNMENT, 4);

		// Query the texture handle and make the texture resident
		TextureHandle = glGetTextureHandleNV(TextureName);
		glMakeTextureHandleResidentNV(TextureHandle);

		return Validated;
	}
GLuint glCreateTextureGTC(GLenum target, GLsizei layers, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLsizei samples, GLboolean fixedsamplelocations)
{
	GLuint texture = 0;
	glCreateTextures(target, 1, &texture);
	glTextureParameteri(texture, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
	glTextureParameteri(texture, GL_TEXTURE_MAG_FILTER, GL_NEAREST);

	switch (target)
	{
	case GL_TEXTURE_2D:
		assert(layers == 1 && width >= 1 && height >= 1 && depth == 1 && samples == 1 && fixedsamplelocations == GL_TRUE);
		glTextureStorage2D(texture, levels, internalformat, width, height);
		break;
	case GL_TEXTURE_2D_ARRAY:
		assert(layers >= 1 && width >= 1 && height >= 1 && depth == 1 && samples == 1 && fixedsamplelocations == GL_TRUE);
		glTextureStorage3D(texture, levels, internalformat, width, height, layers);
		break;
	case GL_TEXTURE_2D_MULTISAMPLE:
		assert(layers == 1 && width >= 1 && height >= 1 && depth == 1 && samples >= 1);
		glTextureStorage2DMultisample(texture, samples, internalformat, width, height, fixedsamplelocations);
		break;
	case GL_TEXTURE_2D_MULTISAMPLE_ARRAY:
		assert(layers >= 1 && width >= 1 && height >= 1 && depth == 1 && samples >= 1);
		glTextureStorage3DMultisample(texture, samples, internalformat, width, height, layers, fixedsamplelocations);
		break;
	case GL_TEXTURE_3D:
		assert(layers == 1 && width >= 1 && height >= 1 && depth >= 1 && samples == 1 && fixedsamplelocations == GL_TRUE);
		glTextureStorage3D(texture, levels, internalformat, width, height, depth);
		break;
	case GL_TEXTURE_CUBE_MAP:
		assert(layers == 1 && width >= 1 && height >= 1 && depth == 1 && samples == 1 && fixedsamplelocations == GL_TRUE);
		glTextureStorage2D(texture, levels, internalformat, width, height);
		break;
	case GL_TEXTURE_CUBE_MAP_ARRAY:
		assert(layers >= 1 && width >= 1 && height >= 1 && depth == 1 && samples == 1 && fixedsamplelocations == GL_TRUE);
		glTextureStorage3D(texture, levels, internalformat, width, height, layers * 6);
		break;
	}

	return texture;
}
Ejemplo n.º 19
0
static int glnvg__renderCreateTexture(void* uptr, int type, int w, int h, int imageFlags, const unsigned char* data)
{
    GLNVGcontext* gl = (GLNVGcontext*)uptr;
    GLNVGtexture* tex = glnvg__allocTexture(gl);

    if (tex == NULL) return 0;

    const bool formatRGBA8 = type == NVG_TEXTURE_RGBA;
    const bool useMipmaps = (imageFlags & NVG_IMAGE_GENERATE_MIPMAPS) != 0;
    glCreateTextures(GL_TEXTURE_2D, 1, &tex->tex);
    const uint32_t mipCount = useMipmaps ? bit_fls(core::max<uint32_t>(w, h)) : 1;
    glTextureStorage2D(tex->tex, mipCount, formatRGBA8 ? GL_RGBA8 : GL_R8, w, h);
    tex->width = w;
    tex->height = h;
    tex->type = type;


    if (data)
    {
        glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
        glPixelStorei(GL_UNPACK_ROW_LENGTH, tex->width);
        glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
        glPixelStorei(GL_UNPACK_SKIP_ROWS, 0);
        glTextureSubImage2D(tex->tex, 0, 0, 0, w, h, formatRGBA8 ? GL_RGBA : GL_RED, GL_UNSIGNED_BYTE, data);
        glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
        glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
        glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
        glPixelStorei(GL_UNPACK_SKIP_ROWS, 0);
        // The new way to build mipmaps on GLES and GL3
        if (useMipmaps) {
            glGenerateTextureMipmap(tex->tex);
        }
    }

    glTextureParameteri(tex->tex, GL_TEXTURE_MIN_FILTER, useMipmaps ? GL_LINEAR_MIPMAP_LINEAR : GL_LINEAR);
    glTextureParameteri(tex->tex, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

    return tex->id;
}
Ejemplo n.º 20
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;
}
Ejemplo n.º 21
0
Texture::Texture(const GLenum type, const GLvoid* data, const uint_fast32_t width, const uint_fast32_t height, const GLenum data_type)
{
	glCreateTextures(type, 1, &name);

	glBindTexture(type, name);
	glTexImage2D(
		type,
		0,			// level
		GL_RED,		// internal format
		width,
		height,
		0,
		GL_RED,		// format
		data_type,
		data
	);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

	inited = true;
}
Ejemplo n.º 22
0
	bool initTexture()
	{
		glCreateTextures(GL_TEXTURE_2D, texture::MAX, &TextureName[0]);

		glm::vec2 const FramwbufferSize = glm::vec2(this->getWindowSize()) * FRAMEBUFFER_SCALE;

		glTextureParameteri(TextureName[texture::COLORBUFFER], GL_TEXTURE_BASE_LEVEL, 0);
		glTextureParameteri(TextureName[texture::COLORBUFFER], GL_TEXTURE_MAX_LEVEL, 0);
		glTextureParameteri(TextureName[texture::COLORBUFFER], GL_TEXTURE_MIN_FILTER, GL_NEAREST);
		glTextureParameteri(TextureName[texture::COLORBUFFER], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
		glTextureParameteri(TextureName[texture::COLORBUFFER], GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
		glTextureParameteri(TextureName[texture::COLORBUFFER], GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
		glTextureStorage2D(TextureName[texture::COLORBUFFER], GLint(1), GL_RGBA8, GLsizei(FramwbufferSize.x), GLsizei(FramwbufferSize.y));

		glTextureParameteri(TextureName[texture::RENDERBUFFER], GL_TEXTURE_BASE_LEVEL, 0);
		glTextureParameteri(TextureName[texture::RENDERBUFFER], GL_TEXTURE_MAX_LEVEL, 0);
		glTextureStorage2D(TextureName[texture::RENDERBUFFER], GLint(1), GL_DEPTH_COMPONENT24, GLsizei(FramwbufferSize.x), GLsizei(FramwbufferSize.y));

		glTextureParameteri(TextureName[texture::INVOCATION_COUNT], GL_TEXTURE_BASE_LEVEL, 0);
		glTextureParameteri(TextureName[texture::INVOCATION_COUNT], GL_TEXTURE_MAX_LEVEL, 0);
		glTextureStorage2D(TextureName[texture::INVOCATION_COUNT], GLint(1), GL_R32UI, GLsizei(FramwbufferSize.x), GLsizei(FramwbufferSize.y));

		return true;
	}
Ejemplo n.º 23
0
GSTextureOGL::GSTextureOGL(int type, int w, int h, int format, GLuint fbo_read)
	: m_pbo_size(0), m_clean(false), m_local_buffer(NULL), m_r_x(0), m_r_y(0), m_r_w(0), m_r_h(0)
{
	// OpenGL didn't like dimensions of size 0
	m_size.x = max(1,w);
	m_size.y = max(1,h);
	m_format = format;
	m_type   = type;
	m_fbo_read = fbo_read;
	m_texture_id = 0;

	// Bunch of constant parameter
	switch (m_format) {
			// 1 Channel integer
		case GL_R32UI:
		case GL_R32I:
			m_int_format    = GL_RED_INTEGER;
			m_int_type      = (m_format == GL_R32UI) ? GL_UNSIGNED_INT : GL_INT;
			m_int_shift     = 2;
			break;
		case GL_R16UI:
			m_int_format    = GL_RED_INTEGER;
			m_int_type      = GL_UNSIGNED_SHORT;
			m_int_shift     = 1;
			break;

			// 1 Channel normalized
		case GL_R8:
			m_int_format    = GL_RED;
			m_int_type      = GL_UNSIGNED_BYTE;
			m_int_shift     = 0;
			break;

			// 4 channel normalized
		case GL_RGBA16:
			m_int_format    = GL_RGBA;
			m_int_type      = GL_UNSIGNED_SHORT;
			m_int_shift     = 3;
			break;
		case GL_RGBA8:
			m_int_format    = GL_RGBA;
			m_int_type      = GL_UNSIGNED_BYTE;
			m_int_shift     = 2;
			break;

			// 4 channel integer
		case GL_RGBA16I:
		case GL_RGBA16UI:
			m_int_format    = GL_RGBA_INTEGER;
			m_int_type      = (m_format == GL_R16UI) ? GL_UNSIGNED_SHORT : GL_SHORT;
			m_int_shift     = 3;
			break;

			// 4 channel float
		case GL_RGBA32F:
			m_int_format    = GL_RGBA;
			m_int_type      = GL_FLOAT;
			m_int_shift     = 4;
			break;
		case GL_RGBA16F:
			m_int_format    = GL_RGBA;
			m_int_type      = GL_HALF_FLOAT;
			m_int_shift     = 3;
			break;

			// Depth buffer
		case GL_DEPTH32F_STENCIL8:
			m_int_format    = GL_DEPTH_STENCIL;
			m_int_type      = GL_FLOAT_32_UNSIGNED_INT_24_8_REV;
			m_int_shift     = 3; // 4 bytes for depth + 4 bytes for stencil by texels
			break;

			// Backbuffer
		case 0:
			m_int_format    = 0;
			m_int_type      = 0;
			m_int_shift     = 2; // 4 bytes by texels
			break;

		default:
			m_int_format    = 0;
			m_int_type      = 0;
			m_int_shift     = 0;
			ASSERT(0);
	}

	m_mem_usage = (m_size.x * m_size.y) << m_int_shift;

	static int every_512 = 0;
	GLState::available_vram -= m_mem_usage;
	if ((GLState::available_vram < 0) && (every_512 % 512 == 0)) {
		fprintf(stderr, "Available VRAM is very low (%lld), a crash is expected ! Disable Larger framebuffer or reduce upscaling!\n", GLState::available_vram);
		every_512++;
		// Pull emergency break
		throw GSDXErrorOOM();
	}

	// Generate & Allocate the buffer
	switch (m_type) {
		case GSTexture::Offscreen:
			// Offscreen is only used to read color. So it only requires 4B by pixel
			m_local_buffer = (uint8*)_aligned_malloc(m_size.x * m_size.y * 4, 32);
		case GSTexture::Texture:
		case GSTexture::RenderTarget:
		case GSTexture::DepthStencil:
			glCreateTextures(GL_TEXTURE_2D, 1, &m_texture_id);
			glTextureStorage2D(m_texture_id, 1+GL_TEX_LEVEL_0, m_format, m_size.x, m_size.y);
			if (m_format == GL_R8) {
				// Emulate DX behavior, beside it avoid special code in shader to differentiate
				// palette texture from a GL_RGBA target or a GL_R texture.
				glTextureParameteri(m_texture_id, GL_TEXTURE_SWIZZLE_A, GL_RED);
			}
			break;
		case GSTexture::Backbuffer:
		default:
			break;
	}
}
Ejemplo n.º 24
0
GSTextureOGL::GSTextureOGL(int type, int w, int h, int format, GLuint fbo_read, bool mipmap)
	: m_clean(false), m_generate_mipmap(true), m_local_buffer(nullptr), m_r_x(0), m_r_y(0), m_r_w(0), m_r_h(0), m_layer(0)
{
	// OpenGL didn't like dimensions of size 0
	m_size.x = std::max(1,w);
	m_size.y = std::max(1,h);
	m_format = format;
	m_type   = type;
	m_fbo_read = fbo_read;
	m_texture_id = 0;
	m_sparse = false;
	m_max_layer = 1;

	// Bunch of constant parameter
	switch (m_format) {
			// 1 Channel integer
		case GL_R32UI:
		case GL_R32I:
			m_int_format    = GL_RED_INTEGER;
			m_int_type      = (m_format == GL_R32UI) ? GL_UNSIGNED_INT : GL_INT;
			m_int_shift     = 2;
			break;
		case GL_R16UI:
			m_int_format    = GL_RED_INTEGER;
			m_int_type      = GL_UNSIGNED_SHORT;
			m_int_shift     = 1;
			break;

			// 1 Channel normalized
		case GL_R8:
			m_int_format    = GL_RED;
			m_int_type      = GL_UNSIGNED_BYTE;
			m_int_shift     = 0;
			break;

			// 4 channel normalized
		case GL_RGBA16:
			m_int_format    = GL_RGBA;
			m_int_type      = GL_UNSIGNED_SHORT;
			m_int_shift     = 3;
			break;
		case GL_RGBA8:
			m_int_format    = GL_RGBA;
			m_int_type      = GL_UNSIGNED_BYTE;
			m_int_shift     = 2;
			break;

			// 4 channel integer
		case GL_RGBA16I:
		case GL_RGBA16UI:
			m_int_format    = GL_RGBA_INTEGER;
			m_int_type      = (m_format == GL_R16UI) ? GL_UNSIGNED_SHORT : GL_SHORT;
			m_int_shift     = 3;
			break;

			// 4 channel float
		case GL_RGBA32F:
			m_int_format    = GL_RGBA;
			m_int_type      = GL_FLOAT;
			m_int_shift     = 4;
			break;
		case GL_RGBA16F:
			m_int_format    = GL_RGBA;
			m_int_type      = GL_HALF_FLOAT;
			m_int_shift     = 3;
			break;

			// Depth buffer
		case GL_DEPTH32F_STENCIL8:
			m_int_format    = GL_DEPTH_STENCIL;
			m_int_type      = GL_FLOAT_32_UNSIGNED_INT_24_8_REV;
			m_int_shift     = 3; // 4 bytes for depth + 4 bytes for stencil by texels
			break;

			// Backbuffer
		case 0:
			m_int_format    = 0;
			m_int_type      = 0;
			m_int_shift     = 2; // 4 bytes by texels
			break;

		default:
			m_int_format    = 0;
			m_int_type      = 0;
			m_int_shift     = 0;
			ASSERT(0);
	}

	switch (m_type) {
		case GSTexture::Backbuffer:
			return; // backbuffer isn't a real texture
		case GSTexture::Offscreen:
			// Offscreen is only used to read color. So it only requires 4B by pixel
			m_local_buffer = (uint8*)_aligned_malloc(m_size.x * m_size.y * 4, 32);
			break;
		case GSTexture::Texture:
			// Only 32 bits input texture will be supported for mipmap
			m_max_layer = mipmap && m_format == GL_RGBA8 ? (int)log2(std::max(w,h)) : 1;
			break;
		case SparseRenderTarget:
		case SparseDepthStencil:
			m_sparse = true;
			break;
		default:
			break;
	}

	switch (m_format) {
		case GL_R16UI:
		case GL_R8:
			m_sparse &= GLLoader::found_compatible_GL_ARB_sparse_texture2;
			SetGpuPageSize(GSVector2i(255, 255));
			break;

		case GL_R32UI:
		case GL_R32I:
		case GL_RGBA16:
		case GL_RGBA8:
		case GL_RGBA16I:
		case GL_RGBA16UI:
		case GL_RGBA16F:
		case 0:
			m_sparse &= GLLoader::found_compatible_GL_ARB_sparse_texture2;
			SetGpuPageSize(GSVector2i(127, 127));
			break;

		case GL_RGBA32F:
			m_sparse &= GLLoader::found_compatible_GL_ARB_sparse_texture2;
			SetGpuPageSize(GSVector2i(63, 63));
			break;

		case GL_DEPTH32F_STENCIL8:
			m_sparse &= GLLoader::found_compatible_sparse_depth;
			SetGpuPageSize(GSVector2i(127, 127));
			break;

		default:
			ASSERT(0);
	}

	// Create a gl object (texture isn't allocated here)
	glCreateTextures(GL_TEXTURE_2D, 1, &m_texture_id);
	if (m_format == GL_R8) {
		// Emulate DX behavior, beside it avoid special code in shader to differentiate
		// palette texture from a GL_RGBA target or a GL_R texture.
		glTextureParameteri(m_texture_id, GL_TEXTURE_SWIZZLE_A, GL_RED);
	}

	if (m_sparse) {
		GSVector2i old_size = m_size;
		m_size = RoundUpPage(m_size);
		if (m_size != old_size) {
			fprintf(stderr, "Sparse texture size (%dx%d) isn't a multiple of gpu page size (%dx%d)\n",
					old_size.x, old_size.y, m_gpu_page_size.x, m_gpu_page_size.y);
		}
		glTextureParameteri(m_texture_id, GL_TEXTURE_SPARSE_ARB, true);
	} else {
		m_committed_size = m_size;
	}

	m_mem_usage = (m_committed_size.x * m_committed_size.y) << m_int_shift;

	static int every_512 = 0;
	GLState::available_vram -= m_mem_usage;
	if ((GLState::available_vram < 0) && (every_512 % 512 == 0)) {
		fprintf(stderr, "Available VRAM is very low (%lld), a crash is expected ! Disable Larger framebuffer or reduce upscaling!\n", GLState::available_vram);
		every_512++;
		// Pull emergency break
		throw std::bad_alloc();
	}

	glTextureStorage2D(m_texture_id, m_max_layer + GL_TEX_LEVEL_0, m_format, m_size.x, m_size.y);
}
Ejemplo n.º 25
0
bool glPixelBuffer::create(GLushort width, GLushort height, GLushort depth,
                           GFXImageFormat formatEnum,
                           GFXDataFormat dataTypeEnum) {
    GLenum textureTypeEnum = GLUtil::glTextureTypeTable[to_U32(_textureType)];
    _internalFormat = GLUtil::internalFormat(formatEnum, dataTypeEnum, false);
    _format = GLUtil::glImageFormatTable[to_U32(formatEnum)];
    _dataType = GLUtil::glDataFormat[to_U32(dataTypeEnum)];

    Console::printfn(Locale::get(_ID("GL_PB_GEN")), width, height);
    _width = width;
    _height = height;
    _depth = depth;

    _bufferSize = _width * 4;
    switch (_pbtype) {
        case PBType::PB_TEXTURE_2D:
            _bufferSize *= _height;
            break;
        case PBType::PB_TEXTURE_3D:
            _bufferSize *= _height * _depth;
            break;
    };

    switch (_dataType) {
        case GL_SHORT:
        case GL_HALF_FLOAT:
        case GL_UNSIGNED_SHORT:
            _dataSizeBytes = 2;
            break;
        case GL_FLOAT:
        case GL_INT:
        case GL_UNSIGNED_INT:
            _dataSizeBytes = 4;
            break;
        default:
            break;
    }
    _bufferSize *= _dataSizeBytes;

    GL_API::deleteTextures(1, &_textureID, _textureType);

    glCreateTextures(textureTypeEnum, 1, &_textureID);
    glTextureParameteri(_textureID, GL_GENERATE_MIPMAP, 0);
    glTextureParameteri(_textureID, GL_TEXTURE_MIN_FILTER, to_I32(GL_NEAREST));
    glTextureParameteri(_textureID, GL_TEXTURE_MAG_FILTER, to_I32(GL_NEAREST));
    glTextureParameteri(_textureID, GL_TEXTURE_BASE_LEVEL, 0);
    glTextureParameteri(_textureID, GL_TEXTURE_MAX_LEVEL, 1000);
    glTextureParameteri(_textureID, GL_TEXTURE_WRAP_S, to_I32(GL_REPEAT));

    if (_pbtype != PBType::PB_TEXTURE_1D) {
        glTextureParameteri(_textureID, GL_TEXTURE_WRAP_T, to_I32(GL_REPEAT));
    }
    if (_pbtype == PBType::PB_TEXTURE_3D) {
        glTextureParameteri(_textureID, GL_TEXTURE_WRAP_R, to_I32(GL_REPEAT));
    }

    U16 mipLevels = to_U16(std::floor(std::log2(std::max(_width, _height))) + 1);
    GL_API::getStateTracker().setPixelPackUnpackAlignment();
    switch (_pbtype) {
        case PBType::PB_TEXTURE_1D:
            glTextureStorage1D(_textureID, mipLevels, _internalFormat, _width);
            break;
        case PBType::PB_TEXTURE_2D:
            glTextureStorage2D(_textureID, mipLevels, _internalFormat, _width, _height);
            break;
        case PBType::PB_TEXTURE_3D:
            glTextureStorage3D(_textureID, mipLevels, _internalFormat, _width, _height, _depth);
            break;
    };

    if (_pixelBufferHandle > 0) {
        GLUtil::freeBuffer(_pixelBufferHandle);
    }

    GLUtil::createAndAllocBuffer(_bufferSize, GL_STREAM_DRAW, _pixelBufferHandle, NULL, _name.empty() ? nullptr : _name.c_str());

    return _pixelBufferHandle != 0 && _textureID != 0;
}
Ejemplo n.º 26
0
enum piglit_result
piglit_display(void)
{
	bool pass = true;
	GLuint name;
	GLubyte *data = malloc(50 * 50 * 6 * 4 * sizeof(GLubyte));
	GLubyte *image = malloc(50 * 50 * 4 * sizeof(GLubyte));

	/* Throw some invalid inputs at glGetTextureImage. */

	/* Non-gen-ed name */
	glGetTextureImage(3, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, data);
	pass &= piglit_check_gl_error(GL_INVALID_OPERATION);

	/* Unsupported target. */
	glGenTextures(1, &name);
	glBindTexture(GL_TEXTURE_CUBE_MAP_POSITIVE_X, name);
	glGetTextureImage(name, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, data);
	pass &= piglit_check_gl_error(GL_INVALID_ENUM);
	glDeleteTextures(1, &name);

	/* Unsupported dsa target for non-dsa version. */
	glGetTexImage(GL_TEXTURE_CUBE_MAP, 0, GL_RGBA, GL_UNSIGNED_BYTE,
		     data);
	pass &= piglit_check_gl_error(GL_INVALID_ENUM);

	/* No Storage
	 *
	 * The spec doesn't say what should happen in this case.  This is
	 * addressed by Khronos Bug 13223.
	 */
	glCreateTextures(GL_TEXTURE_CUBE_MAP, 1, &name);
	glGetTextureImage(name, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, data);
	pass &= piglit_check_gl_error(GL_INVALID_OPERATION);
	glDeleteTextures(1, &name);

	/* Insufficient storage
	 *
	 * The spec doesn't say what should happen in this case.  This is
	 * addressed by Khronos Bug 13223.
	 */
	glCreateTextures(GL_TEXTURE_CUBE_MAP, 1, &name);
	glBindTexture(GL_TEXTURE_CUBE_MAP, name);
	glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0,
		     GL_RGBA8, 50, 50, 0, GL_RGBA, GL_UNSIGNED_BYTE, image);
	glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0,
		     GL_RGBA8, 50, 50, 0, GL_RGBA, GL_UNSIGNED_BYTE, image);
	glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0,
		     GL_RGBA8, 50, 50, 0, GL_RGBA, GL_UNSIGNED_BYTE, image);
	/* Note: GL_TEXTURE_CUBE_MAP_NEGATIVE_Y not set */
	glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0,
		     GL_RGBA8, 50, 50, 0, GL_RGBA, GL_UNSIGNED_BYTE, image);
	glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0,
		     GL_RGBA8, 50, 50, 0, GL_RGBA, GL_UNSIGNED_BYTE, image);
	glGetTextureImage(name, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, data);
	pass &= piglit_check_gl_error(GL_INVALID_OPERATION);
	glDeleteTextures(1, &name);

	/* Trivial, but should work. */
	glCreateTextures(GL_TEXTURE_CUBE_MAP, 1, &name);
	glTextureStorage2D(name, 1, GL_RGBA8, 50, 50);
	glGetTextureImage(name, 0, GL_RGBA, GL_UNSIGNED_BYTE,
			  50 * 50 * 6 * 4, data);
	pass &= piglit_check_gl_error(GL_NO_ERROR);

	return pass ? PIGLIT_PASS : PIGLIT_FAIL;
}
Ejemplo n.º 27
0
void ImageViewerPanel::initializeGL()
{
	//glewInit();

	glGetIntegerv(GL_MAJOR_VERSION, &ogl_ver_major);
	glGetIntegerv(GL_MINOR_VERSION, &ogl_ver_minor);

	shaderP = make_unique<GLSLProgram>(
		"resources/shaders/img_vs.glsl",
		"resources/shaders/img_fs.glsl");

	if (ogl_ver_major == 4 && ogl_ver_minor >= 5)
	{
		// DSA
		// Create VAO
		glCreateBuffers(1, &vbo);
		glNamedBufferData(vbo, sizeof(frame), frame, GL_STATIC_DRAW);
		
		// IBO
		GLuint indices[] = { 0,1,2,2,3,0 };
		glCreateBuffers(1, &ibo);
		glNamedBufferData(ibo, sizeof(indices), indices, GL_STATIC_DRAW);

		// VAO
		glCreateVertexArrays(1, &vao);
		glEnableVertexArrayAttrib(vao, 0);

		// Setup the formats
		glVertexArrayAttribFormat(vao, 0, 2, GL_FLOAT, GL_FALSE, 0);
		glVertexArrayVertexBuffer(vao, 0, vbo, 0, sizeof(float) * 2);
		glVertexArrayAttribBinding(vao, 0, 0);

		glVertexArrayElementBuffer(vao, ibo);

		// Setup textures
		int texSize = 4;
		glCreateTextures(GL_TEXTURE_2D, 1, &tex);
		glTextureParameteri(tex, GL_TEXTURE_WRAP_S, GL_REPEAT);
		glTextureParameteri(tex, GL_TEXTURE_WRAP_T, GL_REPEAT);
		glTextureParameteri(tex, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
		glTextureParameteri(tex, GL_TEXTURE_MAG_FILTER, GL_NEAREST);

		glTextureStorage2D(tex, 1, GL_RGB32F, imgsize[0], imgsize[1]);
		if (texLen > 0)
		{
			glTextureSubImage2D(tex, 0, 0, 0, imgsize[0], imgsize[1], GL_RGB, GL_FLOAT, textures);
		}
		texHandle = glGetTextureHandleARB(tex);
		glMakeTextureHandleResidentARB(texHandle);
		
		
	}
	else
	{
		// Non-DSA
		glGenVertexArrays(1, &vao);
		glBindVertexArray(vao);
		// Bind UV values
		glGenBuffers(1, &vbo);
		glBindBuffer(GL_ARRAY_BUFFER, vbo);
		glBufferData(GL_ARRAY_BUFFER, sizeof(frame), frame, GL_STATIC_DRAW);
		glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, nullptr);
		glEnableVertexAttribArray(0);

		glBindVertexArray(0);
		glBindBuffer(GL_ARRAY_BUFFER, 0);
	}

}
Ejemplo n.º 28
0
void Tex2DArray::reload()
{
	double timer = ngn::time();

	reset();

	// RN_CHECK(glGenTextures(1, &id));

	// RN_CHECK(glBindTexture(GL_TEXTURE_2D_ARRAY, id));

	RN_CHECK(glCreateTextures(GL_TEXTURE_2D_ARRAY, 1, &id));

	// RN_CHECK_PARAM(glTextureParameteri(id, GL_TEXTURE_MIN_FILTER, minFilter), rn::getEnumName(minFilter));
	// RN_CHECK_PARAM(glTextureParameteri(id, GL_TEXTURE_MAG_FILTER, magFilter), rn::getEnumName(magFilter));
	// RN_CHECK_PARAM(glTextureParameteri(id, GL_TEXTURE_WRAP_S, wrapS), rn::getEnumName(wrapS));
	// RN_CHECK_PARAM(glTextureParameteri(id, GL_TEXTURE_WRAP_T, wrapT), rn::getEnumName(wrapT));

	setParam(GL_TEXTURE_MIN_FILTER, minFilter);
	setParam(GL_TEXTURE_MAG_FILTER, magFilter);
	setParam(GL_TEXTURE_WRAP_S, wrapS);
	setParam(GL_TEXTURE_WRAP_T, wrapT);

	// RN_CHECK(glTextureParameterfv(id, GL_TEXTURE_BORDER_COLOR, glm::value_ptr(borderColor)));
	setParam(GL_TEXTURE_BORDER_COLOR, glm::value_ptr(borderColor));

	if (mipLevels > 0)
	{
		// RN_CHECK_PARAM(glTextureParameteri(id, GL_TEXTURE_MAX_LEVEL, mipLevels), mipLevels);
		setParam(GL_TEXTURE_MAX_LEVEL, mipLevels);
	}

	switch (internalFormat)
	{
		case GL_DEPTH_COMPONENT:
			format = GL_DEPTH_COMPONENT;
			type = GL_UNSIGNED_INT;
		break;
		case GL_DEPTH_COMPONENT16:
			format = GL_DEPTH_COMPONENT;
			type = GL_UNSIGNED_INT;
		break;
		case GL_DEPTH_COMPONENT24:
			format = GL_DEPTH_COMPONENT;
			type = GL_UNSIGNED_INT;
		break;
		case GL_DEPTH_COMPONENT32:
			format = GL_DEPTH_COMPONENT;
			type = GL_UNSIGNED_INT;
		break;
		case GL_DEPTH_COMPONENT32F:
			format = GL_DEPTH_COMPONENT;
			type = GL_FLOAT;
		break;
		case GL_DEPTH24_STENCIL8:
			format = GL_DEPTH_STENCIL;
			type = GL_UNSIGNED_INT_24_8;
		break;
		case GL_DEPTH32F_STENCIL8:
			format = GL_DEPTH_STENCIL;
			type = GL_FLOAT_32_UNSIGNED_INT_24_8_REV;
		break;
		default:
			format = GL_RED;
			type = GL_UNSIGNED_BYTE;
	}

	if (isDepth() && compareFunc != COMPARE_NONE)
	{
		// RN_CHECK(glTextureParameteri(id, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE));
		// RN_CHECK_PARAM(glTextureParameteri(id, GL_TEXTURE_COMPARE_FUNC, compareFunc), rn::getEnumName(compareFunc));
		setParam(GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE);
		setParam(GL_TEXTURE_COMPARE_FUNC, compareFunc);
	}

	RN_CHECK_PARAM(glTextureStorage3D(id, mipLevels + 1, internalFormat, width, height, size), mipLevels << ", " << rn::getEnumName(internalFormat) << ", " << width << ", " << height << ", " << size);
	/*
	GLsizei mipWidth = width;
	GLsizei mipHeight = height;

	for (GLint i = 0; i <= mipLevels; i++)
	{
		RN_CHECK_PARAM(glTexImage3D(GL_TEXTURE_2D_ARRAY, i, internalFormat, mipWidth, mipHeight, size, 0, format, type, nullptr), i << ", " << rn::getEnumName(internalFormat) << ", " << mipWidth << ", " << mipHeight << ", " << rn::getEnumName(format) << ", " << rn::getEnumName(type));

		mipWidth = max(1, mipWidth / 2);
		mipHeight = max(1, mipHeight / 2);
	}
	*/

	// RN_CHECK(glBindTexture(GL_TEXTURE_2D_ARRAY, 0));

	UTIL_DEBUG
	{
		clog << fixed;
		clog << "  [Tex2DArray \"" << texName << "\":" << (ngn::time() - timer) << "s]" << endl;
		clog.unsetf(ios::floatfield);
	}
}
Ejemplo n.º 29
0
GSTextureOGL::GSTextureOGL(int type, int w, int h, int format, GLuint fbo_read)
	: m_pbo_size(0), m_dirty(false), m_clean(false), m_local_buffer(NULL)
{
	// OpenGL didn't like dimensions of size 0
	m_size.x = max(1,w);
	m_size.y = max(1,h);
	m_format = format;
	m_type   = type;
	m_fbo_read = fbo_read;
	m_texture_id = 0;

	// Bunch of constant parameter
	switch (m_format) {
			// 1 Channel integer
		case GL_R32UI:
		case GL_R32I:
			m_int_format    = GL_RED_INTEGER;
			m_int_type      = (m_format == GL_R32UI) ? GL_UNSIGNED_INT : GL_INT;
			m_int_alignment = 4;
			m_int_shift     = 2;
			break;
		case GL_R16UI:
			m_int_format    = GL_RED_INTEGER;
			m_int_type      = GL_UNSIGNED_SHORT;
			m_int_alignment = 2;
			m_int_shift     = 1;
			break;

			// 1 Channel normalized
		case GL_R8:
			m_int_format    = GL_RED;
			m_int_type      = GL_UNSIGNED_BYTE;
			m_int_alignment = 1;
			m_int_shift     = 0;
			break;

			// 4 channel normalized
		case GL_RGBA16:
			m_int_format    = GL_RGBA;
			m_int_type      = GL_UNSIGNED_SHORT;
			m_int_alignment = 8;
			m_int_shift     = 3;
			break;
		case GL_RGBA8:
			m_int_format    = GL_RGBA;
			m_int_type      = GL_UNSIGNED_BYTE;
			m_int_alignment = 4;
			m_int_shift     = 2;
			break;

			// 4 channel integer
		case GL_RGBA16I:
		case GL_RGBA16UI:
			m_int_format    = GL_RGBA_INTEGER;
			m_int_type      = (m_format == GL_R16UI) ? GL_UNSIGNED_SHORT : GL_SHORT;
			m_int_alignment = 8;
			m_int_shift     = 3;
			break;

			// 4 channel float
		case GL_RGBA32F:
			m_int_format    = GL_RGBA;
			m_int_type      = GL_FLOAT;
			m_int_alignment = 16;
			m_int_shift     = 4;
			break;
		case GL_RGBA16F:
			m_int_format    = GL_RGBA;
			m_int_type      = GL_HALF_FLOAT;
			m_int_alignment = 8;
			m_int_shift     = 3;
			break;

			// Special
		case 0:
		case GL_DEPTH32F_STENCIL8:
			// Backbuffer & dss aren't important
			m_int_format    = 0;
			m_int_type      = 0;
			m_int_alignment = 0;
			m_int_shift     = 0;
			break;
		default:
			ASSERT(0);
	}

	// Generate & Allocate the buffer
	switch (m_type) {
		case GSTexture::Offscreen:
			// 8B is the worst case for depth/stencil
			// FIXME I think it is only used for color. So you can save half of the size
			m_local_buffer = (uint8*)_aligned_malloc(m_size.x * m_size.y * 4, 32);
		case GSTexture::Texture:
		case GSTexture::RenderTarget:
		case GSTexture::DepthStencil:
			glCreateTextures(GL_TEXTURE_2D, 1, &m_texture_id);
			glTextureStorage2D(m_texture_id, 1+GL_TEX_LEVEL_0, m_format, m_size.x, m_size.y);
			if (m_format == GL_R8) {
				// Emulate DX behavior, beside it avoid special code in shader to differentiate
				// palette texture from a GL_RGBA target or a GL_R texture.
				glTextureParameteri(m_texture_id, GL_TEXTURE_SWIZZLE_A, GL_RED);
			}
			break;
		case GSTexture::Backbuffer:
		default:
			break;
	}
}
Ejemplo n.º 30
0
void SuzanneGL::RenderShadowMaps()
{
	GLuint FramebufferName = 0;
	glCreateFramebuffers(1, &FramebufferName);
	glBindFramebuffer(GL_FRAMEBUFFER, FramebufferName);

	glm::mat4 depthViewProjectionMatrices[NUMBER_OF_LIGHTS];
	for (int i = 0; i < NUMBER_OF_LIGHTS; ++i)
	{
		glCreateTextures(GL_TEXTURE_2D, 1, &shadowMaps[i]);
		glTextureImage2DEXT(shadowMaps[i], GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT24, SHADOW_RESOLUTION, SHADOW_RESOLUTION, 0, GL_DEPTH_COMPONENT, GL_FLOAT, 0);
		glTextureParameteri(shadowMaps[i], GL_TEXTURE_MAG_FILTER, GL_LINEAR);
		glTextureParameteri(shadowMaps[i], GL_TEXTURE_MIN_FILTER, GL_LINEAR);
		glTextureParameteri(shadowMaps[i], GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
		glTextureParameteri(shadowMaps[i], GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
		glTextureParameteri(shadowMaps[i], GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
		glTextureParameteri(shadowMaps[i], GL_TEXTURE_COMPARE_MODE, GL_COMPARE_R_TO_TEXTURE);

		glFramebufferTexture(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, shadowMaps[i], 0);

		glDrawBuffer(GL_NONE);

		if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
			return;

		glEnable(GL_DEPTH_TEST);
		glClear(GL_DEPTH_BUFFER_BIT);
		glViewport(0, 0, SHADOW_RESOLUTION, SHADOW_RESOLUTION);

		glm::vec3 lightDir = glm::normalize(glm::vec3(lighting.lights[i].position.x, lighting.lights[i].position.y, lighting.lights[i].position.z));
		glm::mat4 depthProjectionMatrix = glm::ortho<float>(-10, 10, -10, 10, -10, 20);
		glm::mat4 depthViewMatrix = glm::lookAt(lightDir, glm::vec3(0, 0, 0), glm::vec3(0, 1, 0));
		depthViewProjectionMatrices[i] = depthProjectionMatrix * depthViewMatrix;

		shadowModelMatrixIndex = glGetUniformLocation(shadowShaderProgram, "modelMatrix");
		shadowViewProjectionMatrixIndex = glGetUniformLocation(shadowShaderProgram, "viewProjectionMatrix");

		glProgramUniformMatrix4fv(shadowShaderProgram, shadowViewProjectionMatrixIndex, 1, GL_FALSE, glm::value_ptr(depthViewProjectionMatrices[i]));

		for (ModelGL model : models)
		{
			glProgramUniformMatrix4fv(shadowShaderProgram, shadowModelMatrixIndex, 1, GL_FALSE, glm::value_ptr(model.modelMatrix));
			glNamedBufferSubData(materialBuffer, 0, sizeof(Material), &model.material);
			glBindVertexArray(model.vertexArray);
			glUseProgram(shadowShaderProgram);
			glDrawArrays(GL_TRIANGLES, 0, model.vertexCount);
		}
	}

	glBindFramebuffer(GL_FRAMEBUFFER, 0);

	glm::mat4 biasMatrix(
		0.5, 0.0, 0.0, 0.0,
		0.0, 0.5, 0.0, 0.0,
		0.0, 0.0, 0.5, 0.0,
		0.5, 0.5, 0.5, 1.0
		);

	shadowViewProjectionMatrixIndex = glGetUniformLocation(shaderProgram, "shadowViewProjectionMatrix");
	shadowBiasMatrixIndex = glGetUniformLocation(shaderProgram, "shadowBiasMatrix");
	glProgramUniformMatrix4fv(shaderProgram, shadowViewProjectionMatrixIndex, 2, GL_FALSE, glm::value_ptr(depthViewProjectionMatrices[0]));
	glProgramUniformMatrix4fv(shaderProgram, shadowBiasMatrixIndex, 1, GL_FALSE, glm::value_ptr(biasMatrix));
}