Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 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_SAMPLER_H |
| 18 | #define ANDROID_RS_SAMPLER_H |
| 19 | |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 20 | #include "rsAllocation.h" |
Jason Sams | 1d6983a | 2012-02-16 16:07:49 -0800 | [diff] [blame] | 21 | #include "rs.h" |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 22 | |
| 23 | // --------------------------------------------------------------------------- |
| 24 | namespace android { |
| 25 | namespace renderscript { |
| 26 | |
| 27 | const static uint32_t RS_MAX_SAMPLER_SLOT = 16; |
| 28 | |
| 29 | class SamplerState; |
Alex Sakhartchouk | 7e6aac1 | 2011-09-23 17:05:04 -0700 | [diff] [blame] | 30 | /***************************************************************************** |
| 31 | * CAUTION |
| 32 | * |
| 33 | * Any layout changes for this class may require a corresponding change to be |
| 34 | * made to frameworks/compile/libbcc/lib/ScriptCRT/rs_core.c, which contains |
| 35 | * a partial copy of the information below. |
| 36 | * |
| 37 | *****************************************************************************/ |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 38 | class Sampler : public ObjectBase { |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 39 | public: |
Alex Sakhartchouk | a89094a | 2011-05-04 17:45:36 -0700 | [diff] [blame] | 40 | struct Hal { |
| 41 | mutable void *drv; |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 42 | |
Alex Sakhartchouk | a89094a | 2011-05-04 17:45:36 -0700 | [diff] [blame] | 43 | struct State { |
| 44 | RsSamplerValue magFilter; |
| 45 | RsSamplerValue minFilter; |
| 46 | RsSamplerValue wrapS; |
| 47 | RsSamplerValue wrapT; |
| 48 | RsSamplerValue wrapR; |
| 49 | float aniso; |
| 50 | }; |
| 51 | State state; |
| 52 | }; |
| 53 | Hal mHal; |
| 54 | |
Alex Sakhartchouk | 7e6aac1 | 2011-09-23 17:05:04 -0700 | [diff] [blame] | 55 | static ObjectBaseRef<Sampler> getSampler(Context *, |
| 56 | RsSamplerValue magFilter, |
| 57 | RsSamplerValue minFilter, |
| 58 | RsSamplerValue wrapS, |
| 59 | RsSamplerValue wrapT, |
| 60 | RsSamplerValue wrapR, |
| 61 | float aniso = 1.0f); |
| 62 | void bindToContext(SamplerState *, uint32_t slot); |
| 63 | void unbindFromContext(SamplerState *); |
| 64 | |
| 65 | virtual void serialize(OStream *stream) const; |
| 66 | virtual RsA3DClassID getClassId() const { return RS_A3D_CLASS_ID_SAMPLER; } |
| 67 | static Sampler *createFromStream(Context *rsc, IStream *stream); |
| 68 | |
Alex Sakhartchouk | a89094a | 2011-05-04 17:45:36 -0700 | [diff] [blame] | 69 | protected: |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 70 | int32_t mBoundSlot; |
| 71 | |
Alex Sakhartchouk | 117abdb | 2011-08-16 13:09:46 -0700 | [diff] [blame] | 72 | virtual void preDestroy() const; |
| 73 | virtual ~Sampler(); |
| 74 | |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 75 | private: |
Jason Sams | a9e7a05 | 2009-09-25 14:51:22 -0700 | [diff] [blame] | 76 | Sampler(Context *); |
Alex Sakhartchouk | 117abdb | 2011-08-16 13:09:46 -0700 | [diff] [blame] | 77 | Sampler(Context *, |
| 78 | RsSamplerValue magFilter, |
| 79 | RsSamplerValue minFilter, |
| 80 | RsSamplerValue wrapS, |
| 81 | RsSamplerValue wrapT, |
| 82 | RsSamplerValue wrapR, |
| 83 | float aniso = 1.0f); |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 84 | }; |
| 85 | |
| 86 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 87 | class SamplerState { |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 88 | public: |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 89 | ObjectBaseRef<Sampler> mSamplers[RS_MAX_SAMPLER_SLOT]; |
Alex Sakhartchouk | 117abdb | 2011-08-16 13:09:46 -0700 | [diff] [blame] | 90 | void init(Context *rsc) { |
| 91 | } |
| 92 | void deinit(Context *rsc) { |
| 93 | for (uint32_t i = 0; i < RS_MAX_SAMPLER_SLOT; i ++) { |
| 94 | mSamplers[i].clear(); |
| 95 | } |
| 96 | } |
| 97 | // Cache of all existing raster programs. |
| 98 | Vector<Sampler *> mAllSamplers; |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 99 | }; |
| 100 | |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 101 | } |
| 102 | } |
| 103 | #endif //ANDROID_RS_SAMPLER_H |
| 104 | |
| 105 | |
| 106 | |