Esempio n. 1
0
	void Texture::read(size_t size, void* data) const
	{
		GLenum tex_type = toTextureType(type());
		SurfaceFormat fmt = this->format();
		ImageFormat gl_fmt = toImageFormat(fmt);

		// Read to 'data', not to a device buffer
		//glBindBuffer(GL_PIXEL_PACK_BUFFER, GL_NONE);

#	if defined(VCL_GL_ARB_direct_state_access)
		glGetTextureImage(_glId, 0, gl_fmt.Format, gl_fmt.Type, (GLsizei)size, data);
#	else
		TextureBindPoint bp(tex_type, _glId);
		if (tex_type != GL_TEXTURE_CUBE_MAP)
		{
#		if defined(VCL_GL_EXT_direct_state_access)
			glGetTextureImageEXT(_glId, tex_type, 0, gl_fmt.Format, gl_fmt.Type, data);
#		else
			glGetTexImage(tex_type, 0, gl_fmt.Format, gl_fmt.Type, data);
#		endif
		}
		else
		{
			const GLenum faces[] =
			{
				GL_TEXTURE_CUBE_MAP_POSITIVE_X,
				GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
				GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
				GL_TEXTURE_CUBE_MAP_NEGATIVE_Y,
				GL_TEXTURE_CUBE_MAP_POSITIVE_Z,
				GL_TEXTURE_CUBE_MAP_NEGATIVE_Z,
			};
			int pixel_size = Vcl::Graphics::sizeInBytes(fmt);
			GLsizei w = (GLsizei)width();
			GLsizei h = (GLsizei)height();

			unsigned char* data_ptr = reinterpret_cast<unsigned char*>(data);
			for (const auto face : faces)
			{
#		if defined(VCL_GL_EXT_direct_state_access)
				glGetTextureImageEXT(_glId, face, 0, gl_fmt.Format, gl_fmt.Type, data_ptr);
#		else
				glGetTexImage(face, 0, gl_fmt.Format, gl_fmt.Type, data_ptr);
#		endif
				data_ptr += w * h * pixel_size;
			}
		}
#	endif
	}
Esempio n. 2
0
bool GLTextureCubeMap::get( Array2DView< Vector4f > output )
{
    // TODO: glPixelStorei allows some packing?

    if( output.isNull() ||
        output.width() != width() ||
        output.height() != height() ||
        !( output.packed() ) )
    {
        return false;
    }

    // TODO: level
    glGetTextureImageEXT( id(), GL_TEXTURE_2D, 0,
        GL_RGBA, GL_FLOAT, output );
    return true;
}
Esempio n. 3
0
bool GPU::Texture2D::DumpTo( void *buffer,
                             const GLenum format,
                             const GLenum type,
                             const GLint level ) const
{
    if( m_Id )
    {
#if glGetTextureImageEXT    // Extension GL_EXT_direct_state_access is no supported by every common computer...
        glGetTextureImageEXT( m_Id, GL_TEXTURE_2D, level, format, type, buffer );
#else
        GPU::FrameBuffer fbuffer( m_Width, m_Height );
        fbuffer.Attach( GL_COLOR_ATTACHMENT0_EXT, this );
        fbuffer.DumpTo( GL_COLOR_ATTACHMENT0_EXT, buffer, format, type );
#endif
    }

    return m_Id != 0;
}
Esempio n. 4
0
bool GLTextureCubeMap::get( Array2DView< Vector2f > output )
{
    // TODO: glPixelStorei allows some packing:
    // GL_PACK_ALIGNMENT

    if( output.isNull() ||
        output.width() != width() ||
        output.height() != height() ||
        !( output.packed() ) )
    {
        return false;
    }

    // TODO: GL_RG_INTEGER
    // output can be normalized or not
    // GL_RG_INTEGER for not normalized

    // TODO: level
    glGetTextureImageEXT( id(), GL_TEXTURE_2D, 0,
        GL_RG, GL_FLOAT, output );
    return true;
}
Esempio n. 5
0
bool GLTextureCubeMap::get( Array2DView< uint8x4 > output, GLImageFormat format )
{
    // TODO: glPixelStorei allows some packing?
    // GL_PACK_ALIGNMENT

    if( output.isNull() ||
        output.width() != width() ||
        output.height() != height() ||
        !( output.packed() ) )
    {
        return false;
    }

    if( format != GLImageFormat::RGBA &&
        format != GLImageFormat::BGRA )
    {
        return false;
    }

    // TODO: mipmap level
    glGetTextureImageEXT( id(), GL_TEXTURE_2D, 0,
        static_cast< GLenum >( format ), GL_UNSIGNED_BYTE, output );
    return true;
}
Esempio n. 6
0
void CubeMapTexture::getImageImplementationDSAEXT(const Coordinate coordinate, const GLint level, const Vector2i&, const ColorFormat format, const ColorType type, std::size_t, GLvoid* const data) {
    _created = true;
    glGetTextureImageEXT(_id, GLenum(coordinate), level, GLenum(format), GLenum(type), data);
}