rsProgram.h revision c2c02a88641620f50a69cc174077ac8bbef40478
1/*
2 * Copyright (C) 2011 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#define RS_SHADER_INTERNAL "//rs_shader_internal\n"
28#define RS_SHADER_ATTR "ATTRIB_"
29#define RS_SHADER_UNI "UNI_"
30
31class Program : public ObjectBase {
32public:
33
34    Program(Context *);
35    Program(Context *, const char * shaderText, uint32_t shaderLength,
36                       const uint32_t * params, uint32_t paramLength);
37    virtual ~Program();
38
39    void bindAllocation(Context *, Allocation *, uint32_t slot);
40
41    bool isUserProgram() const {return !mIsInternal;}
42
43    void bindTexture(Context *, uint32_t slot, Allocation *);
44    void bindSampler(Context *, uint32_t slot, Sampler *);
45
46    void forceDirty() const {mDirty = true;}
47
48    struct Hal {
49        mutable void *drv;
50
51        struct State {
52            // The difference between Textures and Constants is how they are accessed
53            // Texture lookups go though a sampler which in effect converts normalized
54            // coordinates into type specific.  Multiple samples may also be taken
55            // and filtered.
56            //
57            // Constants are strictly accessed by the shader code
58            ObjectBaseRef<Allocation> *textures;
59            RsTextureTarget *textureTargets;
60            uint32_t texturesCount;
61
62            ObjectBaseRef<Sampler> *samplers;
63            uint32_t samplersCount;
64
65            ObjectBaseRef<Allocation> *constants;
66            ObjectBaseRef<Type> *constantTypes;
67            uint32_t constantsCount;
68
69            ObjectBaseRef<Element> *inputElements;
70            uint32_t inputElementsCount;
71        };
72        State state;
73    };
74    Hal mHal;
75
76protected:
77    bool mIsInternal;
78
79    mutable bool mDirty;
80    String8 mUserShader;
81
82    void logUniform(const Element *field, const float *fd, uint32_t arraySize );
83    void setUniform(Context *rsc, const Element *field, const float *fd, int32_t slot, uint32_t arraySize );
84    void initMemberVars();
85};
86
87}
88}
89#endif
90
91
92
93