blob: d3c85bf5275508c07a7936370409764663c0706e [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
36// Helper class representing a single shader uniform
37class Uniform
38{
39 public:
40 Uniform(UniformType type, const std::string &name, unsigned int bytes);
41
42 ~Uniform();
43
44 const UniformType type;
45 const std::string name;
46 const unsigned int bytes;
47 unsigned char *data;
48
49 private:
50 DISALLOW_COPY_AND_ASSIGN(Uniform);
51};
52
53class Program
54{
55 public:
56 Program();
57
58 ~Program();
59
60 bool attachShader(Shader *shader);
61 bool detachShader(Shader *shader);
62
63 IDirect3DPixelShader9 *getPixelShader();
64 IDirect3DVertexShader9 *getVertexShader();
65
66 void bindAttributeLocation(GLuint index, const char *name);
67 GLuint getAttributeLocation(const char *name);
68 bool isActiveAttribute(int attributeIndex);
69 int getInputMapping(int attributeIndex);
70
71 GLint getSamplerMapping(unsigned int samplerIndex);
72
73 GLint getUniformLocation(const char *name);
74 bool setUniform1fv(GLint location, GLsizei count, const GLfloat *v);
75 bool setUniform2fv(GLint location, GLsizei count, const GLfloat *v);
76 bool setUniform3fv(GLint location, GLsizei count, const GLfloat *v);
77 bool setUniform4fv(GLint location, GLsizei count, const GLfloat *v);
78 bool setUniformMatrix2fv(GLint location, GLsizei count, const GLfloat *value);
79 bool setUniformMatrix3fv(GLint location, GLsizei count, const GLfloat *value);
80 bool setUniformMatrix4fv(GLint location, GLsizei count, const GLfloat *value);
81 bool setUniform1iv(GLint location, GLsizei count, const GLint *v);
82
83 void applyUniforms();
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +000084
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000085 void link();
86 bool isLinked();
87
88 void flagForDeletion();
89 bool isFlaggedForDeletion() const;
90
91 private:
92 DISALLOW_COPY_AND_ASSIGN(Program);
93
94 ID3DXBuffer *compileToBinary(const char *hlsl, const char *profile, ID3DXConstantTable **constantTable);
95 void unlink(bool destroy = false);
96
97 bool linkAttributes();
98 void defineUniform(const D3DXCONSTANT_DESC &constantDescription);
99 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
119 GLint mSamplerMapping[MAX_TEXTURE_IMAGE_UNITS];
120
121 typedef std::vector<Uniform*> UniformArray;
122 UniformArray mUniforms;
123
124 bool mLinked;
125 bool mDeleteStatus; // Flag to indicate that the program can be deleted when no longer in use
126};
127}
128
129#endif // LIBGLESV2_PROGRAM_H_