Ver código fonte

Clean up Renderer a bit

Daniele Bartolini 12 anos atrás
pai
commit
c54b791c03
3 arquivos alterados com 151 adições e 395 exclusões
  1. 32 184
      src/renderers/Renderer.h
  2. 98 172
      src/renderers/gl/GLRenderer.cpp
  3. 21 39
      src/renderers/gl/GLRenderer.h

+ 32 - 184
src/renderers/Renderer.h

@@ -36,7 +36,6 @@ namespace crown
 {
 
 class Image;
-class Rect;
 class VertexBuffer;
 class IndexBuffer;
 class OcclusionQuery;
@@ -74,120 +73,39 @@ public:
 	static Renderer* CreateRenderer();
 	static void	DestroyRenderer(Renderer* renderer);
 
-	/**
-		Constructor.
-	*/
-	Renderer() {}
 
-	/**
-		Destructor.
-	*/
+	Renderer() {}
 	virtual ~Renderer() {}
 
-	/**
-		Tasks to perform before a frame is rendered.
-	*/
+	///	Tasks to perform before a frame is rendered.
 	virtual void begin_frame() = 0;
 
-	/**
-		Tasks to perform after a frame is rendered.
-	*/
+	/// Tasks to perform after a frame is rendered.
 	virtual void end_frame() = 0;
 
-	/**
-		Sets the clearing color of the framebuffer.
-	*/
+	/// Sets the clearing color of the framebuffer.
 	virtual void set_clear_color(const Color4& color) = 0;
 
-	/**
-		Sets the viewport.
-	@note
-		The vieport area is defined by a Rectangle containing
-		window-space pixel coordinates for lower left corner and
-		width and height of the viewport rectangle.
-	@param absArea
-		The viewport rectangle.
-	*/
-	virtual void set_viewport(const Rect& absArea) = 0;
-
-	/**
-		Specifies material parameters.
-	@note
-		This method specifies the values for ambient, diffuse,
-		specular, emission and shininess parameters.
-	@param ambient
-		The ambient reflectance
-	@param diffuse
-		The diffuse reflectance
-	@param specular
-		The specular reflectance
-	@param emission
-		The emitted light int32_tensity
-	@param shininess
-		The specular exponent
-	*/
 	virtual void set_material_params(const Color4& ambient, const Color4& diffuse, const Color4& specular,
 					const Color4& emission, int32_t shininess) = 0;
 
-	/**
-		Sets whether lighting is enabled.
-	@param lighting
-		Whether lighting is enabled or not
-	*/
+	
+	/// Sets whether lighting is enabled.
 	virtual void set_lighting(bool lighting) = 0;
 
-	/**
-		Sets the global ambient light.
-	@note
-		The global ambient light defines the ambient
-		int32_tensity for the entire scene.
-	@param color
-		The ambient int32_tensity
-	*/
+	/// Sets the global ambient light @color.
 	virtual void set_ambient_light(const Color4& color) = 0;
 
-	/**
-		Set whether the given texture unit is enabled.
-	@param unit
-		The texture unit
-	@param texturing
-		Whether texturing is enabled or not
-	*/
+	/// Set whether the given texture @unit is enabled.
 	virtual void set_texturing(uint32_t unit, bool texturing) = 0;
 
-
-	/**
-		Sets the texture mode for the given texture unit.
-	@note
-		The texture mode specifies how the texture
-		values are int32_terpreted when a fragment is
-		textured.
-	@param unit
-		The texture unit
-	@param mode
-		The texture mode
-	@param
-		The blend color. This parameter means only when
-		mode == TM_BLEND
-	*/
+	/// Sets the texture @mode for the given texture @unit.
 	virtual void set_texture_mode(uint32_t unit, TextureMode mode, const Color4& blendColor) = 0;
 
-	/**
-		Sets the texture wrap parameter for the given texture unit.
-	@param unit
-		The texture unit
-	@param wrap
-		The wrap parameter
-	*/
+	/// Sets the texture @wrap parameter for the given texture @unit.
 	virtual void set_texture_wrap(uint32_t unit, TextureWrap wrap) = 0;
 
-	/**
-		Sets the filter for the given texture unit.
-	@param unit
-		The texture unit
-	@filter
-		The filter
-	*/
+	/// Sets the @filter for the given texture @unit.
 	virtual void set_texture_filter(uint32_t unit, TextureFilter filter) = 0;
 
 	virtual void set_light(uint32_t light, bool active) = 0;
@@ -195,95 +113,44 @@ public:
 	virtual void set_light_color(uint32_t light, const Color4& ambient, const Color4& diffuse, const Color4& specular) = 0;
 	virtual void set_light_attenuation(uint32_t light, float constant, float linear, float quadratic) = 0;
 
-	/**
-		Sets whether backface-culling is enabled.
-	@param culling
-		Whether backface-culling is enabled or not
-	*/
+	/// Sets whether backface-culling is enabled.
 	virtual void set_backface_culling(bool culling) = 0;
 
-	/**
-		Sets whether separate specular color is enabled.	
-	@param separate
-		Whether separate specular color is enabled or not
-	*/
+	/// Sets whether separate specular color is enabled.	
 	virtual void set_separate_specular_color(bool separate) = 0;
 
-	/**
-		Sets whether depth test is enabled.
-	@param test
-		Whether depth test is enabled or not
-	*/
+	/// Sets whether depth test is enabled.
 	virtual void set_depth_test(bool test) = 0;
 
-	/**
-		Sets whether writing to depth buffer is enabled.
-	@param write
-		Whether writing is enabled or not.
-	*/
+	/// Sets whether writing to depth buffer is enabled.
 	virtual void set_depth_write(bool write) = 0;
 
-	/**
-		Sets the depth function to use when testing depth values.
-	@param func
-		The depth function
-	*/
+	/// Sets the depth function to use when testing depth values.
 	virtual void set_depth_func(CompareFunction func) = 0;
 
-	/**
-		Sets whether normal vectors are scaled after transformations
-		and before lighting.
-	@note
-		If the modelview matrix scales space uniformly, this
-		has the effect of restoring the trasformed normal to unit length.
-	@param rescale
-		Whether rescaling is enabled or not
-	*/
+	///	Sets whether normal vectors are scaled after transformations
+	///	and before lighting.
+	/// @note
+	///	If the modelview matrix scales space uniformly, this
+	///	has the effect of restoring the trasformed normal to unit length.
 	virtual void set_rescale_normals(bool rescale) = 0;
 
-	/**
-		Sets whether blending is enabled.
-	@param blending
-		Whether blending is enabled or not
-	*/
+	/// Sets whether blending is enabled.
 	virtual void set_blending(bool blending) = 0;
 
-	/**
-		Specifies blending parameters.
-	@note
-		This method specifies the blend equation, the blend function
-		for source and destination pixel values and a const blend color.
-	@param equation
-		The blend equation
-	@param src
-		The blend function for source pixel
-	@param dst
-		The blend function for destination pixel
-	@param color
-		The constant color used when src or dst are equal to BF_CONSTANT_COLOR
-	*/
+	///	Specifies blending parameters.
+	/// @note
+	///	This method specifies the blend equation, the blend function
+	///	for source and destination pixel values and a const blend color.
 	virtual void set_blending_params(BlendEquation equation, BlendFunction src, BlendFunction dst, const Color4& color) = 0;
 
-	/**
-		Sets whether writing to color buffer is enabled.
-	@param write
-		Whether writing is enabled or not
-	*/
+	/// Sets whether writing to color buffer is enabled.
 	virtual void set_color_write(bool write) = 0;
 
-	/**
-		Sets whether fog is enabled.
-	@param fog
-		Whether fog is enabled or not
-	*/
+	/// Sets whether fog is enabled.
 	virtual void set_fog(bool fog) = 0;
 
-	/**
-		Specifies fog parameters.
-	@note
-		This method specifies mode, int32_tensity, start
-		and end position and the color of fog.
-	*/ // TODO 
+	/// Specifies fog parameters.
 	virtual void set_fog_params(FogMode mode, float density, float start, float end, const Color4& color) = 0;
 
 	virtual void set_alpha_test(bool test) = 0;
@@ -297,15 +164,14 @@ public:
 	virtual void set_front_face(FrontFace face) = 0;
 
 	virtual void set_viewport_params(int32_t x, int32_t y, int32_t width, int32_t height) = 0;
+	virtual void get_viewport_params(int32_t& x, int32_t& y, int32_t& width, int32_t& height) = 0;
 
 	virtual void set_scissor(bool scissor) = 0;
-
 	virtual void set_scissor_params(int32_t x, int32_t y, int32_t width, int32_t height) = 0;
+	virtual void get_scissor_params(int32_t& x, int32_t& y, int32_t& width, int32_t& height) = 0;
 
 	virtual void set_point_sprite(bool sprite) = 0;
-
 	virtual void set_point_size(float size) = 0;
-
 	virtual void set_point_params(float min, float max) = 0;
 
 	//! Sets the texture to use in the specified layer
@@ -317,32 +183,14 @@ public:
 	//! Loads the current matrix
 	virtual void set_matrix(MatrixType type, const Mat4& matrix) = 0;
 
-	//! Pushes the current model matrix
-	virtual void push_matrix() = 0;
-
-	//! Pops the previously pushed model matrix
-	virtual void pop_matrix() = 0;
-
 	//! Selects the active matrix
 	virtual void select_matrix(MatrixType type) = 0;
 
-	//! Sets the scissor box
-	virtual void set_scissor_box(uint32_t x, uint32_t y, uint32_t width, uint32_t height) = 0;
-
-	//! Gets the scissor box params
-	virtual void get_scissor_box(uint32_t& x, uint32_t& y, uint32_t& width, uint32_t& height) = 0;
-
 	virtual void render_vertex_index_buffer(const VertexBuffer* vertices, const IndexBuffer* indices) = 0;
 
 	virtual void render_point_buffer(const VertexBuffer* buffer) = 0;
 
-	//! Draws a Rectangle
-	virtual void draw_rectangle(const Point2& position, const Point2& dimensions, int32_t drawMode,
-														 const Color4& borderColor = Color4::BLACK, const Color4& fillColor = Color4::WHITE) = 0;
-
-	virtual void add_debug_line(const Vec3& start, const Vec3& end, const Color4& color) = 0;
-	virtual void draw_debug_lines() = 0;
-
+	// FIXME
 	virtual TextureId	load_texture(TextureResource* texture) = 0;
 	virtual void		unload_texture(TextureResource* texture) = 0;
 	virtual TextureId	reload_texture(TextureResource* old_texture, TextureResource* new_texture) = 0;

+ 98 - 172
src/renderers/gl/GLRenderer.cpp

@@ -56,36 +56,43 @@ namespace crown
 
 //-----------------------------------------------------------------------------
 GLRenderer::GLRenderer() :
-	mModelMatrixStackIndex(0),
-
-	mMaxLights(0),
-	mMaxTextureSize(0),
-	mMaxTextureUnits(0),
-	mMaxVertexIndices(0),
-	mMaxVertexVertices(0),
-	mMaxAnisotropy(0.0f),
+	m_max_lights(0),
+	m_max_texture_size(0),
+	m_max_texture_units(0),
+	m_max_vertex_indices(0),
+	m_max_vertex_vertices(0),
+	m_max_anisotropy(0.0f),
 
 	m_texture_count(0),
-	mActiveTextureUnit(0),
-
-	mLinesCount(0)
+	m_active_texture_unit(0)
 {
-	mMinMaxPointSize[0] = 0.0f;
-	mMinMaxPointSize[1] = 0.0f;
-	mMinMaxLineWidth[0] = 0.0f;
-	mMinMaxLineWidth[1] = 0.0f;
+	m_min_max_point_size[0] = 0.0f;
+	m_min_max_point_size[1] = 0.0f;
+	m_min_max_line_width[0] = 0.0f;
+	m_min_max_line_width[1] = 0.0f;
+
+	// Initialize viewport and scissor
+	m_viewport[0] = 0;
+	m_viewport[1] = 0;
+	m_viewport[2] = 0;
+	m_viewport[3] = 0;
+
+	m_scissor[0] = 0;
+	m_scissor[1] = 0;
+	m_scissor[2] = 0;
+	m_scissor[3] = 0;
 
 	// Initialize texture units
 	for (uint32_t i = 0; i < MAX_TEXTURE_UNITS; i++)
 	{
-		mTextureUnit[i] = 0;
-		mTextureUnitTarget[i] = GL_TEXTURE_2D;
+		m_texture_unit[i] = 0;
+		m_texture_unit_target[i] = GL_TEXTURE_2D;
 	}
 
 	// Initialize the matrices
 	for (uint32_t i = 0; i < MT_COUNT; i++)
 	{
-		mMatrix[i].load_identity();
+		m_matrix[i].load_identity();
 	}
 
 	GLenum err = glewInit();
@@ -94,20 +101,20 @@ GLRenderer::GLRenderer() :
 
 	Log::I("GLEW initialized.");
 
-	glGetIntegerv(GL_MAX_LIGHTS, &mMaxLights);
-	glGetIntegerv(GL_MAX_TEXTURE_SIZE, &mMaxTextureSize);
-	glGetIntegerv(GL_MAX_TEXTURE_UNITS, &mMaxTextureUnits);
-	glGetIntegerv(GL_MAX_ELEMENTS_INDICES, &mMaxVertexIndices);
-	glGetIntegerv(GL_MAX_ELEMENTS_VERTICES, &mMaxVertexVertices);
+	glGetIntegerv(GL_MAX_LIGHTS, &m_max_lights);
+	glGetIntegerv(GL_MAX_TEXTURE_SIZE, &m_max_texture_size);
+	glGetIntegerv(GL_MAX_TEXTURE_UNITS, &m_max_texture_units);
+	glGetIntegerv(GL_MAX_ELEMENTS_INDICES, &m_max_vertex_indices);
+	glGetIntegerv(GL_MAX_ELEMENTS_VERTICES, &m_max_vertex_vertices);
 
 	// Check for anisotropic filter support
 	if (GLEW_EXT_texture_filter_anisotropic)
 	{
-		glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &mMaxAnisotropy);
+		glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &m_max_anisotropy);
 	}
 
-	glGetFloatv(GL_ALIASED_POINT_SIZE_RANGE, &mMinMaxPointSize[0]);
-	glGetFloatv(GL_LINE_WIDTH_RANGE, &mMinMaxLineWidth[0]);
+	glGetFloatv(GL_ALIASED_POINT_SIZE_RANGE, &m_min_max_point_size[0]);
+	glGetFloatv(GL_LINE_WIDTH_RANGE, &m_min_max_line_width[0]);
 
 	const unsigned char* gl_vendor = glGetString(GL_VENDOR);
 	const unsigned char* gl_renderer = glGetString(GL_RENDERER);
@@ -116,16 +123,16 @@ GLRenderer::GLRenderer() :
 	Log::I("OpenGL Vendor\t: %s", gl_vendor);
 	Log::I("OpenGL Renderer\t: %s", gl_renderer);
 	Log::I("OpenGL Version\t: %s", gl_version);
-	Log::I("Min Point Size\t: %f", mMinMaxPointSize[0]);
-	Log::I("Max Point Size\t: %f", mMinMaxPointSize[1]);
-	Log::I("Min Line Width\t: %f", mMinMaxLineWidth[0]);
-	Log::I("Max Line Width\t: %f", mMinMaxLineWidth[1]);
-	Log::I("Max Texture Size\t: %dx%d", mMaxTextureSize, mMaxTextureSize);
-	Log::I("Max Texture Units\t: %d", mMaxTextureUnits);
-	Log::I("Max Lights\t\t: %d", mMaxLights);
-	Log::I("Max Vertex Indices\t: %d", mMaxVertexIndices);
-	Log::I("Max Vertex Vertices\t: %d", mMaxVertexVertices);
-	Log::I("Max Anisotropy\t: %f", mMaxAnisotropy);
+	Log::I("Min Point Size\t: %f", m_min_max_point_size[0]);
+	Log::I("Max Point Size\t: %f", m_min_max_point_size[1]);
+	Log::I("Min Line Width\t: %f", m_min_max_line_width[0]);
+	Log::I("Max Line Width\t: %f", m_min_max_line_width[1]);
+	Log::I("Max Texture Size\t: %dx%d", m_max_texture_size, m_max_texture_size);
+	Log::I("Max Texture Units\t: %d", m_max_texture_units);
+	Log::I("Max Lights\t\t: %d", m_max_lights);
+	Log::I("Max Vertex Indices\t: %d", m_max_vertex_indices);
+	Log::I("Max Vertex Vertices\t: %d", m_max_vertex_vertices);
+	Log::I("Max Anisotropy\t: %f", m_max_anisotropy);
 
 	glMatrixMode(GL_PROJECTION);
 	glLoadIdentity();
@@ -180,13 +187,6 @@ GLRenderer::~GLRenderer()
 {
 }
 
-//-----------------------------------------------------------------------------
-void GLRenderer::set_viewport(const Rect& absArea)
-{
-	glViewport((int32_t)absArea.min.x, (int32_t)absArea.min.y, (int32_t)absArea.max.x, (int32_t)absArea.max.y);
-	glScissor((int32_t)absArea.min.x, (int32_t)absArea.min.y, (int32_t)absArea.max.x, (int32_t)absArea.max.y);
-}
-
 //-----------------------------------------------------------------------------
 void GLRenderer::set_clear_color(const Color4& color)
 {
@@ -231,11 +231,11 @@ void GLRenderer::set_texturing(uint32_t unit, bool texturing)
 
 	if (texturing)
 	{
-		glEnable(mTextureUnitTarget[unit]);
+		glEnable(m_texture_unit_target[unit]);
 	}
 	else
 	{
-		glDisable(mTextureUnitTarget[unit]);
+		glDisable(m_texture_unit_target[unit]);
 	}
 }
 
@@ -247,11 +247,11 @@ void GLRenderer::set_texture(uint32_t unit, TextureId texture)
 		return;
 	}
 
-	mTextureUnitTarget[unit] = GL_TEXTURE_2D;
-	mTextureUnit[unit] = m_textures[texture.index].texture_object;
+	m_texture_unit_target[unit] = GL_TEXTURE_2D;
+	m_texture_unit[unit] = m_textures[texture.index].texture_object;
 
-	glEnable(mTextureUnitTarget[unit]);
-	glBindTexture(mTextureUnitTarget[unit], mTextureUnit[unit]);
+	glEnable(m_texture_unit_target[unit]);
+	glBindTexture(m_texture_unit_target[unit], m_texture_unit[unit]);
 }
 
 //-----------------------------------------------------------------------------
@@ -275,9 +275,9 @@ void GLRenderer::set_texture_wrap(uint32_t unit, TextureWrap wrap)
 {
 	GLenum glWrap = GL::GetTextureWrap(wrap);
 
-	glTexParameteri(mTextureUnitTarget[unit], GL_TEXTURE_WRAP_S, glWrap);
-	glTexParameteri(mTextureUnitTarget[unit], GL_TEXTURE_WRAP_T, glWrap);
-	glTexParameteri(mTextureUnitTarget[unit], GL_TEXTURE_WRAP_R, glWrap);
+	glTexParameteri(m_texture_unit_target[unit], GL_TEXTURE_WRAP_S, glWrap);
+	glTexParameteri(m_texture_unit_target[unit], GL_TEXTURE_WRAP_T, glWrap);
+	glTexParameteri(m_texture_unit_target[unit], GL_TEXTURE_WRAP_R, glWrap);
 }
 
 //-----------------------------------------------------------------------------
@@ -291,8 +291,8 @@ void GLRenderer::set_texture_filter(uint32_t unit, TextureFilter filter)
 
 	GL::GetTextureFilter(filter, minFilter, magFilter);
 
-	glTexParameteri(mTextureUnitTarget[unit], GL_TEXTURE_MIN_FILTER, minFilter);
-	glTexParameteri(mTextureUnitTarget[unit], GL_TEXTURE_MAG_FILTER, magFilter);
+	glTexParameteri(m_texture_unit_target[unit], GL_TEXTURE_MIN_FILTER, minFilter);
+	glTexParameteri(m_texture_unit_target[unit], GL_TEXTURE_MAG_FILTER, magFilter);
 }
 
 //-----------------------------------------------------------------------------
@@ -485,9 +485,23 @@ void GLRenderer::set_front_face(FrontFace face)
 //-----------------------------------------------------------------------------
 void GLRenderer::set_viewport_params(int32_t x, int32_t y, int32_t width, int32_t height)
 {
+	m_viewport[0] = x;
+	m_viewport[1] = y;
+	m_viewport[2] = width;
+	m_viewport[3] = height;
+
 	glViewport(x, y, width, height);
 }
 
+//-----------------------------------------------------------------------------
+void GLRenderer::get_viewport_params(int32_t& x, int32_t& y, int32_t& width, int32_t& height)
+{
+	x = m_viewport[0];
+	y = m_viewport[1];
+	width = m_viewport[2];
+	height = m_viewport[3];
+}
+
 //-----------------------------------------------------------------------------
 void GLRenderer::set_scissor(bool scissor)
 {
@@ -504,9 +518,23 @@ void GLRenderer::set_scissor(bool scissor)
 //-----------------------------------------------------------------------------
 void GLRenderer::set_scissor_params(int32_t x, int32_t y, int32_t width, int32_t height)
 {
+	m_scissor[0] = x;
+	m_scissor[1] = y;
+	m_scissor[2] = width;
+	m_scissor[3] = height;
+
 	glScissor(x, y, width, height);
 }
 
+//-----------------------------------------------------------------------------
+void GLRenderer::get_scissor_params(int32_t& x, int32_t& y, int32_t& width, int32_t& height)
+{
+	x = m_scissor[0];
+	y = m_scissor[1];
+	width = m_scissor[2];
+	height = m_scissor[3];
+}
+
 //-----------------------------------------------------------------------------
 void GLRenderer::set_point_sprite(bool sprite)
 {
@@ -553,13 +581,13 @@ void GLRenderer::end_frame()
 //-----------------------------------------------------------------------------
 Mat4 GLRenderer::get_matrix(MatrixType type) const
 {
-	return mMatrix[type];
+	return m_matrix[type];
 }
 
 //-----------------------------------------------------------------------------
 void GLRenderer::set_matrix(MatrixType type, const Mat4& matrix)
 {
-	mMatrix[type] = matrix;
+	m_matrix[type] = matrix;
 
 	switch (type)
 	{
@@ -567,46 +595,25 @@ void GLRenderer::set_matrix(MatrixType type, const Mat4& matrix)
 		case MT_MODEL:
 			glMatrixMode(GL_MODELVIEW);
 			// Transformations must be listed in reverse order
-			glLoadMatrixf((mMatrix[MT_VIEW] * mMatrix[MT_MODEL]).to_float_ptr());
+			glLoadMatrixf((m_matrix[MT_VIEW] * m_matrix[MT_MODEL]).to_float_ptr());
 			break;
 		case MT_PROJECTION:
 			glMatrixMode(GL_PROJECTION);
-			glLoadMatrixf(mMatrix[MT_PROJECTION].to_float_ptr());
+			glLoadMatrixf(m_matrix[MT_PROJECTION].to_float_ptr());
 			break;
 		case MT_TEXTURE:
 			glMatrixMode(GL_TEXTURE);
-			glLoadMatrixf(mMatrix[MT_TEXTURE].to_float_ptr());
+			glLoadMatrixf(m_matrix[MT_TEXTURE].to_float_ptr());
 			break;
 		case MT_COLOR:
 			//glMatrixMode(GL_COLOR);
-			//glLoadMatrixf(mMatrix[MT_COLOR].to_float_ptr());
+			//glLoadMatrixf(m_matrix[MT_COLOR].to_float_ptr());
 			break;
 		default:
 			break;
 	}
 }
 
-//-----------------------------------------------------------------------------
-void GLRenderer::push_matrix()
-{
-	assert(mModelMatrixStackIndex != MAX_MODEL_MATRIX_STACK_DEPTH);
-
-	//Copy the current matrix into the stack, and move to the next location
-	glGetFloatv(GL_MODELVIEW_MATRIX, mModelMatrixStack[mModelMatrixStackIndex].to_float_ptr());
-	mModelMatrixStackIndex++;
-}
-
-//-----------------------------------------------------------------------------
-void GLRenderer::pop_matrix()
-{
-	// Note: Is checking for push-pop count necessary? Maybe it should signal matrix stack underflow.
-	//glPopMatrix();
-	assert(mModelMatrixStackIndex > 0);
-
-	mModelMatrixStackIndex--;
-	set_matrix(MT_MODEL, mModelMatrixStack[mModelMatrixStackIndex]);
-}
-
 //-----------------------------------------------------------------------------
 void GLRenderer::select_matrix(MatrixType type)
 {
@@ -671,70 +678,16 @@ void GLRenderer::render_point_buffer(const VertexBuffer* buffer)
 	glDisableClientState(GL_VERTEX_ARRAY);
 }
 
-//-----------------------------------------------------------------------------
-void GLRenderer::set_scissor_box(uint32_t x, uint32_t y, uint32_t width, uint32_t height)
-{
-	int32_t vals[4];
-	glGetIntegerv(GL_VIEWPORT, vals);
-	glScissor(x, vals[3] - y - height, width, height);
-}
-
-//-----------------------------------------------------------------------------
-void GLRenderer::get_scissor_box(uint32_t& x, uint32_t& y, uint32_t& width, uint32_t& height)
-{
-	int32_t vals[4];
-	glGetIntegerv(GL_SCISSOR_BOX, vals);
-	int32_t valsViewport[4];
-	glGetIntegerv(GL_VIEWPORT, valsViewport);
-	x = vals[0];
-	width = vals[2];
-	height = vals[3];
-	y = valsViewport[3] - vals[1] - height;
-}
-
-//-----------------------------------------------------------------------------
-void GLRenderer::draw_rectangle(const Point2& position, const Point2& dimensions, int32_t drawMode,
-															 const Color4& borderColor, const Color4& fillColor)
-{
-	if (drawMode & DM_FILL)
-	{
-		glBegin(GL_QUADS);
-
-		glColor4f(fillColor.r, fillColor.g, fillColor.b, fillColor.a);
-
-		glVertex3i(position.x								, position.y							 , 0);
-		glVertex3i(position.x + dimensions.x, position.y							 , 0);
-		glVertex3i(position.x + dimensions.x, position.y + dimensions.y, 0);
-		glVertex3i(position.x								, position.y + dimensions.y, 0);
-		
-		glEnd();
-	}
-
-	if (drawMode & DM_BORDER)
-	{
-		glBegin(GL_LINE_LOOP);
-
-		glColor4f(borderColor.r, borderColor.g, borderColor.b, borderColor.a);
-
-		glVertex3i(position.x										, position.y									 , 0);
-		glVertex3i(position.x										, position.y + dimensions.y - 1, 0);
-		glVertex3i(position.x + dimensions.x - 1, position.y + dimensions.y - 1, 0);
-		glVertex3i(position.x + dimensions.x - 1, position.y									 , 0);
-
-		glEnd();
-	}
-}
-
 //-----------------------------------------------------------------------------
 bool GLRenderer::activate_texture_unit(uint32_t unit)
 {
-	if (unit >= (uint32_t) mMaxTextureUnits)
+	if (unit >= (uint32_t) m_max_texture_units)
 	{
 		return false;
 	}
 
 	glActiveTexture(GL_TEXTURE0 + unit);
-	mActiveTextureUnit = unit;
+	m_active_texture_unit = unit;
 
 	return true;
 }
@@ -742,7 +695,7 @@ bool GLRenderer::activate_texture_unit(uint32_t unit)
 //-----------------------------------------------------------------------------
 void GLRenderer::set_light(uint32_t light, bool active)
 {
-	if (light >= (uint32_t) mMaxLights)
+	if (light >= (uint32_t) m_max_lights)
 	{
 		return;
 	}
@@ -835,13 +788,17 @@ TextureId GLRenderer::load_texture(TextureResource* texture)
 //-----------------------------------------------------------------------------
 void GLRenderer::unload_texture(TextureResource* texture)
 {
-
+	// FIXME
+	(void)texture;
 }
 
 //-----------------------------------------------------------------------------
 TextureId GLRenderer::reload_texture(TextureResource* old_texture, TextureResource* new_texture)
 {
-
+	// FIXME
+	(void)old_texture;
+	(void)new_texture;
+	return TextureId();
 }
 
 //-----------------------------------------------------------------------------
@@ -878,36 +835,5 @@ void GLRenderer::check_gl_errors()
 	}
 }
 
-void GLRenderer::add_debug_line(const Vec3& start, const Vec3& end, const Color4& color)
-{
-	if (mLinesCount < 256)
-	{
-		mLinesData[mLinesCount].start		= start;
-		mLinesData[mLinesCount].c1			= color;
-		mLinesData[mLinesCount].end			= end;
-		mLinesData[mLinesCount].c2			= color;
-		mLinesCount++;
-	}
-}
-
-void GLRenderer::draw_debug_lines()
-{
-	if (mLinesCount == 0)
-	{
-		return;
-	}
-
-	glEnableClientState(GL_VERTEX_ARRAY);
-	glEnableClientState(GL_COLOR_ARRAY);
-
-		glVertexPointer(3, GL_FLOAT, sizeof(float) * 7, &mLinesData[0].start);
-		glColorPointer(4, GL_FLOAT, sizeof(float) * 7, &mLinesData[0].c1);
-
-		glDrawArrays(GL_LINES, 0, mLinesCount * 4);
-
-	glDisableClientState(GL_VERTEX_ARRAY);
-
-	mLinesCount = 0;
-}
-
 } // namespace crown
+

+ 21 - 39
src/renderers/gl/GLRenderer.h

@@ -57,7 +57,7 @@ public:
 	void				end_frame();
 
 	void				set_clear_color(const Color4& color);
-	void				set_viewport(const Rect& absArea);
+
 	void				set_material_params(const Color4& ambient, const Color4& diffuse, const Color4& specular, const Color4& emission, int32_t shininess);
 	void				set_lighting(bool lighting);
 	void				set_ambient_light(const Color4& color);
@@ -98,9 +98,11 @@ public:
 	void				set_front_face(FrontFace face);
 
 	void				set_viewport_params(int32_t x, int32_t y, int32_t width, int32_t height);
+	void				get_viewport_params(int32_t& x, int32_t& y, int32_t& width, int32_t& height);
 
 	void				set_scissor(bool scissor);
 	void				set_scissor_params(int32_t x, int32_t y, int32_t width, int32_t height);
+	void				get_scissor_params(int32_t& x, int32_t& y, int32_t& width, int32_t& height);
 
 	void				set_point_sprite(bool sprite);
 	void				set_point_size(float size);
@@ -109,26 +111,17 @@ public:
 	Mat4				get_matrix(MatrixType type) const;
 	void				set_matrix(MatrixType type, const Mat4& matrix);
 
-	void				push_matrix();
-	void				pop_matrix();
-
 	void				select_matrix(MatrixType type);
 
 	void				render_vertex_index_buffer(const VertexBuffer* vertices, const IndexBuffer* indices);
 	void				render_point_buffer(const VertexBuffer* buffer);
 
-	void				set_scissor_box(uint32_t x, uint32_t y, uint32_t width, uint32_t height);
-	void				get_scissor_box(uint32_t& x, uint32_t& y, uint32_t& width, uint32_t& height);
-	void				draw_rectangle(const Point2& position, const Point2& dimensions, int32_t drawMode,
-														 const Color4& borderColor, const Color4& fillColor);
-
-	void				add_debug_line(const Vec3& start, const Vec3& end, const Color4& color);
-	void				draw_debug_lines();
-
 	TextureId			load_texture(TextureResource* texture);
 	void				unload_texture(TextureResource* texture);
 	TextureId			reload_texture(TextureResource* old_texture, TextureResource* new_texture);
 
+private:
+
 	bool				activate_texture_unit(uint32_t unit);		//!< Activates a texture unit and returns true if succes
 	bool				activate_light(uint32_t light);
 
@@ -137,41 +130,30 @@ public:
 private:
 
 	// Matrices
-	Mat4				mMatrix[MT_COUNT];
-
-	Mat4				mModelMatrixStack[MAX_MODEL_MATRIX_STACK_DEPTH];
-	uint32_t			mModelMatrixStackIndex;
+	Mat4				m_matrix[MT_COUNT];
 
 	// Limits
-	int32_t				mMaxLights;
-	int32_t				mMaxTextureSize;
-	int32_t				mMaxTextureUnits;
-	int32_t				mMaxVertexIndices;
-	int32_t				mMaxVertexVertices;
+	int32_t				m_max_lights;
+	int32_t				m_max_texture_size;
+	int32_t				m_max_texture_units;
+	int32_t				m_max_vertex_indices;
+	int32_t				m_max_vertex_vertices;
+
+	float				m_max_anisotropy;
+	float				m_min_max_point_size[2];
+	float				m_min_max_line_width[2];
 
-	float				mMaxAnisotropy;
-	float				mMinMaxPointSize[2];
-	float				mMinMaxLineWidth[2];
+	// Viewport and scissor
+	int32_t				m_viewport[4];
+	int32_t				m_scissor[4];
 
 	// Texture management
 	uint32_t			m_texture_count;
 	GLTexture			m_textures[MAX_TEXTURES];
 
-	uint32_t			mActiveTextureUnit;
-	GLuint				mTextureUnit[MAX_TEXTURE_UNITS];
-	GLenum				mTextureUnitTarget[MAX_TEXTURE_UNITS];
-
-	// Debug lines
-	struct DebugLinesData
-	{
-		Vec3	start;
-		Color4	c1;
-		Vec3	end;
-		Color4	c2;
-	};
-
-	uint32_t				mLinesCount;
-	DebugLinesData		mLinesData[1024];
+	uint32_t			m_active_texture_unit;
+	GLuint				m_texture_unit[MAX_TEXTURE_UNITS];
+	GLenum				m_texture_unit_target[MAX_TEXTURE_UNITS];
 
 	friend class TextureResource;
 };