blob: 86f85fb70e48d08e97ac01c5e20de8edb0dd928c [file] [log] [blame]
Jason Sams326e0dd2009-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 Samsc460e552009-11-25 13:22:07 -080028class ShaderCache;
Jason Sams326e0dd2009-05-22 14:03:28 -070029
30class Program : public ObjectBase
31{
32public:
Jason Samsc460e552009-11-25 13:22:07 -080033 const static uint32_t MAX_ATTRIBS = 8;
34 const static uint32_t MAX_UNIFORMS = 16;
Jason Sams7dad9c32009-12-17 16:55:08 -080035 const static uint32_t MAX_TEXTURE = 2;
Jason Samsc460e552009-11-25 13:22:07 -080036
Jason Sams4815c0d2009-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 Sams326e0dd2009-05-22 14:03:28 -070040 virtual ~Program();
41
Jason Sams9ebb0c42010-01-12 12:12:28 -080042 void bindAllocation(Allocation *, uint32_t slot);
Jason Samsc460e552009-11-25 13:22:07 -080043 virtual void createShader();
44
Jason Sams433eca32010-01-06 11:57:52 -080045 bool isUserProgram() const {return mUserShader.size() > 0;}
46
Jason Sams7dad9c32009-12-17 16:55:08 -080047 void bindTexture(uint32_t slot, Allocation *);
48 void bindSampler(uint32_t slot, Sampler *);
49
Jason Samsc460e552009-11-25 13:22:07 -080050 uint32_t getShaderID() const {return mShaderID;}
Jason Samsf2a5d732009-11-30 14:49:55 -080051 void setShader(const char *, uint32_t len);
Jason Samsc460e552009-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 Samscfb1d112009-08-05 13:57:03 -070057
Jason Samsb4d35682010-01-04 16:52:27 -080058 String8 getGLSLInputString() const;
59 String8 getGLSLOutputString() const;
60 String8 getGLSLConstantString() const;
61
Jason Samsa2cf7552010-03-03 13:03:18 -080062 bool isValid() const {return mIsValid;}
63
Jason Sams326e0dd2009-05-22 14:03:28 -070064protected:
65 // Components not listed in "in" will be passed though
66 // unless overwritten by components in out.
Jason Sams4815c0d2009-12-15 12:58:36 -080067 ObjectBaseRef<Element> *mInputElements;
68 ObjectBaseRef<Element> *mOutputElements;
69 ObjectBaseRef<Type> *mConstantTypes;
70 uint32_t mInputCount;
71 uint32_t mOutputCount;
72 uint32_t mConstantCount;
Jason Samsa2cf7552010-03-03 13:03:18 -080073 bool mIsValid;
Jason Sams326e0dd2009-05-22 14:03:28 -070074
Jason Sams9ebb0c42010-01-12 12:12:28 -080075 ObjectBaseRef<Allocation> mConstants[MAX_UNIFORMS];
Jason Sams326e0dd2009-05-22 14:03:28 -070076
Jason Samscfb1d112009-08-05 13:57:03 -070077 mutable bool mDirty;
Jason Samsc460e552009-11-25 13:22:07 -080078 String8 mShader;
Jason Samsf2a5d732009-11-30 14:49:55 -080079 String8 mUserShader;
Jason Samsc460e552009-11-25 13:22:07 -080080 uint32_t mShaderID;
Jason Samsc2f94902009-10-15 18:45:45 -070081
Jason Samsf2e4fa22009-12-15 13:27:04 -080082 uint32_t mTextureCount;
Jason Samsc460e552009-11-25 13:22:07 -080083 uint32_t mAttribCount;
84 uint32_t mUniformCount;
85 String8 mAttribNames[MAX_ATTRIBS];
86 String8 mUniformNames[MAX_UNIFORMS];
87
Jason Sams7dad9c32009-12-17 16:55:08 -080088 // The difference between Textures and Constants is how they are accessed
89 // Texture lookups go though a sampler which in effect converts normalized
90 // coordinates into type specific. Multiple samples may also be taken
91 // and filtered.
92 //
93 // Constants are strictly accessed by programetic loads.
94 ObjectBaseRef<Allocation> mTextures[MAX_TEXTURE];
95 ObjectBaseRef<Sampler> mSamplers[MAX_TEXTURE];
96
Jason Samscd506532009-12-15 19:10:11 -080097 bool loadShader(Context *, uint32_t type);
Jason Samsc2f94902009-10-15 18:45:45 -070098
99public:
Jason Sams5c3e3bc2009-10-26 15:19:28 -0700100 void forceDirty() const {mDirty = true;}
Jason Sams326e0dd2009-05-22 14:03:28 -0700101};
102
103
104
105}
106}
107#endif
108
109
110