Example #1
0
	//------------------------------------------------------------------------------------------------------
	handle TextureResourceGL::_DoGenerateTexture( const TextureProperty::TextrueSourceDataVector& vec )
	{
		handle hTex = -1;
		glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
		glGenTextures( 1, &hTex );
		switch( _GetTextureType() )
		{
		case TextureProperty::TT_TEXTURE1D: ASSERT(false); break;
		case TextureProperty::TT_TEXTURE2D:
			{
				glBindTexture( GL_TEXTURE_2D, hTex );
				GLint format = _GLPixelFormat( _GetPixelFormat() );
				glTexImage2D( GL_TEXTURE_2D, 0, format, vec[0]->m_Size.m_x, vec[0]->m_Size.m_y, 0, format,
					_GLDataType( _GetPixelFormat() ), vec[0]->m_pData );
				CHECK_GRAPHIC_SYSTEM_ERROR;
				if( isMipMap() )glGenerateMipmap(GL_TEXTURE_2D);//生成mipmap
				CHECK_GRAPHIC_SYSTEM_ERROR;
			}break;
		case TextureProperty::TT_TEXTURE3D: ASSERT(false); break;
		case TextureProperty::TT_TEXTURECUBE:
			{
				glBindTexture( GL_TEXTURE_CUBE_MAP, hTex );
				s_CurrentBind = hTex;
				GLint format = _GLPixelFormat( _GetPixelFormat() );
				GLint type = _GLDataType( _GetPixelFormat() );
				glTexImage2D( GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0, format, vec[0]->m_Size.m_x, vec[0]->m_Size.m_y, 0, format, type, vec[0]->m_pData );
				CHECK_GRAPHIC_SYSTEM_ERROR;
				if( isMipMap() )glGenerateMipmap(GL_TEXTURE_2D);//生成mipmap
				CHECK_GRAPHIC_SYSTEM_ERROR;
				glTexImage2D( GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, format, vec[1]->m_Size.m_x, vec[1]->m_Size.m_y, 0, format, type, vec[1]->m_pData );
				CHECK_GRAPHIC_SYSTEM_ERROR;
				if( isMipMap() )glGenerateMipmap(GL_TEXTURE_2D);//生成mipmap
				CHECK_GRAPHIC_SYSTEM_ERROR;
				glTexImage2D( GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, format, vec[2]->m_Size.m_x, vec[2]->m_Size.m_y, 0, format, type, vec[2]->m_pData );
				CHECK_GRAPHIC_SYSTEM_ERROR;
				if( isMipMap() )glGenerateMipmap(GL_TEXTURE_2D);//生成mipmap
				CHECK_GRAPHIC_SYSTEM_ERROR;
				glTexImage2D( GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0, format, vec[3]->m_Size.m_x, vec[3]->m_Size.m_y, 0, format, type, vec[3]->m_pData );
				CHECK_GRAPHIC_SYSTEM_ERROR;
				if( isMipMap() )glGenerateMipmap(GL_TEXTURE_2D);//生成mipmap
				CHECK_GRAPHIC_SYSTEM_ERROR;
				glTexImage2D( GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0, format, vec[4]->m_Size.m_x, vec[4]->m_Size.m_y, 0, format, type, vec[4]->m_pData );
				CHECK_GRAPHIC_SYSTEM_ERROR;
				if( isMipMap() )glGenerateMipmap(GL_TEXTURE_2D);//生成mipmap
				CHECK_GRAPHIC_SYSTEM_ERROR;
				glTexImage2D( GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, format, vec[5]->m_Size.m_x, vec[5]->m_Size.m_y, 0, format, type, vec[5]->m_pData );
				CHECK_GRAPHIC_SYSTEM_ERROR;
				if( isMipMap() )glGenerateMipmap(GL_TEXTURE_2D);//生成mipmap
				CHECK_GRAPHIC_SYSTEM_ERROR;
			}break;
		default:ASSERT(false&&"Unkown texture type!");
		}
		glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
		return hTex;
	}
Example #2
0
	//------------------------------------------------------------------------------------------------------
	void TextureResourceGL::_DoSubstituteTextureBuffer( const BohgeEngine::vector2d& begin, const BohgeEngine::vector2d& size, const byte* const buffer )
	{
		ActiveTexture();
		glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
		GLenum glformat, gltype, gltext;		
		gltext = _GLTextureType( _GetTextureType() );
		glformat = _GLPixelFormat( _GetPixelFormat() );
		gltype = _GLDataType( _GetPixelFormat() );
		glTexSubImage2D( gltext, 0, begin.m_x, begin.m_y, size.m_x, size.m_y, glformat, gltype, buffer );
		CHECK_GRAPHIC_SYSTEM_ERROR;
		if ( isMipMap() )
		{
			glGenerateMipmap( gltext );
			CHECK_GRAPHIC_SYSTEM_ERROR;
		}
		glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
	}
Example #3
0
	//------------------------------------------------------------------------------------------------------
	void TextureResourceGL::_DoResize( const vector2d& size )
	{
		switch( _GetTextureType() )
		{
		case TextureProperty::TT_TEXTURE2D:
			{
				ActiveTexture();
				GLint format = _GLPixelFormat( _GetPixelFormat() );
				glTexImage2D( GL_TEXTURE_2D, 0, format, size.m_x, size.m_y, 0, format,
					_GLDataType( _GetPixelFormat() ), NULL );
				CHECK_GRAPHIC_SYSTEM_ERROR;
				if( isMipMap() )glGenerateMipmap(GL_TEXTURE_2D);//生成mipmap
				CHECK_GRAPHIC_SYSTEM_ERROR;
			}break;
		case TextureProperty::TT_TEXTURE1D:
		case TextureProperty::TT_TEXTURE3D:
		case TextureProperty::TT_TEXTURECUBE: ASSERT(false); break;
		default:ASSERT(false&&"Unkown texture type!");
		}
	}
Example #4
0
template<> _GLDataType _GetGLType<GfVec4d>()
        { return _GLDataType(GL_DOUBLE, GL_DOUBLE_VEC4); }
Example #5
0
template<> _GLDataType _GetGLType<double>()
        { return _GLDataType(GL_DOUBLE, GL_DOUBLE); }
Example #6
0
template<> _GLDataType _GetGLType<GfVec4f>()
        { return _GLDataType(GL_FLOAT, GL_FLOAT_VEC4); }
Example #7
0
template<> _GLDataType _GetGLType<float>()
        { return _GLDataType(GL_FLOAT, GL_FLOAT); }
Example #8
0
template<> _GLDataType _GetGLType<unsigned int>()
        { return _GLDataType(GL_UNSIGNED_INT, GL_UNSIGNED_INT); }
Example #9
0
template<> _GLDataType _GetGLType<Hd_BSplinePatchIndex>()
        { return _GLDataType(GL_INT, GL_INT); }
Example #10
0
template<> _GLDataType _GetGLType<int>()
        { return _GLDataType(GL_INT, GL_INT); }
Example #11
0
template<> _GLDataType _GetGLType<unsigned short>()
        { return _GLDataType(GL_UNSIGNED_SHORT, GL_UNSIGNED_SHORT); }
Example #12
0
template<> _GLDataType _GetGLType<short>()
        { return _GLDataType(GL_SHORT, GL_SHORT); }
Example #13
0
template<> _GLDataType _GetGLType<char>()
        { return _GLDataType(GL_BYTE, GL_BYTE); }
Example #14
0
template<> _GLDataType _GetGLType<bool>()
        { return _GLDataType(GL_BOOL, GL_BOOL); }
Example #15
0
template<> _GLDataType _GetGLType<GfMatrix4f>()
        { return _GLDataType(GL_FLOAT, GL_FLOAT_MAT4); }
Example #16
0
template<> _GLDataType _GetGLType<GfMatrix4d>()
        { return _GLDataType(GL_DOUBLE, GL_DOUBLE_MAT4); }
Example #17
0
template<> _GLDataType _GetGLType<size_t>()
        { return _GLDataType(GL_UNSIGNED_INT64_NV, GL_UNSIGNED_INT64_NV); }
Example #18
0
template<> _GLDataType _GetGLType<HdVec4f_2_10_10_10_REV>()
        { return _GLDataType(GL_INT_2_10_10_10_REV, GL_INT_2_10_10_10_REV); }
Example #19
0
template<> _GLDataType _GetGLType<GfVec4i>()
        { return _GLDataType(GL_INT, GL_INT_VEC4); }