From 4ea4bbfcb03091cb987dc151d41980ec16f3d18d Mon Sep 17 00:00:00 2001 From: chai Date: Mon, 8 Apr 2019 22:31:12 +0800 Subject: *misc --- source/modules/asura-core/graphics/image.cpp | 48 ++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) (limited to 'source/modules/asura-core/graphics/image.cpp') 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)); // positionºÍuv + + 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 -- cgit v1.1-26-g67d0