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" |
| 21 | #include "RenderScript.h" |
| 22 | |
| 23 | // --------------------------------------------------------------------------- |
| 24 | namespace android { |
| 25 | namespace renderscript { |
| 26 | |
| 27 | const static uint32_t RS_MAX_SAMPLER_SLOT = 16; |
| 28 | |
| 29 | class SamplerState; |
| 30 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 31 | class Sampler : public ObjectBase { |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 32 | public: |
Alex Sakhartchouk | 117abdb | 2011-08-16 13:09:46 -0700 | [diff] [blame] | 33 | static ObjectBaseRef<Sampler> getSampler(Context *, |
| 34 | RsSamplerValue magFilter, |
| 35 | RsSamplerValue minFilter, |
| 36 | RsSamplerValue wrapS, |
| 37 | RsSamplerValue wrapT, |
| 38 | RsSamplerValue wrapR, |
| 39 | float aniso = 1.0f); |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 40 | void bindToContext(SamplerState *, uint32_t slot); |
| 41 | void unbindFromContext(SamplerState *); |
Alex Sakhartchouk | aae74ad | 2010-06-04 10:06:50 -0700 | [diff] [blame] | 42 | |
Alex Sakhartchouk | aa7d288 | 2010-05-21 12:53:13 -0700 | [diff] [blame] | 43 | virtual void serialize(OStream *stream) const; |
Alex Sakhartchouk | aae74ad | 2010-06-04 10:06:50 -0700 | [diff] [blame] | 44 | virtual RsA3DClassID getClassId() const { return RS_A3D_CLASS_ID_SAMPLER; } |
Alex Sakhartchouk | aa7d288 | 2010-05-21 12:53:13 -0700 | [diff] [blame] | 45 | static Sampler *createFromStream(Context *rsc, IStream *stream); |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 46 | |
Alex Sakhartchouk | a89094a | 2011-05-04 17:45:36 -0700 | [diff] [blame] | 47 | struct Hal { |
| 48 | mutable void *drv; |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 49 | |
Alex Sakhartchouk | a89094a | 2011-05-04 17:45:36 -0700 | [diff] [blame] | 50 | struct State { |
| 51 | RsSamplerValue magFilter; |
| 52 | RsSamplerValue minFilter; |
| 53 | RsSamplerValue wrapS; |
| 54 | RsSamplerValue wrapT; |
| 55 | RsSamplerValue wrapR; |
| 56 | float aniso; |
| 57 | }; |
| 58 | State state; |
| 59 | }; |
| 60 | Hal mHal; |
| 61 | |
| 62 | protected: |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 63 | int32_t mBoundSlot; |
| 64 | |
Alex Sakhartchouk | 117abdb | 2011-08-16 13:09:46 -0700 | [diff] [blame] | 65 | virtual void preDestroy() const; |
| 66 | virtual ~Sampler(); |
| 67 | |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 68 | private: |
Jason Sams | a9e7a05 | 2009-09-25 14:51:22 -0700 | [diff] [blame] | 69 | Sampler(Context *); |
Alex Sakhartchouk | 117abdb | 2011-08-16 13:09:46 -0700 | [diff] [blame] | 70 | Sampler(Context *, |
| 71 | RsSamplerValue magFilter, |
| 72 | RsSamplerValue minFilter, |
| 73 | RsSamplerValue wrapS, |
| 74 | RsSamplerValue wrapT, |
| 75 | RsSamplerValue wrapR, |
| 76 | float aniso = 1.0f); |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 77 | }; |
| 78 | |
| 79 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 80 | class SamplerState { |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 81 | public: |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 82 | ObjectBaseRef<Sampler> mSamplers[RS_MAX_SAMPLER_SLOT]; |
Alex Sakhartchouk | 117abdb | 2011-08-16 13:09:46 -0700 | [diff] [blame] | 83 | void init(Context *rsc) { |
| 84 | } |
| 85 | void deinit(Context *rsc) { |
| 86 | for (uint32_t i = 0; i < RS_MAX_SAMPLER_SLOT; i ++) { |
| 87 | mSamplers[i].clear(); |
| 88 | } |
| 89 | } |
| 90 | // Cache of all existing raster programs. |
| 91 | Vector<Sampler *> mAllSamplers; |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 92 | }; |
| 93 | |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 94 | } |
| 95 | } |
| 96 | #endif //ANDROID_RS_SAMPLER_H |
| 97 | |
| 98 | |
| 99 | |