Skip to content
Snippets Groups Projects
Commit 93d93de8 authored by Joseph Walton-Rivers's avatar Joseph Walton-Rivers
Browse files

ensure that two objects using hte same texture share it

parent adf82193
No related branches found
No related tags found
No related merge requests found
...@@ -201,6 +201,11 @@ namespace fggl::gfx::ogl4 { ...@@ -201,6 +201,11 @@ namespace fggl::gfx::ogl4 {
static ogl::Texture* upload_texture( std::string name, assets::AssetManager* manager ) { static ogl::Texture* upload_texture( std::string name, assets::AssetManager* manager ) {
debug::info("loading texture: {}", name); debug::info("loading texture: {}", name);
auto* texture = manager->get<ogl::Texture>("ogl_"+name);
if ( texture != nullptr ) {
return texture;
}
auto textureData = manager->get<data::Texture2D>(name); auto textureData = manager->get<data::Texture2D>(name);
ogl::Image image{ ogl::Image image{
.type = ogl::PixelFormat::UNSIGNED_BYTE, .type = ogl::PixelFormat::UNSIGNED_BYTE,
...@@ -209,9 +214,10 @@ namespace fggl::gfx::ogl4 { ...@@ -209,9 +214,10 @@ namespace fggl::gfx::ogl4 {
.data = textureData->data, .data = textureData->data,
}; };
ogl::Texture* texture = new ogl::Texture(ogl::TextureType::Tex2D); texture = new ogl::Texture(ogl::TextureType::Tex2D);
texture->setData( ogl::InternalImageFormat::RedGreenBlue, image); texture->setData( ogl::InternalImageFormat::RedGreenBlue, image);
return texture;
return manager->set("ogl_"+name, texture);
} }
static Material* upload_material( std::string name, assets::AssetManager* manager ) { static Material* upload_material( std::string name, assets::AssetManager* manager ) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment