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