From 1b5e8697fbcbbc2a99517e8e49fc607b88c4e071 Mon Sep 17 00:00:00 2001 From: Sam Gateau Date: Fri, 13 Feb 2015 11:41:58 -0800 Subject: [PATCH 01/12] modification on the managment of the light map shading --- .../render-utils/src/DeferredBufferWrite.slh | 6 +++--- .../render-utils/src/DeferredLighting.slh | 18 +++++++++++++----- .../src/directional_ambient_light.slf | 2 +- ...ional_ambient_light_cascaded_shadow_map.slf | 2 +- .../directional_ambient_light_shadow_map.slf | 2 +- .../render-utils/src/directional_light.slf | 2 +- .../directional_light_cascaded_shadow_map.slf | 2 +- .../src/directional_light_shadow_map.slf | 2 +- libraries/render-utils/src/model_lightmap.slf | 2 +- .../src/model_lightmap_normal_map.slf | 11 +++++++++-- .../src/model_lightmap_normal_specular_map.slf | 2 +- .../src/model_lightmap_specular_map.slf | 2 +- 12 files changed, 34 insertions(+), 19 deletions(-) diff --git a/libraries/render-utils/src/DeferredBufferWrite.slh b/libraries/render-utils/src/DeferredBufferWrite.slh index 066e0198b1..25c90939ac 100755 --- a/libraries/render-utils/src/DeferredBufferWrite.slh +++ b/libraries/render-utils/src/DeferredBufferWrite.slh @@ -27,11 +27,11 @@ void packDeferredFragment(vec3 normal, float alpha, vec3 diffuse, vec3 specular, gl_FragData[2] = vec4(specular, shininess / 128.0); } -void packDeferredFragmentLightmap(vec3 normal, float alpha, vec3 diffuse, vec3 specular, float shininess, vec3 emissive) { +void packDeferredFragmentLightmap(vec3 normal, float alpha, vec3 diffuse, vec3 specular, float shininess, vec4 lightmap) { gl_FragData[0] = vec4(diffuse.rgb, alpha); - //gl_FragData[1] = vec4(normal, 0.0) * 0.5 + vec4(0.5, 0.5, 0.5, 1.0); gl_FragData[1] = vec4(normal, 0.0) * 0.5 + vec4(0.5, 0.5, 0.5, 0.5); - gl_FragData[2] = vec4(emissive, shininess / 128.0); + //gl_FragData[2] = vec4(emissive, shininess / 128.0); + gl_FragData[2] = lightmap; } void packDeferredFragmentTranslucent(vec3 normal, float alpha, vec3 diffuse, vec3 specular, float shininess) { diff --git a/libraries/render-utils/src/DeferredLighting.slh b/libraries/render-utils/src/DeferredLighting.slh index cd65fd1053..81aa4cabaf 100755 --- a/libraries/render-utils/src/DeferredLighting.slh +++ b/libraries/render-utils/src/DeferredLighting.slh @@ -71,7 +71,7 @@ vec3 evalDirectionalColor(float shadowAttenuation, vec3 position, vec3 normal, v } -vec3 evalLightmappedColor(float shadowAttenuation, vec3 normal, vec3 diffuse, vec3 lightmap) { +vec3 evalLightmappedColor(float shadowAttenuation, vec3 normal, vec3 diffuse, vec4 lightmap) { float diffuseDot = dot(normal, gl_LightSource[0].position.xyz); @@ -79,17 +79,25 @@ vec3 evalLightmappedColor(float shadowAttenuation, vec3 normal, vec3 diffuse, ve // it should be just 0, but we have innacurracy so we need to overshoot const float PERPENDICULAR_THRESHOLD = -0.005; float facingLight = step(PERPENDICULAR_THRESHOLD, diffuseDot); - + + //float normalMapContrib = (lightmap.w != 0.0 ? diffuseDot * abs(2*lightmap.w - 1.0) : 1.0); + // float normalMapContrib = (lightmap.w != 0.0 ? diffuseDot * abs(2*lightmap.w - 1.0) : 1.0); + float normalMapContrib = 2.0 * (lightmap.w - 0.5); + // evaluate the shadow test but only relevant for light facing fragments float lightAttenuation = (1 - facingLight) + facingLight * shadowAttenuation; + lightAttenuation *= (normalMapContrib * max(0, diffuseDot) - (1.0 - normalMapContrib)); + // diffuse light is the lightmap dimmed by shadow - vec3 diffuseLight = lightAttenuation * lightmap; + vec3 diffuseLight = lightAttenuation * lightmap.rgb; // ambient is a tiny percentage of the lightmap and only when in the shadow - vec3 ambientLight = (1 - lightAttenuation) * 0.5 * lightmap; + vec3 ambientLight = (1 - lightAttenuation) * 0.5 * lightmap.rgb; - return diffuse * (ambientLight + diffuseLight); + + // return normal; + return diffuse * (ambientLight + diffuseLight); } diff --git a/libraries/render-utils/src/directional_ambient_light.slf b/libraries/render-utils/src/directional_ambient_light.slf index 803bd5ac30..05bc7329e4 100755 --- a/libraries/render-utils/src/directional_ambient_light.slf +++ b/libraries/render-utils/src/directional_ambient_light.slf @@ -26,7 +26,7 @@ void main(void) { 1.0, frag.normal, frag.diffuse, - frag.specularVal.xyz), + frag.specularVal), 1.0); } else { vec3 color = evalAmbientSphereColor(frag.normal, frag.diffuse, frag.specular, frag.gloss) diff --git a/libraries/render-utils/src/directional_ambient_light_cascaded_shadow_map.slf b/libraries/render-utils/src/directional_ambient_light_cascaded_shadow_map.slf index 5f88c558d3..2250efec01 100755 --- a/libraries/render-utils/src/directional_ambient_light_cascaded_shadow_map.slf +++ b/libraries/render-utils/src/directional_ambient_light_cascaded_shadow_map.slf @@ -33,7 +33,7 @@ void main(void) { shadowAttenuation, frag.normal, frag.diffuse, - frag.specularVal.xyz), + frag.specularVal), 1.0); } else { vec3 color = evalAmbientSphereColor(frag.normal, frag.diffuse, frag.specular, frag.gloss) diff --git a/libraries/render-utils/src/directional_ambient_light_shadow_map.slf b/libraries/render-utils/src/directional_ambient_light_shadow_map.slf index 6c241853e3..107382620b 100755 --- a/libraries/render-utils/src/directional_ambient_light_shadow_map.slf +++ b/libraries/render-utils/src/directional_ambient_light_shadow_map.slf @@ -34,7 +34,7 @@ void main(void) { shadowAttenuation, frag.normal, frag.diffuse, - frag.specularVal.xyz), + frag.specularVal), 1.0); } else { vec3 color = evalAmbientSphereColor(frag.normal, frag.diffuse, frag.specular, frag.gloss) diff --git a/libraries/render-utils/src/directional_light.slf b/libraries/render-utils/src/directional_light.slf index 8ff6cd6c87..dc1d140e2e 100644 --- a/libraries/render-utils/src/directional_light.slf +++ b/libraries/render-utils/src/directional_light.slf @@ -26,7 +26,7 @@ void main(void) { 1.0, frag.normal, frag.diffuse, - frag.specularVal.xyz), + frag.specularVal), 1.0); } else { vec3 color = evalAmbientColor(frag.normal, frag.diffuse, frag.specular, frag.gloss) diff --git a/libraries/render-utils/src/directional_light_cascaded_shadow_map.slf b/libraries/render-utils/src/directional_light_cascaded_shadow_map.slf index ccf8909b64..df6e24964f 100644 --- a/libraries/render-utils/src/directional_light_cascaded_shadow_map.slf +++ b/libraries/render-utils/src/directional_light_cascaded_shadow_map.slf @@ -33,7 +33,7 @@ void main(void) { shadowAttenuation, frag.normal, frag.diffuse, - frag.specularVal.xyz), + frag.specularVal), 1.0); } else { vec3 color = evalAmbientColor(frag.normal, frag.diffuse, frag.specular, frag.gloss) diff --git a/libraries/render-utils/src/directional_light_shadow_map.slf b/libraries/render-utils/src/directional_light_shadow_map.slf index 13435e9101..dce2388ac4 100644 --- a/libraries/render-utils/src/directional_light_shadow_map.slf +++ b/libraries/render-utils/src/directional_light_shadow_map.slf @@ -34,7 +34,7 @@ void main(void) { shadowAttenuation, frag.normal, frag.diffuse, - frag.specularVal.xyz), + frag.specularVal), 1.0); } else { vec3 color = evalAmbientColor(frag.normal, frag.diffuse, frag.specular, frag.gloss) diff --git a/libraries/render-utils/src/model_lightmap.slf b/libraries/render-utils/src/model_lightmap.slf index 59836e9737..be9418634b 100755 --- a/libraries/render-utils/src/model_lightmap.slf +++ b/libraries/render-utils/src/model_lightmap.slf @@ -42,5 +42,5 @@ void main(void) { getMaterialDiffuse(mat) * diffuse.rgb, getMaterialSpecular(mat), getMaterialShininess(mat), - (vec3(emissiveParams.x) + emissiveParams.y * emissive.rgb)); + vec4(vec3(emissiveParams.x) + emissiveParams.y * emissive.rgb, 0.0)); } diff --git a/libraries/render-utils/src/model_lightmap_normal_map.slf b/libraries/render-utils/src/model_lightmap_normal_map.slf index 6310ab0086..3e55675106 100755 --- a/libraries/render-utils/src/model_lightmap_normal_map.slf +++ b/libraries/render-utils/src/model_lightmap_normal_map.slf @@ -39,7 +39,7 @@ void main(void) { vec3 normalizedNormal = normalize(vec3(interpolatedNormal)); vec3 normalizedTangent = normalize(vec3(interpolatedTangent)); vec3 normalizedBitangent = normalize(cross(normalizedNormal, normalizedTangent)); - vec3 localNormal = vec3(texture2D(normalMap, gl_TexCoord[0].st)) - vec3(0.5, 0.5, 0.5); + vec3 localNormal = normalize(vec3(texture2D(normalMap, gl_TexCoord[0].st)) - vec3(0.5, 0.5, 0.5)); vec4 viewNormal = vec4(normalizedTangent * localNormal.x + normalizedBitangent * localNormal.y + normalizedNormal * localNormal.z, 0.0); @@ -47,6 +47,13 @@ void main(void) { vec4 diffuse = texture2D(diffuseMap, gl_TexCoord[0].st); vec4 emissive = texture2D(emissiveMap, interpolatedTexcoord1.st); + // WE have lightmap AND normal map so we are going to alter the lighting intensity + // from the lightmap with the dot product between the surface normal and the normal map + // Why will you ask? because we want to see something out of the normal map and since + // the lighting from the lightmap doesnt't give a light direction, we just hack one... + vec4 lightIntensity = vec4(vec3(emissiveParams.x) + emissiveParams.y * emissive.rgb, + 0.5 * dot(localNormal, vec3(0.0, 1.0, 0.0)) + 0.5 ); + Material mat = getMaterial(); packDeferredFragmentLightmap( @@ -55,5 +62,5 @@ void main(void) { getMaterialDiffuse(mat) * diffuse.rgb, getMaterialSpecular(mat), getMaterialShininess(mat), - (vec3(emissiveParams.x) + emissiveParams.y * emissive.rgb)); + lightIntensity); } diff --git a/libraries/render-utils/src/model_lightmap_normal_specular_map.slf b/libraries/render-utils/src/model_lightmap_normal_specular_map.slf index ab555ea0c0..9564071d64 100755 --- a/libraries/render-utils/src/model_lightmap_normal_specular_map.slf +++ b/libraries/render-utils/src/model_lightmap_normal_specular_map.slf @@ -59,5 +59,5 @@ void main(void) { getMaterialDiffuse(mat) * diffuse.rgb, specular, // no use of getMaterialSpecular(mat) getMaterialShininess(mat), - (vec3(emissiveParams.x) + emissiveParams.y * emissive.rgb)); + vec4(vec3(emissiveParams.x) + emissiveParams.y * emissive.rgb, 0.0)); } diff --git a/libraries/render-utils/src/model_lightmap_specular_map.slf b/libraries/render-utils/src/model_lightmap_specular_map.slf index 2973882e8a..b511e1d976 100755 --- a/libraries/render-utils/src/model_lightmap_specular_map.slf +++ b/libraries/render-utils/src/model_lightmap_specular_map.slf @@ -45,5 +45,5 @@ void main(void) { getMaterialDiffuse(mat) * diffuse.rgb, specular, // no use of getMaterialSpecular(mat) getMaterialShininess(mat), - (vec3(emissiveParams.x) + emissiveParams.y * emissive.rgb)); + vec4(vec3(emissiveParams.x) + emissiveParams.y * emissive.rgb, 0.0)); } From 767407af9c0e71fab9c5fcc9366a8a8568011294 Mon Sep 17 00:00:00 2001 From: samcake Date: Fri, 18 Sep 2015 11:46:44 -0700 Subject: [PATCH 02/12] Merging and cleaning shaders --- libraries/render-utils/src/DeferredBufferWrite.slh | 1 + libraries/render-utils/src/DeferredGlobalLight.slh | 11 +++-------- libraries/render-utils/src/model_lightmap.slf | 2 +- .../render-utils/src/model_lightmap_normal_map.slf | 10 +--------- .../src/model_lightmap_normal_specular_map.slf | 2 +- .../render-utils/src/model_lightmap_specular_map.slf | 2 +- 6 files changed, 8 insertions(+), 20 deletions(-) diff --git a/libraries/render-utils/src/DeferredBufferWrite.slh b/libraries/render-utils/src/DeferredBufferWrite.slh index 8666a80386..b9b0198ba5 100755 --- a/libraries/render-utils/src/DeferredBufferWrite.slh +++ b/libraries/render-utils/src/DeferredBufferWrite.slh @@ -60,6 +60,7 @@ void packDeferredFragmentLightmap(vec3 normal, float alpha, vec3 diffuse, vec3 s } _fragColor0 = vec4(diffuse.rgb, alpha); + //_fragColor1 = vec4(normal, 0.0) * 0.5 + vec4(0.5, 0.5, 0.5, 1.0); _fragColor1 = vec4(bestFitNormal(normal), 0.5); _fragColor2 = vec4(emissive, shininess / 128.0); } diff --git a/libraries/render-utils/src/DeferredGlobalLight.slh b/libraries/render-utils/src/DeferredGlobalLight.slh index 5f32bb5fe6..9f29a25cf0 100755 --- a/libraries/render-utils/src/DeferredGlobalLight.slh +++ b/libraries/render-utils/src/DeferredGlobalLight.slh @@ -135,7 +135,6 @@ vec3 evalSkyboxGlobalColor(mat4 invViewMat, float shadowAttenuation, vec3 positi } <@endfunc@> - <@func declareEvalLightmappedColor()@> vec3 evalLightmappedColor(mat4 invViewMat, float shadowAttenuation, vec3 normal, vec3 diffuse, vec3 lightmap) { @@ -148,22 +147,18 @@ vec3 evalLightmappedColor(mat4 invViewMat, float shadowAttenuation, vec3 normal, // it should be just 0, but we have innacurracy so we need to overshoot const float PERPENDICULAR_THRESHOLD = -0.005; float facingLight = step(PERPENDICULAR_THRESHOLD, diffuseDot); + //float facingLight = step(PERPENDICULAR_THRESHOLD, diffuseDot); // evaluate the shadow test but only relevant for light facing fragments float lightAttenuation = (1 - facingLight) + facingLight * shadowAttenuation; - - // lightAttenuation *= (abs(normalMapContrib) * max(0, diffuseDot) + (1.0 - abs(normalMapContrib))); - lightAttenuation *= (abs(normalMapContrib) * max(0, diffuseDot)); // diffuse light is the lightmap dimmed by shadow - vec3 diffuseLight = lightAttenuation * lightmap.rgb; + vec3 diffuseLight = lightAttenuation * lightmap; // ambient is a tiny percentage of the lightmap and only when in the shadow vec3 ambientLight = (1 - lightAttenuation) * lightmap * getLightAmbientIntensity(light); - // return normal; - return diffuse * (ambientLight + diffuseLight); - // return lightmap.rgb; + return diffuse * (ambientLight + diffuseLight); } <@endfunc@> diff --git a/libraries/render-utils/src/model_lightmap.slf b/libraries/render-utils/src/model_lightmap.slf index 02598fdb59..ab92d2bf4c 100755 --- a/libraries/render-utils/src/model_lightmap.slf +++ b/libraries/render-utils/src/model_lightmap.slf @@ -41,5 +41,5 @@ void main(void) { getMaterialDiffuse(mat) * diffuse.rgb * _color, getMaterialSpecular(mat), getMaterialShininess(mat), - vec4(vec3(emissiveParams.x) + emissiveParams.y * emissive.rgb, 0.0)); + (vec3(emissiveParams.x) + emissiveParams.y * emissive.rgb)); } diff --git a/libraries/render-utils/src/model_lightmap_normal_map.slf b/libraries/render-utils/src/model_lightmap_normal_map.slf index 1a22343958..78c802be51 100755 --- a/libraries/render-utils/src/model_lightmap_normal_map.slf +++ b/libraries/render-utils/src/model_lightmap_normal_map.slf @@ -39,7 +39,6 @@ void main(void) { vec3 normalizedTangent = normalize(_tangent); vec3 normalizedBitangent = normalize(cross(normalizedNormal, normalizedTangent)); vec3 localNormal = vec3(texture(normalMap, _texCoord0)) - vec3(0.5, 0.5, 0.5); - vec4 viewNormal = vec4(normalizedTangent * localNormal.x + normalizedBitangent * localNormal.y + normalizedNormal * localNormal.z, 0.0); @@ -47,13 +46,6 @@ void main(void) { vec4 diffuse = texture(diffuseMap, _texCoord0); vec4 emissive = texture(emissiveMap, _texCoord1); - // WE have lightmap AND normal map so we are going to alter the lighting intensity - // from the lightmap with the dot product between the surface normal and the normal map - // Why will you ask? because we want to see something out of the normal map and since - // the lighting from the lightmap doesnt't give a light direction, we just hack one... - vec4 lightIntensity = vec4(vec3(emissiveParams.x) + emissiveParams.y * emissive.rgb, - 0.5 * dot(localNormal, vec3(0.0, 1.0, 0.0)) + 0.5 ); - Material mat = getMaterial(); packDeferredFragmentLightmap( @@ -62,5 +54,5 @@ void main(void) { getMaterialDiffuse(mat) * diffuse.rgb * _color, getMaterialSpecular(mat), getMaterialShininess(mat), - lightIntensity); + (vec3(emissiveParams.x) + emissiveParams.y * emissive.rgb)); } diff --git a/libraries/render-utils/src/model_lightmap_normal_specular_map.slf b/libraries/render-utils/src/model_lightmap_normal_specular_map.slf index 83423ac3c7..1b7416baa5 100755 --- a/libraries/render-utils/src/model_lightmap_normal_specular_map.slf +++ b/libraries/render-utils/src/model_lightmap_normal_specular_map.slf @@ -58,5 +58,5 @@ void main(void) { getMaterialDiffuse(mat) * diffuse.rgb * _color, specular, // no use of getMaterialSpecular(mat) getMaterialShininess(mat), - vec4(vec3(emissiveParams.x) + emissiveParams.y * emissive.rgb, 0.0)); + (vec3(emissiveParams.x) + emissiveParams.y * emissive.rgb)); } diff --git a/libraries/render-utils/src/model_lightmap_specular_map.slf b/libraries/render-utils/src/model_lightmap_specular_map.slf index 83f232c958..efdfcd6be9 100755 --- a/libraries/render-utils/src/model_lightmap_specular_map.slf +++ b/libraries/render-utils/src/model_lightmap_specular_map.slf @@ -46,5 +46,5 @@ void main(void) { getMaterialDiffuse(mat) * diffuse.rgb * _color, specular, // no use of getMaterialSpecular(mat) getMaterialShininess(mat), - vec4(vec3(emissiveParams.x) + emissiveParams.y * emissive.rgb, 0.0)); + (vec3(emissiveParams.x) + emissiveParams.y * emissive.rgb)); } From 5f5cc3dbafb55c450b966c4772ad79440d604e05 Mon Sep 17 00:00:00 2001 From: samcake Date: Fri, 18 Sep 2015 11:51:28 -0700 Subject: [PATCH 03/12] fix typos --- libraries/render-utils/src/DeferredGlobalLight.slh | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/libraries/render-utils/src/DeferredGlobalLight.slh b/libraries/render-utils/src/DeferredGlobalLight.slh index 9f29a25cf0..16cd272da5 100755 --- a/libraries/render-utils/src/DeferredGlobalLight.slh +++ b/libraries/render-utils/src/DeferredGlobalLight.slh @@ -147,18 +147,17 @@ vec3 evalLightmappedColor(mat4 invViewMat, float shadowAttenuation, vec3 normal, // it should be just 0, but we have innacurracy so we need to overshoot const float PERPENDICULAR_THRESHOLD = -0.005; float facingLight = step(PERPENDICULAR_THRESHOLD, diffuseDot); - //float facingLight = step(PERPENDICULAR_THRESHOLD, diffuseDot); + //float facingLight = step(PERPENDICULAR_THRESHOLD, diffuseDot); // evaluate the shadow test but only relevant for light facing fragments float lightAttenuation = (1 - facingLight) + facingLight * shadowAttenuation; - // diffuse light is the lightmap dimmed by shadow vec3 diffuseLight = lightAttenuation * lightmap; // ambient is a tiny percentage of the lightmap and only when in the shadow vec3 ambientLight = (1 - lightAttenuation) * lightmap * getLightAmbientIntensity(light); - return diffuse * (ambientLight + diffuseLight); + return diffuse * (ambientLight + diffuseLight); } <@endfunc@> From 64cf8590ebccddac204b31d2645e3ae5dcd62020 Mon Sep 17 00:00:00 2001 From: samcake Date: Fri, 18 Sep 2015 11:51:58 -0700 Subject: [PATCH 04/12] fix typos --- libraries/render-utils/src/DeferredGlobalLight.slh | 1 - 1 file changed, 1 deletion(-) diff --git a/libraries/render-utils/src/DeferredGlobalLight.slh b/libraries/render-utils/src/DeferredGlobalLight.slh index 16cd272da5..983b8002f7 100755 --- a/libraries/render-utils/src/DeferredGlobalLight.slh +++ b/libraries/render-utils/src/DeferredGlobalLight.slh @@ -148,7 +148,6 @@ vec3 evalLightmappedColor(mat4 invViewMat, float shadowAttenuation, vec3 normal, const float PERPENDICULAR_THRESHOLD = -0.005; float facingLight = step(PERPENDICULAR_THRESHOLD, diffuseDot); //float facingLight = step(PERPENDICULAR_THRESHOLD, diffuseDot); - // evaluate the shadow test but only relevant for light facing fragments float lightAttenuation = (1 - facingLight) + facingLight * shadowAttenuation; // diffuse light is the lightmap dimmed by shadow From deaa4a747b57d1996365df5a5d45a1bcfa70942d Mon Sep 17 00:00:00 2001 From: Brad Davis Date: Tue, 22 Sep 2015 10:11:49 -0700 Subject: [PATCH 05/12] Batch side implementation of multi-draw indirect --- libraries/gpu/src/gpu/Batch.cpp | 27 +++ libraries/gpu/src/gpu/Batch.h | 36 +++- libraries/gpu/src/gpu/GLBackend.cpp | 56 +++++- libraries/gpu/src/gpu/GLBackend.h | 13 +- libraries/gpu/src/gpu/GLBackendInput.cpp | 37 ++-- libraries/render-utils/src/GeometryCache.cpp | 17 +- libraries/render-utils/src/GeometryCache.h | 14 +- tests/gpu-test/src/main.cpp | 196 +++++++++++++++---- 8 files changed, 318 insertions(+), 78 deletions(-) diff --git a/libraries/gpu/src/gpu/Batch.cpp b/libraries/gpu/src/gpu/Batch.cpp index e6e176be88..15b841dd04 100644 --- a/libraries/gpu/src/gpu/Batch.cpp +++ b/libraries/gpu/src/gpu/Batch.cpp @@ -102,6 +102,19 @@ void Batch::drawIndexedInstanced(uint32 nbInstances, Primitive primitiveType, ui _params.push_back(nbInstances); } + +void Batch::multiDrawIndirect(uint32 nbCommands, Primitive primitiveType) { + ADD_COMMAND(multiDrawIndirect); + _params.push_back(nbCommands); + _params.push_back(primitiveType); +} + +void Batch::multiDrawIndexedIndirect(uint32 nbCommands, Primitive primitiveType) { + ADD_COMMAND(multiDrawIndexedIndirect); + _params.push_back(nbCommands); + _params.push_back(primitiveType); +} + void Batch::setInputFormat(const Stream::FormatPointer& format) { ADD_COMMAND(setInputFormat); @@ -144,6 +157,15 @@ void Batch::setIndexBuffer(const BufferView& buffer) { setIndexBuffer(buffer._element.getType(), buffer._buffer, buffer._offset); } +void Batch::setIndirectBuffer(const BufferPointer& buffer, Offset offset, Offset stride) { + ADD_COMMAND(setIndirectBuffer); + + _params.push_back(_buffers.cache(buffer)); + _params.push_back(offset); + _params.push_back(stride); +} + + void Batch::setModelTransform(const Transform& model) { ADD_COMMAND(setModelTransform); @@ -288,6 +310,11 @@ void Batch::resetStages() { ADD_COMMAND(resetStages); } +void Batch::runLambda(std::function f) { + ADD_COMMAND(runLambda); + _params.push_back(_lambdas.cache(f)); +} + void Batch::enableStereo(bool enable) { _enableStereo = enable; } diff --git a/libraries/gpu/src/gpu/Batch.h b/libraries/gpu/src/gpu/Batch.h index ec6fb26c34..6dd92739c5 100644 --- a/libraries/gpu/src/gpu/Batch.h +++ b/libraries/gpu/src/gpu/Batch.h @@ -63,8 +63,8 @@ public: void process(Batch& batch) { if (_function) { - _function(batch, *this); - } + _function(batch, *this); + } } }; @@ -96,12 +96,15 @@ public: void drawIndexed(Primitive primitiveType, uint32 nbIndices, uint32 startIndex = 0); void drawInstanced(uint32 nbInstances, Primitive primitiveType, uint32 nbVertices, uint32 startVertex = 0, uint32 startInstance = 0); void drawIndexedInstanced(uint32 nbInstances, Primitive primitiveType, uint32 nbIndices, uint32 startIndex = 0, uint32 startInstance = 0); + void multiDrawIndirect(uint32 nbCommands, Primitive primitiveType); + void multiDrawIndexedIndirect(uint32 nbCommands, Primitive primitiveType); void setupNamedCalls(const std::string& instanceName, size_t count, NamedBatchData::Function function); void setupNamedCalls(const std::string& instanceName, NamedBatchData::Function function); BufferPointer getNamedBuffer(const std::string& instanceName, uint8_t index = 0); - + void setNamedBuffer(const std::string& instanceName, BufferPointer& buffer, uint8_t index = 0); + // Input Stage @@ -117,6 +120,8 @@ public: void setIndexBuffer(Type type, const BufferPointer& buffer, Offset offset); void setIndexBuffer(const BufferView& buffer); // not a command, just a shortcut from a BufferView + void setIndirectBuffer(const BufferPointer& buffer, Offset offset = 0, Offset stride = 0); + // Transform Stage // Vertex position is transformed by ModelTransform from object space to world space // Then by the inverse of the ViewTransform from world space to eye space @@ -169,6 +174,8 @@ public: // Reset the stage caches and states void resetStages(); + void runLambda(std::function f); + // TODO: As long as we have gl calls explicitely issued from interface // code, we need to be able to record and batch these calls. THe long // term strategy is to get rid of any GL calls in favor of the HIFI GPU API @@ -194,10 +201,13 @@ public: COMMAND_drawIndexed, COMMAND_drawInstanced, COMMAND_drawIndexedInstanced, + COMMAND_multiDrawIndirect, + COMMAND_multiDrawIndexedIndirect, COMMAND_setInputFormat, COMMAND_setInputBuffer, COMMAND_setIndexBuffer, + COMMAND_setIndirectBuffer, COMMAND_setModelTransform, COMMAND_setViewTransform, @@ -221,6 +231,8 @@ public: COMMAND_resetStages, + COMMAND_runLambda, + // TODO: As long as we have gl calls explicitely issued from interface // code, we need to be able to record and batch these calls. THe long // term strategy is to get rid of any GL calls in favor of the HIFI GPU API @@ -302,6 +314,7 @@ public: typedef Cache::Vector PipelineCaches; typedef Cache::Vector FramebufferCaches; typedef Cache::Vector QueryCaches; + typedef Cache>::Vector LambdaCache; // Cache Data in a byte array if too big to fit in Param // FOr example Mat4s are going there @@ -327,6 +340,7 @@ public: PipelineCaches _pipelines; FramebufferCaches _framebuffers; QueryCaches _queries; + LambdaCache _lambdas; NamedBatchDataMap _namedData; @@ -336,6 +350,20 @@ public: protected: }; -}; +template +void popVectorParam(Batch::Params& params, uint32& paramOffset, V& v) { + for (size_t i = 0; i < v.length(); ++i) { + v[i] = params[paramOffset++]._float; + } +} + +template +void pushVectorParam(Batch::Params& params, const V& v) { + for (size_t i = 0; i < v.length(); ++i) { + params.push_back(v[i]); + } +} + +} #endif diff --git a/libraries/gpu/src/gpu/GLBackend.cpp b/libraries/gpu/src/gpu/GLBackend.cpp index 62508f273c..79b37ddc0e 100644 --- a/libraries/gpu/src/gpu/GLBackend.cpp +++ b/libraries/gpu/src/gpu/GLBackend.cpp @@ -23,10 +23,13 @@ GLBackend::CommandCall GLBackend::_commandCalls[Batch::NUM_COMMANDS] = (&::gpu::GLBackend::do_drawIndexed), (&::gpu::GLBackend::do_drawInstanced), (&::gpu::GLBackend::do_drawIndexedInstanced), - + (&::gpu::GLBackend::do_multiDrawIndirect), + (&::gpu::GLBackend::do_multiDrawIndexedIndirect), + (&::gpu::GLBackend::do_setInputFormat), (&::gpu::GLBackend::do_setInputBuffer), (&::gpu::GLBackend::do_setIndexBuffer), + (&::gpu::GLBackend::do_setIndirectBuffer), (&::gpu::GLBackend::do_setModelTransform), (&::gpu::GLBackend::do_setViewTransform), @@ -50,6 +53,8 @@ GLBackend::CommandCall GLBackend::_commandCalls[Batch::NUM_COMMANDS] = (&::gpu::GLBackend::do_resetStages), + (&::gpu::GLBackend::do_runLambda), + (&::gpu::GLBackend::do_glActiveBindTexture), (&::gpu::GLBackend::do_glUniform1i), @@ -323,6 +328,9 @@ void GLBackend::do_drawInstanced(Batch& batch, uint32 paramOffset) { (void) CHECK_GL_ERROR(); } +// DO NOT MERGE THIS, it will break mac clients +#define GL_430 + void GLBackend::do_drawIndexedInstanced(Batch& batch, uint32 paramOffset) { updateInput(); updateTransform(); @@ -332,17 +340,63 @@ void GLBackend::do_drawIndexedInstanced(Batch& batch, uint32 paramOffset) { GLenum mode = _primitiveToGLmode[(Primitive)batch._params[paramOffset + 3]._uint]; uint32 numIndices = batch._params[paramOffset + 2]._uint; uint32 startIndex = batch._params[paramOffset + 1]._uint; + // FIXME glDrawElementsInstancedBaseVertexBaseInstance is only available in GL 4.3 + // and higher, so currently we ignore this field uint32 startInstance = batch._params[paramOffset + 0]._uint; GLenum glType = _elementTypeToGLType[_input._indexBufferType]; +#ifdef GL_430 + glDrawElementsInstancedBaseVertexBaseInstance(mode, numIndices, glType, reinterpret_cast(startIndex + _input._indexBufferOffset), numInstances, 0, startInstance); +#else glDrawElementsInstanced(mode, numIndices, glType, reinterpret_cast(startIndex + _input._indexBufferOffset), numInstances); +#endif (void)CHECK_GL_ERROR(); } + +void GLBackend::do_multiDrawIndirect(Batch& batch, uint32 paramOffset) { +#ifdef GL_430 + updateInput(); + updateTransform(); + updatePipeline(); + + uint commandCount = batch._params[paramOffset + 0]._uint; + GLenum mode = _primitiveToGLmode[(Primitive)batch._params[paramOffset + 1]._uint]; + + glMultiDrawArraysIndirect(mode, reinterpret_cast(_input._indirectBufferOffset), commandCount, _input._indirectBufferStride); +#else + // FIXME implement the slow path +#endif + (void)CHECK_GL_ERROR(); +} + +void GLBackend::do_multiDrawIndexedIndirect(Batch& batch, uint32 paramOffset) { +#ifdef GL_430 + updateInput(); + updateTransform(); + updatePipeline(); + + uint commandCount = batch._params[paramOffset + 0]._uint; + GLenum mode = _primitiveToGLmode[(Primitive)batch._params[paramOffset + 1]._uint]; + GLenum indexType = _elementTypeToGLType[_input._indexBufferType]; + + glMultiDrawElementsIndirect(mode, indexType, reinterpret_cast(_input._indirectBufferOffset), commandCount, _input._indirectBufferStride); +#else + // FIXME implement the slow path +#endif + (void)CHECK_GL_ERROR(); +} + + void GLBackend::do_resetStages(Batch& batch, uint32 paramOffset) { resetStages(); } +void GLBackend::do_runLambda(Batch& batch, uint32 paramOffset) { + std::function f = batch._lambdas.get(batch._params[paramOffset]._uint); + f(); +} + void GLBackend::resetStages() { resetInputStage(); resetPipelineStage(); diff --git a/libraries/gpu/src/gpu/GLBackend.h b/libraries/gpu/src/gpu/GLBackend.h index dabc69dedb..f12cda827a 100644 --- a/libraries/gpu/src/gpu/GLBackend.h +++ b/libraries/gpu/src/gpu/GLBackend.h @@ -252,11 +252,14 @@ protected: void do_drawIndexed(Batch& batch, uint32 paramOffset); void do_drawInstanced(Batch& batch, uint32 paramOffset); void do_drawIndexedInstanced(Batch& batch, uint32 paramOffset); - + void do_multiDrawIndirect(Batch& batch, uint32 paramOffset); + void do_multiDrawIndexedIndirect(Batch& batch, uint32 paramOffset); + // Input Stage void do_setInputFormat(Batch& batch, uint32 paramOffset); void do_setInputBuffer(Batch& batch, uint32 paramOffset); void do_setIndexBuffer(Batch& batch, uint32 paramOffset); + void do_setIndirectBuffer(Batch& batch, uint32 paramOffset); void initInput(); void killInput(); @@ -284,6 +287,10 @@ protected: Offset _indexBufferOffset; Type _indexBufferType; + BufferPointer _indirectBuffer; + Offset _indirectBufferOffset{ 0 }; + Offset _indirectBufferStride{ 0 }; + GLuint _defaultVAO; InputStageState() : @@ -448,6 +455,9 @@ protected: // Reset stages void do_resetStages(Batch& batch, uint32 paramOffset); + + void do_runLambda(Batch& batch, uint32 paramOffset); + void resetStages(); // TODO: As long as we have gl calls explicitely issued from interface @@ -471,7 +481,6 @@ protected: static CommandCall _commandCalls[Batch::NUM_COMMANDS]; }; - }; #endif diff --git a/libraries/gpu/src/gpu/GLBackendInput.cpp b/libraries/gpu/src/gpu/GLBackendInput.cpp index 7f021fd5c5..2b14e4d7f0 100755 --- a/libraries/gpu/src/gpu/GLBackendInput.cpp +++ b/libraries/gpu/src/gpu/GLBackendInput.cpp @@ -273,21 +273,36 @@ void GLBackend::resetInputStage() { } void GLBackend::do_setIndexBuffer(Batch& batch, uint32 paramOffset) { - _input._indexBufferType = (Type) batch._params[paramOffset + 2]._uint; - BufferPointer indexBuffer = batch._buffers.get(batch._params[paramOffset + 1]._uint); + _input._indexBufferType = (Type)batch._params[paramOffset + 2]._uint; _input._indexBufferOffset = batch._params[paramOffset + 0]._uint; - _input._indexBuffer = indexBuffer; - if (indexBuffer) { - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, getBufferID(*indexBuffer)); - } else { - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); + + BufferPointer indexBuffer = batch._buffers.get(batch._params[paramOffset + 1]._uint); + if (indexBuffer != _input._indexBuffer) { + _input._indexBuffer = indexBuffer; + if (indexBuffer) { + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, getBufferID(*indexBuffer)); + } else { + // FIXME do we really need this? Is there ever a draw call where we care that the element buffer is null? + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); + } } (void) CHECK_GL_ERROR(); } -template -void popParam(Batch::Params& params, uint32& paramOffset, V& v) { - for (size_t i = 0; i < v.length(); ++i) { - v[i] = params[paramOffset++]._float; +void GLBackend::do_setIndirectBuffer(Batch& batch, uint32 paramOffset) { + _input._indirectBufferOffset = batch._params[paramOffset + 1]._uint; + _input._indirectBufferStride = batch._params[paramOffset + 2]._uint; + + BufferPointer buffer = batch._buffers.get(batch._params[paramOffset]._uint); + if (buffer != _input._indirectBuffer) { + _input._indirectBuffer = buffer; + if (buffer) { + glBindBuffer(GL_DRAW_INDIRECT_BUFFER, getBufferID(*buffer)); + } else { + // FIXME do we really need this? Is there ever a draw call where we care that the element buffer is null? + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); + } } + + (void)CHECK_GL_ERROR(); } diff --git a/libraries/render-utils/src/GeometryCache.cpp b/libraries/render-utils/src/GeometryCache.cpp index 093434f079..5e04fe867f 100644 --- a/libraries/render-utils/src/GeometryCache.cpp +++ b/libraries/render-utils/src/GeometryCache.cpp @@ -87,37 +87,34 @@ void GeometryCache::ShapeData::setupIndices(gpu::BufferPointer& indexBuffer, con void GeometryCache::ShapeData::setupBatch(gpu::Batch& batch) const { batch.setInputBuffer(gpu::Stream::POSITION, _positionView); batch.setInputBuffer(gpu::Stream::NORMAL, _normalView); + batch.setIndexBuffer(gpu::UINT16, _indices, 0); } void GeometryCache::ShapeData::draw(gpu::Batch& batch) const { if (_indexCount) { setupBatch(batch); - batch.setIndexBuffer(gpu::UINT16, _indices, _indexOffset); - batch.drawIndexed(gpu::TRIANGLES, _indexCount); + batch.drawIndexed(gpu::TRIANGLES, _indexCount, _indexOffset); } } void GeometryCache::ShapeData::drawWire(gpu::Batch& batch) const { if (_wireIndexCount) { setupBatch(batch); - batch.setIndexBuffer(gpu::UINT16, _indices, _wireIndexOffset); - batch.drawIndexed(gpu::LINES, _wireIndexCount); + batch.drawIndexed(gpu::LINES, _wireIndexCount, _wireIndexOffset); } } void GeometryCache::ShapeData::drawInstances(gpu::Batch& batch, size_t count) const { if (_indexCount) { setupBatch(batch); - batch.setIndexBuffer(gpu::UINT16, _indices, _indexOffset); - batch.drawIndexedInstanced(count, gpu::TRIANGLES, _indexCount); + batch.drawIndexedInstanced(count, gpu::TRIANGLES, _indexCount, _indexOffset); } } void GeometryCache::ShapeData::drawWireInstances(gpu::Batch& batch, size_t count) const { if (_wireIndexCount) { setupBatch(batch); - batch.setIndexBuffer(gpu::UINT16, _indices, _wireIndexOffset); - batch.drawIndexedInstanced(count, gpu::LINES, _wireIndexCount); + batch.drawIndexedInstanced(count, gpu::LINES, _wireIndexCount, _wireIndexOffset); } } @@ -323,7 +320,7 @@ void GeometryCache::buildShapes() { 20, 21, 21, 22, 22, 23, 23, 20, // back 0, 23, 1, 22, 2, 21, 3, 20 // sides }; - for (int i = 0; i < wireIndices.size(); ++i) { + for (size_t i = 0; i < wireIndices.size(); ++i) { indices[i] += startingIndex; } @@ -374,7 +371,7 @@ void GeometryCache::buildShapes() { 0, 3, 1, 3, 2, 3, }; - for (int i = 0; i < wireIndices.size(); ++i) { + for (size_t i = 0; i < wireIndices.size(); ++i) { wireIndices[i] += startingIndex; } diff --git a/libraries/render-utils/src/GeometryCache.h b/libraries/render-utils/src/GeometryCache.h index 2e0d0a5493..aa1593db78 100644 --- a/libraries/render-utils/src/GeometryCache.h +++ b/libraries/render-utils/src/GeometryCache.h @@ -232,14 +232,6 @@ public: /// Set a batch to the simple pipeline, returning the previous pipeline void useSimpleDrawPipeline(gpu::Batch& batch, bool noBlend = false); -private: - GeometryCache(); - virtual ~GeometryCache(); - void buildShapes(); - - typedef QPair IntPair; - typedef QPair VerticesIndices; - struct ShapeData { size_t _indexOffset{ 0 }; size_t _indexCount{ 0 }; @@ -263,7 +255,13 @@ private: VShape _shapes; +private: + GeometryCache(); + virtual ~GeometryCache(); + void buildShapes(); + typedef QPair IntPair; + typedef QPair VerticesIndices; gpu::PipelinePointer _standardDrawPipeline; gpu::PipelinePointer _standardDrawPipelineNoBlend; diff --git a/tests/gpu-test/src/main.cpp b/tests/gpu-test/src/main.cpp index ad9ed9bb4a..0acbbcd725 100644 --- a/tests/gpu-test/src/main.cpp +++ b/tests/gpu-test/src/main.cpp @@ -35,6 +35,7 @@ // Must come after GL headers #include +#include #include #include @@ -101,7 +102,24 @@ float getSeconds(quint64 start = 0) { return seconds; } +struct DrawElementsIndirectCommand { + uint _count{ 0 }; + uint _instanceCount{ 0 }; + uint _firstIndex{ 0 }; + uint _baseVertex{ 0 }; + uint _baseInstance{ 0 }; +}; +static const size_t TYPE_COUNT = 4; +static GeometryCache::Shape SHAPE[TYPE_COUNT] = { + GeometryCache::Icosahedron, + GeometryCache::Cube, + GeometryCache::Sphere, + GeometryCache::Tetrahedron, + //GeometryCache::Line, +}; + +gpu::Stream::FormatPointer& getInstancedSolidStreamFormat(); // Creates an OpenGL window that renders a simple unlit scene using the gpu library and GeometryCache // Should eventually get refactored into something that supports multiple gpu backends. @@ -134,7 +152,7 @@ public: // Qt Quick may need a depth and stencil buffer. Always make sure these are available. format.setDepthBufferSize(16); format.setStencilBufferSize(8); - format.setVersion(4, 1); + format.setVersion(4, 3); format.setProfile(QSurfaceFormat::OpenGLContextProfile::CoreProfile); format.setOption(QSurfaceFormat::DebugContext); format.setSwapInterval(0); @@ -147,6 +165,13 @@ public: show(); makeCurrent(); + QOpenGLDebugLogger *logger = new QOpenGLDebugLogger(this); + logger->initialize(); // initializes in the current context, i.e. ctx + connect(logger, &QOpenGLDebugLogger::messageLogged, [](const QOpenGLDebugMessage& message){ + qDebug() << message; + }); + logger->startLogging(QOpenGLDebugLogger::SynchronousLogging); + gpu::Context::init(); _context = std::make_shared(); @@ -177,7 +202,9 @@ public: void draw() { static auto startTime = usecTimestampNow(); - if (!isVisible()) { + // Attempting to draw before we're visible and have a valid size will + // produce GL errors. + if (!isVisible() || _size.width() <= 0 || _size.height() <= 0) { return; } makeCurrent(); @@ -192,7 +219,8 @@ public: glm::vec3 unitscale { 1.0f }; glm::vec3 up { 0.0f, 1.0f, 0.0f }; - glm::vec3 camera_position { 1.5f * sinf(t), 0.0f, 1.5f * cos(t) }; + float distance = 3.0f; + glm::vec3 camera_position{ distance * sinf(t), 0.0f, distance * cos(t) }; static const vec3 camera_focus(0); static const vec3 camera_up(0, 1, 0); @@ -202,57 +230,141 @@ public: batch.setModelTransform(Transform()); auto geometryCache = DependencyManager::get(); - + // Render grid on xz plane (not the optimal way to do things, but w/e) // Note: GeometryCache::renderGrid will *not* work, as it is apparenly unaffected by batch rotations and renders xy only - static const std::string GRID_INSTANCE = "Grid"; - static auto compactColor1 = toCompactColor(vec4{ 0.35f, 0.25f, 0.15f, 1.0f }); - static auto compactColor2 = toCompactColor(vec4{ 0.15f, 0.25f, 0.35f, 1.0f }); - auto transformBuffer = batch.getNamedBuffer(GRID_INSTANCE, 0); - auto colorBuffer = batch.getNamedBuffer(GRID_INSTANCE, 1); - for (int i = 0; i < 100; ++i) { - { - glm::mat4 transform = glm::translate(mat4(), vec3(0, -1, -50 + i)); - transform = glm::scale(transform, vec3(100, 1, 1)); - transformBuffer->append(transform); - colorBuffer->append(compactColor1); - } + { + static const std::string GRID_INSTANCE = "Grid"; + static auto compactColor1 = toCompactColor(vec4{ 0.35f, 0.25f, 0.15f, 1.0f }); + static auto compactColor2 = toCompactColor(vec4{ 0.15f, 0.25f, 0.35f, 1.0f }); + static gpu::BufferPointer transformBuffer; + static gpu::BufferPointer colorBuffer; + if (!transformBuffer) { + transformBuffer = std::make_shared(); + colorBuffer = std::make_shared(); + for (int i = 0; i < 100; ++i) { + { + glm::mat4 transform = glm::translate(mat4(), vec3(0, -1, -50 + i)); + transform = glm::scale(transform, vec3(100, 1, 1)); + transformBuffer->append(transform); + colorBuffer->append(compactColor1); + } - { - glm::mat4 transform = glm::mat4_cast(quat(vec3(0, PI / 2.0f, 0))); - transform = glm::translate(transform, vec3(0, -1, -50 + i)); - transform = glm::scale(transform, vec3(100, 1, 1)); - transformBuffer->append(transform); - colorBuffer->append(compactColor2); + { + glm::mat4 transform = glm::mat4_cast(quat(vec3(0, PI / 2.0f, 0))); + transform = glm::translate(transform, vec3(0, -1, -50 + i)); + transform = glm::scale(transform, vec3(100, 1, 1)); + transformBuffer->append(transform); + colorBuffer->append(compactColor2); + } + } } + + batch.setupNamedCalls(GRID_INSTANCE, 200, [=](gpu::Batch& batch, gpu::Batch::NamedBatchData& data) { + batch.setViewTransform(camera); + batch.setModelTransform(Transform()); + batch.setPipeline(_pipeline); + batch._glUniform1i(_instanceLocation, 1); + geometryCache->renderWireShapeInstances(batch, GeometryCache::Line, data._count, transformBuffer, colorBuffer); + batch._glUniform1i(_instanceLocation, 0); + }); } - batch.setupNamedCalls(GRID_INSTANCE, 200, [=](gpu::Batch& batch, gpu::Batch::NamedBatchData& data) { + { + static const size_t ITEM_COUNT = 1000; + static const float SHAPE_INTERVAL = (PI * 2.0f) / ITEM_COUNT; + static const float ITEM_INTERVAL = SHAPE_INTERVAL / TYPE_COUNT; + + static const gpu::Element POSITION_ELEMENT{ gpu::VEC3, gpu::FLOAT, gpu::XYZ }; + static const gpu::Element NORMAL_ELEMENT{ gpu::VEC3, gpu::FLOAT, gpu::XYZ }; + static const gpu::Element COLOR_ELEMENT{ gpu::VEC4, gpu::NUINT8, gpu::RGBA }; + static const gpu::Element TRANSFORM_ELEMENT{ gpu::MAT4, gpu::FLOAT, gpu::XYZW }; + + + static std::vector transforms; + static std::vector colors; + static gpu::BufferPointer indirectBuffer; + static gpu::BufferPointer transformBuffer; + static gpu::BufferPointer colorBuffer; + static gpu::BufferView colorView; + static gpu::BufferView instanceXfmView; + + if (!transformBuffer) { + transformBuffer = std::make_shared(); + colorBuffer = std::make_shared(); + indirectBuffer = std::make_shared(); + + static const float ITEM_RADIUS = 20; + static const vec3 ITEM_TRANSLATION{ 0, 0, -ITEM_RADIUS }; + for (size_t i = 0; i < TYPE_COUNT; ++i) { + GeometryCache::Shape shape = SHAPE[i]; + GeometryCache::ShapeData shapeData = geometryCache->_shapes[shape]; + { + DrawElementsIndirectCommand indirectCommand; + indirectCommand._count = shapeData._indexCount; + indirectCommand._instanceCount = ITEM_COUNT; + indirectCommand._baseInstance = i * ITEM_COUNT; + indirectCommand._firstIndex = shapeData._indexOffset / 2; + indirectCommand._baseVertex = 0; + indirectBuffer->append(indirectCommand); + } + + //indirectCommand._count + float startingInterval = ITEM_INTERVAL * i; + for (size_t j = 0; j < ITEM_COUNT; ++j) { + float theta = j * SHAPE_INTERVAL + startingInterval; + auto transform = glm::rotate(mat4(), theta, Vectors::UP); + transform = glm::rotate(transform, (randFloat() - 0.5f) * PI / 4.0f, Vectors::UNIT_X); + transform = glm::translate(transform, ITEM_TRANSLATION); + transform = glm::scale(transform, vec3(randFloat() / 2.0f + 0.5f)); + transformBuffer->append(transform); + transforms.push_back(transform); + auto color = vec4{ randomColorValue(64), randomColorValue(64), randomColorValue(64), 255 }; + color /= 255.0f; + colors.push_back(color); + colorBuffer->append(toCompactColor(color)); + } + } + colorView = gpu::BufferView(colorBuffer, COLOR_ELEMENT); + instanceXfmView = gpu::BufferView(transformBuffer, TRANSFORM_ELEMENT); + } + +#if 1 + GeometryCache::ShapeData shapeData = geometryCache->_shapes[GeometryCache::Icosahedron]; + { + batch.setViewTransform(camera); + batch.setModelTransform(Transform()); + batch.setPipeline(_pipeline); + batch._glUniform1i(_instanceLocation, 1); + batch.setInputFormat(getInstancedSolidStreamFormat()); + batch.setInputBuffer(gpu::Stream::COLOR, colorView); + batch.setInputBuffer(gpu::Stream::INSTANCE_XFM, instanceXfmView); + batch.setIndirectBuffer(indirectBuffer); + shapeData.setupBatch(batch); + batch.multiDrawIndexedIndirect(TYPE_COUNT, gpu::TRIANGLES); + batch._glUniform1i(_instanceLocation, 0); + } +#else batch.setViewTransform(camera); - batch.setModelTransform(Transform()); batch.setPipeline(_pipeline); - auto& xfm = data._buffers[0]; - auto& color = data._buffers[1]; - batch._glUniform1i(_instanceLocation, 1); - geometryCache->renderWireShapeInstances(batch, GeometryCache::Line, data._count, xfm, color); - batch._glUniform1i(_instanceLocation, 0); - }); - - + for (size_t i = 0; i < TYPE_COUNT; ++i) { + GeometryCache::Shape shape = SHAPE[i]; + for (size_t j = 0; j < ITEM_COUNT; ++j) { + int index = i * ITEM_COUNT + j; + batch.setModelTransform(transforms[index]); + const vec4& color = colors[index]; + batch._glColor4f(color.r, color.g, color.b, 1.0); + geometryCache->renderShape(batch, shape); + } + } +#endif + } // Render unlit cube + sphere - - static GeometryCache::Shape SHAPE[] = { - GeometryCache::Cube, - GeometryCache::Sphere, - GeometryCache::Tetrahedron, - GeometryCache::Icosahedron, - }; - static auto startUsecs = usecTimestampNow(); float seconds = getSeconds(startUsecs); seconds /= 4.0; - int shapeIndex = ((int)seconds) % 4; + int shapeIndex = ((int)seconds) % TYPE_COUNT; bool wire = seconds - floor(seconds) > 0.5f; batch.setModelTransform(Transform()); batch._glColor4f(0.8f, 0.25f, 0.25f, 1.0f); @@ -263,7 +375,7 @@ public: geometryCache->renderShape(batch, SHAPE[shapeIndex]); } - batch.setModelTransform(Transform().setScale(1.05f)); + batch.setModelTransform(Transform().setScale(2.05f)); batch._glColor4f(1, 1, 1, 1); geometryCache->renderWireCube(batch); From acfb5a32bc0945f02ee4dd77179048563583da3c Mon Sep 17 00:00:00 2001 From: samcake Date: Wed, 23 Sep 2015 12:28:46 -0700 Subject: [PATCH 06/12] Rename the nb parameters with num --- libraries/gpu/src/gpu/Batch.cpp | 28 ++++++++++++++-------------- libraries/gpu/src/gpu/Batch.h | 28 +++++++--------------------- 2 files changed, 21 insertions(+), 35 deletions(-) diff --git a/libraries/gpu/src/gpu/Batch.cpp b/libraries/gpu/src/gpu/Batch.cpp index 15b841dd04..3c787aee2e 100644 --- a/libraries/gpu/src/gpu/Batch.cpp +++ b/libraries/gpu/src/gpu/Batch.cpp @@ -59,53 +59,53 @@ void Batch::clear() { uint32 Batch::cacheData(uint32 size, const void* data) { uint32 offset = _data.size(); - uint32 nbBytes = size; - _data.resize(offset + nbBytes); + uint32 numBytes = size; + _data.resize(offset + numBytes); memcpy(_data.data() + offset, data, size); return offset; } -void Batch::draw(Primitive primitiveType, uint32 nbVertices, uint32 startVertex) { +void Batch::draw(Primitive primitiveType, uint32 numVertices, uint32 startVertex) { ADD_COMMAND(draw); _params.push_back(startVertex); - _params.push_back(nbVertices); + _params.push_back(numVertices); _params.push_back(primitiveType); } -void Batch::drawIndexed(Primitive primitiveType, uint32 nbIndices, uint32 startIndex) { +void Batch::drawIndexed(Primitive primitiveType, uint32 numIndices, uint32 startIndex) { ADD_COMMAND(drawIndexed); _params.push_back(startIndex); - _params.push_back(nbIndices); + _params.push_back(numIndices); _params.push_back(primitiveType); } -void Batch::drawInstanced(uint32 nbInstances, Primitive primitiveType, uint32 nbVertices, uint32 startVertex, uint32 startInstance) { +void Batch::drawInstanced(uint32 numInstances, Primitive primitiveType, uint32 numVertices, uint32 startVertex, uint32 startInstance) { ADD_COMMAND(drawInstanced); _params.push_back(startInstance); _params.push_back(startVertex); - _params.push_back(nbVertices); + _params.push_back(numVertices); _params.push_back(primitiveType); - _params.push_back(nbInstances); + _params.push_back(numInstances); } -void Batch::drawIndexedInstanced(uint32 nbInstances, Primitive primitiveType, uint32 nbIndices, uint32 startIndex, uint32 startInstance) { +void Batch::drawIndexedInstanced(uint32 numInstances, Primitive primitiveType, uint32 numIndices, uint32 startIndex, uint32 startInstance) { ADD_COMMAND(drawIndexedInstanced); _params.push_back(startInstance); _params.push_back(startIndex); - _params.push_back(nbIndices); + _params.push_back(numIndices); _params.push_back(primitiveType); - _params.push_back(nbInstances); + _params.push_back(numInstances); } -void Batch::multiDrawIndirect(uint32 nbCommands, Primitive primitiveType) { +void Batch::multiDrawIndirect(uint32 numCommands, Primitive primitiveType) { ADD_COMMAND(multiDrawIndirect); - _params.push_back(nbCommands); + _params.push_back(numCommands); _params.push_back(primitiveType); } diff --git a/libraries/gpu/src/gpu/Batch.h b/libraries/gpu/src/gpu/Batch.h index 6dd92739c5..9b74179967 100644 --- a/libraries/gpu/src/gpu/Batch.h +++ b/libraries/gpu/src/gpu/Batch.h @@ -93,11 +93,11 @@ public: // Drawcalls void draw(Primitive primitiveType, uint32 numVertices, uint32 startVertex = 0); - void drawIndexed(Primitive primitiveType, uint32 nbIndices, uint32 startIndex = 0); - void drawInstanced(uint32 nbInstances, Primitive primitiveType, uint32 nbVertices, uint32 startVertex = 0, uint32 startInstance = 0); - void drawIndexedInstanced(uint32 nbInstances, Primitive primitiveType, uint32 nbIndices, uint32 startIndex = 0, uint32 startInstance = 0); - void multiDrawIndirect(uint32 nbCommands, Primitive primitiveType); - void multiDrawIndexedIndirect(uint32 nbCommands, Primitive primitiveType); + void drawIndexed(Primitive primitiveType, uint32 numIndices, uint32 startIndex = 0); + void drawInstanced(uint32 numInstances, Primitive primitiveType, uint32 numVertices, uint32 startVertex = 0, uint32 startInstance = 0); + void drawIndexedInstanced(uint32 numInstances, Primitive primitiveType, uint32 numIndices, uint32 startIndex = 0, uint32 startInstance = 0); + void multiDrawIndirect(uint32 numCommands, Primitive primitiveType); + void multiDrawIndexedIndirect(uint32 numCommands, Primitive primitiveType); void setupNamedCalls(const std::string& instanceName, size_t count, NamedBatchData::Function function); @@ -174,8 +174,6 @@ public: // Reset the stage caches and states void resetStages(); - void runLambda(std::function f); - // TODO: As long as we have gl calls explicitely issued from interface // code, we need to be able to record and batch these calls. THe long // term strategy is to get rid of any GL calls in favor of the HIFI GPU API @@ -348,22 +346,10 @@ public: bool _enableSkybox{ false }; protected: + // Maybe useful but shoudln't be public. Please convince me otherwise + void runLambda(std::function f); }; -template -void popVectorParam(Batch::Params& params, uint32& paramOffset, V& v) { - for (size_t i = 0; i < v.length(); ++i) { - v[i] = params[paramOffset++]._float; - } -} - -template -void pushVectorParam(Batch::Params& params, const V& v) { - for (size_t i = 0; i < v.length(); ++i) { - params.push_back(v[i]); - } -} - } #endif From 83116fdd851cf349a74df45b9445bc44573d891d Mon Sep 17 00:00:00 2001 From: samcake Date: Wed, 23 Sep 2015 15:20:39 -0700 Subject: [PATCH 07/12] Fixed the code path with tseparate vertex format, still broken otherwise in the case of primitive instanced --- libraries/gpu/src/gpu/Batch.h | 21 ++++++++++++++++++++ libraries/gpu/src/gpu/Format.h | 25 +++++++++++++++++++----- libraries/gpu/src/gpu/GLBackendInput.cpp | 20 ++++++++++--------- libraries/gpu/src/gpu/Texture.cpp | 2 +- tests/gpu-test/src/main.cpp | 10 +--------- 5 files changed, 54 insertions(+), 24 deletions(-) diff --git a/libraries/gpu/src/gpu/Batch.h b/libraries/gpu/src/gpu/Batch.h index 9b74179967..fafc3cc8d0 100644 --- a/libraries/gpu/src/gpu/Batch.h +++ b/libraries/gpu/src/gpu/Batch.h @@ -120,7 +120,28 @@ public: void setIndexBuffer(Type type, const BufferPointer& buffer, Offset offset); void setIndexBuffer(const BufferView& buffer); // not a command, just a shortcut from a BufferView + // Indirect buffer is used by the multiDrawXXXIndirect calls + // The indirect buffer contains the command descriptions to execute multiple drawcalls in a single call void setIndirectBuffer(const BufferPointer& buffer, Offset offset = 0, Offset stride = 0); + + // multi command desctription for multiDrawIndexedIndirect + class DrawIndirectCommand { + public: + uint _count{ 0 }; + uint _instanceCount{ 0 }; + uint _firstIndex{ 0 }; + uint _baseInstance{ 0 }; + }; + + // multi command desctription for multiDrawIndexedIndirect + class DrawIndexedIndirectCommand { + public: + uint _count{ 0 }; + uint _instanceCount{ 0 }; + uint _firstIndex{ 0 }; + uint _baseVertex{ 0 }; + uint _baseInstance{ 0 }; + }; // Transform Stage // Vertex position is transformed by ModelTransform from object space to world space diff --git a/libraries/gpu/src/gpu/Format.h b/libraries/gpu/src/gpu/Format.h index 530db084a3..ff0fd9faea 100644 --- a/libraries/gpu/src/gpu/Format.h +++ b/libraries/gpu/src/gpu/Format.h @@ -130,8 +130,8 @@ static const int LOCATION_COUNT[NUM_DIMENSIONS] = { 4, }; -// Count (of scalars) in an Element for a given Dimension -static const int DIMENSION_COUNT[NUM_DIMENSIONS] = { +// Count (of scalars) in an Element for a given Dimension's location +static const int SCALAR_COUNT_PER_LOCATION[NUM_DIMENSIONS] = { 1, 2, 3, @@ -141,6 +141,17 @@ static const int DIMENSION_COUNT[NUM_DIMENSIONS] = { 4, }; +// Count (of scalars) in an Element for a given Dimension +static const int SCALAR_COUNT[NUM_DIMENSIONS] = { + 1, + 2, + 3, + 4, + 4, + 9, + 16, +}; + // Semantic of an Element // Provide information on how to use the element enum Semantic { @@ -194,14 +205,18 @@ public: Semantic getSemantic() const { return (Semantic)_semantic; } Dimension getDimension() const { return (Dimension)_dimension; } - uint8 getDimensionCount() const { return DIMENSION_COUNT[(Dimension)_dimension]; } - uint8 getLocationCount() const { return LOCATION_COUNT[(Dimension)_dimension]; } + Type getType() const { return (Type)_type; } bool isNormalized() const { return (getType() >= NORMALIZED_START); } bool isInteger() const { return TYPE_IS_INTEGER[getType()]; } - uint32 getSize() const { return DIMENSION_COUNT[_dimension] * TYPE_SIZE[_type]; } + uint8 getScalarCount() const { return SCALAR_COUNT[(Dimension)_dimension]; } + uint32 getSize() const { return SCALAR_COUNT[_dimension] * TYPE_SIZE[_type]; } + + uint8 getLocationCount() const { return LOCATION_COUNT[(Dimension)_dimension]; } + uint8 getLocationScalarCount() const { return SCALAR_COUNT_PER_LOCATION[(Dimension)_dimension]; } + uint32 getLocationSize() const { return SCALAR_COUNT_PER_LOCATION[_dimension] * TYPE_SIZE[_type]; } uint16 getRaw() const { return *((uint16*) (this)); } diff --git a/libraries/gpu/src/gpu/GLBackendInput.cpp b/libraries/gpu/src/gpu/GLBackendInput.cpp index f5d456326e..f2cb914ad5 100755 --- a/libraries/gpu/src/gpu/GLBackendInput.cpp +++ b/libraries/gpu/src/gpu/GLBackendInput.cpp @@ -88,11 +88,11 @@ void GLBackend::syncInputStateCache() { // Core 41 doesn't expose the features to really separate the vertex format from the vertex buffers binding // Core 43 does :) -#if (GPU_INPUT_PROFILE == GPU_CORE_41) +//#if (GPU_INPUT_PROFILE == GPU_CORE_41) #define NO_SUPPORT_VERTEX_ATTRIB_FORMAT -#else +/*#else #define SUPPORT_VERTEX_ATTRIB_FORMAT -#endif +#endif*/ void GLBackend::updateInput() { #if defined(SUPPORT_VERTEX_ATTRIB_FORMAT) @@ -106,17 +106,18 @@ void GLBackend::updateInput() { const Stream::Attribute& attrib = (it).second; GLuint slot = attrib._slot; - GLuint count = attrib._element.getDimensionCount(); + GLuint count = attrib._element.getLocationScalarCount(); uint8_t locationCount = attrib._element.getLocationCount(); GLenum type = _elementTypeToGLType[attrib._element.getType()]; GLuint offset = attrib._offset;; GLboolean isNormalized = attrib._element.isNormalized(); + GLenum perLocationSize = attrib._element.getLocationSize(); + for (int j = 0; j < locationCount; ++j) { newActivation.set(slot + j); - glVertexAttribFormat(slot + j, count, type, isNormalized, offset); + glVertexAttribFormat(slot + j, count, type, isNormalized, offset + j * perLocationSize); glVertexAttribDivisor(slot + j, attrib._frequency); - glVertexAttribBinding(slot + j, attrib._channel); } } @@ -225,11 +226,12 @@ void GLBackend::updateInput() { for (unsigned int i = 0; i < channel._slots.size(); i++) { const Stream::Attribute& attrib = attributes.at(channel._slots[i]); GLuint slot = attrib._slot; - GLuint count = attrib._element.getDimensionCount(); + GLuint count = attrib._element.getLocationScalarCount(); uint8_t locationCount = attrib._element.getLocationCount(); GLenum type = _elementTypeToGLType[attrib._element.getType()]; - GLenum perLocationStride = strides[bufferNum]; - GLuint stride = perLocationStride * locationCount; + // GLenum perLocationStride = strides[bufferNum]; + GLenum perLocationStride = attrib._element.getLocationSize(); + GLuint stride = strides[bufferNum]; GLuint pointer = attrib._offset + offsets[bufferNum]; GLboolean isNormalized = attrib._element.isNormalized(); diff --git a/libraries/gpu/src/gpu/Texture.cpp b/libraries/gpu/src/gpu/Texture.cpp index 57df7b8ec0..d358b6431d 100755 --- a/libraries/gpu/src/gpu/Texture.cpp +++ b/libraries/gpu/src/gpu/Texture.cpp @@ -629,7 +629,7 @@ bool sphericalHarmonicsFromTexture(const gpu::Texture& cubeTexture, std::vector< // for each face of cube texture for(int face=0; face < gpu::Texture::NUM_CUBE_FACES; face++) { - auto numComponents = cubeTexture.accessStoredMipFace(0,face)->_format.getDimensionCount(); + auto numComponents = cubeTexture.accessStoredMipFace(0,face)->_format.getScalarCount(); auto data = cubeTexture.accessStoredMipFace(0,face)->_sysmem.readData(); if (data == nullptr) { continue; diff --git a/tests/gpu-test/src/main.cpp b/tests/gpu-test/src/main.cpp index 0a4a983a94..3c6da82b68 100644 --- a/tests/gpu-test/src/main.cpp +++ b/tests/gpu-test/src/main.cpp @@ -102,14 +102,6 @@ float getSeconds(quint64 start = 0) { return seconds; } -struct DrawElementsIndirectCommand { - uint _count{ 0 }; - uint _instanceCount{ 0 }; - uint _firstIndex{ 0 }; - uint _baseVertex{ 0 }; - uint _baseInstance{ 0 }; -}; - static const size_t TYPE_COUNT = 4; static GeometryCache::Shape SHAPE[TYPE_COUNT] = { GeometryCache::Icosahedron, @@ -300,7 +292,7 @@ public: GeometryCache::Shape shape = SHAPE[i]; GeometryCache::ShapeData shapeData = geometryCache->_shapes[shape]; { - DrawElementsIndirectCommand indirectCommand; + gpu::Batch::DrawIndexedIndirectCommand indirectCommand; indirectCommand._count = shapeData._indexCount; indirectCommand._instanceCount = ITEM_COUNT; indirectCommand._baseInstance = i * ITEM_COUNT; From 5fd2992c284d152f687248c4e8487655e0183d1b Mon Sep 17 00:00:00 2001 From: samcake Date: Wed, 23 Sep 2015 15:34:49 -0700 Subject: [PATCH 08/12] sometimes, magic happens, and clean rebuilds... --- libraries/gpu/src/gpu/GLBackendInput.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libraries/gpu/src/gpu/GLBackendInput.cpp b/libraries/gpu/src/gpu/GLBackendInput.cpp index f2cb914ad5..4877b57128 100755 --- a/libraries/gpu/src/gpu/GLBackendInput.cpp +++ b/libraries/gpu/src/gpu/GLBackendInput.cpp @@ -88,11 +88,11 @@ void GLBackend::syncInputStateCache() { // Core 41 doesn't expose the features to really separate the vertex format from the vertex buffers binding // Core 43 does :) -//#if (GPU_INPUT_PROFILE == GPU_CORE_41) +#if (GPU_INPUT_PROFILE == GPU_CORE_41) #define NO_SUPPORT_VERTEX_ATTRIB_FORMAT -/*#else +#else #define SUPPORT_VERTEX_ATTRIB_FORMAT -#endif*/ +#endif void GLBackend::updateInput() { #if defined(SUPPORT_VERTEX_ATTRIB_FORMAT) From 5176d51714730e94486a7604d7357e57f345e284 Mon Sep 17 00:00:00 2001 From: samcake Date: Wed, 23 Sep 2015 16:05:53 -0700 Subject: [PATCH 09/12] Merge and fix warnings --- libraries/gpu/src/gpu/GLBackendInput.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/libraries/gpu/src/gpu/GLBackendInput.cpp b/libraries/gpu/src/gpu/GLBackendInput.cpp index 4877b57128..0176d9ba0c 100755 --- a/libraries/gpu/src/gpu/GLBackendInput.cpp +++ b/libraries/gpu/src/gpu/GLBackendInput.cpp @@ -114,11 +114,11 @@ void GLBackend::updateInput() { GLenum perLocationSize = attrib._element.getLocationSize(); - for (int j = 0; j < locationCount; ++j) { - newActivation.set(slot + j); - glVertexAttribFormat(slot + j, count, type, isNormalized, offset + j * perLocationSize); - glVertexAttribDivisor(slot + j, attrib._frequency); - glVertexAttribBinding(slot + j, attrib._channel); + for (size_t locNum = 0; locNum < locationCount; ++locNum) { + newActivation.set(slot + locNum); + glVertexAttribFormat(slot + locNum, count, type, isNormalized, offset + locNum * perLocationSize); + glVertexAttribDivisor(slot + locNum, attrib._frequency); + glVertexAttribBinding(slot + locNum, attrib._channel); } } (void) CHECK_GL_ERROR(); @@ -235,10 +235,10 @@ void GLBackend::updateInput() { GLuint pointer = attrib._offset + offsets[bufferNum]; GLboolean isNormalized = attrib._element.isNormalized(); - for (int j = 0; j < locationCount; ++j) { - glVertexAttribPointer(slot + j, count, type, isNormalized, stride, - reinterpret_cast(pointer + perLocationStride * j)); - glVertexAttribDivisor(slot + j, attrib._frequency); + for (size_t locNum = 0; locNum < locationCount; ++locNum) { + glVertexAttribPointer(slot + locNum, count, type, isNormalized, stride, + reinterpret_cast(pointer + perLocationStride * locNum)); + glVertexAttribDivisor(slot + locNum, attrib._frequency); } // TODO: Support properly the IAttrib version From 9c44c3e4a41c2c459121d9e3d333e58234a205a2 Mon Sep 17 00:00:00 2001 From: samcake Date: Wed, 23 Sep 2015 16:19:34 -0700 Subject: [PATCH 10/12] Removing warnings --- libraries/gpu/src/gpu/GLBackendInput.cpp | 2 +- tests/gpu-test/src/main.cpp | 8 +++----- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/libraries/gpu/src/gpu/GLBackendInput.cpp b/libraries/gpu/src/gpu/GLBackendInput.cpp index 0176d9ba0c..6a4a092c64 100755 --- a/libraries/gpu/src/gpu/GLBackendInput.cpp +++ b/libraries/gpu/src/gpu/GLBackendInput.cpp @@ -125,7 +125,7 @@ void GLBackend::updateInput() { } // Manage Activation what was and what is expected now - for (int i = 0; i < newActivation.size(); i++) { + for (size_t i = 0; i < newActivation.size(); i++) { bool newState = newActivation[i]; if (newState != _input._attributeActivation[i]) { if (newState) { diff --git a/tests/gpu-test/src/main.cpp b/tests/gpu-test/src/main.cpp index 3c6da82b68..97fa728c47 100644 --- a/tests/gpu-test/src/main.cpp +++ b/tests/gpu-test/src/main.cpp @@ -192,8 +192,6 @@ public: } void draw() { - static auto startTime = usecTimestampNow(); - // Attempting to draw before we're visible and have a valid size will // produce GL errors. if (!isVisible() || _size.width() <= 0 || _size.height() <= 0) { @@ -207,7 +205,7 @@ public: batch.setViewportTransform({ 0, 0, _size.width() * devicePixelRatio(), _size.height() * devicePixelRatio() }); batch.setProjectionTransform(_projectionMatrix); - double t = _time.elapsed() * 1e-3; + float t = _time.elapsed() * 1e-3f; glm::vec3 unitscale { 1.0f }; glm::vec3 up { 0.0f, 1.0f, 0.0f }; @@ -356,9 +354,9 @@ public: static auto startUsecs = usecTimestampNow(); float seconds = getSeconds(startUsecs); - seconds /= 4.0; + seconds /= 4.0f; int shapeIndex = ((int)seconds) % TYPE_COUNT; - bool wire = seconds - floor(seconds) > 0.5f; + bool wire = (seconds - floor(seconds) > 0.5f); batch.setModelTransform(Transform()); batch._glColor4f(0.8f, 0.25f, 0.25f, 1.0f); From b8e630a7a781c87bedd7e72830d7141b449d732e Mon Sep 17 00:00:00 2001 From: samcake Date: Wed, 23 Sep 2015 17:46:10 -0700 Subject: [PATCH 11/12] Less Warnigns --- tests/gpu-test/src/main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/gpu-test/src/main.cpp b/tests/gpu-test/src/main.cpp index 97fa728c47..e4853bf596 100644 --- a/tests/gpu-test/src/main.cpp +++ b/tests/gpu-test/src/main.cpp @@ -210,7 +210,7 @@ public: glm::vec3 up { 0.0f, 1.0f, 0.0f }; float distance = 3.0f; - glm::vec3 camera_position{ distance * sinf(t), 0.0f, distance * cos(t) }; + glm::vec3 camera_position{ distance * sinf(t), 0.0f, distance * cosf(t) }; static const vec3 camera_focus(0); static const vec3 camera_up(0, 1, 0); @@ -356,7 +356,7 @@ public: seconds /= 4.0f; int shapeIndex = ((int)seconds) % TYPE_COUNT; - bool wire = (seconds - floor(seconds) > 0.5f); + bool wire = (seconds - floorf(seconds) > 0.5f); batch.setModelTransform(Transform()); batch._glColor4f(0.8f, 0.25f, 0.25f, 1.0f); From 7d8f3661ad9d3af0e02d9b7a409d0515137d0071 Mon Sep 17 00:00:00 2001 From: samcake Date: Wed, 23 Sep 2015 17:49:03 -0700 Subject: [PATCH 12/12] coding standard --- tests/gpu-test/src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/gpu-test/src/main.cpp b/tests/gpu-test/src/main.cpp index e4853bf596..80c2dbf8e9 100644 --- a/tests/gpu-test/src/main.cpp +++ b/tests/gpu-test/src/main.cpp @@ -157,7 +157,7 @@ public: show(); makeCurrent(); - QOpenGLDebugLogger *logger = new QOpenGLDebugLogger(this); + QOpenGLDebugLogger* logger = new QOpenGLDebugLogger(this); logger->initialize(); // initializes in the current context, i.e. ctx connect(logger, &QOpenGLDebugLogger::messageLogged, [](const QOpenGLDebugMessage& message){ qDebug() << message;