blob: 6f2cf3e7f7f609edce89e80f726de249a07228f9 [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
17#include "rsContext.h"
18
Jason Samsb5909ce2009-07-21 12:20:54 -070019#include <GLES/gl.h>
20
Jason Sams1aa5a4e2009-06-22 17:15:15 -070021using namespace android;
22using namespace android::renderscript;
23
24
Jason Samse514b452009-09-25 14:51:22 -070025Light::Light(Context *rsc, bool isLocal, bool isMono) : ObjectBase(rsc)
Jason Sams1aa5a4e2009-06-22 17:15:15 -070026{
Jason Samsf2649a92009-09-25 16:37:33 -070027 mAllocFile = __FILE__;
28 mAllocLine = __LINE__;
Jason Sams1aa5a4e2009-06-22 17:15:15 -070029 mIsLocal = isLocal;
30 mIsMono = isMono;
31
Jason Samsb5909ce2009-07-21 12:20:54 -070032 mPosition[0] = 0;
33 mPosition[1] = 0;
34 mPosition[2] = 1;
35 mPosition[3] = 0;
Jason Sams1aa5a4e2009-06-22 17:15:15 -070036
Jason Samsb5909ce2009-07-21 12:20:54 -070037 mColor[0] = 1.f;
38 mColor[1] = 1.f;
39 mColor[2] = 1.f;
40 mColor[3] = 1.f;
Jason Sams1aa5a4e2009-06-22 17:15:15 -070041}
42
43Light::~Light()
44{
45}
46
47void Light::setPosition(float x, float y, float z)
48{
Jason Samsb5909ce2009-07-21 12:20:54 -070049 mPosition[0] = x;
50 mPosition[1] = y;
51 mPosition[2] = z;
Jason Sams1aa5a4e2009-06-22 17:15:15 -070052}
53
54void Light::setColor(float r, float g, float b)
55{
Jason Samsb5909ce2009-07-21 12:20:54 -070056 mColor[0] = r;
57 mColor[1] = g;
58 mColor[2] = b;
59}
60
61void Light::setupGL(uint32_t num) const
62{
63 glLightfv(GL_LIGHT0 + num, GL_DIFFUSE, mColor);
64 glLightfv(GL_LIGHT0 + num, GL_SPECULAR, mColor);
65 glLightfv(GL_LIGHT0 + num, GL_POSITION, mPosition);
Jason Sams1aa5a4e2009-06-22 17:15:15 -070066}
67
68////////////////////////////////////////////
69
70LightState::LightState()
71{
72 clear();
73}
74
75LightState::~LightState()
76{
77}
78
79void LightState::clear()
80{
81 mIsLocal = false;
82 mIsMono = false;
83}
84
85
86////////////////////////////////////////////////////
Jason Sams707aaf32009-08-18 14:14:24 -070087//
Jason Sams1aa5a4e2009-06-22 17:15:15 -070088
89namespace android {
90namespace renderscript {
91
92void rsi_LightBegin(Context *rsc)
93{
94 rsc->mStateLight.clear();
95}
96
97void rsi_LightSetLocal(Context *rsc, bool isLocal)
98{
99 rsc->mStateLight.mIsLocal = isLocal;
100}
101
102void rsi_LightSetMonochromatic(Context *rsc, bool isMono)
103{
104 rsc->mStateLight.mIsMono = isMono;
105}
106
107RsLight rsi_LightCreate(Context *rsc)
108{
Jason Samse514b452009-09-25 14:51:22 -0700109 Light *l = new Light(rsc, rsc->mStateLight.mIsLocal,
Jason Sams1aa5a4e2009-06-22 17:15:15 -0700110 rsc->mStateLight.mIsMono);
Jason Sams9397e302009-08-27 20:23:34 -0700111 l->incUserRef();
Jason Sams1aa5a4e2009-06-22 17:15:15 -0700112 return l;
113}
114
Jason Sams1aa5a4e2009-06-22 17:15:15 -0700115void rsi_LightSetColor(Context *rsc, RsLight vl, float r, float g, float b)
116{
117 Light *l = static_cast<Light *>(vl);
118 l->setColor(r, g, b);
119}
120
121void rsi_LightSetPosition(Context *rsc, RsLight vl, float x, float y, float z)
122{
123 Light *l = static_cast<Light *>(vl);
124 l->setPosition(x, y, z);
125}
126
127
128
129}
130}