blob: fa6b2fdae8bdf39b3ac36e6c704d0b3b5c9424a9 [file] [log] [blame]
Tim Murray729b6fe2013-07-23 16:20:42 -07001/*
2 * Copyright (C) 2008-2012 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#include "RenderScript.h"
18#include <rs.h>
19
20using namespace android;
21using namespace RSC;
22
23Sampler::Sampler(sp<RS> rs, void* id):
24 BaseObj(id, rs)
25{
26 RsSamplerValue mMin = RS_SAMPLER_INVALID;
27 RsSamplerValue mMag = RS_SAMPLER_INVALID;
28 RsSamplerValue mWrapS = RS_SAMPLER_INVALID;;
29 RsSamplerValue mWrapT = RS_SAMPLER_INVALID;;
30 float mAniso = 0.f;
31}
32
33RsSamplerValue Sampler::getMinification() {
34 return mMin;
35}
36
37RsSamplerValue Sampler::getMagnification() {
38 return mMag;
39}
40
41RsSamplerValue Sampler::getWrapS() {
42 return mWrapS;
43}
44
45RsSamplerValue Sampler::getWrapT() {
46 return mWrapT;
47}
48
49float Sampler::getAnisotropy() {
50 return mAniso;
51}
52
53sp<Sampler> Sampler::create(sp<RS> rs, RsSamplerValue min, RsSamplerValue mag, RsSamplerValue wrapS, RsSamplerValue wrapT, float anisotropy) {
54 // we aren't supporting wrapR in C++ API atm, so always pass wrap for that
55 void* id = RS::dispatch->SamplerCreate(rs.get(), min, mag, wrapS, wrapT, RS_SAMPLER_WRAP, anisotropy);
56 return new Sampler(rs, id);
57}
58
59#define CREATE_SAMPLER(N, MIN, MAG, WRAPS, WRAPT) sp<const Sampler> Sampler::N(sp<RS> rs) { \
60 if (rs->mSamplers.N == NULL) { \
61 rs->mSamplers.N = (create(rs, MIN, MAG, WRAPS, WRAPT, 0.f)).get(); \
62 } \
63 return rs->mSamplers.N; \
64 }
65
66CREATE_SAMPLER(CLAMP_NEAREST, RS_SAMPLER_CLAMP, RS_SAMPLER_CLAMP, RS_SAMPLER_NEAREST, RS_SAMPLER_NEAREST);
67CREATE_SAMPLER(CLAMP_LINEAR, RS_SAMPLER_CLAMP, RS_SAMPLER_CLAMP, RS_SAMPLER_LINEAR, RS_SAMPLER_LINEAR);
68CREATE_SAMPLER(CLAMP_LINEAR_MIP_LINEAR, RS_SAMPLER_CLAMP, RS_SAMPLER_CLAMP, RS_SAMPLER_LINEAR_MIP_LINEAR, RS_SAMPLER_LINEAR_MIP_LINEAR);
69CREATE_SAMPLER(WRAP_NEAREST, RS_SAMPLER_WRAP, RS_SAMPLER_WRAP, RS_SAMPLER_NEAREST, RS_SAMPLER_NEAREST);
70CREATE_SAMPLER(WRAP_LINEAR, RS_SAMPLER_WRAP, RS_SAMPLER_WRAP, RS_SAMPLER_LINEAR, RS_SAMPLER_LINEAR);
71CREATE_SAMPLER(WRAP_LINEAR_MIP_LINEAR, RS_SAMPLER_WRAP, RS_SAMPLER_WRAP, RS_SAMPLER_LINEAR_MIP_LINEAR, RS_SAMPLER_LINEAR_MIP_LINEAR);
72CREATE_SAMPLER(MIRRORED_REPEAT_NEAREST, RS_SAMPLER_MIRRORED_REPEAT, RS_SAMPLER_MIRRORED_REPEAT, RS_SAMPLER_NEAREST, RS_SAMPLER_NEAREST);
73CREATE_SAMPLER(MIRRORED_REPEAT_LINEAR, RS_SAMPLER_MIRRORED_REPEAT, RS_SAMPLER_MIRRORED_REPEAT, RS_SAMPLER_LINEAR, RS_SAMPLER_LINEAR);
74CREATE_SAMPLER(MIRRORED_REPEAT_LINEAR_MIP_LINEAR, RS_SAMPLER_MIRRORED_REPEAT, RS_SAMPLER_MIRRORED_REPEAT, RS_SAMPLER_LINEAR_MIP_LINEAR, RS_SAMPLER_LINEAR_MIP_LINEAR);