00001 #ifndef GSGL_PLATFORM_BUFFER_POOL_H 00002 #define GSGL_PLATFORM_BUFFER_POOL_H 00003 00004 // 00005 // $Id: buffer_pool.hpp 2 2008-03-01 20:58:50Z kulibali $ 00006 // 00007 // Copyright (c) 2008, The Periapsis Project. All rights reserved. 00008 // 00009 // Redistribution and use in source and binary forms, with or without 00010 // modification, are permitted provided that the following conditions are 00011 // met: 00012 // 00013 // * Redistributions of source code must retain the above copyright notice, 00014 // this list of conditions and the following disclaimer. 00015 // 00016 // * Redistributions in binary form must reproduce the above copyright 00017 // notice, this list of conditions and the following disclaimer in the 00018 // documentation and/or other materials provided with the distribution. 00019 // 00020 // * Neither the name of the The Periapsis Project nor the names of its 00021 // contributors may be used to endorse or promote products derived from 00022 // this software without specific prior written permission. 00023 // 00024 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 00025 // IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 00026 // TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 00027 // PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 00028 // OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00029 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00030 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00031 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00032 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00033 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00034 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00035 // 00036 00037 #include "platform/platform.hpp" 00038 #include "platform/vbuffer.hpp" 00039 #include "data/array.hpp" 00040 #include "data/stack.hpp" 00041 00042 namespace gsgl 00043 { 00044 00045 namespace platform 00046 { 00047 00048 class PLATFORM_API buffer_pool 00049 { 00050 const vbuffer::update_mode mode; 00051 const gsgl::index_t num_objects_per_bucket; 00052 const gsgl::index_t num_vertices_per_object; 00053 const gsgl::index_t num_indices_per_object; 00054 00055 public: 00056 struct bucket 00057 { 00058 vertex_buffer vertices; 00059 index_buffer indices; 00060 00061 bucket(const vbuffer::update_mode & mode, const gsgl::index_t num_vertices = 0, const gsgl::index_t num_indices = 0) 00062 : vertices(mode, num_vertices), indices(mode, num_indices) {} 00063 }; 00064 00065 struct object_record 00066 { 00067 vbuffer::index_t pos_in_vertices; 00068 vbuffer::index_t pos_in_indices; 00069 bucket *parent; 00070 00071 bool operator== (const object_record & or) const 00072 { 00073 return pos_in_vertices == or.pos_in_vertices && pos_in_indices == or.pos_in_indices && parent == or.parent; 00074 } 00075 }; 00076 00077 private: 00078 data::simple_array<bucket *> buckets; 00079 data::simple_stack<object_record> available_objects; 00080 00081 public: 00082 buffer_pool(const vbuffer::update_mode & mode, const gsgl::index_t & num_objects_per_bucket, const gsgl::index_t & num_vertices_per_object, const gsgl::index_t & num_indices_per_object); 00083 virtual ~buffer_pool(); 00084 00085 object_record allocate_object(); 00086 void free_object(const object_record &); 00087 00088 void load(); 00089 void unload(); 00090 }; // class buffer_pool 00091 00092 } // namespace platform 00093 00094 } // namespace gsgl 00095 00096 #endif