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.

program.h 5.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /*
  2. * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
  3. * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
  4. * Copyright © 2010 Intel Corporation
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining a
  7. * copy of this software and associated documentation files (the "Software"),
  8. * to deal in the Software without restriction, including without limitation
  9. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  10. * and/or sell copies of the Software, and to permit persons to whom the
  11. * Software is furnished to do so, subject to the following conditions:
  12. *
  13. * The above copyright notice and this permission notice shall be included
  14. * in all copies or substantial portions of the Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  17. * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  19. * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
  20. * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  21. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  22. */
  23. #include <GL/gl.h>
  24. /**
  25. * Based on gl_shader in Mesa's mtypes.h.
  26. */
  27. struct glsl_shader {
  28. GLenum Type;
  29. GLuint Name;
  30. GLint RefCount;
  31. GLboolean DeletePending;
  32. GLboolean CompileStatus;
  33. const GLchar *Source; /**< Source code string */
  34. size_t SourceLen;
  35. GLchar *InfoLog;
  36. struct exec_list ir;
  37. struct glsl_symbol_table *symbols;
  38. };
  39. typedef int gl_register_file;
  40. typedef int gl_state_index;
  41. #define STATE_LENGTH 5
  42. /**
  43. * Program parameter.
  44. * Used by shaders/programs for uniforms, constants, varying vars, etc.
  45. */
  46. struct gl_program_parameter
  47. {
  48. const char *Name; /**< Null-terminated string */
  49. gl_register_file Type; /**< PROGRAM_NAMED_PARAM, CONSTANT or STATE_VAR */
  50. GLenum DataType; /**< GL_FLOAT, GL_FLOAT_VEC2, etc */
  51. /**
  52. * Number of components (1..4), or more.
  53. * If the number of components is greater than 4,
  54. * this parameter is part of a larger uniform like a GLSL matrix or array.
  55. * The next program parameter's Size will be Size-4 of this parameter.
  56. */
  57. GLuint Size;
  58. GLboolean Used; /**< Helper flag for GLSL uniform tracking */
  59. GLboolean Initialized; /**< Has the ParameterValue[] been set? */
  60. GLbitfield Flags; /**< Bitmask of PROG_PARAM_*_BIT */
  61. /**
  62. * A sequence of STATE_* tokens and integers to identify GL state.
  63. */
  64. gl_state_index StateIndexes[STATE_LENGTH];
  65. };
  66. /**
  67. * List of gl_program_parameter instances.
  68. */
  69. struct gl_program_parameter_list
  70. {
  71. GLuint Size; /**< allocated size of Parameters, ParameterValues */
  72. GLuint NumParameters; /**< number of parameters in arrays */
  73. struct gl_program_parameter *Parameters; /**< Array [Size] */
  74. GLfloat (*ParameterValues)[4]; /**< Array [Size] of GLfloat[4] */
  75. GLbitfield StateFlags; /**< _NEW_* flags indicating which state changes
  76. might invalidate ParameterValues[] */
  77. };
  78. /**
  79. * Shader program uniform variable.
  80. * The glGetUniformLocation() and glUniform() commands will use this
  81. * information.
  82. * Note that a uniform such as "binormal" might be used in both the
  83. * vertex shader and the fragment shader. When glUniform() is called to
  84. * set the uniform's value, it must be updated in both the vertex and
  85. * fragment shaders. The uniform may be in different locations in the
  86. * two shaders so we keep track of that here.
  87. */
  88. struct gl_uniform
  89. {
  90. const char *Name; /**< Null-terminated string */
  91. GLint VertPos;
  92. GLint FragPos;
  93. GLboolean Initialized; /**< For debug. Has this uniform been set? */
  94. #if 0
  95. GLenum DataType; /**< GL_FLOAT, GL_FLOAT_VEC2, etc */
  96. GLuint Size; /**< Number of components (1..4) */
  97. #endif
  98. };
  99. /**
  100. * List of gl_uniforms
  101. */
  102. struct gl_uniform_list
  103. {
  104. GLuint Size; /**< allocated size of Uniforms array */
  105. GLuint NumUniforms; /**< number of uniforms in the array */
  106. struct gl_uniform *Uniforms; /**< Array [Size] */
  107. };
  108. /**
  109. * Based on gl_shader_program in Mesa's mtypes.h.
  110. */
  111. struct glsl_program {
  112. GLenum Type; /**< Always GL_SHADER_PROGRAM (internal token) */
  113. GLuint Name; /**< aka handle or ID */
  114. GLint RefCount; /**< Reference count */
  115. GLboolean DeletePending;
  116. GLuint NumShaders; /**< number of attached shaders */
  117. struct glsl_shader **Shaders; /**< List of attached the shaders */
  118. /**
  119. * Per-stage shaders resulting from the first stage of linking.
  120. */
  121. /*@{*/
  122. unsigned _NumLinkedShaders;
  123. struct glsl_shader **_LinkedShaders;
  124. /*@}*/
  125. /** User-defined attribute bindings (glBindAttribLocation) */
  126. struct gl_program_parameter_list *Attributes;
  127. /* post-link info: */
  128. struct gl_uniform_list *Uniforms;
  129. struct gl_program_parameter_list *Varying;
  130. GLboolean LinkStatus; /**< GL_LINK_STATUS */
  131. GLboolean Validated;
  132. GLboolean _Used; /**< Ever used for drawing? */
  133. GLchar *InfoLog;
  134. };
  135. extern void
  136. link_shaders(struct glsl_program *prog);