//------------------------------------------------------------------------------------------------------ void TextureResourceGL::_DoSetFilterType( const TextureProperty::FilterType& ft ) { ActiveTexture(); int TexType = _GLTextureType( _GetTextureType() ); glTexParameteri(TexType, GL_TEXTURE_MAG_FILTER, _GLFilter(ft.m_MagFilter) ); CHECK_GRAPHIC_SYSTEM_ERROR; glTexParameteri(TexType, GL_TEXTURE_MIN_FILTER, _GLFilter(ft.m_MinFilter) ); CHECK_GRAPHIC_SYSTEM_ERROR; }
//------------------------------------------------------------------------------------------------------ void TextureResourceGL::_DoSetWarpType( const TextureProperty::WarpType& wt ) { ActiveTexture(); int TexType = _GLTextureType( _GetTextureType() ); glTexParameteri( TexType, GL_TEXTURE_WRAP_S, _GLWrap(wt.m_SWarp) ); CHECK_GRAPHIC_SYSTEM_ERROR; glTexParameteri( TexType, GL_TEXTURE_WRAP_T, _GLWrap(wt.m_TWarp) ); CHECK_GRAPHIC_SYSTEM_ERROR; }
//------------------------------------------------------------------------------------------------------ void TextureResourceGL::_DoSetWarpType( const TextureStatus::WarpType& wt ) { ActiveTexture(); int TexType = _GLTextureType( _GetTextureType() ); glTexParameteri( TexType, GL_TEXTURE_WRAP_S, _GLWrap(wt.m_SWarp) ); CHECK_ERROR_RENDER; glTexParameteri( TexType, GL_TEXTURE_WRAP_T, _GLWrap(wt.m_TWarp) ); CHECK_ERROR_RENDER; }
//------------------------------------------------------------------------------------------------------ void TextureResourceGL::_DoSetFilterType( const TextureStatus::FilterType& ft ) { ActiveTexture(); int TexType = _GLTextureType( _GetTextureType() ); glTexParameteri(TexType, GL_TEXTURE_MAG_FILTER, _GLFilter(ft.m_MagFilter) ); CHECK_ERROR_RENDER; glTexParameteri(TexType, GL_TEXTURE_MIN_FILTER, _GLFilter(ft.m_MinFilter) ); CHECK_ERROR_RENDER; }
//------------------------------------------------------------------------------------------------------ void TextureResourceGL::_DoActiveTexture( handle h ) const { OpenGLGraphicSystem* glsys = static_cast<OpenGLGraphicSystem*>( IGraphicSystem::Instance() ); const_cast<TextureResourceGL*>(this)->m_hSlotIndex = glsys->GetTextureReferencre(); glsys->IncreaseTextureReferencre(); glActiveTexture( GL_TEXTURE0 + m_hSlotIndex ); CHECK_GRAPHIC_SYSTEM_ERROR; glBindTexture( _GLTextureType( _GetTextureType() ), h ); CHECK_GRAPHIC_SYSTEM_ERROR; }
//------------------------------------------------------------------------------------------------------ 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; }
//------------------------------------------------------------------------------------------------------ void TextureResourceGL::_DoSetAnisotropic( uint ani ) { if( /*true == m_isUsingAnisotropic &&*/ 0 != ani ) //如果支持各向异性 { ActiveTexture(); int TexType = _GLTextureType( _GetTextureType() ); /*uint to = x <= m_fMaxAnisotropic ? x : m_fMaxAnisotropic;*/ glTexParameterf(TexType, GL_TEXTURE_MAX_ANISOTROPY_EXT, ani ); CHECK_GRAPHIC_SYSTEM_ERROR; } }
//------------------------------------------------------------------------------------------------------ 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); }
//------------------------------------------------------------------------------------------------------ void TextureResourceGL::_DoGenerateMipMap() { ActiveTexture(); switch( _GetTextureType() ) { case TextureProperty::TT_TEXTURE1D: ASSERT(false); break; case TextureProperty::TT_TEXTURE2D: { glGenerateMipmap(GL_TEXTURE_2D);//生成mipmap CHECK_GRAPHIC_SYSTEM_ERROR; }break; case TextureProperty::TT_TEXTURE3D: ASSERT(false); break; case TextureProperty::TT_TEXTURECUBE: { glGenerateMipmap(GL_TEXTURE_CUBE_MAP);//生成mipmap CHECK_GRAPHIC_SYSTEM_ERROR; }break; default:ASSERT(false&&"Unkown texture type!"); } }
//------------------------------------------------------------------------------------------------------ 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!"); } }
//------------------------------------------------------------------------------------------------------ void TextureResourceGL::_DoActiveTexture( handle h ) { glActiveTexture( GL_TEXTURE0 /*+ m_uTextrueReferenceCount*/ ); glBindTexture( _GLTextureType( _GetTextureType() ), h ); CHECK_ERROR_RENDER; }