blob: 0f5ec5134a4ce1d6a41d60103f02096faa26802e [file] [log] [blame]
Jason Samsebfb4362009-09-23 13:57:02 -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#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 LOGE("setup %i %i %i %f %f", mPointSmooth, mLineSmooth, mPointSprite, mPointSize, mLineWidth);
64
65 glPointSize(mPointSize);
66 if (mPointSmooth) {
67 glEnable(GL_POINT_SMOOTH);
68 } else {
69 glDisable(GL_POINT_SMOOTH);
70 }
71
72 glLineWidth(mLineWidth);
73 if (mLineSmooth) {
74 glEnable(GL_LINE_SMOOTH);
75 } else {
76 glEnable(GL_LINE_SMOOTH);
77 }
78
79 if (rsc->checkVersion1_1()) {
80 if (mPointSprite) {
81 glEnable(GL_POINT_SPRITE_OES);
82 } else {
83 glDisable(GL_POINT_SPRITE_OES);
84 }
85 }
86}
87
88
89
90ProgramRasterState::ProgramRasterState()
91{
92}
93
94ProgramRasterState::~ProgramRasterState()
95{
96}
97
98void ProgramRasterState::init(Context *rsc, int32_t w, int32_t h)
99{
100 ProgramRaster *pr = new ProgramRaster(NULL, NULL, false, false, false);
101 mDefault.set(pr);
102}
103
104
105namespace android {
106namespace renderscript {
107
108RsProgramRaster rsi_ProgramRasterCreate(Context * rsc, RsElement in, RsElement out,
109 bool pointSmooth,
110 bool lineSmooth,
111 bool pointSprite)
112{
113 ProgramRaster *pr = new ProgramRaster(static_cast<Element *>(in),
114 static_cast<Element *>(out),
115 pointSmooth,
116 lineSmooth,
117 pointSprite);
118 pr->incUserRef();
119 return pr;
120}
121
122void rsi_ProgramRasterSetPointSize(Context * rsc, RsProgramRaster vpr, float s)
123{
124 ProgramRaster *pr = static_cast<ProgramRaster *>(vpr);
125 pr->setPointSize(s);
126}
127
128void rsi_ProgramRasterSetLineWidth(Context * rsc, RsProgramRaster vpr, float s)
129{
130 ProgramRaster *pr = static_cast<ProgramRaster *>(vpr);
131 pr->setLineWidth(s);
132}
133
134
135}
136}
137