Clone of mesa.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

crossbar.c 7.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. /*
  2. * (C) Copyright IBM Corporation 2005
  3. * All Rights Reserved.
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining a
  6. * copy of this software and associated documentation files (the "Software"),
  7. * to deal in the Software without restriction, including without limitation
  8. * on the rights to use, copy, modify, merge, publish, distribute, sub
  9. * license, and/or sell copies of the Software, and to permit persons to whom
  10. * the Software is furnished to do so, subject to the following conditions:
  11. *
  12. * The above copyright notice and this permission notice (including the next
  13. * paragraph) shall be included in all copies or substantial portions of the
  14. * Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
  19. * VA LINUX SYSTEM, IBM AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
  20. * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  21. * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  22. * USE OR OTHER DEALINGS IN THE SOFTWARE.
  23. */
  24. /**
  25. * \file crossbar.c
  26. *
  27. * Simple test of GL_ARB_texture_env_crossbar functionality. Several squares
  28. * are drawn with different texture combine modes, but all should be rendered
  29. * with the same final color.
  30. *
  31. * \author Ian Romanick <idr@us.ibm.com>
  32. */
  33. #include <stdio.h>
  34. #include <stdlib.h>
  35. #include <string.h>
  36. #include <GL/glut.h>
  37. static const GLint tests[][8] = {
  38. { 1, GL_REPLACE, GL_PRIMARY_COLOR, GL_PRIMARY_COLOR,
  39. 2, GL_REPLACE, GL_TEXTURE, GL_PRIMARY_COLOR },
  40. { 3, GL_REPLACE, GL_PRIMARY_COLOR, GL_PRIMARY_COLOR,
  41. 2, GL_SUBTRACT, GL_TEXTURE0, GL_TEXTURE1 },
  42. { 2, GL_REPLACE, GL_PRIMARY_COLOR, GL_PRIMARY_COLOR,
  43. 2, GL_REPLACE, GL_TEXTURE0, GL_TEXTURE0 },
  44. { 2, GL_REPLACE, GL_PRIMARY_COLOR, GL_PRIMARY_COLOR,
  45. 1, GL_SUBTRACT, GL_TEXTURE0, GL_TEXTURE1 },
  46. { 3, GL_ADD, GL_TEXTURE1, GL_TEXTURE1,
  47. 2, GL_MODULATE, GL_TEXTURE1, GL_PREVIOUS },
  48. { 3, GL_ADD, GL_TEXTURE1, GL_TEXTURE1,
  49. 4, GL_MODULATE, GL_TEXTURE0, GL_PREVIOUS },
  50. };
  51. #define NUM_TESTS (sizeof(tests) / sizeof(tests[0]))
  52. static int Width = 100 * (NUM_TESTS + 1);
  53. static int Height = 200;
  54. static const GLfloat Near = 5.0, Far = 25.0;
  55. static void Display( void )
  56. {
  57. unsigned i;
  58. glClearColor(0.2, 0.2, 0.8, 0);
  59. glClear( GL_COLOR_BUFFER_BIT );
  60. glPushMatrix();
  61. /* This is the "reference" square.
  62. */
  63. glActiveTexture( GL_TEXTURE0 );
  64. glDisable( GL_TEXTURE_2D );
  65. glActiveTexture( GL_TEXTURE1 );
  66. glDisable( GL_TEXTURE_2D );
  67. glTranslatef(-(NUM_TESTS * 1.5), 0, 0);
  68. glBegin(GL_QUADS);
  69. glColor3f( 0.5, 0.5, 0.5 );
  70. glVertex2f(-1, -1);
  71. glVertex2f( 1, -1);
  72. glVertex2f( 1, 1);
  73. glVertex2f(-1, 1);
  74. glEnd();
  75. for ( i = 0 ; i < NUM_TESTS ; i++ ) {
  76. glActiveTexture( GL_TEXTURE0 );
  77. glEnable( GL_TEXTURE_2D );
  78. glBindTexture( GL_TEXTURE_2D, tests[i][0] );
  79. glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE );
  80. glTexEnvi( GL_TEXTURE_ENV, GL_COMBINE_RGB, tests[i][1] );
  81. glTexEnvi( GL_TEXTURE_ENV, GL_SOURCE0_RGB, tests[i][2] );
  82. glTexEnvi( GL_TEXTURE_ENV, GL_SOURCE1_RGB, tests[i][3] );
  83. glActiveTexture( GL_TEXTURE1 );
  84. glEnable( GL_TEXTURE_2D );
  85. glBindTexture( GL_TEXTURE_2D, tests[i][4] );
  86. glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE );
  87. glTexEnvi( GL_TEXTURE_ENV, GL_COMBINE_RGB, tests[i][5] );
  88. glTexEnvi( GL_TEXTURE_ENV, GL_SOURCE0_RGB, tests[i][6] );
  89. glTexEnvi( GL_TEXTURE_ENV, GL_SOURCE1_RGB, tests[i][7] );
  90. glCallList(1);
  91. }
  92. glPopMatrix();
  93. glutSwapBuffers();
  94. }
  95. static void Reshape( int width, int height )
  96. {
  97. GLfloat ar = (float) width / (float) height;
  98. Width = width;
  99. Height = height;
  100. glViewport( 0, 0, width, height );
  101. glMatrixMode( GL_PROJECTION );
  102. glLoadIdentity();
  103. glFrustum( -ar, ar, -1.0, 1.0, Near, Far );
  104. glMatrixMode( GL_MODELVIEW );
  105. glLoadIdentity();
  106. glTranslatef( 0.0, 0.0, -15.0 );
  107. }
  108. static void Key( unsigned char key, int x, int y )
  109. {
  110. (void) x;
  111. (void) y;
  112. switch (key) {
  113. case 27:
  114. exit(0);
  115. break;
  116. }
  117. glutPostRedisplay();
  118. }
  119. static void Init( void )
  120. {
  121. const char * const ver_string = (const char * const)
  122. glGetString( GL_VERSION );
  123. float ver = strtof( ver_string, NULL );
  124. GLint tex_units;
  125. GLint temp[ 256 ];
  126. printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER));
  127. printf("GL_VERSION = %s\n", ver_string);
  128. if ( (!glutExtensionSupported("GL_ARB_multitexture")
  129. && (ver < 1.3))
  130. || (!glutExtensionSupported("GL_ARB_texture_env_combine")
  131. && !glutExtensionSupported("GL_EXT_texture_env_combine")
  132. && (ver < 1.3))
  133. || (!glutExtensionSupported("GL_ARB_texture_env_crossbar")
  134. && !glutExtensionSupported("GL_NV_texture_env_combine4")
  135. && (ver < 1.4)) ) {
  136. printf("\nSorry, this program requires GL_ARB_multitexture and either\n"
  137. "GL_ARB_texture_env_combine or GL_EXT_texture_env_combine (or OpenGL 1.3).\n"
  138. "Either GL_ARB_texture_env_crossbar or GL_NV_texture_env_combine4 (or\n"
  139. "OpenGL 1.4) are also required.\n");
  140. exit(1);
  141. }
  142. glGetIntegerv( GL_MAX_TEXTURE_UNITS, & tex_units );
  143. if ( tex_units < 2 ) {
  144. printf("\nSorry, this program requires at least 2 texture units.\n");
  145. exit(1);
  146. }
  147. printf("\nAll %u squares should be the same color.\n", NUM_TESTS + 1);
  148. (void) memset( temp, 0x00, sizeof( temp ) );
  149. glBindTexture( GL_TEXTURE_2D, 1 );
  150. glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
  151. glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
  152. glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, 8, 8, 0,
  153. GL_RGBA, GL_UNSIGNED_BYTE, temp );
  154. (void) memset( temp, 0x7f, sizeof( temp ) );
  155. glBindTexture( GL_TEXTURE_2D, 2 );
  156. glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
  157. glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
  158. glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, 8, 8, 0,
  159. GL_RGBA, GL_UNSIGNED_BYTE, temp );
  160. (void) memset( temp, 0xff, sizeof( temp ) );
  161. glBindTexture( GL_TEXTURE_2D, 3 );
  162. glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
  163. glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
  164. glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, 8, 8, 0,
  165. GL_RGBA, GL_UNSIGNED_BYTE, temp );
  166. (void) memset( temp, 0x3f, sizeof( temp ) );
  167. glBindTexture( GL_TEXTURE_2D, 4 );
  168. glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
  169. glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
  170. glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, 8, 8, 0,
  171. GL_RGBA, GL_UNSIGNED_BYTE, temp );
  172. glNewList( 1, GL_COMPILE );
  173. glTranslatef(3.0, 0, 0);
  174. glBegin(GL_QUADS);
  175. glColor3f( 0.9, 0.0, 0.0 );
  176. glMultiTexCoord2f( GL_TEXTURE0, 0.5, 0.5 );
  177. glMultiTexCoord2f( GL_TEXTURE1, 0.5, 0.5 );
  178. glVertex2f(-1, -1);
  179. glVertex2f( 1, -1);
  180. glVertex2f( 1, 1);
  181. glVertex2f(-1, 1);
  182. glEnd();
  183. glEndList();
  184. }
  185. int main( int argc, char *argv[] )
  186. {
  187. glutInit( &argc, argv );
  188. glutInitWindowPosition( 0, 0 );
  189. glutInitWindowSize( Width, Height );
  190. glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE );
  191. glutCreateWindow( "GL_ARB_texture_env_crossbar test" );
  192. glutReshapeFunc( Reshape );
  193. glutKeyboardFunc( Key );
  194. glutDisplayFunc( Display );
  195. Init();
  196. glutMainLoop();
  197. return 0;
  198. }