summaryrefslogtreecommitdiff
path: root/source/modules/asura-core/graphics
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2019-04-03 21:56:51 +0800
committerchai <chaifix@163.com>2019-04-03 21:56:51 +0800
commite13616b5c40f912853be99f0603f0e4c97b22062 (patch)
tree6663eab986dbf0317f326bce863edc3d7bf3332e /source/modules/asura-core/graphics
parentc8a6a8e2dd6f015a31b4f8191ad945a78fe77f3d (diff)
*misc
Diffstat (limited to 'source/modules/asura-core/graphics')
-rw-r--r--source/modules/asura-core/graphics/gl.cpp72
-rw-r--r--source/modules/asura-core/graphics/gl.h13
-rw-r--r--source/modules/asura-core/graphics/image.h5
-rw-r--r--source/modules/asura-core/graphics/shader.cpp37
-rw-r--r--source/modules/asura-core/graphics/shader.h5
-rw-r--r--source/modules/asura-core/graphics/texture.h2
6 files changed, 96 insertions, 38 deletions
diff --git a/source/modules/asura-core/graphics/gl.cpp b/source/modules/asura-core/graphics/gl.cpp
index e199a41..47476a7 100644
--- a/source/modules/asura-core/graphics/gl.cpp
+++ b/source/modules/asura-core/graphics/gl.cpp
@@ -12,24 +12,24 @@ namespace AsuraEngine
namespace Graphics
{
+#if ASURA_DEBUG
static bool _instantiated = false;
+#endif
- //
OpenGL gl;
OpenGL::OpenGL()
{
- // Ҫڶʵ
+#if ASURA_DEBUG
ASSERT(!_instantiated);
_instantiated = true;
+#endif
}
OpenGL::~OpenGL()
{
}
- //------------------------------------------------------------------------------//
-
void OpenGL::SetViewport(const Recti v)
{
glViewport(v.x, v.y, v.w, v.h);
@@ -52,5 +52,69 @@ namespace AsuraEngine
state.shader = nullptr;
}
+ //------------------------------------------------------------------------------//
+
+ void OpenGL::SetMatrixMode(MatrixMode mode)
+ {
+ state.matrixMode = mode;
+ }
+
+ MatrixMode OpenGL::GetMatrixMode()
+ {
+ return state.matrixMode;
+ }
+
+ void OpenGL::PushMatrix()
+ {
+ state.matrix[state.matrixMode].Push();
+ }
+
+ void OpenGL::PopMatrix()
+ {
+ state.matrix[state.matrixMode].Pop();
+ }
+
+ void OpenGL::LoadIdentity()
+ {
+ state.matrix[state.matrixMode].LoadIdentity();
+ }
+
+ void OpenGL::Rotate(float angle, float x, float y, float z)
+ {
+ state.matrix[state.matrixMode].Rotate(angle, x, y, z);
+ }
+
+ void OpenGL::Translate(float x, float y, float z)
+ {
+ state.matrix[state.matrixMode].Translate(x, y, z);
+ }
+
+ void OpenGL::Scale(float x, float y, float z)
+ {
+ state.matrix[state.matrixMode].Scale(x, y, z);
+ }
+
+ void OpenGL::Ortho(float l, float r, float b, float t, float n, float f)
+ {
+ state.matrix[state.matrixMode].Ortho(l, r, b, t, n, f);
+ }
+
+ AEMath::Matrix44& OpenGL::GetMatrix(MatrixMode mode)
+ {
+ return state.matrix[state.matrixMode].GetTop();
+ }
+
+ uint OpenGL::GetMatrixDepth()
+ {
+ return state.matrix[state.matrixMode].GetCapacity();
+ }
+
+ uint OpenGL::GetMatrixIndex()
+ {
+ return state.matrix[state.matrixMode].GetTopIndex();
+ }
+
+ //------------------------------------------------------------------------------//
+
}
} \ 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 3104288..6838bc9 100644
--- a/source/modules/asura-core/graphics/gl.h
+++ b/source/modules/asura-core/graphics/gl.h
@@ -22,15 +22,14 @@ namespace AsuraEngine
enum MatrixMode
{
MATRIX_PROJECTION = 0,
- MATRIX_MODELVIEW,
- _MATRIX_COUNT
+ MATRIX_MODELVIEW = 1,
};
///
/// OpenGLģһЩopengl״̬׷١ڱ༭രڻ£һڶӦһhwnd
/// һhdcԼopengl contextʹwglMakeCurrent(hdc, glc)ָǰ̶߳
/// Ⱦhdcopenglglcglм¼ľһ̵߳һڵһOpenGL
- /// ĵ״̬
+ /// ĵ״ֶ̬֧Ⱦ
///
class OpenGL : public AEScripting::Portable<OpenGL>
{
@@ -69,10 +68,10 @@ namespace AsuraEngine
///
struct
{
- Shader* shader; ///< ǰʹõshader
- AEMath::Recti viewport; ///< ǰлHDC߱ڴСı߲ˢʱ䶯
- MatrixStack matrix[_MATRIX_COUNT]; ///< ͶӰ
- MatrixMode matrixMode; ///< ǰľ
+ Shader* shader; ///< ǰʹõshader
+ AEMath::Recti viewport; ///< ǰлHDC߱ڴСı߲ˢʱ䶯
+ MatrixStack matrix[2]; ///< 任
+ MatrixMode matrixMode; ///< ǰľ
} state;
private:
diff --git a/source/modules/asura-core/graphics/image.h b/source/modules/asura-core/graphics/image.h
index 2e6ced2..e4aecd1 100644
--- a/source/modules/asura-core/graphics/image.h
+++ b/source/modules/asura-core/graphics/image.h
@@ -28,9 +28,8 @@ namespace AsuraEngine
/// һֻࡣҪǿǵeditorengineʹòͬķװ
///
class Image ASURA_FINAL
- : public Texture
- , public Scripting::Portable<Image>
- , public AEIO::Renewable
+ : public AEIO::Renewable
+ , public AEScripting::Portable<Image, Texture>
{
public:
diff --git a/source/modules/asura-core/graphics/shader.cpp b/source/modules/asura-core/graphics/shader.cpp
index fdcdf1b..c26ddf1 100644
--- a/source/modules/asura-core/graphics/shader.cpp
+++ b/source/modules/asura-core/graphics/shader.cpp
@@ -12,24 +12,25 @@ 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.");
- }
+ //Fix: Ҫʱ
+ //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()
diff --git a/source/modules/asura-core/graphics/shader.h b/source/modules/asura-core/graphics/shader.h
index 6d51b8e..f4bce25 100644
--- a/source/modules/asura-core/graphics/shader.h
+++ b/source/modules/asura-core/graphics/shader.h
@@ -82,11 +82,6 @@ namespace AsuraEngine
private:
///
- /// ǰshader
- ///
- static Shader* mCurrentShader;
-
- ///
/// ñ
/// vec2 Asura_Time xֵΪ뵱ǰʼʱ䣬yֵΪһ֡ʱ
/// vec2 Asura_RenderTargetSize RTĴСΪλ
diff --git a/source/modules/asura-core/graphics/texture.h b/source/modules/asura-core/graphics/texture.h
index f19f3a7..571c617 100644
--- a/source/modules/asura-core/graphics/texture.h
+++ b/source/modules/asura-core/graphics/texture.h
@@ -57,7 +57,7 @@ namespace AsuraEngine
/// ϲԵѿϵΪ׼EditorҲϽΪԭ㣬Ϊ
/// 㡣
///
- ASURA_ABSTRACT class Texture : virtual public AEScripting::NativeAccessor
+ ASURA_ABSTRACT class Texture : public AEScripting::Object
{
public: