summaryrefslogtreecommitdiff
path: root/source/modules/asura-core/graphics/gpu_buffer.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'source/modules/asura-core/graphics/gpu_buffer.cpp')
-rw-r--r--source/modules/asura-core/graphics/gpu_buffer.cpp38
1 files changed, 24 insertions, 14 deletions
diff --git a/source/modules/asura-core/graphics/gpu_buffer.cpp b/source/modules/asura-core/graphics/gpu_buffer.cpp
index c796bb0..6e6aead 100644
--- a/source/modules/asura-core/graphics/gpu_buffer.cpp
+++ b/source/modules/asura-core/graphics/gpu_buffer.cpp
@@ -34,19 +34,6 @@ namespace AsuraEngine
mUsage = GL_STATIC_DRAW;
break;
}
- gl.WipeError();
- glGenBuffers(1, &mBuffer);
- if (mBuffer == 0)
- throw Exception("OpenGL glGenBuffers failed.");
- glBindBuffer(mTarget, mBuffer);
- glBufferData(mTarget, size, NULL, mUsage); // ʼСΪsizeĻ
- if (gl.HasError())
- throw Exception("OpenGL glBufferData failed. Errorcode=%d.", gl.GetError());
- glBindBuffer(mTarget, 0);
-#if ASURA_DEBUG
- mData = (byte*)malloc(size);
- memset(mData, 0, size);
-#endif
mSize = size;
}
@@ -63,10 +50,33 @@ namespace AsuraEngine
{
if (data == nullptr)
return false;
- glBindBuffer(mTarget, mBuffer);
+ if (mBuffer == 0)
+ {
+ // ʼ
+ gl.WipeError();
+ glGenBuffers(1, &mBuffer);
+ if (mBuffer == 0)
+ throw Exception("OpenGL glGenBuffers failed.");
+ glBindBuffer(mTarget, mBuffer);
+ glBufferData(mTarget, mSize, NULL, mUsage); // ʼСΪsizeĻ
+ if (gl.HasError())
+ {
+ glBindBuffer(mTarget, 0);
+ throw Exception("OpenGL glBufferData failed. Errorcode=%d.", gl.GetError());
+ }
+#if ASURA_DEBUG
+ mData = (byte*)malloc(size);
+ memset(mData, 0, size);
+#endif
+ }
+ else
+ glBindBuffer(mTarget, mBuffer);
glBufferSubData(mTarget, offset, size, data);
if (gl.HasError())
+ {
+ glBindBuffer(mTarget, 0);
throw Exception("OpenGL glBufferSubData failed. Errorcode=%d.", gl.GetError());
+ }
glBindBuffer(mTarget, 0);
#if ASURA_DEBUG
// һݣ