rsProgramRaster.cpp revision 225afd317e101a7be5fe02c0a86361146ea89f05
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 mPointSmooth = pointSmooth; 40 mLineSmooth = lineSmooth; 41 mPointSprite = pointSprite; 42 mLineWidth = 1.0f; 43 mCull = RS_CULL_BACK; 44} 45 46ProgramRaster::~ProgramRaster() 47{ 48} 49 50void ProgramRaster::setLineWidth(float s) 51{ 52 mLineWidth = s; 53 mDirty = true; 54} 55 56void ProgramRaster::setCullMode(RsCullMode mode) 57{ 58 mCull = mode; 59 mDirty = true; 60} 61 62void ProgramRaster::setupGL2(const Context *rsc, ProgramRasterState *state) 63{ 64 if (state->mLast.get() == this && !mDirty) { 65 return; 66 } 67 state->mLast.set(this); 68 mDirty = false; 69 70 switch(mCull) { 71 case RS_CULL_BACK: 72 glEnable(GL_CULL_FACE); 73 glCullFace(GL_BACK); 74 break; 75 case RS_CULL_FRONT: 76 glEnable(GL_CULL_FACE); 77 glCullFace(GL_FRONT); 78 break; 79 case RS_CULL_NONE: 80 glDisable(GL_CULL_FACE); 81 break; 82 } 83} 84 85void ProgramRaster::serialize(OStream *stream) const 86{ 87 88} 89 90ProgramRaster *ProgramRaster::createFromStream(Context *rsc, IStream *stream) 91{ 92 return NULL; 93} 94 95ProgramRasterState::ProgramRasterState() 96{ 97} 98 99ProgramRasterState::~ProgramRasterState() 100{ 101} 102 103void ProgramRasterState::init(Context *rsc) 104{ 105 ProgramRaster *pr = new ProgramRaster(rsc, false, false, false); 106 mDefault.set(pr); 107} 108 109void ProgramRasterState::deinit(Context *rsc) 110{ 111 mDefault.clear(); 112 mLast.clear(); 113} 114 115 116namespace android { 117namespace renderscript { 118 119RsProgramRaster rsi_ProgramRasterCreate(Context * rsc, 120 bool pointSmooth, 121 bool lineSmooth, 122 bool pointSprite) 123{ 124 ProgramRaster *pr = new ProgramRaster(rsc, 125 pointSmooth, 126 lineSmooth, 127 pointSprite); 128 pr->incUserRef(); 129 return pr; 130} 131 132void rsi_ProgramRasterSetLineWidth(Context * rsc, RsProgramRaster vpr, float s) 133{ 134 ProgramRaster *pr = static_cast<ProgramRaster *>(vpr); 135 pr->setLineWidth(s); 136} 137 138void rsi_ProgramRasterSetCullMode(Context * rsc, RsProgramRaster vpr, RsCullMode mode) 139{ 140 ProgramRaster *pr = static_cast<ProgramRaster *>(vpr); 141 pr->setCullMode(mode); 142} 143 144 145} 146} 147 148