| 1 | // This file can be included several times. |
| 2 | #if (!defined(BACKEND_AS_OPENGL_ES) && !defined(ENGINE_CLIENT_BACKEND_OPENGL_OPENGL_SL_PROGRAM_H)) || \ |
| 3 | (defined(BACKEND_AS_OPENGL_ES) && !defined(ENGINE_CLIENT_BACKEND_OPENGL_OPENGL_SL_PROGRAM_H_AS_ES)) |
| 4 | |
| 5 | #if !defined(BACKEND_AS_OPENGL_ES) && !defined(ENGINE_CLIENT_BACKEND_OPENGL_OPENGL_SL_PROGRAM_H) |
| 6 | #define ENGINE_CLIENT_BACKEND_OPENGL_OPENGL_SL_PROGRAM_H |
| 7 | #endif |
| 8 | |
| 9 | #if defined(BACKEND_AS_OPENGL_ES) && !defined(ENGINE_CLIENT_BACKEND_OPENGL_OPENGL_SL_PROGRAM_H_AS_ES) |
| 10 | #define ENGINE_CLIENT_BACKEND_OPENGL_OPENGL_SL_PROGRAM_H_AS_ES |
| 11 | #endif |
| 12 | |
| 13 | #include <base/color.h> |
| 14 | #include <base/vmath.h> |
| 15 | |
| 16 | #include <engine/client/graphics_defines.h> |
| 17 | |
| 18 | class CGLSL; |
| 19 | |
| 20 | class CGLSLProgram |
| 21 | { |
| 22 | public: |
| 23 | void CreateProgram(); |
| 24 | void DeleteProgram(); |
| 25 | |
| 26 | bool AddShader(CGLSL *pShader) const; |
| 27 | |
| 28 | bool LinkProgram(); |
| 29 | void UseProgram() const; |
| 30 | TWGLuint GetProgramId() const; |
| 31 | |
| 32 | void DetachShader(CGLSL *pShader) const; |
| 33 | void DetachShaderById(TWGLuint ShaderId) const; |
| 34 | void DetachAllShaders() const; |
| 35 | |
| 36 | //Support various types |
| 37 | void SetUniformVec2(int Loc, int Count, const float *pValue); |
| 38 | void SetUniformVec4(int Loc, int Count, const float *pValue); |
| 39 | void SetUniform(int Loc, int Value); |
| 40 | void SetUniform(int Loc, bool Value); |
| 41 | void SetUniform(int Loc, float Value); |
| 42 | void SetUniform(int Loc, int Count, const float *pValues); |
| 43 | |
| 44 | //for performance reason we do not use SetUniform with using strings... save the Locations of the variables instead |
| 45 | int GetUniformLoc(const char *pName) const; |
| 46 | |
| 47 | CGLSLProgram(); |
| 48 | virtual ~CGLSLProgram(); |
| 49 | |
| 50 | protected: |
| 51 | TWGLuint m_ProgramId; |
| 52 | bool m_IsLinked; |
| 53 | }; |
| 54 | |
| 55 | class CGLSLTWProgram : public CGLSLProgram |
| 56 | { |
| 57 | public: |
| 58 | CGLSLTWProgram() : |
| 59 | m_LocPos(-1), m_LocTextureSampler(-1), m_LastTextureSampler(-1), m_LastIsTextured(-1) |
| 60 | { |
| 61 | m_LastScreenTL = m_LastScreenBR = vec2(-1, -1); |
| 62 | } |
| 63 | |
| 64 | int m_LocPos; |
| 65 | int m_LocTextureSampler; |
| 66 | |
| 67 | int m_LastTextureSampler; |
| 68 | int m_LastIsTextured; |
| 69 | vec2 m_LastScreenTL; |
| 70 | vec2 m_LastScreenBR; |
| 71 | }; |
| 72 | |
| 73 | class CGLSLTextProgram : public CGLSLTWProgram |
| 74 | { |
| 75 | public: |
| 76 | CGLSLTextProgram() |
| 77 | |
| 78 | { |
| 79 | m_LastColor[0] = m_LastColor[1] = m_LastColor[2] = m_LastColor[3] = -1.f; |
| 80 | m_LastOutlineColor[0] = m_LastOutlineColor[1] = m_LastOutlineColor[2] = m_LastOutlineColor[3] = -1.f; |
| 81 | m_LastTextSampler = m_LastTextOutlineSampler = -1; |
| 82 | m_LastTextureSize = -1; |
| 83 | } |
| 84 | |
| 85 | int m_LocColor; |
| 86 | int m_LocOutlineColor; |
| 87 | int m_LocTextSampler; |
| 88 | int m_LocTextOutlineSampler; |
| 89 | int m_LocTextureSize; |
| 90 | |
| 91 | ColorRGBA m_LastColor; |
| 92 | ColorRGBA m_LastOutlineColor; |
| 93 | int m_LastTextSampler; |
| 94 | int m_LastTextOutlineSampler; |
| 95 | int m_LastTextureSize; |
| 96 | }; |
| 97 | |
| 98 | class CGLSLPrimitiveProgram : public CGLSLTWProgram |
| 99 | { |
| 100 | public: |
| 101 | }; |
| 102 | |
| 103 | class CGLSLPrimitiveExProgram : public CGLSLTWProgram |
| 104 | { |
| 105 | public: |
| 106 | CGLSLPrimitiveExProgram() |
| 107 | |
| 108 | { |
| 109 | m_LastRotation = 0.f; |
| 110 | m_LastCenter = vec2(0, 0); |
| 111 | m_LastVerticesColor = ColorRGBA(-1, -1, -1, -1); |
| 112 | } |
| 113 | |
| 114 | int m_LocRotation; |
| 115 | int m_LocCenter; |
| 116 | int m_LocVertciesColor; |
| 117 | |
| 118 | float m_LastRotation; |
| 119 | vec2 m_LastCenter; |
| 120 | ColorRGBA m_LastVerticesColor; |
| 121 | }; |
| 122 | |
| 123 | class CGLSLSpriteMultipleProgram : public CGLSLTWProgram |
| 124 | { |
| 125 | public: |
| 126 | CGLSLSpriteMultipleProgram() |
| 127 | |
| 128 | { |
| 129 | m_LastCenter = vec2(0, 0); |
| 130 | m_LastVerticesColor = ColorRGBA(-1, -1, -1, -1); |
| 131 | } |
| 132 | |
| 133 | int m_LocRSP; |
| 134 | int m_LocCenter; |
| 135 | int m_LocVertciesColor; |
| 136 | |
| 137 | vec2 m_LastCenter; |
| 138 | ColorRGBA m_LastVerticesColor; |
| 139 | }; |
| 140 | |
| 141 | class CGLSLQuadProgram : public CGLSLTWProgram |
| 142 | { |
| 143 | public: |
| 144 | int m_LocColors; |
| 145 | int m_LocOffsets; |
| 146 | int m_LocRotations; |
| 147 | int m_LocQuadOffset; |
| 148 | }; |
| 149 | |
| 150 | class CGLSLTileProgram : public CGLSLTWProgram |
| 151 | { |
| 152 | public: |
| 153 | CGLSLTileProgram() : |
| 154 | m_LocColor(-1), m_LocOffset(-1), m_LocDir(-1), m_LocNum(-1), m_LocJumpIndex(-1) {} |
| 155 | |
| 156 | int m_LocColor; |
| 157 | int m_LocOffset; |
| 158 | int m_LocDir; |
| 159 | int m_LocScale = -1; |
| 160 | int m_LocNum; |
| 161 | int m_LocJumpIndex; |
| 162 | }; |
| 163 | |
| 164 | #endif |
| 165 | |