Clean up billboard texture code

Todo: compress them in STKTexture class
This commit is contained in:
Benau 2017-01-04 14:35:49 +08:00
parent c98e4f2bac
commit 497f1e2785
8 changed files with 94 additions and 25 deletions

View File

@ -24,7 +24,6 @@
#include "graphics/shader.hpp"
#include "graphics/shaders.hpp"
#include "graphics/shared_gpu_objects.hpp"
#include "graphics/texture_manager.hpp"
#include "graphics/texture_shader.hpp"
#include "utils/cpp2011.hpp"
@ -661,8 +660,7 @@ void draw2DVertexPrimitiveList(video::ITexture *tex, const void* vertices,
Primitive2DList::getInstance()->use();
Primitive2DList::getInstance()->setUniforms(1.0f);
compressTexture(tex, false);
Primitive2DList::getInstance()->setTextureUnits(getTextureGLuint(tex));
Primitive2DList::getInstance()->setTextureUnits(tex->getOpenGLTextureName());
glDrawElements(GL_TRIANGLE_FAN, primitiveCount, GL_UNSIGNED_SHORT, 0);
glDeleteVertexArrays(1, &tmpvao);

View File

@ -23,7 +23,6 @@
#include "graphics/irr_driver.hpp"
#include "graphics/particle_emitter.hpp"
#include "graphics/shared_gpu_objects.hpp"
#include "graphics/texture_manager.hpp"
#include "graphics/texture_shader.hpp"
#include "guiengine/engine.hpp"
#include "io/file_manager.hpp"
@ -158,7 +157,7 @@ ParticleSystemProxy::ParticleSystemProxy(bool createDefaultEmitter,
track_z = 0;
track_x_len = 0;
track_z_len = 0;
texture = 0;
m_texture_name = 0;
}
ParticleSystemProxy::~ParticleSystemProxy()
@ -394,9 +393,7 @@ void ParticleSystemProxy::setEmitter(scene::IParticleEmitter* emitter)
assert(0 && "Wrong particle type");
}
video::ITexture *tex = getMaterial(0).getTexture(0);
compressTexture(tex, true, true);
texture = getTextureGLuint(getMaterial(0).getTexture(0));
m_texture_name = getMaterial(0).getTexture(0)->getOpenGLTextureName();
}
void ParticleSystemProxy::cleanGL()
@ -528,7 +525,7 @@ void ParticleSystemProxy::drawFlip()
glBlendFunc(GL_ONE, GL_ONE);
FlipParticleRender::getInstance()->use();
FlipParticleRender::getInstance()->setTextureUnits(texture, irr_driver->getDepthStencilTexture());
FlipParticleRender::getInstance()->setTextureUnits(m_texture_name, irr_driver->getDepthStencilTexture());
FlipParticleRender::getInstance()->setUniforms();
glBindVertexArray(current_rendering_vao);
@ -543,7 +540,7 @@ void ParticleSystemProxy::drawNotFlip()
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
SimpleParticleRender::getInstance()->use();
SimpleParticleRender::getInstance()->setTextureUnits(texture, irr_driver->getDepthStencilTexture());
SimpleParticleRender::getInstance()->setTextureUnits(m_texture_name, irr_driver->getDepthStencilTexture());
video::SColorf ColorFrom = video::SColorf(getColorFrom()[0], getColorFrom()[1], getColorFrom()[2]);
video::SColorf ColorTo = video::SColorf(getColorTo()[0], getColorTo()[1], getColorTo()[2]);

View File

@ -43,7 +43,7 @@ protected:
bool m_first_execution;
bool m_randomize_initial_y;
GLuint texture;
GLuint m_texture_name;
/** Previous frame particles emitter source matrix */
core::matrix4 m_previous_frame_matrix;

View File

@ -18,10 +18,12 @@
#include "graphics/stars.hpp"
#include "graphics/central_settings.hpp"
#include "graphics/irr_driver.hpp"
#include "graphics/material.hpp"
#include "graphics/material_manager.hpp"
#include "graphics/stk_texture.hpp"
#include "graphics/stk_tex_manager.hpp"
#include "karts/abstract_kart.hpp"
#include "karts/kart_model.hpp"
#include "utils/constants.hpp"
@ -40,7 +42,21 @@ Stars::Stars(AbstractKart *kart)
m_parent_kart_node = kart->getNode();
m_enabled = false;
video::ITexture* texture = irr_driver->getTexture("starparticle.png");
video::ITexture* texture = NULL;
#ifndef SERVER_ONLY
if (CVS->isGLSL())
{
texture = STKTexManager::getInstance()->getTexture
("starparticle.png", true/*srgb*/, true/*premul_alpha*/,
false/*set_material*/, true/*mesh_tex*/);
}
else
#endif
{
texture =
irr_driver->getTexture("starparticle.png");
}
Material* star_material =
material_manager->getMaterial("starparticle.png");

View File

@ -23,7 +23,6 @@
#include "graphics/material.hpp"
#include "graphics/material_manager.hpp"
#include "graphics/shared_gpu_objects.hpp"
#include "graphics/texture_manager.hpp"
#include "graphics/texture_shader.hpp"
#include <ISceneManager.h>
@ -110,10 +109,8 @@ void STKBillboard::render()
else
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
compressTexture(tex, true, true);
GLuint texid = getTextureGLuint(tex);
BillboardShader::getInstance()->use();
BillboardShader::getInstance()->setTextureUnits(texid);
BillboardShader::getInstance()->setTextureUnits(tex->getOpenGLTextureName());
BillboardShader::getInstance()->setUniforms(irr_driver->getViewMatrix(),
irr_driver->getProjMatrix(),
pos, Size);

View File

@ -25,6 +25,8 @@
#include "graphics/central_settings.hpp"
#include "graphics/irr_driver.hpp"
#include "graphics/render_info.hpp"
#include "graphics/stk_tex_manager.hpp"
#include "graphics/stk_texture.hpp"
#include "karts/kart.hpp"
#include "karts/kart_model.hpp"
#include "karts/kart_properties.hpp"
@ -325,10 +327,38 @@ void SoccerWorld::initKartList()
const unsigned int kart_amount = (unsigned int)m_karts.size();
//Loading the indicator textures
irr::video::ITexture *red =
irr_driver->getTexture(FileManager::GUI, "soccer_player_red.png");
irr::video::ITexture *blue =
irr_driver->getTexture(FileManager::GUI, "soccer_player_blue.png");
video::ITexture* red = NULL;
video::ITexture* blue = NULL;
std::string red_path =
file_manager->getAsset(FileManager::GUI, "soccer_player_red.png");
std::string blue_path =
file_manager->getAsset(FileManager::GUI, "soccer_player_blue.png");
#ifndef SERVER_ONLY
if (CVS->isGLSL())
{
red = STKTexManager::getInstance()->getTexture
(red_path, true/*srgb*/, true/*premul_alpha*/,
false/*set_material*/, true/*mesh_tex*/);
}
else
#endif
{
red = irr_driver->getTexture(red_path);
}
#ifndef SERVER_ONLY
if (CVS->isGLSL())
{
blue = STKTexManager::getInstance()->getTexture
(blue_path, true/*srgb*/, true/*premul_alpha*/,
false/*set_material*/, true/*mesh_tex*/);
}
else
#endif
{
blue = irr_driver->getTexture(blue_path);
}
//Assigning indicators
for(unsigned int i = 0; i < kart_amount; i++)

View File

@ -21,7 +21,10 @@
#include "audio/music_manager.hpp"
#include "config/user_config.hpp"
#include "graphics/camera.hpp"
#include "graphics/central_settings.hpp"
#include "graphics/irr_driver.hpp"
#include "graphics/stk_tex_manager.hpp"
#include "graphics/stk_texture.hpp"
#include "io/file_manager.hpp"
#include "karts/kart.hpp"
#include "karts/controller/spare_tire_ai.hpp"
@ -176,8 +179,22 @@ void ThreeStrikesBattle::kartAdded(AbstractKart* kart, scene::ISceneNode* node)
if (kart->getType() == RaceManager::KartType::KT_SPARE_TIRE)
{
// Add heart billboard above it
video::ITexture *heart =
irr_driver->getTexture(FileManager::GUI, "heart.png");
std::string heart_path =
file_manager->getAsset(FileManager::GUI, "heart.png");
video::ITexture* heart = NULL;
#ifndef SERVER_ONLY
if (CVS->isGLSL())
{
heart = STKTexManager::getInstance()->getTexture
(heart_path, true/*srgb*/, true/*premul_alpha*/,
false/*set_material*/, true/*mesh_tex*/);
}
else
#endif
{
heart = irr_driver->getTexture(heart_path);
}
float height = kart->getKartHeight() + 0.5f;
scene::ISceneNode* billboard = irr_driver->addBillboard

View File

@ -31,6 +31,8 @@
#include "graphics/particle_emitter.hpp"
#include "graphics/particle_kind_manager.hpp"
#include "graphics/stk_mesh_scene_node.hpp"
#include "graphics/stk_texture.hpp"
#include "graphics/stk_tex_manager.hpp"
#include "graphics/render_info.hpp"
#include "io/file_manager.hpp"
#include "io/xml_node.hpp"
@ -830,9 +832,21 @@ TrackObjectPresentationBillboard::TrackObjectPresentationBillboard(
xml_node.get("start", &m_fade_out_start);
xml_node.get("end", &m_fade_out_end );
}
video::ITexture* texture = NULL;
#ifndef SERVER_ONLY
if (CVS->isGLSL())
{
texture = STKTexManager::getInstance()->getTexture
(file_manager->searchTexture(texture_name), true/*srgb*/,
true/*premul_alpha*/, false/*set_material*/, true/*mesh_tex*/);
}
else
#endif
{
texture =
irr_driver->getTexture(file_manager->searchTexture(texture_name));
}
video::ITexture* texture =
irr_driver->getTexture(file_manager->searchTexture(texture_name));
if (texture == NULL)
{
Log::warn("TrackObjectPresentation", "Billboard texture '%s' not found",