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 | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 62 | protected: |
| 63 | // Components not listed in "in" will be passed though |
| 64 | // unless overwritten by components in out. |
Jason Sams | 0011bcf | 2009-12-15 12:58:36 -0800 | [diff] [blame] | 65 | ObjectBaseRef<Element> *mInputElements; |
| 66 | ObjectBaseRef<Element> *mOutputElements; |
| 67 | ObjectBaseRef<Type> *mConstantTypes; |
| 68 | uint32_t mInputCount; |
| 69 | uint32_t mOutputCount; |
| 70 | uint32_t mConstantCount; |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 71 | |
Jason Sams | ea87e96 | 2010-01-12 12:12:28 -0800 | [diff] [blame] | 72 | ObjectBaseRef<Allocation> mConstants[MAX_UNIFORMS]; |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 73 | |
Jason Sams | 9bee51c | 2009-08-05 13:57:03 -0700 | [diff] [blame] | 74 | mutable bool mDirty; |
Jason Sams | bb51c40 | 2009-11-25 13:22:07 -0800 | [diff] [blame] | 75 | String8 mShader; |
Jason Sams | 54c0ec1 | 2009-11-30 14:49:55 -0800 | [diff] [blame] | 76 | String8 mUserShader; |
Jason Sams | bb51c40 | 2009-11-25 13:22:07 -0800 | [diff] [blame] | 77 | uint32_t mShaderID; |
Jason Sams | 741a610 | 2009-10-15 18:45:45 -0700 | [diff] [blame] | 78 | |
Jason Sams | 7e5ab3b | 2009-12-15 13:27:04 -0800 | [diff] [blame] | 79 | uint32_t mTextureCount; |
Jason Sams | bb51c40 | 2009-11-25 13:22:07 -0800 | [diff] [blame] | 80 | uint32_t mAttribCount; |
| 81 | uint32_t mUniformCount; |
| 82 | String8 mAttribNames[MAX_ATTRIBS]; |
| 83 | String8 mUniformNames[MAX_UNIFORMS]; |
| 84 | |
Jason Sams | 68afd01 | 2009-12-17 16:55:08 -0800 | [diff] [blame] | 85 | // 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 Sams | 5dad8b4 | 2009-12-15 19:10:11 -0800 | [diff] [blame] | 94 | bool loadShader(Context *, uint32_t type); |
Jason Sams | 741a610 | 2009-10-15 18:45:45 -0700 | [diff] [blame] | 95 | |
| 96 | public: |
Jason Sams | 83f1c63 | 2009-10-26 15:19:28 -0700 | [diff] [blame] | 97 | void forceDirty() const {mDirty = true;} |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 98 | }; |
| 99 | |
| 100 | |
| 101 | |
| 102 | } |
| 103 | } |
| 104 | #endif |
| 105 | |
| 106 | |
| 107 | |