shader_lightlist.h

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

Copyright © 1986-2008 by mental images GmbH