summaryrefslogtreecommitdiff
path: root/source/modules/asura-core/graphics
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2019-06-08 08:34:52 +0800
committerchai <chaifix@163.com>2019-06-08 08:34:52 +0800
commitd7a972a0f16da0fd7bf4c0b70913920216ff3113 (patch)
treea9146629cbf513200462c3f1223a9e07f3e01862 /source/modules/asura-core/graphics
parent8bfe54676f728076a92d802bb5d064e58265c8f2 (diff)
*misc
Diffstat (limited to 'source/modules/asura-core/graphics')
-rw-r--r--source/modules/asura-core/graphics/canvas.h9
-rw-r--r--source/modules/asura-core/graphics/gfx_device.h26
-rw-r--r--source/modules/asura-core/graphics/image.cpp1
-rw-r--r--source/modules/asura-core/graphics/image.h4
-rw-r--r--source/modules/asura-core/graphics/shader.cpp97
-rw-r--r--source/modules/asura-core/graphics/shader.h9
6 files changed, 71 insertions, 75 deletions
diff --git a/source/modules/asura-core/graphics/canvas.h b/source/modules/asura-core/graphics/canvas.h
index 49096c7..4175561 100644
--- a/source/modules/asura-core/graphics/canvas.h
+++ b/source/modules/asura-core/graphics/canvas.h
@@ -47,19 +47,10 @@ namespace AsuraEngine
private:
- ///
- /// Frame buffer object id.
- ///
GLuint mFBO;
- ///
- /// 󶨵tex
- ///
GLuint mTex;
- ///
- /// canvasĴС
- ///
uint mWidth, mHeight;
public:
diff --git a/source/modules/asura-core/graphics/gfx_device.h b/source/modules/asura-core/graphics/gfx_device.h
index 5bb8c6a..c93717f 100644
--- a/source/modules/asura-core/graphics/gfx_device.h
+++ b/source/modules/asura-core/graphics/gfx_device.h
@@ -46,14 +46,8 @@ namespace AsuraEngine
GfxDevice();
~GfxDevice();
- ///
- /// óֵ
- ///
int GetParam(GLParams param);
- ///
- /// ʼOpenGLIJڴOpenGL֮󡣴˺עOpenGLĵַ
- ///
bool Init(const AEMath::Recti& viewport);
bool Inited();
@@ -64,12 +58,8 @@ namespace AsuraEngine
void UnuseShader();
Shader* GetShader();
- // Draw call.
void DrawArrays(GLenum mode, GLint first, GLsizei count);
- ///
- /// Matrix stackز
- ///
void SetMatrixMode(MatrixMode mode);
MatrixMode GetMatrixMode();
void PushMatrix();
@@ -87,20 +77,10 @@ namespace AsuraEngine
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\shaderhandle
- ///
struct
{
Shader* shader; ///< ǰʹõshader
@@ -113,9 +93,9 @@ namespace AsuraEngine
#if ASURA_GL_PROFILE
struct
{
- uint drawCall; ///< ͳdrawcall
- uint canvasSwitch; ///< лtextureĴ
- uint shaderSwitch; ///< лshaderĴ
+ uint drawCall; ///< ͳdrawcall
+ uint canvasSwitch; ///< лtextureĴ
+ uint shaderSwitch; ///< лshaderĴ
} stats;
#endif
diff --git a/source/modules/asura-core/graphics/image.cpp b/source/modules/asura-core/graphics/image.cpp
index d2f1d7b..42fc2ab 100644
--- a/source/modules/asura-core/graphics/image.cpp
+++ b/source/modules/asura-core/graphics/image.cpp
@@ -7,6 +7,7 @@
#include "gfx_device.h"
using namespace AEIO;
+using namespace AEImage;
namespace AsuraEngine
{
diff --git a/source/modules/asura-core/graphics/image.h b/source/modules/asura-core/graphics/image.h
index 932ca65..8e3e7d3 100644
--- a/source/modules/asura-core/graphics/image.h
+++ b/source/modules/asura-core/graphics/image.h
@@ -44,8 +44,8 @@ namespace AsuraEngine
/// ͼύGPUϢ¹imageʹglTexImage2D
/// ύimageݡ
///
- bool Load(ImageData* decodeData);
- bool Load(ImageData* decodeData, const AEMath::Vector2i& pos);
+ bool Load(AEImage::ImageData* decodeData);
+ bool Load(AEImage::ImageData* decodeData, const AEMath::Vector2i& pos);
uint GetWidth();
uint GetHeight();
diff --git a/source/modules/asura-core/graphics/shader.cpp b/source/modules/asura-core/graphics/shader.cpp
index 866c4da..afd10b0 100644
--- a/source/modules/asura-core/graphics/shader.cpp
+++ b/source/modules/asura-core/graphics/shader.cpp
@@ -21,74 +21,97 @@ namespace AsuraEngine
Shader::~Shader()
{
- if(mVertShader != 0)
- glDeleteShader(mVertShader);
- if(mFragShader != 0)
- glDeleteShader(mFragShader);
- if(mProgram != 0)
- glDeleteProgram(mProgram);
+ if(mVertShader) glDeleteShader(mVertShader);
+ if(mFragShader) glDeleteShader(mFragShader);
+ if(mProgram) glDeleteProgram(mProgram);
}
bool Shader::Load(const string& vert, const string& frag)
{
- GLenum err = GL_NO_ERROR;
- GLint success;
string warnning = "";
- if (mProgram == 0)
+ if (!mProgram)
{
mProgram = glCreateProgram();
- if (mProgram == 0)
+ if (!mProgram)
throw Exception("Cannot create OpenGL shader program.");
}
- if (mVertShader == 0)
+ if (!CompileVertexShader(vert, warnning))
{
- mVertShader = glCreateShader(GL_VERTEX_SHADER);
- if (mVertShader == 0)
- throw Exception("Cannot create OpenGL vertex shader.");
+ throw Exception("Compile vertex shader failed:%s", warnning);
}
- if (mFragShader == 0)
+ if (!CompileFragementShader(frag, warnning))
{
- mFragShader = glCreateShader(GL_FRAGMENT_SHADER);
- if(mFragShader == 0)
- throw Exception("Cannot create OpenGL fragment shader.");
+ throw Exception("Compile fragment shader failed:%s", warnning);
}
- const GLchar* source;
+ glAttachShader(mProgram, mVertShader);
+ glAttachShader(mProgram, mFragShader);
+
+ glLinkProgram(mProgram);
+ GLint success;
+ glGetProgramiv(mProgram, GL_LINK_STATUS, &success);
+ if (success == GL_FALSE)
+ {
+ warnning = GetProgramWarnings();
+ throw Exception("Link shader program failed:\n%s", warnning.c_str());
+ }
+
+ return true;
+ }
+
+ bool Shader::CompileVertexShader(const string& vert, string& outError)
+ {
+ if (!mVertShader)
+ {
+ mVertShader = glCreateShader(GL_VERTEX_SHADER);
+ if (!mVertShader)
+ {
+ outError = "Cannot create OpenGL Vertex shader.";
+ return false;
+ }
+ }
+
+ const GLchar* source = vert.c_str();
+ GLint success;
- // Compile vertex shader.
- source = vert.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());
+ outError = GetShaderWarnings(mVertShader);
+ return false;
}
- // Compile fragment shader.
+ return true;
+ }
+
+ bool Shader::CompileFragementShader(const string& frag, string& outError)
+ {
+ if (!mFragShader)
+ {
+ mFragShader = glCreateShader(GL_FRAGMENT_SHADER);
+ if (!mFragShader)
+ {
+ outError = "Cannot create OpenGL fragment shader.";
+ return false;
+ }
+ }
+
+ const GLchar* source = frag.c_str();
+ GLint success;
+
source = frag.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());
+ outError = GetShaderWarnings(mFragShader);
+ return false;
}
return true;
diff --git a/source/modules/asura-core/graphics/shader.h b/source/modules/asura-core/graphics/shader.h
index b5d866e..f4553ec 100644
--- a/source/modules/asura-core/graphics/shader.h
+++ b/source/modules/asura-core/graphics/shader.h
@@ -45,12 +45,10 @@ namespace AsuraEngine
void OnUse();
void OnUnuse();
- ///
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
bool HasUniform(const std::string& uniform);
uint GetUniformLocation(const std::string& uniform);
void SetUniformFloat(uint loc, float value);
@@ -88,15 +86,18 @@ namespace AsuraEngine
LUAX_DECL_METHOD(_SetUniformVector3);
LUAX_DECL_METHOD(_SetUniformVector4);
LUAX_DECL_METHOD(_SetUniformColor);
- /// vertex attributes
+
LUAX_DECL_METHOD(_GetAttributeLocation);
LUAX_DECL_METHOD(_SetAttribute);
LUAX_DECL_METHOD(_DisableAttribute);
- /// uniform
+
LUAX_DECL_METHOD(_SetBuiltInUniforms);
//----------------------------------------------------------------------------//
+ bool CompileVertexShader(const std::string& vert, std::string& outError);
+ bool CompileFragementShader(const std::string& frag, std::string& outError);
+
std::string GetProgramWarnings();
std::string GetShaderWarnings(GLuint shader);