blob: dea4cb676f6956efe168ef2d023d02b73c5f9818 [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
17#ifndef ANDROID_RS_SAMPLER_H
18#define ANDROID_RS_SAMPLER_H
19
Jason Sams326e0dd2009-05-22 14:03:28 -070020#include "rsAllocation.h"
Jason Sams326e0dd2009-05-22 14:03:28 -070021
22// ---------------------------------------------------------------------------
23namespace android {
24namespace renderscript {
25
26const static uint32_t RS_MAX_SAMPLER_SLOT = 16;
27
28class SamplerState;
Alex Sakhartchouk407f8ca2011-09-23 17:05:04 -070029/*****************************************************************************
30 * CAUTION
31 *
32 * Any layout changes for this class may require a corresponding change to be
33 * made to frameworks/compile/libbcc/lib/ScriptCRT/rs_core.c, which contains
34 * a partial copy of the information below.
35 *
36 *****************************************************************************/
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -080037class Sampler : public ObjectBase {
Jason Sams326e0dd2009-05-22 14:03:28 -070038public:
Alex Sakhartchoukc2c02a82011-05-04 17:45:36 -070039 struct Hal {
40 mutable void *drv;
Jason Sams326e0dd2009-05-22 14:03:28 -070041
Alex Sakhartchoukc2c02a82011-05-04 17:45:36 -070042 struct State {
43 RsSamplerValue magFilter;
44 RsSamplerValue minFilter;
45 RsSamplerValue wrapS;
46 RsSamplerValue wrapT;
47 RsSamplerValue wrapR;
48 float aniso;
49 };
50 State state;
51 };
52 Hal mHal;
53
Alex Sakhartchouk407f8ca2011-09-23 17:05:04 -070054 static ObjectBaseRef<Sampler> getSampler(Context *,
55 RsSamplerValue magFilter,
56 RsSamplerValue minFilter,
57 RsSamplerValue wrapS,
58 RsSamplerValue wrapT,
59 RsSamplerValue wrapR,
60 float aniso = 1.0f);
61 void bindToContext(SamplerState *, uint32_t slot);
62 void unbindFromContext(SamplerState *);
63
64 virtual void serialize(OStream *stream) const;
65 virtual RsA3DClassID getClassId() const { return RS_A3D_CLASS_ID_SAMPLER; }
66 static Sampler *createFromStream(Context *rsc, IStream *stream);
67
Alex Sakhartchoukc2c02a82011-05-04 17:45:36 -070068protected:
Jason Sams326e0dd2009-05-22 14:03:28 -070069 int32_t mBoundSlot;
70
Alex Sakhartchoukc700e642011-08-16 13:09:46 -070071 virtual void preDestroy() const;
72 virtual ~Sampler();
73
Jason Sams326e0dd2009-05-22 14:03:28 -070074private:
Jason Samse514b452009-09-25 14:51:22 -070075 Sampler(Context *);
Alex Sakhartchoukc700e642011-08-16 13:09:46 -070076 Sampler(Context *,
77 RsSamplerValue magFilter,
78 RsSamplerValue minFilter,
79 RsSamplerValue wrapS,
80 RsSamplerValue wrapT,
81 RsSamplerValue wrapR,
82 float aniso = 1.0f);
Jason Sams326e0dd2009-05-22 14:03:28 -070083};
84
85
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -080086class SamplerState {
Jason Sams326e0dd2009-05-22 14:03:28 -070087public:
Jason Sams326e0dd2009-05-22 14:03:28 -070088 ObjectBaseRef<Sampler> mSamplers[RS_MAX_SAMPLER_SLOT];
Alex Sakhartchoukc700e642011-08-16 13:09:46 -070089 void init(Context *rsc) {
90 }
91 void deinit(Context *rsc) {
92 for (uint32_t i = 0; i < RS_MAX_SAMPLER_SLOT; i ++) {
93 mSamplers[i].clear();
94 }
95 }
96 // Cache of all existing raster programs.
97 Vector<Sampler *> mAllSamplers;
Jason Sams326e0dd2009-05-22 14:03:28 -070098};
99
Jason Sams326e0dd2009-05-22 14:03:28 -0700100}
101}
102#endif //ANDROID_RS_SAMPLER_H
103
104
105