rsProgram.h revision 7dad9c30a59c99b57269e1b498807b6f034d56e9
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    const static uint32_t MAX_TEXTURE = 2;
36
37    Program(Context *);
38    Program(Context *, const char * shaderText, uint32_t shaderLength,
39                       const uint32_t * params, uint32_t paramLength);
40    virtual ~Program();
41
42    void bindAllocation(Allocation *);
43    virtual void createShader();
44
45    void bindTexture(uint32_t slot, Allocation *);
46    void bindSampler(uint32_t slot, Sampler *);
47
48    uint32_t getShaderID() const {return mShaderID;}
49    void setShader(const char *, uint32_t len);
50
51    uint32_t getAttribCount() const {return mAttribCount;}
52    uint32_t getUniformCount() const {return mUniformCount;}
53    const String8 & getAttribName(uint32_t i) const {return mAttribNames[i];}
54    const String8 & getUniformName(uint32_t i) const {return mUniformNames[i];}
55
56protected:
57    // Components not listed in "in" will be passed though
58    // unless overwritten by components in out.
59    ObjectBaseRef<Element> *mInputElements;
60    ObjectBaseRef<Element> *mOutputElements;
61    ObjectBaseRef<Type> *mConstantTypes;
62    uint32_t mInputCount;
63    uint32_t mOutputCount;
64    uint32_t mConstantCount;
65
66    ObjectBaseRef<Allocation> mConstants;
67
68    mutable bool mDirty;
69    String8 mShader;
70    String8 mUserShader;
71    uint32_t mShaderID;
72
73    uint32_t mTextureCount;
74    uint32_t mAttribCount;
75    uint32_t mUniformCount;
76    String8 mAttribNames[MAX_ATTRIBS];
77    String8 mUniformNames[MAX_UNIFORMS];
78
79    // The difference between Textures and Constants is how they are accessed
80    // Texture lookups go though a sampler which in effect converts normalized
81    // coordinates into type specific.  Multiple samples may also be taken
82    // and filtered.
83    //
84    // Constants are strictly accessed by programetic loads.
85    ObjectBaseRef<Allocation> mTextures[MAX_TEXTURE];
86    ObjectBaseRef<Sampler> mSamplers[MAX_TEXTURE];
87
88    bool loadShader(Context *, uint32_t type);
89
90public:
91    void forceDirty() const {mDirty = true;}
92};
93
94
95
96}
97}
98#endif
99
100
101
102