From 7aa5c9884fd95f89ae2f39159f8b329317b8fb32 Mon Sep 17 00:00:00 2001 From: ExMix Date: Tue, 24 Sep 2013 18:44:46 +0300 Subject: [PATCH] [drape] - move constants to separate file. it's need to use other opengl backend for testing - move check macroses. In testing enviroment CheckGLError must be empty. We don't need to link to real opengl for testing - separate glUniformValue function to glUniformValuei and glUniformValuef for explicit using --- drape/glIncludes.cpp | 10 -------- drape/glIncludes.hpp | 5 ---- drape/glconstants.cpp | 28 +++++++++++++++++++++ drape/glconstants.hpp | 36 +++++++++++++++++++++++++++ drape/glfunctions.cpp | 49 +++++++++++------------------------- drape/glfunctions.hpp | 55 +++++++++++------------------------------ drape/gpu_program.cpp | 2 +- drape/texture.cpp | 2 +- drape/uniform_value.cpp | 36 +++++++++++++++++++++------ drape/uniform_value.hpp | 18 +++++++------- 10 files changed, 132 insertions(+), 109 deletions(-) delete mode 100644 drape/glIncludes.cpp create mode 100644 drape/glconstants.cpp create mode 100644 drape/glconstants.hpp diff --git a/drape/glIncludes.cpp b/drape/glIncludes.cpp deleted file mode 100644 index d85cbe4631..0000000000 --- a/drape/glIncludes.cpp +++ /dev/null @@ -1,10 +0,0 @@ -#include "glIncludes.hpp" - -#include - -void CheckGLError() -{ - GLenum result = glGetError(); - if (result != GL_NO_ERROR) - assert(false); -} diff --git a/drape/glIncludes.hpp b/drape/glIncludes.hpp index 1afea50e0d..32e937510e 100644 --- a/drape/glIncludes.hpp +++ b/drape/glIncludes.hpp @@ -17,8 +17,3 @@ #include #define OGL_ANDROID #endif - -void CheckGLError(); - -#define GLCHECK(x) do { (x); CheckGLError(); } while (false) -#define GLCHECKCALL() do { CheckGLError(); } while (false) diff --git a/drape/glconstants.cpp b/drape/glconstants.cpp new file mode 100644 index 0000000000..aacde4e8ad --- /dev/null +++ b/drape/glconstants.cpp @@ -0,0 +1,28 @@ +#include "glconstants.hpp" +#include "glIncludes.hpp" + +namespace GLConst +{ + const glConst GLArrayBuffer = GL_ARRAY_BUFFER; + const glConst GLElementArrayBuffer = GL_ELEMENT_ARRAY_BUFFER; + + const glConst GLStaticDraw = GL_STATIC_DRAW; + const glConst GLStreamDraw = GL_STREAM_DRAW; + const glConst GLDynamicDraw = GL_DYNAMIC_DRAW; + + const glConst GLVertexShader = GL_VERTEX_SHADER; + const glConst GLFragmentShader = GL_FRAGMENT_SHADER; + const glConst GLCurrentProgram = GL_CURRENT_PROGRAM; + + const glConst GL8BitOnChannel = GL_UNSIGNED_BYTE; + const glConst GL4BitOnChannel = GL_UNSIGNED_SHORT_4_4_4_4; + + const glConst GLByteType = GL_BYTE; + const glConst GLUnsignedByteType = GL_UNSIGNED_BYTE; + const glConst GLShortType = GL_SHORT; + const glConst GLUnsignedShortType = GL_UNSIGNED_SHORT; + const glConst GLIntType = GL_INT; + const glConst GLUnsignedIntType = GL_UNSIGNED_INT; + const glConst GLFloatType = GL_FLOAT; + const glConst GLDoubleType = GL_DOUBLE; +} diff --git a/drape/glconstants.hpp b/drape/glconstants.hpp new file mode 100644 index 0000000000..c22fe1d560 --- /dev/null +++ b/drape/glconstants.hpp @@ -0,0 +1,36 @@ +#pragma once + +#include "../std/stdint.hpp" + +typedef uint32_t glConst; + +namespace GLConst +{ + /// Buffer targets + extern const glConst GLArrayBuffer; + extern const glConst GLElementArrayBuffer; + + /// BufferUsage + extern const glConst GLStaticDraw; + extern const glConst GLStreamDraw; + extern const glConst GLDynamicDraw; + + /// ShaderType + extern const glConst GLVertexShader; + extern const glConst GLFragmentShader; + extern const glConst GLCurrentProgram; + + /// Pixel type for texture upload + extern const glConst GL8BitOnChannel; + extern const glConst GL4BitOnChannel; + + /// OpenGL types + extern const glConst GLByteType; + extern const glConst GLUnsignedByteType; + extern const glConst GLShortType; + extern const glConst GLUnsignedShortType; + extern const glConst GLIntType; + extern const glConst GLUnsignedIntType; + extern const glConst GLFloatType; + extern const glConst GLDoubleType; +} diff --git a/drape/glfunctions.cpp b/drape/glfunctions.cpp index 48832ab77f..476a844dc8 100644 --- a/drape/glfunctions.cpp +++ b/drape/glfunctions.cpp @@ -66,32 +66,6 @@ namespace const int GLLinkStatus = GL_LINK_STATUS; } -namespace GLConst -{ - const glConst GLArrayBuffer = GL_ARRAY_BUFFER; - const glConst GLElementArrayBuffer = GL_ELEMENT_ARRAY_BUFFER; - - const glConst GLStaticDraw = GL_STATIC_DRAW; - const glConst GLStreamDraw = GL_STREAM_DRAW; - const glConst GLDynamicDraw = GL_DYNAMIC_DRAW; - - const glConst GLVertexShader = GL_VERTEX_SHADER; - const glConst GLFragmentShader = GL_FRAGMENT_SHADER; - const glConst GLCurrentProgram = GL_CURRENT_PROGRAM; - - const glConst GL8BitOnChannel = GL_UNSIGNED_BYTE; - const glConst GL4BitOnChannel = GL_UNSIGNED_SHORT_4_4_4_4; - - const glConst GLByteType = GL_BYTE; - const glConst GLUnsignedByteType = GL_UNSIGNED_BYTE; - const glConst GLShortType = GL_SHORT; - const glConst GLUnsignedShortType = GL_UNSIGNED_SHORT; - const glConst GLIntType = GL_INT; - const glConst GLUnsignedIntType = GL_UNSIGNED_INT; - const glConst GLFloatType = GL_FLOAT; - const glConst GLDoubleType = GL_DOUBLE; -} - void GLFunctions::Init() { /// VAO @@ -358,56 +332,56 @@ int8_t GLFunctions::glGetUniformLocation(uint32_t programID, const string & name return result; } -void GLFunctions::glUniformValue(int8_t location, int32_t v) +void GLFunctions::glUniformValuei(int8_t location, int32_t v) { ASSERT(glUniform1iFn != NULL, ()); ASSERT(location != -1, ()); GLCHECK(glUniform1iFn(location, v)); } -void GLFunctions::glUniformValue(int8_t location, int32_t v1, int32_t v2) +void GLFunctions::glUniformValuei(int8_t location, int32_t v1, int32_t v2) { ASSERT(glUniform2iFn != NULL, ()); ASSERT(location != -1, ()); GLCHECK(glUniform2iFn(location, v1, v2)); } -void GLFunctions::glUniformValue(int8_t location, int32_t v1, int32_t v2, int32_t v3) +void GLFunctions::glUniformValuei(int8_t location, int32_t v1, int32_t v2, int32_t v3) { ASSERT(glUniform3iFn != NULL, ()); ASSERT(location != -1, ()); GLCHECK(glUniform3iFn(location, v1, v2, v3)); } -void GLFunctions::glUniformValue(int8_t location, int32_t v1, int32_t v2, int32_t v3, int32_t v4) +void GLFunctions::glUniformValuei(int8_t location, int32_t v1, int32_t v2, int32_t v3, int32_t v4) { ASSERT(glUniform4iFn != NULL, ()); ASSERT(location != -1, ()); GLCHECK(glUniform4iFn(location, v1, v2, v3, v4)); } -void GLFunctions::glUniformValue(int8_t location, float v) +void GLFunctions::glUniformValuef(int8_t location, float v) { ASSERT(glUniform1fFn != NULL, ()); ASSERT(location != -1, ()); GLCHECK(glUniform1fFn(location, v)); } -void GLFunctions::glUniformValue(int8_t location, float v1, float v2) +void GLFunctions::glUniformValuef(int8_t location, float v1, float v2) { ASSERT(glUniform2fFn != NULL, ()); ASSERT(location != -1, ()); GLCHECK(glUniform2fFn(location, v1, v2)); } -void GLFunctions::glUniformValue(int8_t location, float v1, float v2, float v3) +void GLFunctions::glUniformValuef(int8_t location, float v1, float v2, float v3) { ASSERT(glUniform3fFn != NULL, ()); ASSERT(location != -1, ()); GLCHECK(glUniform3fFn(location, v1, v2, v3)); } -void GLFunctions::glUniformValue(int8_t location, float v1, float v2, float v3, float v4) +void GLFunctions::glUniformValuef(int8_t location, float v1, float v2, float v3, float v4) { ASSERT(glUniform4fFn != NULL, ()); ASSERT(location != -1, ()); @@ -466,3 +440,10 @@ void GLFunctions::glDrawElements(uint16_t indexCount) { GLCHECK(::glDrawElements(GL_TRIANGLES, indexCount, GL_UNSIGNED_SHORT, 0)); } + +void CheckGLError() +{ + GLenum result = glGetError(); + if (result != GL_NO_ERROR) + ASSERT(false, ()); +} diff --git a/drape/glfunctions.hpp b/drape/glfunctions.hpp index 95734e76af..9a940a6e8a 100644 --- a/drape/glfunctions.hpp +++ b/drape/glfunctions.hpp @@ -1,40 +1,8 @@ #pragma once +#include "glconstants.hpp" #include "../std/string.hpp" -typedef uint32_t glConst; - -namespace GLConst -{ - /// Buffer targets - extern const glConst GLArrayBuffer; - extern const glConst GLElementArrayBuffer; - - /// BufferUsage - extern const glConst GLStaticDraw; - extern const glConst GLStreamDraw; - extern const glConst GLDynamicDraw; - - /// ShaderType - extern const glConst GLVertexShader; - extern const glConst GLFragmentShader; - extern const glConst GLCurrentProgram; - - /// Pixel type for texture upload - extern const glConst GL8BitOnChannel; - extern const glConst GL4BitOnChannel; - - /// OpenGL types - extern const glConst GLByteType; - extern const glConst GLUnsignedByteType; - extern const glConst GLShortType; - extern const glConst GLUnsignedShortType; - extern const glConst GLIntType; - extern const glConst GLUnsignedIntType; - extern const glConst GLFloatType; - extern const glConst GLDoubleType; -} - class GLFunctions { public: @@ -90,15 +58,15 @@ public: uint32_t offset); static int8_t glGetUniformLocation(uint32_t programID, const string & name); - static void glUniformValue(int8_t location, int32_t v); - static void glUniformValue(int8_t location, int32_t v1, int32_t v2); - static void glUniformValue(int8_t location, int32_t v1, int32_t v2, int32_t v3); - static void glUniformValue(int8_t location, int32_t v1, int32_t v2, int32_t v3, int32_t v4); + static void glUniformValuei(int8_t location, int32_t v); + static void glUniformValuei(int8_t location, int32_t v1, int32_t v2); + static void glUniformValuei(int8_t location, int32_t v1, int32_t v2, int32_t v3); + static void glUniformValuei(int8_t location, int32_t v1, int32_t v2, int32_t v3, int32_t v4); - static void glUniformValue(int8_t location, float v); - static void glUniformValue(int8_t location, float v1, float v2); - static void glUniformValue(int8_t location, float v1, float v2, float v3); - static void glUniformValue(int8_t location, float v1, float v2, float v3, float v4); + static void glUniformValuef(int8_t location, float v); + static void glUniformValuef(int8_t location, float v1, float v2); + static void glUniformValuef(int8_t location, float v1, float v2, float v3); + static void glUniformValuef(int8_t location, float v1, float v2, float v3, float v4); static void glUniformMatrix4x4Value(int8_t location, float * values); @@ -115,3 +83,8 @@ public: // Draw support static void glDrawElements(uint16_t indexCount); }; + +void CheckGLError(); + +#define GLCHECK(x) do { (x); CheckGLError(); } while (false) +#define GLCHECKCALL() do { CheckGLError(); } while (false) diff --git a/drape/gpu_program.cpp b/drape/gpu_program.cpp index 1e3613c4c3..38264079db 100644 --- a/drape/gpu_program.cpp +++ b/drape/gpu_program.cpp @@ -52,5 +52,5 @@ void GpuProgram::ActivateSampler(uint8_t textureBlock, const string & samplerNam { ASSERT(GLFunctions::glGetCurrentProgram() == m_programID, ()); int8_t location = GLFunctions::glGetUniformLocation(m_programID, samplerName); - GLFunctions::glUniformValue(location, textureBlock); + GLFunctions::glUniformValuei(location, textureBlock); } diff --git a/drape/texture.cpp b/drape/texture.cpp index 1eabe609c2..3e905ba61b 100644 --- a/drape/texture.cpp +++ b/drape/texture.cpp @@ -69,7 +69,7 @@ void TextureBinding::Bind(int8_t uniformLocation) GLFunctions::glActiveTexture(m_samplerBlock); m_texture->Bind(); - GLFunctions::glUniformValue(uniformLocation, (int32_t)m_texture->GetID()); + GLFunctions::glUniformValuei(uniformLocation, (int32_t)m_texture->GetID()); } bool TextureBinding::IsEnabled() const diff --git a/drape/uniform_value.cpp b/drape/uniform_value.cpp index c0d330f590..e29856f39c 100644 --- a/drape/uniform_value.cpp +++ b/drape/uniform_value.cpp @@ -11,22 +11,42 @@ namespace dstPointer[i] = values[i]; } - template - void ApplyScalar(int8_t location, T * pointer, size_t componentCount) + void ApplyInt(int8_t location, int32_t * pointer, size_t componentCount) { switch (componentCount) { case 1: - GLFunctions::glUniformValue(location, pointer[0]); + GLFunctions::glUniformValuei(location, pointer[0]); break; case 2: - GLFunctions::glUniformValue(location, pointer[0], pointer[1]); + GLFunctions::glUniformValuei(location, pointer[0], pointer[1]); break; case 3: - GLFunctions::glUniformValue(location, pointer[0], pointer[1], pointer[2]); + GLFunctions::glUniformValuei(location, pointer[0], pointer[1], pointer[2]); break; case 4: - GLFunctions::glUniformValue(location, pointer[0], pointer[1], pointer[2], pointer[3]); + GLFunctions::glUniformValuei(location, pointer[0], pointer[1], pointer[2], pointer[3]); + break; + default: + ASSERT(false, ()); + } + } + + void ApplyFloat(int8_t location, float * pointer, size_t componentCount) + { + switch (componentCount) + { + case 1: + GLFunctions::glUniformValuef(location, pointer[0]); + break; + case 2: + GLFunctions::glUniformValuef(location, pointer[0], pointer[1]); + break; + case 3: + GLFunctions::glUniformValuef(location, pointer[0], pointer[1], pointer[2]); + break; + case 4: + GLFunctions::glUniformValuef(location, pointer[0], pointer[1], pointer[2], pointer[3]); break; default: ASSERT(false, ()); @@ -133,10 +153,10 @@ void UniformValue::Apply(ReferencePoiner program) uint8_t location = program->GetUniformLocation(m_name); switch (m_type) { case Int: - ApplyScalar(location, CastMemory(), m_componentCount); + ApplyInt(location, CastMemory(), m_componentCount); break; case Float: - ApplyScalar(location, CastMemory(), m_componentCount); + ApplyFloat(location, CastMemory(), m_componentCount); break; case Matrix4x4: ApplyMatrix(location, CastMemory()); diff --git a/drape/uniform_value.hpp b/drape/uniform_value.hpp index b4528f09e9..d8174047bb 100644 --- a/drape/uniform_value.hpp +++ b/drape/uniform_value.hpp @@ -9,17 +9,17 @@ class UniformValue { public: - UniformValue(const string & name, int32_t v); - UniformValue(const string & name, int32_t v1, int32_t v2); - UniformValue(const string & name, int32_t v1, int32_t v2, int32_t v3); - UniformValue(const string & name, int32_t v1, int32_t v2, int32_t v3, int32_t v4); + explicit UniformValue(const string & name, int32_t v); + explicit UniformValue(const string & name, int32_t v1, int32_t v2); + explicit UniformValue(const string & name, int32_t v1, int32_t v2, int32_t v3); + explicit UniformValue(const string & name, int32_t v1, int32_t v2, int32_t v3, int32_t v4); - UniformValue(const string & name, float v); - UniformValue(const string & name, float v1, float v2); - UniformValue(const string & name, float v1, float v2, float v3); - UniformValue(const string & name, float v1, float v2, float v3, float v4); + explicit UniformValue(const string & name, float v); + explicit UniformValue(const string & name, float v1, float v2); + explicit UniformValue(const string & name, float v1, float v2, float v3); + explicit UniformValue(const string & name, float v1, float v2, float v3, float v4); - UniformValue(const string & name, float * matrixValue); + explicit UniformValue(const string & name, float * matrixValue); void Apply(ReferencePoiner program);