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