rsProgramRaster.cpp revision a891933b4c5ab1b63103add167269cfc404c2adf
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#include "rsContext.h"
18#include "rsProgramRaster.h"
19
20#include <GLES/gl.h>
21#include <GLES/glext.h>
22
23using namespace android;
24using namespace android::renderscript;
25
26
27ProgramRaster::ProgramRaster(Element *in,
28                             Element *out,
29                             bool pointSmooth,
30                             bool lineSmooth,
31                             bool pointSprite) :
32    Program(in, out)
33{
34    mPointSmooth = pointSmooth;
35    mLineSmooth = lineSmooth;
36    mPointSprite = pointSprite;
37
38    mPointSize = 1.0f;
39    mLineWidth = 1.0f;
40}
41
42ProgramRaster::~ProgramRaster()
43{
44}
45
46void ProgramRaster::setLineWidth(float s)
47{
48    mLineWidth = s;
49}
50
51void ProgramRaster::setPointSize(float s)
52{
53    mPointSize = s;
54}
55
56void ProgramRaster::setupGL(const Context *rsc, ProgramRasterState *state)
57{
58    if (state->mLast.get() == this) {
59        return;
60    }
61    state->mLast.set(this);
62
63    glPointSize(mPointSize);
64    if (mPointSmooth) {
65        glEnable(GL_POINT_SMOOTH);
66    } else {
67        glDisable(GL_POINT_SMOOTH);
68    }
69
70    glLineWidth(mLineWidth);
71    if (mLineSmooth) {
72        glEnable(GL_LINE_SMOOTH);
73    } else {
74        glEnable(GL_LINE_SMOOTH);
75    }
76
77    if (rsc->checkVersion1_1()) {
78        if (mPointSprite) {
79            glEnable(GL_POINT_SPRITE_OES);
80        } else {
81            glDisable(GL_POINT_SPRITE_OES);
82        }
83    }
84}
85
86
87
88ProgramRasterState::ProgramRasterState()
89{
90}
91
92ProgramRasterState::~ProgramRasterState()
93{
94}
95
96void ProgramRasterState::init(Context *rsc, int32_t w, int32_t h)
97{
98    ProgramRaster *pr = new ProgramRaster(NULL, NULL, false, false, false);
99    mDefault.set(pr);
100}
101
102
103namespace android {
104namespace renderscript {
105
106RsProgramRaster rsi_ProgramRasterCreate(Context * rsc, RsElement in, RsElement out,
107                                      bool pointSmooth,
108                                      bool lineSmooth,
109                                      bool pointSprite)
110{
111    ProgramRaster *pr = new ProgramRaster(static_cast<Element *>(in),
112                                          static_cast<Element *>(out),
113                                          pointSmooth,
114                                          lineSmooth,
115                                          pointSprite);
116    pr->incUserRef();
117    return pr;
118}
119
120void rsi_ProgramRasterSetPointSize(Context * rsc, RsProgramRaster vpr, float s)
121{
122    ProgramRaster *pr = static_cast<ProgramRaster *>(vpr);
123    pr->setPointSize(s);
124}
125
126void rsi_ProgramRasterSetLineWidth(Context * rsc, RsProgramRaster vpr, float s)
127{
128    ProgramRaster *pr = static_cast<ProgramRaster *>(vpr);
129    pr->setLineWidth(s);
130}
131
132
133}
134}
135
136