Clone of mesa.
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

arbfptest1.c 5.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. /* Test GL_ARB_fragment_program */
  2. #include <assert.h>
  3. #include <string.h>
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include <math.h>
  7. #define GL_GLEXT_PROTOTYPES
  8. #include <GL/glut.h>
  9. static void Display( void )
  10. {
  11. glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
  12. glPushMatrix();
  13. glColor4f(0, 0.5, 0, 1);
  14. glColor4f(0, 1, 0, 1);
  15. glBegin(GL_POLYGON);
  16. glVertex2f(-1, -1);
  17. glVertex2f( 1, -1);
  18. glVertex2f( 0, 1);
  19. glEnd();
  20. glPopMatrix();
  21. glutSwapBuffers();
  22. }
  23. static void Reshape( int width, int height )
  24. {
  25. glViewport( 0, 0, width, height );
  26. glMatrixMode( GL_PROJECTION );
  27. glLoadIdentity();
  28. glFrustum( -1.0, 1.0, -1.0, 1.0, 5.0, 25.0 );
  29. glMatrixMode( GL_MODELVIEW );
  30. glLoadIdentity();
  31. glTranslatef( 0.0, 0.0, -15.0 );
  32. }
  33. static void Key( unsigned char key, int x, int y )
  34. {
  35. (void) x;
  36. (void) y;
  37. switch (key) {
  38. case 27:
  39. exit(0);
  40. break;
  41. }
  42. glutPostRedisplay();
  43. }
  44. static void load_program(const char *prog, GLuint prognum)
  45. {
  46. int a;
  47. GLint errorpos, errno;
  48. glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, prognum);
  49. glProgramStringARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB,
  50. strlen(prog), (const GLubyte *) prog);
  51. assert(glIsProgramARB(prognum));
  52. errno = glGetError();
  53. printf("glGetError = %d\n", errno);
  54. if (errno != GL_NO_ERROR)
  55. {
  56. glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &errorpos);
  57. printf("errorpos: %d\n", errorpos);
  58. printf("%s\n", glGetString(GL_PROGRAM_ERROR_STRING_ARB));
  59. for (a=-10; a<10; a++)
  60. {
  61. if ((errorpos+a < 0) || (errorpos+a >= strlen(prog))) continue;
  62. printf("%c", prog[errorpos+a]);
  63. }
  64. printf("\n");
  65. exit(1);
  66. }
  67. }
  68. static void Init( void )
  69. {
  70. static const char *prog0 =
  71. "!!ARBfp1.0\n"
  72. "TEMP R0, RC, HC, H0, H1, H2, H3, H30 ;\n"
  73. "MUL result.color, R0, fragment.position; \n"
  74. "ADD result.color, H3, fragment.texcoord; \n"
  75. "ADD_SAT result.color, H3, fragment.texcoord; \n"
  76. "MUL result.color.xy, R0.wzyx, fragment.position; \n"
  77. "MUL result.color, H0, fragment.position; \n"
  78. "MUL result.color, -H0, fragment.position; \n"
  79. "MOV RC, H1; \n"
  80. "MOV HC, H2; \n"
  81. "END \n"
  82. ;
  83. /* masked updates, defines, declarations */
  84. static const char *prog1 =
  85. "!!ARBfp1.0\n"
  86. "PARAM foo = {1., 2., 3., 4.}; \n"
  87. "PARAM foo2 = 5.; \n"
  88. "PARAM foo3 = {5., 6., 7., 8.}; \n"
  89. "PARAM bar = 3.; \n"
  90. "TEMP R0, R1, RC, EQ, NE, bar2; \n"
  91. "ALIAS bar3 = bar; \n"
  92. "MOV result.color.xy, R0; \n"
  93. "MOV result.color, R0; \n"
  94. "MOV result.color.xyzw, R0; \n"
  95. "MOV result.color.xy, R0; \n"
  96. "MOV RC.x, R1.x; \n"
  97. "KIL NE; \n"
  98. "KIL EQ.xyxy; \n"
  99. "END \n"
  100. ;
  101. /* texture instructions */
  102. static const char *prog2 =
  103. "!!ARBfp1.0\n"
  104. "TEMP R0, R1, R2, R3;\n"
  105. "TEX R0, fragment.texcoord, texture[1], 2D; \n"
  106. "TEX R1, fragment.texcoord[1], texture[1], CUBE; \n"
  107. "TEX R2, fragment.texcoord[2], texture[2], 3D; \n"
  108. "TXP R3, fragment.texcoord[3], texture[3], RECT; \n"
  109. "MUL result.color, R0, fragment.color; \n"
  110. "END \n"
  111. ;
  112. /* test negation, absolute value */
  113. static const char *prog3 =
  114. "!!ARBfp1.0\n"
  115. "TEMP R0, R1;\n"
  116. "MOV R0, R1; \n"
  117. "MOV R0, -R1; \n"
  118. "MOV result.color, R0; \n"
  119. "END \n"
  120. ;
  121. /* literal constant sources */
  122. static const char *prog4 =
  123. "!!ARBfp1.0\n"
  124. "TEMP R0, R1;\n"
  125. "PARAM Pi = 3.14159; \n"
  126. "MOV R0, {1., -2., +3., 4.}; \n"
  127. "MOV R0, 5.; \n"
  128. "MOV R0, -5.; \n"
  129. "MOV R0, 5.; \n"
  130. "MOV R0, Pi; \n"
  131. "MOV result.color, R0; \n"
  132. "END \n"
  133. ;
  134. /* change the fragment color in a simple way */
  135. static const char *prog10 =
  136. "!!ARBfp1.0\n"
  137. "PARAM blue = {0., 0., 1., 0.};\n"
  138. "PARAM color = {1., 0., 0., 1.};\n"
  139. "TEMP R0; \n"
  140. "MOV R0, fragment.color; \n"
  141. "#ADD result.color, R0, fragment.color; \n"
  142. "#ADD result.color, blue, fragment.color; \n"
  143. "#ADD result.color, {1., 0., 0., 0.}, fragment.color; \n"
  144. "ADD result.color, color, fragment.color; \n"
  145. "END \n"
  146. ;
  147. GLuint progs[20];
  148. glGenProgramsARB(20, progs);
  149. assert(progs[0]);
  150. assert(progs[1]);
  151. assert(progs[0] != progs[1]);
  152. printf("program 0:\n");
  153. load_program(prog0, progs[0]);
  154. printf("program 1:\n");
  155. load_program(prog1, progs[1]);
  156. printf("program 2:\n");
  157. load_program(prog2, progs[2]);
  158. printf("program 3:\n");
  159. load_program(prog3, progs[3]);
  160. printf("program 4:\n");
  161. load_program(prog4, progs[4]);
  162. printf("program 10:\n");
  163. load_program(prog10, progs[5]);
  164. glEnable(GL_FRAGMENT_PROGRAM_ARB);
  165. glEnable(GL_ALPHA_TEST);
  166. glAlphaFunc(GL_ALWAYS, 0.0);
  167. }
  168. int main( int argc, char *argv[] )
  169. {
  170. glutInit( &argc, argv );
  171. glutInitWindowPosition( 0, 0 );
  172. glutInitWindowSize( 250, 250 );
  173. glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH );
  174. glutCreateWindow(argv[0]);
  175. glutReshapeFunc( Reshape );
  176. glutKeyboardFunc( Key );
  177. glutDisplayFunc( Display );
  178. Init();
  179. glutMainLoop();
  180. return 0;
  181. }