PageRenderTime 67ms CodeModel.GetById 30ms app.highlight 16ms RepoModel.GetById 14ms app.codeStats 0ms

/opengles/src/Buffer.h

http://ftk.googlecode.com/
C++ Header | 107 lines | 53 code | 19 blank | 35 comment | 6 complexity | 92f0bb92d4a0ba32c0b470e75195a01f MD5 | raw file
  1#ifndef EGL_BUFFER_H
  2#define EGL_BUFFER_H 1
  3
  4// ==========================================================================
  5//
  6// Buffer.h			Buffer Object Class for 3D Rendering Library
  7//
  8// --------------------------------------------------------------------------
  9//
 10// 08-30-2004		Hans-Martin Will	initial version
 11//
 12// --------------------------------------------------------------------------
 13//
 14// Copyright (c) 2004, Hans-Martin Will. All rights reserved.
 15// 
 16// Redistribution and use in source and binary forms, with or without 
 17// modification, are permitted provided that the following conditions are 
 18// met:
 19// 
 20//	 *  Redistributions of source code must retain the above copyright
 21// 		notice, this list of conditions and the following disclaimer. 
 22//   *	Redistributions in binary form must reproduce the above copyright
 23// 		notice, this list of conditions and the following disclaimer in the 
 24// 		documentation and/or other materials provided with the distribution. 
 25// 
 26// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 27// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
 28// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
 29// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 
 30// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, 
 31// OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
 32// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 33// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
 34// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
 35// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 
 36// THE POSSIBILITY OF SUCH DAMAGE.
 37//
 38// ==========================================================================
 39
 40
 41#include "OGLES.h"
 42#include "GLES/gl.h"
 43
 44
 45namespace EGL {
 46
 47	enum BufferUsage {
 48		BufferUsageStaticDraw,
 49		BufferUsageDynamicDraw
 50	};
 51
 52	class Buffer { 
 53
 54	public:
 55		Buffer(): m_Data(0), m_Size(0), m_Usage(BufferUsageStaticDraw) { }
 56
 57		~Buffer() { 
 58			Deallocate();
 59		}
 60
 61		bool Allocate(size_t size, BufferUsage usage) {
 62			Deallocate();
 63
 64			if (size) {
 65				m_Data = malloc(size);
 66
 67				if (m_Data == 0) {
 68					return false;
 69				} else {
 70					m_Size = size;
 71					m_Usage = usage;
 72					return true;
 73				}
 74			} else {
 75				return true;
 76			}
 77		}
 78
 79		void Deallocate() {
 80			if (m_Data) {
 81				free(m_Data);
 82				m_Data = 0;
 83				m_Size = 0;
 84			}
 85		}
 86
 87		void *	GetData() const {
 88			return m_Data;
 89		}
 90
 91		size_t GetSize() const {
 92			return m_Size;
 93		}
 94
 95		BufferUsage GetUsage() const {
 96			return m_Usage;
 97		}
 98
 99	private:
100		void *		m_Data;
101		size_t		m_Size;
102		BufferUsage m_Usage;
103	};
104
105}
106
107#endif //ndef EGL_BUFFER_H