blob: 7e848591cf1fcd7e3e9f42d723f264120beaa0b8 [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;
shannon.woods@transgaming.com486d9e92013-02-28 23:15:41 +000029class Shader;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000030
apatrick@chromium.org253b8d22012-06-22 19:27:21 +000031extern const char * const g_fakepath;
32
apatrick@chromium.org9a30b092012-06-06 20:21:55 +000033class AttributeBindings
34{
35 public:
36 AttributeBindings();
37 ~AttributeBindings();
38
39 void bindAttributeLocation(GLuint index, const char *name);
40 int getAttributeBinding(const std::string &name) const;
41
42 private:
43 std::set<std::string> mAttributeBinding[MAX_VERTEX_ATTRIBS];
44};
45
apatrick@chromium.org253b8d22012-06-22 19:27:21 +000046class InfoLog
47{
48 public:
49 InfoLog();
50 ~InfoLog();
51
52 int getLength() const;
53 void getLog(GLsizei bufSize, GLsizei *length, char *infoLog);
54
55 void appendSanitized(const char *message);
56 void append(const char *info, ...);
57 void reset();
58 private:
59 DISALLOW_COPY_AND_ASSIGN(InfoLog);
60 char *mInfoLog;
61};
62
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +000063class Program
64{
65 public:
daniel@transgaming.com70062c92012-11-28 19:32:30 +000066 Program(rx::Renderer *renderer, ResourceManager *manager, GLuint handle);
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +000067
68 ~Program();
69
70 bool attachShader(Shader *shader);
71 bool detachShader(Shader *shader);
72 int getAttachedShadersCount() const;
73
74 void bindAttributeLocation(GLuint index, const char *name);
75
daniel@transgaming.com4c962bf2012-07-24 18:37:02 +000076 bool link();
daniel@transgaming.com716056c2012-07-24 18:38:59 +000077 bool isLinked();
Geoff Lang900013c2014-07-07 11:32:19 -040078 bool setProgramBinary(GLenum binaryFormat, const void *binary, GLsizei length);
Geoff Lang48dcae72014-02-05 16:28:24 -050079 ProgramBinary *getProgramBinary() const;
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +000080
81 int getInfoLogLength() const;
82 void getInfoLog(GLsizei bufSize, GLsizei *length, char *infoLog);
83 void getAttachedShaders(GLsizei maxCount, GLsizei *count, GLuint *shaders);
84
85 void getActiveAttribute(GLuint index, GLsizei bufsize, GLsizei *length, GLint *size, GLenum *type, GLchar *name);
86 GLint getActiveAttributeCount();
87 GLint getActiveAttributeMaxLength();
88
89 void getActiveUniform(GLuint index, GLsizei bufsize, GLsizei *length, GLint *size, GLenum *type, GLchar *name);
90 GLint getActiveUniformCount();
91 GLint getActiveUniformMaxLength();
92
shannonwoods@chromium.orge684b582013-05-30 00:07:42 +000093 GLint getActiveUniformBlockCount();
94 GLint getActiveUniformBlockMaxLength();
95
shannonwoods@chromium.org70eb1ea2013-05-30 00:07:20 +000096 void bindUniformBlock(GLuint uniformBlockIndex, GLuint uniformBlockBinding);
97 GLuint getUniformBlockBinding(GLuint uniformBlockIndex) const;
98
Geoff Lang48dcae72014-02-05 16:28:24 -050099 void setTransformFeedbackVaryings(GLsizei count, const GLchar *const *varyings, GLenum bufferMode);
100 void getTransformFeedbackVarying(GLuint index, GLsizei bufSize, GLsizei *length, GLsizei *size, GLenum *type, GLchar *name) const;
Geoff Lang1b6edcb2014-02-03 14:27:56 -0500101 GLsizei getTransformFeedbackVaryingCount() const;
102 GLsizei getTransformFeedbackVaryingMaxLength() const;
103 GLenum getTransformFeedbackBufferMode() const;
104
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +0000105 void addRef();
106 void release();
107 unsigned int getRefCount() const;
108 void flagForDeletion();
109 bool isFlaggedForDeletion() const;
110
apatrick@chromium.org253b8d22012-06-22 19:27:21 +0000111 void validate();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +0000112 bool isValidated() const;
113
apatrick@chromium.org90080e32012-07-09 22:15:33 +0000114 GLint getProgramBinaryLength() const;
115
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +0000116 private:
117 DISALLOW_COPY_AND_ASSIGN(Program);
118
119 void unlink(bool destroy = false);
shannonwoods@chromium.org70eb1ea2013-05-30 00:07:20 +0000120 void resetUniformBlockBindings();
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +0000121
Brandon Jones71620962014-08-20 14:04:59 -0700122 Shader *mFragmentShader;
123 Shader *mVertexShader;
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +0000124
125 AttributeBindings mAttributeBindings;
126
shannonwoods@chromium.org70eb1ea2013-05-30 00:07:20 +0000127 GLuint mUniformBlockBindings[IMPLEMENTATION_MAX_COMBINED_SHADER_UNIFORM_BUFFERS];
128
Geoff Lang48dcae72014-02-05 16:28:24 -0500129 std::vector<std::string> mTransformFeedbackVaryings;
130 GLuint mTransformFeedbackBufferMode;
131
daniel@transgaming.com989c1c82012-07-24 18:40:38 +0000132 BindingPointer<ProgramBinary> mProgramBinary;
daniel@transgaming.com716056c2012-07-24 18:38:59 +0000133 bool mLinked;
apatrick@chromium.orge2a59bb2012-06-07 21:09:53 +0000134 bool mDeleteStatus; // Flag to indicate that the program can be deleted when no longer in use
daniel@transgaming.com4fa08332010-05-11 02:29:27 +0000135
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000136 unsigned int mRefCount;
137
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000138 ResourceManager *mResourceManager;
daniel@transgaming.com70062c92012-11-28 19:32:30 +0000139 rx::Renderer *mRenderer;
daniel@transgaming.comda13f3e2010-07-28 19:20:56 +0000140 const GLuint mHandle;
apatrick@chromium.org253b8d22012-06-22 19:27:21 +0000141
142 InfoLog mInfoLog;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000143};
144}
145
146#endif // LIBGLESV2_PROGRAM_H_