Allolib  1.0
C++ Components For Interactive Multimedia
al_GPUObject.hpp
1 #ifndef INCLUDE_AL_GRAPHICS_GPUOBJECT_H
2 #define INCLUDE_AL_GRAPHICS_GPUOBJECT_H
3 
4 /* Allocore --
5  Multimedia / virtual environment application class library
6 
7  Copyright (C) 2009. AlloSphere Research Group, Media Arts & Technology, UCSB.
8  Copyright (C) 2012. The Regents of the University of California.
9  All rights reserved.
10 
11  Redistribution and use in source and binary forms, with or without
12  modification, are permitted provided that the following conditions are met:
13 
14  Redistributions of source code must retain the above copyright notice,
15  this list of conditions and the following disclaimer.
16 
17  Redistributions in binary form must reproduce the above copyright
18  notice, this list of conditions and the following disclaimer in the
19  documentation and/or other materials provided with the distribution.
20 
21  Neither the name of the University of California nor the names of its
22  contributors may be used to endorse or promote products derived from
23  this software without specific prior written permission.
24 
25  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
26  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
29  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35  POSSIBILITY OF SUCH DAMAGE.
36 
37 
38  File description:
39  Ensures that GPU resources are valid even when a rendering context is
40  rebuilt.
41 
42  File author(s):
43  Graham Wakefield, 2010, grrrwaaa@gmail.com
44  Lance Putnam, 2010, putnam.lance@gmail.com
45  Keehong Youn, 2017, younkeehong@gmail.com
46 */
47 
70 namespace al {
71 
75 class GPUObject {
76  public:
77  GPUObject();
78 
79  // disable copy/move construction
80  GPUObject(GPUObject const&) = delete;
81  GPUObject(GPUObject&&) = delete;
82 
83  // disable copy/move assignment
84  GPUObject& operator=(GPUObject const&) = delete;
85  GPUObject& operator=(GPUObject&&) = delete;
86 
87  virtual ~GPUObject();
88 
90  bool created() const;
91 
93  void create();
94 
96  void destroy();
97 
99  unsigned long id() const { return mID; }
100 
101  void id(unsigned long v) { mID = v; }
102 
104 
109  void validate();
110 
112  void invalidate();
113 
114  protected:
115  unsigned int mID;
116  bool mResubmit;
117 
119  virtual void onCreate() = 0;
120 
122  virtual void onDestroy() = 0;
123 };
124 
125 } // namespace al
126 
127 #endif
void validate()
Ensure that the GPUObject is ready to use.
unsigned long id() const
Returns the assigned object id.
virtual void onDestroy()=0
Called when currently assigned context is destroyed.
void destroy()
Destroys object on GPU.
bool created() const
Returns whether object has been created.
void create()
Creates object on GPU.
virtual void onCreate()=0
Called when currently assigned context is created.
void invalidate()
Triggers re-creation of object safely.
Definition: al_App.hpp:23