blob: 37b1c3d0b496c82cd6c489a4c578b93291feca96 [file] [log] [blame]
Alex Sakhartchouk4a36b452011-04-29 16:49:08 -07001/*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef ANDROID_RSD_SHADER_H
18#define ANDROID_RSD_SHADER_H
19
20#include <utils/String8.h>
21
22// ---------------------------------------------------------------------------
23namespace android {
24namespace renderscript {
25
26class Element;
27class Context;
28class Program;
29
30}
31}
32
33class RsdShaderCache;
34
35#define RS_SHADER_ATTR "ATTRIB_"
36#define RS_SHADER_UNI "UNI_"
37
38class RsdShader {
39public:
40
41 RsdShader(const android::renderscript::Program *p, uint32_t type,
42 const char * shaderText, uint32_t shaderLength);
43 virtual ~RsdShader();
44
45 bool createShader();
46
47 uint32_t getShaderID() const {return mShaderID;}
48
49 uint32_t getAttribCount() const {return mAttribCount;}
50 uint32_t getUniformCount() const {return mUniformCount;}
51 const android::String8 & getAttribName(uint32_t i) const {return mAttribNames[i];}
52 const android::String8 & getUniformName(uint32_t i) const {return mUniformNames[i];}
53 uint32_t getUniformArraySize(uint32_t i) const {return mUniformArraySizes[i];}
54
55 android::String8 getGLSLInputString() const;
56
57 bool isValid() const {return mIsValid;}
58 void forceDirty() const {mDirty = true;}
59
60 bool loadShader(const android::renderscript::Context *);
61 void setup(const android::renderscript::Context *, RsdShaderCache *sc);
62
63protected:
64
65 const android::renderscript::Program *mRSProgram;
66 bool mIsValid;
67
68 // Applies to vertex and fragment shaders only
69 void appendUserConstants();
70 void setupUserConstants(const android::renderscript::Context *rsc, RsdShaderCache *sc, bool isFragment);
71 void initAddUserElement(const android::renderscript::Element *e, android::String8 *names, uint32_t *arrayLengths, uint32_t *count, const char *prefix);
72 void setupTextures(const android::renderscript::Context *rsc, RsdShaderCache *sc);
73
74 void appendAttributes();
75 void appendTextures();
76
77 void initAttribAndUniformArray();
78
79 mutable bool mDirty;
80 android::String8 mShader;
81 android::String8 mUserShader;
82 uint32_t mShaderID;
83 uint32_t mType;
84
85 uint32_t mTextureCount;
86 uint32_t mAttribCount;
87 uint32_t mUniformCount;
88 android::String8 *mAttribNames;
89 android::String8 *mUniformNames;
90 uint32_t *mUniformArraySizes;
91
92 int32_t mTextureUniformIndexStart;
93
94 void logUniform(const android::renderscript::Element *field, const float *fd, uint32_t arraySize );
95 void setUniform(const android::renderscript::Context *rsc, const android::renderscript::Element *field, const float *fd, int32_t slot, uint32_t arraySize );
96 void initMemberVars();
97 void init();
98};
99
100#endif //ANDROID_RSD_SHADER_H
101
102
103
104