Jason Sams | 326e0dd | 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 | |
Alex Sakhartchouk | 77d9f4b | 2011-01-31 14:53:24 -0800 | [diff] [blame] | 17 | #include "rsContext.h" |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 18 | #include "rsSampler.h" |
| 19 | |
Jason Sams | 1aa5a4e | 2009-06-22 17:15:15 -0700 | [diff] [blame] | 20 | |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 21 | using namespace android; |
| 22 | using namespace android::renderscript; |
| 23 | |
| 24 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 25 | Sampler::Sampler(Context *rsc) : ObjectBase(rsc) { |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 26 | // Should not get called. |
| 27 | rsAssert(0); |
| 28 | } |
| 29 | |
Jason Sams | e514b45 | 2009-09-25 14:51:22 -0700 | [diff] [blame] | 30 | Sampler::Sampler(Context *rsc, |
| 31 | RsSamplerValue magFilter, |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 32 | RsSamplerValue minFilter, |
| 33 | RsSamplerValue wrapS, |
| 34 | RsSamplerValue wrapT, |
Alex Sakhartchouk | 1103d8e | 2010-09-30 11:36:37 -0700 | [diff] [blame] | 35 | RsSamplerValue wrapR, |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 36 | float aniso) : ObjectBase(rsc) { |
Alex Sakhartchouk | c2c02a8 | 2011-05-04 17:45:36 -0700 | [diff] [blame] | 37 | mHal.state.magFilter = magFilter; |
| 38 | mHal.state.minFilter = minFilter; |
| 39 | mHal.state.wrapS = wrapS; |
| 40 | mHal.state.wrapT = wrapT; |
| 41 | mHal.state.wrapR = wrapR; |
| 42 | mHal.state.aniso = aniso; |
Alex Sakhartchouk | 7f126c7 | 2011-05-05 16:56:27 -0700 | [diff] [blame^] | 43 | |
| 44 | mRSC->mHal.funcs.sampler.init(mRSC, this); |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 45 | } |
| 46 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 47 | Sampler::~Sampler() { |
Alex Sakhartchouk | 7f126c7 | 2011-05-05 16:56:27 -0700 | [diff] [blame^] | 48 | mRSC->mHal.funcs.sampler.destroy(mRSC, this); |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 49 | } |
| 50 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 51 | void Sampler::bindToContext(SamplerState *ss, uint32_t slot) { |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 52 | ss->mSamplers[slot].set(this); |
| 53 | mBoundSlot = slot; |
| 54 | } |
| 55 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 56 | void Sampler::unbindFromContext(SamplerState *ss) { |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 57 | int32_t slot = mBoundSlot; |
| 58 | mBoundSlot = -1; |
| 59 | ss->mSamplers[slot].clear(); |
| 60 | } |
Alex Sakhartchouk | fb6b614 | 2010-05-21 12:53:13 -0700 | [diff] [blame] | 61 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 62 | void Sampler::serialize(OStream *stream) const { |
Alex Sakhartchouk | fb6b614 | 2010-05-21 12:53:13 -0700 | [diff] [blame] | 63 | } |
| 64 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 65 | Sampler *Sampler::createFromStream(Context *rsc, IStream *stream) { |
Alex Sakhartchouk | fb6b614 | 2010-05-21 12:53:13 -0700 | [diff] [blame] | 66 | return NULL; |
| 67 | } |
| 68 | |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 69 | //////////////////////////////// |
| 70 | |
| 71 | namespace android { |
| 72 | namespace renderscript { |
| 73 | |
Alex Sakhartchouk | c2c02a8 | 2011-05-04 17:45:36 -0700 | [diff] [blame] | 74 | RsSampler rsi_SamplerCreate(Context * rsc, |
| 75 | RsSamplerValue magFilter, |
| 76 | RsSamplerValue minFilter, |
| 77 | RsSamplerValue wrapS, |
| 78 | RsSamplerValue wrapT, |
| 79 | RsSamplerValue wrapR, |
| 80 | float aniso) { |
| 81 | Sampler * s = new Sampler(rsc, magFilter, minFilter, wrapS, wrapT, wrapR, aniso); |
Jason Sams | 9397e30 | 2009-08-27 20:23:34 -0700 | [diff] [blame] | 82 | s->incUserRef(); |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 83 | return s; |
| 84 | } |
| 85 | |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 86 | }} |