blob: 157e36e65ff60861e80555e18ef9c818661b56b4 [file] [log] [blame]
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001//
2// Copyright (c) 2002-2010 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_H_
11#define LIBGLESV2_PROGRAM_H_
12
13#include "Context.h"
14
15#include <d3dx9.h>
16#include <string>
17#include <vector>
18
19namespace gl
20{
21class FragmentShader;
22class VertexShader;
23
24enum UniformType
25{
26 UNIFORM_1FV,
27 UNIFORM_2FV,
28 UNIFORM_3FV,
29 UNIFORM_4FV,
30 UNIFORM_MATRIX_2FV,
31 UNIFORM_MATRIX_3FV,
32 UNIFORM_MATRIX_4FV,
33 UNIFORM_1IV
34};
35
daniel@transgaming.com86487c22010-03-11 19:41:43 +000036// Helper struct representing a single shader uniform
37struct Uniform
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000038{
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000039 Uniform(UniformType type, const std::string &name, unsigned int bytes);
40
41 ~Uniform();
42
43 const UniformType type;
44 const std::string name;
45 const unsigned int bytes;
46 unsigned char *data;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000047};
48
49class Program
50{
51 public:
52 Program();
53
54 ~Program();
55
56 bool attachShader(Shader *shader);
57 bool detachShader(Shader *shader);
58
59 IDirect3DPixelShader9 *getPixelShader();
60 IDirect3DVertexShader9 *getVertexShader();
61
62 void bindAttributeLocation(GLuint index, const char *name);
63 GLuint getAttributeLocation(const char *name);
64 bool isActiveAttribute(int attributeIndex);
65 int getInputMapping(int attributeIndex);
66
67 GLint getSamplerMapping(unsigned int samplerIndex);
daniel@transgaming.com416485f2010-03-16 06:23:23 +000068 SamplerType getSamplerType(unsigned int samplerIndex);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000069
70 GLint getUniformLocation(const char *name);
71 bool setUniform1fv(GLint location, GLsizei count, const GLfloat *v);
72 bool setUniform2fv(GLint location, GLsizei count, const GLfloat *v);
73 bool setUniform3fv(GLint location, GLsizei count, const GLfloat *v);
74 bool setUniform4fv(GLint location, GLsizei count, const GLfloat *v);
75 bool setUniformMatrix2fv(GLint location, GLsizei count, const GLfloat *value);
76 bool setUniformMatrix3fv(GLint location, GLsizei count, const GLfloat *value);
77 bool setUniformMatrix4fv(GLint location, GLsizei count, const GLfloat *value);
78 bool setUniform1iv(GLint location, GLsizei count, const GLint *v);
79
80 void applyUniforms();
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +000081
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000082 void link();
83 bool isLinked();
84
85 void flagForDeletion();
86 bool isFlaggedForDeletion() const;
87
88 private:
89 DISALLOW_COPY_AND_ASSIGN(Program);
90
91 ID3DXBuffer *compileToBinary(const char *hlsl, const char *profile, ID3DXConstantTable **constantTable);
92 void unlink(bool destroy = false);
93
94 bool linkAttributes();
daniel@transgaming.com86487c22010-03-11 19:41:43 +000095 bool linkUniforms(ID3DXConstantTable *constantTable);
96 bool defineUniform(const D3DXHANDLE &constantHandle, const D3DXCONSTANT_DESC &constantDescription, std::string name = "");
97 bool defineUniform(const D3DXCONSTANT_DESC &constantDescription, std::string &name);
98 Uniform *createUniform(const D3DXCONSTANT_DESC &constantDescription, std::string &name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000099 bool applyUniform1fv(GLint location, GLsizei count, const GLfloat *v);
100 bool applyUniform2fv(GLint location, GLsizei count, const GLfloat *v);
101 bool applyUniform3fv(GLint location, GLsizei count, const GLfloat *v);
102 bool applyUniform4fv(GLint location, GLsizei count, const GLfloat *v);
103 bool applyUniformMatrix2fv(GLint location, GLsizei count, const GLfloat *value);
104 bool applyUniformMatrix3fv(GLint location, GLsizei count, const GLfloat *value);
105 bool applyUniformMatrix4fv(GLint location, GLsizei count, const GLfloat *value);
106 bool applyUniform1iv(GLint location, GLsizei count, const GLint *v);
107
108 FragmentShader *mFragmentShader;
109 VertexShader *mVertexShader;
110
111 IDirect3DPixelShader9 *mPixelExecutable;
112 IDirect3DVertexShader9 *mVertexExecutable;
113 ID3DXConstantTable *mConstantTablePS;
114 ID3DXConstantTable *mConstantTableVS;
115
116 char *mAttributeName[MAX_VERTEX_ATTRIBS];
117 int mInputMapping[MAX_VERTEX_ATTRIBS];
118
daniel@transgaming.com416485f2010-03-16 06:23:23 +0000119 struct Sampler
120 {
121 bool active;
122 GLint logicalTextureUnit;
123 SamplerType type;
124 };
125
126 Sampler mSamplers[MAX_TEXTURE_IMAGE_UNITS];
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000127
128 typedef std::vector<Uniform*> UniformArray;
129 UniformArray mUniforms;
130
131 bool mLinked;
132 bool mDeleteStatus; // Flag to indicate that the program can be deleted when no longer in use
133};
134}
135
136#endif // LIBGLESV2_PROGRAM_H_