Index: third_party/gles2_book/Chapter_11/Stencil_Test/Stencil_Test.c |
diff --git a/third_party/gles2_book/Chapter_11/Stencil_Test/Stencil_Test.c b/third_party/gles2_book/Chapter_11/Stencil_Test/Stencil_Test.c |
deleted file mode 100644 |
index 1c899d0fcc7665e24fd344dbb7b1e53aa49de8f4..0000000000000000000000000000000000000000 |
--- a/third_party/gles2_book/Chapter_11/Stencil_Test/Stencil_Test.c |
+++ /dev/null |
@@ -1,243 +0,0 @@ |
-// |
-// Book: OpenGL(R) ES 2.0 Programming Guide |
-// Authors: Aaftab Munshi, Dan Ginsburg, Dave Shreiner |
-// ISBN-10: 0321502795 |
-// ISBN-13: 9780321502797 |
-// Publisher: Addison-Wesley Professional |
-// URLs: http://safari.informit.com/9780321563835 |
-// http://www.opengles-book.com |
-// |
- |
-// Stencil_Test.c |
-// |
-// This example shows various stencil buffer |
-// operations. |
-// |
-#include <stdlib.h> |
-#include "Stencil_Test.h" |
- |
-/// |
-// Initialize the shader and program object |
-// |
-int stInit ( ESContext *esContext ) |
-{ |
- STUserData *userData = esContext->userData; |
- GLbyte vShaderStr[] = |
- "attribute vec4 a_position; \n" |
- "void main() \n" |
- "{ \n" |
- " gl_Position = a_position; \n" |
- "} \n"; |
- |
- GLbyte fShaderStr[] = |
- "precision mediump float; \n" |
- "uniform vec4 u_color; \n" |
- "void main() \n" |
- "{ \n" |
- " gl_FragColor = u_color; \n" |
- "} \n"; |
- |
- GLfloat vVertices[] = { |
- -0.75f, 0.25f, 0.50f, // Quad #0 |
- -0.25f, 0.25f, 0.50f, |
- -0.25f, 0.75f, 0.50f, |
- -0.75f, 0.75f, 0.50f, |
- 0.25f, 0.25f, 0.50f, // Quad #1 |
- 0.75f, 0.25f, 0.50f, |
- 0.75f, 0.75f, 0.50f, |
- 0.25f, 0.75f, 0.50f, |
- -0.75f, -0.75f, 0.50f, // Quad #2 |
- -0.25f, -0.75f, 0.50f, |
- -0.25f, -0.25f, 0.50f, |
- -0.75f, -0.25f, 0.50f, |
- 0.25f, -0.75f, 0.50f, // Quad #3 |
- 0.75f, -0.75f, 0.50f, |
- 0.75f, -0.25f, 0.50f, |
- 0.25f, -0.25f, 0.50f, |
- -1.00f, -1.00f, 0.00f, // Big Quad |
- 1.00f, -1.00f, 0.00f, |
- 1.00f, 1.00f, 0.00f, |
- -1.00f, 1.00f, 0.00f |
- }; |
- |
- GLubyte indices[] = { |
- 0, 1, 2, 0, 2, 3, // Quad #0 |
- 4, 5, 6, 4, 6, 7, // Quad #1 |
- 8, 9, 10, 8, 10, 11, // Quad #2 |
- 12, 13, 14, 12, 14, 15, // Quad #3 |
- 16, 17, 18, 16, 18, 19 // Big Quad |
- }; |
- |
- // Load the shaders and get a linked program object |
- userData->programObject = esLoadProgram ( vShaderStr, fShaderStr ); |
- |
- // Get the attribute locations |
- userData->positionLoc = glGetAttribLocation ( userData->programObject, "a_position" ); |
- |
- // Get the sampler location |
- userData->colorLoc = glGetUniformLocation ( userData->programObject, "u_color" ); |
- |
- // Load vertex data |
- glGenBuffers ( 2, userData->vboIds ); |
- glBindBuffer ( GL_ARRAY_BUFFER, userData->vboIds[0] ); |
- glBufferData ( GL_ARRAY_BUFFER, sizeof(vVertices), |
- vVertices, GL_STATIC_DRAW ); |
- glBindBuffer ( GL_ELEMENT_ARRAY_BUFFER, userData->vboIds[1] ); |
- glBufferData ( GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), |
- indices, GL_STATIC_DRAW ); |
- |
- // Set the clear color |
- glClearColor ( 0.0f, 0.0f, 0.0f, 0.0f ); |
- |
- // Set the stencil clear value |
- glClearStencil ( 0x1 ); |
- |
- // Set the depth clear value |
- glClearDepthf( 0.75f ); |
- |
- // Enable the depth and stencil tests |
- glEnable( GL_DEPTH_TEST ); |
- glEnable( GL_STENCIL_TEST ); |
- |
- return TRUE; |
-} |
- |
-/// |
-// Initialize the stencil buffer values, and then use those |
-// values to control rendering |
-// |
-void stDraw ( ESContext *esContext ) |
-{ |
- int i; |
- GLubyte *offset = NULL; |
- |
- STUserData *userData = esContext->userData; |
- |
-#define NumTests 4 |
- GLfloat colors[NumTests][4] = { |
- { 1.0f, 0.0f, 0.0f, 1.0f }, |
- { 0.0f, 1.0f, 0.0f, 1.0f }, |
- { 0.0f, 0.0f, 1.0f, 1.0f }, |
- { 1.0f, 1.0f, 0.0f, 1.0f } |
- }; |
- |
- GLuint stencilValues[NumTests] = { |
- 0x7, // Result of test 0 |
- 0x0, // Result of test 1 |
- 0x2, // Result of test 2 |
- 0xfe // Result of test 3 |
- }; |
- |
- // Set the viewport |
- glViewport ( 0, 0, esContext->width, esContext->height ); |
- |
- // Clear the color, depth, and stencil buffers. At this |
- // point, the stencil buffer will be 0x1 for all pixels |
- glClear ( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT ); |
- |
- // Use the program object |
- glUseProgram ( userData->programObject ); |
- |
- // Load the vertex position |
- glVertexAttribPointer ( userData->positionLoc, 3, GL_FLOAT, |
- GL_FALSE, 0, 0 ); |
- |
- glEnableVertexAttribArray ( userData->positionLoc ); |
- |
- // Test 0: |
- // |
- // Initialize upper-left region. In this case, the |
- // stencil-buffer values will be replaced because the |
- // stencil test for the rendered pixels will fail the |
- // stencil test, which is |
- // |
- // ref mask stencil mask |
- // ( 0x7 & 0x3 ) < ( 0x1 & 0x7 ) |
- // |
- // The value in the stencil buffer for these pixels will |
- // be 0x7. |
- // |
- glStencilFunc( GL_LESS, 0x7, 0x3 ); |
- glStencilOp( GL_REPLACE, GL_DECR, GL_DECR ); |
- glDrawElements( GL_TRIANGLES, 6, GL_UNSIGNED_BYTE, offset ); |
- |
- // Test 1: |
- // |
- // Initialize the upper-right region. Here, we'll decrement |
- // the stencil-buffer values where the stencil test passes |
- // but the depth test fails. The stencil test is |
- // |
- // ref mask stencil mask |
- // ( 0x3 & 0x3 ) > ( 0x1 & 0x3 ) |
- // |
- // but where the geometry fails the depth test. The |
- // stencil values for these pixels will be 0x0. |
- // |
- glStencilFunc( GL_GREATER, 0x3, 0x3 ); |
- glStencilOp( GL_KEEP, GL_DECR, GL_KEEP ); |
- offset += 6; |
- glDrawElements( GL_TRIANGLES, 6, GL_UNSIGNED_BYTE, offset ); |
- |
- // Test 2: |
- // |
- // Initialize the lower-left region. Here we'll increment |
- // (with saturation) the stencil value where both the |
- // stencil and depth tests pass. The stencil test for |
- // these pixels will be |
- // |
- // ref mask stencil mask |
- // ( 0x1 & 0x3 ) == ( 0x1 & 0x3 ) |
- // |
- // The stencil values for these pixels will be 0x2. |
- // |
- glStencilFunc( GL_EQUAL, 0x1, 0x3 ); |
- glStencilOp( GL_KEEP, GL_INCR, GL_INCR ); |
- offset += 6; |
- glDrawElements( GL_TRIANGLES, 6, GL_UNSIGNED_BYTE, offset ); |
- |
- // Test 3: |
- // |
- // Finally, initialize the lower-right region. We'll invert |
- // the stencil value where the stencil tests fails. The |
- // stencil test for these pixels will be |
- // |
- // ref mask stencil mask |
- // ( 0x2 & 0x1 ) == ( 0x1 & 0x1 ) |
- // |
- // The stencil value here will be set to ~((2^s-1) & 0x1), |
- // (with the 0x1 being from the stencil clear value), |
- // where 's' is the number of bits in the stencil buffer |
- // |
- glStencilFunc( GL_EQUAL, 0x2, 0x1 ); |
- glStencilOp( GL_INVERT, GL_KEEP, GL_KEEP ); |
- offset += 6; |
- glDrawElements( GL_TRIANGLES, 6, GL_UNSIGNED_BYTE, offset ); |
- |
- // Use the stencil buffer for controlling where rendering will |
- // occur. We diable writing to the stencil buffer so we |
- // can test against them without modifying the values we |
- // generated. |
- glStencilMask( 0x0 ); |
- offset += 6; |
- for ( i = 0; i < NumTests; ++i ) |
- { |
- glStencilFunc( GL_EQUAL, stencilValues[i], 0xff ); |
- glUniform4fv( userData->colorLoc, 1, colors[i] ); |
- glDrawElements( GL_TRIANGLES, 6, GL_UNSIGNED_BYTE, offset ); |
- } |
- glStencilMask( 0xff ); |
-} |
- |
-/// |
-// Cleanup |
-// |
-void stShutDown ( ESContext *esContext ) |
-{ |
- STUserData *userData = esContext->userData; |
- |
- // Delete program object |
- glDeleteProgram ( userData->programObject ); |
- |
- // Delete vertex buffer objects |
- glDeleteBuffers ( 2, userData->vboIds ); |
-} |