blob: 5b69370172944db5ec0f19be73727b6684a441af [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
Alex Sakhartchoukaa7d2882010-05-21 12:53:13 -070017#ifndef ANDROID_RS_BUILD_FOR_HOST
Jason Samsebfb4362009-09-23 13:57:02 -070018#include "rsContext.h"
Jason Samsebfb4362009-09-23 13:57:02 -070019#include <GLES/gl.h>
20#include <GLES/glext.h>
Alex Sakhartchoukaa7d2882010-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 Samsebfb4362009-09-23 13:57:02 -070028
29using namespace android;
30using namespace android::renderscript;
31
32
Jason Samsa9e7a052009-09-25 14:51:22 -070033ProgramRaster::ProgramRaster(Context *rsc,
Jason Samsebfb4362009-09-23 13:57:02 -070034 bool pointSmooth,
35 bool lineSmooth,
36 bool pointSprite) :
Jason Sams0011bcf2009-12-15 12:58:36 -080037 Program(rsc)
Jason Samsebfb4362009-09-23 13:57:02 -070038{
Jason Sams61f08d62009-09-25 16:37:33 -070039 mAllocFile = __FILE__;
40 mAllocLine = __LINE__;
Jason Samsebfb4362009-09-23 13:57:02 -070041 mPointSmooth = pointSmooth;
42 mLineSmooth = lineSmooth;
43 mPointSprite = pointSprite;
Jason Samsebfb4362009-09-23 13:57:02 -070044 mLineWidth = 1.0f;
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -070045 mCull = RS_CULL_BACK;
Jason Samsebfb4362009-09-23 13:57:02 -070046}
47
48ProgramRaster::~ProgramRaster()
49{
50}
51
52void ProgramRaster::setLineWidth(float s)
53{
54 mLineWidth = s;
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -070055 mDirty = true;
56}
57
58void ProgramRaster::setCullMode(RsCullMode mode)
59{
60 mCull = mode;
61 mDirty = true;
Jason Samsebfb4362009-09-23 13:57:02 -070062}
63
Jason Samsebfb4362009-09-23 13:57:02 -070064void ProgramRaster::setupGL(const Context *rsc, ProgramRasterState *state)
65{
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -070066 if (state->mLast.get() == this && !mDirty) {
Jason Samsebfb4362009-09-23 13:57:02 -070067 return;
68 }
69 state->mLast.set(this);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -070070 mDirty = false;
Jason Samsebfb4362009-09-23 13:57:02 -070071
Jason Samsebfb4362009-09-23 13:57:02 -070072 if (mPointSmooth) {
73 glEnable(GL_POINT_SMOOTH);
74 } else {
75 glDisable(GL_POINT_SMOOTH);
76 }
77
78 glLineWidth(mLineWidth);
79 if (mLineSmooth) {
80 glEnable(GL_LINE_SMOOTH);
81 } else {
Jason Samsc7412b32009-10-14 15:43:53 -070082 glDisable(GL_LINE_SMOOTH);
Jason Samsebfb4362009-09-23 13:57:02 -070083 }
84
85 if (rsc->checkVersion1_1()) {
Alex Sakhartchoukaa7d2882010-05-21 12:53:13 -070086#ifndef ANDROID_RS_BUILD_FOR_HOST
Jason Samsebfb4362009-09-23 13:57:02 -070087 if (mPointSprite) {
88 glEnable(GL_POINT_SPRITE_OES);
89 } else {
90 glDisable(GL_POINT_SPRITE_OES);
91 }
Alex Sakhartchoukaa7d2882010-05-21 12:53:13 -070092#endif //ANDROID_RS_BUILD_FOR_HOST
Jason Samsebfb4362009-09-23 13:57:02 -070093 }
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -070094
95 switch(mCull) {
96 case RS_CULL_BACK:
97 glEnable(GL_CULL_FACE);
98 glCullFace(GL_BACK);
99 break;
100 case RS_CULL_FRONT:
101 glEnable(GL_CULL_FACE);
102 glCullFace(GL_FRONT);
103 break;
104 case RS_CULL_NONE:
105 glDisable(GL_CULL_FACE);
106 break;
107 }
Jason Samsebfb4362009-09-23 13:57:02 -0700108}
109
Jason Samsbb51c402009-11-25 13:22:07 -0800110void ProgramRaster::setupGL2(const Context *rsc, ProgramRasterState *state)
111{
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -0700112 if (state->mLast.get() == this && !mDirty) {
Jason Samsbb51c402009-11-25 13:22:07 -0800113 return;
114 }
115 state->mLast.set(this);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -0700116 mDirty = false;
117
118 switch(mCull) {
119 case RS_CULL_BACK:
120 glEnable(GL_CULL_FACE);
121 glCullFace(GL_BACK);
122 break;
123 case RS_CULL_FRONT:
124 glEnable(GL_CULL_FACE);
125 glCullFace(GL_FRONT);
126 break;
127 case RS_CULL_NONE:
128 glDisable(GL_CULL_FACE);
129 break;
130 }
Jason Samsbb51c402009-11-25 13:22:07 -0800131}
132
Alex Sakhartchoukaa7d2882010-05-21 12:53:13 -0700133void ProgramRaster::serialize(OStream *stream) const
134{
Jason Sams53a93d52010-07-09 15:34:32 -0700135
Alex Sakhartchoukaa7d2882010-05-21 12:53:13 -0700136}
Jason Samsebfb4362009-09-23 13:57:02 -0700137
Alex Sakhartchoukaa7d2882010-05-21 12:53:13 -0700138ProgramRaster *ProgramRaster::createFromStream(Context *rsc, IStream *stream)
139{
140 return NULL;
141}
Jason Samsebfb4362009-09-23 13:57:02 -0700142
143ProgramRasterState::ProgramRasterState()
144{
145}
146
147ProgramRasterState::~ProgramRasterState()
148{
149}
150
Jason Samsf603d212010-05-14 15:30:29 -0700151void ProgramRasterState::init(Context *rsc)
Jason Samsebfb4362009-09-23 13:57:02 -0700152{
Jason Sams0011bcf2009-12-15 12:58:36 -0800153 ProgramRaster *pr = new ProgramRaster(rsc, false, false, false);
Jason Samsebfb4362009-09-23 13:57:02 -0700154 mDefault.set(pr);
155}
156
Jason Sams61f08d62009-09-25 16:37:33 -0700157void ProgramRasterState::deinit(Context *rsc)
158{
159 mDefault.clear();
160 mLast.clear();
161}
162
Jason Samsebfb4362009-09-23 13:57:02 -0700163
164namespace android {
165namespace renderscript {
166
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -0700167RsProgramRaster rsi_ProgramRasterCreate(Context * rsc,
Jason Samsebfb4362009-09-23 13:57:02 -0700168 bool pointSmooth,
169 bool lineSmooth,
170 bool pointSprite)
171{
Jason Samsa9e7a052009-09-25 14:51:22 -0700172 ProgramRaster *pr = new ProgramRaster(rsc,
Jason Samsebfb4362009-09-23 13:57:02 -0700173 pointSmooth,
174 lineSmooth,
175 pointSprite);
176 pr->incUserRef();
177 return pr;
178}
179
Jason Samsebfb4362009-09-23 13:57:02 -0700180void rsi_ProgramRasterSetLineWidth(Context * rsc, RsProgramRaster vpr, float s)
181{
182 ProgramRaster *pr = static_cast<ProgramRaster *>(vpr);
183 pr->setLineWidth(s);
184}
185
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -0700186void rsi_ProgramRasterSetCullMode(Context * rsc, RsProgramRaster vpr, RsCullMode mode)
187{
188 ProgramRaster *pr = static_cast<ProgramRaster *>(vpr);
189 pr->setCullMode(mode);
190}
191
Jason Samsebfb4362009-09-23 13:57:02 -0700192
193}
194}
195