summaryrefslogtreecommitdiff
path: root/source/modules/asura-core/graphics/image.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'source/modules/asura-core/graphics/image.cpp')
-rw-r--r--source/modules/asura-core/graphics/image.cpp66
1 files changed, 37 insertions, 29 deletions
diff --git a/source/modules/asura-core/graphics/image.cpp b/source/modules/asura-core/graphics/image.cpp
index cb5b573..9244e73 100644
--- a/source/modules/asura-core/graphics/image.cpp
+++ b/source/modules/asura-core/graphics/image.cpp
@@ -2,6 +2,7 @@
#include "../core_config.h"
+#include "shader.h"
#include "image.h"
#include "gl.h"
@@ -13,16 +14,13 @@ namespace AsuraEngine
{
Image::Image()
- : mVBO(nullptr)
- , mWidth(0)
+ : mWidth(0)
, mHeight(0)
{
}
Image::~Image()
{
- if (mVBO)
- delete mVBO;
}
bool Image::Load(ImageData* imgData)
@@ -52,23 +50,6 @@ namespace AsuraEngine
, 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();
@@ -118,21 +99,48 @@ namespace AsuraEngine
{
return mHeight;
}
-
- void Image::UpdateBuffer()
+ /*
+ void Image::Render()
{
- if (!mVBO)
+ Shader* shader = gl.GetShader();
+ if (!shader)
return;
- float w = mWidth,
- h = mHeight;
- float buffer[] = {
+ uint32& w = mWidth, &h = mHeight;
+ int vertices[] = {
0, 0, 0, 0,
0, h, 0, 1,
+ w, 0, 1, 0,
w, h, 1, 1,
- w, 0, 1, 0
};
- mVBO->Fill(buffer, sizeof(buffer));
+ // öϵUV
+ shader->SetAttribPosition(2, GL_INT, GL_FALSE, 4 * sizeof(int), vertices);
+ shader->SetAttribTexcoord0(2, GL_INT, GL_FALSE, 4 * sizeof(int), &vertices[2]);
+ gl.DrawArrays(GL_TRIANGLE_STRIP, 0, 4);
}
+ void Image::Render(AEMath::Recti& quad)
+ {
+ //
+ Shader* shader = gl.GetShader();
+ if (!shader)
+ return;
+ int &w = quad.w, &h = quad.h;
+ // UV
+ float l = quad.x / mWidth,
+ r = (quad.x + quad.w) / mWidth,
+ t = quad.y / mHeight,
+ b = (quad.y + quad.h) / mHeight;
+ float vertices[] = {
+ 0, 0, l, t,
+ 0, h, l, b,
+ w, 0, r, t,
+ w, h, r, b,
+ };
+ // öϵUV
+ shader->SetAttribPosition(2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), vertices);
+ shader->SetAttribTexcoord0(2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), &vertices[2]);
+ gl.DrawArrays(GL_TRIANGLE_STRIP, 0, 4);
+ }
+ */
}
} \ No newline at end of file