Jason Sams | 5fd09d8 | 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 | fb6b614 | 2010-05-21 12:53:13 -0700 | [diff] [blame] | 17 | #ifndef ANDROID_RS_BUILD_FOR_HOST |
Jason Sams | 5fd09d8 | 2009-09-23 13:57:02 -0700 | [diff] [blame] | 18 | #include "rsContext.h" |
Jason Sams | 5fd09d8 | 2009-09-23 13:57:02 -0700 | [diff] [blame] | 19 | #include <GLES/gl.h> |
| 20 | #include <GLES/glext.h> |
Alex Sakhartchouk | fb6b614 | 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 | 5fd09d8 | 2009-09-23 13:57:02 -0700 | [diff] [blame] | 28 | |
| 29 | using namespace android; |
| 30 | using namespace android::renderscript; |
| 31 | |
| 32 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 33 | ProgramRaster::ProgramRaster(Context *rsc, bool pointSmooth, |
| 34 | bool lineSmooth, bool pointSprite) |
| 35 | : Program(rsc) { |
| 36 | |
Jason Sams | 5fd09d8 | 2009-09-23 13:57:02 -0700 | [diff] [blame] | 37 | mPointSmooth = pointSmooth; |
| 38 | mLineSmooth = lineSmooth; |
| 39 | mPointSprite = pointSprite; |
Jason Sams | 5fd09d8 | 2009-09-23 13:57:02 -0700 | [diff] [blame] | 40 | mLineWidth = 1.0f; |
Alex Sakhartchouk | d18c744 | 2010-07-12 15:50:32 -0700 | [diff] [blame] | 41 | mCull = RS_CULL_BACK; |
Jason Sams | 5fd09d8 | 2009-09-23 13:57:02 -0700 | [diff] [blame] | 42 | } |
| 43 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 44 | ProgramRaster::~ProgramRaster() { |
Jason Sams | 5fd09d8 | 2009-09-23 13:57:02 -0700 | [diff] [blame] | 45 | } |
| 46 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 47 | void ProgramRaster::setLineWidth(float s) { |
Jason Sams | 5fd09d8 | 2009-09-23 13:57:02 -0700 | [diff] [blame] | 48 | mLineWidth = s; |
Alex Sakhartchouk | d18c744 | 2010-07-12 15:50:32 -0700 | [diff] [blame] | 49 | mDirty = true; |
| 50 | } |
| 51 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 52 | void ProgramRaster::setCullMode(RsCullMode mode) { |
Alex Sakhartchouk | d18c744 | 2010-07-12 15:50:32 -0700 | [diff] [blame] | 53 | mCull = mode; |
| 54 | mDirty = true; |
Jason Sams | 5fd09d8 | 2009-09-23 13:57:02 -0700 | [diff] [blame] | 55 | } |
| 56 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 57 | void ProgramRaster::setupGL2(const Context *rsc, ProgramRasterState *state) { |
Alex Sakhartchouk | d18c744 | 2010-07-12 15:50:32 -0700 | [diff] [blame] | 58 | if (state->mLast.get() == this && !mDirty) { |
Jason Sams | c460e55 | 2009-11-25 13:22:07 -0800 | [diff] [blame] | 59 | return; |
| 60 | } |
| 61 | state->mLast.set(this); |
Alex Sakhartchouk | d18c744 | 2010-07-12 15:50:32 -0700 | [diff] [blame] | 62 | mDirty = false; |
| 63 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 64 | switch (mCull) { |
Alex Sakhartchouk | d18c744 | 2010-07-12 15:50:32 -0700 | [diff] [blame] | 65 | case RS_CULL_BACK: |
| 66 | glEnable(GL_CULL_FACE); |
| 67 | glCullFace(GL_BACK); |
| 68 | break; |
| 69 | case RS_CULL_FRONT: |
| 70 | glEnable(GL_CULL_FACE); |
| 71 | glCullFace(GL_FRONT); |
| 72 | break; |
| 73 | case RS_CULL_NONE: |
| 74 | glDisable(GL_CULL_FACE); |
| 75 | break; |
| 76 | } |
Jason Sams | c460e55 | 2009-11-25 13:22:07 -0800 | [diff] [blame] | 77 | } |
| 78 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 79 | void ProgramRaster::serialize(OStream *stream) const { |
Alex Sakhartchouk | fb6b614 | 2010-05-21 12:53:13 -0700 | [diff] [blame] | 80 | } |
Jason Sams | 5fd09d8 | 2009-09-23 13:57:02 -0700 | [diff] [blame] | 81 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 82 | ProgramRaster *ProgramRaster::createFromStream(Context *rsc, IStream *stream) { |
Alex Sakhartchouk | fb6b614 | 2010-05-21 12:53:13 -0700 | [diff] [blame] | 83 | return NULL; |
| 84 | } |
Jason Sams | 5fd09d8 | 2009-09-23 13:57:02 -0700 | [diff] [blame] | 85 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 86 | ProgramRasterState::ProgramRasterState() { |
Jason Sams | 5fd09d8 | 2009-09-23 13:57:02 -0700 | [diff] [blame] | 87 | } |
| 88 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 89 | ProgramRasterState::~ProgramRasterState() { |
Jason Sams | 5fd09d8 | 2009-09-23 13:57:02 -0700 | [diff] [blame] | 90 | } |
| 91 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 92 | void ProgramRasterState::init(Context *rsc) { |
Jason Sams | 4815c0d | 2009-12-15 12:58:36 -0800 | [diff] [blame] | 93 | ProgramRaster *pr = new ProgramRaster(rsc, false, false, false); |
Jason Sams | 5fd09d8 | 2009-09-23 13:57:02 -0700 | [diff] [blame] | 94 | mDefault.set(pr); |
| 95 | } |
| 96 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 97 | void ProgramRasterState::deinit(Context *rsc) { |
Jason Sams | f2649a9 | 2009-09-25 16:37:33 -0700 | [diff] [blame] | 98 | mDefault.clear(); |
| 99 | mLast.clear(); |
| 100 | } |
| 101 | |
Jason Sams | 5fd09d8 | 2009-09-23 13:57:02 -0700 | [diff] [blame] | 102 | namespace android { |
| 103 | namespace renderscript { |
| 104 | |
Alex Sakhartchouk | d18c744 | 2010-07-12 15:50:32 -0700 | [diff] [blame] | 105 | RsProgramRaster rsi_ProgramRasterCreate(Context * rsc, |
Jason Sams | 5fd09d8 | 2009-09-23 13:57:02 -0700 | [diff] [blame] | 106 | bool pointSmooth, |
| 107 | bool lineSmooth, |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 108 | bool pointSprite) { |
| 109 | ProgramRaster *pr = new ProgramRaster(rsc, pointSmooth, |
| 110 | lineSmooth, pointSprite); |
Jason Sams | 5fd09d8 | 2009-09-23 13:57:02 -0700 | [diff] [blame] | 111 | pr->incUserRef(); |
| 112 | return pr; |
| 113 | } |
| 114 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 115 | void rsi_ProgramRasterSetLineWidth(Context * rsc, |
| 116 | RsProgramRaster vpr, |
| 117 | float s) { |
Jason Sams | 5fd09d8 | 2009-09-23 13:57:02 -0700 | [diff] [blame] | 118 | ProgramRaster *pr = static_cast<ProgramRaster *>(vpr); |
| 119 | pr->setLineWidth(s); |
| 120 | } |
| 121 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 122 | void rsi_ProgramRasterSetCullMode(Context * rsc, |
| 123 | RsProgramRaster vpr, |
| 124 | RsCullMode mode) { |
Alex Sakhartchouk | d18c744 | 2010-07-12 15:50:32 -0700 | [diff] [blame] | 125 | ProgramRaster *pr = static_cast<ProgramRaster *>(vpr); |
| 126 | pr->setCullMode(mode); |
| 127 | } |
| 128 | |
Jason Sams | 5fd09d8 | 2009-09-23 13:57:02 -0700 | [diff] [blame] | 129 | } |
| 130 | } |
| 131 | |