diff options
| author | chai <chaifix@163.com> | 2019-06-06 00:11:18 +0800 |
|---|---|---|
| committer | chai <chaifix@163.com> | 2019-06-06 00:11:18 +0800 |
| commit | 88b882ed0b432c6aff2063213e2f793a36dd25f7 (patch) | |
| tree | 5fe5d5334050e1a1146aa63e61e88aa2f5170727 /source/modules/asura-core/graphics/gfx_device.h | |
| parent | f6c0498c9728a286c13980ed3b60763d02e1b3a0 (diff) | |
*misc
Diffstat (limited to 'source/modules/asura-core/graphics/gfx_device.h')
| -rw-r--r-- | source/modules/asura-core/graphics/gfx_device.h | 160 |
1 files changed, 160 insertions, 0 deletions
diff --git a/source/modules/asura-core/graphics/gfx_device.h b/source/modules/asura-core/graphics/gfx_device.h new file mode 100644 index 0000000..5bb8c6a --- /dev/null +++ b/source/modules/asura-core/graphics/gfx_device.h @@ -0,0 +1,160 @@ +#ifndef __ASURA_ENGINE_GFX_DEVICE_H__ +#define __ASURA_ENGINE_GFX_DEVICE_H__ + +#include <stack> + +#include <glad/glad.h> + +#include <asura-utils/scripting/portable.hpp> +#include <asura-utils/math/rect.hpp> +#include <asura-utils/math/matrix44.h> +#include <asura-utils/math/vector4.h> + +#include "color.h" +#include "matrix_stack.h" + +namespace AsuraEngine +{ + namespace Graphics + { + + class Profiler; + class Shader; + + enum MatrixMode + { + MATRIX_MODE_PROJECTION = 0, + MATRIX_MODE_MODEL = 1, + MATRIX_MODE_VIEW = 2, + }; + + enum GLParams + { + GL_PARAM_MAX_TEXTURE_UNIT = 1, + }; + + /// + /// OpenGLÉÏÏÂÎÄ£¬ÓÃÀ´×öһЩopengl״̬µÄ×·×Ù¡£ÔÚ±à¼Æ÷¶à´°¿Ú»·¾³Ï£¬Ò»¸ö´°¿Ú¶ÔÓ¦Ò»¸öhwnd£¬ + /// Ò»¸öhdc£¬ÒÔ¼°Êý¸öopengl context£¬Èç¹ûʹÓÃwglMakeCurrent(hdc, glc)Ö¸¶¨µ±Ç°Ï̶߳ú¶ä + /// äÖȾ´°¿ÚhdcºÍopenglÉÏÏÂÎÄglc£¬glÖмǼµÄ¾ÍÊÇÈÎÒâÒ»¸öÏ̵߳ÄÈÎÒâÒ»¸ö´°¿ÚµÄÈÎÒâÒ»¸öOpenGL + /// ÉÏÏÂÎĵÄ״̬£¬²»Ö§³Ö¶àÉÏÏÂÎÄäÖȾ¡£ + /// + class GfxDevice : public AEScripting::Portable<GfxDevice> + { + public: + + GfxDevice(); + ~GfxDevice(); + + /// + /// »ñµÃ³£Á¿Öµ + /// + int GetParam(GLParams param); + + /// + /// ³õʼ»¯OpenGLÉÏÏÂÎIJÎÊý£¬·¢ÉúÔÚ´´½¨OpenGLÉÏÏÂÎÄÖ®ºó¡£´Ëº¯Êý»á×¢²áOpenGLº¯ÊýµÄµØÖ·¡£ + /// + bool Init(const AEMath::Recti& viewport); + bool Inited(); + + void SetViewport(const AEMath::Recti viewport); + const AEMath::Recti& GetViewport(); + + void UseShader(Shader* shader); + void UnuseShader(); + Shader* GetShader(); + + // Draw call. + void DrawArrays(GLenum mode, GLint first, GLsizei count); + + /// + /// Matrix stackÏà¹Ø²Ù×÷ + /// + void SetMatrixMode(MatrixMode mode); + MatrixMode GetMatrixMode(); + void PushMatrix(); + void PopMatrix(); + void LoadIdentity(); + void Rotate(float angle); + void Translate(float x, float y); + void Scale(float x, float y); + void Ortho(float l, float r, float b, float t, float n, float f); + AEMath::Matrix44& GetMatrix(MatrixMode mode); + AEMath::Matrix44 GetMVPMatrix(); + uint GetMatrixDepth(); + uint GetMatrixIndex(); + + void SetDrawColor(float r, float g, float b, float a); + Color& GetDrawColor(); + + /// + /// ÇåÀí´íÎóÌáʾ + /// + void WipeError(); + bool HasError(); + GLenum GetError(); + + /// + /// OpenGL3.0ÒÔºóÓÉÓû§¹ÜÀí¾ØÕó±ä»»¡¢ÊÓ¿Ú¡¢shaderµÈ²ÎÊý£¬ÕâÀï±£´æÒ»Ð©OpenGL״̬¡£×¢Òâ + /// ËÆºõÈ«½ø³ÌµÄ£¬Ò²¾ÍÊÇ˵£¬Asura²»Ö§³Ö¶àÏß³ÌäÖȾ¡£OpenGLÉÏÏÂÎĵĴ´½¨Ê¹µÃÒ»¸öÉÏÏ + /// Îİó¶¨ÔÚÒ»¸öHDC\´°¿ÚÉÏ£¬ÓÉÓÚ´°¿ÚÊÇÔÚÌØ¶¨Ï̴߳´½¨µÄ£¬ËùÒÔOpenGLÉÏÏÂÎÄÒ²°ó¶¨ÁËÒ»¸ö + /// ÌØ¶¨µÄÏ̡߳£Í¬Ò»¸öÏ̵߳IJ»Í¬HDC\´°¿Ú¿ÉÒÔ¹²Ïíͬһ¸öOpenGLÉÏÏÂÎÄ¡£¹²ÏíÉÏÏÂÎÄÊÇΪÁË + /// ¹²ÏíÉÏÏÂÎÄÖд´½¨µÄtextuer\shaderµÈhandle¡£ + /// + struct + { + Shader* shader; ///< µ±Ç°Ê¹ÓõÄshader + AEMath::Recti viewport; ///< µ±Ç°µÄÊÓÇø£¬ÔÚÇл»HDC»òÕß±¾´°¿Ú´óС¸Ä±ä»òÕß²¿·ÖË¢ÐÂʱ±ä¶¯ + MatrixStack matrix[3]; ///< model, view, projection¾ØÕó + MatrixMode matrixMode; ///< µ±Ç°²Ù×÷µÄ¾ØÕó + Color drawColor; ///< »æÖƵÄÑÕÉ« + } state; + +#if ASURA_GL_PROFILE + struct + { + uint drawCall; ///< ͳ¼Ædrawcall + uint canvasSwitch; ///< Çл»textureµÄ´ÎÊý + uint shaderSwitch; ///< Çл»shaderµÄ´ÎÊý + } stats; +#endif + + private: + + friend class Profiler; + + //----------------------------------------------------------------------------// + + LUAX_DECL_SINGLETON(GfxDevice); + + LUAX_DECL_ENUM(MatrixMode, 1); + LUAX_DECL_ENUM(GLParams, 1); + + LUAX_DECL_METHOD(_SetMatrixMode); + LUAX_DECL_METHOD(_GetMatrixMode); + LUAX_DECL_METHOD(_PushMatrix); + LUAX_DECL_METHOD(_PopMatrix); + LUAX_DECL_METHOD(_LoadIdentity); + LUAX_DECL_METHOD(_Rotate); + LUAX_DECL_METHOD(_Translate); + LUAX_DECL_METHOD(_Scale); + LUAX_DECL_METHOD(_Ortho); + LUAX_DECL_METHOD(_GetMatrixDepth); + LUAX_DECL_METHOD(_GetMatrixIndex); + + LUAX_DECL_METHOD(_UseShader); + LUAX_DECL_METHOD(_UnuseShader); + + //----------------------------------------------------------------------------// + + }; + + /// + /// OpenGLµ¥Àý¡£ + /// + extern GfxDevice gfx; + + } +} + +#endif
\ No newline at end of file |
