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 
9 #ifndef LIBANGLE_RENDERER_PROGRAMIMPL_H_
10 #define LIBANGLE_RENDERER_PROGRAMIMPL_H_
11 
12 #include "common/angleutils.h"
13 #include "libANGLE/BinaryStream.h"
14 #include "libANGLE/Constants.h"
15 #include "libANGLE/Program.h"
16 #include "libANGLE/Shader.h"
17 
18 #include <map>
19 
20 namespace gl
21 {
22 class Context;
23 struct ProgramLinkedResources;
24 }
25 
26 namespace sh
27 {
28 struct BlockMemberInfo;
29 }
30 
31 namespace rx
32 {
33 class ProgramImpl : angle::NonCopyable
34 {
35   public:
ProgramImpl(const gl::ProgramState & state)36     ProgramImpl(const gl::ProgramState &state) : mState(state) {}
~ProgramImpl()37     virtual ~ProgramImpl() {}
destroy(const gl::Context * context)38     virtual void destroy(const gl::Context *context) {}
39 
40     virtual gl::LinkResult load(const gl::Context *context,
41                                 gl::InfoLog &infoLog,
42                                 gl::BinaryInputStream *stream) = 0;
43     virtual void save(const gl::Context *context, gl::BinaryOutputStream *stream) = 0;
44     virtual void setBinaryRetrievableHint(bool retrievable) = 0;
45     virtual void setSeparable(bool separable)               = 0;
46 
47     virtual gl::LinkResult link(const gl::Context *context,
48                                 const gl::ProgramLinkedResources &resources,
49                                 gl::InfoLog &infoLog)                      = 0;
50     virtual GLboolean validate(const gl::Caps &caps, gl::InfoLog *infoLog) = 0;
51 
52     virtual void setUniform1fv(GLint location, GLsizei count, const GLfloat *v) = 0;
53     virtual void setUniform2fv(GLint location, GLsizei count, const GLfloat *v) = 0;
54     virtual void setUniform3fv(GLint location, GLsizei count, const GLfloat *v) = 0;
55     virtual void setUniform4fv(GLint location, GLsizei count, const GLfloat *v) = 0;
56     virtual void setUniform1iv(GLint location, GLsizei count, const GLint *v) = 0;
57     virtual void setUniform2iv(GLint location, GLsizei count, const GLint *v) = 0;
58     virtual void setUniform3iv(GLint location, GLsizei count, const GLint *v) = 0;
59     virtual void setUniform4iv(GLint location, GLsizei count, const GLint *v) = 0;
60     virtual void setUniform1uiv(GLint location, GLsizei count, const GLuint *v) = 0;
61     virtual void setUniform2uiv(GLint location, GLsizei count, const GLuint *v) = 0;
62     virtual void setUniform3uiv(GLint location, GLsizei count, const GLuint *v) = 0;
63     virtual void setUniform4uiv(GLint location, GLsizei count, const GLuint *v) = 0;
64     virtual void setUniformMatrix2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) = 0;
65     virtual void setUniformMatrix3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) = 0;
66     virtual void setUniformMatrix4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) = 0;
67     virtual void setUniformMatrix2x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) = 0;
68     virtual void setUniformMatrix3x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) = 0;
69     virtual void setUniformMatrix2x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) = 0;
70     virtual void setUniformMatrix4x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) = 0;
71     virtual void setUniformMatrix3x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) = 0;
72     virtual void setUniformMatrix4x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) = 0;
73 
74     // Done in the back-end to avoid having to keep a system copy of uniform data.
75     virtual void getUniformfv(const gl::Context *context,
76                               GLint location,
77                               GLfloat *params) const = 0;
78     virtual void getUniformiv(const gl::Context *context, GLint location, GLint *params) const = 0;
79     virtual void getUniformuiv(const gl::Context *context,
80                                GLint location,
81                                GLuint *params) const = 0;
82 
83     // TODO: synchronize in syncState when dirty bits exist.
84     virtual void setUniformBlockBinding(GLuint uniformBlockIndex, GLuint uniformBlockBinding) = 0;
85 
86     // CHROMIUM_path_rendering
87     // Set parameters to control fragment shader input variable interpolation
88     virtual void setPathFragmentInputGen(const std::string &inputName,
89                                          GLenum genMode,
90                                          GLint components,
91                                          const GLfloat *coeffs) = 0;
92 
93     // Implementation-specific method for ignoring unreferenced uniforms. Some implementations may
94     // perform more extensive analysis and ignore some locations that ANGLE doesn't detect as
95     // unreferenced. This method is not required to be overriden by a back-end.
markUnusedUniformLocations(std::vector<gl::VariableLocation> * uniformLocations,std::vector<gl::SamplerBinding> * samplerBindings)96     virtual void markUnusedUniformLocations(std::vector<gl::VariableLocation> *uniformLocations,
97                                             std::vector<gl::SamplerBinding> *samplerBindings)
98     {
99     }
100 
101   protected:
102     const gl::ProgramState &mState;
103 };
104 
105 }  // namespace rx
106 
107 #endif // LIBANGLE_RENDERER_PROGRAMIMPL_H_
108