diff options
Diffstat (limited to 'source/modules/asura-core/graphics/image.cpp')
-rw-r--r-- | source/modules/asura-core/graphics/image.cpp | 48 |
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 |