Home | History | Annotate | Download | only in rs
      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 #include <GLES/gl.h>
     20 
     21 using namespace android;
     22 using namespace android::renderscript;
     23 
     24 
     25 Light::Light(Context *rsc, bool isLocal, bool isMono) : ObjectBase(rsc)
     26 {
     27     mAllocFile = __FILE__;
     28     mAllocLine = __LINE__;
     29     mIsLocal = isLocal;
     30     mIsMono = isMono;
     31 
     32     mPosition[0] = 0;
     33     mPosition[1] = 0;
     34     mPosition[2] = 1;
     35     mPosition[3] = 0;
     36 
     37     mColor[0] = 1.f;
     38     mColor[1] = 1.f;
     39     mColor[2] = 1.f;
     40     mColor[3] = 1.f;
     41 }
     42 
     43 Light::~Light()
     44 {
     45 }
     46 
     47 void Light::setPosition(float x, float y, float z)
     48 {
     49     mPosition[0] = x;
     50     mPosition[1] = y;
     51     mPosition[2] = z;
     52 }
     53 
     54 void Light::setColor(float r, float g, float b)
     55 {
     56     mColor[0] = r;
     57     mColor[1] = g;
     58     mColor[2] = b;
     59 }
     60 
     61 void 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);
     66 }
     67 
     68 ////////////////////////////////////////////
     69 
     70 LightState::LightState()
     71 {
     72     clear();
     73 }
     74 
     75 LightState::~LightState()
     76 {
     77 }
     78 
     79 void LightState::clear()
     80 {
     81     mIsLocal = false;
     82     mIsMono = false;
     83 }
     84 
     85 
     86 ////////////////////////////////////////////////////
     87 //
     88 
     89 namespace android {
     90 namespace renderscript {
     91 
     92 void rsi_LightBegin(Context *rsc)
     93 {
     94     rsc->mStateLight.clear();
     95 }
     96 
     97 void rsi_LightSetLocal(Context *rsc, bool isLocal)
     98 {
     99     rsc->mStateLight.mIsLocal = isLocal;
    100 }
    101 
    102 void rsi_LightSetMonochromatic(Context *rsc, bool isMono)
    103 {
    104     rsc->mStateLight.mIsMono = isMono;
    105 }
    106 
    107 RsLight rsi_LightCreate(Context *rsc)
    108 {
    109     Light *l = new Light(rsc, rsc->mStateLight.mIsLocal,
    110                          rsc->mStateLight.mIsMono);
    111     l->incUserRef();
    112     return l;
    113 }
    114 
    115 void 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 
    121 void 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 }
    131