blob: 3237a7295eca1f5784ed4167ce30601556288d8d [file] [log] [blame]
Jason Sams326e0dd2009-05-22 14:03:28 -07001/*
Alex Sakhartchouka04e30d2011-04-29 16:49:08 -07002 * Copyright (C) 2011 The Android Open Source Project
Jason Sams326e0dd2009-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
Alex Sakhartchouk7f126c72011-05-05 16:56:27 -070020#include "rsProgramBase.h"
Jason Sams326e0dd2009-05-22 14:03:28 -070021#include "rsElement.h"
22
23// ---------------------------------------------------------------------------
24namespace android {
25namespace renderscript {
Jason Sams326e0dd2009-05-22 14:03:28 -070026
Alex Sakhartchouke7ae69f2010-09-14 09:50:43 -070027#define RS_SHADER_INTERNAL "//rs_shader_internal\n"
Alex Sakhartchouk886f11a2010-09-29 09:49:13 -070028#define RS_SHADER_ATTR "ATTRIB_"
29#define RS_SHADER_UNI "UNI_"
Alex Sakhartchouke7ae69f2010-09-14 09:50:43 -070030
Alex Sakhartchouk7f126c72011-05-05 16:56:27 -070031class Program : public ProgramBase {
Jason Sams326e0dd2009-05-22 14:03:28 -070032public:
Jason Samsc460e552009-11-25 13:22:07 -080033
Jason Sams4815c0d2009-12-15 12:58:36 -080034 Program(Context *, const char * shaderText, uint32_t shaderLength,
35 const uint32_t * params, uint32_t paramLength);
Jason Sams326e0dd2009-05-22 14:03:28 -070036 virtual ~Program();
Jason Samsc7cec1e2011-08-18 18:01:33 -070037 virtual bool freeChildren();
Jason Sams326e0dd2009-05-22 14:03:28 -070038
Alex Sakhartchouk383e5b12010-09-23 16:16:33 -070039 void bindAllocation(Context *, Allocation *, uint32_t slot);
Jason Samsc460e552009-11-25 13:22:07 -080040
Alex Sakhartchouke7ae69f2010-09-14 09:50:43 -070041 bool isUserProgram() const {return !mIsInternal;}
Jason Sams433eca32010-01-06 11:57:52 -080042
Alex Sakhartchouk383e5b12010-09-23 16:16:33 -070043 void bindTexture(Context *, uint32_t slot, Allocation *);
44 void bindSampler(Context *, uint32_t slot, Sampler *);
Jason Sams7dad9c32009-12-17 16:55:08 -080045
Alex Sakhartchouka04e30d2011-04-29 16:49:08 -070046 struct Hal {
47 mutable void *drv;
48
49 struct State {
50 // The difference between Textures and Constants is how they are accessed
51 // Texture lookups go though a sampler which in effect converts normalized
52 // coordinates into type specific. Multiple samples may also be taken
53 // and filtered.
54 //
55 // Constants are strictly accessed by the shader code
56 ObjectBaseRef<Allocation> *textures;
57 RsTextureTarget *textureTargets;
58 uint32_t texturesCount;
59
60 ObjectBaseRef<Sampler> *samplers;
61 uint32_t samplersCount;
62
63 ObjectBaseRef<Allocation> *constants;
64 ObjectBaseRef<Type> *constantTypes;
65 uint32_t constantsCount;
66
67 ObjectBaseRef<Element> *inputElements;
68 uint32_t inputElementsCount;
69 };
70 State state;
71 };
72 Hal mHal;
73
Jason Sams326e0dd2009-05-22 14:03:28 -070074protected:
Alex Sakhartchouke7ae69f2010-09-14 09:50:43 -070075 bool mIsInternal;
Jason Samsf2a5d732009-11-30 14:49:55 -080076 String8 mUserShader;
Alex Sakhartchouk54929cc2010-11-08 15:10:52 -080077 void initMemberVars();
Jason Sams326e0dd2009-05-22 14:03:28 -070078};
79
Jason Sams326e0dd2009-05-22 14:03:28 -070080}
81}
Alex Sakhartchouk7f126c72011-05-05 16:56:27 -070082#endif // ANDROID_RS_PROGRAM_H
Jason Sams326e0dd2009-05-22 14:03:28 -070083
84
85