blob: 2a9c4abd2cb61554ad2bf53684e223b8fb1130e2 [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
Jason Samsa9e7a052009-09-25 14:51:22 -070027ProgramRaster::ProgramRaster(Context *rsc,
28 Element *in,
Jason Samsebfb4362009-09-23 13:57:02 -070029 Element *out,
30 bool pointSmooth,
31 bool lineSmooth,
32 bool pointSprite) :
Jason Samsa9e7a052009-09-25 14:51:22 -070033 Program(rsc, in, out)
Jason Samsebfb4362009-09-23 13:57:02 -070034{
35 mPointSmooth = pointSmooth;
36 mLineSmooth = lineSmooth;
37 mPointSprite = pointSprite;
38
39 mPointSize = 1.0f;
40 mLineWidth = 1.0f;
41}
42
43ProgramRaster::~ProgramRaster()
44{
45}
46
47void ProgramRaster::setLineWidth(float s)
48{
49 mLineWidth = s;
50}
51
52void ProgramRaster::setPointSize(float s)
53{
54 mPointSize = s;
55}
56
57void ProgramRaster::setupGL(const Context *rsc, ProgramRasterState *state)
58{
59 if (state->mLast.get() == this) {
60 return;
61 }
62 state->mLast.set(this);
63
Jason Samsebfb4362009-09-23 13:57:02 -070064 glPointSize(mPointSize);
65 if (mPointSmooth) {
66 glEnable(GL_POINT_SMOOTH);
67 } else {
68 glDisable(GL_POINT_SMOOTH);
69 }
70
71 glLineWidth(mLineWidth);
72 if (mLineSmooth) {
73 glEnable(GL_LINE_SMOOTH);
74 } else {
75 glEnable(GL_LINE_SMOOTH);
76 }
77
78 if (rsc->checkVersion1_1()) {
79 if (mPointSprite) {
80 glEnable(GL_POINT_SPRITE_OES);
81 } else {
82 glDisable(GL_POINT_SPRITE_OES);
83 }
84 }
85}
86
87
88
89ProgramRasterState::ProgramRasterState()
90{
91}
92
93ProgramRasterState::~ProgramRasterState()
94{
95}
96
97void ProgramRasterState::init(Context *rsc, int32_t w, int32_t h)
98{
Jason Samsa9e7a052009-09-25 14:51:22 -070099 ProgramRaster *pr = new ProgramRaster(rsc, NULL, NULL, false, false, false);
Jason Samsebfb4362009-09-23 13:57:02 -0700100 mDefault.set(pr);
101}
102
103
104namespace android {
105namespace renderscript {
106
107RsProgramRaster rsi_ProgramRasterCreate(Context * rsc, RsElement in, RsElement out,
108 bool pointSmooth,
109 bool lineSmooth,
110 bool pointSprite)
111{
Jason Samsa9e7a052009-09-25 14:51:22 -0700112 ProgramRaster *pr = new ProgramRaster(rsc,
113 static_cast<Element *>(in),
Jason Samsebfb4362009-09-23 13:57:02 -0700114 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