blob: 2a05d16e9bbec0bf6c1b18704e91511cfa065f9b [file] [log] [blame]
Jason Samsd19f10d2009-05-22 14:03:28 -07001/*
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 Sakhartchoukd0f5bd12011-01-31 14:53:24 -080017#include "rsContext.h"
Jason Samsd19f10d2009-05-22 14:03:28 -070018#include "rsSampler.h"
19
Jason Sams4b962e52009-06-22 17:15:15 -070020
Jason Samsd19f10d2009-05-22 14:03:28 -070021using namespace android;
22using namespace android::renderscript;
23
24
Alex Sakhartchouked9f2102010-11-09 17:00:54 -080025Sampler::Sampler(Context *rsc) : ObjectBase(rsc) {
Jason Samsd19f10d2009-05-22 14:03:28 -070026 // Should not get called.
27 rsAssert(0);
28}
29
Jason Samsa9e7a052009-09-25 14:51:22 -070030Sampler::Sampler(Context *rsc,
31 RsSamplerValue magFilter,
Jason Samsd19f10d2009-05-22 14:03:28 -070032 RsSamplerValue minFilter,
33 RsSamplerValue wrapS,
34 RsSamplerValue wrapT,
Alex Sakhartchoukf5b35102010-09-30 11:36:37 -070035 RsSamplerValue wrapR,
Alex Sakhartchouked9f2102010-11-09 17:00:54 -080036 float aniso) : ObjectBase(rsc) {
Alex Sakhartchouka89094a2011-05-04 17:45:36 -070037 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 Sakhartchouk43850542011-05-05 16:56:27 -070043
44 mRSC->mHal.funcs.sampler.init(mRSC, this);
Jason Samsd19f10d2009-05-22 14:03:28 -070045}
46
Alex Sakhartchouked9f2102010-11-09 17:00:54 -080047Sampler::~Sampler() {
Alex Sakhartchouk43850542011-05-05 16:56:27 -070048 mRSC->mHal.funcs.sampler.destroy(mRSC, this);
Jason Samsd19f10d2009-05-22 14:03:28 -070049}
50
Alex Sakhartchouked9f2102010-11-09 17:00:54 -080051void Sampler::bindToContext(SamplerState *ss, uint32_t slot) {
Jason Samsd19f10d2009-05-22 14:03:28 -070052 ss->mSamplers[slot].set(this);
53 mBoundSlot = slot;
54}
55
Alex Sakhartchouked9f2102010-11-09 17:00:54 -080056void Sampler::unbindFromContext(SamplerState *ss) {
Jason Samsd19f10d2009-05-22 14:03:28 -070057 int32_t slot = mBoundSlot;
58 mBoundSlot = -1;
59 ss->mSamplers[slot].clear();
60}
Alex Sakhartchoukaa7d2882010-05-21 12:53:13 -070061
Alex Sakhartchouked9f2102010-11-09 17:00:54 -080062void Sampler::serialize(OStream *stream) const {
Alex Sakhartchoukaa7d2882010-05-21 12:53:13 -070063}
64
Alex Sakhartchouked9f2102010-11-09 17:00:54 -080065Sampler *Sampler::createFromStream(Context *rsc, IStream *stream) {
Alex Sakhartchoukaa7d2882010-05-21 12:53:13 -070066 return NULL;
67}
68
Jason Samsd19f10d2009-05-22 14:03:28 -070069////////////////////////////////
70
71namespace android {
72namespace renderscript {
73
Alex Sakhartchouka89094a2011-05-04 17:45:36 -070074RsSampler 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 Sams07ae4062009-08-27 20:23:34 -070082 s->incUserRef();
Jason Samsd19f10d2009-05-22 14:03:28 -070083 return s;
84}
85
Jason Samsd19f10d2009-05-22 14:03:28 -070086}}