blob: 3c008c9de8cc4f6a1d28db4db0d69bcf3ad340de [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
17#include "rsContext.h"
18
19
20#include <GLES/gl.h>
21#include <GLES/glext.h>
22#include <utils/Log.h>
23
24#include "rsContext.h"
25#include "rsSampler.h"
26
27using namespace android;
28using namespace android::renderscript;
29
30
31Sampler::Sampler()
32{
33 // Should not get called.
34 rsAssert(0);
35}
36
37Sampler::Sampler(RsSamplerValue magFilter,
38 RsSamplerValue minFilter,
39 RsSamplerValue wrapS,
40 RsSamplerValue wrapT,
41 RsSamplerValue wrapR)
42{
43 mMagFilter = magFilter;
44 mMinFilter = minFilter;
45 mWrapS = wrapS;
46 mWrapT = wrapT;
47 mWrapR = wrapR;
48}
49
50Sampler::~Sampler()
51{
52}
53
54void Sampler::setupGL()
55{
56 //LOGE("setup gl");
57 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
58 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
59 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
60 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
61
62}
63
64void Sampler::bindToContext(SamplerState *ss, uint32_t slot)
65{
66 ss->mSamplers[slot].set(this);
67 mBoundSlot = slot;
68}
69
70void Sampler::unbindFromContext(SamplerState *ss)
71{
72 int32_t slot = mBoundSlot;
73 mBoundSlot = -1;
74 ss->mSamplers[slot].clear();
75}
76
77void SamplerState::setupGL()
78{
79 for (uint32_t ct=0; ct < 1/*RS_MAX_SAMPLER_SLOT*/; ct++) {
80 Sampler *s = mSamplers[ct].get();
81 if (s) {
82 s->setupGL();
83 } else {
84 glBindTexture(GL_TEXTURE_2D, 0);
85 }
86 }
87}
88
89////////////////////////////////
90
91namespace android {
92namespace renderscript {
93
94
95void rsi_SamplerBegin(Context *rsc)
96{
97 SamplerState * ss = &rsc->mStateSampler;
98
99 ss->mMagFilter = RS_SAMPLER_LINEAR;
100 ss->mMinFilter = RS_SAMPLER_LINEAR;
101 ss->mWrapS = RS_SAMPLER_WRAP;
102 ss->mWrapT = RS_SAMPLER_WRAP;
103 ss->mWrapR = RS_SAMPLER_WRAP;
104}
105
106void rsi_SamplerSet(Context *rsc, RsSamplerParam param, RsSamplerValue value)
107{
108 SamplerState * ss = &rsc->mStateSampler;
109
110 switch(param) {
111 case RS_SAMPLER_MAG_FILTER:
112 ss->mMagFilter = value;
113 break;
114 case RS_SAMPLER_MIN_FILTER:
115 ss->mMinFilter = value;
116 break;
117 case RS_SAMPLER_WRAP_S:
118 ss->mWrapS = value;
119 break;
120 case RS_SAMPLER_WRAP_T:
121 ss->mWrapT = value;
122 break;
123 case RS_SAMPLER_WRAP_R:
124 ss->mWrapR = value;
125 break;
126 }
127
128}
129
130RsSampler rsi_SamplerCreate(Context *rsc)
131{
132 SamplerState * ss = &rsc->mStateSampler;
133
134
135 Sampler * s = new Sampler(ss->mMagFilter,
136 ss->mMinFilter,
137 ss->mWrapS,
138 ss->mWrapT,
139 ss->mWrapR);
140 return s;
141}
142
143}}