summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2015-12-10 02:59:18 +0300
committerAndrei Karas <akaras@inbox.ru>2015-12-10 15:12:12 +0300
commit740b10240414ae3b7c37ee21fd131ffdb296b2b9 (patch)
treeb1c03b4c9eeb8790033c79cece88162597711fbb /src
parent54d0234c8334bcd61ffb655a57e6147fd279b9e1 (diff)
downloadmv-740b10240414ae3b7c37ee21fd131ffdb296b2b9.tar.gz
mv-740b10240414ae3b7c37ee21fd131ffdb296b2b9.tar.bz2
mv-740b10240414ae3b7c37ee21fd131ffdb296b2b9.tar.xz
mv-740b10240414ae3b7c37ee21fd131ffdb296b2b9.zip
Add function for load OpenGL ES 2 shaders.
Diffstat (limited to 'src')
-rw-r--r--src/defaults.cpp2
-rw-r--r--src/render/shaders/shadersmanager.cpp19
-rw-r--r--src/render/shaders/shadersmanager.h5
-rw-r--r--src/resources/resourcemanager.cpp10
-rw-r--r--src/resources/resourcemanager.h3
5 files changed, 31 insertions, 8 deletions
diff --git a/src/defaults.cpp b/src/defaults.cpp
index a301d2323..16cab02a6 100644
--- a/src/defaults.cpp
+++ b/src/defaults.cpp
@@ -501,6 +501,8 @@ DefaultsData* getPathsDefaults()
AddDEF("simpleVertexShader", "simple_vertex.glsl");
AddDEF("simpleFragmentShader", "simple_frag.glsl");
+ AddDEF("gles2VertexShader", "gles2_vertex.glsl");
+ AddDEF("gles2FragmentShader", "gles2_frag.glsl");
AddDEF("particles", "graphics/particles/");
AddDEF("portalEffectFile", "warparea.particle.xml");
diff --git a/src/render/shaders/shadersmanager.cpp b/src/render/shaders/shadersmanager.cpp
index 345093074..c79abe2cc 100644
--- a/src/render/shaders/shadersmanager.cpp
+++ b/src/render/shaders/shadersmanager.cpp
@@ -63,7 +63,8 @@ Shader *ShadersManager::createShader(const unsigned int type,
}
ShaderProgram *ShadersManager::createProgram(const std::string &vertex,
- const std::string &fragment)
+ const std::string &fragment,
+ const bool isNewShader)
{
Shader *const vertexShader = static_cast<Shader*>(
resourceManager->getShader(GL_VERTEX_SHADER, vertex));
@@ -89,7 +90,10 @@ ShaderProgram *ShadersManager::createProgram(const std::string &vertex,
mglAttachShader(programId, vertexShader->getShaderId());
mglAttachShader(programId, fragmentShader->getShaderId());
- mglBindFragDataLocation(programId, 0, "outColor");
+ if (isNewShader)
+ mglBindFragDataLocation(programId, 0, "outColor");
+ else
+ mglBindAttribLocation(programId, 0, "position");
mglLinkProgram(programId);
GLint isLinked = 0;
mglGetProgramiv(programId, GL_LINK_STATUS, &isLinked);
@@ -122,7 +126,16 @@ ShaderProgram *ShadersManager::getSimpleProgram()
{
const std::string dir = paths.getStringValue("shaders");
return createProgram(dir + paths.getStringValue("simpleVertexShader"),
- dir + paths.getStringValue("simpleFragmentShader"));
+ dir + paths.getStringValue("simpleFragmentShader"),
+ true);
+}
+
+ShaderProgram *ShadersManager::getGles2Program()
+{
+ const std::string dir = paths.getStringValue("shaders");
+ return createProgram(dir + paths.getStringValue("gles2VertexShader"),
+ dir + paths.getStringValue("gles2FragmentShader"),
+ false);
}
#endif
diff --git a/src/render/shaders/shadersmanager.h b/src/render/shaders/shadersmanager.h
index 6c71dba17..b0cf56159 100644
--- a/src/render/shaders/shadersmanager.h
+++ b/src/render/shaders/shadersmanager.h
@@ -37,10 +37,13 @@ class ShadersManager final
const std::string &fileName) A_WARN_UNUSED;
ShaderProgram *createProgram(const std::string &vertex,
- const std::string &fragment)
+ const std::string &fragment,
+ const bool isNewShader)
A_WARN_UNUSED;
ShaderProgram *getSimpleProgram();
+
+ ShaderProgram *getGles2Program();
};
extern ShadersManager shaders;
diff --git a/src/resources/resourcemanager.cpp b/src/resources/resourcemanager.cpp
index f9f55ca03..bb566d9f4 100644
--- a/src/resources/resourcemanager.cpp
+++ b/src/resources/resourcemanager.cpp
@@ -763,6 +763,7 @@ struct ShaderProgramLoader final
{
const std::string vertex;
const std::string fragment;
+ const bool isNewShader;
static Resource *load(const void *const v)
{
@@ -772,15 +773,18 @@ struct ShaderProgramLoader final
const ShaderProgramLoader *const rl
= static_cast<const ShaderProgramLoader *const>(v);
ShaderProgram *const resource = shaders.createProgram(
- rl->vertex, rl->fragment);
+ rl->vertex,
+ rl->fragment,
+ rl->isNewShader);
return resource;
}
};
Resource *ResourceManager::getShaderProgram(const std::string &vertex,
- const std::string &fragment)
+ const std::string &fragment,
+ const bool isNewShader)
{
- ShaderProgramLoader rl = { vertex, fragment };
+ ShaderProgramLoader rl = { vertex, fragment, isNewShader };
return get("program_" + vertex + " + " + fragment,
ShaderProgramLoader::load, &rl);
}
diff --git a/src/resources/resourcemanager.h b/src/resources/resourcemanager.h
index 13d05f0b2..329820246 100644
--- a/src/resources/resourcemanager.h
+++ b/src/resources/resourcemanager.h
@@ -181,7 +181,8 @@ class ResourceManager final
const std::string &name) A_WARN_UNUSED;
Resource *getShaderProgram(const std::string &vertex,
- const std::string &fragment) A_WARN_UNUSED;
+ const std::string &fragment,
+ const bool isNewShader) A_WARN_UNUSED;
#endif
WalkLayer *getWalkLayer(const std::string &name, Map *const map);