Bladeren bron

android sucks

mikymod 12 jaren geleden
bovenliggende
commit
4dba4b239c

+ 6 - 0
engine/os/android/AndroidDevice.cpp

@@ -99,4 +99,10 @@ extern "C" JNIEXPORT void JNICALL Java_crown_android_CrownLib_shutdownRenderer(J
 	device()->renderer()->shutdown();
 }
 
+//-----------------------------------------------------------------------------
+extern "C" JNIEXPORT void JNICALL Java_crown_android_CrownLib_invalidateRenderer(JNIEnv* /*env*/, jobject /*obj*/)
+{
+	device()->renderer()->invalidate();
+}
+
 } // namespace crown

+ 1 - 0
engine/os/android/CrownLib.java

@@ -59,6 +59,7 @@ public class CrownLib
 	// Renderer functions
 	public static native void		initRenderer();
 	public static native void		shutdownRenderer();
+	public static native void		invalidateRenderer();
 
 	// InputManager functions
 	public static native void 		pushIntEvent(int type, int a, int b, int c, int d);

+ 1 - 2
engine/os/android/CrownSurfaceView.java

@@ -68,7 +68,6 @@ public class CrownSurfaceView extends SurfaceView implements SurfaceHolder.Callb
 		}
 		else
 		{
-			CrownLib.initRenderer();
 			CrownLib.unpauseDevice();
 		}
 	}
@@ -80,6 +79,6 @@ public class CrownSurfaceView extends SurfaceView implements SurfaceHolder.Callb
 		Log.d(TAG, "Crown Surface destroyed");
 		
 		CrownLib.pauseDevice();
-		CrownLib.shutdownRenderer();
+		CrownLib.invalidateRenderer();
 	}
 }

+ 7 - 0
engine/renderers/Renderer.h

@@ -104,6 +104,7 @@ public:
 	static Renderer*		create(Allocator& a);
 	static void				destroy(Allocator& a, Renderer* renderer);
 
+							Renderer() : m_is_valid(true) {}
 	virtual 				~Renderer() {};
 
 	virtual void			init() = 0;
@@ -228,6 +229,12 @@ public:
 	virtual void 			draw_triangles(IndexBufferId id) const = 0;
 				
 	virtual void 			draw_lines(const float* vertices, const float* colors, uint32_t count) = 0;
+
+	inline	void			invalidate() { m_is_valid = false; }
+
+public:
+
+	bool 					m_is_valid;
 };
 
 } // namespace crown

+ 12 - 2
engine/renderers/gles/GLESRenderer.cpp

@@ -72,6 +72,8 @@ static const char* gl_error_to_string(GLenum error)
 
 //-----------------------------------------------------------------------------
 GLESRenderer::GLESRenderer() :
+	Renderer(),
+
 	m_max_texture_size(0),
 	m_max_texture_units(0),
 	m_max_vertex_indices(0),
@@ -757,13 +759,21 @@ void GLESRenderer::get_scissor_params(int32_t& x, int32_t& y, int32_t& width, in
 //-----------------------------------------------------------------------------
 void GLESRenderer::frame()
 {
+	if (!m_is_valid)
+	{
+		m_context.destroy_context();
+		m_context.create_context();
+		m_is_valid = true;
+	}
+
 	// Clear frame/depth buffer
 	GL_CHECK(glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT));
+	GL_CHECK(glClearColor(0.5f, 0.5f, 0.5f, 0.5f));
 
 	// Bind the default gpu program
-	bind_gpu_program(m_default_gpu_program);
+	// bind_gpu_program(m_default_gpu_program);
 
-	set_gpu_program_mat4_uniform(m_default_gpu_program, "mvp_matrix", m_model_view_projection_matrix);
+	// set_gpu_program_mat4_uniform(m_default_gpu_program, "mvp_matrix", m_model_view_projection_matrix);
 
 	GL_CHECK(glFinish());