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 | 0b7eef7 | 2014-06-12 14:10:47 -0400 | [diff] [blame] | 13 | #include <GLES2/gl2.h> |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 14 | #include <GLSLANG/ShaderLang.h> |
Geoff Lang | 0b7eef7 | 2014-06-12 14:10:47 -0400 | [diff] [blame] | 15 | |
Jamie Madill | 63805b4 | 2015-08-25 13:17:39 -0400 | [diff] [blame] | 16 | #include <set> |
Jamie Madill | 71c3b2c | 2015-05-07 11:49:20 -0400 | [diff] [blame] | 17 | #include <sstream> |
Geoff Lang | 0b7eef7 | 2014-06-12 14:10:47 -0400 | [diff] [blame] | 18 | #include <string> |
Jamie Madill | 63805b4 | 2015-08-25 13:17:39 -0400 | [diff] [blame] | 19 | #include <vector> |
Geoff Lang | 0b7eef7 | 2014-06-12 14:10:47 -0400 | [diff] [blame] | 20 | |
Jamie Madill | 3d3d2f2 | 2015-09-23 16:47:51 -0400 | [diff] [blame^] | 21 | #include "common/angleutils.h" |
| 22 | #include "common/mathutil.h" |
| 23 | #include "common/Optional.h" |
| 24 | |
| 25 | #include "libANGLE/angletypes.h" |
| 26 | #include "libANGLE/Constants.h" |
| 27 | #include "libANGLE/Error.h" |
| 28 | #include "libANGLE/RefCountObject.h" |
| 29 | |
shannon.woods@transgaming.com | 486d9e9 | 2013-02-28 23:15:41 +0000 | [diff] [blame] | 30 | namespace rx |
| 31 | { |
Jamie Madill | 5c6b7bf | 2015-08-17 12:53:35 -0400 | [diff] [blame] | 32 | class ImplFactory; |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 33 | class ProgramImpl; |
Jamie Madill | 5c6b7bf | 2015-08-17 12:53:35 -0400 | [diff] [blame] | 34 | struct TranslatedAttribute; |
shannon.woods@transgaming.com | 486d9e9 | 2013-02-28 23:15:41 +0000 | [diff] [blame] | 35 | } |
daniel@transgaming.com | e684229 | 2010-04-20 18:52:50 +0000 | [diff] [blame] | 36 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 37 | namespace gl |
| 38 | { |
Brandon Jones | 43a53e2 | 2014-08-28 16:23:22 -0700 | [diff] [blame] | 39 | struct Caps; |
Jamie Madill | de8892b | 2014-11-11 13:00:22 -0500 | [diff] [blame] | 40 | struct Data; |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 41 | class ResourceManager; |
shannon.woods@transgaming.com | 486d9e9 | 2013-02-28 23:15:41 +0000 | [diff] [blame] | 42 | class Shader; |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 43 | class InfoLog; |
| 44 | class AttributeBindings; |
| 45 | class Buffer; |
| 46 | class Framebuffer; |
| 47 | struct UniformBlock; |
| 48 | struct LinkedUniform; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 49 | |
apatrick@chromium.org | 253b8d2 | 2012-06-22 19:27:21 +0000 | [diff] [blame] | 50 | extern const char * const g_fakepath; |
| 51 | |
apatrick@chromium.org | 9a30b09 | 2012-06-06 20:21:55 +0000 | [diff] [blame] | 52 | class AttributeBindings |
| 53 | { |
| 54 | public: |
| 55 | AttributeBindings(); |
| 56 | ~AttributeBindings(); |
| 57 | |
| 58 | void bindAttributeLocation(GLuint index, const char *name); |
| 59 | int getAttributeBinding(const std::string &name) const; |
| 60 | |
| 61 | private: |
| 62 | std::set<std::string> mAttributeBinding[MAX_VERTEX_ATTRIBS]; |
| 63 | }; |
| 64 | |
Jamie Madill | f0d10f8 | 2015-03-31 12:56:52 -0400 | [diff] [blame] | 65 | class InfoLog : angle::NonCopyable |
apatrick@chromium.org | 253b8d2 | 2012-06-22 19:27:21 +0000 | [diff] [blame] | 66 | { |
| 67 | public: |
| 68 | InfoLog(); |
| 69 | ~InfoLog(); |
| 70 | |
Jamie Madill | 71c3b2c | 2015-05-07 11:49:20 -0400 | [diff] [blame] | 71 | size_t getLength() const; |
apatrick@chromium.org | 253b8d2 | 2012-06-22 19:27:21 +0000 | [diff] [blame] | 72 | void getLog(GLsizei bufSize, GLsizei *length, char *infoLog); |
| 73 | |
| 74 | void appendSanitized(const char *message); |
apatrick@chromium.org | 253b8d2 | 2012-06-22 19:27:21 +0000 | [diff] [blame] | 75 | void reset(); |
Jamie Madill | f611316 | 2015-05-07 11:49:21 -0400 | [diff] [blame] | 76 | |
| 77 | // This helper class ensures we append a newline after writing a line. |
| 78 | class StreamHelper : angle::NonCopyable |
| 79 | { |
| 80 | public: |
| 81 | StreamHelper(StreamHelper &&rhs) |
| 82 | : mStream(rhs.mStream) |
| 83 | { |
| 84 | rhs.mStream = nullptr; |
| 85 | } |
| 86 | |
| 87 | StreamHelper &operator=(StreamHelper &&rhs) |
| 88 | { |
| 89 | std::swap(mStream, rhs.mStream); |
| 90 | return *this; |
| 91 | } |
| 92 | |
| 93 | ~StreamHelper() |
| 94 | { |
| 95 | // Write newline when destroyed on the stack |
| 96 | if (mStream) |
| 97 | { |
| 98 | (*mStream) << std::endl; |
| 99 | } |
| 100 | } |
| 101 | |
| 102 | template <typename T> |
| 103 | StreamHelper &operator<<(const T &value) |
| 104 | { |
| 105 | (*mStream) << value; |
| 106 | return *this; |
| 107 | } |
| 108 | |
| 109 | private: |
| 110 | friend class InfoLog; |
| 111 | |
| 112 | StreamHelper(std::stringstream *stream) |
| 113 | : mStream(stream) |
| 114 | { |
| 115 | ASSERT(stream); |
| 116 | } |
| 117 | |
| 118 | std::stringstream *mStream; |
| 119 | }; |
| 120 | |
| 121 | template <typename T> |
| 122 | StreamHelper operator<<(const T &value) |
| 123 | { |
| 124 | StreamHelper helper(&mStream); |
| 125 | helper << value; |
| 126 | return helper; |
| 127 | } |
| 128 | |
| 129 | std::string str() const { return mStream.str(); } |
| 130 | |
apatrick@chromium.org | 253b8d2 | 2012-06-22 19:27:21 +0000 | [diff] [blame] | 131 | private: |
Jamie Madill | 71c3b2c | 2015-05-07 11:49:20 -0400 | [diff] [blame] | 132 | std::stringstream mStream; |
apatrick@chromium.org | 253b8d2 | 2012-06-22 19:27:21 +0000 | [diff] [blame] | 133 | }; |
| 134 | |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 135 | // Struct used for correlating uniforms/elements of uniform arrays to handles |
| 136 | struct VariableLocation |
| 137 | { |
| 138 | VariableLocation(); |
| 139 | VariableLocation(const std::string &name, unsigned int element, unsigned int index); |
| 140 | |
| 141 | std::string name; |
| 142 | unsigned int element; |
| 143 | unsigned int index; |
| 144 | }; |
| 145 | |
| 146 | struct LinkedVarying |
| 147 | { |
| 148 | LinkedVarying(); |
| 149 | LinkedVarying(const std::string &name, GLenum type, GLsizei size, const std::string &semanticName, |
| 150 | unsigned int semanticIndex, unsigned int semanticIndexCount); |
| 151 | |
| 152 | // Original GL name |
| 153 | std::string name; |
| 154 | |
| 155 | GLenum type; |
| 156 | GLsizei size; |
| 157 | |
| 158 | // DirectX semantic information |
| 159 | std::string semanticName; |
| 160 | unsigned int semanticIndex; |
| 161 | unsigned int semanticIndexCount; |
| 162 | }; |
| 163 | |
Jamie Madill | f0d10f8 | 2015-03-31 12:56:52 -0400 | [diff] [blame] | 164 | class Program : angle::NonCopyable |
apatrick@chromium.org | e2a59bb | 2012-06-07 21:09:53 +0000 | [diff] [blame] | 165 | { |
| 166 | public: |
Jamie Madill | 5c6b7bf | 2015-08-17 12:53:35 -0400 | [diff] [blame] | 167 | class Data final : angle::NonCopyable |
| 168 | { |
| 169 | public: |
| 170 | Data(); |
| 171 | ~Data(); |
| 172 | |
| 173 | const Shader *getAttachedVertexShader() const { return mAttachedVertexShader; } |
| 174 | const Shader *getAttachedFragmentShader() const { return mAttachedFragmentShader; } |
Jamie Madill | ccdf74b | 2015-08-18 10:46:12 -0400 | [diff] [blame] | 175 | const std::vector<std::string> &getTransformFeedbackVaryingNames() const |
Jamie Madill | ada9ecc | 2015-08-17 12:53:37 -0400 | [diff] [blame] | 176 | { |
Jamie Madill | ccdf74b | 2015-08-18 10:46:12 -0400 | [diff] [blame] | 177 | return mTransformFeedbackVaryingNames; |
Jamie Madill | ada9ecc | 2015-08-17 12:53:37 -0400 | [diff] [blame] | 178 | } |
| 179 | GLint getTransformFeedbackBufferMode() const { return mTransformFeedbackBufferMode; } |
Jamie Madill | d1fe164 | 2015-08-21 16:26:04 -0400 | [diff] [blame] | 180 | GLuint getUniformBlockBinding(GLuint uniformBlockIndex) const |
| 181 | { |
| 182 | ASSERT(uniformBlockIndex < IMPLEMENTATION_MAX_COMBINED_SHADER_UNIFORM_BUFFERS); |
| 183 | return mUniformBlockBindings[uniformBlockIndex]; |
| 184 | } |
Jamie Madill | c349ec0 | 2015-08-21 16:53:12 -0400 | [diff] [blame] | 185 | const std::vector<sh::Attribute> &getAttributes() const { return mAttributes; } |
Jamie Madill | 63805b4 | 2015-08-25 13:17:39 -0400 | [diff] [blame] | 186 | const AttributesMask &getActiveAttribLocationsMask() const |
| 187 | { |
| 188 | return mActiveAttribLocationsMask; |
| 189 | } |
Jamie Madill | 80a6fc0 | 2015-08-21 16:53:16 -0400 | [diff] [blame] | 190 | const std::map<int, VariableLocation> &getOutputVariables() const |
| 191 | { |
| 192 | return mOutputVariables; |
| 193 | } |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 194 | const std::vector<LinkedUniform> &getUniforms() const { return mUniforms; } |
| 195 | const std::vector<VariableLocation> &getUniformLocations() const |
| 196 | { |
| 197 | return mUniformLocations; |
| 198 | } |
| 199 | const std::vector<UniformBlock> &getUniformBlocks() const { return mUniformBlocks; } |
| 200 | |
| 201 | const LinkedUniform *getUniformByName(const std::string &name) const; |
| 202 | GLint getUniformLocation(const std::string &name) const; |
| 203 | GLuint getUniformIndex(const std::string &name) const; |
Jamie Madill | 5c6b7bf | 2015-08-17 12:53:35 -0400 | [diff] [blame] | 204 | |
| 205 | private: |
| 206 | friend class Program; |
| 207 | |
| 208 | Shader *mAttachedFragmentShader; |
| 209 | Shader *mAttachedVertexShader; |
| 210 | |
Jamie Madill | ccdf74b | 2015-08-18 10:46:12 -0400 | [diff] [blame] | 211 | std::vector<std::string> mTransformFeedbackVaryingNames; |
| 212 | std::vector<sh::Varying> mTransformFeedbackVaryingVars; |
Jamie Madill | 5c6b7bf | 2015-08-17 12:53:35 -0400 | [diff] [blame] | 213 | GLenum mTransformFeedbackBufferMode; |
| 214 | |
Jamie Madill | d1fe164 | 2015-08-21 16:26:04 -0400 | [diff] [blame] | 215 | GLuint mUniformBlockBindings[IMPLEMENTATION_MAX_COMBINED_SHADER_UNIFORM_BUFFERS]; |
| 216 | |
Jamie Madill | c349ec0 | 2015-08-21 16:53:12 -0400 | [diff] [blame] | 217 | std::vector<sh::Attribute> mAttributes; |
Jamie Madill | 63805b4 | 2015-08-25 13:17:39 -0400 | [diff] [blame] | 218 | std::bitset<MAX_VERTEX_ATTRIBS> mActiveAttribLocationsMask; |
Jamie Madill | c349ec0 | 2015-08-21 16:53:12 -0400 | [diff] [blame] | 219 | |
Jamie Madill | 3d3d2f2 | 2015-09-23 16:47:51 -0400 | [diff] [blame^] | 220 | // Uniforms are sorted in order: |
| 221 | // 1. Non-sampler uniforms |
| 222 | // 2. Sampler uniforms |
| 223 | // 3. Uniform block uniforms |
| 224 | // This makes sampler validation easier, since we don't need a separate list. |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 225 | std::vector<LinkedUniform> mUniforms; |
| 226 | std::vector<VariableLocation> mUniformLocations; |
| 227 | std::vector<UniformBlock> mUniformBlocks; |
| 228 | |
Jamie Madill | 80a6fc0 | 2015-08-21 16:53:16 -0400 | [diff] [blame] | 229 | // TODO(jmadill): use unordered/hash map when available |
| 230 | std::map<int, VariableLocation> mOutputVariables; |
Jamie Madill | 5c6b7bf | 2015-08-17 12:53:35 -0400 | [diff] [blame] | 231 | }; |
| 232 | |
| 233 | Program(rx::ImplFactory *factory, ResourceManager *manager, GLuint handle); |
apatrick@chromium.org | e2a59bb | 2012-06-07 21:09:53 +0000 | [diff] [blame] | 234 | ~Program(); |
| 235 | |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 236 | GLuint id() const { return mHandle; } |
| 237 | |
| 238 | rx::ProgramImpl *getImplementation() { return mProgram; } |
| 239 | const rx::ProgramImpl *getImplementation() const { return mProgram; } |
| 240 | |
apatrick@chromium.org | e2a59bb | 2012-06-07 21:09:53 +0000 | [diff] [blame] | 241 | bool attachShader(Shader *shader); |
| 242 | bool detachShader(Shader *shader); |
| 243 | int getAttachedShadersCount() const; |
| 244 | |
| 245 | void bindAttributeLocation(GLuint index, const char *name); |
| 246 | |
Jamie Madill | 5c6b7bf | 2015-08-17 12:53:35 -0400 | [diff] [blame] | 247 | Error link(const gl::Data &data); |
daniel@transgaming.com | 716056c | 2012-07-24 18:38:59 +0000 | [diff] [blame] | 248 | bool isLinked(); |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 249 | |
| 250 | Error loadBinary(GLenum binaryFormat, const void *binary, GLsizei length); |
| 251 | Error saveBinary(GLenum *binaryFormat, void *binary, GLsizei bufSize, GLsizei *length) const; |
| 252 | GLint getBinaryLength() const; |
apatrick@chromium.org | e2a59bb | 2012-06-07 21:09:53 +0000 | [diff] [blame] | 253 | |
| 254 | int getInfoLogLength() const; |
| 255 | void getInfoLog(GLsizei bufSize, GLsizei *length, char *infoLog); |
| 256 | void getAttachedShaders(GLsizei maxCount, GLsizei *count, GLuint *shaders); |
| 257 | |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 258 | GLuint getAttributeLocation(const std::string &name); |
Jamie Madill | 63805b4 | 2015-08-25 13:17:39 -0400 | [diff] [blame] | 259 | bool isAttribLocationActive(size_t attribLocation) const; |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 260 | |
apatrick@chromium.org | e2a59bb | 2012-06-07 21:09:53 +0000 | [diff] [blame] | 261 | void getActiveAttribute(GLuint index, GLsizei bufsize, GLsizei *length, GLint *size, GLenum *type, GLchar *name); |
| 262 | GLint getActiveAttributeCount(); |
| 263 | GLint getActiveAttributeMaxLength(); |
Jamie Madill | c349ec0 | 2015-08-21 16:53:12 -0400 | [diff] [blame] | 264 | const std::vector<sh::Attribute> &getAttributes() const { return mData.mAttributes; } |
apatrick@chromium.org | e2a59bb | 2012-06-07 21:09:53 +0000 | [diff] [blame] | 265 | |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 266 | GLint getFragDataLocation(const std::string &name) const; |
| 267 | |
apatrick@chromium.org | e2a59bb | 2012-06-07 21:09:53 +0000 | [diff] [blame] | 268 | void getActiveUniform(GLuint index, GLsizei bufsize, GLsizei *length, GLint *size, GLenum *type, GLchar *name); |
| 269 | GLint getActiveUniformCount(); |
| 270 | GLint getActiveUniformMaxLength(); |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 271 | GLint getActiveUniformi(GLuint index, GLenum pname) const; |
| 272 | bool isValidUniformLocation(GLint location) const; |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 273 | const LinkedUniform &getUniformByLocation(GLint location) const; |
apatrick@chromium.org | e2a59bb | 2012-06-07 21:09:53 +0000 | [diff] [blame] | 274 | |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 275 | GLint getUniformLocation(const std::string &name) const; |
| 276 | GLuint getUniformIndex(const std::string &name) const; |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 277 | void setUniform1fv(GLint location, GLsizei count, const GLfloat *v); |
| 278 | void setUniform2fv(GLint location, GLsizei count, const GLfloat *v); |
| 279 | void setUniform3fv(GLint location, GLsizei count, const GLfloat *v); |
| 280 | void setUniform4fv(GLint location, GLsizei count, const GLfloat *v); |
| 281 | void setUniform1iv(GLint location, GLsizei count, const GLint *v); |
| 282 | void setUniform2iv(GLint location, GLsizei count, const GLint *v); |
| 283 | void setUniform3iv(GLint location, GLsizei count, const GLint *v); |
| 284 | void setUniform4iv(GLint location, GLsizei count, const GLint *v); |
| 285 | void setUniform1uiv(GLint location, GLsizei count, const GLuint *v); |
| 286 | void setUniform2uiv(GLint location, GLsizei count, const GLuint *v); |
| 287 | void setUniform3uiv(GLint location, GLsizei count, const GLuint *v); |
| 288 | void setUniform4uiv(GLint location, GLsizei count, const GLuint *v); |
| 289 | void setUniformMatrix2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); |
| 290 | void setUniformMatrix3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); |
| 291 | void setUniformMatrix4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); |
| 292 | void setUniformMatrix2x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); |
| 293 | void setUniformMatrix3x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); |
| 294 | void setUniformMatrix2x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); |
| 295 | void setUniformMatrix4x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); |
| 296 | void setUniformMatrix3x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); |
| 297 | void setUniformMatrix4x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); |
| 298 | |
| 299 | void getUniformfv(GLint location, GLfloat *params); |
| 300 | void getUniformiv(GLint location, GLint *params); |
| 301 | void getUniformuiv(GLint location, GLuint *params); |
| 302 | |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 303 | void getActiveUniformBlockName(GLuint uniformBlockIndex, GLsizei bufSize, GLsizei *length, GLchar *uniformBlockName) const; |
| 304 | void getActiveUniformBlockiv(GLuint uniformBlockIndex, GLenum pname, GLint *params) const; |
| 305 | GLuint getActiveUniformBlockCount(); |
shannonwoods@chromium.org | e684b58 | 2013-05-30 00:07:42 +0000 | [diff] [blame] | 306 | GLint getActiveUniformBlockMaxLength(); |
| 307 | |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 308 | GLuint getUniformBlockIndex(const std::string &name); |
| 309 | |
shannonwoods@chromium.org | 70eb1ea | 2013-05-30 00:07:20 +0000 | [diff] [blame] | 310 | void bindUniformBlock(GLuint uniformBlockIndex, GLuint uniformBlockBinding); |
| 311 | GLuint getUniformBlockBinding(GLuint uniformBlockIndex) const; |
| 312 | |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 313 | const UniformBlock &getUniformBlockByIndex(GLuint index) const; |
Gregoire Payen de La Garanderie | 68694e9 | 2015-03-24 14:03:37 +0000 | [diff] [blame] | 314 | |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 315 | void setTransformFeedbackVaryings(GLsizei count, const GLchar *const *varyings, GLenum bufferMode); |
| 316 | 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] | 317 | GLsizei getTransformFeedbackVaryingCount() const; |
| 318 | GLsizei getTransformFeedbackVaryingMaxLength() const; |
| 319 | GLenum getTransformFeedbackBufferMode() const; |
| 320 | |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 321 | static bool linkValidateUniforms(InfoLog &infoLog, const std::string &uniformName, const sh::Uniform &vertexUniform, const sh::Uniform &fragmentUniform); |
| 322 | static bool linkValidateInterfaceBlockFields(InfoLog &infoLog, const std::string &uniformName, const sh::InterfaceBlockField &vertexUniform, const sh::InterfaceBlockField &fragmentUniform); |
| 323 | |
apatrick@chromium.org | e2a59bb | 2012-06-07 21:09:53 +0000 | [diff] [blame] | 324 | void addRef(); |
| 325 | void release(); |
| 326 | unsigned int getRefCount() const; |
| 327 | void flagForDeletion(); |
| 328 | bool isFlaggedForDeletion() const; |
| 329 | |
Brandon Jones | 43a53e2 | 2014-08-28 16:23:22 -0700 | [diff] [blame] | 330 | void validate(const Caps &caps); |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 331 | bool validateSamplers(InfoLog *infoLog, const Caps &caps); |
apatrick@chromium.org | e2a59bb | 2012-06-07 21:09:53 +0000 | [diff] [blame] | 332 | bool isValidated() const; |
apatrick@chromium.org | 90080e3 | 2012-07-09 22:15:33 +0000 | [diff] [blame] | 333 | |
Jamie Madill | 63805b4 | 2015-08-25 13:17:39 -0400 | [diff] [blame] | 334 | const AttributesMask &getActiveAttribLocationsMask() const |
| 335 | { |
| 336 | return mData.mActiveAttribLocationsMask; |
| 337 | } |
| 338 | |
apatrick@chromium.org | e2a59bb | 2012-06-07 21:09:53 +0000 | [diff] [blame] | 339 | private: |
apatrick@chromium.org | e2a59bb | 2012-06-07 21:09:53 +0000 | [diff] [blame] | 340 | void unlink(bool destroy = false); |
shannonwoods@chromium.org | 70eb1ea | 2013-05-30 00:07:20 +0000 | [diff] [blame] | 341 | void resetUniformBlockBindings(); |
apatrick@chromium.org | e2a59bb | 2012-06-07 21:09:53 +0000 | [diff] [blame] | 342 | |
Jamie Madill | 5c6b7bf | 2015-08-17 12:53:35 -0400 | [diff] [blame] | 343 | bool linkAttributes(const gl::Data &data, |
Jamie Madill | 3da79b7 | 2015-04-27 11:09:17 -0400 | [diff] [blame] | 344 | InfoLog &infoLog, |
| 345 | const AttributeBindings &attributeBindings, |
| 346 | const Shader *vertexShader); |
Jamie Madill | e473dee | 2015-08-18 14:49:01 -0400 | [diff] [blame] | 347 | bool linkUniformBlocks(InfoLog &infoLog, const Caps &caps); |
Jamie Madill | ada9ecc | 2015-08-17 12:53:37 -0400 | [diff] [blame] | 348 | static bool linkVaryings(InfoLog &infoLog, |
| 349 | const Shader *vertexShader, |
| 350 | const Shader *fragmentShader); |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 351 | bool linkUniforms(gl::InfoLog &infoLog, const gl::Caps &caps); |
| 352 | void indexUniforms(); |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 353 | bool areMatchingInterfaceBlocks(gl::InfoLog &infoLog, const sh::InterfaceBlock &vertexInterfaceBlock, |
| 354 | const sh::InterfaceBlock &fragmentInterfaceBlock); |
| 355 | |
| 356 | static bool linkValidateVariablesBase(InfoLog &infoLog, |
| 357 | const std::string &variableName, |
| 358 | const sh::ShaderVariable &vertexVariable, |
| 359 | const sh::ShaderVariable &fragmentVariable, |
| 360 | bool validatePrecision); |
| 361 | |
| 362 | static bool linkValidateVaryings(InfoLog &infoLog, const std::string &varyingName, const sh::Varying &vertexVarying, const sh::Varying &fragmentVarying); |
Jamie Madill | ccdf74b | 2015-08-18 10:46:12 -0400 | [diff] [blame] | 363 | bool linkValidateTransformFeedback(InfoLog &infoLog, |
| 364 | const std::vector<const sh::Varying *> &linkedVaryings, |
| 365 | const Caps &caps) const; |
| 366 | |
| 367 | void gatherTransformFeedbackVaryings(const std::vector<const sh::Varying *> &varyings); |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 368 | bool assignUniformBlockRegister(InfoLog &infoLog, UniformBlock *uniformBlock, GLenum shader, unsigned int registerIndex, const Caps &caps); |
| 369 | void defineOutputVariables(Shader *fragmentShader); |
| 370 | |
Jamie Madill | ccdf74b | 2015-08-18 10:46:12 -0400 | [diff] [blame] | 371 | std::vector<const sh::Varying *> getMergedVaryings() const; |
Jamie Madill | 80a6fc0 | 2015-08-21 16:53:16 -0400 | [diff] [blame] | 372 | void linkOutputVariables(); |
Jamie Madill | ccdf74b | 2015-08-18 10:46:12 -0400 | [diff] [blame] | 373 | |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 374 | bool flattenUniformsAndCheckCaps(const Caps &caps, InfoLog &infoLog); |
| 375 | |
| 376 | struct VectorAndSamplerCount |
| 377 | { |
| 378 | VectorAndSamplerCount() : vectorCount(0), samplerCount(0) {} |
| 379 | VectorAndSamplerCount(const VectorAndSamplerCount &other) = default; |
| 380 | VectorAndSamplerCount &operator=(const VectorAndSamplerCount &other) = default; |
| 381 | |
| 382 | VectorAndSamplerCount &operator+=(const VectorAndSamplerCount &other) |
| 383 | { |
| 384 | vectorCount += other.vectorCount; |
| 385 | samplerCount += other.samplerCount; |
| 386 | return *this; |
| 387 | } |
| 388 | |
| 389 | unsigned int vectorCount; |
| 390 | unsigned int samplerCount; |
| 391 | }; |
| 392 | |
| 393 | VectorAndSamplerCount flattenUniform(const sh::ShaderVariable &uniform, |
Jamie Madill | 3d3d2f2 | 2015-09-23 16:47:51 -0400 | [diff] [blame^] | 394 | const std::string &fullName, |
| 395 | std::vector<LinkedUniform> *samplerUniforms); |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 396 | |
| 397 | void gatherInterfaceBlockInfo(); |
| 398 | void defineUniformBlock(const sh::InterfaceBlock &interfaceBlock, GLenum shaderType); |
| 399 | |
| 400 | template <typename T> |
| 401 | void setUniformInternal(GLint location, GLsizei count, const T *v); |
| 402 | |
| 403 | template <size_t cols, size_t rows, typename T> |
| 404 | void setMatrixUniformInternal(GLint location, GLsizei count, GLboolean transpose, const T *v); |
| 405 | |
| 406 | template <typename DestT> |
| 407 | void getUniformInternal(GLint location, DestT *dataOut) const; |
| 408 | |
Jamie Madill | 5c6b7bf | 2015-08-17 12:53:35 -0400 | [diff] [blame] | 409 | Data mData; |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 410 | rx::ProgramImpl *mProgram; |
| 411 | |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 412 | bool mValidated; |
| 413 | |
apatrick@chromium.org | e2a59bb | 2012-06-07 21:09:53 +0000 | [diff] [blame] | 414 | AttributeBindings mAttributeBindings; |
| 415 | |
daniel@transgaming.com | 716056c | 2012-07-24 18:38:59 +0000 | [diff] [blame] | 416 | bool mLinked; |
apatrick@chromium.org | e2a59bb | 2012-06-07 21:09:53 +0000 | [diff] [blame] | 417 | 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] | 418 | |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 419 | unsigned int mRefCount; |
| 420 | |
daniel@transgaming.com | da13f3e | 2010-07-28 19:20:56 +0000 | [diff] [blame] | 421 | ResourceManager *mResourceManager; |
| 422 | const GLuint mHandle; |
apatrick@chromium.org | 253b8d2 | 2012-06-22 19:27:21 +0000 | [diff] [blame] | 423 | |
| 424 | InfoLog mInfoLog; |
Jamie Madill | 3d3d2f2 | 2015-09-23 16:47:51 -0400 | [diff] [blame^] | 425 | |
| 426 | // Cache for sampler validation |
| 427 | Optional<bool> mCachedValidateSamplersResult; |
| 428 | std::vector<GLenum> mTextureUnitTypesCache; |
| 429 | RangeUI mSamplerUniformRange; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 430 | }; |
| 431 | } |
| 432 | |
Geoff Lang | 0a73dd8 | 2014-11-19 16:18:08 -0500 | [diff] [blame] | 433 | #endif // LIBANGLE_PROGRAM_H_ |