diff options
Diffstat (limited to 'source/modules/asura-core')
18 files changed, 275 insertions, 379 deletions
diff --git a/source/modules/asura-core/graphics/binding/_gfx_device.cpp b/source/modules/asura-core/graphics/binding/_gfx_device.cpp new file mode 100644 index 0000000..5ae475c --- /dev/null +++ b/source/modules/asura-core/graphics/binding/_gfx_device.cpp @@ -0,0 +1,152 @@ +#include "../gfx_device.h" + +using namespace std; +using namespace Luax; + +namespace AsuraEngine +{ + namespace Graphics + { + + LUAX_REGISTRY(GfxDevice) + { + LUAX_REGISTER_METHODS(state, + { "SetMatrixMode", _SetMatrixMode }, + { "GetMatrixMode", _GetMatrixMode }, + { "PushMatrix", _PushMatrix }, + { "PopMatrix", _PopMatrix }, + { "LoadIdentity", _LoadIdentity }, + { "Rotate", _Rotate }, + { "Translate", _Translate }, + { "Scale", _Scale }, + { "Ortho", _Ortho }, + { "GetMatrixDepth", _GetMatrixDepth }, + { "GetMatrixIndex", _GetMatrixIndex }, + { "UseShader", _UseShader }, + { "UnuseShader", _UnuseShader } + ); + } + + LUAX_POSTPROCESS(GfxDevice) + { + LUAX_REGISTER_ENUM(state, "EMatrixMode", + { "PROJECTION", MATRIX_MODE_PROJECTION }, + { "0", 0 }, + { "MODEL", MATRIX_MODE_MODEL }, + { "1", 1 }, + { "VIEW", MATRIX_MODE_VIEW }, + { "2", 2 } + ); + LUAX_REGISTER_ENUM(state, "EGLParams", + { "MAX_TEXTURE_UNIT", GL_PARAM_MAX_TEXTURE_UNIT }, + { "1", 1 } + ); + + } + + // gfxdevice:SetMatrixMode() + LUAX_IMPL_METHOD(GfxDevice, _SetMatrixMode) + { + LUAX_PREPARE(L, GfxDevice); + + return 0; + } + + // gfxdevice:GetMatrixMode() + LUAX_IMPL_METHOD(GfxDevice, _GetMatrixMode) + { + LUAX_PREPARE(L, GfxDevice); + + return 0; + } + + // gfxdevice:PushMatrix() + LUAX_IMPL_METHOD(GfxDevice, _PushMatrix) + { + LUAX_PREPARE(L, GfxDevice); + + return 0; + } + + // gfxdevice:PopMatrix() + LUAX_IMPL_METHOD(GfxDevice, _PopMatrix) + { + LUAX_PREPARE(L, GfxDevice); + + return 0; + } + + // gfxdevice:LoadIdentity() + LUAX_IMPL_METHOD(GfxDevice, _LoadIdentity) + { + LUAX_PREPARE(L, GfxDevice); + + return 0; + } + + // gfxdevice:Rotate() + LUAX_IMPL_METHOD(GfxDevice, _Rotate) + { + LUAX_PREPARE(L, GfxDevice); + + return 0; + } + + // gfxdevice:Translate() + LUAX_IMPL_METHOD(GfxDevice, _Translate) + { + LUAX_PREPARE(L, GfxDevice); + + return 0; + } + + // gfxdevice:Scale() + LUAX_IMPL_METHOD(GfxDevice, _Scale) + { + LUAX_PREPARE(L, GfxDevice); + + return 0; + } + + // gfxdevice:Ortho() + LUAX_IMPL_METHOD(GfxDevice, _Ortho) + { + LUAX_PREPARE(L, GfxDevice); + + return 0; + } + + // gfxdevice:GetMatrixDepth() + LUAX_IMPL_METHOD(GfxDevice, _GetMatrixDepth) + { + LUAX_PREPARE(L, GfxDevice); + + return 0; + } + + // gfxdevice:GetMatrixIndex() + LUAX_IMPL_METHOD(GfxDevice, _GetMatrixIndex) + { + LUAX_PREPARE(L, GfxDevice); + + return 0; + } + + // gfxdevice:UseShader() + LUAX_IMPL_METHOD(GfxDevice, _UseShader) + { + LUAX_PREPARE(L, GfxDevice); + + return 0; + } + + // gfxdevice:UnuseShader() + LUAX_IMPL_METHOD(GfxDevice, _UnuseShader) + { + LUAX_PREPARE(L, GfxDevice); + + return 0; + } + + } +} diff --git a/source/modules/asura-core/graphics/binding/_gl.cpp b/source/modules/asura-core/graphics/binding/_gl.cpp deleted file mode 100644 index 0c3a18f..0000000 --- a/source/modules/asura-core/graphics/binding/_gl.cpp +++ /dev/null @@ -1,128 +0,0 @@ -#include "../gl.h" - -using namespace std; -using namespace Luax; - -namespace AsuraEngine -{ - namespace Graphics - { - - LUAX_REGISTRY(OpenGL) - { - LUAX_REGISTER_METHODS(state, - { "SetMatrixMode", _SetMatrixMode }, - { "GetMatrixMode", _GetMatrixMode }, - { "PushMatrix", _PushMatrix }, - { "PopMatrix", _PopMatrix }, - { "LoadIdentity", _LoadIdentity }, - { "Rotate", _Rotate }, - { "Translate", _Translate }, - { "Scale", _Scale }, - { "Ortho", _Ortho }, - { "GetMatrixDepth", _GetMatrixDepth }, - { "GetMatrixIndex", _GetMatrixIndex } - ); - } - - LUAX_POSTPROCESS(OpenGL) - { - LUAX_REGISTER_ENUM(state, "EMatrixMode", - { "PROJECTION", MATRIX_MODE_PROJECTION }, - { "MODEL", MATRIX_MODE_MODEL }, - { "VIEW", MATRIX_MODE_VIEW } - ); - - } - - // GL.SetMatrixMode() - LUAX_IMPL_METHOD(OpenGL, _SetMatrixMode) - { - LUAX_PREPARE(L, OpenGL); - MatrixMode mode = (MatrixMode)state.CheckValue<int>(1); - gl.SetMatrixMode(mode); - return 0; - } - - // GL.GetMatrixMode() - LUAX_IMPL_METHOD(OpenGL, _GetMatrixMode) - { - LUAX_PREPARE(L, OpenGL); - - return 0; - } - - // GL.PushMatrix() - LUAX_IMPL_METHOD(OpenGL, _PushMatrix) - { - LUAX_PREPARE(L, OpenGL); - - return 0; - } - - // GL.PopMatrix() - LUAX_IMPL_METHOD(OpenGL, _PopMatrix) - { - LUAX_PREPARE(L, OpenGL); - - return 0; - } - - // GL.LoadIdentity() - LUAX_IMPL_METHOD(OpenGL, _LoadIdentity) - { - LUAX_PREPARE(L, OpenGL); - - return 0; - } - - // GL.Rotate() - LUAX_IMPL_METHOD(OpenGL, _Rotate) - { - LUAX_PREPARE(L, OpenGL); - - return 0; - } - - // GL.Translate() - LUAX_IMPL_METHOD(OpenGL, _Translate) - { - LUAX_PREPARE(L, OpenGL); - - return 0; - } - - // GL.Scale() - LUAX_IMPL_METHOD(OpenGL, _Scale) - { - LUAX_PREPARE(L, OpenGL); - - return 0; - } - - // GL.Ortho() - LUAX_IMPL_METHOD(OpenGL, _Ortho) - { - LUAX_PREPARE(L, OpenGL); - - return 0; - } - - // GL.GetMatrixDepth() - LUAX_IMPL_METHOD(OpenGL, _GetMatrixDepth) - { - LUAX_PREPARE(L, OpenGL); - - return 0; - } - - // GL.GetMatrixIndex() - LUAX_IMPL_METHOD(OpenGL, _GetMatrixIndex) - { - LUAX_PREPARE(L, OpenGL); - - return 0; - } - - } -} diff --git a/source/modules/asura-core/graphics/binding/_shader.cpp b/source/modules/asura-core/graphics/binding/_shader.cpp index 34bc98b..71f4e28 100644 --- a/source/modules/asura-core/graphics/binding/_shader.cpp +++ b/source/modules/asura-core/graphics/binding/_shader.cpp @@ -11,25 +11,19 @@ namespace AsuraEngine LUAX_REGISTRY(Shader) { LUAX_REGISTER_METHODS(state, - { "New", _New }, - { "Load", _Load }, - { "Update", _Update }, - { "HasUniform", _HasUniform }, - { "GetUniformLocation", _GetUniformLocation }, - { "SetUniformFloat", _SetUniformFloat }, - { "SetUniformTexture", _SetUniformTexture }, - { "SetUniformVector2", _SetUniformVector2 }, - { "SetUniformVector3", _SetUniformVector3 }, - { "SetUniformVector4", _SetUniformVector4 }, - { "SetUniformColor", _SetUniformColor }, - { "GetAttributeLocation", _GetAttributeLocation }, - { "SetAttribute", _SetAttribute }, - { "DisableAttribute", _DisableAttribute }, - { "SetBuiltInModelMatrix", _SetBuiltInModelMatrix }, - { "SetBuiltInViewMatrix", _SetBuiltInViewMatrix }, - { "SetBuiltInProjectionMatrix", _SetBuiltInProjectionMatrix }, - { "SetBuiltInMVPMatrix", _SetBuiltInMVPMatrix }, - { "SetBuiltInDrawColor", _SetBuiltInDrawColor } + { "New", _New }, + { "Load", _Load }, + { "Update", _Update }, + { "HasUniform", _HasUniform }, + { "GetUniformLocation", _GetUniformLocation }, + { "SetBuiltInUniforms", _SetBuiltInUniforms }, + { "SetUniformFloat", _SetUniformFloat }, + { "SetUniformTexture", _SetUniformTexture }, + { "SetUniformVector2", _SetUniformVector2 }, + { "SetUniformVector3", _SetUniformVector3 }, + { "SetUniformVector4", _SetUniformVector4 }, + { "SetUniformColor", _SetUniformColor }, + { "SetBuiltInUniforms", _SetBuiltInUniforms } ); } @@ -78,6 +72,14 @@ namespace AsuraEngine return 0; } + // shader:SetBuiltInUniforms() + LUAX_IMPL_METHOD(Shader, _SetBuiltInUniforms) + { + LUAX_PREPARE(L, Shader); + + return 0; + } + // shader:SetUniformFloat() LUAX_IMPL_METHOD(Shader, _SetUniformFloat) { @@ -126,69 +128,5 @@ namespace AsuraEngine return 0; } - // shader:GetAttributeLocation() - LUAX_IMPL_METHOD(Shader, _GetAttributeLocation) - { - LUAX_PREPARE(L, Shader); - - return 0; - } - - // shader:SetAttribute() - LUAX_IMPL_METHOD(Shader, _SetAttribute) - { - LUAX_PREPARE(L, Shader); - - return 0; - } - - // shader:DisableAttribute() - LUAX_IMPL_METHOD(Shader, _DisableAttribute) - { - LUAX_PREPARE(L, Shader); - - return 0; - } - - // shader:SetBuiltInModelMatrix() - LUAX_IMPL_METHOD(Shader, _SetBuiltInModelMatrix) - { - LUAX_PREPARE(L, Shader); - - return 0; - } - - // shader:SetBuiltInViewMatrix() - LUAX_IMPL_METHOD(Shader, _SetBuiltInViewMatrix) - { - LUAX_PREPARE(L, Shader); - - return 0; - } - - // shader:SetBuiltInProjectionMatrix() - LUAX_IMPL_METHOD(Shader, _SetBuiltInProjectionMatrix) - { - LUAX_PREPARE(L, Shader); - - return 0; - } - - // shader:SetBuiltInMVPMatrix() - LUAX_IMPL_METHOD(Shader, _SetBuiltInMVPMatrix) - { - LUAX_PREPARE(L, Shader); - - return 0; - } - - // shader:SetBuiltInColor() - LUAX_IMPL_METHOD(Shader, _SetBuiltInDrawColor) - { - LUAX_PREPARE(L, Shader); - - return 0; - } - } } diff --git a/source/modules/asura-core/graphics/canvas.h b/source/modules/asura-core/graphics/canvas.h index 555ce5d..49096c7 100644 --- a/source/modules/asura-core/graphics/canvas.h +++ b/source/modules/asura-core/graphics/canvas.h @@ -6,7 +6,7 @@ #include <asura-utils/math/vector2.hpp> #include <asura-utils/exceptions/exception.h> -#include "gl.h" +#include "gfx_device.h" #include "texture.h" #include "render_target.h" #include "render_state.h" diff --git a/source/modules/asura-core/graphics/gl.cpp b/source/modules/asura-core/graphics/gfx_device.cpp index 5e6f216..edfa784 100644 --- a/source/modules/asura-core/graphics/gl.cpp +++ b/source/modules/asura-core/graphics/gfx_device.cpp @@ -2,7 +2,7 @@ #include "../core_config.h" -#include "gl.h" +#include "gfx_device.h" #include "shader.h" #include "matrix_stack.h" #include "color.h" @@ -18,10 +18,9 @@ namespace AsuraEngine static bool _instantiated = false; #endif - OpenGL gl; + GfxDevice gfx; - OpenGL::OpenGL() - : mUpdateMVPMatrix(true) + GfxDevice::GfxDevice() { #if ASURA_DEBUG ASSERT(!_instantiated); @@ -29,13 +28,13 @@ namespace AsuraEngine #endif } - OpenGL::~OpenGL() + GfxDevice::~GfxDevice() { } static bool inited = false; - bool OpenGL::Init(const AEMath::Recti& view) + bool GfxDevice::Init(const AEMath::Recti& view) { bool loaded = false; #if ASURA_OPENGL_LOADER & ASURA_OPENGL_GLAD @@ -50,48 +49,48 @@ namespace AsuraEngine return true; } - bool OpenGL::Inited() + bool GfxDevice::Inited() { return inited; } - void OpenGL::WipeError() + void GfxDevice::WipeError() { while (glGetError() != GL_NO_ERROR); } - bool OpenGL::HasError() + bool GfxDevice::HasError() { return glGetError() != GL_NO_ERROR; } - GLenum OpenGL::GetError() + GLenum GfxDevice::GetError() { return glGetError(); } - void OpenGL::SetDrawColor(float r, float g, float b, float a) + void GfxDevice::SetDrawColor(float r, float g, float b, float a) { state.drawColor.Set(r, g, b, a); } - Color& OpenGL::GetDrawColor() + Color& GfxDevice::GetDrawColor() { return state.drawColor; } - void OpenGL::SetViewport(const Recti v) + void GfxDevice::SetViewport(const Recti v) { state.viewport = v; glViewport(v.x, v.y, v.w, v.h); } - const Recti& OpenGL::GetViewport() + const Recti& GfxDevice::GetViewport() { return state.viewport; } - void OpenGL::UseShader(Shader* shader) + void GfxDevice::UseShader(Shader* shader) { if (state.shader != shader) { @@ -104,18 +103,18 @@ namespace AsuraEngine shader->OnUse(); } - void OpenGL::UnuseShader() + void GfxDevice::UnuseShader() { state.shader->OnUnuse(); state.shader = nullptr; } - Shader* OpenGL::GetShader() + Shader* GfxDevice::GetShader() { return state.shader; } - void OpenGL::DrawArrays(GLenum mode, GLint first, GLsizei count) + void GfxDevice::DrawArrays(GLenum mode, GLint first, GLsizei count) { glDrawArrays(mode, first, count); #if ASURA_GL_PROFILE @@ -125,90 +124,69 @@ namespace AsuraEngine //------------------------------------------------------------------------------// - void OpenGL::SetMatrixMode(MatrixMode mode) + void GfxDevice::SetMatrixMode(MatrixMode mode) { state.matrixMode = mode; } - MatrixMode OpenGL::GetMatrixMode() + MatrixMode GfxDevice::GetMatrixMode() { return state.matrixMode; } - void OpenGL::PushMatrix() + void GfxDevice::PushMatrix() { state.matrix[state.matrixMode].Push(); - - mUpdateMVPMatrix = true; } - void OpenGL::PopMatrix() + void GfxDevice::PopMatrix() { state.matrix[state.matrixMode].Pop(); - - mUpdateMVPMatrix = true; } - void OpenGL::LoadIdentity() + void GfxDevice::LoadIdentity() { state.matrix[state.matrixMode].LoadIdentity(); - - mUpdateMVPMatrix = true; } - void OpenGL::Rotate(float angle) + void GfxDevice::Rotate(float angle) { state.matrix[state.matrixMode].Rotate(angle); - - mUpdateMVPMatrix = true; } - void OpenGL::Translate(float x, float y) + void GfxDevice::Translate(float x, float y) { state.matrix[state.matrixMode].Translate(x, y); - - mUpdateMVPMatrix = true; } - void OpenGL::Scale(float x, float y) + void GfxDevice::Scale(float x, float y) { state.matrix[state.matrixMode].Scale(x, y); - - mUpdateMVPMatrix = true; } - void OpenGL::Ortho(float l, float r, float b, float t, float n, float f) + void GfxDevice::Ortho(float l, float r, float b, float t, float n, float f) { state.matrix[state.matrixMode].Ortho(l, r, b, t, n, f); - - mUpdateMVPMatrix = true; } - AEMath::Matrix44& OpenGL::GetMatrix(MatrixMode mode) + AEMath::Matrix44& GfxDevice::GetMatrix(MatrixMode mode) { return state.matrix[mode].GetTop(); } - AEMath::Matrix44 OpenGL::GetMVPMatrix() + AEMath::Matrix44 GfxDevice::GetMVPMatrix() { - if (mUpdateMVPMatrix) - { - Matrix44& m = state.matrix[MATRIX_MODE_MODEL].GetTop(); - Matrix44& v = state.matrix[MATRIX_MODE_VIEW].GetTop(); - Matrix44& p = state.matrix[MATRIX_MODE_PROJECTION].GetTop(); - state.mvpMatrix = p * (v * m); - - mUpdateMVPMatrix = false; - } - return state.mvpMatrix; + return state.matrix[MATRIX_MODE_MODEL].GetTop() + * state.matrix[MATRIX_MODE_MODEL].GetTop() + * state.matrix[MATRIX_MODE_MODEL].GetTop(); } - uint OpenGL::GetMatrixDepth() + uint GfxDevice::GetMatrixDepth() { return state.matrix[state.matrixMode].GetCapacity(); } - uint OpenGL::GetMatrixIndex() + uint GfxDevice::GetMatrixIndex() { return state.matrix[state.matrixMode].GetTopIndex(); } diff --git a/source/modules/asura-core/graphics/gl.h b/source/modules/asura-core/graphics/gfx_device.h index 6c6ff30..5bb8c6a 100644 --- a/source/modules/asura-core/graphics/gl.h +++ b/source/modules/asura-core/graphics/gfx_device.h @@ -1,5 +1,5 @@ -#ifndef __ASURA_ENGINE_OPENGL_H__ -#define __ASURA_ENGINE_OPENGL_H__ +#ifndef __ASURA_ENGINE_GFX_DEVICE_H__ +#define __ASURA_ENGINE_GFX_DEVICE_H__ #include <stack> @@ -39,12 +39,12 @@ namespace AsuraEngine /// Ⱦhdcopenglglcglм¼ľһ̵߳һڵһOpenGL /// ĵ״ֶ̬֧Ⱦ /// - class OpenGL : public AEScripting::Portable<OpenGL> + class GfxDevice : public AEScripting::Portable<GfxDevice> { public: - OpenGL(); - ~OpenGL(); + GfxDevice(); + ~GfxDevice(); /// /// óֵ @@ -64,9 +64,7 @@ namespace AsuraEngine void UnuseShader(); Shader* GetShader(); - /// - /// ͳdrawcall - /// + // Draw call. void DrawArrays(GLenum mode, GLint first, GLsizei count); /// @@ -105,12 +103,11 @@ namespace AsuraEngine /// struct { - Shader* shader; ///< ǰʹõshader - AEMath::Recti viewport; ///< ǰлHDC߱ڴСı߲ˢʱ䶯 - MatrixStack matrix[3]; ///< model, view, projection - MatrixMode matrixMode; ///< ǰľ - AEMath::Matrix44 mvpMatrix; ///< mvp matrix - Color drawColor; ///< Ƶɫ + Shader* shader; ///< ǰʹõshader + AEMath::Recti viewport; ///< ǰлHDC߱ڴСı߲ˢʱ䶯 + MatrixStack matrix[3]; ///< model, view, projection + MatrixMode matrixMode; ///< ǰľ + Color drawColor; ///< Ƶɫ } state; #if ASURA_GL_PROFILE @@ -128,7 +125,7 @@ namespace AsuraEngine //----------------------------------------------------------------------------// - LUAX_DECL_SINGLETON(OpenGL); + LUAX_DECL_SINGLETON(GfxDevice); LUAX_DECL_ENUM(MatrixMode, 1); LUAX_DECL_ENUM(GLParams, 1); @@ -150,14 +147,12 @@ namespace AsuraEngine //----------------------------------------------------------------------------// - bool mUpdateMVPMatrix; - }; /// /// OpenGL /// - extern OpenGL gl; + extern GfxDevice gfx; } } diff --git a/source/modules/asura-core/graphics/gpu_buffer.cpp b/source/modules/asura-core/graphics/gpu_buffer.cpp index e16a4ac..4c84b7e 100644 --- a/source/modules/asura-core/graphics/gpu_buffer.cpp +++ b/source/modules/asura-core/graphics/gpu_buffer.cpp @@ -72,16 +72,16 @@ namespace AsuraEngine if (mBuffer == 0) { // ʼ - gl.WipeError(); + gfx.WipeError(); glGenBuffers(1, &mBuffer); if (mBuffer == 0) throw Exception("OpenGL glGenBuffers failed."); glBindBuffer(mTarget, mBuffer); glBufferData(mTarget, mSize, NULL, mUsage); // ʼСΪsizeĻ壬usageŵӦԴ - if (gl.HasError()) + if (gfx.HasError()) { glBindBuffer(mTarget, 0); - throw Exception("OpenGL glBufferData failed. Errorcode=%d.", gl.GetError()); + throw Exception("OpenGL glBufferData failed. Errorcode=%d.", gfx.GetError()); } #if ASURA_DEBUG mData = (byte*)malloc(size); @@ -91,10 +91,10 @@ namespace AsuraEngine else glBindBuffer(mTarget, mBuffer); glBufferSubData(mTarget, offset, size, data); - if (gl.HasError()) + if (gfx.HasError()) { glBindBuffer(mTarget, 0); - throw Exception("OpenGL glBufferSubData failed. Errorcode=%d.", gl.GetError()); + throw Exception("OpenGL glBufferSubData failed. Errorcode=%d.", gfx.GetError()); } glBindBuffer(mTarget, 0); #if ASURA_DEBUG @@ -108,7 +108,7 @@ namespace AsuraEngine { glBindBuffer(mTarget, mBuffer); } - + void GPUBuffer::UnBind() { glBindBuffer(mTarget, 0); diff --git a/source/modules/asura-core/graphics/gpu_buffer.h b/source/modules/asura-core/graphics/gpu_buffer.h index c492cbb..9013619 100644 --- a/source/modules/asura-core/graphics/gpu_buffer.h +++ b/source/modules/asura-core/graphics/gpu_buffer.h @@ -5,7 +5,7 @@ #include <asura-utils/exceptions/exception.h> #include <asura-utils/type.h> -#include "gl.h" +#include "gfx_device.h" namespace AsuraEngine { diff --git a/source/modules/asura-core/graphics/image.cpp b/source/modules/asura-core/graphics/image.cpp index ad2ae9a..d2f1d7b 100644 --- a/source/modules/asura-core/graphics/image.cpp +++ b/source/modules/asura-core/graphics/image.cpp @@ -4,7 +4,7 @@ #include "shader.h" #include "image.h" -#include "gl.h" +#include "gfx_device.h" using namespace AEIO; diff --git a/source/modules/asura-core/graphics/image.h b/source/modules/asura-core/graphics/image.h index cdc1b1a..932ca65 100644 --- a/source/modules/asura-core/graphics/image.h +++ b/source/modules/asura-core/graphics/image.h @@ -73,6 +73,10 @@ namespace AsuraEngine uint32 mWidth, mHeight; +#if ASURA_EDITOR + +#endif + }; } diff --git a/source/modules/asura-core/graphics/index_buffer.h b/source/modules/asura-core/graphics/index_buffer.h index 5fca0ea..ac77162 100644 --- a/source/modules/asura-core/graphics/index_buffer.h +++ b/source/modules/asura-core/graphics/index_buffer.h @@ -10,6 +10,9 @@ namespace AsuraEngine namespace Graphics { + /// + /// + /// class IndexBuffer ASURA_FINAL : public AEScripting::Portable<IndexBuffer> , public GPUBuffer diff --git a/source/modules/asura-core/graphics/shader.cpp b/source/modules/asura-core/graphics/shader.cpp index 833cef0..866c4da 100644 --- a/source/modules/asura-core/graphics/shader.cpp +++ b/source/modules/asura-core/graphics/shader.cpp @@ -1,6 +1,6 @@ #include <asura-utils/exceptions/exception.h> -#include "gl.h" +#include "gfx_device.h" #include "shader.h" using namespace std; @@ -123,59 +123,65 @@ namespace AsuraEngine void Shader::SetUniformFloat(uint loc, float value) { - if(gl.state.shader == this) + if(gfx.state.shader == this) glUniform1f(loc, value); } bool Shader::SetUniformTexture(uint loc, const Texture& texture) { - if (gl.state.shader != this) + if (gfx.state.shader != this) return false; - gl.WipeError(); + gfx.WipeError(); glActiveTexture(GL_TEXTURE0 + _texture_unit); - if (gl.HasError()) + if (gfx.HasError()) return false; GLint tex = texture.GetGLTexture(); glBindTexture(GL_TEXTURE_2D, tex); - if (gl.HasError()) + if (gfx.HasError()) return false; glUniform1i(loc, _texture_unit); - if (gl.HasError()) + if (gfx.HasError()) return false; ++_texture_unit; } void Shader::SetUniformVector2(uint loc, const Math::Vector2f& vec2) { - if (gl.state.shader == this) + if (gfx.state.shader == this) glUniform2f(loc, vec2.x, vec2.y); } void Shader::SetUniformVector3(uint loc, const Math::Vector3f& vec3) { - if (gl.state.shader == this) + if (gfx.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) + if (gfx.state.shader == this) glUniform4f(loc, vec4.x, vec4.y, vec4.z, vec4.w); } void Shader::SetUniformMatrix44(uint loc, const Math::Matrix44& mat) { - if (gl.state.shader == this) + if (gfx.state.shader == this) glUniformMatrix4fv(loc, 1, GL_FALSE, mat.GetElements()); } void Shader::SetUniformColor(uint loc, const Color& color) { - if (gl.state.shader == this) + if (gfx.state.shader == this) glUniform4f(loc, color.r, color.g, color.b, color.a); } + //void Shader::GetUniform() + //{ + // //if(gfx.state.shader == this) + // // glGetUniformfv() + //} + uint Shader::GetGLTextureUnitCount() { GLint maxTextureUnits; @@ -244,30 +250,5 @@ namespace AsuraEngine glDisableVertexAttribArray(loc); } - void Shader::SetBuiltInModelMatrix(uint loc) - { - SetUniformMatrix44(loc, gl.GetMatrix(MATRIX_MODE_MODEL)); - } - - void Shader::SetBuiltInViewMatrix(uint loc) - { - SetUniformMatrix44(loc, gl.GetMatrix(MATRIX_MODE_VIEW)); - } - - void Shader::SetBuiltInProjectionMatrix(uint loc) - { - SetUniformMatrix44(loc, gl.GetMatrix(MATRIX_MODE_PROJECTION)); - } - - void Shader::SetBuiltInMVPMatrix(uint loc) - { - SetUniformMatrix44(loc, gl.GetMVPMatrix()); - } - - void Shader::SetBuiltInDrawColor(uint loc) - { - SetUniformColor(loc, gl.GetDrawColor()); - } - } }
\ 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 913332b..b5d866e 100644 --- a/source/modules/asura-core/graphics/shader.h +++ b/source/modules/asura-core/graphics/shader.h @@ -14,7 +14,7 @@ #include <asura-utils/stringmap.hpp> #include <asura-utils/manager.hpp> -#include "gl.h" +#include "gfx_device.h" #include "color.h" #include "texture.h" #include "vertex_buffer.h" @@ -45,18 +45,12 @@ namespace AsuraEngine void OnUse(); void OnUnuse(); - /// - /// öԣЩֵframeworkrenderer汻ãImageMesh2DЩԴ - /// normalizedΪtrueݻڸbuffer¹һ255ɫһ - /// 0~1 - /// + /// void SetAttribute(int loc, VertexBuffer* vbo, uint offseti = 0, uint stridei = 0, bool normalized = false); int GetAttributeLocation(const std::string& attribute); void DisableAttribute(int loc); - /// - /// uniform - /// + /// Uniform bool HasUniform(const std::string& uniform); uint GetUniformLocation(const std::string& uniform); void SetUniformFloat(uint loc, float value); @@ -67,14 +61,11 @@ namespace AsuraEngine void SetUniformMatrix44(uint loc, const Math::Matrix44& mat44); bool SetUniformTexture(uint loc, const Texture& texture); - /// - /// ñ - /// - void SetBuiltInModelMatrix(uint loc); - void SetBuiltInViewMatrix(uint loc); - void SetBuiltInProjectionMatrix(uint loc); - void SetBuiltInMVPMatrix(uint loc); - void SetBuiltInDrawColor(uint loc); + float GetUniformFloat(uint loc); + AEMath::Vector2f GetUniformVector2(uint loc); + AEMath::Vector3f GetUniformVector3(uint loc); + AEMath::Vector4f GetUniformVector4s(uint loc); + AEMath::Matrix44 GetUniformMatrix44(uint loc); GLuint GetGLProgram(); @@ -97,16 +88,12 @@ namespace AsuraEngine LUAX_DECL_METHOD(_SetUniformVector3); LUAX_DECL_METHOD(_SetUniformVector4); LUAX_DECL_METHOD(_SetUniformColor); - // vertex attributes + /// vertex attributes LUAX_DECL_METHOD(_GetAttributeLocation); LUAX_DECL_METHOD(_SetAttribute); LUAX_DECL_METHOD(_DisableAttribute); - // uniform - LUAX_DECL_METHOD(_SetBuiltInModelMatrix); - LUAX_DECL_METHOD(_SetBuiltInViewMatrix); - LUAX_DECL_METHOD(_SetBuiltInProjectionMatrix); - LUAX_DECL_METHOD(_SetBuiltInMVPMatrix); - LUAX_DECL_METHOD(_SetBuiltInDrawColor); + /// uniform + LUAX_DECL_METHOD(_SetBuiltInUniforms); //----------------------------------------------------------------------------// @@ -118,6 +105,8 @@ namespace AsuraEngine GLuint mFragShader; }; + + typedef Shader GpuProgram; } } diff --git a/source/modules/asura-core/graphics/texture.cpp b/source/modules/asura-core/graphics/texture.cpp index 522ba95..3438334 100644 --- a/source/modules/asura-core/graphics/texture.cpp +++ b/source/modules/asura-core/graphics/texture.cpp @@ -34,12 +34,12 @@ namespace AsuraEngine switch (colorformat) { case COLOR_FORMAT_RGBA8: - t.internalformat = GL_RGBA8; + t.internalformat = GL_RGBA8; // 4*sizeof(byte) ~= 4 bytes t.externalformat = GL_RGBA; t.type = GL_UNSIGNED_BYTE; break; case COLOR_FORMAT_RGBA32F: - t.internalformat = GL_RGBA32F; + t.internalformat = GL_RGBA32F; // 4*sizeof(float) = 16 bytes t.externalformat = GL_RGBA; t.type = GL_FLOAT; break; diff --git a/source/modules/asura-core/graphics/texture.h b/source/modules/asura-core/graphics/texture.h index 36a773d..799227e 100644 --- a/source/modules/asura-core/graphics/texture.h +++ b/source/modules/asura-core/graphics/texture.h @@ -7,7 +7,7 @@ #include "../core_config.h" #include "render_state.h" -#include "gl.h" +#include "gfx_device.h" namespace AsuraEngine { @@ -78,26 +78,6 @@ namespace AsuraEngine /// UVfilterΪ /// bool IsGenMipmap(); -/* - /// - /// ȾtexturertϣԭϽǣң - /// - virtual void Render(const RenderTarget* rt, const RenderState& state) = 0; - - /// - /// ȾtextureһֵrtϣԭϽǣң졣 - /// - virtual void Render(const RenderTarget* rt, const AEMath::Rectf& quad, const RenderState& state) = 0; -*/ - /// - /// Ⱦimage - /// - //virtual void Render() = 0; - - /// - /// Ⱦimage - /// - //virtual void Render(AEMath::Recti& quad) = 0; protected: diff --git a/source/modules/asura-core/graphics/vertex_buffer.h b/source/modules/asura-core/graphics/vertex_buffer.h index f00b4d2..b078c2b 100644 --- a/source/modules/asura-core/graphics/vertex_buffer.h +++ b/source/modules/asura-core/graphics/vertex_buffer.h @@ -10,6 +10,10 @@ namespace AsuraEngine namespace Graphics { + /// + /// frameworkṩ˴Դ滺Ĺܣֱû壬ܶͨ + /// ֱöݡ + /// class VertexBuffer ASURA_FINAL : public AEScripting::Portable<VertexBuffer> , public GPUBuffer diff --git a/source/modules/asura-core/input/input_device.hpp b/source/modules/asura-core/input/input_device.hpp index 1d08d09..4d82343 100644 --- a/source/modules/asura-core/input/input_device.hpp +++ b/source/modules/asura-core/input/input_device.hpp @@ -2,9 +2,9 @@ #define __ASURA_ENGINE_INPUT_BASE_H__ #include <asura-utils/scripting/portable.hpp> +#include <asura-utils/singleton.hpp> #include "../core_config.h" -#include "../singleton.hpp" namespace AsuraEngine { diff --git a/source/modules/asura-core/mesh/mesh2d_data.h b/source/modules/asura-core/mesh/mesh2d_data.h index 8cb9723..cd7c9ee 100644 --- a/source/modules/asura-core/mesh/mesh2d_data.h +++ b/source/modules/asura-core/mesh/mesh2d_data.h @@ -66,7 +66,7 @@ namespace AsuraEngine /// /// ebo /// - std::vector<float> mIndices; + std::vector<int> mIndices; int mComponents; |