Subversion Repository Public Repository

Divide-Framework

This repository has no backups
This repository's network speed is throttled to 100KB/sec

Diff Revisions 1016 vs 1017 for /trunk/Source Code/Platform/Video/OpenGL/Shaders/Headers/glShaderProgram.inl

Diff revisions: vs.
  @@ -35,6 +35,7 @@
35 35
36 36 namespace Divide {
37 37 namespace {
38 +
38 39 bool compare(GFX::PushConstantType type, const vectorImpl<AnyParam>& lhsVec, const vectorImpl<AnyParam>& rhsVec) {
39 40 for (vectorAlg::vecSize i = 0; i < lhsVec.size(); ++i) {
40 41 const AnyParam& lhs = lhsVec[i];
  @@ -76,26 +77,28 @@
76 77 return false;
77 78 }
78 79
79 - template<typename T>
80 - typename std::enable_if<!std::is_same<T, bool>::value, void>::type
81 - convert(const vectorImpl<AnyParam>& valuesIn, vectorImpl<T>& valuesOut) {
82 - std::transform(std::cbegin(valuesIn), std::cend(valuesIn), std::begin(valuesOut), [](const AnyParam& val)
83 - {
84 - return val.constant_cast<T>();
80 + template<typename T_in>
81 + typename std::enable_if<!std::is_same<T_in, bool>::value, void>::type
82 + convert(const vectorImpl<AnyParam>& valuesIn, vectorImpl<T_in>& valuesOut) {
83 + valuesOut.reserve(valuesIn.size());
84 +
85 + std::transform(std::cbegin(valuesIn), std::cend(valuesIn), std::begin(valuesOut), [](const AnyParam& val) {
86 + return val.constant_cast<T_in>();
85 87 });
86 88 }
87 89
88 - template<typename T>
89 - typename std::enable_if<std::is_same<T, bool>::value, void>::type
90 - convert(const vectorImpl<AnyParam>& valuesIn, vectorImpl<T>& valuesOut) {
91 - std::transform(std::cbegin(valuesIn), std::cend(valuesIn), std::begin(valuesOut), [](const AnyParam& val)
92 - {
90 + template<typename T_in>
91 + typename std::enable_if<std::is_same<T_in, bool>::value, void>::type
92 + convert(const vectorImpl<AnyParam>& valuesIn, vectorImpl<T_in>& valuesOut) {
93 + valuesOut.reserve(valuesIn.size());
94 +
95 + std::transform(std::cbegin(valuesIn), std::cend(valuesIn), std::begin(valuesOut), [](const AnyParam& val) {
93 96 return val.constant_cast<bool>() ? 1 : 0;
94 97 });
95 98 }
96 99
97 100 //ToDo: REALLY SLOW! Find a faster way of handling this! -Ionut
98 - template<typename T_out, typename T_in>
101 + template<typename T_out, size_t T_out_count, typename T_in>
99 102 struct castData {
100 103 castData(const vectorImpl<AnyParam>& values)
101 104 : _convertedData(values.size()),
  @@ -105,7 +108,7 @@
105 108 }
106 109
107 110 T_out* operator()() {
108 - return (T_out*)(_convertedData.data());
111 + return reinterpret_cast<T_out*>(_convertedData.data());
109 112 }
110 113
111 114 using vectorType = typename std::conditional<std::is_same<T_in, bool>::value, I32, T_in>::type;
  @@ -131,91 +134,91 @@
131 134 GLsizei count = (GLsizei)values.size();
132 135 switch (type) {
133 136 case GFX::PushConstantType::BOOL:
134 - glProgramUniform1iv(_shaderProgramID, binding, count, castData<GLint, bool>(values)());
137 + glProgramUniform1iv(_shaderProgramID, binding, count, castData<GLint, 1, bool>(values)());
135 138 break;
136 139 case GFX::PushConstantType::INT:
137 - glProgramUniform1iv(_shaderProgramID, binding, count, castData<GLint, I32>(values)());
140 + glProgramUniform1iv(_shaderProgramID, binding, count, castData<GLint, 1, I32>(values)());
138 141 break;
139 142 case GFX::PushConstantType::UINT:
140 - glProgramUniform1uiv(_shaderProgramID, binding, count, castData<GLuint, U32>(values)());
143 + glProgramUniform1uiv(_shaderProgramID, binding, count, castData<GLuint, 1, U32>(values)());
141 144 break;
142 145 case GFX::PushConstantType::DOUBLE: // Warning! Downcasting to float -Ionut
143 - glProgramUniform1fv(_shaderProgramID, binding, count, castData<GLfloat, D64>(values)());
146 + glProgramUniform1fv(_shaderProgramID, binding, count, castData<GLfloat, 1, D64>(values)());
144 147 break;
145 148 case GFX::PushConstantType::FLOAT:
146 - glProgramUniform1fv(_shaderProgramID, binding, count, castData<GLfloat, F32>(values)());
149 + glProgramUniform1fv(_shaderProgramID, binding, count, castData<GLfloat, 1, F32>(values)());
147 150 break;
148 151 case GFX::PushConstantType::IVEC2:
149 - glProgramUniform2iv(_shaderProgramID, binding, count, castData<GLint, vec2<I32>>(values)());
152 + glProgramUniform2iv(_shaderProgramID, binding, count, castData<GLint, 2, vec2<I32>>(values)());
150 153 break;
151 154 case GFX::PushConstantType::IVEC3:
152 - glProgramUniform3iv(_shaderProgramID, binding, count, castData<GLint, vec3<I32>>(values)());
155 + glProgramUniform3iv(_shaderProgramID, binding, count, castData<GLint, 3, vec3<I32>>(values)());
153 156 break;
154 157 case GFX::PushConstantType::IVEC4:
155 - glProgramUniform4iv(_shaderProgramID, binding, count, castData<GLint, vec4<I32>>(values)());
158 + glProgramUniform4iv(_shaderProgramID, binding, count, castData<GLint, 4, vec4<I32>>(values)());
156 159 break;
157 160 case GFX::PushConstantType::UVEC2:
158 - glProgramUniform2uiv(_shaderProgramID, binding, count, castData<GLuint, vec2<U32>>(values)());
161 + glProgramUniform2uiv(_shaderProgramID, binding, count, castData<GLuint, 2, vec2<U32>>(values)());
159 162 break;
160 163 case GFX::PushConstantType::UVEC3:
161 - glProgramUniform3uiv(_shaderProgramID, binding, count, castData<GLuint, vec3<U32>>(values)());
164 + glProgramUniform3uiv(_shaderProgramID, binding, count, castData<GLuint, 3, vec3<U32>>(values)());
162 165 break;
163 166 case GFX::PushConstantType::UVEC4:
164 - glProgramUniform4uiv(_shaderProgramID, binding, count, castData<GLuint, vec4<U32>>(values)());
167 + glProgramUniform4uiv(_shaderProgramID, binding, count, castData<GLuint, 4, vec4<U32>>(values)());
165 168 break;
166 169 case GFX::PushConstantType::DVEC2: // Warning! Downcasting to float -Ionut
167 - glProgramUniform2fv(_shaderProgramID, binding, count, castData<GLfloat, vec2<D64>>(values)());
170 + glProgramUniform2fv(_shaderProgramID, binding, count, castData<GLfloat, 2, vec2<D64>>(values)());
168 171 break;
169 172 case GFX::PushConstantType::VEC2:
170 - glProgramUniform2fv(_shaderProgramID, binding, count, castData<GLfloat, vec2<F32>>(values)());
173 + glProgramUniform2fv(_shaderProgramID, binding, count, castData<GLfloat, 2, vec2<F32>>(values)());
171 174 break;
172 175 case GFX::PushConstantType::DVEC3: // Warning! Downcasting to float -Ionut
173 - glProgramUniform3fv(_shaderProgramID, binding, count, castData<GLfloat, vec3<D64>>(values)());
176 + glProgramUniform3fv(_shaderProgramID, binding, count, castData<GLfloat, 3, vec3<D64>>(values)());
174 177 break;
175 178 case GFX::PushConstantType::VEC3:
176 - glProgramUniform3fv(_shaderProgramID, binding, count, castData<GLfloat, vec3<F32>>(values)());
179 + glProgramUniform3fv(_shaderProgramID, binding, count, castData<GLfloat, 3, vec3<F32>>(values)());
177 180 break;
178 181 case GFX::PushConstantType::DVEC4: // Warning! Downcasting to float -Ionut
179 - glProgramUniform4fv(_shaderProgramID, binding, count, castData<GLfloat, vec4<D64>>(values)());
182 + glProgramUniform4fv(_shaderProgramID, binding, count, castData<GLfloat, 4, vec4<D64>>(values)());
180 183 break;
181 184 case GFX::PushConstantType::VEC4:
182 - glProgramUniform4fv(_shaderProgramID, binding, count, castData<GLfloat, vec4<F32>>(values)());
185 + glProgramUniform4fv(_shaderProgramID, binding, count, castData<GLfloat, 4, vec4<F32>>(values)());
183 186 break;
184 187 case GFX::PushConstantType::IMAT2:
185 - glProgramUniformMatrix2fv(_shaderProgramID, binding, count, flag ? GL_TRUE : GL_FALSE, castData<GLfloat, mat2<I32>>(values)());
188 + glProgramUniformMatrix2fv(_shaderProgramID, binding, count, flag ? GL_TRUE : GL_FALSE, castData<GLfloat, 4, mat2<I32>>(values)());
186 189 break;
187 190 case GFX::PushConstantType::IMAT3:
188 - glProgramUniformMatrix3fv(_shaderProgramID, binding, count, flag ? GL_TRUE : GL_FALSE, castData<GLfloat, mat3<I32>>(values)());
191 + glProgramUniformMatrix3fv(_shaderProgramID, binding, count, flag ? GL_TRUE : GL_FALSE, castData<GLfloat, 9 , mat3<I32>>(values)());
189 192 break;
190 193 case GFX::PushConstantType::IMAT4:
191 - glProgramUniformMatrix4fv(_shaderProgramID, binding, count, flag ? GL_TRUE : GL_FALSE, castData<GLfloat, mat4<I32>>(values)());
194 + glProgramUniformMatrix4fv(_shaderProgramID, binding, count, flag ? GL_TRUE : GL_FALSE, castData<GLfloat, 16, mat4<I32>>(values)());
192 195 break;
193 196 case GFX::PushConstantType::UMAT2:
194 - glProgramUniformMatrix2fv(_shaderProgramID, binding, count, flag ? GL_TRUE : GL_FALSE, castData<GLfloat, mat2<U32>>(values)());
197 + glProgramUniformMatrix2fv(_shaderProgramID, binding, count, flag ? GL_TRUE : GL_FALSE, castData<GLfloat, 4, mat2<U32>>(values)());
195 198 break;
196 199 case GFX::PushConstantType::UMAT3:
197 - glProgramUniformMatrix3fv(_shaderProgramID, binding, count, flag ? GL_TRUE : GL_FALSE, castData<GLfloat, mat3<U32>>(values)());
200 + glProgramUniformMatrix3fv(_shaderProgramID, binding, count, flag ? GL_TRUE : GL_FALSE, castData<GLfloat, 9, mat3<U32>>(values)());
198 201 break;
199 202 case GFX::PushConstantType::UMAT4:
200 - glProgramUniformMatrix4fv(_shaderProgramID, binding, count, flag ? GL_TRUE : GL_FALSE, castData<GLfloat, mat4<U32>>(values)());
203 + glProgramUniformMatrix4fv(_shaderProgramID, binding, count, flag ? GL_TRUE : GL_FALSE, castData<GLfloat, 16, mat4<U32>>(values)());
201 204 break;
202 205 case GFX::PushConstantType::MAT2:
203 - glProgramUniformMatrix2fv(_shaderProgramID, binding, count, flag ? GL_TRUE : GL_FALSE, castData<GLfloat, mat2<F32>>(values)());
206 + glProgramUniformMatrix2fv(_shaderProgramID, binding, count, flag ? GL_TRUE : GL_FALSE, castData<GLfloat, 4, mat2<F32>>(values)());
204 207 break;
205 208 case GFX::PushConstantType::MAT3:
206 - glProgramUniformMatrix3fv(_shaderProgramID, binding, count, flag ? GL_TRUE : GL_FALSE, castData<GLfloat, mat3<F32>>(values)());
209 + glProgramUniformMatrix3fv(_shaderProgramID, binding, count, flag ? GL_TRUE : GL_FALSE, castData<GLfloat, 9, mat3<F32>>(values)());
207 210 break;
208 211 case GFX::PushConstantType::MAT4: {
209 - glProgramUniformMatrix4fv(_shaderProgramID, binding, count, flag ? GL_TRUE : GL_FALSE, castData<GLfloat, mat4<F32>>(values)());
212 + glProgramUniformMatrix4fv(_shaderProgramID, binding, count, flag ? GL_TRUE : GL_FALSE, castData<GLfloat, 16, mat4<F32>>(values)());
210 213 }break;
211 214 case GFX::PushConstantType::DMAT2:
212 - glProgramUniformMatrix2fv(_shaderProgramID, binding, count, flag ? GL_TRUE : GL_FALSE, castData<GLfloat, mat2<D64>>(values)());
215 + glProgramUniformMatrix2fv(_shaderProgramID, binding, count, flag ? GL_TRUE : GL_FALSE, castData<GLfloat, 4, mat2<D64>>(values)());
213 216 break;
214 217 case GFX::PushConstantType::DMAT3:
215 - glProgramUniformMatrix3fv(_shaderProgramID, binding, count, flag ? GL_TRUE : GL_FALSE, castData<GLfloat, mat3<D64>>(values)());
218 + glProgramUniformMatrix3fv(_shaderProgramID, binding, count, flag ? GL_TRUE : GL_FALSE, castData<GLfloat, 9, mat3<D64>>(values)());
216 219 break;
217 220 case GFX::PushConstantType::DMAT4:
218 - glProgramUniformMatrix4fv(_shaderProgramID, binding, count, flag ? GL_TRUE : GL_FALSE, castData<GLfloat, mat4<D64>>(values)());
221 + glProgramUniformMatrix4fv(_shaderProgramID, binding, count, flag ? GL_TRUE : GL_FALSE, castData<GLfloat, 16, mat4<D64>>(values)());
219 222 break;
220 223 default:
221 224 DIVIDE_ASSERT(false, "glShaderProgram::Uniform error: Unhandled data type!");