Browse Source

Remove some more deprecated OpenGL functions and start to port to OpenGL ES 2.0

Daniele Bartolini 12 years ago
parent
commit
68ef145209

+ 0 - 9
src/renderers/Renderer.h

@@ -178,9 +178,6 @@ public:
 	/// Set whether the given texture @unit is enabled.
 	/// Set whether the given texture @unit is enabled.
 	virtual void			set_texturing(uint32_t unit, bool texturing) = 0;
 	virtual void			set_texturing(uint32_t unit, bool texturing) = 0;
 
 
-	/// 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.
 	/// Sets the texture @wrap parameter for the given texture @unit.
 	virtual void			set_texture_wrap(uint32_t unit, TextureWrap wrap) = 0;
 	virtual void			set_texture_wrap(uint32_t unit, TextureWrap wrap) = 0;
 
 
@@ -210,8 +207,6 @@ public:
 
 
 	/// Sets whether writing to color buffer is enabled.
 	/// Sets whether writing to color buffer is enabled.
 	virtual void			set_color_write(bool write) = 0;
 	virtual void			set_color_write(bool write) = 0;
-
-	virtual void			set_shading_type(ShadingType type) = 0;
 				
 				
 	virtual void 			set_front_face(FrontFace face) = 0;
 	virtual void 			set_front_face(FrontFace face) = 0;
 				
 				
@@ -222,10 +217,6 @@ public:
 	virtual void 			set_scissor_params(int32_t x, int32_t y, int32_t width, int32_t height) = 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 			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;
-				
 	virtual Mat4 			get_matrix(MatrixType type) const = 0;
 	virtual Mat4 			get_matrix(MatrixType type) const = 0;
 	virtual void 			set_matrix(MatrixType type, const Mat4& matrix) = 0;
 	virtual void 			set_matrix(MatrixType type, const Mat4& matrix) = 0;
 				
 				

+ 5 - 68
src/renderers/gl/GLRenderer.cpp

@@ -113,7 +113,7 @@ void GLRenderer::init()
 	assert(err == GLEW_OK);
 	assert(err == GLEW_OK);
 
 
 	glGetIntegerv(GL_MAX_TEXTURE_SIZE, &m_max_texture_size);
 	glGetIntegerv(GL_MAX_TEXTURE_SIZE, &m_max_texture_size);
-	glGetIntegerv(GL_MAX_TEXTURE_UNITS, &m_max_texture_units);
+	glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &m_max_texture_units);
 	glGetIntegerv(GL_MAX_ELEMENTS_INDICES, &m_max_vertex_indices);
 	glGetIntegerv(GL_MAX_ELEMENTS_INDICES, &m_max_vertex_indices);
 	glGetIntegerv(GL_MAX_ELEMENTS_VERTICES, &m_max_vertex_vertices);
 	glGetIntegerv(GL_MAX_ELEMENTS_VERTICES, &m_max_vertex_vertices);
 
 
@@ -164,6 +164,10 @@ void GLRenderer::init()
 	// Disable dithering
 	// Disable dithering
 	glDisable(GL_DITHER);
 	glDisable(GL_DITHER);
 
 
+	// Point sprites enabled by default
+	glEnable(GL_POINT_SPRITE);
+	glTexEnvi(GL_POINT_SPRITE, GL_COORD_REPLACE, GL_TRUE);
+
 	Log::i("OpenGL Renderer initialized.");
 	Log::i("OpenGL Renderer initialized.");
 
 
 	load_default_shaders();
 	load_default_shaders();
@@ -612,22 +616,6 @@ void GLRenderer::set_texturing(uint32_t unit, bool texturing)
 	}
 	}
 }
 }
 
 
-//-----------------------------------------------------------------------------
-void GLRenderer::set_texture_mode(uint32_t unit, TextureMode mode, const Color4& blendColor)
-{
-	if (!activate_texture_unit(unit))
-		return;
-
-	GLint envMode = GL::texture_mode(mode);
-
-	if (envMode == GL_BLEND)
-	{
-		glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, &blendColor.r);
-	}
-
-	glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, envMode);
-}
-
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 void GLRenderer::set_texture_wrap(uint32_t unit, TextureWrap wrap)
 void GLRenderer::set_texture_wrap(uint32_t unit, TextureWrap wrap)
 {
 {
@@ -635,7 +623,6 @@ void GLRenderer::set_texture_wrap(uint32_t unit, TextureWrap wrap)
 
 
 	glTexParameteri(m_texture_unit_target[unit], GL_TEXTURE_WRAP_S, 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_T, glWrap);
-	glTexParameteri(m_texture_unit_target[unit], GL_TEXTURE_WRAP_R, glWrap);
 }
 }
 
 
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
@@ -734,19 +721,6 @@ void GLRenderer::set_color_write(bool write)
 	}
 	}
 }
 }
 
 
-//-----------------------------------------------------------------------------
-void GLRenderer::set_shading_type(ShadingType type)
-{
-	GLenum glMode = GL_SMOOTH;
-
-	if (type == ST_FLAT)
-	{
-		glMode = GL_FLAT;
-	}
-
-	glShadeModel(glMode);
-}
-
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 void GLRenderer::set_front_face(FrontFace face)
 void GLRenderer::set_front_face(FrontFace face)
 {
 {
@@ -813,34 +787,6 @@ void GLRenderer::get_scissor_params(int32_t& x, int32_t& y, int32_t& width, int3
 	height = m_scissor[3];
 	height = m_scissor[3];
 }
 }
 
 
-//-----------------------------------------------------------------------------
-void GLRenderer::set_point_sprite(bool sprite)
-{
-	if (sprite)
-	{
-		glEnable(GL_POINT_SPRITE);
-		glTexEnvi(GL_POINT_SPRITE, GL_COORD_REPLACE, GL_TRUE);
-	}
-	else
-	{
-		glDisable(GL_POINT_SPRITE);
-		glTexEnvi(GL_POINT_SPRITE, GL_COORD_REPLACE, GL_FALSE);
-	}
-}
-
-//-----------------------------------------------------------------------------
-void GLRenderer::set_point_size(float size)
-{
-	glPointSize(size);
-}
-
-//-----------------------------------------------------------------------------
-void GLRenderer::set_point_params(float min, float max)
-{
-	glPointParameterf(GL_POINT_SIZE_MIN, min);
-	glPointParameterf(GL_POINT_SIZE_MAX, max);
-}
-
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 void GLRenderer::begin_frame()
 void GLRenderer::begin_frame()
 {
 {
@@ -1077,18 +1023,9 @@ void GLRenderer::check_gl_errors() const
 			case GL_INVALID_OPERATION:
 			case GL_INVALID_OPERATION:
 				Log::e("GLRenderer: GL_INVALID_OPERATION");
 				Log::e("GLRenderer: GL_INVALID_OPERATION");
 				break;
 				break;
-			case GL_STACK_OVERFLOW:
-				Log::e("GLRenderer: GL_STACK_OVERFLOW");
-				break;
-			case GL_STACK_UNDERFLOW:
-				Log::e("GLRenderer: GL_STACK_UNDERFLOW");
-				break;
 			case GL_OUT_OF_MEMORY:
 			case GL_OUT_OF_MEMORY:
 				Log::e("GLRenderer: GL_OUT_OF_MEMORY");
 				Log::e("GLRenderer: GL_OUT_OF_MEMORY");
 				break;
 				break;
-			case GL_TABLE_TOO_LARGE:
-				Log::e("GLRenderer: GL_OUT_OF_MEMORY");
-				break;
 		}
 		}
 	}
 	}
 }
 }

+ 0 - 6
src/renderers/gl/GLRenderer.h

@@ -118,7 +118,6 @@ public:
 
 
 	void				bind_texture(uint32_t unit, TextureId texture);
 	void				bind_texture(uint32_t unit, TextureId texture);
 	void				set_texturing(uint32_t unit, bool texturing);
 	void				set_texturing(uint32_t unit, bool texturing);
-	void				set_texture_mode(uint32_t unit, TextureMode mode, const Color4& blendColor);
 	void				set_texture_wrap(uint32_t unit, TextureWrap wrap);
 	void				set_texture_wrap(uint32_t unit, TextureWrap wrap);
 	void				set_texture_filter(uint32_t unit, TextureFilter filter);
 	void				set_texture_filter(uint32_t unit, TextureFilter filter);
 
 
@@ -172,7 +171,6 @@ public:
 	void				set_blending_params(BlendEquation equation, BlendFunction src, BlendFunction dst, const Color4& color);
 	void				set_blending_params(BlendEquation equation, BlendFunction src, BlendFunction dst, const Color4& color);
 	void				set_color_write(bool write);
 	void				set_color_write(bool write);
 
 
-	void				set_shading_type(ShadingType type);
 	void				set_front_face(FrontFace face);
 	void				set_front_face(FrontFace face);
 
 
 	void				set_viewport_params(int32_t x, int32_t y, int32_t width, int32_t height);
 	void				set_viewport_params(int32_t x, int32_t y, int32_t width, int32_t height);
@@ -182,10 +180,6 @@ public:
 	void				set_scissor_params(int32_t x, int32_t y, int32_t width, int32_t height);
 	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				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);
-	void				set_point_params(float min, float max);
-
 	Mat4				get_matrix(MatrixType type) const;
 	Mat4				get_matrix(MatrixType type) const;
 	void				set_matrix(MatrixType type, const Mat4& matrix);
 	void				set_matrix(MatrixType type, const Mat4& matrix);
 
 

+ 0 - 18
src/renderers/gl/GLUtils.cpp

@@ -71,16 +71,6 @@ const GLenum GL::BLEND_EQUATION_TABLE[BE_COUNT] =
 	GL_MAX
 	GL_MAX
 };
 };
 
 
-//-----------------------------------------------------------------------------
-const GLenum GL::TEXTURE_MODE_TABLE[TM_COUNT] =
-{
-	GL_MODULATE,
-	GL_REPLACE,
-	GL_DECAL,
-	GL_BLEND,
-	GL_ADD
-};
-
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 const GLenum GL::TEXTURE_WRAP_TABLE[TW_COUNT] =
 const GLenum GL::TEXTURE_WRAP_TABLE[TW_COUNT] =
 {
 {
@@ -110,14 +100,6 @@ const GLenum GL::TEXTURE_MAG_FILTER_TABLE[TF_COUNT] =
 	GL_LINEAR
 	GL_LINEAR
 };
 };
 
 
-//-----------------------------------------------------------------------------
-const GLenum GL::FOG_MODE_TABLE[FM_COUNT] =
-{
-	GL_LINEAR,
-	GL_EXP,
-	GL_EXP2
-};
-
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 const GLenum GL::POLYGON_MODE_TABLE[PM_COUNT] =
 const GLenum GL::POLYGON_MODE_TABLE[PM_COUNT] =
 {
 {

+ 0 - 20
src/renderers/gl/GLUtils.h

@@ -42,10 +42,8 @@ public:
 	static GLenum			compare_function(CompareFunction function);
 	static GLenum			compare_function(CompareFunction function);
 	static GLenum			blend_function(BlendFunction function);
 	static GLenum			blend_function(BlendFunction function);
 	static GLenum			blend_equation(BlendEquation equation);
 	static GLenum			blend_equation(BlendEquation equation);
-	static GLenum			texture_mode(TextureMode mode);
 	static GLenum			texture_wrap(TextureWrap wrap);
 	static GLenum			texture_wrap(TextureWrap wrap);
 	static void				texture_filter(TextureFilter filter, GLint& minFilter, GLint& magFilter);
 	static void				texture_filter(TextureFilter filter, GLint& minFilter, GLint& magFilter);
-	static GLenum			fog_mode(FogMode mode);
 	static GLenum			polygon_mode(PolygonMode mode);
 	static GLenum			polygon_mode(PolygonMode mode);
 	static GLenum			pixel_format(PixelFormat format);
 	static GLenum			pixel_format(PixelFormat format);
 	static PixelFormat		pixel_format_from_gl_format(GLenum format);
 	static PixelFormat		pixel_format_from_gl_format(GLenum format);
@@ -55,11 +53,9 @@ private:
 	static const GLenum		COMPARE_FUNCTION_TABLE[CF_COUNT];
 	static const GLenum		COMPARE_FUNCTION_TABLE[CF_COUNT];
 	static const GLenum		BLEND_FUNCTION_TABLE[BF_COUNT];
 	static const GLenum		BLEND_FUNCTION_TABLE[BF_COUNT];
 	static const GLenum		BLEND_EQUATION_TABLE[BE_COUNT];
 	static const GLenum		BLEND_EQUATION_TABLE[BE_COUNT];
-	static const GLenum		TEXTURE_MODE_TABLE[TM_COUNT];
 	static const GLenum		TEXTURE_WRAP_TABLE[TW_COUNT];
 	static const GLenum		TEXTURE_WRAP_TABLE[TW_COUNT];
 	static const GLenum		TEXTURE_MIN_FILTER_TABLE[TF_COUNT];
 	static const GLenum		TEXTURE_MIN_FILTER_TABLE[TF_COUNT];
 	static const GLenum		TEXTURE_MAG_FILTER_TABLE[TF_COUNT];
 	static const GLenum		TEXTURE_MAG_FILTER_TABLE[TF_COUNT];
-	static const GLenum		FOG_MODE_TABLE[FM_COUNT];
 	static const GLenum		POLYGON_MODE_TABLE[PM_COUNT];
 	static const GLenum		POLYGON_MODE_TABLE[PM_COUNT];
 
 
 	// Disable construction
 	// Disable construction
@@ -90,14 +86,6 @@ inline GLenum GL::blend_equation(BlendEquation equation)
 	return BLEND_EQUATION_TABLE[equation];
 	return BLEND_EQUATION_TABLE[equation];
 }
 }
 
 
-//-----------------------------------------------------------------------------
-inline GLenum GL::texture_mode(TextureMode mode)
-{
-	assert(mode < TM_COUNT);
-
-	return TEXTURE_MODE_TABLE[mode];
-}
-
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 inline GLenum GL::texture_wrap(TextureWrap wrap)
 inline GLenum GL::texture_wrap(TextureWrap wrap)
 {
 {
@@ -115,14 +103,6 @@ inline void GL::texture_filter(TextureFilter filter, GLint& minFilter, GLint& ma
 	magFilter = TEXTURE_MAG_FILTER_TABLE[filter];
 	magFilter = TEXTURE_MAG_FILTER_TABLE[filter];
 }
 }
 
 
-//-----------------------------------------------------------------------------
-inline GLenum GL::fog_mode(FogMode mode)
-{
-	assert(mode < FM_COUNT);
-
-	return FOG_MODE_TABLE[mode];
-}
-
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 inline GLenum GL::polygon_mode(PolygonMode mode)
 inline GLenum GL::polygon_mode(PolygonMode mode)
 {
 {

File diff suppressed because it is too large
+ 588 - 360
src/renderers/gles/GLESRenderer.cpp


+ 165 - 53
src/renderers/gles/GLESRenderer.h

@@ -25,26 +25,72 @@ OTHER DEALINGS IN THE SOFTWARE.
 
 
 #pragma once
 #pragma once
 
 
-#include <GLES/gl.h>
-#include "Renderer.h"
+#include <GLES2/gl2.h>
 
 
-#define MAX_TEXTURES 1024
-#define MAX_TEXTURE_UNITS 8
+#include "Renderer.h"
+#include "Texture.h"
+#include "VertexBuffer.h"
+#include "IndexBuffer.h"
+#include "RenderBuffer.h"
+#include "VertexShader.h"
+#include "PixelShader.h"
+#include "IdTable.h"
+#include "MallocAllocator.h"
+#include "Resource.h"
 
 
 namespace crown
 namespace crown
 {
 {
 
 
-class TextureResource;
+const uint32_t MAX_TEXTURE_UNITS = 8;
+
+//-----------------------------------------------------------------------------
+struct Texture
+{
+	GLuint				gl_object;
+	PixelFormat			format;
+};
+
+//-----------------------------------------------------------------------------
+struct VertexBuffer
+{
+	GLuint				gl_object;
+	size_t				count;
+	VertexFormat		format;
+};
+
+//-----------------------------------------------------------------------------
+struct IndexBuffer
+{
+	GLuint				gl_object;
+	uint32_t			index_count;
+};
+
+//-----------------------------------------------------------------------------
+struct RenderBuffer
+{
+	GLuint				gl_frame_buffer;
+	GLuint				gl_render_buffer;
+};
+
+//-----------------------------------------------------------------------------
+struct VertexShader
+{
+	GLuint				gl_object;
+};
+
+//-----------------------------------------------------------------------------
+struct PixelShader
+{
+	GLuint				gl_object;
+};
 
 
-/// OpenGLES texture
-struct GLESTexture
+//-----------------------------------------------------------------------------
+struct GPUProgram
 {
 {
-	TextureId			id;
-	GLuint				texture_object;
-	TextureResource*	texture_resource;
+	GLuint				gl_object;
 };
 };
 
 
-/// OpenGL|ES 1.1 renderer.
+/// OpenGLES2 renderer
 class GLESRenderer : public Renderer
 class GLESRenderer : public Renderer
 {
 {
 public:
 public:
@@ -52,48 +98,79 @@ public:
 						GLESRenderer();
 						GLESRenderer();
 						~GLESRenderer();
 						~GLESRenderer();
 
 
-	void				begin_frame();
-	void				end_frame();
+	void				init();
+	void				shutdown();
 
 
-	void				set_clear_color(const Color4& color);
+	// Vertex buffers
+	VertexBufferId		create_vertex_buffer(size_t count, VertexFormat format, const void* vertices);
+	VertexBufferId		create_dynamic_vertex_buffer(size_t count, VertexFormat format, const void* vertices);
+	void				update_vertex_buffer(VertexBufferId id, size_t offset, size_t count, const void* vertices);
+	void				destroy_vertex_buffer(VertexBufferId id);
 
 
-	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);
+	// Index buffers
+	IndexBufferId		create_index_buffer(size_t count, const void* indices);
+	void				destroy_index_buffer(IndexBufferId id);
+
+	// Textures
+	TextureId			create_texture(uint32_t width, uint32_t height, PixelFormat format, const void* data);
+	void				update_texture(TextureId id, uint32_t x, uint32_t y, uint32_t width, uint32_t height, const void* data);
+	void				destroy_texture(TextureId id);
 
 
+	void				bind_texture(uint32_t unit, TextureId texture);
 	void				set_texturing(uint32_t unit, bool texturing);
 	void				set_texturing(uint32_t unit, bool texturing);
-	void				set_texture(uint32_t unit, TextureId texture);
-	void				set_texture_mode(uint32_t unit, TextureMode mode, const Color4& blendColor);
 	void				set_texture_wrap(uint32_t unit, TextureWrap wrap);
 	void				set_texture_wrap(uint32_t unit, TextureWrap wrap);
 	void				set_texture_filter(uint32_t unit, TextureFilter filter);
 	void				set_texture_filter(uint32_t unit, TextureFilter filter);
 
 
-	void				set_light(uint32_t light, bool active);
-	void				set_light_params(uint32_t light, LightType type, const Vec3& position);
-	void				set_light_color(uint32_t light, const Color4& ambient, const Color4& diffuse, const Color4& specular);
-	void				set_light_attenuation(uint32_t light, float constant, float linear, float quadratic);
+	// Vertex shaders
+	VertexShaderId		create_vertex_shader(const char* program);
+	void				destroy_vertex_shader(VertexShaderId id);
 
 
-	void				set_backface_culling(bool culling);
+	// Pixel shaders
+	PixelShaderId 		create_pixel_shader(const char* program);
+	void				destroy_pixel_shader(PixelShaderId id);
+
+	// GPU programs
+	GPUProgramId		create_gpu_program(VertexShaderId vs, PixelShaderId ps);
+	void				destroy_gpu_program(GPUProgramId id);
+
+	void				set_gpu_program_bool_uniform(GPUProgramId id, const char* name, bool value);
+	void				set_gpu_program_int_uniform(GPUProgramId id, const char* name, int value);
+
+	void				set_gpu_program_vec2_uniform(GPUProgramId id, const char* name, const Vec2& value);
+	void				set_gpu_program_vec3_uniform(GPUProgramId id, const char* name, const Vec3& value);
+	void				set_gpu_program_vec4_uniform(GPUProgramId id, const char* name, const Vec4& value);
+
+	void				set_gpu_porgram_mat3_uniform(GPUProgramId id, const char* name, const Mat3& value);
+	void				set_gpu_program_mat4_uniform(GPUProgramId id, const char* name, const Mat4& value);
 
 
-	void				set_separate_specular_color(bool separate);
+	void				set_gpu_program_sampler_uniform(GPUProgramId id, const char* name, uint32_t value);
 
 
+	void				bind_gpu_program(GPUProgramId id) const;
+
+	// Frame buffers
+	// RenderBufferId	create_render_buffer(uint32_t width, uint32_t height, PixelFormat format);
+	// void				destroy_render_buffer(RenderBufferId id);
+
+	// Called once a frame
+	void				begin_frame();
+	void				end_frame();
+
+	void				set_clear_color(const Color4& color);
+
+	// Lighting
+	void				set_ambient_light(const Color4& color);
+
+	void				set_backface_culling(bool culling);
+
+	// Fragment operations
 	void				set_depth_test(bool test);
 	void				set_depth_test(bool test);
 	void				set_depth_write(bool write);
 	void				set_depth_write(bool write);
 	void				set_depth_func(CompareFunction func);
 	void				set_depth_func(CompareFunction func);
 
 
-	void				set_rescale_normals(bool rescale);
-
 	void				set_blending(bool blending);
 	void				set_blending(bool blending);
 	void				set_blending_params(BlendEquation equation, BlendFunction src, BlendFunction dst, const Color4& color);
 	void				set_blending_params(BlendEquation equation, BlendFunction src, BlendFunction dst, const Color4& color);
 	void				set_color_write(bool write);
 	void				set_color_write(bool write);
 
 
-	void				set_fog(bool fog);
-	void				set_fog_params(FogMode mode, float density, float start, float end, const Color4& color);
-
-	void				set_alpha_test(bool test);
-	void				set_alpha_params(CompareFunction func, float ref);
-
-	void				set_shading_type(ShadingType type);
-	void				set_polygon_mode(PolygonMode mode);
 	void				set_front_face(FrontFace face);
 	void				set_front_face(FrontFace face);
 
 
 	void				set_viewport_params(int32_t x, int32_t y, int32_t width, int32_t height);
 	void				set_viewport_params(int32_t x, int32_t y, int32_t width, int32_t height);
@@ -103,37 +180,44 @@ public:
 	void				set_scissor_params(int32_t x, int32_t y, int32_t width, int32_t height);
 	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				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);
-	void				set_point_params(float min, float max);
-
 	Mat4				get_matrix(MatrixType type) const;
 	Mat4				get_matrix(MatrixType type) const;
 	void				set_matrix(MatrixType type, const Mat4& matrix);
 	void				set_matrix(MatrixType type, const Mat4& matrix);
 
 
-	void				draw_vertex_index_buffer(const VertexBuffer* vertices, const IndexBuffer* indices);
-	void				draw_point_buffer(const VertexBuffer* buffer);
+	void				bind_vertex_buffer(VertexBufferId vb) const;
+	//void				bind_render_buffer(RenderBufferId id) const;
 
 
-	void				draw_lines(const float* vertices, const float* colors, uint32_t count);
-	void				draw_triangles(const float* vertices, const float* normals, const float* uvs, const uint16_t* indices, uint32_t count);
+	void				draw_triangles(IndexBufferId id) const;
 
 
-	TextureId			load_texture(TextureResource* texture);
-	void				unload_texture(TextureResource* texture);
-	TextureId			reload_texture(TextureResource* old_texture, TextureResource* new_texture);
+	void				draw_lines(const float* vertices, const float* colors, uint32_t count);
 
 
 private:
 private:
 
 
-	bool				activate_texture_unit(uint32_t unit);		//!< Activates a texture unit and returns true if succes
+	// Loads the default shaders
+	void				load_default_shaders();
+	void				unload_default_shaders();
+	void				reload_default_shaders();
+
+	// Activates a texture unit and returns true if succes
+	bool				activate_texture_unit(uint32_t unit);
 	bool				activate_light(uint32_t light);
 	bool				activate_light(uint32_t light);
 
 
-	void				check_gl_errors();
+	// Shaders
+	GLint				find_gpu_program_uniform(GLuint program, const char* name) const;
+
+	// GL error checking
+	void				check_gl_errors() const;
 
 
 private:
 private:
 
 
+	MallocAllocator		m_allocator;
+
 	// Matrices
 	// Matrices
 	Mat4				m_matrix[MT_COUNT];
 	Mat4				m_matrix[MT_COUNT];
 
 
+	Mat4				m_model_view_matrix;
+	Mat4				m_model_view_projection_matrix;
+
 	// Limits
 	// Limits
-	int32_t				m_max_lights;
 	int32_t				m_max_texture_size;
 	int32_t				m_max_texture_size;
 	int32_t				m_max_texture_units;
 	int32_t				m_max_texture_units;
 	int32_t				m_max_vertex_indices;
 	int32_t				m_max_vertex_indices;
@@ -147,16 +231,44 @@ private:
 	int32_t				m_viewport[4];
 	int32_t				m_viewport[4];
 	int32_t				m_scissor[4];
 	int32_t				m_scissor[4];
 
 
+	// Lighting
+	Color4				m_ambient_light_color;
+
 	// Texture management
 	// Texture management
-	uint32_t			m_texture_count;
-	GLESTexture			m_textures[MAX_TEXTURES];
+	IdTable 			m_textures_id_table;
+	Texture				m_textures[MAX_TEXTURES];
 
 
 	uint32_t			m_active_texture_unit;
 	uint32_t			m_active_texture_unit;
 	GLuint				m_texture_unit[MAX_TEXTURE_UNITS];
 	GLuint				m_texture_unit[MAX_TEXTURE_UNITS];
 	GLenum				m_texture_unit_target[MAX_TEXTURE_UNITS];
 	GLenum				m_texture_unit_target[MAX_TEXTURE_UNITS];
 
 
-	friend class TextureResource;
+	// Vertex/Index buffer management
+	IdTable				m_vertex_buffers_id_table;
+	VertexBuffer		m_vertex_buffers[MAX_VERTEX_BUFFERS];
+
+	IdTable				m_index_buffers_id_table;
+	IndexBuffer			m_index_buffers[MAX_INDEX_BUFFERS];
+
+	// Vertex shader management
+	IdTable 			m_vertex_shaders_id_table;
+	VertexShader		m_vertex_shaders[MAX_VERTEX_SHADERS];
+
+	// Pixel shader management
+	IdTable 			m_pixel_shaders_id_table;
+	PixelShader			m_pixel_shaders[MAX_PIXEL_SHADERS];
+
+	// GPU program management
+	IdTable 			m_gpu_programs_id_table;
+	GPUProgram			m_gpu_programs[128];
+
+	// Render buffer management
+	//IdTable			m_render_buffers_id_table;
+	//GLRenderBuffer	m_render_buffers[MAX_RENDER_BUFFERS];
+
+	// Default shaders
+	ResourceId			m_default_vertex_shader;
+	ResourceId			m_default_pixel_shader;
+	GPUProgramId		m_default_gpu_program;
 };
 };
 
 
 } // namespace crown
 } // namespace crown
-

+ 6 - 14
src/renderers/gles/GLESUtils.cpp

@@ -62,13 +62,13 @@ const GLenum GLES::BLEND_FUNCTION_TABLE[BF_COUNT] =
 };
 };
 
 
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
-const GLenum GLES::TEXTURE_MODE_TABLE[TM_COUNT] =
+const GLenum GLES::BLEND_EQUATION_TABLE[BE_COUNT] =
 {
 {
-	GL_MODULATE,
-	GL_REPLACE,
-	GL_DECAL,
-	GL_BLEND,
-	GL_ADD
+	GL_FUNC_ADD,
+	GL_FUNC_SUBTRACT,
+	GL_FUNC_REVERSE_SUBTRACT,
+	GL_ONE,						// not supported
+	GL_ONE						// not supported
 };
 };
 
 
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
@@ -100,13 +100,5 @@ const GLenum GLES::TEXTURE_MAG_FILTER_TABLE[TF_COUNT] =
 	GL_LINEAR
 	GL_LINEAR
 };
 };
 
 
-//-----------------------------------------------------------------------------
-const GLenum GLES::FOG_MODE_TABLE[FM_COUNT] =
-{
-	GL_LINEAR,
-	GL_EXP,
-	GL_EXP2
-};
-
 } // namespace crown
 } // namespace crown
 
 

+ 8 - 17
src/renderers/gles/GLESUtils.h

@@ -25,11 +25,12 @@ OTHER DEALINGS IN THE SOFTWARE.
 
 
 #pragma once
 #pragma once
 
 
-#include <GLES/gl.h>
+#include <GLES2/gl2.h>
 #include <cassert>
 #include <cassert>
+
 #include "Texture.h"
 #include "Texture.h"
 #include "Material.h"
 #include "Material.h"
-#include "Pixel.h"
+#include "PixelFormat.h"
 
 
 namespace crown
 namespace crown
 {
 {
@@ -41,10 +42,9 @@ public:
 
 
 	static GLenum			compare_function(CompareFunction function);
 	static GLenum			compare_function(CompareFunction function);
 	static GLenum			blend_function(BlendFunction function);
 	static GLenum			blend_function(BlendFunction function);
-	static GLenum			texture_mode(TextureMode mode);
+	static GLenum			blend_equation(BlendEquation equation);
 	static GLenum			texture_wrap(TextureWrap wrap);
 	static GLenum			texture_wrap(TextureWrap wrap);
 	static void				texture_filter(TextureFilter filter, GLint& minFilter, GLint& magFilter);
 	static void				texture_filter(TextureFilter filter, GLint& minFilter, GLint& magFilter);
-	static GLenum			fog_mode(FogMode mode);
 	static GLenum			pixel_format(PixelFormat format);
 	static GLenum			pixel_format(PixelFormat format);
 	static PixelFormat		pixel_format_from_gl_format(GLenum format);
 	static PixelFormat		pixel_format_from_gl_format(GLenum format);
 
 
@@ -52,11 +52,10 @@ private:
 
 
 	static const GLenum		COMPARE_FUNCTION_TABLE[CF_COUNT];
 	static const GLenum		COMPARE_FUNCTION_TABLE[CF_COUNT];
 	static const GLenum		BLEND_FUNCTION_TABLE[BF_COUNT];
 	static const GLenum		BLEND_FUNCTION_TABLE[BF_COUNT];
-	static const GLenum		TEXTURE_MODE_TABLE[TM_COUNT];
+	static const GLenum		BLEND_EQUATION_TABLE[BE_COUNT];
 	static const GLenum		TEXTURE_WRAP_TABLE[TW_COUNT];
 	static const GLenum		TEXTURE_WRAP_TABLE[TW_COUNT];
 	static const GLenum		TEXTURE_MIN_FILTER_TABLE[TF_COUNT];
 	static const GLenum		TEXTURE_MIN_FILTER_TABLE[TF_COUNT];
 	static const GLenum		TEXTURE_MAG_FILTER_TABLE[TF_COUNT];
 	static const GLenum		TEXTURE_MAG_FILTER_TABLE[TF_COUNT];
-	static const GLenum		FOG_MODE_TABLE[FM_COUNT];
 
 
 	// Disable construction
 	// Disable construction
 	GLES();
 	GLES();
@@ -79,11 +78,11 @@ inline GLenum GLES::blend_function(BlendFunction function)
 }
 }
 
 
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
-inline GLenum GLES::texture_mode(TextureMode mode)
+inline GLenum GLES::blend_equation(BlendEquation equation)
 {
 {
-	assert(mode < TM_COUNT);
+	assert(equation < BE_COUNT);
 
 
-	return TEXTURE_MODE_TABLE[mode];
+	return BLEND_EQUATION_TABLE[equation];
 }
 }
 
 
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
@@ -103,14 +102,6 @@ inline void GLES::texture_filter(TextureFilter filter, GLint& minFilter, GLint&
 	magFilter = TEXTURE_MAG_FILTER_TABLE[filter];
 	magFilter = TEXTURE_MAG_FILTER_TABLE[filter];
 }
 }
 
 
-//-----------------------------------------------------------------------------
-inline GLenum GLES::fog_mode(FogMode mode)
-{
-	assert(mode < FM_COUNT);
-
-	return FOG_MODE_TABLE[mode];
-}
-
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 inline GLenum GLES::pixel_format(PixelFormat format)
 inline GLenum GLES::pixel_format(PixelFormat format)
 {
 {

Some files were not shown because too many files changed in this diff