Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1 | /* |
| 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 | // --------------------------------------------------------------------------- |
| 24 | namespace android { |
| 25 | namespace renderscript { |
| 26 | |
| 27 | |
Jason Sams | bb51c40 | 2009-11-25 13:22:07 -0800 | [diff] [blame] | 28 | class ShaderCache; |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 29 | |
| 30 | class Program : public ObjectBase |
| 31 | { |
| 32 | public: |
Jason Sams | bb51c40 | 2009-11-25 13:22:07 -0800 | [diff] [blame] | 33 | const static uint32_t MAX_ATTRIBS = 8; |
| 34 | const static uint32_t MAX_UNIFORMS = 16; |
Jason Sams | 68afd01 | 2009-12-17 16:55:08 -0800 | [diff] [blame] | 35 | const static uint32_t MAX_TEXTURE = 2; |
Jason Sams | bb51c40 | 2009-11-25 13:22:07 -0800 | [diff] [blame] | 36 | |
Jason Sams | 0011bcf | 2009-12-15 12:58:36 -0800 | [diff] [blame] | 37 | Program(Context *); |
| 38 | Program(Context *, const char * shaderText, uint32_t shaderLength, |
| 39 | const uint32_t * params, uint32_t paramLength); |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 40 | virtual ~Program(); |
| 41 | |
Jason Sams | ea87e96 | 2010-01-12 12:12:28 -0800 | [diff] [blame] | 42 | void bindAllocation(Allocation *, uint32_t slot); |
Jason Sams | bb51c40 | 2009-11-25 13:22:07 -0800 | [diff] [blame] | 43 | virtual void createShader(); |
| 44 | |
Jason Sams | a09a6e1 | 2010-01-06 11:57:52 -0800 | [diff] [blame] | 45 | bool isUserProgram() const {return mUserShader.size() > 0;} |
| 46 | |
Jason Sams | 68afd01 | 2009-12-17 16:55:08 -0800 | [diff] [blame] | 47 | void bindTexture(uint32_t slot, Allocation *); |
| 48 | void bindSampler(uint32_t slot, Sampler *); |
| 49 | |
Jason Sams | bb51c40 | 2009-11-25 13:22:07 -0800 | [diff] [blame] | 50 | uint32_t getShaderID() const {return mShaderID;} |
Jason Sams | 54c0ec1 | 2009-11-30 14:49:55 -0800 | [diff] [blame] | 51 | void setShader(const char *, uint32_t len); |
Jason Sams | bb51c40 | 2009-11-25 13:22:07 -0800 | [diff] [blame] | 52 | |
| 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 Sams | 9bee51c | 2009-08-05 13:57:03 -0700 | [diff] [blame] | 57 | |
Jason Sams | e17964e | 2010-01-04 16:52:27 -0800 | [diff] [blame] | 58 | String8 getGLSLInputString() const; |
| 59 | String8 getGLSLOutputString() const; |
| 60 | String8 getGLSLConstantString() const; |
| 61 | |
Jason Sams | 156cce6 | 2010-03-03 13:03:18 -0800 | [diff] [blame] | 62 | bool isValid() const {return mIsValid;} |
| 63 | |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 64 | protected: |
| 65 | // Components not listed in "in" will be passed though |
| 66 | // unless overwritten by components in out. |
Jason Sams | 0011bcf | 2009-12-15 12:58:36 -0800 | [diff] [blame] | 67 | ObjectBaseRef<Element> *mInputElements; |
| 68 | ObjectBaseRef<Element> *mOutputElements; |
| 69 | ObjectBaseRef<Type> *mConstantTypes; |
| 70 | uint32_t mInputCount; |
| 71 | uint32_t mOutputCount; |
| 72 | uint32_t mConstantCount; |
Jason Sams | 156cce6 | 2010-03-03 13:03:18 -0800 | [diff] [blame] | 73 | bool mIsValid; |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 74 | |
Jason Sams | ea87e96 | 2010-01-12 12:12:28 -0800 | [diff] [blame] | 75 | ObjectBaseRef<Allocation> mConstants[MAX_UNIFORMS]; |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 76 | |
Jason Sams | 9bee51c | 2009-08-05 13:57:03 -0700 | [diff] [blame] | 77 | mutable bool mDirty; |
Jason Sams | bb51c40 | 2009-11-25 13:22:07 -0800 | [diff] [blame] | 78 | String8 mShader; |
Jason Sams | 54c0ec1 | 2009-11-30 14:49:55 -0800 | [diff] [blame] | 79 | String8 mUserShader; |
Jason Sams | bb51c40 | 2009-11-25 13:22:07 -0800 | [diff] [blame] | 80 | uint32_t mShaderID; |
Jason Sams | 741a610 | 2009-10-15 18:45:45 -0700 | [diff] [blame] | 81 | |
Jason Sams | 7e5ab3b | 2009-12-15 13:27:04 -0800 | [diff] [blame] | 82 | uint32_t mTextureCount; |
Jason Sams | bb51c40 | 2009-11-25 13:22:07 -0800 | [diff] [blame] | 83 | uint32_t mAttribCount; |
| 84 | uint32_t mUniformCount; |
| 85 | String8 mAttribNames[MAX_ATTRIBS]; |
| 86 | String8 mUniformNames[MAX_UNIFORMS]; |
| 87 | |
Jason Sams | 68afd01 | 2009-12-17 16:55:08 -0800 | [diff] [blame] | 88 | // 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 Sams | 5dad8b4 | 2009-12-15 19:10:11 -0800 | [diff] [blame] | 97 | bool loadShader(Context *, uint32_t type); |
Jason Sams | 741a610 | 2009-10-15 18:45:45 -0700 | [diff] [blame] | 98 | |
| 99 | public: |
Jason Sams | 83f1c63 | 2009-10-26 15:19:28 -0700 | [diff] [blame] | 100 | void forceDirty() const {mDirty = true;} |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 101 | }; |
| 102 | |
| 103 | |
| 104 | |
| 105 | } |
| 106 | } |
| 107 | #endif |
| 108 | |
| 109 | |
| 110 | |