コード例 #1
0
void Texture2DArray::pushToGPU(bool deleteAfterPush) {
	glTextureStorage3D(name, mipmapLevels, images[0].format.sizedFormat, images[0].width, images[0].height, images.size()); //allocate space for all

	for (unsigned int i = 0; i < images.size(); ++i) {
		ImageData &imageData = images[i];

		if (imageData.data != 0)
			glTextureSubImage3D(name,
				0,
				0, 0, i,
				imageData.width, imageData.height, 1,
				imageData.format.baseFormat, imageData.format.type, imageData.data);

		if (deleteAfterPush) {
			delete[] imageData.data;
			imageData.data = 0;
		}
	}

	if (mipmapLevels > 1) {
		glGenerateTextureMipmap(name); //generate the remaining mipmaps
		glTextureParameterf(name, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
	}
	else
		glTextureParameterf(name, GL_TEXTURE_MIN_FILTER, GL_LINEAR);

	glTextureParameterf(name, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

	glTextureParameterf(name, GL_TEXTURE_WRAP_S, GL_REPEAT);
	glTextureParameterf(name, GL_TEXTURE_WRAP_T, GL_REPEAT);
}
コード例 #2
0
ファイル: GSTextureOGL.cpp プロジェクト: PCSX2/pcsx2
void GSTextureOGL::GenerateMipmap()
{
	if (m_generate_mipmap && m_max_layer > 1) {
		glGenerateTextureMipmap(m_texture_id);
		m_generate_mipmap = false;
	}
}
コード例 #3
0
ファイル: Texture.cpp プロジェクト: xHaVoK87/kit
void kit::Texture::generateMipmap()
{
#ifndef KIT_SHITTY_INTEL
    glGenerateTextureMipmap(m_glHandle);
#else
    bind();
    glGenerateMipmap(m_type);
#endif
}
コード例 #4
0
ファイル: Texture.cpp プロジェクト: Theundeadwarrior/Casiope
	Texture::Texture(const Core::Image<unsigned char>& imageParameters, TextureFormat format)
	{
		glGenTextures(1, &m_id);
		glBindTexture(GL_TEXTURE_2D, m_id);
		glTexImage2D(GL_TEXTURE_2D, 0, format, imageParameters.m_Width, imageParameters.m_Height, 0, format, GL_UNSIGNED_BYTE, imageParameters.m_ImageData.data());
		glGenerateTextureMipmap(m_id);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
		//LowLevelAPI::GenerateTexture(m_id, imageParameters, format);
		//m_path = imageParameters.path;
		glBindTexture(GL_TEXTURE_2D, 0);
	}
コード例 #5
0
ファイル: nanovg_gfx.cpp プロジェクト: sopyer/Infinity
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;
}
コード例 #6
0
ファイル: TextureGL.cpp プロジェクト: hsdxpro/ExcessiveTeam
void TextureGL::GenMipChain()
{
  glGenerateTextureMipmap( ID );
}
コード例 #7
0
ファイル: Texture.cpp プロジェクト: bryongloden/kit
void kit::Texture::generateMipmap()
{
  KIT_GL(glGenerateTextureMipmap(this->m_glHandle));
}
コード例 #8
0
	//[-------------------------------------------------------]
	//[ Public methods                                        ]
	//[-------------------------------------------------------]
	Texture2DArrayDsa::Texture2DArrayDsa(OpenGLRenderer &openGLRenderer, uint32_t width, uint32_t height, uint32_t numberOfSlices, Renderer::TextureFormat::Enum textureFormat, const void *data, uint32_t flags) :
		Texture2DArray(openGLRenderer, width, height, numberOfSlices)
	{
		#ifndef OPENGLRENDERER_NO_STATE_CLEANUP
			// Backup the currently set alignment
			GLint openGLAlignmentBackup = 0;
			glGetIntegerv(GL_UNPACK_ALIGNMENT, &openGLAlignmentBackup);
		#endif

		// Set correct alignment
		glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

		// Create the OpenGL texture instance
		const bool isARB_DSA = openGLRenderer.getExtensions().isGL_ARB_direct_state_access();
		if (isARB_DSA)
		{
			glCreateTextures(GL_TEXTURE_2D_ARRAY_EXT, 1, &mOpenGLTexture);
		}
		else
		{
			glGenTextures(1, &mOpenGLTexture);
		}

		// Upload the base map of the texture (mipmaps are automatically created as soon as the base map is changed)
		if (isARB_DSA)
		{
			glTextureStorage3D(mOpenGLTexture, 1, Mapping::getOpenGLInternalFormat(textureFormat), static_cast<GLsizei>(width), static_cast<GLsizei>(height), static_cast<GLsizei>(numberOfSlices));
			if (nullptr != data)
			{
				glTextureSubImage3D(mOpenGLTexture, 0, 0, 0, 0, static_cast<GLsizei>(width), static_cast<GLsizei>(height), static_cast<GLsizei>(numberOfSlices), Mapping::getOpenGLFormat(textureFormat), Mapping::getOpenGLType(textureFormat), data);
			}
		}
		else
		{
			glTextureImage3DEXT(mOpenGLTexture, GL_TEXTURE_2D_ARRAY_EXT, 0, static_cast<GLint>(Mapping::getOpenGLInternalFormat(textureFormat)), static_cast<GLsizei>(width), static_cast<GLsizei>(height), static_cast<GLsizei>(numberOfSlices), 0, Mapping::getOpenGLFormat(textureFormat), Mapping::getOpenGLType(textureFormat), data);
		}

		// Build mipmaps automatically on the GPU? (or GPU driver)
		if (flags & Renderer::TextureFlag::GENERATE_MIPMAPS)
		{
			if (isARB_DSA)
			{
				glGenerateTextureMipmap(mOpenGLTexture);
				glTextureParameteri(mOpenGLTexture, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
			}
			else
			{
				glGenerateTextureMipmapEXT(mOpenGLTexture, GL_TEXTURE_2D_ARRAY_EXT);
				glTextureParameteriEXT(mOpenGLTexture, GL_TEXTURE_2D_ARRAY_EXT, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
			}
		}
		else
		{
			if (isARB_DSA)
			{
				glTextureParameteri(mOpenGLTexture, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
			}
			else
			{
				glTextureParameteriEXT(mOpenGLTexture, GL_TEXTURE_2D_ARRAY_EXT, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
			}
		}

		if (isARB_DSA)
		{
			glTextureParameteri(mOpenGLTexture, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
		}
		else
		{
			glTextureParameteriEXT(mOpenGLTexture, GL_TEXTURE_2D_ARRAY_EXT, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
		}

		#ifndef OPENGLRENDERER_NO_STATE_CLEANUP
			// Restore previous alignment
			glPixelStorei(GL_UNPACK_ALIGNMENT, openGLAlignmentBackup);
		#endif
	}
コード例 #9
-1
ファイル: image2d.cpp プロジェクト: qnope/Dark-Light
Image2D::Image2D(std::string const &path) :
    AbstractTexture(GL_TEXTURE_2D, true, true)
{
    ImageLoader il(path);

    GLsizei levels = log2(std::max(il.width(), il.height())) + 1;

    glTextureStorage2D(mId, levels, il.internalFormat(), il.width(), il.height());
    glTextureSubImage2D(mId, 0, 0, 0, il.width(), il.height(),
                        il.format(), GL_UNSIGNED_BYTE, il.data());
    glGenerateTextureMipmap(mId);
    makeResident();
}