rsProgram.h revision f2e4fa215c420cf0f8d226e9a59acb1f312e5e40
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// --------------------------------------------------------------------------- 24namespace android { 25namespace renderscript { 26 27 28class ShaderCache; 29 30class Program : public ObjectBase 31{ 32public: 33 const static uint32_t MAX_ATTRIBS = 8; 34 const static uint32_t MAX_UNIFORMS = 16; 35 36 Program(Context *); 37 Program(Context *, const char * shaderText, uint32_t shaderLength, 38 const uint32_t * params, uint32_t paramLength); 39 virtual ~Program(); 40 41 void bindAllocation(Allocation *); 42 virtual void createShader(); 43 44 uint32_t getShaderID() const {return mShaderID;} 45 void setShader(const char *, uint32_t len); 46 47 uint32_t getAttribCount() const {return mAttribCount;} 48 uint32_t getUniformCount() const {return mUniformCount;} 49 const String8 & getAttribName(uint32_t i) const {return mAttribNames[i];} 50 const String8 & getUniformName(uint32_t i) const {return mUniformNames[i];} 51 52protected: 53 // Components not listed in "in" will be passed though 54 // unless overwritten by components in out. 55 ObjectBaseRef<Element> *mInputElements; 56 ObjectBaseRef<Element> *mOutputElements; 57 ObjectBaseRef<Type> *mConstantTypes; 58 uint32_t mInputCount; 59 uint32_t mOutputCount; 60 uint32_t mConstantCount; 61 62 ObjectBaseRef<Allocation> mConstants; 63 64 mutable bool mDirty; 65 String8 mShader; 66 String8 mUserShader; 67 uint32_t mShaderID; 68 69 uint32_t mTextureCount; 70 uint32_t mAttribCount; 71 uint32_t mUniformCount; 72 String8 mAttribNames[MAX_ATTRIBS]; 73 String8 mUniformNames[MAX_UNIFORMS]; 74 75 bool loadShader(uint32_t type); 76 77public: 78 void forceDirty() const {mDirty = true;} 79}; 80 81 82 83} 84} 85#endif 86 87 88 89