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