blob: 62d060d378992d0a93e1e0c4bb99acb2d0d41420 [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 Samsbb51c402009-11-25 13:22:07 -080064void ProgramRaster::setupGL2(const Context *rsc, ProgramRasterState *state)
65{
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -070066 if (state->mLast.get() == this && !mDirty) {
Jason Samsbb51c402009-11-25 13:22:07 -080067 return;
68 }
69 state->mLast.set(this);
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -070070 mDirty = false;
71
72 switch(mCull) {
73 case RS_CULL_BACK:
74 glEnable(GL_CULL_FACE);
75 glCullFace(GL_BACK);
76 break;
77 case RS_CULL_FRONT:
78 glEnable(GL_CULL_FACE);
79 glCullFace(GL_FRONT);
80 break;
81 case RS_CULL_NONE:
82 glDisable(GL_CULL_FACE);
83 break;
84 }
Jason Samsbb51c402009-11-25 13:22:07 -080085}
86
Alex Sakhartchoukaa7d2882010-05-21 12:53:13 -070087void ProgramRaster::serialize(OStream *stream) const
88{
Jason Sams53a93d52010-07-09 15:34:32 -070089
Alex Sakhartchoukaa7d2882010-05-21 12:53:13 -070090}
Jason Samsebfb4362009-09-23 13:57:02 -070091
Alex Sakhartchoukaa7d2882010-05-21 12:53:13 -070092ProgramRaster *ProgramRaster::createFromStream(Context *rsc, IStream *stream)
93{
94 return NULL;
95}
Jason Samsebfb4362009-09-23 13:57:02 -070096
97ProgramRasterState::ProgramRasterState()
98{
99}
100
101ProgramRasterState::~ProgramRasterState()
102{
103}
104
Jason Samsf603d212010-05-14 15:30:29 -0700105void ProgramRasterState::init(Context *rsc)
Jason Samsebfb4362009-09-23 13:57:02 -0700106{
Jason Sams0011bcf2009-12-15 12:58:36 -0800107 ProgramRaster *pr = new ProgramRaster(rsc, false, false, false);
Jason Samsebfb4362009-09-23 13:57:02 -0700108 mDefault.set(pr);
109}
110
Jason Sams61f08d62009-09-25 16:37:33 -0700111void ProgramRasterState::deinit(Context *rsc)
112{
113 mDefault.clear();
114 mLast.clear();
115}
116
Jason Samsebfb4362009-09-23 13:57:02 -0700117
118namespace android {
119namespace renderscript {
120
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -0700121RsProgramRaster rsi_ProgramRasterCreate(Context * rsc,
Jason Samsebfb4362009-09-23 13:57:02 -0700122 bool pointSmooth,
123 bool lineSmooth,
124 bool pointSprite)
125{
Jason Samsa9e7a052009-09-25 14:51:22 -0700126 ProgramRaster *pr = new ProgramRaster(rsc,
Jason Samsebfb4362009-09-23 13:57:02 -0700127 pointSmooth,
128 lineSmooth,
129 pointSprite);
130 pr->incUserRef();
131 return pr;
132}
133
Jason Samsebfb4362009-09-23 13:57:02 -0700134void rsi_ProgramRasterSetLineWidth(Context * rsc, RsProgramRaster vpr, float s)
135{
136 ProgramRaster *pr = static_cast<ProgramRaster *>(vpr);
137 pr->setLineWidth(s);
138}
139
Alex Sakhartchouk80a4c2c2010-07-12 15:50:32 -0700140void rsi_ProgramRasterSetCullMode(Context * rsc, RsProgramRaster vpr, RsCullMode mode)
141{
142 ProgramRaster *pr = static_cast<ProgramRaster *>(vpr);
143 pr->setCullMode(mode);
144}
145
Jason Samsebfb4362009-09-23 13:57:02 -0700146
147}
148}
149