summaryrefslogtreecommitdiff
path: root/source/modules/asura-core/graphics/image.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/image.cpp
parente47baca4f23db43ec91fbf64d5d06d7c0dbee495 (diff)
*misc
Diffstat (limited to 'source/modules/asura-core/graphics/image.cpp')
-rw-r--r--source/modules/asura-core/graphics/image.cpp48
1 files changed, 48 insertions, 0 deletions
diff --git a/source/modules/asura-core/graphics/image.cpp b/source/modules/asura-core/graphics/image.cpp
index d4c4cdd..cb5b573 100644
--- a/source/modules/asura-core/graphics/image.cpp
+++ b/source/modules/asura-core/graphics/image.cpp
@@ -13,11 +13,16 @@ namespace AsuraEngine
{
Image::Image()
+ : mVBO(nullptr)
+ , mWidth(0)
+ , mHeight(0)
{
}
Image::~Image()
{
+ if (mVBO)
+ delete mVBO;
}
bool Image::Load(ImageData* imgData)
@@ -46,6 +51,24 @@ namespace AsuraEngine
, tf.type
, imgData->pixels
);
+
+ // ʼbuffer
+ if (!mVBO)
+ mVBO = new GPUBuffer(BUFFER_TYPE_VERTEX, BUFFER_USAGE_STATIC, 16*sizeof(float)); // positionuv
+
+ if (mWidth != imgData->width || mHeight != imgData->height)
+ {
+ float w = imgData->width,
+ h = imgData->height;
+ float buffer[] = {
+ 0, 0, 0, 0,
+ 0, h, 0, 1,
+ w, h, 1, 1,
+ w, 0, 1, 0
+ };
+ mVBO->Fill(buffer, sizeof(buffer));
+ }
+
mWidth = imgData->width;
mHeight = imgData->height;
imgData->Unlock();
@@ -86,5 +109,30 @@ namespace AsuraEngine
return true;
}
+ uint32 Image::GetWidth()
+ {
+ return mWidth;
+ }
+
+ uint32 Image::GetHeight()
+ {
+ return mHeight;
+ }
+
+ void Image::UpdateBuffer()
+ {
+ if (!mVBO)
+ return;
+ float w = mWidth,
+ h = mHeight;
+ float buffer[] = {
+ 0, 0, 0, 0,
+ 0, h, 0, 1,
+ w, h, 1, 1,
+ w, 0, 1, 0
+ };
+ mVBO->Fill(buffer, sizeof(buffer));
+ }
+
}
} \ No newline at end of file