blob: 76638409aa09d0804d6829b029533505306aad07 [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;
45}
46
47ProgramRaster::~ProgramRaster()
48{
49}
50
51void ProgramRaster::setLineWidth(float s)
52{
53 mLineWidth = s;
54}
55
Jason Samsebfb4362009-09-23 13:57:02 -070056void ProgramRaster::setupGL(const Context *rsc, ProgramRasterState *state)
57{
58 if (state->mLast.get() == this) {
59 return;
60 }
61 state->mLast.set(this);
62
Jason Samsebfb4362009-09-23 13:57:02 -070063 if (mPointSmooth) {
64 glEnable(GL_POINT_SMOOTH);
65 } else {
66 glDisable(GL_POINT_SMOOTH);
67 }
68
69 glLineWidth(mLineWidth);
70 if (mLineSmooth) {
71 glEnable(GL_LINE_SMOOTH);
72 } else {
Jason Samsc7412b32009-10-14 15:43:53 -070073 glDisable(GL_LINE_SMOOTH);
Jason Samsebfb4362009-09-23 13:57:02 -070074 }
75
76 if (rsc->checkVersion1_1()) {
Alex Sakhartchoukaa7d2882010-05-21 12:53:13 -070077#ifndef ANDROID_RS_BUILD_FOR_HOST
Jason Samsebfb4362009-09-23 13:57:02 -070078 if (mPointSprite) {
79 glEnable(GL_POINT_SPRITE_OES);
80 } else {
81 glDisable(GL_POINT_SPRITE_OES);
82 }
Alex Sakhartchoukaa7d2882010-05-21 12:53:13 -070083#endif //ANDROID_RS_BUILD_FOR_HOST
Jason Samsebfb4362009-09-23 13:57:02 -070084 }
85}
86
Jason Samsbb51c402009-11-25 13:22:07 -080087void ProgramRaster::setupGL2(const Context *rsc, ProgramRasterState *state)
88{
89 if (state->mLast.get() == this) {
90 return;
91 }
92 state->mLast.set(this);
93}
94
Alex Sakhartchoukaa7d2882010-05-21 12:53:13 -070095void ProgramRaster::serialize(OStream *stream) const
96{
Jason Sams53a93d52010-07-09 15:34:32 -070097
Alex Sakhartchoukaa7d2882010-05-21 12:53:13 -070098}
Jason Samsebfb4362009-09-23 13:57:02 -070099
Alex Sakhartchoukaa7d2882010-05-21 12:53:13 -0700100ProgramRaster *ProgramRaster::createFromStream(Context *rsc, IStream *stream)
101{
102 return NULL;
103}
Jason Samsebfb4362009-09-23 13:57:02 -0700104
105ProgramRasterState::ProgramRasterState()
106{
107}
108
109ProgramRasterState::~ProgramRasterState()
110{
111}
112
Jason Samsf603d212010-05-14 15:30:29 -0700113void ProgramRasterState::init(Context *rsc)
Jason Samsebfb4362009-09-23 13:57:02 -0700114{
Jason Sams0011bcf2009-12-15 12:58:36 -0800115 ProgramRaster *pr = new ProgramRaster(rsc, false, false, false);
Jason Samsebfb4362009-09-23 13:57:02 -0700116 mDefault.set(pr);
117}
118
Jason Sams61f08d62009-09-25 16:37:33 -0700119void ProgramRasterState::deinit(Context *rsc)
120{
121 mDefault.clear();
122 mLast.clear();
123}
124
Jason Samsebfb4362009-09-23 13:57:02 -0700125
126namespace android {
127namespace renderscript {
128
129RsProgramRaster rsi_ProgramRasterCreate(Context * rsc, RsElement in, RsElement out,
130 bool pointSmooth,
131 bool lineSmooth,
132 bool pointSprite)
133{
Jason Samsa9e7a052009-09-25 14:51:22 -0700134 ProgramRaster *pr = new ProgramRaster(rsc,
Jason Samsebfb4362009-09-23 13:57:02 -0700135 pointSmooth,
136 lineSmooth,
137 pointSprite);
138 pr->incUserRef();
139 return pr;
140}
141
Jason Samsebfb4362009-09-23 13:57:02 -0700142void rsi_ProgramRasterSetLineWidth(Context * rsc, RsProgramRaster vpr, float s)
143{
144 ProgramRaster *pr = static_cast<ProgramRaster *>(vpr);
145 pr->setLineWidth(s);
146}
147
148
149}
150}
151