Jason Sams | 4b962e5 | 2009-06-22 17:15:15 -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 | |
Jason Sams | ee41112 | 2009-07-21 12:20:54 -0700 | [diff] [blame] | 19 | #include <GLES/gl.h> |
| 20 | |
Jason Sams | 4b962e5 | 2009-06-22 17:15:15 -0700 | [diff] [blame] | 21 | using namespace android; |
| 22 | using namespace android::renderscript; |
| 23 | |
| 24 | |
| 25 | Light::Light(bool isLocal, bool isMono) |
| 26 | { |
| 27 | mIsLocal = isLocal; |
| 28 | mIsMono = isMono; |
| 29 | |
Jason Sams | ee41112 | 2009-07-21 12:20:54 -0700 | [diff] [blame] | 30 | mPosition[0] = 0; |
| 31 | mPosition[1] = 0; |
| 32 | mPosition[2] = 1; |
| 33 | mPosition[3] = 0; |
Jason Sams | 4b962e5 | 2009-06-22 17:15:15 -0700 | [diff] [blame] | 34 | |
Jason Sams | ee41112 | 2009-07-21 12:20:54 -0700 | [diff] [blame] | 35 | mColor[0] = 1.f; |
| 36 | mColor[1] = 1.f; |
| 37 | mColor[2] = 1.f; |
| 38 | mColor[3] = 1.f; |
Jason Sams | 4b962e5 | 2009-06-22 17:15:15 -0700 | [diff] [blame] | 39 | } |
| 40 | |
| 41 | Light::~Light() |
| 42 | { |
| 43 | } |
| 44 | |
| 45 | void Light::setPosition(float x, float y, float z) |
| 46 | { |
Jason Sams | ee41112 | 2009-07-21 12:20:54 -0700 | [diff] [blame] | 47 | mPosition[0] = x; |
| 48 | mPosition[1] = y; |
| 49 | mPosition[2] = z; |
Jason Sams | 4b962e5 | 2009-06-22 17:15:15 -0700 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | void Light::setColor(float r, float g, float b) |
| 53 | { |
Jason Sams | ee41112 | 2009-07-21 12:20:54 -0700 | [diff] [blame] | 54 | mColor[0] = r; |
| 55 | mColor[1] = g; |
| 56 | mColor[2] = b; |
| 57 | } |
| 58 | |
| 59 | void Light::setupGL(uint32_t num) const |
| 60 | { |
| 61 | glLightfv(GL_LIGHT0 + num, GL_DIFFUSE, mColor); |
| 62 | glLightfv(GL_LIGHT0 + num, GL_SPECULAR, mColor); |
| 63 | glLightfv(GL_LIGHT0 + num, GL_POSITION, mPosition); |
Jason Sams | 4b962e5 | 2009-06-22 17:15:15 -0700 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | //////////////////////////////////////////// |
| 67 | |
| 68 | LightState::LightState() |
| 69 | { |
| 70 | clear(); |
| 71 | } |
| 72 | |
| 73 | LightState::~LightState() |
| 74 | { |
| 75 | } |
| 76 | |
| 77 | void LightState::clear() |
| 78 | { |
| 79 | mIsLocal = false; |
| 80 | mIsMono = false; |
| 81 | } |
| 82 | |
| 83 | |
| 84 | //////////////////////////////////////////////////// |
Jason Sams | 7ce033d | 2009-08-18 14:14:24 -0700 | [diff] [blame] | 85 | // |
Jason Sams | 4b962e5 | 2009-06-22 17:15:15 -0700 | [diff] [blame] | 86 | |
| 87 | namespace android { |
| 88 | namespace renderscript { |
| 89 | |
| 90 | void rsi_LightBegin(Context *rsc) |
| 91 | { |
| 92 | rsc->mStateLight.clear(); |
| 93 | } |
| 94 | |
| 95 | void rsi_LightSetLocal(Context *rsc, bool isLocal) |
| 96 | { |
| 97 | rsc->mStateLight.mIsLocal = isLocal; |
| 98 | } |
| 99 | |
| 100 | void rsi_LightSetMonochromatic(Context *rsc, bool isMono) |
| 101 | { |
| 102 | rsc->mStateLight.mIsMono = isMono; |
| 103 | } |
| 104 | |
| 105 | RsLight rsi_LightCreate(Context *rsc) |
| 106 | { |
| 107 | Light *l = new Light(rsc->mStateLight.mIsLocal, |
| 108 | rsc->mStateLight.mIsMono); |
Jason Sams | 07ae406 | 2009-08-27 20:23:34 -0700 | [diff] [blame] | 109 | l->incUserRef(); |
Jason Sams | 4b962e5 | 2009-06-22 17:15:15 -0700 | [diff] [blame] | 110 | return l; |
| 111 | } |
| 112 | |
Jason Sams | 4b962e5 | 2009-06-22 17:15:15 -0700 | [diff] [blame] | 113 | void rsi_LightSetColor(Context *rsc, RsLight vl, float r, float g, float b) |
| 114 | { |
| 115 | Light *l = static_cast<Light *>(vl); |
| 116 | l->setColor(r, g, b); |
| 117 | } |
| 118 | |
| 119 | void rsi_LightSetPosition(Context *rsc, RsLight vl, float x, float y, float z) |
| 120 | { |
| 121 | Light *l = static_cast<Light *>(vl); |
| 122 | l->setPosition(x, y, z); |
| 123 | } |
| 124 | |
| 125 | |
| 126 | |
| 127 | } |
| 128 | } |