daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1 | // |
Geoff Lang | 1b6edcb | 2014-02-03 14:27:56 -0500 | [diff] [blame] | 2 | // Copyright (c) 2002-2014 The ANGLE Project Authors. All rights reserved. |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 3 | // Use of this source code is governed by a BSD-style license that can be |
| 4 | // found in the LICENSE file. |
| 5 | // |
| 6 | |
| 7 | // Program.h: Defines the gl::Program class. Implements GL program objects |
| 8 | // and related functionality. [OpenGL ES 2.0.24] section 2.10.3 page 28. |
| 9 | |
Geoff Lang | 0a73dd8 | 2014-11-19 16:18:08 -0500 | [diff] [blame] | 10 | #ifndef LIBANGLE_PROGRAM_H_ |
| 11 | #define LIBANGLE_PROGRAM_H_ |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 12 | |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 13 | #include "libANGLE/angletypes.h" |
Geoff Lang | 2132941 | 2014-12-02 20:50:30 +0000 | [diff] [blame] | 14 | #include "libANGLE/Constants.h" |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 15 | #include "libANGLE/Error.h" |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 16 | #include "libANGLE/RefCountObject.h" |
| 17 | |
| 18 | #include "common/angleutils.h" |
shannon.woods@transgaming.com | 486d9e9 | 2013-02-28 23:15:41 +0000 | [diff] [blame] | 19 | |
Geoff Lang | 0b7eef7 | 2014-06-12 14:10:47 -0400 | [diff] [blame] | 20 | #include <GLES2/gl2.h> |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 21 | #include <GLSLANG/ShaderLang.h> |
Geoff Lang | 0b7eef7 | 2014-06-12 14:10:47 -0400 | [diff] [blame] | 22 | |
| 23 | #include <vector> |
| 24 | #include <string> |
| 25 | #include <set> |
| 26 | |
shannon.woods@transgaming.com | 486d9e9 | 2013-02-28 23:15:41 +0000 | [diff] [blame] | 27 | namespace rx |
| 28 | { |
| 29 | class Renderer; |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 30 | class Renderer; |
| 31 | struct TranslatedAttribute; |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 32 | class ProgramImpl; |
shannon.woods@transgaming.com | 486d9e9 | 2013-02-28 23:15:41 +0000 | [diff] [blame] | 33 | } |
daniel@transgaming.com | e684229 | 2010-04-20 18:52:50 +0000 | [diff] [blame] | 34 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 35 | namespace gl |
| 36 | { |
Brandon Jones | 43a53e2 | 2014-08-28 16:23:22 -0700 | [diff] [blame] | 37 | struct Caps; |
Jamie Madill | de8892b | 2014-11-11 13:00:22 -0500 | [diff] [blame] | 38 | struct Data; |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 39 | class ResourceManager; |
shannon.woods@transgaming.com | 486d9e9 | 2013-02-28 23:15:41 +0000 | [diff] [blame] | 40 | class Shader; |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 41 | class InfoLog; |
| 42 | class AttributeBindings; |
| 43 | class Buffer; |
| 44 | class Framebuffer; |
| 45 | struct UniformBlock; |
| 46 | struct LinkedUniform; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 47 | |
apatrick@chromium.org | 253b8d2 | 2012-06-22 19:27:21 +0000 | [diff] [blame] | 48 | extern const char * const g_fakepath; |
| 49 | |
apatrick@chromium.org | 9a30b09 | 2012-06-06 20:21:55 +0000 | [diff] [blame] | 50 | class AttributeBindings |
| 51 | { |
| 52 | public: |
| 53 | AttributeBindings(); |
| 54 | ~AttributeBindings(); |
| 55 | |
| 56 | void bindAttributeLocation(GLuint index, const char *name); |
| 57 | int getAttributeBinding(const std::string &name) const; |
| 58 | |
| 59 | private: |
| 60 | std::set<std::string> mAttributeBinding[MAX_VERTEX_ATTRIBS]; |
| 61 | }; |
| 62 | |
Jamie Madill | f0d10f8 | 2015-03-31 12:56:52 -0400 | [diff] [blame] | 63 | class InfoLog : angle::NonCopyable |
apatrick@chromium.org | 253b8d2 | 2012-06-22 19:27:21 +0000 | [diff] [blame] | 64 | { |
| 65 | public: |
| 66 | InfoLog(); |
| 67 | ~InfoLog(); |
| 68 | |
| 69 | int getLength() const; |
| 70 | void getLog(GLsizei bufSize, GLsizei *length, char *infoLog); |
| 71 | |
| 72 | void appendSanitized(const char *message); |
| 73 | void append(const char *info, ...); |
| 74 | void reset(); |
| 75 | private: |
apatrick@chromium.org | 253b8d2 | 2012-06-22 19:27:21 +0000 | [diff] [blame] | 76 | char *mInfoLog; |
| 77 | }; |
| 78 | |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 79 | // Struct used for correlating uniforms/elements of uniform arrays to handles |
| 80 | struct VariableLocation |
| 81 | { |
| 82 | VariableLocation(); |
| 83 | VariableLocation(const std::string &name, unsigned int element, unsigned int index); |
| 84 | |
| 85 | std::string name; |
| 86 | unsigned int element; |
| 87 | unsigned int index; |
| 88 | }; |
| 89 | |
| 90 | struct LinkedVarying |
| 91 | { |
| 92 | LinkedVarying(); |
| 93 | LinkedVarying(const std::string &name, GLenum type, GLsizei size, const std::string &semanticName, |
| 94 | unsigned int semanticIndex, unsigned int semanticIndexCount); |
| 95 | |
| 96 | // Original GL name |
| 97 | std::string name; |
| 98 | |
| 99 | GLenum type; |
| 100 | GLsizei size; |
| 101 | |
| 102 | // DirectX semantic information |
| 103 | std::string semanticName; |
| 104 | unsigned int semanticIndex; |
| 105 | unsigned int semanticIndexCount; |
| 106 | }; |
| 107 | |
Jamie Madill | f0d10f8 | 2015-03-31 12:56:52 -0400 | [diff] [blame] | 108 | class Program : angle::NonCopyable |
apatrick@chromium.org | e2a59bb | 2012-06-07 21:09:53 +0000 | [diff] [blame] | 109 | { |
| 110 | public: |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 111 | Program(rx::ProgramImpl *impl, ResourceManager *manager, GLuint handle); |
apatrick@chromium.org | e2a59bb | 2012-06-07 21:09:53 +0000 | [diff] [blame] | 112 | ~Program(); |
| 113 | |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 114 | GLuint id() const { return mHandle; } |
| 115 | |
| 116 | rx::ProgramImpl *getImplementation() { return mProgram; } |
| 117 | const rx::ProgramImpl *getImplementation() const { return mProgram; } |
| 118 | |
apatrick@chromium.org | e2a59bb | 2012-06-07 21:09:53 +0000 | [diff] [blame] | 119 | bool attachShader(Shader *shader); |
| 120 | bool detachShader(Shader *shader); |
| 121 | int getAttachedShadersCount() const; |
| 122 | |
| 123 | void bindAttributeLocation(GLuint index, const char *name); |
| 124 | |
Jamie Madill | de8892b | 2014-11-11 13:00:22 -0500 | [diff] [blame] | 125 | Error link(const Data &data); |
daniel@transgaming.com | 716056c | 2012-07-24 18:38:59 +0000 | [diff] [blame] | 126 | bool isLinked(); |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 127 | |
| 128 | Error loadBinary(GLenum binaryFormat, const void *binary, GLsizei length); |
| 129 | Error saveBinary(GLenum *binaryFormat, void *binary, GLsizei bufSize, GLsizei *length) const; |
| 130 | GLint getBinaryLength() const; |
apatrick@chromium.org | e2a59bb | 2012-06-07 21:09:53 +0000 | [diff] [blame] | 131 | |
| 132 | int getInfoLogLength() const; |
| 133 | void getInfoLog(GLsizei bufSize, GLsizei *length, char *infoLog); |
| 134 | void getAttachedShaders(GLsizei maxCount, GLsizei *count, GLuint *shaders); |
| 135 | |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 136 | GLuint getAttributeLocation(const std::string &name); |
| 137 | int getSemanticIndex(int attributeIndex); |
Jamie Madill | 56c6e3c | 2015-04-15 10:18:05 -0400 | [diff] [blame^] | 138 | const int *getSemanticIndexes() const; |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 139 | |
apatrick@chromium.org | e2a59bb | 2012-06-07 21:09:53 +0000 | [diff] [blame] | 140 | void getActiveAttribute(GLuint index, GLsizei bufsize, GLsizei *length, GLint *size, GLenum *type, GLchar *name); |
| 141 | GLint getActiveAttributeCount(); |
| 142 | GLint getActiveAttributeMaxLength(); |
| 143 | |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 144 | GLint getSamplerMapping(SamplerType type, unsigned int samplerIndex, const Caps &caps); |
| 145 | GLenum getSamplerTextureType(SamplerType type, unsigned int samplerIndex); |
| 146 | GLint getUsedSamplerRange(SamplerType type); |
| 147 | bool usesPointSize() const; |
| 148 | |
| 149 | GLint getFragDataLocation(const std::string &name) const; |
| 150 | |
apatrick@chromium.org | e2a59bb | 2012-06-07 21:09:53 +0000 | [diff] [blame] | 151 | void getActiveUniform(GLuint index, GLsizei bufsize, GLsizei *length, GLint *size, GLenum *type, GLchar *name); |
| 152 | GLint getActiveUniformCount(); |
| 153 | GLint getActiveUniformMaxLength(); |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 154 | GLint getActiveUniformi(GLuint index, GLenum pname) const; |
| 155 | bool isValidUniformLocation(GLint location) const; |
| 156 | LinkedUniform *getUniformByLocation(GLint location) const; |
| 157 | LinkedUniform *getUniformByName(const std::string &name) const; |
apatrick@chromium.org | e2a59bb | 2012-06-07 21:09:53 +0000 | [diff] [blame] | 158 | |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 159 | GLint getUniformLocation(const std::string &name); |
| 160 | GLuint getUniformIndex(const std::string &name); |
| 161 | void setUniform1fv(GLint location, GLsizei count, const GLfloat *v); |
| 162 | void setUniform2fv(GLint location, GLsizei count, const GLfloat *v); |
| 163 | void setUniform3fv(GLint location, GLsizei count, const GLfloat *v); |
| 164 | void setUniform4fv(GLint location, GLsizei count, const GLfloat *v); |
| 165 | void setUniform1iv(GLint location, GLsizei count, const GLint *v); |
| 166 | void setUniform2iv(GLint location, GLsizei count, const GLint *v); |
| 167 | void setUniform3iv(GLint location, GLsizei count, const GLint *v); |
| 168 | void setUniform4iv(GLint location, GLsizei count, const GLint *v); |
| 169 | void setUniform1uiv(GLint location, GLsizei count, const GLuint *v); |
| 170 | void setUniform2uiv(GLint location, GLsizei count, const GLuint *v); |
| 171 | void setUniform3uiv(GLint location, GLsizei count, const GLuint *v); |
| 172 | void setUniform4uiv(GLint location, GLsizei count, const GLuint *v); |
| 173 | void setUniformMatrix2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); |
| 174 | void setUniformMatrix3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); |
| 175 | void setUniformMatrix4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); |
| 176 | void setUniformMatrix2x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); |
| 177 | void setUniformMatrix3x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); |
| 178 | void setUniformMatrix2x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); |
| 179 | void setUniformMatrix4x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); |
| 180 | void setUniformMatrix3x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); |
| 181 | void setUniformMatrix4x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); |
| 182 | |
| 183 | void getUniformfv(GLint location, GLfloat *params); |
| 184 | void getUniformiv(GLint location, GLint *params); |
| 185 | void getUniformuiv(GLint location, GLuint *params); |
| 186 | |
| 187 | Error applyUniforms(); |
Gregoire Payen de La Garanderie | 68694e9 | 2015-03-24 14:03:37 +0000 | [diff] [blame] | 188 | Error applyUniformBuffers(const gl::Data &data); |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 189 | |
| 190 | void getActiveUniformBlockName(GLuint uniformBlockIndex, GLsizei bufSize, GLsizei *length, GLchar *uniformBlockName) const; |
| 191 | void getActiveUniformBlockiv(GLuint uniformBlockIndex, GLenum pname, GLint *params) const; |
| 192 | GLuint getActiveUniformBlockCount(); |
shannonwoods@chromium.org | e684b58 | 2013-05-30 00:07:42 +0000 | [diff] [blame] | 193 | GLint getActiveUniformBlockMaxLength(); |
| 194 | |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 195 | GLuint getUniformBlockIndex(const std::string &name); |
| 196 | |
shannonwoods@chromium.org | 70eb1ea | 2013-05-30 00:07:20 +0000 | [diff] [blame] | 197 | void bindUniformBlock(GLuint uniformBlockIndex, GLuint uniformBlockBinding); |
| 198 | GLuint getUniformBlockBinding(GLuint uniformBlockIndex) const; |
| 199 | |
Gregoire Payen de La Garanderie | 68694e9 | 2015-03-24 14:03:37 +0000 | [diff] [blame] | 200 | const UniformBlock *getUniformBlockByIndex(GLuint index) const; |
| 201 | |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 202 | void setTransformFeedbackVaryings(GLsizei count, const GLchar *const *varyings, GLenum bufferMode); |
| 203 | void getTransformFeedbackVarying(GLuint index, GLsizei bufSize, GLsizei *length, GLsizei *size, GLenum *type, GLchar *name) const; |
Geoff Lang | 1b6edcb | 2014-02-03 14:27:56 -0500 | [diff] [blame] | 204 | GLsizei getTransformFeedbackVaryingCount() const; |
| 205 | GLsizei getTransformFeedbackVaryingMaxLength() const; |
| 206 | GLenum getTransformFeedbackBufferMode() const; |
| 207 | |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 208 | static bool linkVaryings(InfoLog &infoLog, Shader *fragmentShader, Shader *vertexShader); |
| 209 | static bool linkValidateUniforms(InfoLog &infoLog, const std::string &uniformName, const sh::Uniform &vertexUniform, const sh::Uniform &fragmentUniform); |
| 210 | static bool linkValidateInterfaceBlockFields(InfoLog &infoLog, const std::string &uniformName, const sh::InterfaceBlockField &vertexUniform, const sh::InterfaceBlockField &fragmentUniform); |
| 211 | |
apatrick@chromium.org | e2a59bb | 2012-06-07 21:09:53 +0000 | [diff] [blame] | 212 | void addRef(); |
| 213 | void release(); |
| 214 | unsigned int getRefCount() const; |
| 215 | void flagForDeletion(); |
| 216 | bool isFlaggedForDeletion() const; |
| 217 | |
Brandon Jones | 43a53e2 | 2014-08-28 16:23:22 -0700 | [diff] [blame] | 218 | void validate(const Caps &caps); |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 219 | bool validateSamplers(InfoLog *infoLog, const Caps &caps); |
apatrick@chromium.org | e2a59bb | 2012-06-07 21:09:53 +0000 | [diff] [blame] | 220 | bool isValidated() const; |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 221 | void updateSamplerMapping(); |
apatrick@chromium.org | 90080e3 | 2012-07-09 22:15:33 +0000 | [diff] [blame] | 222 | |
apatrick@chromium.org | e2a59bb | 2012-06-07 21:09:53 +0000 | [diff] [blame] | 223 | private: |
apatrick@chromium.org | e2a59bb | 2012-06-07 21:09:53 +0000 | [diff] [blame] | 224 | void unlink(bool destroy = false); |
shannonwoods@chromium.org | 70eb1ea | 2013-05-30 00:07:20 +0000 | [diff] [blame] | 225 | void resetUniformBlockBindings(); |
apatrick@chromium.org | e2a59bb | 2012-06-07 21:09:53 +0000 | [diff] [blame] | 226 | |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 227 | bool linkAttributes(InfoLog &infoLog, const AttributeBindings &attributeBindings, const Shader *vertexShader); |
| 228 | bool linkUniformBlocks(InfoLog &infoLog, const Shader &vertexShader, const Shader &fragmentShader, const Caps &caps); |
| 229 | bool areMatchingInterfaceBlocks(gl::InfoLog &infoLog, const sh::InterfaceBlock &vertexInterfaceBlock, |
| 230 | const sh::InterfaceBlock &fragmentInterfaceBlock); |
| 231 | |
| 232 | static bool linkValidateVariablesBase(InfoLog &infoLog, |
| 233 | const std::string &variableName, |
| 234 | const sh::ShaderVariable &vertexVariable, |
| 235 | const sh::ShaderVariable &fragmentVariable, |
| 236 | bool validatePrecision); |
| 237 | |
| 238 | static bool linkValidateVaryings(InfoLog &infoLog, const std::string &varyingName, const sh::Varying &vertexVarying, const sh::Varying &fragmentVarying); |
| 239 | bool gatherTransformFeedbackLinkedVaryings(InfoLog &infoLog, const std::vector<LinkedVarying> &linkedVaryings, |
| 240 | const std::vector<std::string> &transformFeedbackVaryingNames, |
| 241 | GLenum transformFeedbackBufferMode, |
| 242 | std::vector<LinkedVarying> *outTransformFeedbackLinkedVaryings, |
| 243 | const Caps &caps) const; |
| 244 | bool assignUniformBlockRegister(InfoLog &infoLog, UniformBlock *uniformBlock, GLenum shader, unsigned int registerIndex, const Caps &caps); |
| 245 | void defineOutputVariables(Shader *fragmentShader); |
| 246 | |
| 247 | rx::ProgramImpl *mProgram; |
| 248 | |
| 249 | sh::Attribute mLinkedAttribute[MAX_VERTEX_ATTRIBS]; |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 250 | |
| 251 | std::map<int, VariableLocation> mOutputVariables; |
| 252 | |
| 253 | bool mValidated; |
| 254 | |
Brandon Jones | 7162096 | 2014-08-20 14:04:59 -0700 | [diff] [blame] | 255 | Shader *mFragmentShader; |
| 256 | Shader *mVertexShader; |
apatrick@chromium.org | e2a59bb | 2012-06-07 21:09:53 +0000 | [diff] [blame] | 257 | |
| 258 | AttributeBindings mAttributeBindings; |
| 259 | |
shannonwoods@chromium.org | 70eb1ea | 2013-05-30 00:07:20 +0000 | [diff] [blame] | 260 | GLuint mUniformBlockBindings[IMPLEMENTATION_MAX_COMBINED_SHADER_UNIFORM_BUFFERS]; |
| 261 | |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 262 | std::vector<std::string> mTransformFeedbackVaryings; |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 263 | GLenum mTransformFeedbackBufferMode; |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 264 | |
daniel@transgaming.com | 716056c | 2012-07-24 18:38:59 +0000 | [diff] [blame] | 265 | bool mLinked; |
apatrick@chromium.org | e2a59bb | 2012-06-07 21:09:53 +0000 | [diff] [blame] | 266 | bool mDeleteStatus; // Flag to indicate that the program can be deleted when no longer in use |
daniel@transgaming.com | 4fa0833 | 2010-05-11 02:29:27 +0000 | [diff] [blame] | 267 | |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 268 | unsigned int mRefCount; |
| 269 | |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 270 | ResourceManager *mResourceManager; |
| 271 | const GLuint mHandle; |
apatrick@chromium.org | 253b8d2 | 2012-06-22 19:27:21 +0000 | [diff] [blame] | 272 | |
| 273 | InfoLog mInfoLog; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 274 | }; |
| 275 | } |
| 276 | |
Geoff Lang | 0a73dd8 | 2014-11-19 16:18:08 -0500 | [diff] [blame] | 277 | #endif // LIBANGLE_PROGRAM_H_ |