blob: 67ee546abc69588f1867437e205e8f5ce0c769c1 [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"
15#include "libGLESv2/Constants.h"
Shannon Woods53a94a82014-06-24 15:20:36 -040016#include "libGLESv2/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{
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000031class ResourceManager;
shannon.woods@transgaming.com486d9e92013-02-28 23:15:41 +000032class Shader;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000033
apatrick@chromium.org253b8d22012-06-22 19:27:21 +000034extern const char * const g_fakepath;
35
apatrick@chromium.org9a30b092012-06-06 20:21:55 +000036class AttributeBindings
37{
38 public:
39 AttributeBindings();
40 ~AttributeBindings();
41
42 void bindAttributeLocation(GLuint index, const char *name);
43 int getAttributeBinding(const std::string &name) const;
44
45 private:
46 std::set<std::string> mAttributeBinding[MAX_VERTEX_ATTRIBS];
47};
48
apatrick@chromium.org253b8d22012-06-22 19:27:21 +000049class InfoLog
50{
51 public:
52 InfoLog();
53 ~InfoLog();
54
55 int getLength() const;
56 void getLog(GLsizei bufSize, GLsizei *length, char *infoLog);
57
58 void appendSanitized(const char *message);
59 void append(const char *info, ...);
60 void reset();
61 private:
62 DISALLOW_COPY_AND_ASSIGN(InfoLog);
63 char *mInfoLog;
64};
65
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +000066class Program
67{
68 public:
daniel@transgaming.com70062c92012-11-28 19:32:30 +000069 Program(rx::Renderer *renderer, ResourceManager *manager, GLuint handle);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +000070
71 ~Program();
72
73 bool attachShader(Shader *shader);
74 bool detachShader(Shader *shader);
75 int getAttachedShadersCount() const;
76
77 void bindAttributeLocation(GLuint index, const char *name);
78
daniel@transgaming.com4c962bf2012-07-24 18:37:02 +000079 bool link();
daniel@transgaming.com716056c2012-07-24 18:38:59 +000080 bool isLinked();
Geoff Lang900013c2014-07-07 11:32:19 -040081 bool setProgramBinary(GLenum binaryFormat, const void *binary, GLsizei length);
Geoff Lang48dcae72014-02-05 16:28:24 -050082 ProgramBinary *getProgramBinary() const;
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +000083
84 int getInfoLogLength() const;
85 void getInfoLog(GLsizei bufSize, GLsizei *length, char *infoLog);
86 void getAttachedShaders(GLsizei maxCount, GLsizei *count, GLuint *shaders);
87
88 void getActiveAttribute(GLuint index, GLsizei bufsize, GLsizei *length, GLint *size, GLenum *type, GLchar *name);
89 GLint getActiveAttributeCount();
90 GLint getActiveAttributeMaxLength();
91
92 void getActiveUniform(GLuint index, GLsizei bufsize, GLsizei *length, GLint *size, GLenum *type, GLchar *name);
93 GLint getActiveUniformCount();
94 GLint getActiveUniformMaxLength();
95
shannonwoods@chromium.orge684b582013-05-30 00:07:42 +000096 GLint getActiveUniformBlockCount();
97 GLint getActiveUniformBlockMaxLength();
98
shannonwoods@chromium.org70eb1ea2013-05-30 00:07:20 +000099 void bindUniformBlock(GLuint uniformBlockIndex, GLuint uniformBlockBinding);
100 GLuint getUniformBlockBinding(GLuint uniformBlockIndex) const;
101
Geoff Lang48dcae72014-02-05 16:28:24 -0500102 void setTransformFeedbackVaryings(GLsizei count, const GLchar *const *varyings, GLenum bufferMode);
103 void getTransformFeedbackVarying(GLuint index, GLsizei bufSize, GLsizei *length, GLsizei *size, GLenum *type, GLchar *name) const;
Geoff Lang1b6edcb2014-02-03 14:27:56 -0500104 GLsizei getTransformFeedbackVaryingCount() const;
105 GLsizei getTransformFeedbackVaryingMaxLength() const;
106 GLenum getTransformFeedbackBufferMode() const;
107
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +0000108 void addRef();
109 void release();
110 unsigned int getRefCount() const;
111 void flagForDeletion();
112 bool isFlaggedForDeletion() const;
113
apatrick@chromium.org253b8d22012-06-22 19:27:21 +0000114 void validate();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +0000115 bool isValidated() const;
116
apatrick@chromium.org90080e32012-07-09 22:15:33 +0000117 GLint getProgramBinaryLength() const;
118
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +0000119 private:
120 DISALLOW_COPY_AND_ASSIGN(Program);
121
122 void unlink(bool destroy = false);
shannonwoods@chromium.org70eb1ea2013-05-30 00:07:20 +0000123 void resetUniformBlockBindings();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +0000124
Brandon Jones71620962014-08-20 14:04:59 -0700125 Shader *mFragmentShader;
126 Shader *mVertexShader;
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +0000127
128 AttributeBindings mAttributeBindings;
129
shannonwoods@chromium.org70eb1ea2013-05-30 00:07:20 +0000130 GLuint mUniformBlockBindings[IMPLEMENTATION_MAX_COMBINED_SHADER_UNIFORM_BUFFERS];
131
Geoff Lang48dcae72014-02-05 16:28:24 -0500132 std::vector<std::string> mTransformFeedbackVaryings;
133 GLuint mTransformFeedbackBufferMode;
134
daniel@transgaming.com989c1c82012-07-24 18:40:38 +0000135 BindingPointer<ProgramBinary> mProgramBinary;
daniel@transgaming.com716056c2012-07-24 18:38:59 +0000136 bool mLinked;
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +0000137 bool mDeleteStatus; // Flag to indicate that the program can be deleted when no longer in use
daniel@transgaming.com4fa08332010-05-11 02:29:27 +0000138
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000139 unsigned int mRefCount;
140
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000141 ResourceManager *mResourceManager;
daniel@transgaming.com70062c92012-11-28 19:32:30 +0000142 rx::Renderer *mRenderer;
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000143 const GLuint mHandle;
apatrick@chromium.org253b8d22012-06-22 19:27:21 +0000144
145 InfoLog mInfoLog;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000146};
147}
148
149#endif // LIBGLESV2_PROGRAM_H_