rsSampler.h revision 7f126c78a107257090c6675ea40ffac41516a9dc
1/*
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
20#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;
30
31class Sampler : public ObjectBase {
32public:
33    Sampler(Context *,
34            RsSamplerValue magFilter,
35            RsSamplerValue minFilter,
36            RsSamplerValue wrapS,
37            RsSamplerValue wrapT,
38            RsSamplerValue wrapR,
39            float aniso = 1.0f);
40
41    virtual ~Sampler();
42
43    void bindToContext(SamplerState *, uint32_t slot);
44    void unbindFromContext(SamplerState *);
45
46    virtual void serialize(OStream *stream) const;
47    virtual RsA3DClassID getClassId() const { return RS_A3D_CLASS_ID_SAMPLER; }
48    static Sampler *createFromStream(Context *rsc, IStream *stream);
49
50    struct Hal {
51        mutable void *drv;
52
53        struct State {
54            RsSamplerValue magFilter;
55            RsSamplerValue minFilter;
56            RsSamplerValue wrapS;
57            RsSamplerValue wrapT;
58            RsSamplerValue wrapR;
59            float aniso;
60        };
61        State state;
62    };
63    Hal mHal;
64
65protected:
66    int32_t mBoundSlot;
67
68private:
69    Sampler(Context *);
70};
71
72
73class SamplerState {
74public:
75    ObjectBaseRef<Sampler> mSamplers[RS_MAX_SAMPLER_SLOT];
76};
77
78}
79}
80#endif //ANDROID_RS_SAMPLER_H
81
82
83
84