Jason Sams | 1aa5a4e | 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 | |
Alex Sakhartchouk | fb6b614 | 2010-05-21 12:53:13 -0700 | [diff] [blame] | 17 | #ifndef ANDROID_RS_BUILD_FOR_HOST |
Jason Sams | 1aa5a4e | 2009-06-22 17:15:15 -0700 | [diff] [blame] | 18 | #include "rsContext.h" |
Jason Sams | b5909ce | 2009-07-21 12:20:54 -0700 | [diff] [blame] | 19 | #include <GLES/gl.h> |
Alex Sakhartchouk | fb6b614 | 2010-05-21 12:53:13 -0700 | [diff] [blame] | 20 | #else |
| 21 | #include "rsContextHostStub.h" |
| 22 | #include <OpenGL/gl.h> |
| 23 | #endif //ANDROID_RS_BUILD_FOR_HOST |
Jason Sams | b5909ce | 2009-07-21 12:20:54 -0700 | [diff] [blame] | 24 | |
Jason Sams | 1aa5a4e | 2009-06-22 17:15:15 -0700 | [diff] [blame] | 25 | using namespace android; |
| 26 | using namespace android::renderscript; |
| 27 | |
| 28 | |
Jason Sams | e514b45 | 2009-09-25 14:51:22 -0700 | [diff] [blame] | 29 | Light::Light(Context *rsc, bool isLocal, bool isMono) : ObjectBase(rsc) |
Jason Sams | 1aa5a4e | 2009-06-22 17:15:15 -0700 | [diff] [blame] | 30 | { |
Jason Sams | f2649a9 | 2009-09-25 16:37:33 -0700 | [diff] [blame] | 31 | mAllocFile = __FILE__; |
| 32 | mAllocLine = __LINE__; |
Jason Sams | 1aa5a4e | 2009-06-22 17:15:15 -0700 | [diff] [blame] | 33 | mIsLocal = isLocal; |
| 34 | mIsMono = isMono; |
| 35 | |
Jason Sams | b5909ce | 2009-07-21 12:20:54 -0700 | [diff] [blame] | 36 | mPosition[0] = 0; |
| 37 | mPosition[1] = 0; |
| 38 | mPosition[2] = 1; |
| 39 | mPosition[3] = 0; |
Jason Sams | 1aa5a4e | 2009-06-22 17:15:15 -0700 | [diff] [blame] | 40 | |
Jason Sams | b5909ce | 2009-07-21 12:20:54 -0700 | [diff] [blame] | 41 | mColor[0] = 1.f; |
| 42 | mColor[1] = 1.f; |
| 43 | mColor[2] = 1.f; |
| 44 | mColor[3] = 1.f; |
Jason Sams | 1aa5a4e | 2009-06-22 17:15:15 -0700 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | Light::~Light() |
| 48 | { |
| 49 | } |
| 50 | |
| 51 | void Light::setPosition(float x, float y, float z) |
| 52 | { |
Jason Sams | b5909ce | 2009-07-21 12:20:54 -0700 | [diff] [blame] | 53 | mPosition[0] = x; |
| 54 | mPosition[1] = y; |
| 55 | mPosition[2] = z; |
Jason Sams | 1aa5a4e | 2009-06-22 17:15:15 -0700 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | void Light::setColor(float r, float g, float b) |
| 59 | { |
Jason Sams | b5909ce | 2009-07-21 12:20:54 -0700 | [diff] [blame] | 60 | mColor[0] = r; |
| 61 | mColor[1] = g; |
| 62 | mColor[2] = b; |
| 63 | } |
| 64 | |
| 65 | void Light::setupGL(uint32_t num) const |
| 66 | { |
| 67 | glLightfv(GL_LIGHT0 + num, GL_DIFFUSE, mColor); |
| 68 | glLightfv(GL_LIGHT0 + num, GL_SPECULAR, mColor); |
| 69 | glLightfv(GL_LIGHT0 + num, GL_POSITION, mPosition); |
Jason Sams | 1aa5a4e | 2009-06-22 17:15:15 -0700 | [diff] [blame] | 70 | } |
| 71 | |
Alex Sakhartchouk | fb6b614 | 2010-05-21 12:53:13 -0700 | [diff] [blame] | 72 | void Light::serialize(OStream *stream) const |
| 73 | { |
| 74 | |
| 75 | } |
| 76 | |
| 77 | Light *Light::createFromStream(Context *rsc, IStream *stream) |
| 78 | { |
| 79 | return NULL; |
| 80 | } |
| 81 | |
Jason Sams | 1aa5a4e | 2009-06-22 17:15:15 -0700 | [diff] [blame] | 82 | //////////////////////////////////////////// |
| 83 | |
| 84 | LightState::LightState() |
| 85 | { |
| 86 | clear(); |
| 87 | } |
| 88 | |
| 89 | LightState::~LightState() |
| 90 | { |
| 91 | } |
| 92 | |
| 93 | void LightState::clear() |
| 94 | { |
| 95 | mIsLocal = false; |
| 96 | mIsMono = false; |
| 97 | } |
| 98 | |
| 99 | |
| 100 | //////////////////////////////////////////////////// |
Jason Sams | 707aaf3 | 2009-08-18 14:14:24 -0700 | [diff] [blame] | 101 | // |
Jason Sams | 1aa5a4e | 2009-06-22 17:15:15 -0700 | [diff] [blame] | 102 | |
| 103 | namespace android { |
| 104 | namespace renderscript { |
| 105 | |
| 106 | void rsi_LightBegin(Context *rsc) |
| 107 | { |
| 108 | rsc->mStateLight.clear(); |
| 109 | } |
| 110 | |
| 111 | void rsi_LightSetLocal(Context *rsc, bool isLocal) |
| 112 | { |
| 113 | rsc->mStateLight.mIsLocal = isLocal; |
| 114 | } |
| 115 | |
| 116 | void rsi_LightSetMonochromatic(Context *rsc, bool isMono) |
| 117 | { |
| 118 | rsc->mStateLight.mIsMono = isMono; |
| 119 | } |
| 120 | |
| 121 | RsLight rsi_LightCreate(Context *rsc) |
| 122 | { |
Jason Sams | e514b45 | 2009-09-25 14:51:22 -0700 | [diff] [blame] | 123 | Light *l = new Light(rsc, rsc->mStateLight.mIsLocal, |
Jason Sams | 1aa5a4e | 2009-06-22 17:15:15 -0700 | [diff] [blame] | 124 | rsc->mStateLight.mIsMono); |
Jason Sams | 9397e30 | 2009-08-27 20:23:34 -0700 | [diff] [blame] | 125 | l->incUserRef(); |
Jason Sams | 1aa5a4e | 2009-06-22 17:15:15 -0700 | [diff] [blame] | 126 | return l; |
| 127 | } |
| 128 | |
Jason Sams | 1aa5a4e | 2009-06-22 17:15:15 -0700 | [diff] [blame] | 129 | void rsi_LightSetColor(Context *rsc, RsLight vl, float r, float g, float b) |
| 130 | { |
| 131 | Light *l = static_cast<Light *>(vl); |
| 132 | l->setColor(r, g, b); |
| 133 | } |
| 134 | |
| 135 | void rsi_LightSetPosition(Context *rsc, RsLight vl, float x, float y, float z) |
| 136 | { |
| 137 | Light *l = static_cast<Light *>(vl); |
| 138 | l->setPosition(x, y, z); |
| 139 | } |
| 140 | |
| 141 | |
| 142 | |
| 143 | } |
| 144 | } |