blob: 24b58b622ac6350d94d7013f80409d3c2782885e [file] [log] [blame]
Jason Sams4b962e52009-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
17#include "rsContext.h"
18
Jason Samsee411122009-07-21 12:20:54 -070019#include <GLES/gl.h>
20
Jason Sams4b962e52009-06-22 17:15:15 -070021using namespace android;
22using namespace android::renderscript;
23
24
25Light::Light(bool isLocal, bool isMono)
26{
27 mIsLocal = isLocal;
28 mIsMono = isMono;
29
Jason Samsee411122009-07-21 12:20:54 -070030 mPosition[0] = 0;
31 mPosition[1] = 0;
32 mPosition[2] = 1;
33 mPosition[3] = 0;
Jason Sams4b962e52009-06-22 17:15:15 -070034
Jason Samsee411122009-07-21 12:20:54 -070035 mColor[0] = 1.f;
36 mColor[1] = 1.f;
37 mColor[2] = 1.f;
38 mColor[3] = 1.f;
Jason Sams4b962e52009-06-22 17:15:15 -070039}
40
41Light::~Light()
42{
43}
44
45void Light::setPosition(float x, float y, float z)
46{
Jason Samsee411122009-07-21 12:20:54 -070047 mPosition[0] = x;
48 mPosition[1] = y;
49 mPosition[2] = z;
Jason Sams4b962e52009-06-22 17:15:15 -070050}
51
52void Light::setColor(float r, float g, float b)
53{
Jason Samsee411122009-07-21 12:20:54 -070054 mColor[0] = r;
55 mColor[1] = g;
56 mColor[2] = b;
57}
58
59void 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 Sams4b962e52009-06-22 17:15:15 -070064}
65
66////////////////////////////////////////////
67
68LightState::LightState()
69{
70 clear();
71}
72
73LightState::~LightState()
74{
75}
76
77void LightState::clear()
78{
79 mIsLocal = false;
80 mIsMono = false;
81}
82
83
84////////////////////////////////////////////////////
85//
86
87namespace android {
88namespace renderscript {
89
90void rsi_LightBegin(Context *rsc)
91{
92 rsc->mStateLight.clear();
93}
94
95void rsi_LightSetLocal(Context *rsc, bool isLocal)
96{
97 rsc->mStateLight.mIsLocal = isLocal;
98}
99
100void rsi_LightSetMonochromatic(Context *rsc, bool isMono)
101{
102 rsc->mStateLight.mIsMono = isMono;
103}
104
105RsLight rsi_LightCreate(Context *rsc)
106{
107 Light *l = new Light(rsc->mStateLight.mIsLocal,
108 rsc->mStateLight.mIsMono);
109 l->incRef();
110 return l;
111}
112
113void rsi_LightDestroy(Context *rsc, RsLight vl)
114{
115 Light *l = static_cast<Light *>(vl);
116 l->decRef();
117}
118
119void rsi_LightSetColor(Context *rsc, RsLight vl, float r, float g, float b)
120{
121 Light *l = static_cast<Light *>(vl);
122 l->setColor(r, g, b);
123}
124
125void rsi_LightSetPosition(Context *rsc, RsLight vl, float x, float y, float z)
126{
127 Light *l = static_cast<Light *>(vl);
128 l->setPosition(x, y, z);
129}
130
131
132
133}
134}