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 ProgramRaster(Context * rsc,Element * in,Element * out,bool pointSmooth,bool lineSmooth,bool pointSprite)27 ProgramRaster::ProgramRaster(Context *rsc, 28 Element *in, 29 Element *out, 30 bool pointSmooth, 31 bool lineSmooth, 32 bool pointSprite) : 33 Program(rsc, in, out) 34 { 35 mAllocFile = __FILE__; 36 mAllocLine = __LINE__; 37 mPointSmooth = pointSmooth; 38 mLineSmooth = lineSmooth; 39 mPointSprite = pointSprite; 40 41 mPointSize = 1.0f; 42 mLineWidth = 1.0f; 43 } 44 ~ProgramRaster()45 ProgramRaster::~ProgramRaster() 46 { 47 } 48 setLineWidth(float s)49 void ProgramRaster::setLineWidth(float s) 50 { 51 mLineWidth = s; 52 } 53 setPointSize(float s)54 void ProgramRaster::setPointSize(float s) 55 { 56 mPointSize = s; 57 } 58 setupGL(const Context * rsc,ProgramRasterState * state)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 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 { 77 glDisable(GL_LINE_SMOOTH); 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 89 90 ProgramRasterState()91 ProgramRasterState::ProgramRasterState() 92 { 93 } 94 ~ProgramRasterState()95 ProgramRasterState::~ProgramRasterState() 96 { 97 } 98 init(Context * rsc,int32_t w,int32_t h)99 void ProgramRasterState::init(Context *rsc, int32_t w, int32_t h) 100 { 101 ProgramRaster *pr = new ProgramRaster(rsc, NULL, NULL, false, false, false); 102 mDefault.set(pr); 103 } 104 deinit(Context * rsc)105 void ProgramRasterState::deinit(Context *rsc) 106 { 107 mDefault.clear(); 108 mLast.clear(); 109 } 110 111 112 namespace android { 113 namespace renderscript { 114 rsi_ProgramRasterCreate(Context * rsc,RsElement in,RsElement out,bool pointSmooth,bool lineSmooth,bool pointSprite)115 RsProgramRaster rsi_ProgramRasterCreate(Context * rsc, RsElement in, RsElement out, 116 bool pointSmooth, 117 bool lineSmooth, 118 bool pointSprite) 119 { 120 ProgramRaster *pr = new ProgramRaster(rsc, 121 static_cast<Element *>(in), 122 static_cast<Element *>(out), 123 pointSmooth, 124 lineSmooth, 125 pointSprite); 126 pr->incUserRef(); 127 return pr; 128 } 129 rsi_ProgramRasterSetPointSize(Context * rsc,RsProgramRaster vpr,float s)130 void rsi_ProgramRasterSetPointSize(Context * rsc, RsProgramRaster vpr, float s) 131 { 132 ProgramRaster *pr = static_cast<ProgramRaster *>(vpr); 133 pr->setPointSize(s); 134 } 135 rsi_ProgramRasterSetLineWidth(Context * rsc,RsProgramRaster vpr,float s)136 void rsi_ProgramRasterSetLineWidth(Context * rsc, RsProgramRaster vpr, float s) 137 { 138 ProgramRaster *pr = static_cast<ProgramRaster *>(vpr); 139 pr->setLineWidth(s); 140 } 141 142 143 } 144 } 145 146