blob: 4c067838fa83a6241946dd63991b6fce148a9010 [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
shannon.woods@transgaming.com486d9e92013-02-28 23:15:41 +000013#include "common/angleutils.h"
14#include "common/RefCountObject.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050015#include "libANGLE/Constants.h"
16#include "libANGLE/ProgramBinary.h"
shannon.woods@transgaming.com486d9e92013-02-28 23:15:41 +000017
Geoff Lang0b7eef72014-06-12 14:10:47 -040018#include <GLES2/gl2.h>
19
20#include <vector>
21#include <string>
22#include <set>
23
shannon.woods@transgaming.com486d9e92013-02-28 23:15:41 +000024namespace rx
25{
26class Renderer;
27}
daniel@transgaming.come6842292010-04-20 18:52:50 +000028
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000029namespace gl
30{
Brandon Jones43a53e22014-08-28 16:23:22 -070031struct Caps;
Jamie Madillde8892b2014-11-11 13:00:22 -050032struct Data;
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000033class ResourceManager;
shannon.woods@transgaming.com486d9e92013-02-28 23:15:41 +000034class Shader;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000035
apatrick@chromium.org253b8d22012-06-22 19:27:21 +000036extern const char * const g_fakepath;
37
apatrick@chromium.org9a30b092012-06-06 20:21:55 +000038class AttributeBindings
39{
40 public:
41 AttributeBindings();
42 ~AttributeBindings();
43
44 void bindAttributeLocation(GLuint index, const char *name);
45 int getAttributeBinding(const std::string &name) const;
46
47 private:
48 std::set<std::string> mAttributeBinding[MAX_VERTEX_ATTRIBS];
49};
50
apatrick@chromium.org253b8d22012-06-22 19:27:21 +000051class InfoLog
52{
53 public:
54 InfoLog();
55 ~InfoLog();
56
57 int getLength() const;
58 void getLog(GLsizei bufSize, GLsizei *length, char *infoLog);
59
60 void appendSanitized(const char *message);
61 void append(const char *info, ...);
62 void reset();
63 private:
64 DISALLOW_COPY_AND_ASSIGN(InfoLog);
65 char *mInfoLog;
66};
67
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +000068class Program
69{
70 public:
daniel@transgaming.com70062c92012-11-28 19:32:30 +000071 Program(rx::Renderer *renderer, ResourceManager *manager, GLuint handle);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +000072
73 ~Program();
74
75 bool attachShader(Shader *shader);
76 bool detachShader(Shader *shader);
77 int getAttachedShadersCount() const;
78
79 void bindAttributeLocation(GLuint index, const char *name);
80
Jamie Madillde8892b2014-11-11 13:00:22 -050081 Error link(const Data &data);
daniel@transgaming.com716056c2012-07-24 18:38:59 +000082 bool isLinked();
Geoff Langb543aff2014-09-30 14:52:54 -040083 Error setProgramBinary(GLenum binaryFormat, const void *binary, GLsizei length);
Geoff Lang48dcae72014-02-05 16:28:24 -050084 ProgramBinary *getProgramBinary() const;
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +000085
86 int getInfoLogLength() const;
87 void getInfoLog(GLsizei bufSize, GLsizei *length, char *infoLog);
88 void getAttachedShaders(GLsizei maxCount, GLsizei *count, GLuint *shaders);
89
90 void getActiveAttribute(GLuint index, GLsizei bufsize, GLsizei *length, GLint *size, GLenum *type, GLchar *name);
91 GLint getActiveAttributeCount();
92 GLint getActiveAttributeMaxLength();
93
94 void getActiveUniform(GLuint index, GLsizei bufsize, GLsizei *length, GLint *size, GLenum *type, GLchar *name);
95 GLint getActiveUniformCount();
96 GLint getActiveUniformMaxLength();
97
shannonwoods@chromium.orge684b582013-05-30 00:07:42 +000098 GLint getActiveUniformBlockCount();
99 GLint getActiveUniformBlockMaxLength();
100
shannonwoods@chromium.org70eb1ea2013-05-30 00:07:20 +0000101 void bindUniformBlock(GLuint uniformBlockIndex, GLuint uniformBlockBinding);
102 GLuint getUniformBlockBinding(GLuint uniformBlockIndex) const;
103
Geoff Lang48dcae72014-02-05 16:28:24 -0500104 void setTransformFeedbackVaryings(GLsizei count, const GLchar *const *varyings, GLenum bufferMode);
105 void getTransformFeedbackVarying(GLuint index, GLsizei bufSize, GLsizei *length, GLsizei *size, GLenum *type, GLchar *name) const;
Geoff Lang1b6edcb2014-02-03 14:27:56 -0500106 GLsizei getTransformFeedbackVaryingCount() const;
107 GLsizei getTransformFeedbackVaryingMaxLength() const;
108 GLenum getTransformFeedbackBufferMode() const;
109
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +0000110 void addRef();
111 void release();
112 unsigned int getRefCount() const;
113 void flagForDeletion();
114 bool isFlaggedForDeletion() const;
115
Brandon Jones43a53e22014-08-28 16:23:22 -0700116 void validate(const Caps &caps);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +0000117 bool isValidated() const;
118
apatrick@chromium.org90080e32012-07-09 22:15:33 +0000119 GLint getProgramBinaryLength() const;
120
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +0000121 private:
122 DISALLOW_COPY_AND_ASSIGN(Program);
123
124 void unlink(bool destroy = false);
shannonwoods@chromium.org70eb1ea2013-05-30 00:07:20 +0000125 void resetUniformBlockBindings();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +0000126
Brandon Jones71620962014-08-20 14:04:59 -0700127 Shader *mFragmentShader;
128 Shader *mVertexShader;
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +0000129
130 AttributeBindings mAttributeBindings;
131
shannonwoods@chromium.org70eb1ea2013-05-30 00:07:20 +0000132 GLuint mUniformBlockBindings[IMPLEMENTATION_MAX_COMBINED_SHADER_UNIFORM_BUFFERS];
133
Geoff Lang48dcae72014-02-05 16:28:24 -0500134 std::vector<std::string> mTransformFeedbackVaryings;
135 GLuint mTransformFeedbackBufferMode;
136
daniel@transgaming.com989c1c82012-07-24 18:40:38 +0000137 BindingPointer<ProgramBinary> mProgramBinary;
daniel@transgaming.com716056c2012-07-24 18:38:59 +0000138 bool mLinked;
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +0000139 bool mDeleteStatus; // Flag to indicate that the program can be deleted when no longer in use
daniel@transgaming.com4fa08332010-05-11 02:29:27 +0000140
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000141 unsigned int mRefCount;
142
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000143 ResourceManager *mResourceManager;
daniel@transgaming.com70062c92012-11-28 19:32:30 +0000144 rx::Renderer *mRenderer;
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000145 const GLuint mHandle;
apatrick@chromium.org253b8d22012-06-22 19:27:21 +0000146
147 InfoLog mInfoLog;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000148};
149}
150
151#endif // LIBGLESV2_PROGRAM_H_