blob: 654cd9ce1a0689b0e5ce4083a1ff6f157b081254 [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"
21#include "RenderScript.h"
22
23// ---------------------------------------------------------------------------
24namespace android {
25namespace renderscript {
26
27const static uint32_t RS_MAX_SAMPLER_SLOT = 16;
28
29class SamplerState;
Alex Sakhartchouk407f8ca2011-09-23 17:05:04 -070030/*****************************************************************************
31 * CAUTION
32 *
33 * Any layout changes for this class may require a corresponding change to be
34 * made to frameworks/compile/libbcc/lib/ScriptCRT/rs_core.c, which contains
35 * a partial copy of the information below.
36 *
37 *****************************************************************************/
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -080038class Sampler : public ObjectBase {
Jason Sams326e0dd2009-05-22 14:03:28 -070039public:
Alex Sakhartchoukc2c02a82011-05-04 17:45:36 -070040 struct Hal {
41 mutable void *drv;
Jason Sams326e0dd2009-05-22 14:03:28 -070042
Alex Sakhartchoukc2c02a82011-05-04 17:45:36 -070043 struct State {
44 RsSamplerValue magFilter;
45 RsSamplerValue minFilter;
46 RsSamplerValue wrapS;
47 RsSamplerValue wrapT;
48 RsSamplerValue wrapR;
49 float aniso;
50 };
51 State state;
52 };
53 Hal mHal;
54
Alex Sakhartchouk407f8ca2011-09-23 17:05:04 -070055 static ObjectBaseRef<Sampler> getSampler(Context *,
56 RsSamplerValue magFilter,
57 RsSamplerValue minFilter,
58 RsSamplerValue wrapS,
59 RsSamplerValue wrapT,
60 RsSamplerValue wrapR,
61 float aniso = 1.0f);
62 void bindToContext(SamplerState *, uint32_t slot);
63 void unbindFromContext(SamplerState *);
64
65 virtual void serialize(OStream *stream) const;
66 virtual RsA3DClassID getClassId() const { return RS_A3D_CLASS_ID_SAMPLER; }
67 static Sampler *createFromStream(Context *rsc, IStream *stream);
68
Alex Sakhartchoukc2c02a82011-05-04 17:45:36 -070069protected:
Jason Sams326e0dd2009-05-22 14:03:28 -070070 int32_t mBoundSlot;
71
Alex Sakhartchoukc700e642011-08-16 13:09:46 -070072 virtual void preDestroy() const;
73 virtual ~Sampler();
74
Jason Sams326e0dd2009-05-22 14:03:28 -070075private:
Jason Samse514b452009-09-25 14:51:22 -070076 Sampler(Context *);
Alex Sakhartchoukc700e642011-08-16 13:09:46 -070077 Sampler(Context *,
78 RsSamplerValue magFilter,
79 RsSamplerValue minFilter,
80 RsSamplerValue wrapS,
81 RsSamplerValue wrapT,
82 RsSamplerValue wrapR,
83 float aniso = 1.0f);
Jason Sams326e0dd2009-05-22 14:03:28 -070084};
85
86
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -080087class SamplerState {
Jason Sams326e0dd2009-05-22 14:03:28 -070088public:
Jason Sams326e0dd2009-05-22 14:03:28 -070089 ObjectBaseRef<Sampler> mSamplers[RS_MAX_SAMPLER_SLOT];
Alex Sakhartchoukc700e642011-08-16 13:09:46 -070090 void init(Context *rsc) {
91 }
92 void deinit(Context *rsc) {
93 for (uint32_t i = 0; i < RS_MAX_SAMPLER_SLOT; i ++) {
94 mSamplers[i].clear();
95 }
96 }
97 // Cache of all existing raster programs.
98 Vector<Sampler *> mAllSamplers;
Jason Sams326e0dd2009-05-22 14:03:28 -070099};
100
Jason Sams326e0dd2009-05-22 14:03:28 -0700101}
102}
103#endif //ANDROID_RS_SAMPLER_H
104
105
106