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.

vptest2.c 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. /* Test vertex state program execution */
  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. glutSolidCube(2.0);
  14. glPopMatrix();
  15. glutSwapBuffers();
  16. }
  17. static void Reshape( int width, int height )
  18. {
  19. glViewport( 0, 0, width, height );
  20. glMatrixMode( GL_PROJECTION );
  21. glLoadIdentity();
  22. glFrustum( -1.0, 1.0, -1.0, 1.0, 5.0, 25.0 );
  23. glMatrixMode( GL_MODELVIEW );
  24. glLoadIdentity();
  25. glTranslatef( 0.0, 0.0, -15.0 );
  26. }
  27. static void Key( unsigned char key, int x, int y )
  28. {
  29. (void) x;
  30. (void) y;
  31. switch (key) {
  32. case 27:
  33. exit(0);
  34. break;
  35. }
  36. glutPostRedisplay();
  37. }
  38. static void Test1( void )
  39. {
  40. static const GLfloat p[4] = {9, 8, 7, 6};
  41. GLfloat q[4];
  42. /* test addition */
  43. static const char *prog =
  44. "!!VSP1.0\n"
  45. "MOV R0, c[0];\n"
  46. "MOV R1, c[1];\n"
  47. "ADD c[2], R0, R1;\n"
  48. "END\n";
  49. glLoadProgramNV(GL_VERTEX_STATE_PROGRAM_NV, 1,
  50. strlen(prog),
  51. (const GLubyte *) prog);
  52. assert(glIsProgramNV(1));
  53. glProgramParameter4fNV(GL_VERTEX_PROGRAM_NV, 0, 1, 2, 3, 4);
  54. glProgramParameter4fNV(GL_VERTEX_PROGRAM_NV, 1, 10, 20, 30, 40);
  55. glExecuteProgramNV(GL_VERTEX_STATE_PROGRAM_NV, 1, p);
  56. glGetProgramParameterfvNV(GL_VERTEX_PROGRAM_NV, 2, GL_PROGRAM_PARAMETER_NV, q);
  57. printf("Result c[2] = %g %g %g %g (should be 11 22 33 44)\n",
  58. q[0], q[1], q[2], q[3]);
  59. }
  60. static void Test2( void )
  61. {
  62. static const GLfloat p[4] = {9, 8, 7, 6};
  63. GLfloat q[4];
  64. /* test swizzling */
  65. static const char *prog =
  66. "!!VSP1.0\n"
  67. "MOV R0, c[0].wzyx;\n"
  68. "MOV R1, c[1].wzyx;\n"
  69. "ADD c[2], R0, R1;\n"
  70. "END\n";
  71. glLoadProgramNV(GL_VERTEX_STATE_PROGRAM_NV, 1,
  72. strlen(prog),
  73. (const GLubyte *) prog);
  74. assert(glIsProgramNV(1));
  75. glProgramParameter4fNV(GL_VERTEX_PROGRAM_NV, 0, 1, 2, 3, 4);
  76. glProgramParameter4fNV(GL_VERTEX_PROGRAM_NV, 1, 10, 20, 30, 40);
  77. glExecuteProgramNV(GL_VERTEX_STATE_PROGRAM_NV, 1, p);
  78. glGetProgramParameterfvNV(GL_VERTEX_PROGRAM_NV, 2, GL_PROGRAM_PARAMETER_NV, q);
  79. printf("Result c[2] = %g %g %g %g (should be 44 33 22 11)\n",
  80. q[0], q[1], q[2], q[3]);
  81. }
  82. static void Test3( void )
  83. {
  84. static const GLfloat p[4] = {0, 0, 0, 0};
  85. GLfloat q[4];
  86. /* normalize vector */
  87. static const char *prog =
  88. "!!VSP1.0\n"
  89. "# c[0] = (nx,ny,nz)\n"
  90. "# R0.xyz = normalize(R1)\n"
  91. "# R0.w = 1/sqrt(nx*nx + ny*ny + nz*nz)\n"
  92. "# c[2] = R0\n"
  93. "DP3 R0.w, c[0], c[0];\n"
  94. "RSQ R0.w, R0.w;\n"
  95. "MUL R0.xyz, c[0], R0.w;\n"
  96. "MOV c[2], R0;\n"
  97. "END\n";
  98. glLoadProgramNV(GL_VERTEX_STATE_PROGRAM_NV, 1,
  99. strlen(prog),
  100. (const GLubyte *) prog);
  101. assert(glIsProgramNV(1));
  102. glProgramParameter4fNV(GL_VERTEX_PROGRAM_NV, 0, 0, 10, 0, 0);
  103. glExecuteProgramNV(GL_VERTEX_STATE_PROGRAM_NV, 1, p);
  104. glGetProgramParameterfvNV(GL_VERTEX_PROGRAM_NV, 2, GL_PROGRAM_PARAMETER_NV, q);
  105. printf("Result c[2] = %g %g %g %g (should be 0, 1, 0, 0.1)\n",
  106. q[0], q[1], q[2], q[3]);
  107. }
  108. int main( int argc, char *argv[] )
  109. {
  110. glutInit( &argc, argv );
  111. glutInitWindowPosition( 0, 0 );
  112. glutInitWindowSize( 50, 50 );
  113. glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH );
  114. glutCreateWindow(argv[0]);
  115. glutReshapeFunc( Reshape );
  116. glutKeyboardFunc( Key );
  117. glutDisplayFunc( Display );
  118. Test1();
  119. Test2();
  120. Test3();
  121. glutMainLoop();
  122. return 0;
  123. }