Support PBO

This commit is contained in:
yvt 2013-08-25 02:37:30 +09:00
parent ad90027e75
commit 1b3360e152
3 changed files with 47 additions and 0 deletions

View File

@ -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;

View File

@ -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);
}
}

View File

@ -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,