blob: eab9a077ef89506ef557ca967886f6def9350b15 [file] [log] [blame]
Jason Sams1aa5a4e2009-06-22 17:15:15 -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 Sams1aa5a4e2009-06-22 17:15:15 -070018#include "rsContext.h"
Jason Samsb5909ce2009-07-21 12:20:54 -070019#include <GLES/gl.h>
Alex Sakhartchoukfb6b6142010-05-21 12:53:13 -070020#else
21#include "rsContextHostStub.h"
22#include <OpenGL/gl.h>
23#endif //ANDROID_RS_BUILD_FOR_HOST
Jason Samsb5909ce2009-07-21 12:20:54 -070024
Jason Sams1aa5a4e2009-06-22 17:15:15 -070025using namespace android;
26using namespace android::renderscript;
27
28
Jason Samse514b452009-09-25 14:51:22 -070029Light::Light(Context *rsc, bool isLocal, bool isMono) : ObjectBase(rsc)
Jason Sams1aa5a4e2009-06-22 17:15:15 -070030{
Jason Samsf2649a92009-09-25 16:37:33 -070031 mAllocFile = __FILE__;
32 mAllocLine = __LINE__;
Jason Sams1aa5a4e2009-06-22 17:15:15 -070033 mIsLocal = isLocal;
34 mIsMono = isMono;
35
Jason Samsb5909ce2009-07-21 12:20:54 -070036 mPosition[0] = 0;
37 mPosition[1] = 0;
38 mPosition[2] = 1;
39 mPosition[3] = 0;
Jason Sams1aa5a4e2009-06-22 17:15:15 -070040
Jason Samsb5909ce2009-07-21 12:20:54 -070041 mColor[0] = 1.f;
42 mColor[1] = 1.f;
43 mColor[2] = 1.f;
44 mColor[3] = 1.f;
Jason Sams1aa5a4e2009-06-22 17:15:15 -070045}
46
47Light::~Light()
48{
49}
50
51void Light::setPosition(float x, float y, float z)
52{
Jason Samsb5909ce2009-07-21 12:20:54 -070053 mPosition[0] = x;
54 mPosition[1] = y;
55 mPosition[2] = z;
Jason Sams1aa5a4e2009-06-22 17:15:15 -070056}
57
58void Light::setColor(float r, float g, float b)
59{
Jason Samsb5909ce2009-07-21 12:20:54 -070060 mColor[0] = r;
61 mColor[1] = g;
62 mColor[2] = b;
63}
64
65void 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 Sams1aa5a4e2009-06-22 17:15:15 -070070}
71
Alex Sakhartchoukfb6b6142010-05-21 12:53:13 -070072void Light::serialize(OStream *stream) const
73{
74
75}
76
77Light *Light::createFromStream(Context *rsc, IStream *stream)
78{
79 return NULL;
80}
81
Jason Sams1aa5a4e2009-06-22 17:15:15 -070082////////////////////////////////////////////
83
84LightState::LightState()
85{
86 clear();
87}
88
89LightState::~LightState()
90{
91}
92
93void LightState::clear()
94{
95 mIsLocal = false;
96 mIsMono = false;
97}
98
99
100////////////////////////////////////////////////////
Jason Sams707aaf32009-08-18 14:14:24 -0700101//
Jason Sams1aa5a4e2009-06-22 17:15:15 -0700102
103namespace android {
104namespace renderscript {
105
106void rsi_LightBegin(Context *rsc)
107{
108 rsc->mStateLight.clear();
109}
110
111void rsi_LightSetLocal(Context *rsc, bool isLocal)
112{
113 rsc->mStateLight.mIsLocal = isLocal;
114}
115
116void rsi_LightSetMonochromatic(Context *rsc, bool isMono)
117{
118 rsc->mStateLight.mIsMono = isMono;
119}
120
121RsLight rsi_LightCreate(Context *rsc)
122{
Jason Samse514b452009-09-25 14:51:22 -0700123 Light *l = new Light(rsc, rsc->mStateLight.mIsLocal,
Jason Sams1aa5a4e2009-06-22 17:15:15 -0700124 rsc->mStateLight.mIsMono);
Jason Sams9397e302009-08-27 20:23:34 -0700125 l->incUserRef();
Jason Sams1aa5a4e2009-06-22 17:15:15 -0700126 return l;
127}
128
Jason Sams1aa5a4e2009-06-22 17:15:15 -0700129void 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
135void 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}