diff options
Diffstat (limited to 'source/modules/asura-core/graphics/gfx_device.cpp')
| -rw-r--r-- | source/modules/asura-core/graphics/gfx_device.cpp | 361 | 
1 files changed, 180 insertions, 181 deletions
diff --git a/source/modules/asura-core/graphics/gfx_device.cpp b/source/modules/asura-core/graphics/gfx_device.cpp index 83ea7f4..234ab23 100644 --- a/source/modules/asura-core/graphics/gfx_device.cpp +++ b/source/modules/asura-core/graphics/gfx_device.cpp @@ -9,201 +9,200 @@  using namespace AEMath; -namespace AsuraEngine -{ -	namespace Graphics -	{ +namespace_begin(AsuraEngine) +namespace_begin(Graphics)  #if ASURA_DEBUG -		static bool instantiated = false; +static bool instantiated = false;  #endif -		GfxDevice gfx; +GfxDevice gfx; -		GfxDevice::GfxDevice() -		{ +GfxDevice::GfxDevice() +{  #if ASURA_DEBUG  -			ASSERT(!instantiated); -			instantiated = true; +	ASSERT(!instantiated); +	instantiated = true;  #endif -		} +} -		GfxDevice::~GfxDevice() -		{ -		} +GfxDevice::~GfxDevice() +{ +} -		GfxDevice& GfxDevice::Get() -		{ -			return gfx; -		} +GfxDevice& GfxDevice::Get() +{ +	return gfx; +} -		static bool inited = false; +static bool inited = false; -		bool GfxDevice::Init(const AEMath::Recti& view) -		{ -			bool loaded = false; +bool GfxDevice::Init(const AEMath::Recti& view) +{ +	bool loaded = false;  #if ASURA_OPENGL_LOADER & ASURA_OPENGL_GLAD -			if (!loaded) -				loaded = gladLoadGL(); +	if (!loaded) +		loaded = gladLoadGL();  #endif -			if (!loaded) -				return false; -			SetViewport(view); - -			inited = true; -			return true; -		} - -		bool GfxDevice::Inited() -		{ -			return inited; -		} - -		void GfxDevice::WipeError() -		{ -			while (glGetError() != GL_NO_ERROR); -		} - -		bool GfxDevice::HasError() -		{ -			return glGetError() != GL_NO_ERROR;  -		} - -		GLenum GfxDevice::GetError() -		{ -			return glGetError(); -		} - -		void GfxDevice::SetDrawColor(float r, float g, float b, float a) -		{ -			state.drawColor.Set(r, g, b, a); -		} - -		Color& GfxDevice::GetDrawColor() -		{ -			return state.drawColor; -		} - -		Canvas* GfxDevice::GetActiveCanvas() const -		{ -			return state.canvas; -		} - -		void GfxDevice::SetActiveCanvas(Canvas* canvas) -		{ -			state.canvas = canvas; -		} - -		void GfxDevice::SetViewport(const Recti v) -		{ -			state.viewport = v; -			glViewport(v.x, v.y, v.w, v.h); -		} - -		const Recti& GfxDevice::GetViewport() -		{ -			return state.viewport; -		} - -		void GfxDevice::SetActiveShader(Shader* shader) -		{ -			if (state.shader == shader) -				return; -			if (state.shader)  -				state.shader->OnDisable();  -			state.shader = shader; -			if (shader) -			{ -				GLint program = shader->GetGLProgram(); -				glUseProgram(program); +	if (!loaded) +		return false; +	SetViewport(view); + +	inited = true; +	return true; +} + +bool GfxDevice::Inited() +{ +	return inited; +} + +void GfxDevice::WipeError() +{ +	while (glGetError() != GL_NO_ERROR); +} + +bool GfxDevice::HasError() +{ +	return glGetError() != GL_NO_ERROR;  +} + +GLenum GfxDevice::GetError() +{ +	return glGetError(); +} + +void GfxDevice::SetDrawColor(float r, float g, float b, float a) +{ +	state.drawColor.Set(r, g, b, a); +} + +Color& GfxDevice::GetDrawColor() +{ +	return state.drawColor; +} + +Canvas* GfxDevice::GetActiveCanvas() const +{ +	return state.canvas; +} + +void GfxDevice::SetActiveCanvas(Canvas* canvas) +{ +	state.canvas = canvas; +} + +void GfxDevice::SetViewport(const Recti v) +{ +	state.viewport = v; +	glViewport(v.x, v.y, v.w, v.h); +} + +const Recti& GfxDevice::GetViewport() +{ +	return state.viewport; +} + +void GfxDevice::SetActiveShader(Shader* shader) +{ +	if (state.shader == shader) +		return; +	if (state.shader)  +		state.shader->OnDisable();  +	state.shader = shader; +	if (shader) +	{ +		GLint program = shader->GetGLProgram(); +		glUseProgram(program);  #if ASURA_GL_PROFILE  -				++stats.shaderSwitch; +		++stats.shaderSwitch;  #endif -				shader->OnEnable(); -			} -		} - -		Shader* GfxDevice::GetActiveShader() const -		{ -			return state.shader; -		} - -		void GfxDevice::DrawArrays(GLenum mode, GLint first, GLsizei count) -		{ -			glDrawArrays(mode, first, count); +		shader->OnEnable(); +	} +} + +Shader* GfxDevice::GetActiveShader() const +{ +	return state.shader; +} + +void GfxDevice::DrawArrays(GLenum mode, GLint first, GLsizei count) +{ +	glDrawArrays(mode, first, count);  #if ASURA_GL_PROFILE -			++stats.drawCall; +	++stats.drawCall;  #endif -			if (state.shader) -				state.shader->OnUsed(); -		} - -		void GfxDevice::SetMatrixMode (MatrixMode mode) -		{ -			state.matrixMode = mode; -		} - -		MatrixMode GfxDevice::GetMatrixMode () -		{ -			return state.matrixMode;  -		} - -		void GfxDevice::PushMatrix () -		{ -			state.matrix[state.matrixMode].Push (); -		} - -		void GfxDevice::PopMatrix () -		{ -			state.matrix[state.matrixMode].Pop(); -		} - -		void GfxDevice::LoadIdentity() -		{ -			state.matrix[state.matrixMode].LoadIdentity(); -		} - -		void GfxDevice::Rotate (float angle) -		{ -			state.matrix[state.matrixMode].Rotate(angle); -		} - -		void GfxDevice::Translate (float x, float y) -		{ -			state.matrix[state.matrixMode].Translate(x, y); -		} - -		void GfxDevice::Scale (float x, float y) -		{ -			state.matrix[state.matrixMode].Scale(x, y); -		} - -		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); -		} - -		AEMath::Matrix44& GfxDevice::GetMatrix(MatrixMode mode) -		{ -			return state.matrix[mode].GetTop(); -		} - -		AEMath::Matrix44 GfxDevice::GetMVPMatrix() -		{ -			return state.matrix[MATRIX_MODE_PROJECTION].GetTop() -			     * state.matrix[MATRIX_MODE_VIEW].GetTop() -			     * state.matrix[MATRIX_MODE_MODEL].GetTop(); -		} - -		uint GfxDevice::GetMatrixDepth() -		{ -			return state.matrix[state.matrixMode].GetCapacity(); -		} - -		uint GfxDevice::GetMatrixIndex() -		{ -			return state.matrix[state.matrixMode].GetTopIndex(); -		} - -	} // Graphics  -} // AsuraEngine 
\ No newline at end of file +	if (state.shader) +		state.shader->OnUsed(); +} + +void GfxDevice::SetMatrixMode (MatrixMode mode) +{ +	state.matrixMode = mode; +} + +MatrixMode GfxDevice::GetMatrixMode () +{ +	return state.matrixMode;  +} + +void GfxDevice::PushMatrix () +{ +	state.matrix[state.matrixMode].Push (); +} + +void GfxDevice::PopMatrix () +{ +	state.matrix[state.matrixMode].Pop(); +} + +void GfxDevice::LoadIdentity() +{ +	state.matrix[state.matrixMode].LoadIdentity(); +} + +void GfxDevice::Rotate (float angle) +{ +	state.matrix[state.matrixMode].Rotate(angle); +} + +void GfxDevice::Translate (float x, float y) +{ +	state.matrix[state.matrixMode].Translate(x, y); +} + +void GfxDevice::Scale (float x, float y) +{ +	state.matrix[state.matrixMode].Scale(x, y); +} + +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); +} + +AEMath::Matrix44& GfxDevice::GetMatrix(MatrixMode mode) +{ +	return state.matrix[mode].GetTop(); +} + +AEMath::Matrix44 GfxDevice::GetMVPMatrix() +{ +	return state.matrix[MATRIX_MODE_PROJECTION].GetTop() +			  * state.matrix[MATRIX_MODE_VIEW].GetTop() +			  * state.matrix[MATRIX_MODE_MODEL].GetTop(); +} + +uint GfxDevice::GetMatrixDepth() +{ +	return state.matrix[state.matrixMode].GetCapacity(); +} + +uint GfxDevice::GetMatrixIndex() +{ +	return state.matrix[state.matrixMode].GetTopIndex(); +} + + +namespace_end +namespace_end
\ No newline at end of file  | 
