Cinder  0.8.6
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DisplayList.h
Go to the documentation of this file.
1 /*
2  Copyright (c) 2010, The Barbarian Group
3  All rights reserved.
4 
5  Redistribution and use in source and binary forms, with or without modification, are permitted provided that
6  the following conditions are met:
7 
8  * Redistributions of source code must retain the above copyright notice, this list of conditions and
9  the following disclaimer.
10  * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
11  the following disclaimer in the documentation and/or other materials provided with the distribution.
12 
13  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
14  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
15  PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
16  ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
17  TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
18  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
19  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
20  POSSIBILITY OF SUCH DAMAGE.
21 */
22 
23 #pragma once
24 
25 #include "cinder/Matrix.h"
26 #include "cinder/gl/Material.h"
27 
28 namespace cinder {
29 namespace gl {
30 
31 class DisplayList {
32  protected:
33  struct Obj;
34 
35  public:
37  DisplayList( GLint aMode/* = GL_COMPILE*/ );
38 
39  void newList();
40  void endList();
41  int getID() const { return mObj->mID; }
42 
43  void draw() const;
44 
45  Matrix44f& getModelMatrix() { return mObj->mModelMatrix; }
46  const Matrix44f& getModelMatrix() const { return mObj->mModelMatrix; }
47 
48  void setMaterial( const Material &aMaterial ) { mObj->mMaterial = std::shared_ptr<Material>( new Material( aMaterial ) ); }
49  Material& getMaterial() { return *(mObj->mMaterial); }
50 
52  typedef std::shared_ptr<Obj> DisplayList::*unspecified_bool_type;
54  operator unspecified_bool_type() const { return ( mObj.get() == 0 ) ? 0 : &DisplayList::mObj; }
55  void reset() { mObj.reset(); }
57 
58  protected:
59  struct Obj {
60  Obj() : mID( 0 ) {}
61  ~Obj();
62 
66  std::shared_ptr<Material> mMaterial;
67  };
68 
69  std::shared_ptr<Obj> mObj;
70 };
71 
72 } // namespace gl
73 } // namespace cinder
int getID() const
Definition: DisplayList.h:41
Definition: Material.h:30
Definition: DisplayList.h:31
DisplayList()
Definition: DisplayList.h:36
std::shared_ptr< Obj > mObj
Definition: DisplayList.h:69
void reset()
Emulates shared_ptr-like behavior.
Definition: DisplayList.h:55
std::shared_ptr< Obj > DisplayList::* unspecified_bool_type
Emulates shared_ptr-like behavior.
Definition: DisplayList.h:53
void setMaterial(const Material &aMaterial)
Definition: DisplayList.h:48
unsigned int GLuint
Definition: gldx.h:55
Obj()
Definition: DisplayList.h:60
std::shared_ptr< Material > mMaterial
Definition: DisplayList.h:66
const Matrix44f & getModelMatrix() const
Definition: DisplayList.h:46
Matrix44f & getModelMatrix()
Definition: DisplayList.h:45
void newList()
Definition: DisplayList.cpp:44
Material & getMaterial()
Definition: DisplayList.h:49
GLuint mID
Definition: DisplayList.h:63
Definition: DisplayList.h:59
void endList()
Definition: DisplayList.cpp:49
int GLint
Definition: gldx.h:51
void draw() const
Definition: DisplayList.cpp:54
Matrix44f mModelMatrix
Definition: DisplayList.h:65
GLint mMode
Definition: DisplayList.h:64
~Obj()
Definition: DisplayList.cpp:30