Jason Sams | ebfb436 | 2009-09-23 13:57:02 -0700 | [diff] [blame] | 1 | /* |
| 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 Sakhartchouk | aa7d288 | 2010-05-21 12:53:13 -0700 | [diff] [blame^] | 17 | #ifndef ANDROID_RS_BUILD_FOR_HOST |
Jason Sams | ebfb436 | 2009-09-23 13:57:02 -0700 | [diff] [blame] | 18 | #include "rsContext.h" |
Jason Sams | ebfb436 | 2009-09-23 13:57:02 -0700 | [diff] [blame] | 19 | #include <GLES/gl.h> |
| 20 | #include <GLES/glext.h> |
Alex Sakhartchouk | aa7d288 | 2010-05-21 12:53:13 -0700 | [diff] [blame^] | 21 | #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 Sams | ebfb436 | 2009-09-23 13:57:02 -0700 | [diff] [blame] | 28 | |
| 29 | using namespace android; |
| 30 | using namespace android::renderscript; |
| 31 | |
| 32 | |
Jason Sams | a9e7a05 | 2009-09-25 14:51:22 -0700 | [diff] [blame] | 33 | ProgramRaster::ProgramRaster(Context *rsc, |
Jason Sams | ebfb436 | 2009-09-23 13:57:02 -0700 | [diff] [blame] | 34 | bool pointSmooth, |
| 35 | bool lineSmooth, |
| 36 | bool pointSprite) : |
Jason Sams | 0011bcf | 2009-12-15 12:58:36 -0800 | [diff] [blame] | 37 | Program(rsc) |
Jason Sams | ebfb436 | 2009-09-23 13:57:02 -0700 | [diff] [blame] | 38 | { |
Jason Sams | 61f08d6 | 2009-09-25 16:37:33 -0700 | [diff] [blame] | 39 | mAllocFile = __FILE__; |
| 40 | mAllocLine = __LINE__; |
Jason Sams | ebfb436 | 2009-09-23 13:57:02 -0700 | [diff] [blame] | 41 | mPointSmooth = pointSmooth; |
| 42 | mLineSmooth = lineSmooth; |
| 43 | mPointSprite = pointSprite; |
| 44 | |
| 45 | mPointSize = 1.0f; |
| 46 | mLineWidth = 1.0f; |
| 47 | } |
| 48 | |
| 49 | ProgramRaster::~ProgramRaster() |
| 50 | { |
| 51 | } |
| 52 | |
| 53 | void ProgramRaster::setLineWidth(float s) |
| 54 | { |
| 55 | mLineWidth = s; |
| 56 | } |
| 57 | |
| 58 | void ProgramRaster::setPointSize(float s) |
| 59 | { |
| 60 | mPointSize = s; |
| 61 | } |
| 62 | |
| 63 | void ProgramRaster::setupGL(const Context *rsc, ProgramRasterState *state) |
| 64 | { |
| 65 | if (state->mLast.get() == this) { |
| 66 | return; |
| 67 | } |
| 68 | state->mLast.set(this); |
| 69 | |
Jason Sams | ebfb436 | 2009-09-23 13:57:02 -0700 | [diff] [blame] | 70 | 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 Sams | c7412b3 | 2009-10-14 15:43:53 -0700 | [diff] [blame] | 81 | glDisable(GL_LINE_SMOOTH); |
Jason Sams | ebfb436 | 2009-09-23 13:57:02 -0700 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | if (rsc->checkVersion1_1()) { |
Alex Sakhartchouk | aa7d288 | 2010-05-21 12:53:13 -0700 | [diff] [blame^] | 85 | #ifndef ANDROID_RS_BUILD_FOR_HOST |
Jason Sams | ebfb436 | 2009-09-23 13:57:02 -0700 | [diff] [blame] | 86 | if (mPointSprite) { |
| 87 | glEnable(GL_POINT_SPRITE_OES); |
| 88 | } else { |
| 89 | glDisable(GL_POINT_SPRITE_OES); |
| 90 | } |
Alex Sakhartchouk | aa7d288 | 2010-05-21 12:53:13 -0700 | [diff] [blame^] | 91 | #endif //ANDROID_RS_BUILD_FOR_HOST |
Jason Sams | ebfb436 | 2009-09-23 13:57:02 -0700 | [diff] [blame] | 92 | } |
| 93 | } |
| 94 | |
Jason Sams | bb51c40 | 2009-11-25 13:22:07 -0800 | [diff] [blame] | 95 | void 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 Sakhartchouk | aa7d288 | 2010-05-21 12:53:13 -0700 | [diff] [blame^] | 103 | void ProgramRaster::serialize(OStream *stream) const |
| 104 | { |
| 105 | |
| 106 | } |
Jason Sams | ebfb436 | 2009-09-23 13:57:02 -0700 | [diff] [blame] | 107 | |
Alex Sakhartchouk | aa7d288 | 2010-05-21 12:53:13 -0700 | [diff] [blame^] | 108 | ProgramRaster *ProgramRaster::createFromStream(Context *rsc, IStream *stream) |
| 109 | { |
| 110 | return NULL; |
| 111 | } |
Jason Sams | ebfb436 | 2009-09-23 13:57:02 -0700 | [diff] [blame] | 112 | |
| 113 | ProgramRasterState::ProgramRasterState() |
| 114 | { |
| 115 | } |
| 116 | |
| 117 | ProgramRasterState::~ProgramRasterState() |
| 118 | { |
| 119 | } |
| 120 | |
Jason Sams | f603d21 | 2010-05-14 15:30:29 -0700 | [diff] [blame] | 121 | void ProgramRasterState::init(Context *rsc) |
Jason Sams | ebfb436 | 2009-09-23 13:57:02 -0700 | [diff] [blame] | 122 | { |
Jason Sams | 0011bcf | 2009-12-15 12:58:36 -0800 | [diff] [blame] | 123 | ProgramRaster *pr = new ProgramRaster(rsc, false, false, false); |
Jason Sams | ebfb436 | 2009-09-23 13:57:02 -0700 | [diff] [blame] | 124 | mDefault.set(pr); |
| 125 | } |
| 126 | |
Jason Sams | 61f08d6 | 2009-09-25 16:37:33 -0700 | [diff] [blame] | 127 | void ProgramRasterState::deinit(Context *rsc) |
| 128 | { |
| 129 | mDefault.clear(); |
| 130 | mLast.clear(); |
| 131 | } |
| 132 | |
Jason Sams | ebfb436 | 2009-09-23 13:57:02 -0700 | [diff] [blame] | 133 | |
| 134 | namespace android { |
| 135 | namespace renderscript { |
| 136 | |
| 137 | RsProgramRaster rsi_ProgramRasterCreate(Context * rsc, RsElement in, RsElement out, |
| 138 | bool pointSmooth, |
| 139 | bool lineSmooth, |
| 140 | bool pointSprite) |
| 141 | { |
Jason Sams | a9e7a05 | 2009-09-25 14:51:22 -0700 | [diff] [blame] | 142 | ProgramRaster *pr = new ProgramRaster(rsc, |
Jason Sams | ebfb436 | 2009-09-23 13:57:02 -0700 | [diff] [blame] | 143 | pointSmooth, |
| 144 | lineSmooth, |
| 145 | pointSprite); |
| 146 | pr->incUserRef(); |
| 147 | return pr; |
| 148 | } |
| 149 | |
| 150 | void rsi_ProgramRasterSetPointSize(Context * rsc, RsProgramRaster vpr, float s) |
| 151 | { |
| 152 | ProgramRaster *pr = static_cast<ProgramRaster *>(vpr); |
| 153 | pr->setPointSize(s); |
| 154 | } |
| 155 | |
| 156 | void 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 | |