summaryrefslogtreecommitdiff
path: root/source/modules/asura-core/graphics/gpu_buffer.cpp
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2019-04-08 22:31:12 +0800
committerchai <chaifix@163.com>2019-04-08 22:31:12 +0800
commit4ea4bbfcb03091cb987dc151d41980ec16f3d18d (patch)
treebdbe56d8c570b5f243744fbfc5a6cdd2c4f6dc4f /source/modules/asura-core/graphics/gpu_buffer.cpp
parente47baca4f23db43ec91fbf64d5d06d7c0dbee495 (diff)
*misc
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
// һݣ