Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1 | /* |
Alex Sakhartchouk | 4a36b45 | 2011-04-29 16:49:08 -0700 | [diff] [blame] | 2 | * Copyright (C) 2011 The Android Open Source Project |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 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 | |
Alex Sakhartchouk | 4385054 | 2011-05-05 16:56:27 -0700 | [diff] [blame] | 20 | #include "rsProgramBase.h" |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 21 | #include "rsElement.h" |
| 22 | |
| 23 | // --------------------------------------------------------------------------- |
| 24 | namespace android { |
| 25 | namespace renderscript { |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 26 | |
Alex Sakhartchouk | c984dd7 | 2010-09-14 09:50:43 -0700 | [diff] [blame] | 27 | #define RS_SHADER_INTERNAL "//rs_shader_internal\n" |
Alex Sakhartchouk | 4378f11 | 2010-09-29 09:49:13 -0700 | [diff] [blame] | 28 | #define RS_SHADER_ATTR "ATTRIB_" |
| 29 | #define RS_SHADER_UNI "UNI_" |
Alex Sakhartchouk | c984dd7 | 2010-09-14 09:50:43 -0700 | [diff] [blame] | 30 | |
Alex Sakhartchouk | 4385054 | 2011-05-05 16:56:27 -0700 | [diff] [blame] | 31 | class Program : public ProgramBase { |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 32 | public: |
Jason Sams | bb51c40 | 2009-11-25 13:22:07 -0800 | [diff] [blame] | 33 | |
Jason Sams | 0011bcf | 2009-12-15 12:58:36 -0800 | [diff] [blame] | 34 | Program(Context *, const char * shaderText, uint32_t shaderLength, |
| 35 | const uint32_t * params, uint32_t paramLength); |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 36 | virtual ~Program(); |
| 37 | |
Alex Sakhartchouk | b89aaac | 2010-09-23 16:16:33 -0700 | [diff] [blame] | 38 | void bindAllocation(Context *, Allocation *, uint32_t slot); |
Jason Sams | bb51c40 | 2009-11-25 13:22:07 -0800 | [diff] [blame] | 39 | |
Alex Sakhartchouk | c984dd7 | 2010-09-14 09:50:43 -0700 | [diff] [blame] | 40 | bool isUserProgram() const {return !mIsInternal;} |
Jason Sams | a09a6e1 | 2010-01-06 11:57:52 -0800 | [diff] [blame] | 41 | |
Alex Sakhartchouk | b89aaac | 2010-09-23 16:16:33 -0700 | [diff] [blame] | 42 | void bindTexture(Context *, uint32_t slot, Allocation *); |
| 43 | void bindSampler(Context *, uint32_t slot, Sampler *); |
Jason Sams | 68afd01 | 2009-12-17 16:55:08 -0800 | [diff] [blame] | 44 | |
Alex Sakhartchouk | 4a36b45 | 2011-04-29 16:49:08 -0700 | [diff] [blame] | 45 | struct Hal { |
| 46 | mutable void *drv; |
| 47 | |
| 48 | struct State { |
| 49 | // The difference between Textures and Constants is how they are accessed |
| 50 | // Texture lookups go though a sampler which in effect converts normalized |
| 51 | // coordinates into type specific. Multiple samples may also be taken |
| 52 | // and filtered. |
| 53 | // |
| 54 | // Constants are strictly accessed by the shader code |
| 55 | ObjectBaseRef<Allocation> *textures; |
| 56 | RsTextureTarget *textureTargets; |
| 57 | uint32_t texturesCount; |
| 58 | |
| 59 | ObjectBaseRef<Sampler> *samplers; |
| 60 | uint32_t samplersCount; |
| 61 | |
| 62 | ObjectBaseRef<Allocation> *constants; |
| 63 | ObjectBaseRef<Type> *constantTypes; |
| 64 | uint32_t constantsCount; |
| 65 | |
| 66 | ObjectBaseRef<Element> *inputElements; |
| 67 | uint32_t inputElementsCount; |
| 68 | }; |
| 69 | State state; |
| 70 | }; |
| 71 | Hal mHal; |
| 72 | |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 73 | protected: |
Alex Sakhartchouk | c984dd7 | 2010-09-14 09:50:43 -0700 | [diff] [blame] | 74 | bool mIsInternal; |
Jason Sams | 54c0ec1 | 2009-11-30 14:49:55 -0800 | [diff] [blame] | 75 | String8 mUserShader; |
Alex Sakhartchouk | 9d71e21 | 2010-11-08 15:10:52 -0800 | [diff] [blame] | 76 | void initMemberVars(); |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 77 | }; |
| 78 | |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 79 | } |
| 80 | } |
Alex Sakhartchouk | 4385054 | 2011-05-05 16:56:27 -0700 | [diff] [blame] | 81 | #endif // ANDROID_RS_PROGRAM_H |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 82 | |
| 83 | |
| 84 | |