blob: 6528dd1191462355a43a03d0ec45f7c75c312913 [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{
Brandon Jones43a53e22014-08-28 16:23:22 -070031struct Caps;
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +000032class ResourceManager;
shannon.woods@transgaming.com486d9e92013-02-28 23:15:41 +000033class Shader;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000034
apatrick@chromium.org253b8d22012-06-22 19:27:21 +000035extern const char * const g_fakepath;
36
apatrick@chromium.org9a30b092012-06-06 20:21:55 +000037class AttributeBindings
38{
39 public:
40 AttributeBindings();
41 ~AttributeBindings();
42
43 void bindAttributeLocation(GLuint index, const char *name);
44 int getAttributeBinding(const std::string &name) const;
45
46 private:
47 std::set<std::string> mAttributeBinding[MAX_VERTEX_ATTRIBS];
48};
49
apatrick@chromium.org253b8d22012-06-22 19:27:21 +000050class InfoLog
51{
52 public:
53 InfoLog();
54 ~InfoLog();
55
56 int getLength() const;
57 void getLog(GLsizei bufSize, GLsizei *length, char *infoLog);
58
59 void appendSanitized(const char *message);
60 void append(const char *info, ...);
61 void reset();
62 private:
63 DISALLOW_COPY_AND_ASSIGN(InfoLog);
64 char *mInfoLog;
65};
66
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +000067class Program
68{
69 public:
daniel@transgaming.com70062c92012-11-28 19:32:30 +000070 Program(rx::Renderer *renderer, ResourceManager *manager, GLuint handle);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +000071
72 ~Program();
73
74 bool attachShader(Shader *shader);
75 bool detachShader(Shader *shader);
76 int getAttachedShadersCount() const;
77
78 void bindAttributeLocation(GLuint index, const char *name);
79
Brandon Jones43a53e22014-08-28 16:23:22 -070080 bool link(const Caps &caps);
daniel@transgaming.com716056c2012-07-24 18:38:59 +000081 bool isLinked();
Geoff Lang900013c2014-07-07 11:32:19 -040082 bool setProgramBinary(GLenum binaryFormat, const void *binary, GLsizei length);
Geoff Lang48dcae72014-02-05 16:28:24 -050083 ProgramBinary *getProgramBinary() const;
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +000084
85 int getInfoLogLength() const;
86 void getInfoLog(GLsizei bufSize, GLsizei *length, char *infoLog);
87 void getAttachedShaders(GLsizei maxCount, GLsizei *count, GLuint *shaders);
88
89 void getActiveAttribute(GLuint index, GLsizei bufsize, GLsizei *length, GLint *size, GLenum *type, GLchar *name);
90 GLint getActiveAttributeCount();
91 GLint getActiveAttributeMaxLength();
92
93 void getActiveUniform(GLuint index, GLsizei bufsize, GLsizei *length, GLint *size, GLenum *type, GLchar *name);
94 GLint getActiveUniformCount();
95 GLint getActiveUniformMaxLength();
96
shannonwoods@chromium.orge684b582013-05-30 00:07:42 +000097 GLint getActiveUniformBlockCount();
98 GLint getActiveUniformBlockMaxLength();
99
shannonwoods@chromium.org70eb1ea2013-05-30 00:07:20 +0000100 void bindUniformBlock(GLuint uniformBlockIndex, GLuint uniformBlockBinding);
101 GLuint getUniformBlockBinding(GLuint uniformBlockIndex) const;
102
Geoff Lang48dcae72014-02-05 16:28:24 -0500103 void setTransformFeedbackVaryings(GLsizei count, const GLchar *const *varyings, GLenum bufferMode);
104 void getTransformFeedbackVarying(GLuint index, GLsizei bufSize, GLsizei *length, GLsizei *size, GLenum *type, GLchar *name) const;
Geoff Lang1b6edcb2014-02-03 14:27:56 -0500105 GLsizei getTransformFeedbackVaryingCount() const;
106 GLsizei getTransformFeedbackVaryingMaxLength() const;
107 GLenum getTransformFeedbackBufferMode() const;
108
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +0000109 void addRef();
110 void release();
111 unsigned int getRefCount() const;
112 void flagForDeletion();
113 bool isFlaggedForDeletion() const;
114
Brandon Jones43a53e22014-08-28 16:23:22 -0700115 void validate(const Caps &caps);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +0000116 bool isValidated() const;
117
apatrick@chromium.org90080e32012-07-09 22:15:33 +0000118 GLint getProgramBinaryLength() const;
119
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +0000120 private:
121 DISALLOW_COPY_AND_ASSIGN(Program);
122
123 void unlink(bool destroy = false);
shannonwoods@chromium.org70eb1ea2013-05-30 00:07:20 +0000124 void resetUniformBlockBindings();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +0000125
Brandon Jones71620962014-08-20 14:04:59 -0700126 Shader *mFragmentShader;
127 Shader *mVertexShader;
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +0000128
129 AttributeBindings mAttributeBindings;
130
shannonwoods@chromium.org70eb1ea2013-05-30 00:07:20 +0000131 GLuint mUniformBlockBindings[IMPLEMENTATION_MAX_COMBINED_SHADER_UNIFORM_BUFFERS];
132
Geoff Lang48dcae72014-02-05 16:28:24 -0500133 std::vector<std::string> mTransformFeedbackVaryings;
134 GLuint mTransformFeedbackBufferMode;
135
daniel@transgaming.com989c1c82012-07-24 18:40:38 +0000136 BindingPointer<ProgramBinary> mProgramBinary;
daniel@transgaming.com716056c2012-07-24 18:38:59 +0000137 bool mLinked;
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +0000138 bool mDeleteStatus; // Flag to indicate that the program can be deleted when no longer in use
daniel@transgaming.com4fa08332010-05-11 02:29:27 +0000139
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000140 unsigned int mRefCount;
141
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000142 ResourceManager *mResourceManager;
daniel@transgaming.com70062c92012-11-28 19:32:30 +0000143 rx::Renderer *mRenderer;
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000144 const GLuint mHandle;
apatrick@chromium.org253b8d22012-06-22 19:27:21 +0000145
146 InfoLog mInfoLog;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000147};
148}
149
150#endif // LIBGLESV2_PROGRAM_H_