From 1b3360e1520e6298a08f05569eb7597aea61170b Mon Sep 17 00:00:00 2001 From: yvt Date: Sun, 25 Aug 2013 02:37:30 +0900 Subject: [PATCH] Support PBO --- Sources/Draw/IGLDevice.h | 11 +++++++++++ Sources/Gui/SDLGLDevice.cpp | 33 +++++++++++++++++++++++++++++++++ Sources/Gui/SDLGLDevice.h | 3 +++ 3 files changed, 47 insertions(+) diff --git a/Sources/Draw/IGLDevice.h b/Sources/Draw/IGLDevice.h index 1b76ecc4..90be2896 100644 --- a/Sources/Draw/IGLDevice.h +++ b/Sources/Draw/IGLDevice.h @@ -29,6 +29,7 @@ namespace spades { FloatType, UnsignedShort5551, UnsignedShort1555Rev, + UnsignedInt2101010Rev, // State DepthTest, @@ -88,12 +89,19 @@ namespace spades { // Buffer target ArrayBuffer, ElementArrayBuffer, + PixelPackBuffer, + PixelUnpackBuffer, // Buffer usage StaticDraw, StreamDraw, DynamicDraw, + // Buffer Map access + ReadOnly, + WriteOnly, + ReadWrite, + // Texture targets Texture2D, Texture3D, @@ -243,6 +251,9 @@ namespace spades { Sizei size, const void *data) = 0; + virtual void *MapBuffer(Enum target, Enum access) = 0; + virtual void UnmapBuffer(Enum target) = 0; + virtual UInteger GenTexture() = 0; virtual void DeleteTexture(UInteger) = 0; diff --git a/Sources/Gui/SDLGLDevice.cpp b/Sources/Gui/SDLGLDevice.cpp index b42d19b4..d0545640 100644 --- a/Sources/Gui/SDLGLDevice.cpp +++ b/Sources/Gui/SDLGLDevice.cpp @@ -265,6 +265,7 @@ namespace spades { } IGLDevice::UInteger SDLGLDevice::GenBuffer() { + SPADES_MARK_FUNCTION_DEBUG(); GLuint i; glGenBuffers(1, &i); CheckError(); @@ -272,16 +273,47 @@ namespace spades { } void SDLGLDevice::DeleteBuffer(UInteger i) { + SPADES_MARK_FUNCTION_DEBUG(); GLuint v = (GLuint)i; glDeleteBuffers(1, &v); CheckError(); } + void *SDLGLDevice::MapBuffer(Enum target, + Enum access) { + SPADES_MARK_FUNCTION_DEBUG(); + GLenum acc; + switch(access){ + case draw::IGLDevice::ReadOnly: + acc = GL_READ_ONLY; + break; + case draw::IGLDevice::WriteOnly: + acc = GL_WRITE_ONLY; + break; + case draw::IGLDevice::ReadWrite: + acc = GL_READ_WRITE; + break; + default: + SPInvalidEnum("access", access); + } + void *ret = glMapBuffer(parseBufferTarget(target), + acc); + CheckError(); + return ret; + } + + void SDLGLDevice::UnmapBuffer(Enum target) { + glUnmapBuffer(parseBufferTarget(target)); + CheckError(); + } + GLenum SDLGLDevice::parseBufferTarget(spades::draw::IGLDevice::Enum v){ SPADES_MARK_FUNCTION_DEBUG(); switch(v){ case ArrayBuffer: return GL_ARRAY_BUFFER; case ElementArrayBuffer: return GL_ELEMENT_ARRAY_BUFFER; + case PixelPackBuffer: return GL_PIXEL_PACK_BUFFER; + case PixelUnpackBuffer: return GL_PIXEL_UNPACK_BUFFER; default: SPInvalidEnum("v", v); } } @@ -391,6 +423,7 @@ namespace spades { case FloatType: return GL_FLOAT; case UnsignedShort5551: return GL_UNSIGNED_SHORT_5_5_5_1; case UnsignedShort1555Rev: return GL_UNSIGNED_SHORT_1_5_5_5_REV; + case UnsignedInt2101010Rev: return GL_UNSIGNED_INT_2_10_10_10_REV; default: SPInvalidEnum("v", v); } } diff --git a/Sources/Gui/SDLGLDevice.h b/Sources/Gui/SDLGLDevice.h index d804cadf..1ee28888 100644 --- a/Sources/Gui/SDLGLDevice.h +++ b/Sources/Gui/SDLGLDevice.h @@ -53,6 +53,9 @@ namespace spades { virtual void DeleteBuffer(UInteger); virtual void BindBuffer(Enum, UInteger); + virtual void *MapBuffer(Enum target, Enum access); + virtual void UnmapBuffer(Enum target); + virtual void BufferData(Enum target, Sizei size, const void *data,