summaryrefslogtreecommitdiff
path: root/source/modules/asura-core
diff options
context:
space:
mode:
Diffstat (limited to 'source/modules/asura-core')
-rw-r--r--source/modules/asura-core/graphics/binding/_image.cpp26
-rw-r--r--source/modules/asura-core/graphics/canvas.cpp34
-rw-r--r--source/modules/asura-core/graphics/canvas.h3
-rw-r--r--source/modules/asura-core/graphics/gl.cpp18
-rw-r--r--source/modules/asura-core/graphics/gl.h40
-rw-r--r--source/modules/asura-core/graphics/image.cpp54
-rw-r--r--source/modules/asura-core/graphics/image.h17
-rw-r--r--source/modules/asura-core/graphics/matrix_stack.cpp61
-rw-r--r--source/modules/asura-core/graphics/matrix_stack.h82
-rw-r--r--source/modules/asura-core/graphics/shader.cpp136
-rw-r--r--source/modules/asura-core/graphics/shader.h12
-rw-r--r--source/modules/asura-core/graphics/shader_source.h11
-rw-r--r--source/modules/asura-core/graphics/texture.cpp14
13 files changed, 426 insertions, 82 deletions
diff --git a/source/modules/asura-core/graphics/binding/_image.cpp b/source/modules/asura-core/graphics/binding/_image.cpp
index 407ada7..913bf5c 100644
--- a/source/modules/asura-core/graphics/binding/_image.cpp
+++ b/source/modules/asura-core/graphics/binding/_image.cpp
@@ -13,11 +13,10 @@ namespace AsuraEngine
LUAX_REGISTER_METHODS(state,
{ "New", _New },
- { "Refresh", _Refresh },
+ { "Renew", _Renew },
{ "GetWidth", _GetWidth },
{ "GetHeight", _GetHeight },
{ "GetSize", _GetSize },
- { "GetPixel", _GetPixel },
{ "Render", _Render }
);
}
@@ -35,15 +34,12 @@ namespace AsuraEngine
return 1;
}
- // successed = image:Refresh(imgData)
- LUAX_IMPL_METHOD(Image, _Refresh)
+ // successed = image:Renew(imgData)
+ LUAX_IMPL_METHOD(Image, _Renew)
{
LUAX_PREPARE(L, Image);
ImageData* imgData = state.CheckUserdata<ImageData>(2);
- bool successed = self->Refresh(imgData);
- if (successed)
- self->SetLuaxMemberRef(state, self->mImageDataRef, 2);
- state.Push(successed);
+ state.Push(self->Renew(imgData));
return 1;
}
@@ -74,20 +70,6 @@ namespace AsuraEngine
return 2;
}
- // color32 = image:GetPixel(x, y)
- LUAX_IMPL_METHOD(Image, _GetPixel)
- {
- LUAX_PREPARE(L, Image);
-
- uint x, y;
- x = state.CheckValue<uint>(2);
- y = state.CheckValue<uint>(3);
- Color32* c32 = new Color32();
- c32->Set(self->GetPixel(x, y));
- c32->PushLuaxUserdata(state);
- return 1;
- }
-
// image:Render()
LUAX_IMPL_METHOD(Image, _Render)
{
diff --git a/source/modules/asura-core/graphics/canvas.cpp b/source/modules/asura-core/graphics/canvas.cpp
index 89be45c..0543461 100644
--- a/source/modules/asura-core/graphics/canvas.cpp
+++ b/source/modules/asura-core/graphics/canvas.cpp
@@ -8,21 +8,41 @@ namespace AsuraEngine
Canvas::Canvas()
: mWidth(0)
, mHeight(0)
+ , mFBO(0)
{
- glGenFramebuffers(1, &mFBO);
- GLint current_fbo;
- glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &current_fbo);
- glBindFramebuffer(GL_FRAMEBUFFER, mFBO);
- glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mTex, 0);
- glBindFramebuffer(GL_FRAMEBUFFER, current_fbo);
+ // Fix: ôСʼʱframebufferԴ
+ //glGenFramebuffers(1, &mFBO);
+ //GLint current_fbo;
+ //glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &current_fbo);
+ //glBindFramebuffer(GL_FRAMEBUFFER, mFBO);
+ //glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mTex, 0);
+ //glBindFramebuffer(GL_FRAMEBUFFER, current_fbo);
}
void Canvas::SetSize(uint w, uint h)
{
+ if (mFBO == 0)
+ {
+ glGenFramebuffers(1, &mFBO);
+ if (mFBO == 0)
+ throw Exception("OpenGL glGenFramebuffers cannot generate frame buffer object.");
+ //
+ if (mTex == 0)
+ {
+ glGenTextures(1, &mTex);
+ if (mTex == 0)
+ throw Exception("OpenGL glGenTextures cannot generate texture.");
+ }
+ GLint current_fbo;
+ glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &current_fbo);
+ glBindFramebuffer(GL_FRAMEBUFFER, mFBO);
+ glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mTex, 0);
+ glBindFramebuffer(GL_FRAMEBUFFER, current_fbo);
+ }
GLint current_tex;
glGetIntegerv(GL_TEXTURE_BINDING_2D, &current_tex);
glBindTexture(GL_TEXTURE_2D, mTex);
-
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
glBindTexture(GL_TEXTURE_2D, current_tex);
}
diff --git a/source/modules/asura-core/graphics/canvas.h b/source/modules/asura-core/graphics/canvas.h
index f0b71e2..6af81d7 100644
--- a/source/modules/asura-core/graphics/canvas.h
+++ b/source/modules/asura-core/graphics/canvas.h
@@ -4,6 +4,7 @@
#include <asura-utils/scripting/portable.hpp>
#include <asura-utils/math/rect.hpp>
#include <asura-utils/math/vector2.hpp>
+#include <asura-utils/exceptions/exception.h>
#include "gl.h"
#include "texture.h"
@@ -32,7 +33,7 @@ namespace AsuraEngine
///
/// render textureĴС
///
- void SetSize(uint w, uint h);
+ void SetSize(uint w, uint h) asura_throw(Exception);
void Clear(const Color& col = Color::Black) override;
diff --git a/source/modules/asura-core/graphics/gl.cpp b/source/modules/asura-core/graphics/gl.cpp
index 9ffe010..e199a41 100644
--- a/source/modules/asura-core/graphics/gl.cpp
+++ b/source/modules/asura-core/graphics/gl.cpp
@@ -1,7 +1,9 @@
#include <asura-utils/type.h>
#include "../core_config.h"
+
#include "gl.h"
+#include "shader.h"
using namespace AEMath;
@@ -10,15 +12,16 @@ namespace AsuraEngine
namespace Graphics
{
- bool OpenGL::instantiated = false;
+ static bool _instantiated = false;
//
OpenGL gl;
OpenGL::OpenGL()
{
- ASSERT(!instantiated);
- instantiated = true;
+ // Ҫڶʵ
+ ASSERT(!_instantiated);
+ _instantiated = true;
}
OpenGL::~OpenGL()
@@ -38,7 +41,16 @@ namespace AsuraEngine
return state.viewport;
}
+ void OpenGL::UseShader(Shader* shader)
+ {
+ glUseProgram(shader->GetGLProgramHandle());
+ state.shader = shader;
+ }
+ void OpenGL::UnuseShader()
+ {
+ state.shader = nullptr;
+ }
}
} \ No newline at end of file
diff --git a/source/modules/asura-core/graphics/gl.h b/source/modules/asura-core/graphics/gl.h
index 4d21a5a..9ca1f44 100644
--- a/source/modules/asura-core/graphics/gl.h
+++ b/source/modules/asura-core/graphics/gl.h
@@ -1,21 +1,28 @@
#ifndef __ASURA_ENGINE_OPENGL_H__
#define __ASURA_ENGINE_OPENGL_H__
-#include <asura-utils/math/rect.hpp>
+#include <stack>
#include <glad/glad.h>
+#include <asura-utils/math/rect.hpp>
+#include <asura-utils/math/matrix44.h>
+
+#include "matrix_stack.h"
+
namespace AsuraEngine
{
namespace Graphics
{
class Profiler;
+ class Shader;
///
- /// һЩopengl״̬׷١ڱ༭രڻ£һڶӦһhwndһhdcԼ
- /// opengl contextʹwglMakeCurrent(hdc, glc)ָǰ̶߳Ⱦhdc
- /// openglglcglм¼ľһ̵߳һڵһopenglĵ״̬
+ /// OpenGLģһЩopengl״̬׷١ڱ༭രڻ£һڶӦһhwnd
+ /// һhdcԼopengl contextʹwglMakeCurrent(hdc, glc)ָǰ̶߳
+ /// Ⱦhdcopenglglcglм¼ľһ̵߳һڵһOpenGL
+ /// ĵ״̬
///
class OpenGL
{
@@ -26,23 +33,28 @@ namespace AsuraEngine
void SetViewport(const AEMath::Recti viewport);
AEMath::Recti GetViewport();
- private:
-
- friend class Profiler;
+ void UseShader(Shader* shader);
+ void UnuseShader();
- ///
- /// opengl
///
- static bool instantiated;
-
- ///
- /// ¼opengl״̬
+ /// OpenGL3.0Ժû任ӿڡshaderȲﱣһЩOpenGL״̬ע
+ /// ƺȫ̵ģҲ˵Asuraֶ֧߳ȾOpenGLĵĴʹһ
+ /// İһHDC\ϣڴض̴߳ģOpenGLҲһ
+ /// ض̡߳ͬһ̵߳IJͬHDC\ڿԹͬһOpenGLġΪ
+ /// дtextuer\shaderhandle
///
struct
{
- AEMath::Recti viewport;
+ Shader* shader; ///< ǰʹõshader
+ AEMath::Recti viewport; ///< ǰлHDC߱ڴСı߲ˢʱ䶯
+ MatrixStack projectionMatrix; ///< ͶӰ
+ MatrixStack modelViewMatrix; ///< 任
} state;
+ private:
+
+ friend class Profiler;
+
};
///
diff --git a/source/modules/asura-core/graphics/image.cpp b/source/modules/asura-core/graphics/image.cpp
index 2b274c2..530ea97 100644
--- a/source/modules/asura-core/graphics/image.cpp
+++ b/source/modules/asura-core/graphics/image.cpp
@@ -1,3 +1,5 @@
+#include <asura-utils/exceptions/exception.h>
+
#include "../core_config.h"
#include "image.h"
@@ -18,12 +20,19 @@ namespace AsuraEngine
{
}
- bool Image::Refresh(DecodedData* data)
+ bool Image::Renew(DecodedData* data)
{
- ASSERT(data);
-
+ if (!data) return false;
ImageData* imgData = static_cast<ImageData*>(data);
- ASSERT(imgData);
+ if (!imgData) return false;
+
+ // ûԴһ
+ if (mTex == 0)
+ {
+ glGenTextures(1, &mTex);
+ if (mTex == 0)
+ throw Exception("OpenGL glGenTextures failed.");
+ }
glBindTexture(GL_TEXTURE_2D, mTex);
imgData->Lock();
@@ -40,8 +49,43 @@ namespace AsuraEngine
, tf.type
, imgData->pixels
);
- mImageData = imgData;
+ mWidth = imgData->width;
+ mHeight = imgData->height;
+ imgData->Unlock();
+ GLenum err = glGetError();
+ if (err != GL_NO_ERROR)
+ throw Exception("OpenGL glTexImage2D cause error, error code=%d", err);
+ glBindTexture(GL_TEXTURE_2D, 0);
+
+ return true;
+ }
+
+ bool Image::Renew(AEIO::DecodedData* data, const AEMath::Vector2i& pos)
+ {
+ if (!data) return false;
+ ImageData* imgData = static_cast<ImageData*>(data);
+ if (!imgData) return false;
+
+ glBindTexture(GL_TEXTURE_2D, mTex);
+ imgData->Lock();
+ int width = imgData->width;
+ int height = imgData->height;
+ TextureFormat tf = ConvertColorFormat(imgData->format);
+ glTexSubImage2D(
+ GL_TEXTURE_2D
+ , 0
+ , pos.x
+ , pos.y
+ , imgData->width
+ , imgData->height
+ , tf.externalformat
+ , tf.type
+ , imgData->pixels
+ );
imgData->Unlock();
+ GLenum err = glGetError();
+ if (err != GL_NO_ERROR)
+ throw Exception("OpenGL glTexSubImage2D cause error, error code=%d", err);
glBindTexture(GL_TEXTURE_2D, 0);
return true;
diff --git a/source/modules/asura-core/graphics/image.h b/source/modules/asura-core/graphics/image.h
index 7795c08..d60bd24 100644
--- a/source/modules/asura-core/graphics/image.h
+++ b/source/modules/asura-core/graphics/image.h
@@ -44,12 +44,11 @@ namespace AsuraEngine
/// ͼύGPUϢ¹imageʹglTexImage2D
/// ύimageݡ
///
- bool Refresh(AEIO::DecodedData* decodeData) override;
- bool Refresh(AEIO::DecodedData* decodeData, const AEMath::Recti& rect);
+ bool Renew(AEIO::DecodedData* decodeData) override;
+ bool Renew(AEIO::DecodedData* decodeData, const AEMath::Vector2i& pos);
- uint GetWidth();
- uint GetHeight();
- Color32 GetPixel(uint x, uint y);
+ uint GetWidth();
+ uint GetHeight();
void Render(const RenderTarget* rt, const RenderState& state) override {};
void Render(const RenderTarget* rt, const Math::Rectf& quad, const RenderState& state) override {};
@@ -59,7 +58,7 @@ namespace AsuraEngine
//----------------------------------------------------------------------------//
LUAX_DECL_METHOD(_New);
- LUAX_DECL_METHOD(_Refresh);
+ LUAX_DECL_METHOD(_Renew);
LUAX_DECL_METHOD(_GetWidth);
LUAX_DECL_METHOD(_GetHeight);
LUAX_DECL_METHOD(_GetSize);
@@ -68,11 +67,7 @@ namespace AsuraEngine
//----------------------------------------------------------------------------//
- ///
- /// һͼƬһݵá
- ///
- ImageData* mImageData;
- Luax::LuaxMemberRef mImageDataRef;
+ uint32 mWidth, mHeight;
};
diff --git a/source/modules/asura-core/graphics/matrix_stack.cpp b/source/modules/asura-core/graphics/matrix_stack.cpp
new file mode 100644
index 0000000..72ffb7d
--- /dev/null
+++ b/source/modules/asura-core/graphics/matrix_stack.cpp
@@ -0,0 +1,61 @@
+#include "matrix_stack.h"
+
+namespace AsuraEngine
+{
+ namespace Graphics
+ {
+
+ MatrixStack::MatrixStack()
+ : top(0)
+ {
+ // ջʼջô˱֤ջԶǿգȡֵ
+ mStack[top].SetIdentity();
+ }
+
+ MatrixStack::~MatrixStack()
+ {
+ }
+
+ void MatrixStack::LoadIdentity()
+ {
+ mStack[top].SetIdentity();
+ }
+
+ bool MatrixStack::Push()
+ {
+ if (top == ASURA_MAX_MATRIX_STACK_DEPTH - 1)
+ return false;
+ ++top;
+ mStack[top] = mStack[top - 1];
+ return true;
+ }
+
+ bool MatrixStack::Pop()
+ {
+ if (top == 0)
+ return false;
+ --top;
+ return true;
+ }
+
+ AEMath::Matrix44& MatrixStack::GetTop()
+ {
+ return mStack[top];
+ }
+
+ uint MatrixStack::GetTopIndex()
+ {
+ return top;
+ }
+
+ uint MatrixStack::GetCapacity()
+ {
+ return ASURA_MAX_MATRIX_STACK_DEPTH;
+ }
+
+ void MatrixStack::Ortho(float left, float right, float bottom, float top, float near, float far)
+ {
+ }
+
+ }
+} \ No newline at end of file
diff --git a/source/modules/asura-core/graphics/matrix_stack.h b/source/modules/asura-core/graphics/matrix_stack.h
new file mode 100644
index 0000000..1923b30
--- /dev/null
+++ b/source/modules/asura-core/graphics/matrix_stack.h
@@ -0,0 +1,82 @@
+#ifndef __ASURA_MATRIX_STACK_H__
+#define __ASURA_MATRIX_STACK_H__
+
+#include <asura-utils/type.h>
+#include <asura-utils/math/matrix44.h>
+
+namespace AsuraEngine
+{
+ namespace Graphics
+ {
+
+ ///
+ /// ջľȡ
+ ///
+#define ASURA_MAX_MATRIX_STACK_DEPTH 32 // 2KB
+
+ ///
+ /// ջ״ָ̬֮ǰ״̬ջеһstack[i]ֵstack[0]*..*stack[i-1]
+ /// ֵһϵtransform
+ ///
+ /// TODO: template<uint _capacity> MatrixStack
+ ///
+ class MatrixStack
+ {
+ public:
+
+ MatrixStack();
+ ~MatrixStack();
+
+ ///
+ /// ջԪصIJֻͨºʵ
+ ///
+ void LoadIdentity();
+ bool Push();
+ bool Pop();
+
+ AEMath::Matrix44& GetTop();
+ void GetTop(asura_out AEMath::Matrix44& mat44);
+
+ void LoadMatrix(const AEMath::Matrix44& mat44);
+ void MultMatrix(const AEMath::Matrix44& mat44);
+
+ ///
+ /// 任
+ ///
+ void Rotate(float angle, float x, float y, float z);
+ void Translate(float x, float y, float z);
+ void Scale(float x, float y, float z);
+
+ ///
+ /// ͶӰ任
+ ///
+ void Ortho(float left, float right, float bottom, float top, float near, float far);
+ //void Perspective(float fov, float aspect, float near, float far);
+ //void Frustum(float left, float right, float top, float bottom, float near, float far);
+ //void LookAt(float x, float y, float z, float cx, float cy, float cz, float ux, float uy, float uz);
+
+ ///
+ /// ջΧ0~ASURA_MAX_MATRIX_STACK_DEPTH-1
+ ///
+ uint GetTopIndex();
+
+ ///
+ /// ջASURA_MAX_MATRIX_STACK_DEPTH
+ ///
+ uint GetCapacity();
+
+ private:
+
+ AEMath::Matrix44 mStack[ASURA_MAX_MATRIX_STACK_DEPTH];
+
+ ///
+ /// ջ0~ASURA_MAX_MATRIX_STACK_DEPTH-1
+ ///
+ uint8 top;
+
+ };
+
+ }
+}
+
+#endif \ No newline at end of file
diff --git a/source/modules/asura-core/graphics/shader.cpp b/source/modules/asura-core/graphics/shader.cpp
index f33fd1a..a4738cd 100644
--- a/source/modules/asura-core/graphics/shader.cpp
+++ b/source/modules/asura-core/graphics/shader.cpp
@@ -1,4 +1,9 @@
-#include "Shader.h"
+#include <asura-utils/exceptions/exception.h>
+
+#include "shader_source.h"
+#include "shader.h"
+
+using namespace std;
namespace AsuraEngine
{
@@ -7,17 +12,76 @@ namespace AsuraEngine
Shader::Shader()
{
-
+ mProgram = glCreateProgram();
+ if (mProgram == 0)
+ throw Exception("Cannot create OpenGL shader program.");
+
+ mVertShader = glCreateShader(GL_VERTEX_SHADER);
+ if (mVertShader == 0)
+ {
+ glDeleteProgram(mProgram);
+ throw Exception("Cannot create OpenGL vertex shader.");
+ }
+
+ mFragShader = glCreateShader(GL_FRAGMENT_SHADER);
+ if (mFragShader == 0)
+ {
+ glDeleteProgram(mProgram);
+ glDeleteShader(mVertShader);
+ throw Exception("Cannot create OpenGL fragment shader.");
+ }
}
Shader::~Shader()
{
-
+ glDeleteShader(mVertShader);
+ glDeleteShader(mFragShader);
+ glDeleteProgram(mProgram);
}
- bool Shader::Refresh(AEIO::DecodedData* db)
+ bool Shader::Renew(AEIO::DecodedData* db)
{
- return false;
+ if (!db) return false;
+ ShaderSouce* shaderSource = static_cast<ShaderSouce*>(db);
+ if (!shaderSource) return false;
+
+ GLenum err = GL_NO_ERROR;
+ const GLchar* source;
+ GLint success;
+ string warnning = "";
+
+ // Compile vertex shader.
+ source = shaderSource->mVert.c_str();
+ glShaderSource(mVertShader, 1, &source, NULL);
+ glCompileShader(mVertShader);
+ glGetShaderiv(mVertShader, GL_COMPILE_STATUS, &success);
+ if (success == GL_FALSE)
+ {
+ warnning = GetShaderWarnings(mVertShader);
+ throw Exception("Compile vertex shader failed:\n%s", warnning.c_str());
+ }
+
+ // Compile fragment shader.
+ source = shaderSource->mFrag.c_str();
+ glShaderSource(mFragShader, 1, &source, NULL);
+ glCompileShader(mFragShader);
+ glGetShaderiv(mFragShader, GL_COMPILE_STATUS, &success);
+ if (success == GL_FALSE)
+ {
+ warnning = GetShaderWarnings(mFragShader);
+ throw Exception("Compile fragment shader failed:\n%s", warnning.c_str());
+ }
+
+ // Link program.
+ glAttachShader(mProgram, mVertShader);
+ glAttachShader(mProgram, mFragShader);
+ glLinkProgram(mProgram);
+ glGetProgramiv(mProgram, GL_LINK_STATUS, &success);
+ if (success == GL_FALSE)
+ {
+ warnning = GetProgramWarnings();
+ throw Exception("Link shader program failed:\n%s", warnning.c_str());
+ }
}
uint Shader::GetUniformLocation(const std::string& uniform)
@@ -32,37 +96,45 @@ namespace AsuraEngine
void Shader::Use()
{
-
+ if (mProgram != 0)
+ {
+ gl.UseShader(this);
+ }
}
void Shader::Unuse()
{
-
+ gl.UnuseShader();
}
void Shader::SetUniformFloat(uint loc, float value)
{
-
+ if(gl.state.shader == this)
+ glUniform1f(loc, value);
}
void Shader::SetUniformTexture(uint loc, const Texture& texture)
{
-
+ if (gl.state.shader == this)
+ glUniform1i(loc, texture.GetGLTextureHandle());
}
void Shader::SetUniformVector2(uint loc, const Math::Vector2f& vec2)
{
-
+ if (gl.state.shader == this)
+ glUniform2f(loc, vec2.x, vec2.y);
}
void Shader::SetUniformVector3(uint loc, const Math::Vector3f& vec3)
{
-
+ if (gl.state.shader == this)
+ glUniform3f(loc, vec3.x, vec3.y, vec3.z);
}
void Shader::SetUniformVector4(uint loc, const Math::Vector4f& vec4)
{
-
+ if (gl.state.shader == this)
+ glUniform4f(loc, vec4.x, vec4.y, vec4.z, vec4.w);
}
uint Shader::GetGLTextureUnitCount()
@@ -72,5 +144,45 @@ namespace AsuraEngine
return (uint)maxTextureUnits;
}
+ std::string Shader::GetProgramWarnings()
+ {
+ GLint strsize, nullpos;
+ glGetProgramiv(mProgram, GL_INFO_LOG_LENGTH, &strsize);
+
+ if (strsize == 0)
+ return "";
+
+ char *tempstr = new char[strsize];
+
+ memset(tempstr, '\0', strsize);
+ glGetProgramInfoLog(mProgram, strsize, &nullpos, tempstr);
+ tempstr[nullpos] = '\0';
+
+ std::string warnings(tempstr);
+ delete[] tempstr;
+
+ return warnings;
+ }
+
+ std::string Shader::GetShaderWarnings(GLuint shader)
+ {
+ GLint strsize, nullpos;
+ glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &strsize);
+
+ if (strsize == 0)
+ return "";
+
+ char *tempstr = new char[strsize];
+
+ memset(tempstr, '\0', strsize);
+ glGetShaderInfoLog(shader, strsize, &nullpos, tempstr);
+ tempstr[nullpos] = '\0';
+
+ std::string warnings(tempstr);
+ delete[] tempstr;
+
+ return warnings;
+ }
+
}
} \ No newline at end of file
diff --git a/source/modules/asura-core/graphics/shader.h b/source/modules/asura-core/graphics/shader.h
index ae24548..9077599 100644
--- a/source/modules/asura-core/graphics/shader.h
+++ b/source/modules/asura-core/graphics/shader.h
@@ -4,6 +4,7 @@
#include <map>
#include <string>
+#include <asura-utils/exceptions/exception.h>
#include <asura-utils/scripting/portable.hpp>
#include <asura-utils/io/renewable.h>
#include <asura-utils/math/vector2.hpp>
@@ -36,7 +37,7 @@ namespace AsuraEngine
LUAX_DECL_FACTORY(Shader);
- Shader();
+ Shader() asura_throw(Exception);
~Shader();
@@ -44,8 +45,7 @@ namespace AsuraEngine
/// ӴshaderʱȼǷϴλuniforms location mapʹ
/// glAttachShader±ɫɫ
///
- //bool Load(const std::string& vertexShader, const std::string& fragmentShader);
- bool Refresh(AEIO::DecodedData* decodeData) override;
+ bool Renew(AEIO::DecodedData* decodeData) override;
///
/// shaderΪ
@@ -98,6 +98,8 @@ namespace AsuraEngine
/// OpenGL shader program handle.
///
GLuint mProgram;
+ GLuint mVertShader;
+ GLuint mFragShader;
Luax::LuaxMemberRef mCodeRef;
@@ -109,6 +111,7 @@ namespace AsuraEngine
LUAX_DECL_METHOD(_Use);
LUAX_DECL_METHOD(_Unuse);
LUAX_DECL_METHOD(_Load);
+ LUAX_DECL_METHOD(_Renew);
LUAX_DECL_METHOD(_HasUniform);
LUAX_DECL_METHOD(_GetUniformLocation);
LUAX_DECL_METHOD(_SetBuiltInUniforms);
@@ -121,6 +124,9 @@ namespace AsuraEngine
//----------------------------------------------------------------------------//
+ std::string GetProgramWarnings();
+ std::string GetShaderWarnings(GLuint shader);
+
};
}
diff --git a/source/modules/asura-core/graphics/shader_source.h b/source/modules/asura-core/graphics/shader_source.h
index b3e815c..eedbe53 100644
--- a/source/modules/asura-core/graphics/shader_source.h
+++ b/source/modules/asura-core/graphics/shader_source.h
@@ -10,15 +10,24 @@ namespace AsuraEngine
namespace Graphics
{
+ class Shader;
+
///
/// Asura EngineʹõshaderԴ룬GLSL
///
class ShaderSouce : public AEIO::DecodedData
{
public:
- void Decode(AEIO::DataBuffer& buffer) override;
+
+ void Decode(AEIO::DataBuffer& vert, AEIO::DataBuffer& frag);
+ void Load(const std::string& vert, const std::string& frag);
private:
+
+ friend class Shader;
+
+ void Decode(AEIO::DataBuffer& buffer) override;
+
std::string mVert;
std::string mFrag;
diff --git a/source/modules/asura-core/graphics/texture.cpp b/source/modules/asura-core/graphics/texture.cpp
index 4db6ad3..38a75d7 100644
--- a/source/modules/asura-core/graphics/texture.cpp
+++ b/source/modules/asura-core/graphics/texture.cpp
@@ -1,3 +1,5 @@
+#include <asura-utils/exceptions/exception.h>
+
#include "Texture.h"
namespace AsuraEngine
@@ -8,13 +10,17 @@ namespace AsuraEngine
Texture::Texture()
: mTex(0)
{
- // GL texture
- glGenTextures(1, &mTex);
+ // Fix: ҪʱԴ
+ //glGenTextures(1, &mTex);
+ //if(mTex == 0)
+ // throw Exception("Cannot create texture.");
}
Texture::~Texture()
{
- glDeleteTextures(1, &mTex);
+ // ͷԴ
+ if(mTex != 0)
+ glDeleteTextures(1, &mTex);
}
GLuint Texture::GetGLTextureHandle() const
@@ -37,6 +43,8 @@ namespace AsuraEngine
t.externalformat = GL_RGBA;
t.type = GL_FLOAT;
break;
+ default:
+ ASSERT(false); // cant reach here
}
return t;
}