Brandon Jones | c9610c5 | 2014-08-25 17:02:59 -0700 | [diff] [blame] | 1 | // |
| 2 | // Copyright 2014 The ANGLE Project Authors. All rights reserved. |
| 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 | // ProgramImpl.h: Defines the abstract rx::ProgramImpl class. |
| 8 | |
Geoff Lang | 0a73dd8 | 2014-11-19 16:18:08 -0500 | [diff] [blame] | 9 | #ifndef LIBANGLE_RENDERER_PROGRAMIMPL_H_ |
| 10 | #define LIBANGLE_RENDERER_PROGRAMIMPL_H_ |
Brandon Jones | c9610c5 | 2014-08-25 17:02:59 -0700 | [diff] [blame] | 11 | |
| 12 | #include "common/angleutils.h" |
Geoff Lang | 2b5420c | 2014-11-19 14:20:15 -0500 | [diff] [blame] | 13 | #include "libANGLE/BinaryStream.h" |
| 14 | #include "libANGLE/Constants.h" |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 15 | #include "libANGLE/Program.h" |
Geoff Lang | 2b5420c | 2014-11-19 14:20:15 -0500 | [diff] [blame] | 16 | #include "libANGLE/Shader.h" |
| 17 | #include "libANGLE/renderer/Renderer.h" |
Brandon Jones | c9610c5 | 2014-08-25 17:02:59 -0700 | [diff] [blame] | 18 | |
Brandon Jones | 1a8a7e3 | 2014-10-01 12:49:30 -0700 | [diff] [blame] | 19 | #include <map> |
| 20 | |
Brandon Jones | c9610c5 | 2014-08-25 17:02:59 -0700 | [diff] [blame] | 21 | namespace rx |
| 22 | { |
| 23 | |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 24 | struct LinkResult |
| 25 | { |
| 26 | bool linkSuccess; |
| 27 | gl::Error error; |
| 28 | LinkResult(bool linkSuccess, const gl::Error &error); |
| 29 | }; |
| 30 | |
Jamie Madill | f0d10f8 | 2015-03-31 12:56:52 -0400 | [diff] [blame] | 31 | class ProgramImpl : angle::NonCopyable |
Brandon Jones | c9610c5 | 2014-08-25 17:02:59 -0700 | [diff] [blame] | 32 | { |
Brandon Jones | 1a8a7e3 | 2014-10-01 12:49:30 -0700 | [diff] [blame] | 33 | public: |
Jamie Madill | 437d266 | 2014-12-05 14:23:35 -0500 | [diff] [blame] | 34 | typedef int SemanticIndexArray[gl::MAX_VERTEX_ATTRIBS]; |
| 35 | |
Jamie Madill | 5c6b7bf | 2015-08-17 12:53:35 -0400 | [diff] [blame] | 36 | ProgramImpl(const gl::Program::Data &data); |
Brandon Jones | 1a8a7e3 | 2014-10-01 12:49:30 -0700 | [diff] [blame] | 37 | virtual ~ProgramImpl(); |
| 38 | |
Brandon Jones | 44151a9 | 2014-09-10 11:32:25 -0700 | [diff] [blame] | 39 | virtual bool usesPointSize() const = 0; |
Brandon Jones | 44151a9 | 2014-09-10 11:32:25 -0700 | [diff] [blame] | 40 | virtual int getShaderVersion() const = 0; |
| 41 | |
Brandon Jones | 22502d5 | 2014-08-29 16:58:36 -0700 | [diff] [blame] | 42 | virtual GLenum getBinaryFormat() = 0; |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 43 | virtual LinkResult load(gl::InfoLog &infoLog, gl::BinaryInputStream *stream) = 0; |
Geoff Lang | b543aff | 2014-09-30 14:52:54 -0400 | [diff] [blame] | 44 | virtual gl::Error save(gl::BinaryOutputStream *stream) = 0; |
Brandon Jones | 22502d5 | 2014-08-29 16:58:36 -0700 | [diff] [blame] | 45 | |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 46 | virtual LinkResult link(const gl::Data &data, gl::InfoLog &infoLog, |
| 47 | gl::Shader *fragmentShader, gl::Shader *vertexShader, |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 48 | int *registers, std::vector<gl::LinkedVarying> *linkedVaryings, |
| 49 | std::map<int, gl::VariableLocation> *outputVariables) = 0; |
Brandon Jones | 44151a9 | 2014-09-10 11:32:25 -0700 | [diff] [blame] | 50 | |
Geoff Lang | 0ca5378 | 2015-05-07 13:49:39 -0400 | [diff] [blame] | 51 | virtual void bindAttributeLocation(GLuint index, const std::string &name) = 0; |
| 52 | |
Brandon Jones | 1a8a7e3 | 2014-10-01 12:49:30 -0700 | [diff] [blame] | 53 | virtual void setUniform1fv(GLint location, GLsizei count, const GLfloat *v) = 0; |
| 54 | virtual void setUniform2fv(GLint location, GLsizei count, const GLfloat *v) = 0; |
| 55 | virtual void setUniform3fv(GLint location, GLsizei count, const GLfloat *v) = 0; |
| 56 | virtual void setUniform4fv(GLint location, GLsizei count, const GLfloat *v) = 0; |
| 57 | virtual void setUniform1iv(GLint location, GLsizei count, const GLint *v) = 0; |
| 58 | virtual void setUniform2iv(GLint location, GLsizei count, const GLint *v) = 0; |
| 59 | virtual void setUniform3iv(GLint location, GLsizei count, const GLint *v) = 0; |
| 60 | virtual void setUniform4iv(GLint location, GLsizei count, const GLint *v) = 0; |
| 61 | virtual void setUniform1uiv(GLint location, GLsizei count, const GLuint *v) = 0; |
| 62 | virtual void setUniform2uiv(GLint location, GLsizei count, const GLuint *v) = 0; |
| 63 | virtual void setUniform3uiv(GLint location, GLsizei count, const GLuint *v) = 0; |
| 64 | virtual void setUniform4uiv(GLint location, GLsizei count, const GLuint *v) = 0; |
| 65 | virtual void setUniformMatrix2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) = 0; |
| 66 | virtual void setUniformMatrix3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) = 0; |
| 67 | virtual void setUniformMatrix4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) = 0; |
| 68 | virtual void setUniformMatrix2x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) = 0; |
| 69 | virtual void setUniformMatrix3x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) = 0; |
| 70 | virtual void setUniformMatrix2x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) = 0; |
| 71 | virtual void setUniformMatrix4x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) = 0; |
| 72 | virtual void setUniformMatrix3x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) = 0; |
| 73 | virtual void setUniformMatrix4x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) = 0; |
Brandon Jones | c9610c5 | 2014-08-25 17:02:59 -0700 | [diff] [blame] | 74 | |
Brandon Jones | 1a8a7e3 | 2014-10-01 12:49:30 -0700 | [diff] [blame] | 75 | virtual void getUniformfv(GLint location, GLfloat *params) = 0; |
| 76 | virtual void getUniformiv(GLint location, GLint *params) = 0; |
| 77 | virtual void getUniformuiv(GLint location, GLuint *params) = 0; |
| 78 | |
Brandon Jones | 1a8a7e3 | 2014-10-01 12:49:30 -0700 | [diff] [blame] | 79 | // TODO: The following functions are possibly only applicable to D3D backends. The should be carefully evaluated to |
| 80 | // determine if they can be removed from this interface. |
| 81 | virtual GLint getSamplerMapping(gl::SamplerType type, unsigned int samplerIndex, const gl::Caps &caps) const = 0; |
| 82 | virtual GLenum getSamplerTextureType(gl::SamplerType type, unsigned int samplerIndex) const = 0; |
| 83 | virtual GLint getUsedSamplerRange(gl::SamplerType type) const = 0; |
| 84 | virtual void updateSamplerMapping() = 0; |
| 85 | virtual bool validateSamplers(gl::InfoLog *infoLog, const gl::Caps &caps) = 0; |
| 86 | |
Jamie Madill | 5c6b7bf | 2015-08-17 12:53:35 -0400 | [diff] [blame] | 87 | virtual LinkResult compileProgramExecutables(gl::InfoLog &infoLog, int registers) = 0; |
Brandon Jones | 1a8a7e3 | 2014-10-01 12:49:30 -0700 | [diff] [blame] | 88 | |
Brandon Jones | 1a8a7e3 | 2014-10-01 12:49:30 -0700 | [diff] [blame] | 89 | virtual gl::Error applyUniforms() = 0; |
Gregoire Payen de La Garanderie | 68694e9 | 2015-03-24 14:03:37 +0000 | [diff] [blame] | 90 | virtual gl::Error applyUniformBuffers(const gl::Data &data, GLuint uniformBlockBindings[]) = 0; |
Brandon Jones | 18bd410 | 2014-09-22 14:21:44 -0700 | [diff] [blame] | 91 | |
Jamie Madill | 811b635 | 2015-02-09 10:17:09 -0500 | [diff] [blame] | 92 | const std::vector<gl::LinkedUniform*> &getUniforms() const { return mUniforms; } |
Geoff Lang | 9513784 | 2015-06-02 15:38:43 -0400 | [diff] [blame] | 93 | const std::map<GLuint, gl::VariableLocation> &getUniformIndices() const { return mUniformIndex; } |
Jamie Madill | 811b635 | 2015-02-09 10:17:09 -0500 | [diff] [blame] | 94 | const std::vector<gl::UniformBlock*> &getUniformBlocks() const { return mUniformBlocks; } |
| 95 | const std::vector<gl::LinkedVarying> &getTransformFeedbackLinkedVaryings() const { return mTransformFeedbackLinkedVaryings; } |
Jamie Madill | 3da79b7 | 2015-04-27 11:09:17 -0400 | [diff] [blame] | 96 | const std::vector<sh::Attribute> getShaderAttributes() { return mShaderAttributes; } |
Jamie Madill | 811b635 | 2015-02-09 10:17:09 -0500 | [diff] [blame] | 97 | const SemanticIndexArray &getSemanticIndexes() const { return mSemanticIndex; } |
| 98 | |
| 99 | std::vector<gl::LinkedUniform*> &getUniforms() { return mUniforms; } |
Geoff Lang | 9513784 | 2015-06-02 15:38:43 -0400 | [diff] [blame] | 100 | std::map<GLuint, gl::VariableLocation> &getUniformIndices() { return mUniformIndex; } |
Jamie Madill | 811b635 | 2015-02-09 10:17:09 -0500 | [diff] [blame] | 101 | std::vector<gl::UniformBlock*> &getUniformBlocks() { return mUniformBlocks; } |
| 102 | std::vector<gl::LinkedVarying> &getTransformFeedbackLinkedVaryings() { return mTransformFeedbackLinkedVaryings; } |
Jamie Madill | 811b635 | 2015-02-09 10:17:09 -0500 | [diff] [blame] | 103 | SemanticIndexArray &getSemanticIndexes() { return mSemanticIndex; } |
| 104 | |
| 105 | gl::LinkedUniform *getUniformByLocation(GLint location) const; |
| 106 | gl::LinkedUniform *getUniformByName(const std::string &name) const; |
| 107 | gl::UniformBlock *getUniformBlockByIndex(GLuint blockIndex) const; |
| 108 | |
Geoff Lang | cfaeaa9 | 2015-04-14 13:41:02 -0400 | [diff] [blame] | 109 | GLint getUniformLocation(const std::string &name) const; |
| 110 | GLuint getUniformIndex(const std::string &name) const; |
| 111 | GLuint getUniformBlockIndex(const std::string &name) const; |
Jamie Madill | 811b635 | 2015-02-09 10:17:09 -0500 | [diff] [blame] | 112 | |
Jamie Madill | 3da79b7 | 2015-04-27 11:09:17 -0400 | [diff] [blame] | 113 | void setShaderAttribute(size_t index, const sh::Attribute &attrib); |
| 114 | void setShaderAttribute(size_t index, GLenum type, GLenum precision, const std::string &name, GLint size, int location); |
| 115 | |
Jamie Madill | 811b635 | 2015-02-09 10:17:09 -0500 | [diff] [blame] | 116 | virtual void reset(); |
| 117 | |
Brandon Jones | 1a8a7e3 | 2014-10-01 12:49:30 -0700 | [diff] [blame] | 118 | protected: |
Jamie Madill | 5c6b7bf | 2015-08-17 12:53:35 -0400 | [diff] [blame] | 119 | const gl::Program::Data &mData; |
| 120 | |
Brandon Jones | 1a8a7e3 | 2014-10-01 12:49:30 -0700 | [diff] [blame] | 121 | std::vector<gl::LinkedUniform*> mUniforms; |
Geoff Lang | 9513784 | 2015-06-02 15:38:43 -0400 | [diff] [blame] | 122 | |
| 123 | // TODO: use a hash map |
| 124 | std::map<GLuint, gl::VariableLocation> mUniformIndex; |
| 125 | |
Brandon Jones | 1a8a7e3 | 2014-10-01 12:49:30 -0700 | [diff] [blame] | 126 | std::vector<gl::UniformBlock*> mUniformBlocks; |
| 127 | std::vector<gl::LinkedVarying> mTransformFeedbackLinkedVaryings; |
| 128 | |
Jamie Madill | 437d266 | 2014-12-05 14:23:35 -0500 | [diff] [blame] | 129 | SemanticIndexArray mSemanticIndex; |
Jamie Madill | 3da79b7 | 2015-04-27 11:09:17 -0400 | [diff] [blame] | 130 | |
| 131 | private: |
| 132 | std::vector<sh::Attribute> mShaderAttributes; |
Brandon Jones | c9610c5 | 2014-08-25 17:02:59 -0700 | [diff] [blame] | 133 | }; |
| 134 | |
| 135 | } |
| 136 | |
Geoff Lang | 0a73dd8 | 2014-11-19 16:18:08 -0500 | [diff] [blame] | 137 | #endif // LIBANGLE_RENDERER_PROGRAMIMPL_H_ |