Moved SharedObjects into separate file shared_gpu_object.

This also fixes the missing loading screen (likely caused by
not initialising all objects, or not in the right order).
This commit is contained in:
hiker 2015-05-14 16:27:32 +10:00
parent 3b682ff084
commit f0d0e7e601
13 changed files with 376 additions and 175 deletions

View File

@ -1,5 +1,5 @@
# Modify this file to change the last-modified date when you add/remove a file.
# This will then trigger a new cmake run automatically.
# This will then trigger a new cmake run automatically.
file(GLOB_RECURSE STK_HEADERS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "src/*.hpp")
file(GLOB_RECURSE STK_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "src/*.cpp")
file(GLOB_RECURSE STK_SHADERS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "data/shaders/*")

View File

@ -20,12 +20,14 @@
#include "graphics/central_settings.hpp"
#include "graphics/shader.hpp"
#include "graphics/shaders.hpp"
#include "graphics/shared_gpu_objects.hpp"
#include "graphics/texture_read.hpp"
#include "glwrap.hpp"
#include "utils/cpp2011.hpp"
#include "../../lib/irrlicht/source/Irrlicht/COpenGLTexture.h"
// ============================================================================
class Primitive2DList : public Shader<Primitive2DList>,
public TextureReadNew<ST_BILINEAR_FILTERED >
@ -90,11 +92,13 @@ public:
}; // ColoredRectShader
// ============================================================================
class ColoredTextureRectShader : public Shader<ColoredTextureRectShader,
core::vector2df, core::vector2df,
core::vector2df, core::vector2df>,
public TextureReadNew<ST_BILINEAR_FILTERED>
{
#ifdef XX
private:
GLuint m_quad_buffer;
@ -119,14 +123,16 @@ private:
(GLvoid *)(2 * sizeof(float)));
glBindVertexArray(0);
} // initQuadBuffer
#endif
public:
GLuint m_color_vbo;
GLuint m_vao;
ColoredTextureRectShader()
{
#ifdef XX
initQuadBuffer();
#endif
loadProgram(OBJECT, GL_VERTEX_SHADER, "colortexturedquad.vert",
GL_FRAGMENT_SHADER, "colortexturedquad.frag");
assignUniforms("center", "size", "texcenter", "texsize");
@ -138,7 +144,7 @@ public:
glEnableVertexAttribArray(0);
glEnableVertexAttribArray(3);
glEnableVertexAttribArray(2);
glBindBuffer(GL_ARRAY_BUFFER, m_quad_buffer);
glBindBuffer(GL_ARRAY_BUFFER, SharedGPUObjects::getQuadBuffer());
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), 0);
glVertexAttribPointer(3, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float),
(GLvoid *)(2 * sizeof(float)));
@ -201,7 +207,7 @@ static void drawTexQuad(GLuint texture, float width, float height,
float tex_width, float tex_height)
{
TextureRectShader::getInstance()->use();
glBindVertexArray(SharedObject::UIVAO);
glBindVertexArray(SharedGPUObjects::getUI_VAO());
TextureRectShader::getInstance()->setTextureUnits(texture);
TextureRectShader::getInstance()->setUniforms(
@ -308,7 +314,7 @@ void draw2DImage(const video::ITexture* texture,
}
UniformColoredTextureRectShader::getInstance()->use();
glBindVertexArray(SharedObject::UIVAO);
glBindVertexArray(SharedGPUObjects::getUI_VAO());
const video::COpenGLTexture *c_texture =
static_cast<const video::COpenGLTexture*>(texture);
@ -355,7 +361,7 @@ void draw2DImageFromRTT(GLuint texture, size_t texture_w, size_t texture_h,
tex_width, tex_height, tex_center_pos_x, tex_center_pos_y);
UniformColoredTextureRectShader::getInstance()->use();
glBindVertexArray(SharedObject::UIVAO);
glBindVertexArray(SharedGPUObjects::getUI_VAO());
UniformColoredTextureRectShader::getInstance()->setTextureUnits(texture);
UniformColoredTextureRectShader::getInstance()
@ -528,7 +534,7 @@ void GL32_draw2DRectangle(video::SColor color, const core::rect<s32>& position,
}
ColoredRectShader::getInstance()->use();
glBindVertexArray(SharedObject::UIVAO);
glBindVertexArray(SharedGPUObjects::getUI_VAO());
ColoredRectShader::getInstance()
->setUniforms(core::vector2df(center_pos_x, center_pos_y),
core::vector2df(width, height), color );

View File

@ -15,12 +15,15 @@
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "IBL.hpp"
#include "gl_headers.hpp"
#include "shaders.hpp"
#include "graphics/IBL.hpp"
#include "graphics/central_settings.hpp"
#include "graphics/gl_headers.hpp"
#include "graphics/shaders.hpp"
#include "graphics/shared_gpu_objects.hpp"
#include <cmath>
#include <set>
#include "central_settings.hpp"
class SpecularIBLGenerator : public Shader<SpecularIBLGenerator, core::matrix4,
@ -410,7 +413,7 @@ GLuint generateSpecularCubemap(GLuint probe)
glGenTextures(1, &sampleTex);
glBindTexture(GL_TEXTURE_BUFFER, sampleTex);
glTexBuffer(GL_TEXTURE_BUFFER, GL_RG32F, sampleBuffer);
glBindVertexArray(SharedObject::FullScreenQuadVAO);
glBindVertexArray(SharedGPUObjects::getFullScreenQuadVAO());
for (unsigned face = 0; face < 6; face++)
{

View File

@ -22,6 +22,7 @@
#include "graphics/irr_driver.hpp"
#include "graphics/particle_emitter.hpp"
#include "graphics/shaders.hpp"
#include "graphics/shared_gpu_objects.hpp"
#include "graphics/texture_read.hpp"
#include "guiengine/engine.hpp"
#include "io/file_manager.hpp"
@ -414,7 +415,7 @@ void ParticleSystemProxy::cleanGL()
void ParticleSystemProxy::CommonRenderingVAO(GLuint PositionBuffer)
{
glBindBuffer(GL_ARRAY_BUFFER, SharedObject::ParticleQuadVBO);
glBindBuffer(GL_ARRAY_BUFFER, SharedGPUObjects::getParticleQuadVBO());
glEnableVertexAttribArray(4);
glVertexAttribPointer(4, 4, GL_FLOAT, GL_FALSE, 4 * sizeof(float), 0);
glEnableVertexAttribArray(3);

View File

@ -25,6 +25,7 @@
#include "graphics/irr_driver.hpp"
#include "graphics/mlaa_areamap.hpp"
#include "graphics/shaders.hpp"
#include "graphics/shared_gpu_objects.hpp"
#include "graphics/stkmeshscenenode.hpp"
#include "io/file_manager.hpp"
#include "karts/abstract_kart.hpp"
@ -438,7 +439,7 @@ void PostProcessing::renderEnvMap(const float *bSHCoeff, const float *gSHCoeff,
if (UserConfigParams::m_degraded_IBL)
{
FullScreenShader::DegradedIBLShader::getInstance()->use();
glBindVertexArray(SharedObject::FullScreenQuadVAO);
glBindVertexArray(SharedGPUObjects::getFullScreenQuadVAO());
FullScreenShader::DegradedIBLShader::getInstance()->setTextureUnits(irr_driver->getRenderTargetTexture(RTT_NORMAL_AND_DEPTH));
FullScreenShader::DegradedIBLShader::getInstance()->setUniforms();
@ -446,7 +447,7 @@ void PostProcessing::renderEnvMap(const float *bSHCoeff, const float *gSHCoeff,
else
{
FullScreenShader::IBLShader::getInstance()->use();
glBindVertexArray(SharedObject::FullScreenQuadVAO);
glBindVertexArray(SharedGPUObjects::getFullScreenQuadVAO());
FullScreenShader::IBLShader::getInstance()->setTextureUnits(irr_driver->getRenderTargetTexture(RTT_NORMAL_AND_DEPTH), irr_driver->getDepthStencilTexture(), skybox);
FullScreenShader::IBLShader::getInstance()->setUniforms();

View File

@ -20,6 +20,7 @@
#include "config/user_config.hpp"
#include "graphics/callbacks.hpp"
#include "graphics/shared_gpu_objects.hpp"
#include "central_settings.hpp"
#include "graphics/glwrap.hpp"
#include "graphics/graphics_restrictions.hpp"
@ -288,8 +289,10 @@ void IrrDriver::renderGLSL(float dt)
float tmp[2];
tmp[0] = float(m_actual_screen_size.Width);
tmp[1] = float(m_actual_screen_size.Height);
glBindBuffer(GL_UNIFORM_BUFFER, SharedObject::ViewProjectionMatrixesUBO);
glBufferSubData(GL_UNIFORM_BUFFER, (16 * 9) * sizeof(float), 2 * sizeof(float), tmp);
glBindBuffer(GL_UNIFORM_BUFFER,
SharedGPUObjects::getViewProjectionMatricesUBO());
glBufferSubData(GL_UNIFORM_BUFFER, (16 * 9) * sizeof(float),
2 * sizeof(float), tmp);
glBindVertexArray(0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
@ -342,8 +345,8 @@ void IrrDriver::renderGLSL(float dt)
void IrrDriver::renderScene(scene::ICameraSceneNode * const camnode, unsigned pointlightcount, std::vector<GlowData>& glows, float dt, bool hasShadow, bool forceRTT)
{
glBindBufferBase(GL_UNIFORM_BUFFER, 0, SharedObject::ViewProjectionMatrixesUBO);
glBindBufferBase(GL_UNIFORM_BUFFER, 1, SharedObject::LightingDataUBO);
glBindBufferBase(GL_UNIFORM_BUFFER, 0, SharedGPUObjects::getViewProjectionMatricesUBO());
glBindBufferBase(GL_UNIFORM_BUFFER, 1, SharedGPUObjects::getLightingDataUBO());
m_scene_manager->setActiveCamera(camnode);
PROFILER_PUSH_CPU_MARKER("- Draw Call Generation", 0xFF, 0xFF, 0xFF);
@ -629,7 +632,7 @@ static void renderWireFrameFrustrum(float *tmp, unsigned i)
{
MeshShader::ViewFrustrumShader::getInstance()->use();
glBindVertexArray(MeshShader::ViewFrustrumShader::getInstance()->frustrumvao);
glBindBuffer(GL_ARRAY_BUFFER, SharedObject::frustrumvbo);
glBindBuffer(GL_ARRAY_BUFFER, SharedGPUObjects::getFrustrumVBO());
glBufferSubData(GL_ARRAY_BUFFER, 0, 8 * 3 * sizeof(float), (void *)tmp);
MeshShader::ViewFrustrumShader::getInstance()->setUniforms(video::SColor(255, 0, 255, 0), i);

View File

@ -24,6 +24,7 @@
#include "graphics/post_processing.hpp"
#include "graphics/rtts.hpp"
#include "graphics/shaders.hpp"
#include "graphics/shared_gpu_objects.hpp"
#include "modes/world.hpp"
#include "tracks/track.hpp"
#include "utils/profiler.hpp"
@ -141,7 +142,7 @@ void IrrDriver::uploadLightingData()
memcpy(&Lighting[17], greenSHCoeff, 9 * sizeof(float));
memcpy(&Lighting[26], redSHCoeff, 9 * sizeof(float));
glBindBuffer(GL_UNIFORM_BUFFER, SharedObject::LightingDataUBO);
glBindBuffer(GL_UNIFORM_BUFFER, SharedGPUObjects::getLightingDataUBO());
glBufferSubData(GL_UNIFORM_BUFFER, 0, 36 * sizeof(float), Lighting);
}
@ -155,7 +156,7 @@ void IrrDriver::renderLights(unsigned pointlightcount, bool hasShadow)
ScopedGPUTimer timer(irr_driver->getGPUTimer(Q_RH));
glDisable(GL_BLEND);
m_rtts->getRH().Bind();
glBindVertexArray(SharedObject::FullScreenQuadVAO);
glBindVertexArray(SharedGPUObjects::getFullScreenQuadVAO());
if (CVS->needRHWorkaround())
{
FullScreenShader::NVWorkaroundRadianceHintsConstructionShader::getInstance()->use();

View File

@ -98,6 +98,7 @@
#include "graphics/central_settings.hpp"
#include "graphics/irr_driver.hpp"
#include "graphics/gpuparticles.hpp"
#include "graphics/shared_gpu_objects.hpp"
#include "io/file_manager.hpp"
#include "utils/log.hpp"
#include "graphics/glwrap.hpp"
@ -247,127 +248,6 @@ Shaders::ColoredLine::ColoredLine()
GLuint quad_vbo, tri_vbo;
GLuint SharedObject::FullScreenQuadVAO = 0;
GLuint SharedObject::UIVAO = 0;
static void initQuadVBO()
{
const float quad_vertex[] = {
-1., -1., 0., 0., // UpperLeft
-1., 1., 0., 1., // LowerLeft
1., -1., 1., 0., // UpperRight
1., 1., 1., 1., // LowerRight
};
glGenBuffers(1, &quad_vbo);
glBindBuffer(GL_ARRAY_BUFFER, quad_vbo);
glBufferData(GL_ARRAY_BUFFER, 16 * sizeof(float), quad_vertex, GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0);
const float tri_vertex[] = {
-1., -1.,
-1., 3.,
3., -1.,
};
glGenBuffers(1, &tri_vbo);
glBindBuffer(GL_ARRAY_BUFFER, tri_vbo);
glBufferData(GL_ARRAY_BUFFER, 6 * sizeof(float), tri_vertex, GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glGenVertexArrays(1, &SharedObject::FullScreenQuadVAO);
glBindVertexArray(SharedObject::FullScreenQuadVAO);
glBindBuffer(GL_ARRAY_BUFFER, tri_vbo);
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 2 * sizeof(float), 0);
glBindVertexArray(0);
}
GLuint SharedObject::billboardvbo = 0;
static void initBillboardVBO()
{
float quad[] = {
-.5, -.5, 0., 1.,
-.5, .5, 0., 0.,
.5, -.5, 1., 1.,
.5, .5, 1., 0.,
};
glGenBuffers(1, &(SharedObject::billboardvbo));
glBindBuffer(GL_ARRAY_BUFFER, SharedObject::billboardvbo);
glBufferData(GL_ARRAY_BUFFER, 16 * sizeof(float), quad, GL_STATIC_DRAW);
}
GLuint SharedObject::skytrivbo = 0;
static void initSkyTriVBO()
{
const float tri_vertex[] = {
-1., -1., 1.,
-1., 3., 1.,
3., -1., 1.,
};
glGenBuffers(1, &SharedObject::skytrivbo);
glBindBuffer(GL_ARRAY_BUFFER, SharedObject::skytrivbo);
glBufferData(GL_ARRAY_BUFFER, 3 * 3 * sizeof(float), tri_vertex, GL_STATIC_DRAW);
}
GLuint SharedObject::frustrumvbo = 0;
GLuint SharedObject::frustrumindexes = 0;
static void initFrustrumVBO()
{
glGenBuffers(1, &SharedObject::frustrumvbo);
glBindBuffer(GL_ARRAY_BUFFER, SharedObject::frustrumvbo);
glBufferData(GL_ARRAY_BUFFER, 8 * 3 * sizeof(float), 0, GL_DYNAMIC_DRAW);
int indices[24] = {
0, 1, 1, 3, 3, 2, 2, 0,
4, 5, 5, 7, 7, 6, 6, 4,
0, 4, 1, 5, 2, 6, 3, 7,
};
glGenBuffers(1, &SharedObject::frustrumindexes);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, SharedObject::frustrumindexes);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, 12 * 2 * sizeof(int), indices, GL_STATIC_DRAW);
}
GLuint SharedObject::ViewProjectionMatrixesUBO;
static void initShadowVPMUBO()
{
glGenBuffers(1, &SharedObject::ViewProjectionMatrixesUBO);
glBindBuffer(GL_UNIFORM_BUFFER, SharedObject::ViewProjectionMatrixesUBO);
glBufferData(GL_UNIFORM_BUFFER, (16 * 9 + 2) * sizeof(float), 0, GL_STREAM_DRAW);
glBindBuffer(GL_UNIFORM_BUFFER, 0);
}
GLuint SharedObject::LightingDataUBO;
static void initLightingDataUBO()
{
glGenBuffers(1, &SharedObject::LightingDataUBO);
glBindBuffer(GL_UNIFORM_BUFFER, SharedObject::LightingDataUBO);
glBufferData(GL_UNIFORM_BUFFER, 36 * sizeof(float), 0, GL_STREAM_DRAW);
glBindBuffer(GL_UNIFORM_BUFFER, 0);
}
GLuint SharedObject::ParticleQuadVBO = 0;
static void initParticleQuadVBO()
{
static const GLfloat quad_vertex[] = {
-.5, -.5, 0., 0.,
.5, -.5, 1., 0.,
-.5, .5, 0., 1.,
.5, .5, 1., 1.,
};
glGenBuffers(1, &SharedObject::ParticleQuadVBO);
glBindBuffer(GL_ARRAY_BUFFER, SharedObject::ParticleQuadVBO);
glBufferData(GL_ARRAY_BUFFER, sizeof(quad_vertex), quad_vertex, GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0);
}
void Shaders::loadShaders()
{
@ -447,13 +327,7 @@ void Shaders::loadShaders()
initGL();
CleanTable.clear();
initQuadVBO();
initBillboardVBO();
initSkyTriVBO();
initFrustrumVBO();
initShadowVPMUBO();
initLightingDataUBO();
initParticleQuadVBO();
SharedGPUObjects::init();
}
// ----------------------------------------------------------------------------
@ -668,7 +542,7 @@ namespace MeshShader
glGenVertexArrays(1, &vao);
glBindVertexArray(vao);
glBindBuffer(GL_ARRAY_BUFFER, SharedObject::skytrivbo);
glBindBuffer(GL_ARRAY_BUFFER, SharedGPUObjects::getSkyTriVBO());
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), 0);
glBindVertexArray(0);
@ -694,10 +568,11 @@ namespace MeshShader
glGenVertexArrays(1, &frustrumvao);
glBindVertexArray(frustrumvao);
glBindBuffer(GL_ARRAY_BUFFER, SharedObject::frustrumvbo);
glBindBuffer(GL_ARRAY_BUFFER, SharedGPUObjects::getFrustrumVBO());
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), 0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, SharedObject::frustrumindexes);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,
SharedGPUObjects::getFrustrumIndices());
glBindVertexArray(0);
}
}

View File

@ -20,6 +20,7 @@
#include "config/user_config.hpp"
#include "graphics/shader.hpp"
#include "graphics/shared_gpu_objects.hpp"
#include "graphics/texture_read.hpp"
#include <IMeshSceneNode.h>
@ -30,16 +31,6 @@
using namespace irr;
class ParticleSystemProxy;
class SharedObject
{
public:
static GLuint billboardvbo;
static GLuint skytrivbo, frustrumvbo, frustrumindexes, ParticleQuadVBO;
static GLuint ViewProjectionMatrixesUBO, LightingDataUBO;
static GLuint FullScreenQuadVAO;
static GLuint UIVAO;
};
namespace MeshShader
{
@ -187,7 +178,7 @@ template<typename T, typename... Args>
static void DrawFullScreenEffect(Args...args)
{
T::getInstance()->use();
glBindVertexArray(SharedObject::FullScreenQuadVAO);
glBindVertexArray(SharedGPUObjects::getFullScreenQuadVAO());
T::getInstance()->setUniforms(args...);
glDrawArrays(GL_TRIANGLES, 0, 3);
}

View File

@ -16,17 +16,19 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "graphics/central_settings.hpp"
#include "graphics/irr_driver.hpp"
#include "graphics/shaders.hpp"
#include "graphics/shared_gpu_objects.hpp"
#include "modes/world.hpp"
#include "physics/triangle_mesh.hpp"
#include "tracks/track.hpp"
#include <limits>
#include <ICameraSceneNode.h>
#include <SViewFrustum.h>
#include "../../lib/irrlicht/source/Irrlicht/CSceneManager.h"
#include "../../lib/irrlicht/source/Irrlicht/os.h"
#include "graphics/central_settings.hpp"
#include "graphics/irr_driver.hpp"
#include "graphics/shaders.hpp"
#include "modes/world.hpp"
#include "physics/triangle_mesh.hpp"
#include "tracks/track.hpp"
#define MAX2(a, b) ((a) > (b) ? (a) : (b))
#define MIN2(a, b) ((a) > (b) ? (b) : (a))
@ -164,8 +166,10 @@ void IrrDriver::UpdateSplitAndLightcoordRangeFromComputeShaders(size_t width, si
glMemoryBarrier(GL_SHADER_STORAGE_BARRIER_BIT);
glBindBuffer(GL_COPY_READ_BUFFER, tempShadowMatssbo);
glBindBuffer(GL_COPY_WRITE_BUFFER, SharedObject::ViewProjectionMatrixesUBO);
glCopyBufferSubData(GL_COPY_READ_BUFFER, GL_COPY_WRITE_BUFFER, 0, 80 * sizeof(float), 4 * 16 * sizeof(float));
glBindBuffer(GL_COPY_WRITE_BUFFER,
SharedGPUObjects::getViewProjectionMatricesUBO());
glCopyBufferSubData(GL_COPY_READ_BUFFER, GL_COPY_WRITE_BUFFER, 0,
80 * sizeof(float), 4 * 16 * sizeof(float));
}
/** Generate View, Projection, Inverse View, Inverse Projection, ViewProjection and InverseProjection matrixes
@ -318,7 +322,7 @@ void IrrDriver::computeMatrixesAndCameras(scene::ICameraSceneNode * const camnod
tmp[144] = float(width);
tmp[145] = float(height);
glBindBuffer(GL_UNIFORM_BUFFER, SharedObject::ViewProjectionMatrixesUBO);
glBindBuffer(GL_UNIFORM_BUFFER, SharedGPUObjects::getViewProjectionMatricesUBO());
if (CVS->isSDSMEnabled())
{
glBufferSubData(GL_UNIFORM_BUFFER, 0, (16 * 5) * sizeof(float), tmp);

View File

@ -0,0 +1,198 @@
// SuperTuxKart - a fun racing game with go-kart
// Copyright (C) 2014-2015 SuperTuxKart-Team
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 3
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "graphics/shared_gpu_objects.hpp"
GLuint SharedGPUObjects::m_billboard_vbo;
GLuint SharedGPUObjects::m_sky_tri_vbo;
GLuint SharedGPUObjects::m_frustrum_vbo;
GLuint SharedGPUObjects::m_frustrum_indices;
GLuint SharedGPUObjects::m_particle_quad_vbo;
GLuint SharedGPUObjects::m_View_projection_matrices_ubo;
GLuint SharedGPUObjects::m_lighting_data_ubo;
GLuint SharedGPUObjects::m_full_screen_quad_vao;
GLuint SharedGPUObjects::m_ui_vao;
GLuint SharedGPUObjects::m_quad_buffer;
bool SharedGPUObjects::m_has_been_initialised = false;
/** Initialises m_full_screen_quad_vbo.
*/
void SharedGPUObjects::initQuadVBO()
{
const float QUAD_VERTEX[] =
{
-1., -1., 0., 0., // UpperLeft
-1., 1., 0., 1., // LowerLeft
1., -1., 1., 0., // UpperRight
1., 1., 1., 1. // LowerRight
};
GLuint quad_vbo;
glGenBuffers(1, &quad_vbo);
glBindBuffer(GL_ARRAY_BUFFER, quad_vbo);
glBufferData(GL_ARRAY_BUFFER, 16 * sizeof(float), QUAD_VERTEX,
GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0);
const float TRI_VERTEX[] =
{
-1., -1.,
-1., 3.,
3., -1.,
};
GLuint tri_vbo;
glGenBuffers(1, &tri_vbo);
glBindBuffer(GL_ARRAY_BUFFER, tri_vbo);
glBufferData(GL_ARRAY_BUFFER, 6 * sizeof(float), TRI_VERTEX,
GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glGenVertexArrays(1, &m_full_screen_quad_vao);
glBindVertexArray(m_full_screen_quad_vao);
glBindBuffer(GL_ARRAY_BUFFER, tri_vbo);
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 2 * sizeof(float), 0);
glBindVertexArray(0);
} // initQuadVBO
// ----------------------------------------------------------------------------
void SharedGPUObjects::initQuadBuffer()
{
const float QUAD_VERTEX[] =
{
-1., -1., -1., 1., // UpperLeft
-1., 1., -1., -1., // LowerLeft
1., -1., 1., 1., // UpperRight
1., 1., 1., -1. // LowerRight
};
glGenBuffers(1, &m_quad_buffer);
glBindBuffer(GL_ARRAY_BUFFER, m_quad_buffer);
glBufferData(GL_ARRAY_BUFFER, 16 * sizeof(float), QUAD_VERTEX,
GL_STATIC_DRAW);
glGenVertexArrays(1, &m_ui_vao);
glBindVertexArray(m_ui_vao);
glEnableVertexAttribArray(0);
glEnableVertexAttribArray(3);
glBindBuffer(GL_ARRAY_BUFFER, m_quad_buffer);
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), 0);
glVertexAttribPointer(3, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float),
(GLvoid *)(2 * sizeof(float)));
glBindVertexArray(0);
} // initQuadBuffer
// ----------------------------------------------------------------------------
void SharedGPUObjects::initBillboardVBO()
{
float QUAD[] =
{
-.5, -.5, 0., 1.,
-.5, .5, 0., 0.,
.5, -.5, 1., 1.,
.5, .5, 1., 0.,
};
glGenBuffers(1, &m_billboard_vbo);
glBindBuffer(GL_ARRAY_BUFFER, m_billboard_vbo);
glBufferData(GL_ARRAY_BUFFER, 16 * sizeof(float), QUAD, GL_STATIC_DRAW);
} // initBillboardVBO
// ----------------------------------------------------------------------------
void SharedGPUObjects::initSkyTriVBO()
{
const float TRI_VERTEX[] =
{
-1., -1., 1.,
-1., 3., 1.,
3., -1., 1.,
};
glGenBuffers(1, &m_sky_tri_vbo);
glBindBuffer(GL_ARRAY_BUFFER, m_sky_tri_vbo);
glBufferData(GL_ARRAY_BUFFER, 3 * 3 * sizeof(float), TRI_VERTEX,
GL_STATIC_DRAW);
} // initSkyTriVBO
// ----------------------------------------------------------------------------
void SharedGPUObjects::initFrustrumVBO()
{
glGenBuffers(1, &m_frustrum_vbo);
glBindBuffer(GL_ARRAY_BUFFER, m_frustrum_vbo);
glBufferData(GL_ARRAY_BUFFER, 8 * 3 * sizeof(float), 0, GL_DYNAMIC_DRAW);
int INDICES[24] = {
0, 1, 1, 3, 3, 2, 2, 0,
4, 5, 5, 7, 7, 6, 6, 4,
0, 4, 1, 5, 2, 6, 3, 7,
};
glGenBuffers(1, &m_frustrum_indices);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_frustrum_indices);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, 12 * 2 * sizeof(int), INDICES,
GL_STATIC_DRAW);
} // initFrustrumVBO
// ----------------------------------------------------------------------------
void SharedGPUObjects::initShadowVPMUBO()
{
glGenBuffers(1, &m_View_projection_matrices_ubo);
glBindBuffer(GL_UNIFORM_BUFFER, m_View_projection_matrices_ubo);
glBufferData(GL_UNIFORM_BUFFER, (16 * 9 + 2) * sizeof(float), 0,
GL_STREAM_DRAW);
glBindBuffer(GL_UNIFORM_BUFFER, 0);
} // initShadowVPMUBO
// ----------------------------------------------------------------------------
void SharedGPUObjects::initLightingDataUBO()
{
glGenBuffers(1, &m_lighting_data_ubo);
glBindBuffer(GL_UNIFORM_BUFFER, m_lighting_data_ubo);
glBufferData(GL_UNIFORM_BUFFER, 36 * sizeof(float), 0, GL_STREAM_DRAW);
glBindBuffer(GL_UNIFORM_BUFFER, 0);
} // initLightingDataUBO
// ----------------------------------------------------------------------------
void SharedGPUObjects::initParticleQuadVBO()
{
static const GLfloat QUAD_VERTEX[] =
{
-.5, -.5, 0., 0.,
.5, -.5, 1., 0.,
-.5, .5, 0., 1.,
.5, .5, 1., 1.,
};
glGenBuffers(1, &m_particle_quad_vbo);
glBindBuffer(GL_ARRAY_BUFFER, m_particle_quad_vbo);
glBufferData(GL_ARRAY_BUFFER, sizeof(QUAD_VERTEX), QUAD_VERTEX,
GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0);
} // initParticleQuadVBO
// ----------------------------------------------------------------------------
void SharedGPUObjects::init()
{
if (m_has_been_initialised)
return;
initQuadVBO();
initQuadBuffer();
initBillboardVBO();
initSkyTriVBO();
initFrustrumVBO();
initShadowVPMUBO();
initLightingDataUBO();
initParticleQuadVBO();
m_has_been_initialised = true;
} // SharedGPUObjects

View File

@ -0,0 +1,115 @@
// SuperTuxKart - a fun racing game with go-kart
// Copyright (C) 2014-2015 SuperTuxKart-Team
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 3
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#ifndef HEADER_SHARED_GPU_OBJECTS_HPP
#define HEADER_SHARED_GPU_OBJECTS_HPP
#include "graphics/gl_headers.hpp"
#include <assert.h>
class SharedGPUObjects
{
private:
static bool m_has_been_initialised;
static GLuint m_billboard_vbo;
static GLuint m_sky_tri_vbo;
static GLuint m_frustrum_vbo;
static GLuint m_frustrum_indices;
static GLuint m_particle_quad_vbo;
static GLuint m_View_projection_matrices_ubo;
static GLuint m_lighting_data_ubo;
static GLuint m_full_screen_quad_vao;
static GLuint m_ui_vao;
static GLuint m_quad_buffer;
static void initQuadVBO();
static void initQuadBuffer();
static void initBillboardVBO();
static void initSkyTriVBO();
static void initFrustrumVBO();
static void initShadowVPMUBO();
static void initLightingDataUBO();
static void initParticleQuadVBO();
public:
static void init();
// ------------------------------------------------------------------------
static GLuint getBillboardVBO()
{
assert(m_has_been_initialised);
return m_billboard_vbo;
} // getBillboardVBO
// ------------------------------------------------------------------------
static GLuint getSkyTriVBO()
{
assert(m_has_been_initialised);
return m_sky_tri_vbo;
} // getSkyTriVBO
// ------------------------------------------------------------------------
static GLuint getFrustrumVBO()
{
assert(m_has_been_initialised);
return m_frustrum_vbo;
} // getFrustrumVBO
// ------------------------------------------------------------------------
static GLuint getFrustrumIndices()
{
assert(m_has_been_initialised);
return m_frustrum_indices;
} // getFrustrumIndices
// ------------------------------------------------------------------------
static GLuint getParticleQuadVBO()
{
assert(m_has_been_initialised);
return m_particle_quad_vbo;
} // getParticleQuadVBO
// ------------------------------------------------------------------------
static GLuint getViewProjectionMatricesUBO()
{
assert(m_has_been_initialised);
return m_View_projection_matrices_ubo;
} // getViewProjectionMatricesUBO
// ------------------------------------------------------------------------
static GLuint getLightingDataUBO()
{
assert(m_has_been_initialised);
return m_lighting_data_ubo;
} // getLightingDataUBO
// -------------- ----------------------------------------------------------
static GLuint getFullScreenQuadVAO()
{
assert(m_has_been_initialised);
return m_full_screen_quad_vao;
} // getFullScreenQuadVAO
// ------------------------------------------------------------------------
static GLuint getUI_VAO()
{
assert(m_has_been_initialised);
return m_ui_vao;
} // getUI_VAO
// ------------------------------------------------------------------------
static GLuint getQuadBuffer()
{
assert(m_has_been_initialised);
return m_quad_buffer;
} // getQuadBuffer
}; // class SharedGPUObjecctS
#endif

View File

@ -16,9 +16,12 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "graphics/stkbillboard.hpp"
#include "graphics/glwrap.hpp"
#include "graphics/shaders.hpp"
#include "graphics/irr_driver.hpp"
#include "graphics/shaders.hpp"
#include "graphics/shared_gpu_objects.hpp"
#include <ISceneManager.h>
using namespace irr;
@ -51,7 +54,7 @@ static void createBillboardVAO()
{
glGenVertexArrays(1, &billboardvao);
glBindVertexArray(billboardvao);
glBindBuffer(GL_ARRAY_BUFFER, SharedObject::billboardvbo);
glBindBuffer(GL_ARRAY_BUFFER, SharedGPUObjects::getBillboardVBO());
glEnableVertexAttribArray(0);
glEnableVertexAttribArray(3);
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), 0);