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(Access_interface(version)->createLightList(
00341         state, axis, spread_cos, shader_light_list, n_shader_lights))
00342 , m_current(0)
00343 {
00344 }
00345 
00346 inline LightIterator::LightIterator(
00347     miState             *state,
00348     miTag               *shader_light_list, 
00349     int                 n_shader_lights,
00350     int                 version)
00351 : m_list(Access_interface(version)->createLightList(
00352         state, state->normal, 0, shader_light_list, n_shader_lights))
00353 , m_current(0)
00354 {
00355 }
00356 
00357 inline LightIterator::LightIterator(const LightIterator &iter) 
00358 : m_list(iter.m_list)
00359 , m_current(iter.m_current)
00360 { 
00361     if(m_list) m_list->connect();  // maintain reference count 
00362 }
00363 
00364 inline LightIterator::~LightIterator() 
00365 {
00366     if(m_list) m_list->release();  // maintain reference count
00367 }
00368 
00369 inline const LightIterator& LightIterator::operator=(const LightIterator &iter)
00370 {
00371     if(m_list != iter.m_list) {
00372         // need the compare above, otherwise the release might delete the list
00373         // and the connect below would be invalid.
00374         if (m_list) m_list->release();
00375         m_list = iter.m_list;
00376         m_list->connect();
00377     }
00378     m_current = iter.m_current;
00379     return *this;
00380 }
00381 
00382 inline miTag LightIterator::operator*() const 
00383 {
00384     return m_list->get_light_tag(m_current);
00385 }
00386 
00387 inline LightList* LightIterator::operator->() const
00388 {
00389     m_list->set_current(m_current);
00390     return m_list;
00391 }
00392 
00393 inline const LightIterator& LightIterator::operator++() 
00394 {
00395     ++m_current;
00396     return *this;
00397 }
00398 
00399 inline LightIterator LightIterator::operator++(int)
00400 {
00401     LightIterator res(*this);
00402     ++m_current;
00403     return res;
00404 }
00405 
00406 inline bool LightIterator::at_end() const
00407 {
00408     return m_current == m_list->get_number_of_lights();
00409 }
00410 
00411 inline bool LightIterator::operator==(const LightIterator &iter) const 
00412 {
00413     return m_list == iter.m_list && m_current == iter.m_current;
00414 }
00415 
00416 inline bool LightIterator::operator!=(const LightIterator &iter) const 
00417 {
00418     return !this->operator==(iter);
00419 }
00420 
00421 
00422 }}
00423 
00424 #endif //SHADER_LIGHTLIST_H

Copyright © 1986-2010 by mental images GmbH