diff --git a/proj-web/CMakeLists.txt b/proj-web/CMakeLists.txt index 0f353b1..d7f6fc6 100644 --- a/proj-web/CMakeLists.txt +++ b/proj-web/CMakeLists.txt @@ -73,6 +73,8 @@ set(SOURCES ../src/MenuManager.cpp ../src/Space.h ../src/Space.cpp + ../src/GameConstants.h + ../src/GameConstants.cpp ) add_executable(space-game001 ${SOURCES}) diff --git a/proj-windows/CMakeLists.txt b/proj-windows/CMakeLists.txt index 90e0f67..b49685a 100644 --- a/proj-windows/CMakeLists.txt +++ b/proj-windows/CMakeLists.txt @@ -67,6 +67,8 @@ add_executable(space-game001 ../src/MenuManager.cpp ../src/Space.h ../src/Space.cpp + ../src/GameConstants.h + ../src/GameConstants.cpp ) # Установка проекта по умолчанию для Visual Studio diff --git a/src/Game.cpp b/src/Game.cpp index 7c8b92a..e8536db 100644 --- a/src/Game.cpp +++ b/src/Game.cpp @@ -30,7 +30,7 @@ #include "network/LocalClient.h" #include "network/ClientState.h" - +#include "GameConstants.h" namespace ZL { @@ -217,12 +217,6 @@ namespace ZL void Game::drawUI() { - static const std::string defaultShaderName = "default"; - static const std::string envShaderName = "env"; - static const std::string vPositionName = "vPosition"; - static const std::string vTexCoordName = "vTexCoord"; - static const std::string textureUniformName = "Texture"; - glClear(GL_DEPTH_BUFFER_BIT); renderer.shaderManager.PushShader(defaultShaderName); @@ -242,10 +236,7 @@ namespace ZL } void Game::drawScene() { - //For low quality: glViewport(0, 0, Environment::width, Environment::height); - //For high quality: - //glViewport(0, 0, Environment::projectionWidth, Environment::projectionHeight); if (!loadingCompleted) { drawLoading(); } @@ -266,9 +257,6 @@ namespace ZL void Game::drawLoading() { - static const std::string defaultShaderName = "default"; - static const std::string textureUniformName = "Texture"; - glClear(GL_DEPTH_BUFFER_BIT); renderer.shaderManager.PushShader(defaultShaderName); diff --git a/src/GameConstants.cpp b/src/GameConstants.cpp new file mode 100644 index 0000000..6771660 --- /dev/null +++ b/src/GameConstants.cpp @@ -0,0 +1,9 @@ +#include "GameConstants.h" + +namespace ZL +{ + const std::string defaultShaderName = "default"; + const std::string envShaderName = "env"; + const std::string textureUniformName = "Texture"; +} + diff --git a/src/GameConstants.h b/src/GameConstants.h new file mode 100644 index 0000000..a19c0c8 --- /dev/null +++ b/src/GameConstants.h @@ -0,0 +1,11 @@ +#pragma once +#include "render/Renderer.h" + +namespace ZL +{ + extern const std::string defaultShaderName; + extern const std::string envShaderName; + + extern const std::string textureUniformName; +} + diff --git a/src/SparkEmitter.cpp b/src/SparkEmitter.cpp index 666e311..64cf5d8 100644 --- a/src/SparkEmitter.cpp +++ b/src/SparkEmitter.cpp @@ -8,6 +8,7 @@ #include "Environment.h" #include #include "utils/Utils.h" +#include "GameConstants.h" namespace ZL { @@ -195,8 +196,6 @@ namespace ZL { sparkQuad.data.TexCoordData = drawTexCoords; sparkQuad.RefreshVBO(); - static const std::string textureUniformName = "Texture"; - renderer.shaderManager.PushShader(shaderProgramName); renderer.RenderUniform1i(textureUniformName, 0); diff --git a/src/UiManager.cpp b/src/UiManager.cpp index 2e911b1..4471248 100644 --- a/src/UiManager.cpp +++ b/src/UiManager.cpp @@ -4,6 +4,7 @@ #include #include #include +#include "GameConstants.h" namespace ZL { @@ -61,8 +62,6 @@ namespace ZL { } if (!(*tex)) return; - static const std::string textureUniformName = "Texture"; - renderer.PushMatrix(); renderer.TranslateMatrix({ animOffsetX, animOffsetY, 0.0f }); renderer.ScaleMatrix({ animScaleX, animScaleY, 1.0f }); @@ -140,8 +139,6 @@ namespace ZL { } void UiSlider::draw(Renderer& renderer) const { - static const std::string textureUniformName = "Texture"; - renderer.RenderUniform1i(textureUniformName, 0); if (texTrack) { glBindTexture(GL_TEXTURE_2D, texTrack->getTexID()); @@ -186,8 +183,6 @@ namespace ZL { void UiStaticImage::draw(Renderer& renderer) const { if (!texture) return; - static const std::string textureUniformName = "Texture"; - renderer.RenderUniform1i(textureUniformName, 0); glBindTexture(GL_TEXTURE_2D, texture->getTexID()); renderer.DrawVertexRenderStruct(mesh); diff --git a/src/planet/PlanetObject.cpp b/src/planet/PlanetObject.cpp index c64a9be..ad567e4 100644 --- a/src/planet/PlanetObject.cpp +++ b/src/planet/PlanetObject.cpp @@ -6,6 +6,7 @@ #include "StoneObject.h" #include "utils/TaskManager.h" #include "TextModel.h" +#include "GameConstants.h" namespace ZL { @@ -185,11 +186,9 @@ namespace ZL { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - static const std::string defaultShaderName2 = "planetBake"; - static const std::string textureUniformName = "Texture"; + static const std::string planetBakeShaderName = "planetBake"; - - renderer.shaderManager.PushShader(defaultShaderName2); + renderer.shaderManager.PushShader(planetBakeShaderName); renderer.RenderUniform1i(textureUniformName, 0); Triangle tr = planetData.getLodLevel().triangles[0]; @@ -292,11 +291,11 @@ namespace ZL { void PlanetObject::drawPlanet(Renderer& renderer) { - static const std::string defaultShaderName = "planetLand"; + static const std::string planetLandShaderName = "planetLand"; static const std::string textureUniformName = "Texture"; - renderer.shaderManager.PushShader(defaultShaderName); + renderer.shaderManager.PushShader(planetLandShaderName); float dist = planetData.distanceToPlanetSurfaceFast(Environment::shipState.position); @@ -318,10 +317,9 @@ namespace ZL { const Matrix4f viewMatrix = renderer.GetCurrentModelViewMatrix(); - renderer.RenderUniform1i("Texture", 0); + renderer.RenderUniform1i(textureUniformName, 0); renderer.RenderUniform1i("BakedTexture", 1); - Triangle tr = planetData.getLodLevel().triangles[0]; // Берем базовый треугольник Matrix3f mr = GetRotationForTriangle(tr); // Та же матрица, что и при запекании @@ -367,10 +365,9 @@ namespace ZL { void PlanetObject::drawStones(Renderer& renderer) { - static const std::string defaultShaderName2 = "planetStone"; - static const std::string textureUniformName = "Texture"; + static const std::string planetStoneShaderName = "planetStone"; - renderer.shaderManager.PushShader(defaultShaderName2); + renderer.shaderManager.PushShader(planetStoneShaderName); renderer.RenderUniform1i(textureUniformName, 0); float dist = planetData.distanceToPlanetSurfaceFast(Environment::shipState.position); @@ -536,10 +533,7 @@ namespace ZL { void PlanetObject::drawCamp(Renderer& renderer) { - static const std::string defaultShaderName2 = "default"; - static const std::string textureUniformName = "Texture"; - - renderer.shaderManager.PushShader(defaultShaderName2); + renderer.shaderManager.PushShader(defaultShaderName); renderer.RenderUniform1i(textureUniformName, 0); float dist = planetData.distanceToPlanetSurfaceFast(Environment::shipState.position);