Subversion Repository Public Repository

Divide-Framework

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

Diff Revisions 330 vs 331 for /trunk/Source Code/Hardware/Video/OpenGL/GLWrapper.cpp

Diff revisions: vs.
  @@ -141,48 +141,86 @@
141 141 glswAddDirectiveToken("","//#pragma optionNV(unroll all)");
142 142 }
143 143 // Try to sync engine specific data and values with GLSL
144 - glswAddDirectiveToken("", ("#define MAX_CLIP_PLANES " + Util::toString(Config::MAX_CLIP_PLANES)).c_str());
145 - glswAddDirectiveToken("", ("#define MAX_SHADOW_CASTING_LIGHTS " + Util::toString(Config::Lighting::MAX_SHADOW_CASTING_LIGHTS_PER_NODE)).c_str());
146 - glswAddDirectiveToken("", ("const uint MAX_SPLITS_PER_LIGHT = " + Util::toString(Config::Lighting::MAX_SPLITS_PER_LIGHT) + ";").c_str());
147 - glswAddDirectiveToken("", ("const uint MAX_LIGHTS_PER_SCENE = " + Util::toString(Config::Lighting::MAX_LIGHTS_PER_SCENE) + ";").c_str());
148 - glswAddDirectiveToken("", ("#define SHADER_BUFFER_LIGHT_NORMAL " + Util::toString(SHADER_BUFFER_LIGHT_NORMAL)).c_str());
149 - glswAddDirectiveToken("", ("#define SHADER_BUFFER_GPU_BLOCK " + Util::toString(SHADER_BUFFER_GPU_BLOCK)).c_str());
150 - glswAddDirectiveToken("", ("#define SHADER_BUFFER_NODE_INFO " + Util::toString(SHADER_BUFFER_NODE_INFO)).c_str());
144 + glswAddDirectiveToken("", ("#define MAX_CLIP_PLANES " +
145 + Util::toString(Config::MAX_CLIP_PLANES)).c_str());
146 + glswAddDirectiveToken("", ("#define MAX_SHADOW_CASTING_LIGHTS " +
147 + Util::toString(Config::Lighting::MAX_SHADOW_CASTING_LIGHTS_PER_NODE)).c_str());
148 + glswAddDirectiveToken("", ("const uint MAX_SPLITS_PER_LIGHT = " +
149 + Util::toString(Config::Lighting::MAX_SPLITS_PER_LIGHT) + ";").c_str());
150 + glswAddDirectiveToken("", ("const uint MAX_LIGHTS_PER_SCENE = " +
151 + Util::toString(Config::Lighting::MAX_LIGHTS_PER_SCENE) + ";").c_str());
152 + glswAddDirectiveToken("", ("#define SHADER_BUFFER_LIGHT_NORMAL " +
153 + Util::toString(SHADER_BUFFER_LIGHT_NORMAL)).c_str());
154 + glswAddDirectiveToken("", ("#define SHADER_BUFFER_GPU_BLOCK " +
155 + Util::toString(SHADER_BUFFER_GPU_BLOCK)).c_str());
156 + glswAddDirectiveToken("", ("#define SHADER_BUFFER_NODE_INFO " +
157 + Util::toString(SHADER_BUFFER_NODE_INFO)).c_str());
151 158 glswAddDirectiveToken("", "const float Z_TEST_SIGMA = 0.0001;");
152 159 glswAddDirectiveToken("", "const float ALPHA_DISCARD_THRESHOLD = 0.25;");
153 160
154 161 glswAddDirectiveToken("Fragment", "#define VARYING in");
155 - glswAddDirectiveToken("Fragment", ("#define SHADER_BUFFER_LIGHT_SHADOW " + Util::toString(SHADER_BUFFER_LIGHT_SHADOW)).c_str());
156 - glswAddDirectiveToken("Fragment", ("#define MAX_TEXTURE_SLOTS " + Util::toString(ParamHandler::getInstance().getParam<I32>("rendering.maxTextureSlots", 16))).c_str());
157 - glswAddDirectiveToken("Fragment", ("#define TEXTURE_UNIT0 " + Util::toString(ShaderProgram::TEXTURE_UNIT0)).c_str());
158 - glswAddDirectiveToken("Fragment", ("#define TEXTURE_UNIT1 " + Util::toString(ShaderProgram::TEXTURE_UNIT1)).c_str());
159 - glswAddDirectiveToken("Fragment", ("#define TEXTURE_NORMALMAP " + Util::toString(ShaderProgram::TEXTURE_NORMALMAP)).c_str());
160 - glswAddDirectiveToken("Fragment", ("#define TEXTURE_OPACITY " + Util::toString(ShaderProgram::TEXTURE_OPACITY)).c_str());
161 - glswAddDirectiveToken("Fragment", ("#define TEXTURE_SPECULAR " + Util::toString(ShaderProgram::TEXTURE_SPECULAR)).c_str());
162 - glswAddDirectiveToken("Fragment", ("#define TEXTURE_PROJECTION " + Util::toString(ShaderProgram::TEXTURE_PROJECTION)).c_str());
163 - glswAddDirectiveToken("Fragment", ("#define SHADOW_CUBE_START " + Util::toString((U32)LightManager::getInstance().getShadowBindSlotOffset(LightManager::SHADOW_SLOT_TYPE_CUBE))).c_str());
164 - glswAddDirectiveToken("Fragment", ("#define SHADOW_NORMAL_START " + Util::toString((U32)LightManager::getInstance().getShadowBindSlotOffset(LightManager::SHADOW_SLOT_TYPE_NORMAL))).c_str());
165 - glswAddDirectiveToken("Fragment", ("#define SHADOW_ARRAY_START " + Util::toString((U32)LightManager::getInstance().getShadowBindSlotOffset(LightManager::SHADOW_SLOT_TYPE_ARRAY))).c_str());
162 + glswAddDirectiveToken("Fragment", ("#define SHADER_BUFFER_LIGHT_SHADOW " +
163 + Util::toString(SHADER_BUFFER_LIGHT_SHADOW)).c_str());
164 + glswAddDirectiveToken("Fragment", ("#define MAX_TEXTURE_SLOTS " +
165 + Util::toString(ParamHandler::getInstance().getParam<I32>("rendering.maxTextureSlots", 16))).c_str());
166 + glswAddDirectiveToken("Fragment", ("#define TEXTURE_UNIT0 " +
167 + Util::toString(ShaderProgram::TEXTURE_UNIT0)).c_str());
168 + glswAddDirectiveToken("Fragment", ("#define TEXTURE_UNIT1 " +
169 + Util::toString(ShaderProgram::TEXTURE_UNIT1)).c_str());
170 + glswAddDirectiveToken("Fragment", ("#define TEXTURE_NORMALMAP " +
171 + Util::toString(ShaderProgram::TEXTURE_NORMALMAP)).c_str());
172 + glswAddDirectiveToken("Fragment", ("#define TEXTURE_OPACITY " +
173 + Util::toString(ShaderProgram::TEXTURE_OPACITY)).c_str());
174 + glswAddDirectiveToken("Fragment", ("#define TEXTURE_SPECULAR " +
175 + Util::toString(ShaderProgram::TEXTURE_SPECULAR)).c_str());
176 + glswAddDirectiveToken("Fragment", ("#define TEXTURE_PROJECTION " +
177 + Util::toString(ShaderProgram::TEXTURE_PROJECTION)).c_str());
178 + glswAddDirectiveToken("Fragment", ("#define SHADOW_CUBE_START " +
179 + Util::toString((U32)LightManager::getInstance().getShadowBindSlotOffset(LightManager::SHADOW_SLOT_TYPE_CUBE))).c_str());
180 + glswAddDirectiveToken("Fragment", ("#define SHADOW_NORMAL_START " +
181 + Util::toString((U32)LightManager::getInstance().getShadowBindSlotOffset(LightManager::SHADOW_SLOT_TYPE_NORMAL))).c_str());
182 + glswAddDirectiveToken("Fragment", ("#define SHADOW_ARRAY_START " +
183 + Util::toString((U32)LightManager::getInstance().getShadowBindSlotOffset(LightManager::SHADOW_SLOT_TYPE_ARRAY))).c_str());
166 184 glswAddDirectiveToken("Fragment", "const uint DEPTH_EXP_WARP = 32;");
167 185
168 186 // GLSL <-> VBO intercommunication
169 187 glswAddDirectiveToken("Vertex", "#define VARYING out");
170 - glswAddDirectiveToken("Vertex", ("const uint MAX_BONE_COUNT_PER_NODE = " + Util::toString(Config::MAX_BONE_COUNT_PER_NODE) + ";").c_str());
171 - glswAddDirectiveToken("Vertex", ("#define SHADER_BUFFER_BONE_TRANSFORMS " + Util::toString(SHADER_BUFFER_BONE_TRANSFORMS)).c_str());
188 + glswAddDirectiveToken("Vertex", ("const uint MAX_BONE_COUNT_PER_NODE = " +
189 + Util::toString(Config::MAX_BONE_COUNT_PER_NODE) + ";").c_str());
190 + glswAddDirectiveToken("Vertex", ("#define SHADER_BUFFER_BONE_TRANSFORMS " +
191 + Util::toString(SHADER_BUFFER_BONE_TRANSFORMS)).c_str());
172 192 // Vertex data has a fixed format
173 - glswAddDirectiveToken("Vertex", ("layout(location = " + Util::toString(VERTEX_POSITION_LOCATION) + ") in vec3 inVertexData;").c_str());
174 - glswAddDirectiveToken("Vertex", ("layout(location = " + Util::toString(VERTEX_COLOR_LOCATION) + ") in vec4 inColorData;").c_str());
175 - glswAddDirectiveToken("Vertex", ("layout(location = " + Util::toString(VERTEX_NORMAL_LOCATION) + ") in vec3 inNormalData;").c_str());
176 - glswAddDirectiveToken("Vertex", ("layout(location = " + Util::toString(VERTEX_TEXCOORD_LOCATION) + ") in vec2 inTexCoordData;").c_str());
177 - glswAddDirectiveToken("Vertex", ("layout(location = " + Util::toString(VERTEX_TANGENT_LOCATION) + ") in vec3 inTangentData;").c_str());
178 - glswAddDirectiveToken("Vertex", ("layout(location = " + Util::toString(VERTEX_BITANGENT_LOCATION) + ") in vec3 inBiTangentData;").c_str());
179 - glswAddDirectiveToken("Vertex", ("layout(location = " + Util::toString(VERTEX_BONE_WEIGHT_LOCATION) + ") in vec4 inBoneWeightData;").c_str());
180 - glswAddDirectiveToken("Vertex", ("layout(location = " + Util::toString(VERTEX_BONE_INDICE_LOCATION) + ") in ivec4 inBoneIndiceData;").c_str());
181 - // GPU specific data, such as GFXDevice's main uniform block and clipping planes are defined in an external file included in every shader
193 + glswAddDirectiveToken("Vertex", ("layout(location = " +
194 + Util::toString(VERTEX_POSITION_LOCATION) +
195 + ") in vec3 inVertexData;").c_str());
196 + glswAddDirectiveToken("Vertex", ("layout(location = " +
197 + Util::toString(VERTEX_COLOR_LOCATION) +
198 + ") in vec4 inColorData;").c_str());
199 + glswAddDirectiveToken("Vertex", ("layout(location = " +
200 + Util::toString(VERTEX_NORMAL_LOCATION) +
201 + ") in vec3 inNormalData;").c_str());
202 + glswAddDirectiveToken("Vertex", ("layout(location = " +
203 + Util::toString(VERTEX_TEXCOORD_LOCATION) +
204 + ") in vec2 inTexCoordData;").c_str());
205 + glswAddDirectiveToken("Vertex", ("layout(location = " +
206 + Util::toString(VERTEX_TANGENT_LOCATION) +
207 + ") in vec3 inTangentData;").c_str());
208 + glswAddDirectiveToken("Vertex", ("layout(location = " +
209 + Util::toString(VERTEX_BITANGENT_LOCATION) +
210 + ") in vec3 inBiTangentData;").c_str());
211 + glswAddDirectiveToken("Vertex", ("layout(location = " +
212 + Util::toString(VERTEX_BONE_WEIGHT_LOCATION) +
213 + ") in vec4 inBoneWeightData;").c_str());
214 + glswAddDirectiveToken("Vertex", ("layout(location = " +
215 + Util::toString(VERTEX_BONE_INDICE_LOCATION) +
216 + ") in ivec4 inBoneIndiceData;").c_str());
217 + // GPU specific data, such as GFXDevice's main uniform block and clipping planes
218 + // are defined in an external file included in every shader
182 219 glswAddDirectiveToken("", "#include \"nodeDataInput.cmn\"");
183 220 // After we finish with all of the defines, add all of the custom uniform variables defined by each material
184 221 glswAddDirectiveToken("", "//__CUSTOM_UNIFORMS__");
185 - // Create an optimisation context used for post-processing shaders (using Aras Pranckevičius's glsl-optimizer: https://github.com/aras-p/glsl-optimizer )
222 + // Create an optimisation context used for post-processing shaders
223 + // (using Aras Pranckevičius's glsl-optimizer: https://github.com/aras-p/glsl-optimizer )
186 224 _GLSLOptContex = glslopt_initialize(GFX_DEVICE.getApi() == OpenGLES ? kGlslTargetOpenGLES30 : kGlslTargetOpenGL);
187 225 // Check initialization status for GLSL and glsl-optimizer
188 226 return (glswState == 1 && _GLSLOptContex != nullptr);
  @@ -225,7 +263,8 @@
225 263 return it->second;
226 264 }
227 265
228 - /// Text rendering is handled exclusively by Mikko Mononen's FontStash library (https://github.com/memononen/fontstash) with his OpenGL frontend adapted for core context profiles
266 + /// Text rendering is handled exclusively by Mikko Mononen's FontStash library (https://github.com/memononen/fontstash)
267 + /// with his OpenGL frontend adapted for core context profiles
229 268 void GL_API::drawText(const TextLabel& textLabel, const vec2<I32>& position) {
230 269 // Retrieve the font from the font cache
231 270 I32 font = getFont(textLabel._font);
  @@ -240,7 +279,11 @@
240 279 fonsSetFont(_fonsContext, font);
241 280 F32 lh = 0;
242 281 fonsVertMetrics(_fonsContext, nullptr, nullptr, &lh);
243 - fonsSetColor(_fonsContext, textLabel._color.r * 255, textLabel._color.g * 255, textLabel._color.b * 255, textLabel._color.a * 255);
282 + fonsSetColor(_fonsContext,
283 + textLabel._color.r * 255,
284 + textLabel._color.g * 255,
285 + textLabel._color.b * 255,
286 + textLabel._color.a * 255);
244 287
245 288 if (textLabel._blurAmount > 0.01f) {
246 289 fonsSetBlur(_fonsContext, textLabel._blurAmount );
  @@ -268,7 +311,10 @@
268 311 }
269 312
270 313 void GL_API::uploadDrawCommands(const vectorImpl<IndirectDrawCommand>& drawCommands) const {
271 - glNamedBufferDataEXT(_indirectDrawBuffer, sizeof(IndirectDrawCommand) * drawCommands.size(), drawCommands.data(), GL_DYNAMIC_COPY);
314 + glNamedBufferDataEXT(_indirectDrawBuffer,
315 + sizeof(IndirectDrawCommand) * drawCommands.size(),
316 + drawCommands.data(),
317 + GL_DYNAMIC_COPY);
272 318 }
273 319
274 320 /// Verify if we have a sampler object created and available for the given descriptor
  @@ -280,7 +326,7 @@
280 326 // If we fail to find it, we need to create a new sampler object
281 327 if (it == _samplerMap.end()) {
282 328 // Create and store the newly created sample object. GL_API is responsible for deleting these!
283 - hashAlg::emplace(_samplerMap, hashValue, New glSamplerObject(descriptor));
329 + hashAlg::emplace(_samplerMap, hashValue, MemoryManager_NEW glSamplerObject(descriptor));
284 330 }
285 331 // Return the sampler object's hash value
286 332 return hashValue;
  @@ -304,7 +350,7 @@
304 350
305 351 /// Create and return a new IM emulation primitive. The callee is responsible for it's deletion!
306 352 IMPrimitive* GL_API::newIMP() const {
307 - return New glIMPrimitive();
353 + return MemoryManager_NEW glIMPrimitive();
308 354 }
309 355
310 356 /// Create and return a new framebuffer. The callee is responsible for it's deletion!
  @@ -313,54 +359,58 @@
313 359 // If we requested a MultiSampledFramebuffer and MSAA is enabled, we also allocate a resolve framebuffer
314 360 // We set the resolve framebuffer as the requested framebuffer's child.
315 361 // The framebuffer is responsible for deleting it's own resolve child!
316 - return New glFramebuffer((multisampled && GFX_DEVICE.MSAAEnabled()) ? New glFramebuffer() : nullptr);
362 + return MemoryManager_NEW glFramebuffer((multisampled && GFX_DEVICE.MSAAEnabled()) ? MemoryManager_NEW glFramebuffer() :
363 + nullptr);
317 364 }
318 365
319 366 /// Create and return a new vertex array (VAO + VB + IB). The callee is responsible for it's deletion!
320 367 VertexBuffer* GL_API::newVB() const {
321 - return New glVertexArray();
368 + return MemoryManager_NEW glVertexArray();
322 369 }
323 370
324 371 /// Create and return a new pixel buffer using the requested format. The callee is responsible for it's deletion!
325 372 PixelBuffer* GL_API::newPB(const PBType& type) const {
326 - return New glPixelBuffer(type);
373 + return MemoryManager_NEW glPixelBuffer(type);
327 374 }
328 375
329 - /// Create and return a new generic vertex data object and, optionally set it as persistently mapped. The callee is responsible for it's deletion!
376 + /// Create and return a new generic vertex data object and, optionally set it as persistently mapped.
377 + /// The callee is responsible for it's deletion!
330 378 GenericVertexData* GL_API::newGVD(const bool persistentMapped) const {
331 - return New glGenericVertexData(persistentMapped);
379 + return MemoryManager_NEW glGenericVertexData(persistentMapped);
332 380 }
333 381
334 382 /// Create and return a new shader buffer. The callee is responsible for it's deletion!
335 - /// The OpenGL implementation creates either an 'Uniform Buffer Object' if unbound is false or a 'Shader Storage Block Object' otherwise
383 + /// The OpenGL implementation creates either an 'Uniform Buffer Object' if unbound is false
384 + /// or a 'Shader Storage Block Object' otherwise
336 385 ShaderBuffer* GL_API::newSB(const bool unbound, const bool persistentMapped) const {
337 386 // The shader buffer can also be persistently mapped, if requested
338 - return New glUniformBuffer(unbound, persistentMapped);
387 + return MemoryManager_NEW glUniformBuffer(unbound, persistentMapped);
339 388 }
340 389
341 390 /// Create and return a new texture array (optionally, flipped vertically). The callee is responsible for it's deletion!
342 391 Texture* GL_API::newTextureArray(const bool flipped) const {
343 - return New glTexture(TEXTURE_2D_ARRAY, flipped);
392 + return MemoryManager_NEW glTexture(TEXTURE_2D_ARRAY, flipped);
344 393 }
345 394
346 395 /// Create and return a new 2D texture (optionally, flipped vertically). The callee is responsible for it's deletion!
347 396 Texture* GL_API::newTexture2D(const bool flipped) const {
348 - return New glTexture(TEXTURE_2D, flipped);
397 + return MemoryManager_NEW glTexture(TEXTURE_2D, flipped);
349 398 }
350 399
351 400 /// Create and return a new cube texture (optionally, flipped vertically). The callee is responsible for it's deletion!
352 401 Texture* GL_API::newTextureCubemap(const bool flipped) const {
353 - return New glTexture(TEXTURE_CUBE_MAP, flipped);
402 + return MemoryManager_NEW glTexture(TEXTURE_CUBE_MAP, flipped);
354 403 }
355 404
356 405 /// Create and return a new shader program (optionally, post load optimised). The callee is responsible for it's deletion!
357 406 ShaderProgram* GL_API::newShaderProgram(const bool optimise) const {
358 - return New glShaderProgram(optimise);
407 + return MemoryManager_NEW glShaderProgram(optimise);
359 408 }
360 409
361 - /// Create and return a new shader of the specified type by loading the specified name (optionally, post load optimised). The callee is responsible for it's deletion!
410 + /// Create and return a new shader of the specified type by loading the specified name (optionally, post load optimised).
411 + /// The callee is responsible for it's deletion!
362 412 Shader* GL_API::newShader(const stringImpl& name, const ShaderType& type, const bool optimise) const {
363 - return New glShader(name,type,optimise);
413 + return MemoryManager_NEW glShader(name, type, optimise);
364 414 }
365 415
366 416 };