blob: ab91522828ea27d2cf1b5486890de5748bcb1a7a [file] [log] [blame]
apatrick@chromium.orgea09f9b2012-06-08 00:45:32 +00001//
2// Copyright (c) 2002-2012 The ANGLE Project Authors. All rights reserved.
3// 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_BINARY_H_
11#define LIBGLESV2_PROGRAM_BINARY_H_
12
apatrick@chromium.org90080e32012-07-09 22:15:33 +000013#define GL_APICALL
daniel@transgaming.com29ab9522012-08-27 16:25:37 +000014#include <GLES2/gl2.h>
15#include <GLES2/gl2ext.h>
apatrick@chromium.org90080e32012-07-09 22:15:33 +000016
apatrick@chromium.orgea09f9b2012-06-08 00:45:32 +000017#include <string>
18#include <vector>
19
daniel@transgaming.com4a186ed2012-11-28 20:56:15 +000020#include "libGLESv2/Program.h"
apatrick@chromium.orgea09f9b2012-06-08 00:45:32 +000021#include "libGLESv2/Context.h"
apatrick@chromium.org60dafe82012-09-05 22:26:10 +000022#include "libGLESv2/mathutil.h"
23#include "libGLESv2/Shader.h"
daniel@transgaming.com15186aa2012-12-20 21:08:23 +000024#include "libGLESv2/Uniform.h"
apatrick@chromium.orgea09f9b2012-06-08 00:45:32 +000025
daniel@transgaming.com4f0f65e2012-11-28 21:00:00 +000026#include "libGLESv2/renderer/ShaderExecutable.h"
daniel@transgaming.coma9c71422012-11-28 20:58:45 +000027
apatrick@chromium.orgea09f9b2012-06-08 00:45:32 +000028namespace gl
29{
30class FragmentShader;
31class VertexShader;
32
apatrick@chromium.orgea09f9b2012-06-08 00:45:32 +000033// Struct used for correlating uniforms/elements of uniform arrays to handles
34struct UniformLocation
35{
apatrick@chromium.org90080e32012-07-09 22:15:33 +000036 UniformLocation()
37 {
38 }
39
daniel@transgaming.comdb019952012-12-20 21:13:32 +000040 UniformLocation(const std::string &name, unsigned int element, unsigned int index);
apatrick@chromium.orgea09f9b2012-06-08 00:45:32 +000041
42 std::string name;
43 unsigned int element;
44 unsigned int index;
45};
46
47// This is the result of linking a program. It is the state that would be passed to ProgramBinary.
daniel@transgaming.com989c1c82012-07-24 18:40:38 +000048class ProgramBinary : public RefCountObject
apatrick@chromium.orgea09f9b2012-06-08 00:45:32 +000049{
50 public:
daniel@transgaming.com70062c92012-11-28 19:32:30 +000051 explicit ProgramBinary(rx::Renderer *renderer);
apatrick@chromium.orgea09f9b2012-06-08 00:45:32 +000052 ~ProgramBinary();
53
daniel@transgaming.com95892412012-11-28 20:59:09 +000054 rx::ShaderExecutable *getPixelExecutable();
55 rx::ShaderExecutable *getVertexExecutable();
apatrick@chromium.orgea09f9b2012-06-08 00:45:32 +000056
57 GLuint getAttributeLocation(const char *name);
58 int getSemanticIndex(int attributeIndex);
59
60 GLint getSamplerMapping(SamplerType type, unsigned int samplerIndex);
61 TextureType getSamplerTextureType(SamplerType type, unsigned int samplerIndex);
62 GLint getUsedSamplerRange(SamplerType type);
daniel@transgaming.com087e5782012-09-17 21:28:47 +000063 bool usesPointSize() const;
apatrick@chromium.orgea09f9b2012-06-08 00:45:32 +000064
65 GLint getUniformLocation(std::string name);
66 bool setUniform1fv(GLint location, GLsizei count, const GLfloat *v);
67 bool setUniform2fv(GLint location, GLsizei count, const GLfloat *v);
68 bool setUniform3fv(GLint location, GLsizei count, const GLfloat *v);
69 bool setUniform4fv(GLint location, GLsizei count, const GLfloat *v);
70 bool setUniformMatrix2fv(GLint location, GLsizei count, const GLfloat *value);
71 bool setUniformMatrix3fv(GLint location, GLsizei count, const GLfloat *value);
72 bool setUniformMatrix4fv(GLint location, GLsizei count, const GLfloat *value);
73 bool setUniform1iv(GLint location, GLsizei count, const GLint *v);
74 bool setUniform2iv(GLint location, GLsizei count, const GLint *v);
75 bool setUniform3iv(GLint location, GLsizei count, const GLint *v);
76 bool setUniform4iv(GLint location, GLsizei count, const GLint *v);
77
78 bool getUniformfv(GLint location, GLsizei *bufSize, GLfloat *params);
79 bool getUniformiv(GLint location, GLsizei *bufSize, GLint *params);
80
apatrick@chromium.orgea09f9b2012-06-08 00:45:32 +000081 void dirtyAllUniforms();
82 void applyUniforms();
83
apatrick@chromium.org90080e32012-07-09 22:15:33 +000084 bool load(InfoLog &infoLog, const void *binary, GLsizei length);
85 bool save(void* binary, GLsizei bufSize, GLsizei *length);
86 GLint getLength();
87
apatrick@chromium.org253b8d22012-06-22 19:27:21 +000088 bool link(InfoLog &infoLog, const AttributeBindings &attributeBindings, FragmentShader *fragmentShader, VertexShader *vertexShader);
apatrick@chromium.orgea09f9b2012-06-08 00:45:32 +000089 void getAttachedShaders(GLsizei maxCount, GLsizei *count, GLuint *shaders);
90
91 void getActiveAttribute(GLuint index, GLsizei bufsize, GLsizei *length, GLint *size, GLenum *type, GLchar *name);
92 GLint getActiveAttributeCount();
93 GLint getActiveAttributeMaxLength();
94
95 void getActiveUniform(GLuint index, GLsizei bufsize, GLsizei *length, GLint *size, GLenum *type, GLchar *name);
96 GLint getActiveUniformCount();
97 GLint getActiveUniformMaxLength();
98
apatrick@chromium.org253b8d22012-06-22 19:27:21 +000099 void validate(InfoLog &infoLog);
100 bool validateSamplers(InfoLog *infoLog);
apatrick@chromium.orgea09f9b2012-06-08 00:45:32 +0000101 bool isValidated() const;
102
daniel@transgaming.come87ca002012-07-24 18:30:43 +0000103 unsigned int getSerial() const;
104
apatrick@chromium.orgea09f9b2012-06-08 00:45:32 +0000105 static std::string decorateAttribute(const std::string &name); // Prepend an underscore
apatrick@chromium.orgea09f9b2012-06-08 00:45:32 +0000106
107 private:
108 DISALLOW_COPY_AND_ASSIGN(ProgramBinary);
109
apatrick@chromium.org253b8d22012-06-22 19:27:21 +0000110 int packVaryings(InfoLog &infoLog, const Varying *packing[][4], FragmentShader *fragmentShader);
111 bool linkVaryings(InfoLog &infoLog, std::string& pixelHLSL, std::string& vertexHLSL, FragmentShader *fragmentShader, VertexShader *vertexShader);
apatrick@chromium.orgea09f9b2012-06-08 00:45:32 +0000112
apatrick@chromium.org253b8d22012-06-22 19:27:21 +0000113 bool linkAttributes(InfoLog &infoLog, const AttributeBindings &attributeBindings, FragmentShader *fragmentShader, VertexShader *vertexShader);
apatrick@chromium.orgea09f9b2012-06-08 00:45:32 +0000114
daniel@transgaming.com68aaf932012-12-20 21:13:16 +0000115 bool linkUniforms(InfoLog &infoLog, const sh::ActiveUniforms &vertexUniforms, const sh::ActiveUniforms &fragmentUniforms);
daniel@transgaming.comda8d3802012-12-20 21:12:55 +0000116 bool defineUniform(GLenum shader, const sh::Uniform &constant, InfoLog &infoLog);
daniel@transgaming.comb6e55102012-12-20 21:08:14 +0000117
daniel@transgaming.com77fbf972012-11-28 21:02:55 +0000118 rx::Renderer *const mRenderer;
apatrick@chromium.orgea09f9b2012-06-08 00:45:32 +0000119
daniel@transgaming.com4f0f65e2012-11-28 21:00:00 +0000120 rx::ShaderExecutable *mPixelExecutable;
121 rx::ShaderExecutable *mVertexExecutable;
apatrick@chromium.orgea09f9b2012-06-08 00:45:32 +0000122
apatrick@chromium.orgea09f9b2012-06-08 00:45:32 +0000123 Attribute mLinkedAttribute[MAX_VERTEX_ATTRIBS];
124 int mSemanticIndex[MAX_VERTEX_ATTRIBS];
125
126 struct Sampler
127 {
apatrick@chromium.org90080e32012-07-09 22:15:33 +0000128 Sampler();
129
apatrick@chromium.orgea09f9b2012-06-08 00:45:32 +0000130 bool active;
131 GLint logicalTextureUnit;
132 TextureType textureType;
133 };
134
135 Sampler mSamplersPS[MAX_TEXTURE_IMAGE_UNITS];
shannon.woods@transgaming.com233fe952013-01-25 21:51:57 +0000136 Sampler mSamplersVS[IMPLEMENTATION_MAX_VERTEX_TEXTURE_IMAGE_UNITS];
apatrick@chromium.orgea09f9b2012-06-08 00:45:32 +0000137 GLuint mUsedVertexSamplerRange;
138 GLuint mUsedPixelSamplerRange;
daniel@transgaming.com087e5782012-09-17 21:28:47 +0000139 bool mUsesPointSize;
apatrick@chromium.orgea09f9b2012-06-08 00:45:32 +0000140
apatrick@chromium.orgea09f9b2012-06-08 00:45:32 +0000141 UniformArray mUniforms;
142 typedef std::vector<UniformLocation> UniformIndex;
143 UniformIndex mUniformIndex;
144
apatrick@chromium.orgea09f9b2012-06-08 00:45:32 +0000145 bool mValidated;
daniel@transgaming.come87ca002012-07-24 18:30:43 +0000146
147 const unsigned int mSerial;
148
149 static unsigned int issueSerial();
150 static unsigned int mCurrentSerial;
apatrick@chromium.orgea09f9b2012-06-08 00:45:32 +0000151};
152}
153
154#endif // LIBGLESV2_PROGRAM_BINARY_H_