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