rsProgramFragment.h revision 900f1616bf33c7ba13cf2a737832a95bcd176388
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_FRAGMENT_H
18#define ANDROID_RS_PROGRAM_FRAGMENT_H
19
20#include "rsProgram.h"
21
22// ---------------------------------------------------------------------------
23namespace android {
24namespace renderscript {
25
26class ProgramFragmentState;
27
28class ProgramFragment : public Program
29{
30public:
31    ProgramFragment(Context *, const uint32_t * params, uint32_t paramLength);
32    ProgramFragment(Context *rsc, const char * shaderText,
33                             uint32_t shaderLength, const uint32_t * params,
34                             uint32_t paramLength);
35    virtual ~ProgramFragment();
36
37    virtual void setupGL2(const Context *, ProgramFragmentState *, ShaderCache *sc);
38
39    virtual void createShader();
40    virtual void loadShader(Context *rsc);
41    virtual void init(Context *rsc);
42    virtual void serialize(OStream *stream) const;
43    virtual RsA3DClassID getClassId() const { return RS_A3D_CLASS_ID_PROGRAM_FRAGMENT; }
44    static ProgramFragment *createFromStream(Context *rsc, IStream *stream);
45
46    void setConstantColor(float, float, float, float);
47
48protected:
49    // Hacks to create a program for now
50    uint32_t mTextureFormats[MAX_TEXTURE];
51    uint32_t mTextureDimensions[MAX_TEXTURE];
52    RsTexEnvMode mEnvModes[MAX_TEXTURE];
53    uint32_t mTextureEnableMask;
54    bool mPointSpriteEnable;
55    bool mVaryingColor;
56
57    float mConstantColor[4];
58    int32_t mConstantColorUniformIndex;
59    int32_t mTextureUniformIndexStart;
60};
61
62class ProgramFragmentState
63{
64public:
65    ProgramFragmentState();
66    ~ProgramFragmentState();
67
68    ProgramFragment *mPF;
69    void init(Context *rsc);
70    void deinit(Context *rsc);
71
72    ObjectBaseRef<Type> mTextureTypes[ProgramFragment::MAX_TEXTURE];
73    ObjectBaseRef<ProgramFragment> mDefault;
74    Vector<ProgramFragment *> mPrograms;
75
76    ObjectBaseRef<ProgramFragment> mLast;
77};
78
79
80}
81}
82#endif
83
84
85
86
87