blob: 66f6ef83a2556d96243a3b49960be422d36c6ce8 [file] [log] [blame]
Jason Sams5fd09d82009-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
Alex Sakhartchoukfb6b6142010-05-21 12:53:13 -070017#ifndef ANDROID_RS_BUILD_FOR_HOST
Jason Sams5fd09d82009-09-23 13:57:02 -070018#include "rsContext.h"
Jason Sams5fd09d82009-09-23 13:57:02 -070019#include <GLES/gl.h>
20#include <GLES/glext.h>
Alex Sakhartchoukfb6b6142010-05-21 12:53:13 -070021#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"
Jason Sams5fd09d82009-09-23 13:57:02 -070028
29using namespace android;
30using namespace android::renderscript;
31
32
Jason Samse514b452009-09-25 14:51:22 -070033ProgramRaster::ProgramRaster(Context *rsc,
Jason Sams5fd09d82009-09-23 13:57:02 -070034 bool pointSmooth,
35 bool lineSmooth,
36 bool pointSprite) :
Jason Sams4815c0d2009-12-15 12:58:36 -080037 Program(rsc)
Jason Sams5fd09d82009-09-23 13:57:02 -070038{
Jason Samsf2649a92009-09-25 16:37:33 -070039 mAllocFile = __FILE__;
40 mAllocLine = __LINE__;
Jason Sams5fd09d82009-09-23 13:57:02 -070041 mPointSmooth = pointSmooth;
42 mLineSmooth = lineSmooth;
43 mPointSprite = pointSprite;
44
45 mPointSize = 1.0f;
46 mLineWidth = 1.0f;
47}
48
49ProgramRaster::~ProgramRaster()
50{
51}
52
53void ProgramRaster::setLineWidth(float s)
54{
55 mLineWidth = s;
56}
57
58void ProgramRaster::setPointSize(float s)
59{
60 mPointSize = s;
61}
62
63void ProgramRaster::setupGL(const Context *rsc, ProgramRasterState *state)
64{
65 if (state->mLast.get() == this) {
66 return;
67 }
68 state->mLast.set(this);
69
Jason Sams5fd09d82009-09-23 13:57:02 -070070 glPointSize(mPointSize);
71 if (mPointSmooth) {
72 glEnable(GL_POINT_SMOOTH);
73 } else {
74 glDisable(GL_POINT_SMOOTH);
75 }
76
77 glLineWidth(mLineWidth);
78 if (mLineSmooth) {
79 glEnable(GL_LINE_SMOOTH);
80 } else {
Jason Sams8cfdd242009-10-14 15:43:53 -070081 glDisable(GL_LINE_SMOOTH);
Jason Sams5fd09d82009-09-23 13:57:02 -070082 }
83
84 if (rsc->checkVersion1_1()) {
Alex Sakhartchoukfb6b6142010-05-21 12:53:13 -070085#ifndef ANDROID_RS_BUILD_FOR_HOST
Jason Sams5fd09d82009-09-23 13:57:02 -070086 if (mPointSprite) {
87 glEnable(GL_POINT_SPRITE_OES);
88 } else {
89 glDisable(GL_POINT_SPRITE_OES);
90 }
Alex Sakhartchoukfb6b6142010-05-21 12:53:13 -070091#endif //ANDROID_RS_BUILD_FOR_HOST
Jason Sams5fd09d82009-09-23 13:57:02 -070092 }
93}
94
Jason Samsc460e552009-11-25 13:22:07 -080095void ProgramRaster::setupGL2(const Context *rsc, ProgramRasterState *state)
96{
97 if (state->mLast.get() == this) {
98 return;
99 }
100 state->mLast.set(this);
101}
102
Alex Sakhartchoukfb6b6142010-05-21 12:53:13 -0700103void ProgramRaster::serialize(OStream *stream) const
104{
105
106}
Jason Sams5fd09d82009-09-23 13:57:02 -0700107
Alex Sakhartchoukfb6b6142010-05-21 12:53:13 -0700108ProgramRaster *ProgramRaster::createFromStream(Context *rsc, IStream *stream)
109{
110 return NULL;
111}
Jason Sams5fd09d82009-09-23 13:57:02 -0700112
113ProgramRasterState::ProgramRasterState()
114{
115}
116
117ProgramRasterState::~ProgramRasterState()
118{
119}
120
Jason Sams771565f2010-05-14 15:30:29 -0700121void ProgramRasterState::init(Context *rsc)
Jason Sams5fd09d82009-09-23 13:57:02 -0700122{
Jason Sams4815c0d2009-12-15 12:58:36 -0800123 ProgramRaster *pr = new ProgramRaster(rsc, false, false, false);
Jason Sams5fd09d82009-09-23 13:57:02 -0700124 mDefault.set(pr);
125}
126
Jason Samsf2649a92009-09-25 16:37:33 -0700127void ProgramRasterState::deinit(Context *rsc)
128{
129 mDefault.clear();
130 mLast.clear();
131}
132
Jason Sams5fd09d82009-09-23 13:57:02 -0700133
134namespace android {
135namespace renderscript {
136
137RsProgramRaster rsi_ProgramRasterCreate(Context * rsc, RsElement in, RsElement out,
138 bool pointSmooth,
139 bool lineSmooth,
140 bool pointSprite)
141{
Jason Samse514b452009-09-25 14:51:22 -0700142 ProgramRaster *pr = new ProgramRaster(rsc,
Jason Sams5fd09d82009-09-23 13:57:02 -0700143 pointSmooth,
144 lineSmooth,
145 pointSprite);
146 pr->incUserRef();
147 return pr;
148}
149
150void rsi_ProgramRasterSetPointSize(Context * rsc, RsProgramRaster vpr, float s)
151{
152 ProgramRaster *pr = static_cast<ProgramRaster *>(vpr);
153 pr->setPointSize(s);
154}
155
156void rsi_ProgramRasterSetLineWidth(Context * rsc, RsProgramRaster vpr, float s)
157{
158 ProgramRaster *pr = static_cast<ProgramRaster *>(vpr);
159 pr->setLineWidth(s);
160}
161
162
163}
164}
165