summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2014-06-08 18:38:07 +0300
committerAndrei Karas <akaras@inbox.ru>2014-06-08 18:38:07 +0300
commit7a0ce777e5d7e3c5ba562ea1c811c0c3cb17a976 (patch)
tree04528345be1561b7970b4c1f1c6e1693e5e2f84e
parente7f05704102d204ce73f97bca5f62312adcd1c2b (diff)
downloadmv-7a0ce777e5d7e3c5ba562ea1c811c0c3cb17a976.tar.gz
mv-7a0ce777e5d7e3c5ba562ea1c811c0c3cb17a976.tar.bz2
mv-7a0ce777e5d7e3c5ba562ea1c811c0c3cb17a976.tar.xz
mv-7a0ce777e5d7e3c5ba562ea1c811c0c3cb17a976.zip
Add simple shader creation.
-rw-r--r--data/graphics/CMakeLists.txt1
-rw-r--r--data/graphics/Makefile.am2
-rw-r--r--src/client.cpp2
-rw-r--r--src/defaults.cpp6
-rw-r--r--src/graphicsmanager.cpp2
-rw-r--r--src/render/graphics.h3
-rw-r--r--src/render/modernopenglgraphics.cpp14
-rw-r--r--src/render/modernopenglgraphics.h4
-rw-r--r--src/render/shaders/shadersmanager.cpp7
-rw-r--r--src/render/shaders/shadersmanager.h2
10 files changed, 40 insertions, 3 deletions
diff --git a/data/graphics/CMakeLists.txt b/data/graphics/CMakeLists.txt
index 2713d7899..1b46f9d66 100644
--- a/data/graphics/CMakeLists.txt
+++ b/data/graphics/CMakeLists.txt
@@ -1,4 +1,5 @@
ADD_SUBDIRECTORY(flags)
ADD_SUBDIRECTORY(gui)
ADD_SUBDIRECTORY(images)
+ADD_SUBDIRECTORY(shaders)
ADD_SUBDIRECTORY(sprites)
diff --git a/data/graphics/Makefile.am b/data/graphics/Makefile.am
index c566673ec..a62c42406 100644
--- a/data/graphics/Makefile.am
+++ b/data/graphics/Makefile.am
@@ -4,4 +4,4 @@ graphicsdir = $(pkgdatadir)/data/graphics
EXTRA_DIST = \
CMakeLists.txt
-SUBDIRS = flags gui images sprites
+SUBDIRS = flags gui images shaders sprites
diff --git a/src/client.cpp b/src/client.cpp
index 8ddb5dcdd..f202f1982 100644
--- a/src/client.cpp
+++ b/src/client.cpp
@@ -364,6 +364,8 @@ void Client::gameInit()
WindowManager::initTitle();
+ mainGraphics->postInit();
+
theme = new Theme;
Theme::selectSkin();
touchManager.init();
diff --git a/src/defaults.cpp b/src/defaults.cpp
index dfef414fb..50d15c4df 100644
--- a/src/defaults.cpp
+++ b/src/defaults.cpp
@@ -460,7 +460,11 @@ DefaultsData* getPathsDefaults()
AddDEF("sprites", "graphics/sprites/");
AddDEF("spriteErrorFile", "error.xml");
AddDEF("guiIcons", "graphics/guiicons/");
+ AddDEF("shaders", "graphics/shaders/");
+ AddDEF("help", "help/");
+ AddDEF("simpleVertexShader", "simple_vertex.glsl");
+ AddDEF("simpleFragmentShader", "simple_frag.glsl");
AddDEF("particles", "graphics/particles/");
AddDEF("portalEffectFile", "warparea.particle.xml");
AddDEF("effectId", -1);
@@ -480,8 +484,6 @@ DefaultsData* getPathsDefaults()
AddDEF("wallpapers", "graphics/images/");
AddDEF("wallpaperFile", "login_wallpaper.png");
- AddDEF("help", "help/");
-
AddDEF("statusEffectsFile", "status-effects.xml");
AddDEF("statusEffectsPatchFile", "status-effects_patch.xml");
AddDEF("statusEffectsPatchDir", "status-effects.d");
diff --git a/src/graphicsmanager.cpp b/src/graphicsmanager.cpp
index 4fa4744a6..ed9768473 100644
--- a/src/graphicsmanager.cpp
+++ b/src/graphicsmanager.cpp
@@ -63,6 +63,8 @@
#include "resources/surfaceimagehelper.h"
#endif
+#include "render/shaders/shadersmanager.h"
+
#include "utils/delete2.h"
#include "utils/sdlhelper.h"
#include "utils/stringutils.h"
diff --git a/src/render/graphics.h b/src/render/graphics.h
index 08bb7facf..a61c47437 100644
--- a/src/render/graphics.h
+++ b/src/render/graphics.h
@@ -450,6 +450,9 @@ class Graphics notfinal
virtual void deleteArrays()
{ }
+ virtual void postInit()
+ { }
+
int mWidth;
int mHeight;
int mActualWidth;
diff --git a/src/render/modernopenglgraphics.cpp b/src/render/modernopenglgraphics.cpp
index 2b771a2bb..566dec714 100644
--- a/src/render/modernopenglgraphics.cpp
+++ b/src/render/modernopenglgraphics.cpp
@@ -33,6 +33,9 @@
#include "render/mgl.h"
+#include "render/shaders/shaderprogram.h"
+#include "render/shaders/shadersmanager.h"
+
#include "resources/image.h"
#include "resources/imagerect.h"
#include "resources/openglimagehelper.h"
@@ -52,6 +55,7 @@ ModernOpenGLGraphics::ModernOpenGLGraphics() :
mShortVertArray(nullptr),
mFloatTexArrayCached(nullptr),
mShortVertArrayCached(nullptr),
+ mSimpleProgram(nullptr),
mAlphaCached(1.0F),
mVpCached(0),
mTexture(false),
@@ -97,6 +101,16 @@ void ModernOpenGLGraphics::initArrays(const int vertCount)
mShortVertArrayCached = new GLshort[sz];
}
+void ModernOpenGLGraphics::postInit()
+{
+ logger->log("Compiling shaders");
+ mSimpleProgram = shaders.getSimpleProgram();
+ if (mSimpleProgram)
+ logger->log("Shaders compilation done.");
+ else
+ logger->error("Shaders compilation error.");
+}
+
void ModernOpenGLGraphics::deleteArrays()
{
deleteArraysInternal();
diff --git a/src/render/modernopenglgraphics.h b/src/render/modernopenglgraphics.h
index 09edcbd92..75165031f 100644
--- a/src/render/modernopenglgraphics.h
+++ b/src/render/modernopenglgraphics.h
@@ -46,6 +46,7 @@
#include <set>
class NormalOpenGLGraphicsVertexes;
+class ShaderProgram;
class ModernOpenGLGraphics final : public Graphics
{
@@ -56,6 +57,8 @@ class ModernOpenGLGraphics final : public Graphics
~ModernOpenGLGraphics();
+ void postInit() override final;
+
#include "render/graphicsdef.hpp"
#include "render/openglgraphicsdef.hpp"
@@ -67,6 +70,7 @@ class ModernOpenGLGraphics final : public Graphics
GLshort *mShortVertArray;
GLfloat *mFloatTexArrayCached;
GLshort *mShortVertArrayCached;
+ ShaderProgram *mSimpleProgram;
float mAlphaCached;
int mVpCached;
bool mTexture;
diff --git a/src/render/shaders/shadersmanager.cpp b/src/render/shaders/shadersmanager.cpp
index e6b5c7181..f9c305d79 100644
--- a/src/render/shaders/shadersmanager.cpp
+++ b/src/render/shaders/shadersmanager.cpp
@@ -22,6 +22,7 @@
#ifdef USE_OPENGL
+#include "configuration.h"
#include "logger.h"
#include "settings.h"
@@ -111,4 +112,10 @@ ShaderProgram *ShadersManager::createProgram(const std::string &vertex,
return nullptr;
}
+ShaderProgram *ShadersManager::getSimpleProgram()
+{
+ const std::string dir = paths.getStringValue("shaders");
+ return createProgram(dir + paths.getStringValue("simpleVertexShader"),
+ dir + paths.getStringValue("simpleFragmentShader"));
+}
#endif
diff --git a/src/render/shaders/shadersmanager.h b/src/render/shaders/shadersmanager.h
index ba7d26438..50e714aba 100644
--- a/src/render/shaders/shadersmanager.h
+++ b/src/render/shaders/shadersmanager.h
@@ -39,6 +39,8 @@ class ShadersManager final
ShaderProgram *createProgram(const std::string &vertex,
const std::string &fragment)
A_WARN_UNUSED;
+
+ ShaderProgram *getSimpleProgram();
};
extern ShadersManager shaders;