blob: 14b4ec315ee1504fe3aeefd0fd46e4e13bb453db [file] [log] [blame]
Jason Samsd19f10d2009-05-22 14:03:28 -07001/*
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
Jason Sams9bee51c2009-08-05 13:57:03 -070026class ProgramFragmentState;
Jason Samsd19f10d2009-05-22 14:03:28 -070027
28class ProgramFragment : public Program
29{
30public:
31 const static uint32_t MAX_TEXTURE = 2;
Jason Samsd19f10d2009-05-22 14:03:28 -070032
33
34
Jason Samsa9e7a052009-09-25 14:51:22 -070035 ProgramFragment(Context *, Element *in, Element *out, bool pointSpriteEnable);
Jason Sams7e5ab3b2009-12-15 13:27:04 -080036 ProgramFragment(Context *rsc, const char * shaderText,
37 uint32_t shaderLength, const uint32_t * params,
38 uint32_t paramLength);
Jason Samsd19f10d2009-05-22 14:03:28 -070039 virtual ~ProgramFragment();
40
Jason Samsb13ada52009-08-25 11:34:49 -070041 virtual void setupGL(const Context *, ProgramFragmentState *);
Jason Samsbb51c402009-11-25 13:22:07 -080042 virtual void setupGL2(const Context *, ProgramFragmentState *, ShaderCache *sc);
Jason Samsd19f10d2009-05-22 14:03:28 -070043
44
45 void bindTexture(uint32_t slot, Allocation *);
46 void bindSampler(uint32_t slot, Sampler *);
47 void setType(uint32_t slot, const Element *, uint32_t dim);
48
49 void setEnvMode(uint32_t slot, RsTexEnvMode);
50 void setTexEnable(uint32_t slot, bool);
51
Jason Samsbb51c402009-11-25 13:22:07 -080052 virtual void createShader();
Jason Sams5dad8b42009-12-15 19:10:11 -080053 virtual void loadShader(Context *rsc);
Jason Samsbb51c402009-11-25 13:22:07 -080054 virtual void init(Context *rsc);
Jason Samsd19f10d2009-05-22 14:03:28 -070055
56
57protected:
58 // The difference between Textures and Constants is how they are accessed
59 // Texture lookups go though a sampler which in effect converts normalized
60 // coordinates into type specific. Multiple samples may also be taken
61 // and filtered.
Jason Sams9bee51c2009-08-05 13:57:03 -070062 //
Jason Samsd19f10d2009-05-22 14:03:28 -070063 // Constants are strictly accessed by programetic loads.
64 ObjectBaseRef<Allocation> mTextures[MAX_TEXTURE];
65 ObjectBaseRef<Sampler> mSamplers[MAX_TEXTURE];
66 ObjectBaseRef<const Element> mTextureFormats[MAX_TEXTURE];
67 uint32_t mTextureDimensions[MAX_TEXTURE];
68
69
Jason Samsd19f10d2009-05-22 14:03:28 -070070 // Hacks to create a program for now
71 RsTexEnvMode mEnvModes[MAX_TEXTURE];
72 uint32_t mTextureEnableMask;
Jason Sams25ffcdc2009-08-20 16:10:36 -070073 bool mPointSpriteEnable;
Jason Samsd19f10d2009-05-22 14:03:28 -070074};
75
Jason Sams9bee51c2009-08-05 13:57:03 -070076class ProgramFragmentState
Jason Samsd19f10d2009-05-22 14:03:28 -070077{
78public:
79 ProgramFragmentState();
80 ~ProgramFragmentState();
81
82 ProgramFragment *mPF;
Jason Sams9c54bdb2009-06-17 16:52:59 -070083 void init(Context *rsc, int32_t w, int32_t h);
Jason Sams61f08d62009-09-25 16:37:33 -070084 void deinit(Context *rsc);
Jason Samsd19f10d2009-05-22 14:03:28 -070085
86 ObjectBaseRef<Type> mTextureTypes[ProgramFragment::MAX_TEXTURE];
Jason Sams9c54bdb2009-06-17 16:52:59 -070087 ObjectBaseRef<ProgramFragment> mDefault;
Jason Sams3eaa3382009-06-10 15:04:38 -070088 Vector<ProgramFragment *> mPrograms;
Jason Sams9bee51c2009-08-05 13:57:03 -070089
90 ObjectBaseRef<ProgramFragment> mLast;
Jason Samsd19f10d2009-05-22 14:03:28 -070091};
92
93
94}
95}
96#endif
97
98
99
100