shader_lightlist.h

Go to the documentation of this file.
00001 
00002 // Copyright 1986-2009 by mental images GmbH, Fasanenstr. 81, D-10623 Berlin,
00003 // Germany. All rights reserved.
00005 // Created:     27.02.08
00006 // Module:      api
00007 // Purpose:     mental ray C++ shader interface extensions
00009 
00018 
00019 
00020 #ifndef SHADER_LIGHTLIST_H
00021 #define SHADER_LIGHTLIST_H
00022 
00023 #include "mi_shader_if.h"
00024 
00025 namespace mi {
00026 namespace shader_v3 {
00027 
00028 
00055 class LightIterator {
00056 public:
00080     LightIterator(
00081         miState*        state,
00082         miTag*          shader_light_list = 0,
00083         int             n_shader_lights = 0,
00084         int             version = mi_ray_interface_version);
00085 
00106     LightIterator(
00107         miState*        state,
00108         const miVector  &axis,
00109         miScalar        spread_cos,
00110         miTag*          shader_light_list = 0,
00111         int             n_shader_lights = 0,
00112         int             version = mi_ray_interface_version);
00113 
00114 
00121     LightIterator(const LightIterator &iter);
00122 
00127     ~LightIterator();
00128 
00136     miTag operator*() const;
00137 
00151     LightList* operator->() const;
00152 
00160     const LightIterator& operator++();
00161 
00171     LightIterator operator++(int);
00172 
00177     bool at_end() const;
00178 
00188     const LightIterator &operator=(const LightIterator &iter);
00189 
00196     bool operator==(const LightIterator &iter) const;
00197 
00204     bool operator!=(const LightIterator &iter) const;
00205 
00206 private:
00210     LightList* m_list;
00211 
00215     size_t m_current;
00216 };
00217 
00218 
00228 class LightList {
00229 public:
00230 
00240     virtual size_t set_current(size_t current)          = 0;
00241 
00247     virtual size_t get_current() const                  = 0;
00248 
00255     virtual bool sample()                               = 0;
00256 
00261     virtual miScalar get_dot_nl() const                 = 0;
00262 
00267     virtual const miVector& get_direction() const       = 0;
00268 
00277     virtual void get_contribution(miColor *c) const     = 0;
00278 
00287     virtual void get_contribution(miSpectrum *s) const  = 0;
00288 
00296     virtual int get_number_of_samples() const           = 0;
00297 
00306     virtual miTag get_light_tag(size_t current) const   = 0;
00307 
00311     virtual size_t get_number_of_lights() const         = 0;
00312 
00318     virtual void connect()                              = 0;
00319 
00325     virtual void release()                              = 0;
00326 }; 
00327 
00328 
00329 //-----------------------------------------------------------------------------
00330 // inline implementation for LightIterator methods
00331 //-----------------------------------------------------------------------------
00332 
00333 inline LightIterator::LightIterator(
00334     miState             *state,
00335     const miVector      &axis,
00336     miScalar            spread_cos,
00337     miTag               *shader_light_list, 
00338     int                 n_shader_lights,
00339     int                 version)
00340 : m_list(0)
00341 , m_current(0)
00342 {
00343     Interface* iface = Interface::get(version);
00344     m_list = iface->createLightList(state, axis, spread_cos, shader_light_list, n_shader_lights);
00345     iface->release();
00346 }
00347 
00348 inline LightIterator::LightIterator(
00349     miState             *state,
00350     miTag               *shader_light_list, 
00351     int                 n_shader_lights,
00352     int                 version)
00353 : m_list(0)
00354 , m_current(0)
00355 {
00356     Interface* iface = Interface::get(version);
00357     m_list = iface->createLightList(state, state->normal, 0, shader_light_list, n_shader_lights);
00358     iface->release();
00359 }
00360 
00361 inline LightIterator::LightIterator(const LightIterator &iter) 
00362 : m_list(iter.m_list)
00363 , m_current(iter.m_current)
00364 { 
00365     if(m_list) m_list->connect();  // maintain reference count 
00366 }
00367 
00368 inline LightIterator::~LightIterator() 
00369 {
00370     if(m_list) m_list->release();  // maintain reference count
00371 }
00372 
00373 inline const LightIterator& LightIterator::operator=(const LightIterator &iter)
00374 {
00375     if(m_list != iter.m_list) {
00376         // need the compare above, otherwise the release might delete the list
00377         // and the connect below would be invalid.
00378         m_list->release();
00379         m_list = iter.m_list;
00380         m_list->connect();
00381     }
00382     m_current = iter.m_current;
00383     return *this;
00384 }
00385 
00386 inline miTag LightIterator::operator*() const 
00387 {
00388     return m_list->get_light_tag(m_current);
00389 }
00390 
00391 inline LightList* LightIterator::operator->() const
00392 {
00393     m_list->set_current(m_current);
00394     return m_list;
00395 }
00396 
00397 inline const LightIterator& LightIterator::operator++() 
00398 {
00399     ++m_current;
00400     return *this;
00401 }
00402 
00403 inline LightIterator LightIterator::operator++(int)
00404 {
00405     LightIterator res(*this);
00406     ++m_current;
00407     return res;
00408 }
00409 
00410 inline bool LightIterator::at_end() const
00411 {
00412     return m_current == m_list->get_number_of_lights();
00413 }
00414 
00415 inline bool LightIterator::operator==(const LightIterator &iter) const 
00416 {
00417     return m_list == iter.m_list && m_current == iter.m_current;
00418 }
00419 
00420 inline bool LightIterator::operator!=(const LightIterator &iter) const 
00421 {
00422     return !this->operator==(iter);
00423 }
00424 
00425 
00426 }}
00427 
00428 #endif //SHADER_LIGHTLIST_H

Copyright © 1986-2009 by mental images GmbH