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 | |
| 19 | using namespace android; |
| 20 | using namespace android::renderscript; |
| 21 | |
| 22 | |
| 23 | Light::Light(bool isLocal, bool isMono) |
| 24 | { |
| 25 | mIsLocal = isLocal; |
| 26 | mIsMono = isMono; |
| 27 | |
| 28 | mX = 0; |
| 29 | mY = 0; |
| 30 | mZ = 0; |
| 31 | |
| 32 | mR = 1.f; |
| 33 | mG = 1.f; |
| 34 | mB = 1.f; |
| 35 | } |
| 36 | |
| 37 | Light::~Light() |
| 38 | { |
| 39 | } |
| 40 | |
| 41 | void Light::setPosition(float x, float y, float z) |
| 42 | { |
| 43 | mX = x; |
| 44 | mY = y; |
| 45 | mZ = z; |
| 46 | } |
| 47 | |
| 48 | void Light::setColor(float r, float g, float b) |
| 49 | { |
| 50 | mR = r; |
| 51 | mG = g; |
| 52 | mB = b; |
| 53 | } |
| 54 | |
| 55 | //////////////////////////////////////////// |
| 56 | |
| 57 | LightState::LightState() |
| 58 | { |
| 59 | clear(); |
| 60 | } |
| 61 | |
| 62 | LightState::~LightState() |
| 63 | { |
| 64 | } |
| 65 | |
| 66 | void LightState::clear() |
| 67 | { |
| 68 | mIsLocal = false; |
| 69 | mIsMono = false; |
| 70 | } |
| 71 | |
| 72 | |
| 73 | //////////////////////////////////////////////////// |
| 74 | // |
| 75 | |
| 76 | namespace android { |
| 77 | namespace renderscript { |
| 78 | |
| 79 | void rsi_LightBegin(Context *rsc) |
| 80 | { |
| 81 | rsc->mStateLight.clear(); |
| 82 | } |
| 83 | |
| 84 | void rsi_LightSetLocal(Context *rsc, bool isLocal) |
| 85 | { |
| 86 | rsc->mStateLight.mIsLocal = isLocal; |
| 87 | } |
| 88 | |
| 89 | void rsi_LightSetMonochromatic(Context *rsc, bool isMono) |
| 90 | { |
| 91 | rsc->mStateLight.mIsMono = isMono; |
| 92 | } |
| 93 | |
| 94 | RsLight rsi_LightCreate(Context *rsc) |
| 95 | { |
| 96 | Light *l = new Light(rsc->mStateLight.mIsLocal, |
| 97 | rsc->mStateLight.mIsMono); |
| 98 | l->incRef(); |
| 99 | return l; |
| 100 | } |
| 101 | |
| 102 | void rsi_LightDestroy(Context *rsc, RsLight vl) |
| 103 | { |
| 104 | Light *l = static_cast<Light *>(vl); |
| 105 | l->decRef(); |
| 106 | } |
| 107 | |
| 108 | void rsi_LightSetColor(Context *rsc, RsLight vl, float r, float g, float b) |
| 109 | { |
| 110 | Light *l = static_cast<Light *>(vl); |
| 111 | l->setColor(r, g, b); |
| 112 | } |
| 113 | |
| 114 | void rsi_LightSetPosition(Context *rsc, RsLight vl, float x, float y, float z) |
| 115 | { |
| 116 | Light *l = static_cast<Light *>(vl); |
| 117 | l->setPosition(x, y, z); |
| 118 | } |
| 119 | |
| 120 | |
| 121 | |
| 122 | } |
| 123 | } |