blob: bcf55196fbfa417b563556b63db4f2292841b324 [file] [log] [blame]
Jason Samsd19f10d2009-05-22 14:03:28 -07001/*
Alex Sakhartchouk4a36b452011-04-29 16:49:08 -07002 * Copyright (C) 2011 The Android Open Source Project
Jason Samsd19f10d2009-05-22 14:03:28 -07003 *
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 {
Jason Samsd19f10d2009-05-22 14:03:28 -070026
Alex Sakhartchoukc984dd72010-09-14 09:50:43 -070027#define RS_SHADER_INTERNAL "//rs_shader_internal\n"
Alex Sakhartchouk4378f112010-09-29 09:49:13 -070028#define RS_SHADER_ATTR "ATTRIB_"
29#define RS_SHADER_UNI "UNI_"
Alex Sakhartchoukc984dd72010-09-14 09:50:43 -070030
Alex Sakhartchouked9f2102010-11-09 17:00:54 -080031class Program : public ObjectBase {
Jason Samsd19f10d2009-05-22 14:03:28 -070032public:
Jason Samsbb51c402009-11-25 13:22:07 -080033
Jason Sams0011bcf2009-12-15 12:58:36 -080034 Program(Context *);
35 Program(Context *, const char * shaderText, uint32_t shaderLength,
36 const uint32_t * params, uint32_t paramLength);
Jason Samsd19f10d2009-05-22 14:03:28 -070037 virtual ~Program();
38
Alex Sakhartchoukb89aaac2010-09-23 16:16:33 -070039 void bindAllocation(Context *, Allocation *, uint32_t slot);
Jason Samsbb51c402009-11-25 13:22:07 -080040
Alex Sakhartchoukc984dd72010-09-14 09:50:43 -070041 bool isUserProgram() const {return !mIsInternal;}
Jason Samsa09a6e12010-01-06 11:57:52 -080042
Alex Sakhartchoukb89aaac2010-09-23 16:16:33 -070043 void bindTexture(Context *, uint32_t slot, Allocation *);
44 void bindSampler(Context *, uint32_t slot, Sampler *);
Jason Sams68afd012009-12-17 16:55:08 -080045
Jason Sams54c0ec12009-11-30 14:49:55 -080046 void setShader(const char *, uint32_t len);
Jason Samsbb51c402009-11-25 13:22:07 -080047
Alex Sakhartchouk9d71e212010-11-08 15:10:52 -080048 void forceDirty() const {mDirty = true;}
Jason Sams156cce62010-03-03 13:03:18 -080049
Alex Sakhartchouk4a36b452011-04-29 16:49:08 -070050 struct Hal {
51 mutable void *drv;
52
53 struct State {
54 // The difference between Textures and Constants is how they are accessed
55 // Texture lookups go though a sampler which in effect converts normalized
56 // coordinates into type specific. Multiple samples may also be taken
57 // and filtered.
58 //
59 // Constants are strictly accessed by the shader code
60 ObjectBaseRef<Allocation> *textures;
61 RsTextureTarget *textureTargets;
62 uint32_t texturesCount;
63
64 ObjectBaseRef<Sampler> *samplers;
65 uint32_t samplersCount;
66
67 ObjectBaseRef<Allocation> *constants;
68 ObjectBaseRef<Type> *constantTypes;
69 uint32_t constantsCount;
70
71 ObjectBaseRef<Element> *inputElements;
72 uint32_t inputElementsCount;
73 };
74 State state;
75 };
76 Hal mHal;
77
Jason Samsd19f10d2009-05-22 14:03:28 -070078protected:
Alex Sakhartchoukc984dd72010-09-14 09:50:43 -070079 bool mIsInternal;
Jason Samsd19f10d2009-05-22 14:03:28 -070080
Jason Sams9bee51c2009-08-05 13:57:03 -070081 mutable bool mDirty;
Jason Sams54c0ec12009-11-30 14:49:55 -080082 String8 mUserShader;
Alex Sakhartchouk9d71e212010-11-08 15:10:52 -080083
84 void logUniform(const Element *field, const float *fd, uint32_t arraySize );
85 void setUniform(Context *rsc, const Element *field, const float *fd, int32_t slot, uint32_t arraySize );
86 void initMemberVars();
Jason Samsd19f10d2009-05-22 14:03:28 -070087};
88
Jason Samsd19f10d2009-05-22 14:03:28 -070089}
90}
91#endif
92
93
94