rsProgramRaster.cpp revision afb743aca56c18beb7ab924e75cb6e070ef3e55a
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_BUILD_FOR_HOST
18#include "rsContext.h"
19#include <GLES/gl.h>
20#include <GLES/glext.h>
21#else
22#include "rsContextHostStub.h"
23#include <OpenGL/gl.h>
24#include <OpenGl/glext.h>
25#endif //ANDROID_RS_BUILD_FOR_HOST
26
27#include "rsProgramRaster.h"
28
29using namespace android;
30using namespace android::renderscript;
31
32
33ProgramRaster::ProgramRaster(Context *rsc, bool pointSmooth,
34                             bool lineSmooth, bool pointSprite)
35    : Program(rsc) {
36
37    mPointSmooth = pointSmooth;
38    mLineSmooth = lineSmooth;
39    mPointSprite = pointSprite;
40    mLineWidth = 1.0f;
41    mCull = RS_CULL_BACK;
42}
43
44ProgramRaster::~ProgramRaster() {
45}
46
47void ProgramRaster::setLineWidth(float s) {
48    mLineWidth = s;
49    mDirty = true;
50}
51
52void ProgramRaster::setCullMode(RsCullMode mode) {
53    mCull = mode;
54    mDirty = true;
55}
56
57void ProgramRaster::setupGL2(const Context *rsc, ProgramRasterState *state) {
58    if (state->mLast.get() == this && !mDirty) {
59        return;
60    }
61    state->mLast.set(this);
62    mDirty = false;
63
64    switch (mCull) {
65        case RS_CULL_BACK:
66            glEnable(GL_CULL_FACE);
67            glCullFace(GL_BACK);
68            break;
69        case RS_CULL_FRONT:
70            glEnable(GL_CULL_FACE);
71            glCullFace(GL_FRONT);
72            break;
73        case RS_CULL_NONE:
74            glDisable(GL_CULL_FACE);
75            break;
76    }
77}
78
79void ProgramRaster::serialize(OStream *stream) const {
80}
81
82ProgramRaster *ProgramRaster::createFromStream(Context *rsc, IStream *stream) {
83    return NULL;
84}
85
86ProgramRasterState::ProgramRasterState() {
87}
88
89ProgramRasterState::~ProgramRasterState() {
90}
91
92void ProgramRasterState::init(Context *rsc) {
93    ProgramRaster *pr = new ProgramRaster(rsc, false, false, false);
94    mDefault.set(pr);
95}
96
97void ProgramRasterState::deinit(Context *rsc) {
98    mDefault.clear();
99    mLast.clear();
100}
101
102namespace android {
103namespace renderscript {
104
105RsProgramRaster rsi_ProgramRasterCreate(Context * rsc,
106                                      bool pointSmooth,
107                                      bool lineSmooth,
108                                      bool pointSprite) {
109    ProgramRaster *pr = new ProgramRaster(rsc, pointSmooth,
110                                          lineSmooth, pointSprite);
111    pr->incUserRef();
112    return pr;
113}
114
115void rsi_ProgramRasterSetLineWidth(Context * rsc,
116                                   RsProgramRaster vpr,
117                                   float s) {
118    ProgramRaster *pr = static_cast<ProgramRaster *>(vpr);
119    pr->setLineWidth(s);
120}
121
122void rsi_ProgramRasterSetCullMode(Context * rsc,
123                                  RsProgramRaster vpr,
124                                  RsCullMode mode) {
125    ProgramRaster *pr = static_cast<ProgramRaster *>(vpr);
126    pr->setCullMode(mode);
127}
128
129}
130}
131
132