OSDN Git Service

Fixed flatshading for triangle strip and triangle fan
authorAlexis Hetu <sugoi@google.com>
Thu, 21 Dec 2017 18:52:00 +0000 (13:52 -0500)
committerAlexis Hétu <sugoi@google.com>
Thu, 21 Dec 2017 20:07:40 +0000 (20:07 +0000)
Since OpenGL uses the last vertex, not the leading
vertex, as the vertex used to select the triangle
color, then the last vertex, instead of the first
vertex, has to be consistently incremented for each
triangle in the strip or fan. In order to make this
work, when leadingVertexFirst is true, the first
vertex is consistently the lowest (consistently
incremented) vertex index and when leadingVertexFirst
is false, the last vertex is consistently the highest
vertex index.

Fixes the 2 failures in:
dEQP-GLES3.functional.rasterization.flatshading

Change-Id: Ib2247a219fe8c6725dc141e6860ba2ff521dde8c
Reviewed-on: https://swiftshader-review.googlesource.com/15468
Tested-by: Alexis Hétu <sugoi@google.com>
Reviewed-by: Nicolas Capens <nicolascapens@google.com>
src/Renderer/Renderer.cpp

index aa2038e..8fb1883 100644 (file)
@@ -1165,9 +1165,18 @@ namespace sw
 
                                for(unsigned int i = 0; i < triangleCount; i++)
                                {
-                                       batch[i][0] = index + 0;
-                                       batch[i][1] = index + (index & 1) + 1;
-                                       batch[i][2] = index + (~index & 1) + 1;
+                                       if(leadingVertexFirst)
+                                       {
+                                               batch[i][0] = index + 0;
+                                               batch[i][1] = index + (index & 1) + 1;
+                                               batch[i][2] = index + (~index & 1) + 1;
+                                       }
+                                       else
+                                       {
+                                               batch[i][0] = index + (index & 1);
+                                               batch[i][1] = index + (~index & 1);
+                                               batch[i][2] = index + 2;
+                                       }
 
                                        index += 1;
                                }
@@ -1179,9 +1188,18 @@ namespace sw
 
                                for(unsigned int i = 0; i < triangleCount; i++)
                                {
-                                       batch[i][0] = index + 1;
-                                       batch[i][1] = index + 2;
-                                       batch[i][2] = 0;
+                                       if(leadingVertexFirst)
+                                       {
+                                               batch[i][0] = index + 1;
+                                               batch[i][1] = index + 2;
+                                               batch[i][2] = 0;
+                                       }
+                                       else
+                                       {
+                                               batch[i][0] = 0;
+                                               batch[i][1] = index + 1;
+                                               batch[i][2] = index + 2;
+                                       }
 
                                        index += 1;
                                }