blob: 777e386b2f3bd5f028a4a02fd98288d66e430de7 [file] [log] [blame]
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001//
Geoff Lang1b6edcb2014-02-03 14:27:56 -05002// Copyright (c) 2002-2014 The ANGLE Project Authors. All rights reserved.
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003// 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
10#ifndef LIBGLESV2_PROGRAM_H_
11#define LIBGLESV2_PROGRAM_H_
12
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000013#include <string>
daniel@transgaming.comb4ff1f82010-04-22 13:35:18 +000014#include <set>
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000015
shannon.woods@transgaming.com486d9e92013-02-28 23:15:41 +000016#include "common/angleutils.h"
17#include "common/RefCountObject.h"
18#include "libGLESv2/Constants.h"
Shannon Woods53a94a82014-06-24 15:20:36 -040019#include "libGLESv2/ProgramBinary.h"
shannon.woods@transgaming.com486d9e92013-02-28 23:15:41 +000020
21namespace rx
22{
23class Renderer;
24}
daniel@transgaming.come6842292010-04-20 18:52:50 +000025
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000026namespace gl
27{
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000028class ResourceManager;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000029class FragmentShader;
30class VertexShader;
shannon.woods@transgaming.com486d9e92013-02-28 23:15:41 +000031class Shader;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000032
apatrick@chromium.org253b8d22012-06-22 19:27:21 +000033extern const char * const g_fakepath;
34
apatrick@chromium.org9a30b092012-06-06 20:21:55 +000035class AttributeBindings
36{
37 public:
38 AttributeBindings();
39 ~AttributeBindings();
40
41 void bindAttributeLocation(GLuint index, const char *name);
42 int getAttributeBinding(const std::string &name) const;
43
44 private:
45 std::set<std::string> mAttributeBinding[MAX_VERTEX_ATTRIBS];
46};
47
apatrick@chromium.org253b8d22012-06-22 19:27:21 +000048class InfoLog
49{
50 public:
51 InfoLog();
52 ~InfoLog();
53
54 int getLength() const;
55 void getLog(GLsizei bufSize, GLsizei *length, char *infoLog);
56
57 void appendSanitized(const char *message);
58 void append(const char *info, ...);
59 void reset();
60 private:
61 DISALLOW_COPY_AND_ASSIGN(InfoLog);
62 char *mInfoLog;
63};
64
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +000065class Program
66{
67 public:
daniel@transgaming.com70062c92012-11-28 19:32:30 +000068 Program(rx::Renderer *renderer, ResourceManager *manager, GLuint handle);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +000069
70 ~Program();
71
72 bool attachShader(Shader *shader);
73 bool detachShader(Shader *shader);
74 int getAttachedShadersCount() const;
75
76 void bindAttributeLocation(GLuint index, const char *name);
77
daniel@transgaming.com4c962bf2012-07-24 18:37:02 +000078 bool link();
daniel@transgaming.com716056c2012-07-24 18:38:59 +000079 bool isLinked();
Geoff Lang900013c2014-07-07 11:32:19 -040080 bool setProgramBinary(GLenum binaryFormat, const void *binary, GLsizei length);
Geoff Lang48dcae72014-02-05 16:28:24 -050081 ProgramBinary *getProgramBinary() const;
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +000082
83 int getInfoLogLength() const;
84 void getInfoLog(GLsizei bufSize, GLsizei *length, char *infoLog);
85 void getAttachedShaders(GLsizei maxCount, GLsizei *count, GLuint *shaders);
86
87 void getActiveAttribute(GLuint index, GLsizei bufsize, GLsizei *length, GLint *size, GLenum *type, GLchar *name);
88 GLint getActiveAttributeCount();
89 GLint getActiveAttributeMaxLength();
90
91 void getActiveUniform(GLuint index, GLsizei bufsize, GLsizei *length, GLint *size, GLenum *type, GLchar *name);
92 GLint getActiveUniformCount();
93 GLint getActiveUniformMaxLength();
94
shannonwoods@chromium.orge684b582013-05-30 00:07:42 +000095 GLint getActiveUniformBlockCount();
96 GLint getActiveUniformBlockMaxLength();
97
shannonwoods@chromium.org70eb1ea2013-05-30 00:07:20 +000098 void bindUniformBlock(GLuint uniformBlockIndex, GLuint uniformBlockBinding);
99 GLuint getUniformBlockBinding(GLuint uniformBlockIndex) const;
100
Geoff Lang48dcae72014-02-05 16:28:24 -0500101 void setTransformFeedbackVaryings(GLsizei count, const GLchar *const *varyings, GLenum bufferMode);
102 void getTransformFeedbackVarying(GLuint index, GLsizei bufSize, GLsizei *length, GLsizei *size, GLenum *type, GLchar *name) const;
Geoff Lang1b6edcb2014-02-03 14:27:56 -0500103 GLsizei getTransformFeedbackVaryingCount() const;
104 GLsizei getTransformFeedbackVaryingMaxLength() const;
105 GLenum getTransformFeedbackBufferMode() const;
106
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +0000107 void addRef();
108 void release();
109 unsigned int getRefCount() const;
110 void flagForDeletion();
111 bool isFlaggedForDeletion() const;
112
apatrick@chromium.org253b8d22012-06-22 19:27:21 +0000113 void validate();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +0000114 bool isValidated() const;
115
apatrick@chromium.org90080e32012-07-09 22:15:33 +0000116 GLint getProgramBinaryLength() const;
117
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +0000118 private:
119 DISALLOW_COPY_AND_ASSIGN(Program);
120
121 void unlink(bool destroy = false);
shannonwoods@chromium.org70eb1ea2013-05-30 00:07:20 +0000122 void resetUniformBlockBindings();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +0000123
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +0000124 FragmentShader *mFragmentShader;
125 VertexShader *mVertexShader;
126
127 AttributeBindings mAttributeBindings;
128
shannonwoods@chromium.org70eb1ea2013-05-30 00:07:20 +0000129 GLuint mUniformBlockBindings[IMPLEMENTATION_MAX_COMBINED_SHADER_UNIFORM_BUFFERS];
130
Geoff Lang48dcae72014-02-05 16:28:24 -0500131 std::vector<std::string> mTransformFeedbackVaryings;
132 GLuint mTransformFeedbackBufferMode;
133
daniel@transgaming.com989c1c82012-07-24 18:40:38 +0000134 BindingPointer<ProgramBinary> mProgramBinary;
daniel@transgaming.com716056c2012-07-24 18:38:59 +0000135 bool mLinked;
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +0000136 bool mDeleteStatus; // Flag to indicate that the program can be deleted when no longer in use
daniel@transgaming.com4fa08332010-05-11 02:29:27 +0000137
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000138 unsigned int mRefCount;
139
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000140 ResourceManager *mResourceManager;
daniel@transgaming.com70062c92012-11-28 19:32:30 +0000141 rx::Renderer *mRenderer;
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000142 const GLuint mHandle;
apatrick@chromium.org253b8d22012-06-22 19:27:21 +0000143
144 InfoLog mInfoLog;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000145};
146}
147
148#endif // LIBGLESV2_PROGRAM_H_