Last active
November 20, 2017 12:41
-
-
Save giraphics/c5cfd2e32ad174914defbce043fc7b98 to your computer and use it in GitHub Desktop.
Implicit deallocation model
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This example shows a demo as per existing Pan3D Model. | |
// Here, each class is responsible to release it own resources. | |
#include <iostream> | |
using namespace std; | |
class Position // GPU allocator/deallocator for position buffers | |
{ | |
public: | |
Position() { cout << "Position Ctor" << endl; Allocate(); } | |
virtual ~Position() { cout << "Position Dtor" << endl; Deallocate(); } | |
void Allocate() { cout << "Position Allocated" << endl; } | |
void Deallocate() { cout << "Position Deallocated" << endl; } | |
}; | |
class TextureCoord // GPU allocator/deallocator for texture coordinates buffers | |
{ | |
public: | |
TextureCoord() { cout << "TextureCoord Ctor" << endl; Allocate(); } | |
virtual ~TextureCoord() { cout << "TextureCoord Dtor" << endl; Deallocate(); } | |
void Allocate() { cout << "TextureCoord Allocated" << endl; } | |
void Deallocate() { cout << "TextureCoord Deallocated" << endl; } | |
}; | |
class Normals // GPU allocator/deallocator for normal buffers | |
{ | |
public: | |
Normals() { cout << "Normals Ctor" << endl; Allocate(); } | |
virtual ~Normals() { cout << "Normals Dtor" << endl; Deallocate(); } | |
void Allocate() { cout << "Normals Allocated" << endl; } | |
void Deallocate() { cout << "Normals Deallocated" << endl; } | |
}; | |
class Shape | |
{ | |
public: | |
Shape() { cout << "Shape Ctor" << endl; } | |
virtual ~Shape() { cout << "Shape Dtor" << endl; } | |
}; | |
class Rectangle : public Shape, public Position | |
{ | |
public: | |
Rectangle() { cout << "Rectangle Ctor" << endl; Allocate(); } | |
virtual ~Rectangle() { cout << "Rectangle Dtor" << endl; Deallocate(); } | |
void Allocate() { cout << "Rectangle Allocated" << endl; } | |
void Deallocate() { cout << "Rectangle Deallocated" << endl; } | |
}; | |
// Circle produces with 4 vertices from Rectangle and Texture coords | |
class Circle : public Rectangle, public TextureCoord | |
{ | |
public: | |
Circle() { cout << "Circle Ctor" << endl; Allocate(); } | |
virtual ~Circle() { cout << "Circle Dtor" << endl; Deallocate(); } | |
void Allocate() { cout << "Circle Allocated" << endl; } | |
void Deallocate() { cout << "Circle Deallocated" << endl; } | |
}; | |
// Circle with light shading | |
class ShadedCircle : public Circle, public Normals | |
{ | |
public: | |
ShadedCircle() { cout << "ShadedCircle Ctor" << endl; Allocate(); } | |
virtual ~ShadedCircle() { cout << "ShadedCircle Dtor" << endl; Deallocate(); } | |
void Allocate() { cout << "ShadedCircle Allocated" << endl; } | |
void Deallocate() { cout << "ShadedCircle Deallocated" << endl; } | |
}; | |
int main() | |
{ | |
ShadedCircle a; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment