mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-07-19 08:49:18 +02:00
build 170810. multi-texture materials, reflection map support
This commit is contained in:
123
Texture.cpp
123
Texture.cpp
@@ -506,18 +506,15 @@ opengl_texture::load_TGA() {
|
||||
return;
|
||||
}
|
||||
|
||||
resource_state
|
||||
bool
|
||||
opengl_texture::bind() {
|
||||
|
||||
if( false == is_ready ) {
|
||||
|
||||
create();
|
||||
if( data_state != resource_state::good ) {
|
||||
return data_state;
|
||||
}
|
||||
if( ( false == is_ready )
|
||||
&& ( false == create() ) ) {
|
||||
return false;
|
||||
}
|
||||
::glBindTexture( GL_TEXTURE_2D, id );
|
||||
return data_state;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
@@ -645,40 +642,7 @@ opengl_texture::set_filtering() {
|
||||
switch( trait ) {
|
||||
|
||||
case '#': { sharpen = true; break; }
|
||||
/*
|
||||
// legacy filter modes. TODO, TBD: get rid of them?
|
||||
// let's just turn them off and see if anyone notices.
|
||||
case '4': {
|
||||
// najbliższy z tekstury
|
||||
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
|
||||
break;
|
||||
}
|
||||
case '5': {
|
||||
//średnia z tekstury
|
||||
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
|
||||
break;
|
||||
}
|
||||
case '6': {
|
||||
// najbliższy z mipmapy
|
||||
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST );
|
||||
break;
|
||||
}
|
||||
case '7': {
|
||||
//średnia z mipmapy
|
||||
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST );
|
||||
break;
|
||||
}
|
||||
case '8': {
|
||||
// najbliższy z dwóch mipmap
|
||||
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_LINEAR );
|
||||
break;
|
||||
}
|
||||
case '9': {
|
||||
//średnia z dwóch mipmap
|
||||
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR );
|
||||
break;
|
||||
}
|
||||
*/
|
||||
default: { break; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -718,9 +682,27 @@ opengl_texture::downsize( GLuint const Format ) {
|
||||
};
|
||||
}
|
||||
|
||||
void
|
||||
texture_manager::assign_units( GLint const Helper, GLint const Shadows, GLint const Normals, GLint const Diffuse ) {
|
||||
|
||||
m_units[ 0 ].unit = Helper;
|
||||
m_units[ 1 ].unit = Shadows;
|
||||
m_units[ 2 ].unit = Normals;
|
||||
m_units[ 3 ].unit = Diffuse;
|
||||
}
|
||||
|
||||
void
|
||||
texture_manager::unit( GLint const Textureunit ) {
|
||||
|
||||
if( m_activeunit == Textureunit ) { return; }
|
||||
|
||||
m_activeunit = Textureunit;
|
||||
::glActiveTexture( Textureunit );
|
||||
}
|
||||
|
||||
// ustalenie numeru tekstury, wczytanie jeśli jeszcze takiej nie było
|
||||
texture_handle
|
||||
texture_manager::create( std::string Filename, std::string const &Dir, int const Filter, bool const Loadnow ) {
|
||||
texture_manager::create( std::string Filename, bool const Loadnow ) {
|
||||
|
||||
if( Filename.find( '|' ) != std::string::npos )
|
||||
Filename.erase( Filename.find( '|' ) ); // po | może być nazwa kolejnej tekstury
|
||||
@@ -801,11 +783,7 @@ texture_manager::create( std::string Filename, std::string const &Dir, int const
|
||||
|
||||
auto texture = new opengl_texture();
|
||||
texture->name = filename;
|
||||
if( ( Filter > 0 ) && ( Filter < 10 ) ) {
|
||||
// temporary. TODO, TBD: check how it's used and possibly get rid of it
|
||||
traits += std::to_string( ( Filter < 4 ? Filter + 4 : Filter ) );
|
||||
}
|
||||
if( Filename.find('#') !=std::string::npos ) {
|
||||
if( Filename.find('#') != std::string::npos ) {
|
||||
// temporary code for legacy assets -- textures with names beginning with # are to be sharpened
|
||||
traits += '#';
|
||||
}
|
||||
@@ -830,33 +808,37 @@ texture_manager::create( std::string Filename, std::string const &Dir, int const
|
||||
};
|
||||
|
||||
void
|
||||
texture_manager::bind( texture_handle const Texture ) {
|
||||
texture_manager::bind( std::size_t const Unit, texture_handle const Texture ) {
|
||||
|
||||
m_textures[ Texture ].second = m_garbagecollector.timestamp();
|
||||
|
||||
if( ( Texture != 0 ) && ( Texture == m_activetexture ) ) {
|
||||
if( Texture == m_units[ Unit ].texture ) {
|
||||
// don't bind again what's already active
|
||||
return;
|
||||
}
|
||||
// TODO: do binding in texture object, add support for other types
|
||||
if( Texture != 0 ) {
|
||||
// TBD, TODO: do binding in texture object, add support for other types than 2d
|
||||
if( m_units[ Unit ].unit == NULL ) { return; }
|
||||
unit( m_units[ Unit ].unit );
|
||||
if( Texture != NULL ) {
|
||||
#ifndef EU07_DEFERRED_TEXTURE_UPLOAD
|
||||
// NOTE: we could bind dedicated 'error' texture here if the id isn't valid
|
||||
::glBindTexture( GL_TEXTURE_2D, texture(Texture).id );
|
||||
m_activetexture = Texture;
|
||||
m_units[ Unit ].texture = Texture;
|
||||
#else
|
||||
if( texture( Texture ).bind() == resource_state::good ) {
|
||||
m_activetexture = Texture;
|
||||
if( true == texture( Texture ).bind() ) {
|
||||
m_units[ Unit ].texture = Texture;
|
||||
}
|
||||
else {
|
||||
// TODO: bind a special 'error' texture on failure
|
||||
::glBindTexture( GL_TEXTURE_2D, NULL );
|
||||
m_units[ Unit ].texture = NULL;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
else {
|
||||
|
||||
::glBindTexture( GL_TEXTURE_2D, 0 );
|
||||
m_activetexture = 0;
|
||||
::glBindTexture( GL_TEXTURE_2D, NULL );
|
||||
m_units[ Unit ].texture = NULL;
|
||||
}
|
||||
// all done
|
||||
return;
|
||||
@@ -879,7 +861,9 @@ void
|
||||
texture_manager::update() {
|
||||
|
||||
if( m_garbagecollector.sweep() > 0 ) {
|
||||
m_activetexture = -1;
|
||||
for( auto &unit : m_units ) {
|
||||
unit.texture = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -943,21 +927,10 @@ texture_manager::find_in_databank( std::string const &Texturename ) const {
|
||||
std::string
|
||||
texture_manager::find_on_disk( std::string const &Texturename ) const {
|
||||
|
||||
{
|
||||
std::ifstream file( Texturename );
|
||||
if( true == file.is_open() ) {
|
||||
// success
|
||||
return Texturename;
|
||||
}
|
||||
}
|
||||
// if we fail make a last ditch attempt in the default textures directory
|
||||
{
|
||||
std::ifstream file( szTexturePath + Texturename );
|
||||
if( true == file.is_open() ) {
|
||||
// success
|
||||
return szTexturePath + Texturename;
|
||||
}
|
||||
}
|
||||
// no results either way, report failure
|
||||
return "";
|
||||
return(
|
||||
FileExists( Texturename ) ? Texturename :
|
||||
FileExists( szTexturePath + Texturename ) ? szTexturePath + Texturename :
|
||||
"" );
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user