1. Christian Fischer
  2. wiesel

Commits

Christian Fischer  committed 84d6879

extracted opengl code into seperate module

  • Participants
  • Parent commits 21b9209
  • Branches default

Comments (0)

Files changed (108)

File libraries/android-native/wiesel-android/Android.mk

View file
 				$(subst $(LOCAL_PATH), ,$(foreach dir,$(MY_SUBFOLDERS),$(wildcard $(dir)/*.cpp)))
 
 # configure the module
-LOCAL_MODULE               := wiesel-android
-LOCAL_MODULE_FILENAME      := libwieselandroid
-LOCAL_CFLAGS               := -Werror
-LOCAL_LDLIBS               := 
-LOCAL_STATIC_LIBRARIES     := wiesel-base wiesel-core
-LOCAL_SRC_FILES            := $(MY_FILES)
-LOCAL_C_INCLUDES           := $(MY_LOCAL_FOLDERS)
-LOCAL_EXPORT_C_INCLUDES    := $(MY_LOCAL_FOLDERS)
-LOCAL_EXPORT_LDLIBS        := 
+LOCAL_MODULE                  := wiesel-android
+LOCAL_MODULE_FILENAME         := libwieselandroid
+LOCAL_CFLAGS                  := -Werror
+LOCAL_LDLIBS                  := 
+LOCAL_STATIC_LIBRARIES        := wiesel-base wiesel-core wiesel-opengl
+LOCAL_WHOLE_STATIC_LIBRARIES  := android_native_app_glue
+LOCAL_SRC_FILES               := $(MY_FILES)
+LOCAL_C_INCLUDES              := $(MY_LOCAL_FOLDERS)
+LOCAL_EXPORT_C_INCLUDES       := $(MY_LOCAL_FOLDERS)
+LOCAL_EXPORT_LDLIBS           := -landroid -llog
 
 # Build the static library
 include $(BUILD_STATIC_LIBRARY)
 # import all required modules
 $(call import-module,wiesel-base)
 $(call import-module,wiesel-core)
+$(call import-module,wiesel-opengl)
 
-# External third-party modules
-$(call import-module,third-party/libpng)
+# NativeActivity stuff
+$(call import-module,android/native_app_glue)

File libraries/android-native/wiesel-core/Android.mk

View file
 LOCAL_MODULE_FILENAME      := libwieselcore
 LOCAL_CFLAGS               := -Werror
 LOCAL_LDLIBS               := 
-LOCAL_STATIC_LIBRARIES     := wiesel-base libxml2-static android_native_app_glue
+LOCAL_STATIC_LIBRARIES     := wiesel-base libxml2-static
 LOCAL_SRC_FILES            := $(MY_FILES)
 LOCAL_C_INCLUDES           := $(MY_LOCAL_FOLDERS)
 LOCAL_EXPORT_C_INCLUDES    := $(MY_LOCAL_FOLDERS)
-LOCAL_EXPORT_LDLIBS        := -landroid -llog -lEGL -lGLESv2
+LOCAL_EXPORT_LDLIBS        :=
 
 # Build the static library
 include $(BUILD_STATIC_LIBRARY)
 
 # External third-party modules
 $(call import-module,third-party/libxml)
-
-# NativeActivity stuff
-$(call import-module,android/native_app_glue)

File libraries/android-native/wiesel-opengl/Android.mk

View file
+# wiesel-opengl
+
+LOCAL_PATH := $(call my-dir)
+include $(CLEAR_VARS)
+
+# define source folders of this library
+MY_LOCAL_FOLDERS := \
+				$(LOCAL_PATH)/src							\
+				$(LOCAL_PATH)/../../../src/opengl			\
+
+MY_SUBFOLDERS := \
+				$(foreach dir,$(MY_LOCAL_FOLDERS),$(shell /usr/bin/find $(dir) -type d -print))
+				
+MY_FILES := \
+				$(subst $(LOCAL_PATH), ,$(foreach dir,$(MY_SUBFOLDERS),$(wildcard $(dir)/*.cpp)))
+
+# configure the module
+LOCAL_MODULE               := wiesel-opengl
+LOCAL_MODULE_FILENAME      := libwieselopengl
+LOCAL_CFLAGS               := -Werror
+LOCAL_LDLIBS               := 
+LOCAL_STATIC_LIBRARIES     := wiesel-base wiesel-core
+LOCAL_SRC_FILES            := $(MY_FILES)
+LOCAL_C_INCLUDES           := $(MY_LOCAL_FOLDERS)
+LOCAL_EXPORT_C_INCLUDES    := $(MY_LOCAL_FOLDERS)
+LOCAL_EXPORT_LDLIBS        := -lEGL -lGLESv2
+
+# Build the static library
+include $(BUILD_STATIC_LIBRARY)
+
+# import all required modules
+$(call import-module,wiesel-base)
+$(call import-module,wiesel-core)

File libraries/desktop/wiesel-core/module.cmake

View file
 
 # add required modules
 wiesel_module_add_dependency(wiesel-core wiesel-base)
-wiesel_module_add_dependency(wiesel-core glee third-party/glee)
-
-
-# TODO: remove when GL dependencies gets removed
-wiesel_target_add_compileflags(wiesel-core "-DWIESEL_USE_GLEE")
 
 
 # add libxml2 dependency

File libraries/desktop/wiesel-opengl/module.cmake

View file
+# wiesel-opengl library
+
+
+# create the OpenGL module
+wiesel_create_module(wiesel-opengl ${WIESEL_SRC_DIR}/opengl ${WIESEL_TESTS_DIR}/opengl)
+
+# export include directories of this library for other targets
+wiesel_module_export_includes(wiesel-opengl ${WIESEL_SRC_DIR}/opengl)
+
+# add required modules
+wiesel_module_add_dependency(wiesel-opengl wiesel-base)
+wiesel_module_add_dependency(wiesel-opengl wiesel-core)
+wiesel_module_add_dependency(wiesel-opengl glee third-party/glee)

File libraries/desktop/wiesel-sdl/module.cmake

View file
 # add required modules
 wiesel_module_add_dependency(wiesel-sdl wiesel-base)
 wiesel_module_add_dependency(wiesel-sdl wiesel-core)
-
-
-# TODO: remove when GL dependencies gets removed
-wiesel_target_add_compileflags(wiesel-sdl "-DWIESEL_USE_GLEE")
+wiesel_module_add_dependency(wiesel-sdl wiesel-opengl)
 
 
 # add SDL dependency
 if(DEFINED SDL_FOUND)
 	wiesel_target_add_includes(wiesel-sdl ${SDL_INCLUDE_DIR})
 	wiesel_target_add_libraries(wiesel-sdl ${SDL_LIBRARY})
-	wiesel_target_add_compileflags(wiesel-sdl "-DWIESEL_USE_LIBSDL")
 else()
 	message(FATAL_ERROR "required library SDL not found!")
 endif()

File samples/HelloWiesel/CMakeLists.txt

View file
 
 wiesel_create_executable(HelloWiesel ./src)
 
-# TODO: remove when GL dependencies gets removed
-wiesel_target_add_compileflags(HelloWiesel "-DWIESEL_USE_GLEE")
-
-
 # add required libraries
 wiesel_module_add_dependency(HelloWiesel wiesel-base)
 wiesel_module_add_dependency(HelloWiesel wiesel-core)
 wiesel_module_add_dependency(HelloWiesel wiesel-common)
 wiesel_module_add_dependency(HelloWiesel wiesel-sdl)
 wiesel_module_add_dependency(HelloWiesel wiesel-mainproc)
-
-wiesel_target_add_compileflags(HelloWiesel "-DWIESEL_USE_LIBSDL")
-

File samples/HelloWiesel/android/jni/Android.mk

View file
 LOCAL_MODULE                  := main
 LOCAL_SRC_FILES               := $(MY_FILES)
 LOCAL_LDLIBS                  :=
-LOCAL_STATIC_LIBRARIES        := wiesel-common wiesel-core
-LOCAL_WHOLE_STATIC_LIBRARIES  := wiesel-android
+LOCAL_STATIC_LIBRARIES        := wiesel-common wiesel-core 
+LOCAL_WHOLE_STATIC_LIBRARIES  := wiesel-android wiesel-opengl
 
 # build the shared library
 include $(BUILD_SHARED_LIBRARY)
 
 # import all required modules
 $(call import-module,wiesel-android)
+$(call import-module,wiesel-opengl)
 $(call import-module,wiesel-base)
 $(call import-module,wiesel-core)
 $(call import-module,wiesel-common)

File samples/HelloWiesel/src/HelloWiesel.cpp

View file
  * Boston, MA 02110-1301 USA
  */
 #include <wiesel/application_main.h>
+#include <wiesel/graph/2d/sprite_node.h>
+#include <wiesel/io/filesystem.h>
 #include <wiesel/math/matrix.h>
-#include <wiesel/gl/shaders.h>
-#include <wiesel/gl/textures.h>
-#include <wiesel/gl/vbo.h>
-#include <wiesel/io/filesystem.h>
-#include <wiesel/graph/2d/sprite_node.h>
+#include <wiesel/resources/graphics/spritesheet.h>
 #include <wiesel/ui/bitmapfont.h>
 #include <wiesel/ui/label_node.h>
+#include <wiesel/video/render_context.h>
 #include <wiesel/video/screen.h>
-#include <wiesel/video/video_device.h>
+#include <wiesel/video/shader.h>
+#include <wiesel/video/texture.h>
+#include <wiesel/video/vertexbuffer.h>
+#include <wiesel/video/video_driver.h>
 #include <wiesel.h>
 
 using namespace wiesel;
 		screen->loadVideoDevice(dimension(640, 480), 0);
 		
 		// successful?
-		assert(screen->getVideoDevice());
-		if (!screen->getVideoDevice()) {
+		assert(screen->getVideoDeviceDriver());
+		if (!screen->getVideoDeviceDriver()) {
 			return false;
 		}
-		
+
+		// print video information
+		Log::info << *(screen->getVideoDeviceDriver()->getVideoInfo()) << std::endl;
+
 		// get the screen centre
-		const dimension &screen_size = screen->getVideoDevice()->getResolution();
+		const dimension &screen_size = screen->getVideoDeviceDriver()->getResolution();
 		float center_x = screen_size.width  / 2;
 		float center_y = screen_size.height / 2;
 		float size     = min(screen_size.width, screen_size.height);
 			Log::info << "load texture from: " << tex_file->getFullPath() << std::endl;
 			texture = Texture::fromFile(tex_file);
 			texture->retain();
+			texture->loadContentFrom(screen);
 		}
 		else {
 			Log::info << "texture not found" << endl;
 		Texture*		font_texture	= Texture::fromFile(font_file);
 		SpriteSheet*	font_ss			= new SpriteSheet(font_texture);
 
+		// prepare the texture
+		font_texture->loadContentFrom(screen);
+
 		// configure the font
 		font_ss->createRasterFrames(16, 8,  0, 26, 'A');
 		font_ss->createRasterFrames(16, 8, 32, 26, 'a');
 
 			case Video_Background:
 			case Video_Active: {
-				if (screen && screen->getVideoDevice()) {
-					screen->getVideoDevice()->preRender();
-					this->onRender(screen->getVideoDevice());
-					screen->getVideoDevice()->postRender();
+				if (screen && screen->getVideoDeviceDriver()) {
+					screen->getVideoDeviceDriver()->preRender();
+					this->onRender(screen->getVideoDeviceDriver()->getCurrentRenderContext());
+					screen->getVideoDeviceDriver()->postRender();
 				}
 
 				break;
 	}
 
 
-	virtual void onRender(VideoDevice *video_device) {
-		Application::onRender(video_device);
+	virtual void onRender(RenderContext *render_context) {
+		Application::onRender(render_context);
 		return;
 	}
 
 	virtual void onShutdown() {
 		safe_release(texture);
 		safe_release(sprite);
+		safe_release(label);
+
+		safe_release(screen);
+
 		return;
 	}
 
 	Screen*			screen;
 
 	Texture*		texture;
-	wiesel::Font*	font;
 
 	SpriteNode*		sprite;
 	LabelNode*		label;

File src/android/wiesel/android/android_main.cpp

View file
  * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  * Boston, MA 02110-1301 USA
  */
-#ifdef __ANDROID__
-
 #include <wiesel/engine.h>
 
 #include "android_platform.h"
 	return;
 }
 
-
-#endif // __ANDROID__

File src/android/wiesel/android/android_platform.cpp

View file
 
 #include "android_platform.h"
 #include "io/android_asset_fs.h"
-#include "video/android_video_device.h"
+#include "video/android_video_driver.h"
 
 #include "wiesel/io/datasource.h"
 #include "wiesel/io/file.h"
 #include "wiesel/ui/touchhandler.h"
 #include "wiesel/util/log.h"
-#include "wiesel/video/video_device.h"
+#include "wiesel/video/video_driver.h"
 #include "wiesel/engine.h"
 
 #include <algorithm>

File src/android/wiesel/android/android_platform.h

View file
 
 #include <wiesel/wiesel-android.def>
 
-#ifdef __ANDROID__
-
 #include <wiesel/io/filesystem.h>
 #include <wiesel/platform.h>
 #include <android_native_app_glue.h>
 namespace android {
 
 	class AndroidAssetFileSystem;
-	class AndroidVideoDevice;
+	class AndroidVideoDeviceDriver;
 	class IAndroidMessageReceiver;
 
 
 }
 }
 
-#endif /* __ANDROID__ */
 #endif /* __WIESEL_ANDROID_PLATFORM_H__ */

File src/android/wiesel/android/video/android_gl_rendercontext.cpp

View file
+/**
+ * Copyright (C) 2012
+ * Christian Fischer
+ *
+ * https://bitbucket.org/baldur/wiesel/
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ */
+#include "android_gl_rendercontext.h"
+#include <wiesel/video/gl/gl.h>
+
+
+using namespace wiesel::android;
+using namespace wiesel::video;
+using namespace wiesel::video::gl;
+
+
+
+AndroidGlRenderContext::AndroidGlRenderContext(Screen *screen) : OpenGlRenderContext(screen) {
+	return;
+}
+
+AndroidGlRenderContext::~AndroidGlRenderContext() {
+	return;
+}
+
+
+void AndroidGlRenderContext::preRender() {
+	OpenGlRenderContext::preRender();
+}
+
+
+void AndroidGlRenderContext::postRender() {
+	OpenGlRenderContext::postRender();
+}

File src/android/wiesel/android/video/android_gl_rendercontext.h

View file
+/**
+ * Copyright (C) 2012
+ * Christian Fischer
+ *
+ * https://bitbucket.org/baldur/wiesel/
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ */
+#ifndef __WIESEL_ANDROID_VIDEO_GL_RENDERCONTEXT_H__
+#define	__WIESEL_ANDROID_VIDEO_GL_RENDERCONTEXT_H__
+
+#include <wiesel/wiesel-android.def>
+
+#include <wiesel/video/gl/gl_render_context.h>
+
+
+namespace wiesel {
+namespace android {
+
+
+	/**
+	 * @brief Android version of the OpenGL render context.
+	 */
+	class WIESEL_ANDROID_EXPORT AndroidGlRenderContext : public wiesel::video::gl::OpenGlRenderContext
+	{
+	public:
+		AndroidGlRenderContext(wiesel::video::Screen *screen);
+		virtual ~AndroidGlRenderContext();
+
+	public:
+		virtual void preRender();
+		virtual void postRender();
+	};
+
+}
+}
+
+#endif	// __WIESEL_ANDROID_VIDEO_GL_RENDERCONTEXT_H__

File src/android/wiesel/android/video/android_video_device.cpp

-/**
- * Copyright (C) 2012
- * Christian Fischer
- *
- * https://bitbucket.org/baldur/wiesel/
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General
- * Public License along with this library; if not, write to the
- * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301 USA
- */
-#ifdef __ANDROID__
-
-#include "android_video_device.h"
-#include <wiesel/gl/gl.h>
-#include <wiesel/ui/touchhandler.h>
-#include <wiesel/util/log.h>
-#include <assert.h>
-
-
-using namespace wiesel;
-using namespace wiesel::android;
-using namespace wiesel::video;
-
-
-
-AndroidVideoDevice::AndroidVideoDevice(AndroidPlatform *platform, Screen *screen) : VideoDevice(screen) {
-	this->platform		= platform;
-	this->display		= EGL_NO_DISPLAY;
-	this->surface		= EGL_NO_SURFACE;
-	this->context		= EGL_NO_CONTEXT;
-	this->config		= NULL;
-	return;
-}
-
-
-AndroidVideoDevice::~AndroidVideoDevice() {
-	// check if the screen was released correctly
-	assert(display == EGL_NO_DISPLAY);
-	assert(surface == EGL_NO_SURFACE);
-	assert(context == EGL_NO_CONTEXT);
-	assert(config  == NULL);
-	return;
-}
-
-
-bool AndroidVideoDevice::init() {
-	// check if the screen is not already initialized
-	assert(display == EGL_NO_DISPLAY);
-	assert(surface == EGL_NO_SURFACE);
-	assert(context == EGL_NO_CONTEXT);
-	assert(config  == NULL);
-
-	if (
-			platform
-		&&	platform->getAndroidApp()
-		&&	platform->getAndroidApp()->window
-	) {
-		if (!initContext()) {
-			return false;
-		}
-	}
-	else {
-		setState(Video_Uninitialized);
-	}
-
-	return true;
-}
-
-bool AndroidVideoDevice::initContext() {
-	// initialize OpenGL ES and EGL
-
-	// get the android app object
-	assert(platform);
-	struct android_app *app = platform->getAndroidApp();
-	assert(app);
-
-	logmsg(LogLevel_Info, "TEST", "init context, window=%p", app->window);
-
-	EGLDisplay default_display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
-	if (this->display != EGL_NO_DISPLAY && this->display != default_display) {
-		releaseContext();
-	}
-
-	if (display == EGL_NO_DISPLAY) {
-		display =  default_display;
-		eglInitialize(display, 0, 0);
-	}
-
-	if (config == NULL) {
-		/*
-		 * Here specify the attributes of the desired configuration.
-		 * Below, we select an EGLConfig with at least 8 bits per color
-		 * component compatible with on-screen windows
-		 */
-		const EGLint config_attribs[] = {
-				EGL_SURFACE_TYPE,		EGL_WINDOW_BIT,
-				EGL_RENDERABLE_TYPE,	EGL_OPENGL_ES2_BIT,
-				EGL_BLUE_SIZE,			8,
-				EGL_GREEN_SIZE,			8,
-				EGL_RED_SIZE,			8,
-				EGL_DEPTH_SIZE,			16,
-				EGL_NONE
-		};
-
-		EGLint numConfigs;
-
-		/* Here, the application chooses the configuration it desires. In this
-		 * sample, we have a very simplified selection process, where we pick
-		 * the first EGLConfig that matches our criteria
-		 */
-		eglChooseConfig(display, config_attribs, &config, 1, &numConfigs);
-
-		/* EGL_NATIVE_VISUAL_ID is an attribute of the EGLConfig that is
-		 * guaranteed to be accepted by ANativeWindow_setBuffersGeometry().
-		 * As soon as we picked a EGLConfig, we can safely reconfigure the
-		 * ANativeWindow buffers to match, using EGL_NATIVE_VISUAL_ID.
-		 */
-		eglGetConfigAttrib(display, config, EGL_NATIVE_VISUAL_ID, &format);
-	}
-
-	if (surface == EGL_NO_SURFACE) {
-		ANativeWindow_setBuffersGeometry(app->window, 0, 0, format);
-		
-		surface = eglCreateWindowSurface(display, config, app->window, NULL);
-	}
-
-	if (context == EGL_NO_CONTEXT) {
-		const EGLint context_attribs[] = {
-				EGL_CONTEXT_CLIENT_VERSION,		2,
-				EGL_NONE
-		};
-
-		context = eglCreateContext(display, config, NULL, context_attribs);
-		CHECK_GL_ERROR;
-	}
-
-	if (eglMakeCurrent(display, surface, surface, context) == EGL_FALSE) {
-		logmsg(LogLevel_Error, WIESEL_GL_LOG_TAG, "eglMakeCurrent failed!");
-		return false;
-	}
-
-	// Initialize GL state.
-	glDisable(GL_CULL_FACE);
-	glDisable(GL_DEPTH_TEST);
-
-	glEnable(GL_BLEND);
-	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
-
-	// initialize the window's size
-	resize();
-
-	// video device is ready
-	setState(Video_Active);
-
-	// log OpenGL information
-	logmsg(LogLevel_Info, WIESEL_GL_LOG_TAG, "OpenGL Version:    %s", ((const char*)glGetString(GL_VERSION)));
-	logmsg(LogLevel_Info, WIESEL_GL_LOG_TAG, "OpenGL Vendor:     %s", ((const char*)glGetString(GL_VENDOR)));
-	logmsg(LogLevel_Info, WIESEL_GL_LOG_TAG, "OpenGL Renderer:   %s", ((const char*)glGetString(GL_RENDERER)));
-	logmsg(LogLevel_Info, WIESEL_GL_LOG_TAG, "OpenGL Shader:     %s", ((const char*)glGetString(GL_SHADING_LANGUAGE_VERSION)));
-	logmsg(LogLevel_Info, WIESEL_GL_LOG_TAG, "OpenGL Extensions: %s", ((const char*)glGetString(GL_EXTENSIONS)));
-
-	CHECK_GL_ERROR;
-
-	return true;
-}
-
-
-bool AndroidVideoDevice::resize() {
-	EGLint w, h;
-
-	// get the display size
-	eglQuerySurface(display, surface, EGL_WIDTH,  &w);
-	eglQuerySurface(display, surface, EGL_HEIGHT, &h);
-	CHECK_GL_ERROR;
-
-	// setup viewport
-	glViewport(0, 0, w, h);
-
-	// update screen size and projection
-	updateScreenSize(w, h);
-
-	return true;
-}
-
-
-bool AndroidVideoDevice::releaseContext() {
-	if (display != EGL_NO_DISPLAY) {
-		eglMakeCurrent(display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
-
-		if (context != EGL_NO_CONTEXT) {
-			eglDestroyContext(display, context);
-		}
-
-		if (surface != EGL_NO_SURFACE) {
-			eglDestroySurface(display, surface);
-		}
-
-		eglTerminate(display);
-	}
-
-	display = EGL_NO_DISPLAY;
-	context = EGL_NO_CONTEXT;
-	surface = EGL_NO_SURFACE;
-	config  = NULL;
-
-	CHECK_GL_ERROR;
-
-	return true;
-}
-
-
-bool AndroidVideoDevice::detachContext() {
-	// detach the gl context
-	if (display != EGL_NO_DISPLAY) {
-		eglMakeCurrent(display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
-	}
-
-	// release surface
-	if (surface != EGL_NO_SURFACE) {
-		eglDestroySurface(display, surface);
-		surface = EGL_NO_SURFACE;
-	}
-	
-	return true;
-}
-
-
-bool AndroidVideoDevice::reattachContext() {
-	return initContext();
-}
-
-
-void AndroidVideoDevice::onAndroidCommand(int32_t cmd) {
-	switch(cmd) {
-		case APP_CMD_CONFIG_CHANGED: {
-			resize();
-			break;
-		}
-
-		case APP_CMD_WINDOW_RESIZED: {
-			resize();
-			break;
-		}
-
-		case APP_CMD_INIT_WINDOW: {
-			bool success = initContext();
-			assert(success);
-			break;
-		}
-
-		case APP_CMD_TERM_WINDOW: {
-			// The window is being hidden or closed, clean it up.
-			detachContext();
-			break;
-		}
-
-		case APP_CMD_GAINED_FOCUS: {
-			if (getScreen()) {
-				getScreen()->getTouchHandler()->releaseAllTouches();
-			}
-
-			setState(wiesel::video::Video_Active);
-
-			break;
-		}
-
-		case APP_CMD_LOST_FOCUS: {
-			if (getScreen()) {
-				getScreen()->getTouchHandler()->releaseAllTouches();
-			}
-
-			if (getState() == wiesel::video::Video_Active) {
-				setState(wiesel::video::Video_Background);
-			}
-
-			break;
-		}
-
-		case APP_CMD_PAUSE:
-		case APP_CMD_STOP: {
-			setState(wiesel::video::Video_Suspended);
-			break;
-		}
-
-		case APP_CMD_START:
-		case APP_CMD_RESUME: {
-			setState(wiesel::video::Video_Active);
-			break;
-		}
-
-		case APP_CMD_DESTROY: {
-			break;
-		}
-	}
-
-	return;
-}
-
-
-int32_t AndroidVideoDevice::onAndroidInputEvent(AInputEvent *event) {
-	wiesel::video::Screen *screen = getScreen();
-
-	if (
-			AInputEvent_getType(event)   == AINPUT_EVENT_TYPE_MOTION
-		&&	AInputEvent_getSource(event) == AINPUT_SOURCE_TOUCHSCREEN
-	) {
-		int action = AMotionEvent_getAction(event);
-
-		switch(action & AMOTION_EVENT_ACTION_MASK) {
-			case AMOTION_EVENT_ACTION_DOWN:
-			case AMOTION_EVENT_ACTION_POINTER_DOWN: {
-				int index = (action & AMOTION_EVENT_ACTION_POINTER_INDEX_MASK) >> AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT;
-				int id    = AMotionEvent_getPointerId(event, index);
-				int x     = AMotionEvent_getX(event, index);
-				int y     = AMotionEvent_getY(event, index);
-
-				if (screen) {
-					screen->getTouchHandler()->startTouch(id, x, y);
-				}
-
-				break;
-			}
-
-			case AMOTION_EVENT_ACTION_MOVE: {
-				for(int index=AMotionEvent_getPointerCount(event); --index>=0;) {
-					int id    = AMotionEvent_getPointerId(event, index);
-					int x     = AMotionEvent_getX(event, index);
-					int y     = AMotionEvent_getY(event, index);
-
-					if (screen) {
-						screen->getTouchHandler()->updateTouchLocation(id, x, y);
-					}
-				}
-
-				break;
-			}
-
-			case AMOTION_EVENT_ACTION_UP:
-			case AMOTION_EVENT_ACTION_CANCEL:
-			case AMOTION_EVENT_ACTION_POINTER_UP: {
-				int index = (action & AMOTION_EVENT_ACTION_POINTER_INDEX_MASK) >> AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT;
-				int id    = AMotionEvent_getPointerId(event, index);
-
-				if (screen) {
-					screen->getTouchHandler()->releaseTouch(id);
-				}
-
-				break;
-			}
-		}
-
-		return 1;
-	}
-
-	return 0;
-}
-
-
-void AndroidVideoDevice::preRender() {
-	if (display == EGL_NO_DISPLAY) {
-		return;
-	}
-
-	// Just fill the screen with a color.
-	glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
-	glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
-	CHECK_GL_ERROR;
-
-	return;
-}
-
-
-void AndroidVideoDevice::postRender() {
-	eglSwapBuffers(display, surface);
-	CHECK_GL_ERROR;
-	return;
-}
-
-#endif // __ANDROID__

File src/android/wiesel/android/video/android_video_device.h

-/**
- * Copyright (C) 2012
- * Christian Fischer
- *
- * https://bitbucket.org/baldur/wiesel/
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General
- * Public License along with this library; if not, write to the
- * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301 USA
- */
-#ifndef __WIESEL_ANDROID_VIDEO_DEVICE_H__
-#define __WIESEL_ANDROID_VIDEO_DEVICE_H__
-
-#include <wiesel/wiesel-android.def>
-
-#ifdef __ANDROID__
-
-#include <wiesel/video/screen.h>
-#include <wiesel/video/video_device.h>
-#include <wiesel/android/android_platform.h>
-
-#include <wiesel/geometry.h>
-
-#include <EGL/egl.h>
-#include <GLES2/gl2.h>
-
-#include <android_native_app_glue.h>
-
-
-namespace wiesel {
-namespace android {
-
-	/**
-	 * @brief The android VideoDevice implementation.
-	 */
-	class WIESEL_ANDROID_EXPORT AndroidVideoDevice :
-			public wiesel::video::VideoDevice,
-			public wiesel::android::IAndroidMessageReceiver
-	{
-	public:
-		AndroidVideoDevice(AndroidPlatform *platform, wiesel::video::Screen *screen);
-		virtual ~AndroidVideoDevice();
-
-	public:
-		bool init();
-
-	private:
-		bool initContext();
-		bool resize();
-		bool detachContext();
-		bool reattachContext();
-		bool releaseContext();
-
-		virtual void onAndroidCommand(int32_t cmd);
-		virtual int32_t onAndroidInputEvent(AInputEvent *event);
-
-		virtual void preRender();
-		virtual void postRender();
-
-	private:
-		AndroidPlatform*	platform;
-		dimension			configured_size;
-
-		EGLint     format;
-		EGLConfig  config;
-		EGLDisplay display;
-		EGLSurface surface;
-		EGLContext context;
-	};
-
-}
-}
-
-#endif // __ANDROID__
-
-#endif /* __WIESEL_ANDROID_VIDEO_DEVICE_H__ */

File src/android/wiesel/android/video/android_video_driver.cpp

View file
+/**
+ * Copyright (C) 2012
+ * Christian Fischer
+ *
+ * https://bitbucket.org/baldur/wiesel/
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ */
+#include "android_video_driver.h"
+#include <wiesel/video/gl/gl.h>
+#include <wiesel/ui/touchhandler.h>
+#include <wiesel/util/log.h>
+#include <assert.h>
+
+
+using namespace wiesel;
+using namespace wiesel::android;
+using namespace wiesel::video;
+
+
+
+AndroidVideoDeviceDriver::AndroidVideoDeviceDriver(AndroidPlatform *platform, Screen *screen) : OpenGlVideoDeviceDriver(screen) {
+	this->display		= EGL_NO_DISPLAY;
+	this->surface		= EGL_NO_SURFACE;
+	this->context		= EGL_NO_CONTEXT;
+	this->config		= NULL;
+
+	render_context		= NULL;
+
+	this->platform		= platform;
+	this->platform->addReceiver(this);
+
+	return;
+}
+
+
+AndroidVideoDeviceDriver::~AndroidVideoDeviceDriver() {
+	if (this->platform) {
+		this->platform->removeReceiver(this);
+	}
+
+	// release the render context
+	if (render_context) {
+		render_context->release();
+		render_context = NULL;
+	}
+
+	// check if the screen was released correctly
+	assert(display == EGL_NO_DISPLAY);
+	assert(surface == EGL_NO_SURFACE);
+	assert(context == EGL_NO_CONTEXT);
+	assert(config  == NULL);
+
+	return;
+}
+
+
+bool AndroidVideoDeviceDriver::init() {
+	// check if the screen is not already initialized
+	assert(display == EGL_NO_DISPLAY);
+	assert(surface == EGL_NO_SURFACE);
+	assert(context == EGL_NO_CONTEXT);
+	assert(config  == NULL);
+
+	if (
+			platform
+		&&	platform->getAndroidApp()
+		&&	platform->getAndroidApp()->window
+	) {
+		if (!initContext()) {
+			return false;
+		}
+	}
+	else {
+		setState(Video_Uninitialized);
+	}
+
+	return true;
+}
+
+bool AndroidVideoDeviceDriver::initContext() {
+	// initialize OpenGL ES and EGL
+
+	// get the android app object
+	assert(platform);
+	struct android_app *app = platform->getAndroidApp();
+	assert(app);
+
+	logmsg(LogLevel_Info, "TEST", "init context, window=%p", app->window);
+
+	EGLDisplay default_display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
+	if (this->display != EGL_NO_DISPLAY && this->display != default_display) {
+		releaseContext();
+	}
+
+	if (display == EGL_NO_DISPLAY) {
+		display =  default_display;
+		eglInitialize(display, 0, 0);
+	}
+
+	if (config == NULL) {
+		/*
+		 * Here specify the attributes of the desired configuration.
+		 * Below, we select an EGLConfig with at least 8 bits per color
+		 * component compatible with on-screen windows
+		 */
+		const EGLint config_attribs[] = {
+				EGL_SURFACE_TYPE,		EGL_WINDOW_BIT,
+				EGL_RENDERABLE_TYPE,	EGL_OPENGL_ES2_BIT,
+				EGL_BLUE_SIZE,			8,
+				EGL_GREEN_SIZE,			8,
+				EGL_RED_SIZE,			8,
+				EGL_DEPTH_SIZE,			16,
+				EGL_NONE
+		};
+
+		EGLint numConfigs;
+
+		/* Here, the application chooses the configuration it desires. In this
+		 * sample, we have a very simplified selection process, where we pick
+		 * the first EGLConfig that matches our criteria
+		 */
+		eglChooseConfig(display, config_attribs, &config, 1, &numConfigs);
+
+		/* EGL_NATIVE_VISUAL_ID is an attribute of the EGLConfig that is
+		 * guaranteed to be accepted by ANativeWindow_setBuffersGeometry().
+		 * As soon as we picked a EGLConfig, we can safely reconfigure the
+		 * ANativeWindow buffers to match, using EGL_NATIVE_VISUAL_ID.
+		 */
+		eglGetConfigAttrib(display, config, EGL_NATIVE_VISUAL_ID, &format);
+	}
+
+	if (surface == EGL_NO_SURFACE) {
+		ANativeWindow_setBuffersGeometry(app->window, 0, 0, format);
+		
+		surface = eglCreateWindowSurface(display, config, app->window, NULL);
+	}
+
+	if (context == EGL_NO_CONTEXT) {
+		const EGLint context_attribs[] = {
+				EGL_CONTEXT_CLIENT_VERSION,		2,
+				EGL_NONE
+		};
+
+		context = eglCreateContext(display, config, NULL, context_attribs);
+		CHECK_GL_ERROR;
+	}
+
+	if (eglMakeCurrent(display, surface, surface, context) == EGL_FALSE) {
+		logmsg(LogLevel_Error, WIESEL_GL_LOG_TAG, "eglMakeCurrent failed!");
+		return false;
+	}
+
+
+	// try to initialize the OpenGL part
+	if (!initOpenGl()) {
+		return false;
+	}
+
+	// remove the old context, if any
+	if (render_context) {
+		render_context->release();
+		render_context = NULL;
+	}
+
+	// initialize the new render context
+	render_context = new AndroidGlRenderContext(getScreen());
+	render_context->initContext();
+	render_context->retain();
+
+	// initialize the window's size
+	resize();
+
+	// video device is ready
+	setState(Video_Active);
+
+	CHECK_GL_ERROR;
+
+	return true;
+}
+
+
+bool AndroidVideoDeviceDriver::resize() {
+	EGLint w, h;
+
+	// get the display size
+	eglQuerySurface(display, surface, EGL_WIDTH,  &w);
+	eglQuerySurface(display, surface, EGL_HEIGHT, &h);
+	CHECK_GL_ERROR;
+
+	// setup viewport
+	glViewport(0, 0, w, h);
+
+	// update screen size and projection
+	updateScreenSize(w, h);
+
+	return true;
+}
+
+
+bool AndroidVideoDeviceDriver::releaseContext() {
+	// release the render context
+	if (render_context) {
+		render_context->release();
+		render_context = NULL;
+	}
+
+	if (display != EGL_NO_DISPLAY) {
+		eglMakeCurrent(display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
+
+		if (context != EGL_NO_CONTEXT) {
+			eglDestroyContext(display, context);
+		}
+
+		if (surface != EGL_NO_SURFACE) {
+			eglDestroySurface(display, surface);
+		}
+
+		eglTerminate(display);
+	}
+
+	display = EGL_NO_DISPLAY;
+	context = EGL_NO_CONTEXT;
+	surface = EGL_NO_SURFACE;
+	config  = NULL;
+
+	CHECK_GL_ERROR;
+
+	return true;
+}
+
+
+bool AndroidVideoDeviceDriver::detachContext() {
+	// detach the gl context
+	if (display != EGL_NO_DISPLAY) {
+		eglMakeCurrent(display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
+	}
+
+	// release surface
+	if (surface != EGL_NO_SURFACE) {
+		eglDestroySurface(display, surface);
+		surface = EGL_NO_SURFACE;
+	}
+
+	// the video device is suspended, no rendering should
+	// be possible until the render context is re-attached
+	setState(wiesel::video::Video_Suspended);
+	
+	return true;
+}
+
+
+bool AndroidVideoDeviceDriver::reattachContext() {
+	return initContext();
+}
+
+
+void AndroidVideoDeviceDriver::onAndroidCommand(int32_t cmd) {
+	switch(cmd) {
+		case APP_CMD_CONFIG_CHANGED: {
+			resize();
+			break;
+		}
+
+		case APP_CMD_WINDOW_RESIZED: {
+			resize();
+			break;
+		}
+
+		case APP_CMD_INIT_WINDOW: {
+			bool success = initContext();
+			assert(success);
+			break;
+		}
+
+		case APP_CMD_TERM_WINDOW: {
+			// The window is being hidden or closed, clean it up.
+			detachContext();
+			break;
+		}
+
+		case APP_CMD_GAINED_FOCUS: {
+			if (getScreen()) {
+				getScreen()->getTouchHandler()->releaseAllTouches();
+			}
+
+			setState(wiesel::video::Video_Active);
+
+			break;
+		}
+
+		case APP_CMD_LOST_FOCUS: {
+			if (getScreen()) {
+				getScreen()->getTouchHandler()->releaseAllTouches();
+			}
+
+			if (getState() == wiesel::video::Video_Active) {
+				setState(wiesel::video::Video_Background);
+			}
+
+			break;
+		}
+
+		case APP_CMD_PAUSE:
+		case APP_CMD_STOP: {
+			setState(wiesel::video::Video_Suspended);
+			break;
+		}
+
+		case APP_CMD_START:
+		case APP_CMD_RESUME: {
+			setState(wiesel::video::Video_Active);
+			break;
+		}
+
+		case APP_CMD_DESTROY: {
+			break;
+		}
+	}
+
+	return;
+}
+
+
+int32_t AndroidVideoDeviceDriver::onAndroidInputEvent(AInputEvent *event) {
+	wiesel::video::Screen *screen = getScreen();
+
+	if (
+			AInputEvent_getType(event)   == AINPUT_EVENT_TYPE_MOTION
+		&&	AInputEvent_getSource(event) == AINPUT_SOURCE_TOUCHSCREEN
+	) {
+		int action = AMotionEvent_getAction(event);
+
+		switch(action & AMOTION_EVENT_ACTION_MASK) {
+			case AMOTION_EVENT_ACTION_DOWN:
+			case AMOTION_EVENT_ACTION_POINTER_DOWN: {
+				int index = (action & AMOTION_EVENT_ACTION_POINTER_INDEX_MASK) >> AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT;
+				int id    = AMotionEvent_getPointerId(event, index);
+				int x     = AMotionEvent_getX(event, index);
+				int y     = AMotionEvent_getY(event, index);
+
+				if (screen) {
+					vector2d location = convertScreenToWorld(vector2d(x, y));
+					screen->getTouchHandler()->startTouch(id, location.x, location.y);
+				}
+
+				break;
+			}
+
+			case AMOTION_EVENT_ACTION_MOVE: {
+				for(int index=AMotionEvent_getPointerCount(event); --index>=0;) {
+					int id    = AMotionEvent_getPointerId(event, index);
+					int x     = AMotionEvent_getX(event, index);
+					int y     = AMotionEvent_getY(event, index);
+
+					if (screen) {
+						vector2d location = convertScreenToWorld(vector2d(x, y));
+						screen->getTouchHandler()->updateTouchLocation(id, location.x, location.y);
+					}
+				}
+
+				break;
+			}
+
+			case AMOTION_EVENT_ACTION_UP:
+			case AMOTION_EVENT_ACTION_CANCEL:
+			case AMOTION_EVENT_ACTION_POINTER_UP: {
+				int index = (action & AMOTION_EVENT_ACTION_POINTER_INDEX_MASK) >> AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT;
+				int id    = AMotionEvent_getPointerId(event, index);
+
+				if (screen) {
+					screen->getTouchHandler()->releaseTouch(id);
+				}
+
+				break;
+			}
+		}
+
+		return 1;
+	}
+
+	return 0;
+}
+
+
+void AndroidVideoDeviceDriver::preRender() {
+	if (display == EGL_NO_DISPLAY) {
+		return;
+	}
+
+	OpenGlVideoDeviceDriver::preRender();
+
+	if (render_context) {
+		render_context->preRender();
+		render_context->setProjectionMatrix(projection);
+	}
+
+	return;
+}
+
+
+void AndroidVideoDeviceDriver::postRender() {
+	if (render_context) {
+		render_context->postRender();
+	}
+
+	eglSwapBuffers(display, surface);
+	CHECK_GL_ERROR;
+
+	OpenGlVideoDeviceDriver::postRender();
+
+	return;
+}
+
+
+RenderContext *AndroidVideoDeviceDriver::getCurrentRenderContext() {
+	return render_context;
+}

File src/android/wiesel/android/video/android_video_driver.h

View file
+/**
+ * Copyright (C) 2012
+ * Christian Fischer
+ *
+ * https://bitbucket.org/baldur/wiesel/
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ */
+#ifndef __WIESEL_ANDROID_VIDEO_DRIVER_H__
+#define __WIESEL_ANDROID_VIDEO_DRIVER_H__
+
+#include <wiesel/wiesel-android.def>
+
+#include <wiesel/video/screen.h>
+#include <wiesel/video/gl/gl_video_driver.h>
+#include <wiesel/android/android_platform.h>
+#include <wiesel/android/video/android_gl_rendercontext.h>
+#include <wiesel/video/gl/gl.h>
+
+#include <wiesel/geometry.h>
+
+#include <android_native_app_glue.h>
+
+
+namespace wiesel {
+namespace android {
+
+	/**
+	 * @brief The android VideoDevice implementation.
+	 */
+	class WIESEL_ANDROID_EXPORT AndroidVideoDeviceDriver :
+			public wiesel::video::gl::OpenGlVideoDeviceDriver,
+			public wiesel::android::IAndroidMessageReceiver
+	{
+	public:
+		AndroidVideoDeviceDriver(AndroidPlatform *platform, wiesel::video::Screen *screen);
+		virtual ~AndroidVideoDeviceDriver();
+
+	public:
+		bool init();
+
+	private:
+		bool initContext();
+		bool resize();
+		bool detachContext();
+		bool reattachContext();
+		bool releaseContext();
+
+		virtual void onAndroidCommand(int32_t cmd);
+		virtual int32_t onAndroidInputEvent(AInputEvent *event);
+
+		virtual void preRender();
+		virtual void postRender();
+
+		virtual wiesel::video::RenderContext* getCurrentRenderContext();
+
+	private:
+		AndroidPlatform*			platform;
+		AndroidGlRenderContext*		render_context;
+		dimension					configured_size;
+
+		EGLint     format;
+		EGLConfig  config;
+		EGLDisplay display;
+		EGLSurface surface;
+		EGLContext context;
+	};
+
+}
+}
+
+#endif /* __WIESEL_ANDROID_VIDEO_DRIVER_H__ */

File src/android/wiesel/android/video/android_video_loader.cpp

View file
  * Boston, MA 02110-1301 USA
  */
 #include "android_video_loader.h"
-#include "android_video_device.h"
+#include "android_video_driver.h"
 
 #include <wiesel/video/video_loader.h>
 #include <wiesel/engine.h>
 	}
 
 	// create the new video device
-	AndroidVideoDevice *device = new AndroidVideoDevice(platform, screen);
+	AndroidVideoDeviceDriver *device = new AndroidVideoDeviceDriver(platform, screen);
 
 	// inizialize the window
 	if (device->init() == false) {

File src/common/wiesel/resources/graphics/image_loader_libpng.cpp

View file
 
 #include "wiesel/util/log.h"
 #include <inttypes.h>
+#include <malloc.h>
 #include <png.h>
 
 using namespace wiesel;

File src/core/wiesel.h

View file
 #include "wiesel/engine.h"
 
 // get the basic platform includes
-#include "wiesel/platform/platform_config.h"
+#include "wiesel/platform_config.h"
 
 // some useful default includes
 #include "wiesel/util/log.h"

File src/core/wiesel/application.cpp

View file
 }
 
 
-void Application::onRender(video::VideoDevice *video_device) {
+void Application::onRender(video::RenderContext *render_context) {
 	// draw all scenes
 	for(SceneList::iterator it=scene_stack.begin(); it!=scene_stack.end(); it++) {
-		(*it)->render(video_device);
+		(*it)->render(render_context);
 	}
 
 	return;

File src/core/wiesel/application.h

View file
 		 * @brief called each frame to render graphics.
 		 * DUMMY - will be replaced by scene graph later.
 		 */
-		virtual void onRender(video::VideoDevice *video_device);
+		virtual void onRender(video::RenderContext *render_context);
 
 	// scene stack
 	public:

File src/core/wiesel/device.cpp

View file
 Device::~Device() {
 	// free all device resources
 	for(DeviceResourceList::iterator it=resources.begin(); it!=resources.end(); it++) {
-		// there should be no more references when the device will be released
-		assert((*it)->getReferenceCount() == 1);
+		DeviceResource *resource = *it;
 
-		(*it)->release();
+		// the content should already be unloaded
+		assert(resource->isLoaded() == false);
+
+		resource->release();
 	}
 
 	return;
 
 	if (it == resources.end()) {
 		resources.push_back(resource);
+		resource->device = this;
 		resource->retain();
 	}
 
 
 	if ((*it) == resource) {
 		resources.erase(it);
+
+		if (resource->device == this) {
+			resource->device = NULL;
+		}
+
 		(*it)->release();
 	}
 
 	return;
 }
 
+
+void Device::loadAllResources() {
+	for(DeviceResourceList::iterator it=resources.begin(); it!=resources.end(); it++) {
+		DeviceResource *resource = *it;
+		resource->loadContent();
+	}
+
+	return;
+}
+
+
+void Device::unloadAllResources() {
+	for(DeviceResourceList::iterator it=resources.begin(); it!=resources.end(); it++) {
+		DeviceResource *resource = *it;
+		resource->releaseContent();
+	}
+
+	return;
+}
+
+
+
+
+DeviceDriver::DeviceDriver() {
+	return;
+}
+
+
+DeviceDriver::DeviceDriver(Device *device) {
+	return;
+}
+
+
+DeviceDriver::~DeviceDriver() {
+	return;
+}

File src/core/wiesel/device.h

View file
 	// forward declarations
 	
 	class DeviceResource;
+	class DeviceResourceContent;
 	
 
 	/**
 	 * @brief An abstract baseclass for any device classes.
-	 * Device classes wwill be used as an interface layer between application
+	 * Device classes will be used as an interface layer between application
 	 * and various hardware and platform specific implementations, such as
 	 * video devices for rendering or input devices for pointer and key input.
 	 * A device can handle various \ref DeviceResource objects.
 	 */
 	class WIESEL_CORE_EXPORT Device : public virtual SharedObject
 	{
+	friend class DeviceResource;
+
 	protected:
 		Device();
 		
 		 * their own set of functions to provide access to device resources.
 		 */
 		void removeResource(DeviceResource *resource);
+
+		/**
+		 * @brief Load all attached resources from the device's DeviceDriver.
+		 * The device needs a valid \ref DeviceDriver object.
+		 */
+		void loadAllResources();
+
+		/**
+		 * @brief Unloads the content of all attached resources.
+		 */
+		void unloadAllResources();
 		
 	protected:
 		/// type alias for resource lists
 		DeviceResourceList		resources;
 	};
 
+
+
+	/**
+	 * @brief The DeviceDriver class handles the hardware or platform dependent part
+	 * of any \ref Device object.
+	 */
+	class WIESEL_CORE_EXPORT DeviceDriver : public virtual SharedObject
+	{
+	private:
+		DeviceDriver();
+
+	protected:
+		DeviceDriver(Device *device);
+
+	public:
+		virtual ~DeviceDriver();
+	};
+
 }
 
 #endif /* __WIESEL_ENGINE_H__ */

File src/core/wiesel/device_resource.cpp

View file
 using namespace wiesel;
 
 
-DeviceResource::DeviceResource() : device(NULL) {
-	return;
+DeviceResource::DeviceResource() {
+	this->device		= NULL;
+	this->is_requested	= false;
 }
 
-
-DeviceResource::DeviceResource(Device *device) {
-	// device should be valid
-	assert(device);
-	
-	this->device = device;
-	
-	return;
-}
-
-
 DeviceResource::~DeviceResource() {
 	return;
 }
+
+
+void DeviceResource::_assign(Device *device) {
+	if (getDevice() != device) {
+		if (getDevice() != NULL) {
+			getDevice()->removeResource(this);
+		}
+
+		if (device) {
+			device->addResource(this);
+		}
+	}
+
+	return;
+}
+
+
+void DeviceResource::setRequested(bool requested) {
+	this->is_requested = requested;
+}
+
+
+bool DeviceResource::isRequested() const {
+	return is_requested;
+}
+
+
+bool DeviceResource::loadContent() {
+	setRequested(true);
+
+	if (getDevice()) {
+		doLoadContent();
+	}
+
+	return isLoaded();
+}
+
+
+void DeviceResource::releaseContent() {
+	setRequested(false);
+	doUnloadContent();
+	return;
+}
+
+
+
+
+DeviceResourceContent::DeviceResourceContent() {
+	return;
+}
+
+DeviceResourceContent::~DeviceResourceContent() {
+	return;
+}
+
+

File src/core/wiesel/device_resource.h

View file
 	// forward declarations
 	
 	class Device;
-	
-	
+
+
+	/**
+	 * @brief A base class for resources like textures or sounds.
+	 * The resource manages the basic interface and settings for the resource,
+	 * but doesn't store any data. The device-specific data will be stored
+	 * in a separate ResourceContent object.
+	 */
 	class WIESEL_CORE_EXPORT DeviceResource : public virtual SharedObject
 	{
-	private:
-		/// hidden default constructor
-		DeviceResource();
-		
+	friend class Device;
+
 	protected:
 		/// create a new device resource, 
-		DeviceResource(Device *device);
+		DeviceResource();
 		
 	public:
 		virtual ~DeviceResource();