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