rsProgramRaster.cpp revision fb6b614bcea88a587a7ea4530be45ff0ffa0210e
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#ifndef ANDROID_RS_BUILD_FOR_HOST 18#include "rsContext.h" 19#include <GLES/gl.h> 20#include <GLES/glext.h> 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" 28 29using namespace android; 30using namespace android::renderscript; 31 32 33ProgramRaster::ProgramRaster(Context *rsc, 34 bool pointSmooth, 35 bool lineSmooth, 36 bool pointSprite) : 37 Program(rsc) 38{ 39 mAllocFile = __FILE__; 40 mAllocLine = __LINE__; 41 mPointSmooth = pointSmooth; 42 mLineSmooth = lineSmooth; 43 mPointSprite = pointSprite; 44 45 mPointSize = 1.0f; 46 mLineWidth = 1.0f; 47} 48 49ProgramRaster::~ProgramRaster() 50{ 51} 52 53void ProgramRaster::setLineWidth(float s) 54{ 55 mLineWidth = s; 56} 57 58void ProgramRaster::setPointSize(float s) 59{ 60 mPointSize = s; 61} 62 63void ProgramRaster::setupGL(const Context *rsc, ProgramRasterState *state) 64{ 65 if (state->mLast.get() == this) { 66 return; 67 } 68 state->mLast.set(this); 69 70 glPointSize(mPointSize); 71 if (mPointSmooth) { 72 glEnable(GL_POINT_SMOOTH); 73 } else { 74 glDisable(GL_POINT_SMOOTH); 75 } 76 77 glLineWidth(mLineWidth); 78 if (mLineSmooth) { 79 glEnable(GL_LINE_SMOOTH); 80 } else { 81 glDisable(GL_LINE_SMOOTH); 82 } 83 84 if (rsc->checkVersion1_1()) { 85#ifndef ANDROID_RS_BUILD_FOR_HOST 86 if (mPointSprite) { 87 glEnable(GL_POINT_SPRITE_OES); 88 } else { 89 glDisable(GL_POINT_SPRITE_OES); 90 } 91#endif //ANDROID_RS_BUILD_FOR_HOST 92 } 93} 94 95void ProgramRaster::setupGL2(const Context *rsc, ProgramRasterState *state) 96{ 97 if (state->mLast.get() == this) { 98 return; 99 } 100 state->mLast.set(this); 101} 102 103void ProgramRaster::serialize(OStream *stream) const 104{ 105 106} 107 108ProgramRaster *ProgramRaster::createFromStream(Context *rsc, IStream *stream) 109{ 110 return NULL; 111} 112 113ProgramRasterState::ProgramRasterState() 114{ 115} 116 117ProgramRasterState::~ProgramRasterState() 118{ 119} 120 121void ProgramRasterState::init(Context *rsc) 122{ 123 ProgramRaster *pr = new ProgramRaster(rsc, false, false, false); 124 mDefault.set(pr); 125} 126 127void ProgramRasterState::deinit(Context *rsc) 128{ 129 mDefault.clear(); 130 mLast.clear(); 131} 132 133 134namespace android { 135namespace renderscript { 136 137RsProgramRaster rsi_ProgramRasterCreate(Context * rsc, RsElement in, RsElement out, 138 bool pointSmooth, 139 bool lineSmooth, 140 bool pointSprite) 141{ 142 ProgramRaster *pr = new ProgramRaster(rsc, 143 pointSmooth, 144 lineSmooth, 145 pointSprite); 146 pr->incUserRef(); 147 return pr; 148} 149 150void rsi_ProgramRasterSetPointSize(Context * rsc, RsProgramRaster vpr, float s) 151{ 152 ProgramRaster *pr = static_cast<ProgramRaster *>(vpr); 153 pr->setPointSize(s); 154} 155 156void rsi_ProgramRasterSetLineWidth(Context * rsc, RsProgramRaster vpr, float s) 157{ 158 ProgramRaster *pr = static_cast<ProgramRaster *>(vpr); 159 pr->setLineWidth(s); 160} 161 162 163} 164} 165 166