blob: a34e89fa40ffd9c01eeb46127fb1ce3072b1a277 [file] [log] [blame]
Jason Samsd19f10d2009-05-22 14:03:28 -07001/*
2 * Copyright (C) 2009 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_RS_PROGRAM_H
18#define ANDROID_RS_PROGRAM_H
19
20#include "rsObjectBase.h"
21#include "rsElement.h"
22
23// ---------------------------------------------------------------------------
24namespace android {
25namespace renderscript {
26
27
Jason Samsbb51c402009-11-25 13:22:07 -080028class ShaderCache;
Jason Samsd19f10d2009-05-22 14:03:28 -070029
30class Program : public ObjectBase
31{
32public:
Jason Samsbb51c402009-11-25 13:22:07 -080033 const static uint32_t MAX_ATTRIBS = 8;
34 const static uint32_t MAX_UNIFORMS = 16;
Jason Sams68afd012009-12-17 16:55:08 -080035 const static uint32_t MAX_TEXTURE = 2;
Jason Samsbb51c402009-11-25 13:22:07 -080036
Jason Sams0011bcf2009-12-15 12:58:36 -080037 Program(Context *);
38 Program(Context *, const char * shaderText, uint32_t shaderLength,
39 const uint32_t * params, uint32_t paramLength);
Jason Samsd19f10d2009-05-22 14:03:28 -070040 virtual ~Program();
41
Jason Samsea87e962010-01-12 12:12:28 -080042 void bindAllocation(Allocation *, uint32_t slot);
Jason Samsbb51c402009-11-25 13:22:07 -080043 virtual void createShader();
44
Jason Samsa09a6e12010-01-06 11:57:52 -080045 bool isUserProgram() const {return mUserShader.size() > 0;}
46
Jason Sams68afd012009-12-17 16:55:08 -080047 void bindTexture(uint32_t slot, Allocation *);
48 void bindSampler(uint32_t slot, Sampler *);
49
Jason Samsbb51c402009-11-25 13:22:07 -080050 uint32_t getShaderID() const {return mShaderID;}
Jason Sams54c0ec12009-11-30 14:49:55 -080051 void setShader(const char *, uint32_t len);
Jason Samsbb51c402009-11-25 13:22:07 -080052
53 uint32_t getAttribCount() const {return mAttribCount;}
54 uint32_t getUniformCount() const {return mUniformCount;}
55 const String8 & getAttribName(uint32_t i) const {return mAttribNames[i];}
56 const String8 & getUniformName(uint32_t i) const {return mUniformNames[i];}
Jason Sams9bee51c2009-08-05 13:57:03 -070057
Jason Samse17964e2010-01-04 16:52:27 -080058 String8 getGLSLInputString() const;
59 String8 getGLSLOutputString() const;
60 String8 getGLSLConstantString() const;
61
Jason Samsd19f10d2009-05-22 14:03:28 -070062protected:
63 // Components not listed in "in" will be passed though
64 // unless overwritten by components in out.
Jason Sams0011bcf2009-12-15 12:58:36 -080065 ObjectBaseRef<Element> *mInputElements;
66 ObjectBaseRef<Element> *mOutputElements;
67 ObjectBaseRef<Type> *mConstantTypes;
68 uint32_t mInputCount;
69 uint32_t mOutputCount;
70 uint32_t mConstantCount;
Jason Samsd19f10d2009-05-22 14:03:28 -070071
Jason Samsea87e962010-01-12 12:12:28 -080072 ObjectBaseRef<Allocation> mConstants[MAX_UNIFORMS];
Jason Samsd19f10d2009-05-22 14:03:28 -070073
Jason Sams9bee51c2009-08-05 13:57:03 -070074 mutable bool mDirty;
Jason Samsbb51c402009-11-25 13:22:07 -080075 String8 mShader;
Jason Sams54c0ec12009-11-30 14:49:55 -080076 String8 mUserShader;
Jason Samsbb51c402009-11-25 13:22:07 -080077 uint32_t mShaderID;
Jason Sams741a6102009-10-15 18:45:45 -070078
Jason Sams7e5ab3b2009-12-15 13:27:04 -080079 uint32_t mTextureCount;
Jason Samsbb51c402009-11-25 13:22:07 -080080 uint32_t mAttribCount;
81 uint32_t mUniformCount;
82 String8 mAttribNames[MAX_ATTRIBS];
83 String8 mUniformNames[MAX_UNIFORMS];
84
Jason Sams68afd012009-12-17 16:55:08 -080085 // The difference between Textures and Constants is how they are accessed
86 // Texture lookups go though a sampler which in effect converts normalized
87 // coordinates into type specific. Multiple samples may also be taken
88 // and filtered.
89 //
90 // Constants are strictly accessed by programetic loads.
91 ObjectBaseRef<Allocation> mTextures[MAX_TEXTURE];
92 ObjectBaseRef<Sampler> mSamplers[MAX_TEXTURE];
93
Jason Sams5dad8b42009-12-15 19:10:11 -080094 bool loadShader(Context *, uint32_t type);
Jason Sams741a6102009-10-15 18:45:45 -070095
96public:
Jason Sams83f1c632009-10-26 15:19:28 -070097 void forceDirty() const {mDirty = true;}
Jason Samsd19f10d2009-05-22 14:03:28 -070098};
99
100
101
102}
103}
104#endif
105
106
107