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; |
Jason Sams | ebfb436 | 2009-09-23 13:57:02 -0700 | [diff] [blame] | 44 | mLineWidth = 1.0f; |
Alex Sakhartchouk | 80a4c2c | 2010-07-12 15:50:32 -0700 | [diff] [blame] | 45 | mCull = RS_CULL_BACK; |
Jason Sams | ebfb436 | 2009-09-23 13:57:02 -0700 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | ProgramRaster::~ProgramRaster() |
| 49 | { |
| 50 | } |
| 51 | |
| 52 | void ProgramRaster::setLineWidth(float s) |
| 53 | { |
| 54 | mLineWidth = s; |
Alex Sakhartchouk | 80a4c2c | 2010-07-12 15:50:32 -0700 | [diff] [blame] | 55 | mDirty = true; |
| 56 | } |
| 57 | |
| 58 | void ProgramRaster::setCullMode(RsCullMode mode) |
| 59 | { |
| 60 | mCull = mode; |
| 61 | mDirty = true; |
Jason Sams | ebfb436 | 2009-09-23 13:57:02 -0700 | [diff] [blame] | 62 | } |
| 63 | |
Jason Sams | ebfb436 | 2009-09-23 13:57:02 -0700 | [diff] [blame] | 64 | void ProgramRaster::setupGL(const Context *rsc, ProgramRasterState *state) |
| 65 | { |
Alex Sakhartchouk | 80a4c2c | 2010-07-12 15:50:32 -0700 | [diff] [blame] | 66 | if (state->mLast.get() == this && !mDirty) { |
Jason Sams | ebfb436 | 2009-09-23 13:57:02 -0700 | [diff] [blame] | 67 | return; |
| 68 | } |
| 69 | state->mLast.set(this); |
Alex Sakhartchouk | 80a4c2c | 2010-07-12 15:50:32 -0700 | [diff] [blame] | 70 | mDirty = false; |
Jason Sams | ebfb436 | 2009-09-23 13:57:02 -0700 | [diff] [blame] | 71 | |
Jason Sams | ebfb436 | 2009-09-23 13:57:02 -0700 | [diff] [blame] | 72 | 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 Sams | c7412b3 | 2009-10-14 15:43:53 -0700 | [diff] [blame] | 82 | glDisable(GL_LINE_SMOOTH); |
Jason Sams | ebfb436 | 2009-09-23 13:57:02 -0700 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | if (rsc->checkVersion1_1()) { |
Alex Sakhartchouk | aa7d288 | 2010-05-21 12:53:13 -0700 | [diff] [blame] | 86 | #ifndef ANDROID_RS_BUILD_FOR_HOST |
Jason Sams | ebfb436 | 2009-09-23 13:57:02 -0700 | [diff] [blame] | 87 | if (mPointSprite) { |
| 88 | glEnable(GL_POINT_SPRITE_OES); |
| 89 | } else { |
| 90 | glDisable(GL_POINT_SPRITE_OES); |
| 91 | } |
Alex Sakhartchouk | aa7d288 | 2010-05-21 12:53:13 -0700 | [diff] [blame] | 92 | #endif //ANDROID_RS_BUILD_FOR_HOST |
Jason Sams | ebfb436 | 2009-09-23 13:57:02 -0700 | [diff] [blame] | 93 | } |
Alex Sakhartchouk | 80a4c2c | 2010-07-12 15:50:32 -0700 | [diff] [blame] | 94 | |
| 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 Sams | ebfb436 | 2009-09-23 13:57:02 -0700 | [diff] [blame] | 108 | } |
| 109 | |
Jason Sams | bb51c40 | 2009-11-25 13:22:07 -0800 | [diff] [blame] | 110 | void ProgramRaster::setupGL2(const Context *rsc, ProgramRasterState *state) |
| 111 | { |
Alex Sakhartchouk | 80a4c2c | 2010-07-12 15:50:32 -0700 | [diff] [blame] | 112 | if (state->mLast.get() == this && !mDirty) { |
Jason Sams | bb51c40 | 2009-11-25 13:22:07 -0800 | [diff] [blame] | 113 | return; |
| 114 | } |
| 115 | state->mLast.set(this); |
Alex Sakhartchouk | 80a4c2c | 2010-07-12 15:50:32 -0700 | [diff] [blame] | 116 | 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 Sams | bb51c40 | 2009-11-25 13:22:07 -0800 | [diff] [blame] | 131 | } |
| 132 | |
Alex Sakhartchouk | aa7d288 | 2010-05-21 12:53:13 -0700 | [diff] [blame] | 133 | void ProgramRaster::serialize(OStream *stream) const |
| 134 | { |
Jason Sams | 53a93d5 | 2010-07-09 15:34:32 -0700 | [diff] [blame] | 135 | |
Alex Sakhartchouk | aa7d288 | 2010-05-21 12:53:13 -0700 | [diff] [blame] | 136 | } |
Jason Sams | ebfb436 | 2009-09-23 13:57:02 -0700 | [diff] [blame] | 137 | |
Alex Sakhartchouk | aa7d288 | 2010-05-21 12:53:13 -0700 | [diff] [blame] | 138 | ProgramRaster *ProgramRaster::createFromStream(Context *rsc, IStream *stream) |
| 139 | { |
| 140 | return NULL; |
| 141 | } |
Jason Sams | ebfb436 | 2009-09-23 13:57:02 -0700 | [diff] [blame] | 142 | |
| 143 | ProgramRasterState::ProgramRasterState() |
| 144 | { |
| 145 | } |
| 146 | |
| 147 | ProgramRasterState::~ProgramRasterState() |
| 148 | { |
| 149 | } |
| 150 | |
Jason Sams | f603d21 | 2010-05-14 15:30:29 -0700 | [diff] [blame] | 151 | void ProgramRasterState::init(Context *rsc) |
Jason Sams | ebfb436 | 2009-09-23 13:57:02 -0700 | [diff] [blame] | 152 | { |
Jason Sams | 0011bcf | 2009-12-15 12:58:36 -0800 | [diff] [blame] | 153 | ProgramRaster *pr = new ProgramRaster(rsc, false, false, false); |
Jason Sams | ebfb436 | 2009-09-23 13:57:02 -0700 | [diff] [blame] | 154 | mDefault.set(pr); |
| 155 | } |
| 156 | |
Jason Sams | 61f08d6 | 2009-09-25 16:37:33 -0700 | [diff] [blame] | 157 | void ProgramRasterState::deinit(Context *rsc) |
| 158 | { |
| 159 | mDefault.clear(); |
| 160 | mLast.clear(); |
| 161 | } |
| 162 | |
Jason Sams | ebfb436 | 2009-09-23 13:57:02 -0700 | [diff] [blame] | 163 | |
| 164 | namespace android { |
| 165 | namespace renderscript { |
| 166 | |
Alex Sakhartchouk | 80a4c2c | 2010-07-12 15:50:32 -0700 | [diff] [blame] | 167 | RsProgramRaster rsi_ProgramRasterCreate(Context * rsc, |
Jason Sams | ebfb436 | 2009-09-23 13:57:02 -0700 | [diff] [blame] | 168 | bool pointSmooth, |
| 169 | bool lineSmooth, |
| 170 | bool pointSprite) |
| 171 | { |
Jason Sams | a9e7a05 | 2009-09-25 14:51:22 -0700 | [diff] [blame] | 172 | ProgramRaster *pr = new ProgramRaster(rsc, |
Jason Sams | ebfb436 | 2009-09-23 13:57:02 -0700 | [diff] [blame] | 173 | pointSmooth, |
| 174 | lineSmooth, |
| 175 | pointSprite); |
| 176 | pr->incUserRef(); |
| 177 | return pr; |
| 178 | } |
| 179 | |
Jason Sams | ebfb436 | 2009-09-23 13:57:02 -0700 | [diff] [blame] | 180 | void rsi_ProgramRasterSetLineWidth(Context * rsc, RsProgramRaster vpr, float s) |
| 181 | { |
| 182 | ProgramRaster *pr = static_cast<ProgramRaster *>(vpr); |
| 183 | pr->setLineWidth(s); |
| 184 | } |
| 185 | |
Alex Sakhartchouk | 80a4c2c | 2010-07-12 15:50:32 -0700 | [diff] [blame] | 186 | void rsi_ProgramRasterSetCullMode(Context * rsc, RsProgramRaster vpr, RsCullMode mode) |
| 187 | { |
| 188 | ProgramRaster *pr = static_cast<ProgramRaster *>(vpr); |
| 189 | pr->setCullMode(mode); |
| 190 | } |
| 191 | |
Jason Sams | ebfb436 | 2009-09-23 13:57:02 -0700 | [diff] [blame] | 192 | |
| 193 | } |
| 194 | } |
| 195 | |