blob: f2b5b9af7d4bdd18830aec161b66f2c63bfaf737 [file] [log] [blame]
Jason Sams5fd09d82009-09-23 13:57:02 -07001/*
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
Alex Sakhartchoukfb6b6142010-05-21 12:53:13 -070017#ifndef ANDROID_RS_BUILD_FOR_HOST
Jason Sams5fd09d82009-09-23 13:57:02 -070018#include "rsContext.h"
Jason Sams5fd09d82009-09-23 13:57:02 -070019#include <GLES/gl.h>
20#include <GLES/glext.h>
Alex Sakhartchoukfb6b6142010-05-21 12:53:13 -070021#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"
Jason Sams5fd09d82009-09-23 13:57:02 -070028
29using namespace android;
30using namespace android::renderscript;
31
32
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -080033ProgramRaster::ProgramRaster(Context *rsc, bool pointSmooth,
34 bool lineSmooth, bool pointSprite)
35 : Program(rsc) {
36
Jason Sams5fd09d82009-09-23 13:57:02 -070037 mPointSmooth = pointSmooth;
38 mLineSmooth = lineSmooth;
39 mPointSprite = pointSprite;
Jason Sams5fd09d82009-09-23 13:57:02 -070040 mLineWidth = 1.0f;
Alex Sakhartchoukd18c7442010-07-12 15:50:32 -070041 mCull = RS_CULL_BACK;
Jason Sams5fd09d82009-09-23 13:57:02 -070042}
43
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -080044ProgramRaster::~ProgramRaster() {
Jason Sams5fd09d82009-09-23 13:57:02 -070045}
46
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -080047void ProgramRaster::setLineWidth(float s) {
Jason Sams5fd09d82009-09-23 13:57:02 -070048 mLineWidth = s;
Alex Sakhartchoukd18c7442010-07-12 15:50:32 -070049 mDirty = true;
50}
51
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -080052void ProgramRaster::setCullMode(RsCullMode mode) {
Alex Sakhartchoukd18c7442010-07-12 15:50:32 -070053 mCull = mode;
54 mDirty = true;
Jason Sams5fd09d82009-09-23 13:57:02 -070055}
56
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -080057void ProgramRaster::setupGL2(const Context *rsc, ProgramRasterState *state) {
Alex Sakhartchoukd18c7442010-07-12 15:50:32 -070058 if (state->mLast.get() == this && !mDirty) {
Jason Samsc460e552009-11-25 13:22:07 -080059 return;
60 }
61 state->mLast.set(this);
Alex Sakhartchoukd18c7442010-07-12 15:50:32 -070062 mDirty = false;
63
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -080064 switch (mCull) {
Alex Sakhartchoukd18c7442010-07-12 15:50:32 -070065 case RS_CULL_BACK:
66 glEnable(GL_CULL_FACE);
67 glCullFace(GL_BACK);
68 break;
69 case RS_CULL_FRONT:
70 glEnable(GL_CULL_FACE);
71 glCullFace(GL_FRONT);
72 break;
73 case RS_CULL_NONE:
74 glDisable(GL_CULL_FACE);
75 break;
76 }
Jason Samsc460e552009-11-25 13:22:07 -080077}
78
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -080079void ProgramRaster::serialize(OStream *stream) const {
Alex Sakhartchoukfb6b6142010-05-21 12:53:13 -070080}
Jason Sams5fd09d82009-09-23 13:57:02 -070081
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -080082ProgramRaster *ProgramRaster::createFromStream(Context *rsc, IStream *stream) {
Alex Sakhartchoukfb6b6142010-05-21 12:53:13 -070083 return NULL;
84}
Jason Sams5fd09d82009-09-23 13:57:02 -070085
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -080086ProgramRasterState::ProgramRasterState() {
Jason Sams5fd09d82009-09-23 13:57:02 -070087}
88
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -080089ProgramRasterState::~ProgramRasterState() {
Jason Sams5fd09d82009-09-23 13:57:02 -070090}
91
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -080092void ProgramRasterState::init(Context *rsc) {
Jason Sams4815c0d2009-12-15 12:58:36 -080093 ProgramRaster *pr = new ProgramRaster(rsc, false, false, false);
Jason Sams5fd09d82009-09-23 13:57:02 -070094 mDefault.set(pr);
95}
96
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -080097void ProgramRasterState::deinit(Context *rsc) {
Jason Samsf2649a92009-09-25 16:37:33 -070098 mDefault.clear();
99 mLast.clear();
100}
101
Jason Sams5fd09d82009-09-23 13:57:02 -0700102namespace android {
103namespace renderscript {
104
Alex Sakhartchoukd18c7442010-07-12 15:50:32 -0700105RsProgramRaster rsi_ProgramRasterCreate(Context * rsc,
Jason Sams5fd09d82009-09-23 13:57:02 -0700106 bool pointSmooth,
107 bool lineSmooth,
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800108 bool pointSprite) {
109 ProgramRaster *pr = new ProgramRaster(rsc, pointSmooth,
110 lineSmooth, pointSprite);
Jason Sams5fd09d82009-09-23 13:57:02 -0700111 pr->incUserRef();
112 return pr;
113}
114
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800115void rsi_ProgramRasterSetLineWidth(Context * rsc,
116 RsProgramRaster vpr,
117 float s) {
Jason Sams5fd09d82009-09-23 13:57:02 -0700118 ProgramRaster *pr = static_cast<ProgramRaster *>(vpr);
119 pr->setLineWidth(s);
120}
121
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800122void rsi_ProgramRasterSetCullMode(Context * rsc,
123 RsProgramRaster vpr,
124 RsCullMode mode) {
Alex Sakhartchoukd18c7442010-07-12 15:50:32 -0700125 ProgramRaster *pr = static_cast<ProgramRaster *>(vpr);
126 pr->setCullMode(mode);
127}
128
Jason Sams5fd09d82009-09-23 13:57:02 -0700129}
130}
131