blob: 3e72d86787bcdb269b09bd08a4c0324199a3662d [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);
68
69 GLint getUniformLocation(const char *name);
70 bool setUniform1fv(GLint location, GLsizei count, const GLfloat *v);
71 bool setUniform2fv(GLint location, GLsizei count, const GLfloat *v);
72 bool setUniform3fv(GLint location, GLsizei count, const GLfloat *v);
73 bool setUniform4fv(GLint location, GLsizei count, const GLfloat *v);
74 bool setUniformMatrix2fv(GLint location, GLsizei count, const GLfloat *value);
75 bool setUniformMatrix3fv(GLint location, GLsizei count, const GLfloat *value);
76 bool setUniformMatrix4fv(GLint location, GLsizei count, const GLfloat *value);
77 bool setUniform1iv(GLint location, GLsizei count, const GLint *v);
78
79 void applyUniforms();
daniel@transgaming.comfab5a1a2010-03-11 19:22:30 +000080
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000081 void link();
82 bool isLinked();
83
84 void flagForDeletion();
85 bool isFlaggedForDeletion() const;
86
87 private:
88 DISALLOW_COPY_AND_ASSIGN(Program);
89
90 ID3DXBuffer *compileToBinary(const char *hlsl, const char *profile, ID3DXConstantTable **constantTable);
91 void unlink(bool destroy = false);
92
93 bool linkAttributes();
daniel@transgaming.com86487c22010-03-11 19:41:43 +000094 bool linkUniforms(ID3DXConstantTable *constantTable);
95 bool defineUniform(const D3DXHANDLE &constantHandle, const D3DXCONSTANT_DESC &constantDescription, std::string name = "");
96 bool defineUniform(const D3DXCONSTANT_DESC &constantDescription, std::string &name);
97 Uniform *createUniform(const D3DXCONSTANT_DESC &constantDescription, std::string &name);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000098 bool applyUniform1fv(GLint location, GLsizei count, const GLfloat *v);
99 bool applyUniform2fv(GLint location, GLsizei count, const GLfloat *v);
100 bool applyUniform3fv(GLint location, GLsizei count, const GLfloat *v);
101 bool applyUniform4fv(GLint location, GLsizei count, const GLfloat *v);
102 bool applyUniformMatrix2fv(GLint location, GLsizei count, const GLfloat *value);
103 bool applyUniformMatrix3fv(GLint location, GLsizei count, const GLfloat *value);
104 bool applyUniformMatrix4fv(GLint location, GLsizei count, const GLfloat *value);
105 bool applyUniform1iv(GLint location, GLsizei count, const GLint *v);
106
107 FragmentShader *mFragmentShader;
108 VertexShader *mVertexShader;
109
110 IDirect3DPixelShader9 *mPixelExecutable;
111 IDirect3DVertexShader9 *mVertexExecutable;
112 ID3DXConstantTable *mConstantTablePS;
113 ID3DXConstantTable *mConstantTableVS;
114
115 char *mAttributeName[MAX_VERTEX_ATTRIBS];
116 int mInputMapping[MAX_VERTEX_ATTRIBS];
117
118 GLint mSamplerMapping[MAX_TEXTURE_IMAGE_UNITS];
119
120 typedef std::vector<Uniform*> UniformArray;
121 UniformArray mUniforms;
122
123 bool mLinked;
124 bool mDeleteStatus; // Flag to indicate that the program can be deleted when no longer in use
125};
126}
127
128#endif // LIBGLESV2_PROGRAM_H_