Sfoglia il codice sorgente

Adding skeleton for MacOS backends

Panagiotis Christopoulos Charitos 12 anni fa
parent
commit
f56c9b0594

+ 3 - 1
CMakeLists.txt

@@ -54,11 +54,13 @@ OPTION(ANKI_SYSTEM_LIBPNG "Use the system's libpng" OFF)
 # Take a wild guess on the windowing system
 IF(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
 	SET(_WIN_BACKEND "GLXX11")
+ELSEIF(${CMAKE_SYSTEM_NAME} STREQUAL "Darwin")
+	SET(_WIN_BACKEND "MACOS")
 ELSE()
 	SET(_WIN_BACKEND "DONT_KNOW")
 ENDIF()
 
-SET(ANKI_WINDOW_BACKEND "${_WIN_BACKEND}" CACHE STRING "The window backend (GLXX11 or EGLX11 or EGLFBDEV or DUMMY)")
+SET(ANKI_WINDOW_BACKEND "${_WIN_BACKEND}" CACHE STRING "The window backend (GLXX11 or EGLX11 or EGLFBDEV or MACOS or DUMMY)")
 
 SET(ANKI_GCC_TO_STRING_WORKAROUND "0" CACHE STRING "Enable workaround for C++11 GCC bug (0 or 1)")
 

+ 1 - 1
docs/manual.rst

@@ -1,6 +1,6 @@
 **AnKi 3D Engine**
 
-Copyright (C) 2009-2011 Panagiotis Christopoulos-Charitos
+Copyright (C) 2009-2013 Panagiotis Christopoulos-Charitos
 
 http://www.anki3d.org
 

+ 19 - 9
include/anki/Config.h.cmake

@@ -10,14 +10,11 @@
 
 #define ANKI_DEBUG ${ANKI_DEBUG}
 
-#define ANKI_FILE __FILE__
-#define ANKI_FUNC __func__
-
 // Operating system
 #define ANKI_OS_LINUX 1 
 #define ANKI_OS_ANDROID 2
-#define ANKI_OS_APPLE 3
-#define ANKI_OS_APPLE_IOS 4
+#define ANKI_OS_MACOS 3
+#define ANKI_OS_IOS 4
 #define ANKI_OS_WINDOWS 5
 
 #if defined( __WIN32__ ) || defined( _WIN32 )
@@ -25,9 +22,9 @@
 #elif defined( __APPLE_CC__)
 #	if __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ >= 40000 \
 	|| __IPHONE_OS_VERSION_MIN_REQUIRED >= 40000
-#		define ANKI_OS ANKI_OS_APPLE_IOS
+#		define ANKI_OS ANKI_OS_IOS
 #	else
-#		define ANKI_OS ANKI_OS_APPLE
+#		define ANKI_OS ANKI_OS_MACOS
 #	endif
 #elif defined(__ANDROID__)
 #	define ANKI_OS ANKI_OS_ANDROID
@@ -37,7 +34,7 @@
 
 // POSIX system or not
 #if ANKI_OS == ANKI_OS_LINUX || ANKI_OS == ANKI_OS_ANDROID \
-	|| ANKI_OS == ANKI_OS_APPLE || ANKI_OS == ANKI_OS_APPLE_IOS
+	|| ANKI_OS == ANKI_OS_MACOS || ANKI_OS == ANKI_OS_IOS
 #	define ANKI_POSIX 1
 #else
 #	define ANKI_POSIX 0
@@ -71,13 +68,15 @@
 #define ANKI_WINDOW_BACKEND_GLXX11 1
 #define ANKI_WINDOW_BACKEND_EGLX11 2
 #define ANKI_WINDOW_BACKEND_EGLFBDEV 3
+#define ANKI_WINDOW_BACKEND_MACOS 4
 #define ANKI_WINDOW_BACKEND ANKI_WINDOW_BACKEND_${ANKI_WINDOW_BACKEND}
 #define ANKI_WINDOW_BACKEND_STR "ANKI_WINDOW_BACKEND_${ANKI_WINDOW_BACKEND}"
 
 // OpenGL version
 #define ANKI_GL_DESKTOP 1
 #define ANKI_GL_ES 2
-#if ANKI_WINDOW_BACKEND == ANKI_WINDOW_BACKEND_GLXX11
+#if ANKI_WINDOW_BACKEND == ANKI_WINDOW_BACKEND_GLXX11 \
+	|| ANKI_WINDOW_BACKEND == ANKI_WINDOW_BACKEND_MACOS
 #	define ANKI_GL ANKI_GL_DESKTOP
 #	define ANKI_GL_STR "ANKI_GL_DESKTOP"
 #else
@@ -88,6 +87,10 @@
 // Enable performance counters
 #define ANKI_ENABLE_COUNTERS ${_ANKI_ENABLE_COUNTERS}
 
+//==============================================================================
+// Engine config                                                               =
+//==============================================================================
+
 // General config
 #define ANKI_MAX_MULTIDRAW_PRIMITIVES 64
 #define ANKI_MAX_INSTANCES 64
@@ -122,6 +125,13 @@
 /// If true then we can place spatials in a thread-safe way
 #define ANKI_CFG_OCTREE_THREAD_SAFE 1
 
+//==============================================================================
+// Other                                                                       =
+//==============================================================================
+
+#define ANKI_FILE __FILE__
+#define ANKI_FUNC __func__
+
 // Some compiler struff
 #if defined(__GNUC__)
 #	define ANKI_LIKELY(x) __builtin_expect((x), 1)

+ 28 - 0
include/anki/core/NativeWindowMacos.h

@@ -0,0 +1,28 @@
+#ifndef ANKI_CORE_NATIVE_WINDOW_MACOS_H
+#define ANKI_CORE_NATIVE_WINDOW_MACOS_H
+
+#include "anki/core/NativeWindow.h"
+// XXX Include native libraries
+
+namespace anki {
+
+/// Native window implementation for Macos
+struct NativeWindowImpl
+{
+	// XXX Add native data
+
+	~NativeWindowImpl()
+	{
+		destroy();
+	}
+
+	void create(NativeWindowInitializer& init);
+	void destroy();
+
+private:
+	// XXX Add private methods if needed
+};
+
+} // end namespace anki
+
+#endif

+ 11 - 2
include/anki/input/Input.h

@@ -43,10 +43,21 @@ public:
 	}
 	/// @}
 
+	/// Initialize the platform's input system
 	void init(NativeWindow* nativeWindow);
+
+	/// Reset the keys and mouse buttons
 	void reset();
+
+	/// Populate the key and button with the new state
 	void handleEvents();
+
+	/// Move the mouse cursor to a position inside the window. Useful for 
+	/// locking the cursor into a fixed location (eg in the center of the 
+	/// screen)
 	void moveMouse(const Vec2& posNdc);
+
+	/// Hide the mouse cursor
 	void hideCursor(Bool hide);
 
 private:
@@ -67,8 +78,6 @@ private:
 
 	Vec2 mousePosNdc; ///< The coords are in the NDC space
 
-	Array<U16, 256> nativeKeyToAnki;
-
 	std::shared_ptr<InputImpl> impl;
 };
 

+ 16 - 0
include/anki/input/InputMacos.h

@@ -0,0 +1,16 @@
+#ifndef ANKI_INPUT_INPUT_MACOS_H
+#define ANKI_INPUT_INPUT_MACOS_H
+
+// XXX Include native libraries
+
+namespace anki {
+
+/// MacOs input implementation
+struct InputImpl
+{
+	// XXX Add native types
+};
+
+} // end namespace anki
+
+#endif

+ 1 - 0
include/anki/input/InputX11.h

@@ -9,6 +9,7 @@ namespace anki {
 struct InputImpl
 {
 	Cursor emptyCursor = 0;
+	Array<U16, 256> nativeKeyToAnki;
 };
 
 } // end namespace anki

+ 2 - 0
src/core/CMakeLists.txt

@@ -6,6 +6,8 @@ ELSEIF(ANKI_WINDOW_BACKEND STREQUAL "EGLX11")
 	SET(ANKI_CORE_SOURCES ${ANKI_CORE_SOURCES} NativeWindowEglX11.cpp)
 ELSEIF(ANKI_WINDOW_BACKEND STREQUAL "EGLFBDEV")
 	SET(ANKI_CORE_SOURCES ${ANKI_CORE_SOURCES} NativeWindowEglFbdev.cpp)
+ELSEIF(ANKI_WINDOW_BACKEND STREQUAL "MACOS")
+	SET(ANKI_CORE_SOURCES ${ANKI_CORE_SOURCES} NativeWindowMacos.cpp)
 ELSEIF(ANKI_WINDOW_BACKEND STREQUAL "DUMMY")
 	SET(ANKI_CORE_SOURCES ${ANKI_CORE_SOURCES} NativeWindowDummy.cpp)
 ELSE()

+ 58 - 0
src/core/NativeWindowMacos.cpp

@@ -0,0 +1,58 @@
+#include "anki/core/NativeWindowMacos.h"
+#include "anki/core/Counters.h"
+#include "anki/util/Exception.h"
+
+namespace anki {
+
+//==============================================================================
+// NativeWindowImpl                                                            =
+//==============================================================================
+
+//==============================================================================
+void NativeWindowImpl::create(NativeWindowInitializer& init)
+{
+	// XXX Populate
+}
+
+//==============================================================================
+void NativeWindowImpl::destroy()
+{
+	// XXX Populate
+}
+
+//==============================================================================
+// NativeWindow                                                                =
+//==============================================================================
+
+//==============================================================================
+NativeWindow::~NativeWindow()
+{}
+
+//==============================================================================
+void NativeWindow::create(NativeWindowInitializer& initializer)
+{
+	impl.reset(new NativeWindowImpl);
+	impl->create(initializer);
+
+	// Set the size after because the create may have changed it to something
+	// more nice
+	width = initializer.width;
+	height = initializer.height;
+}
+
+//==============================================================================
+void NativeWindow::destroy()
+{
+	impl.reset();
+}
+
+//==============================================================================
+void NativeWindow::swapBuffers()
+{
+	ANKI_COUNTER_START_TIMER(C_SWAP_BUFFERS_TIME);
+	ANKI_ASSERT(isCreated());
+	// XXX Add func to swap buffers
+	ANKI_COUNTER_STOP_TIMER_INC(C_SWAP_BUFFERS_TIME);
+}
+
+} // end namespace anki

+ 2 - 0
src/input/CMakeLists.txt

@@ -2,6 +2,8 @@ FILE(GLOB ANKI_INPUT_SOURCES Input.cpp)
 
 IF(ANKI_WINDOW_BACKEND STREQUAL "GLXX11" OR ANKI_WINDOW_BACKEND STREQUAL "EGLX11")
 	SET(ANKI_INPUT_SOURCES ${ANKI_INPUT_SOURCES} InputX11.cpp)
+ELSEIF(ANKI_WINDOW_BACKEND STREQUAL "MACOS")
+	SET(ANKI_INPUT_SOURCES ${ANKI_INPUT_SOURCES} InputMacos.cpp)
 ELSE()
 	SET(ANKI_INPUT_SOURCES ${ANKI_INPUT_SOURCES} InputDummy.cpp)
 ENDIF()

+ 34 - 0
src/input/InputMacos.cpp

@@ -0,0 +1,34 @@
+#include "anki/input/Input.h"
+#include "anki/input/InputMacos.h"
+
+namespace anki {
+
+//==============================================================================
+Input::~Input()
+{}
+
+//==============================================================================
+void Input::init(NativeWindow* nativeWindow)
+{
+	// XXX Add initialization code
+}
+
+//==============================================================================
+void Input::handleEvents()
+{
+	// XXX Add platform code
+}
+
+//==============================================================================
+void Input::moveMouse(const Vec2& pos)
+{
+	// XXX Add platform code
+}
+
+//==============================================================================
+void Input::hideCursor(Bool hide)
+{
+	// XXX Add platform code
+}
+
+} // end namespace anki

+ 7 - 6
src/input/InputX11.cpp

@@ -122,7 +122,7 @@ static const X11KeyCodeToAnki x2a[] = {
 	{XK_Right, KC_RIGHT}
 };
 
-#define XKEYCODE2ANKI(k_) nativeKeyToAnki[k_ & 0xFF]
+#define XKEYCODE2ANKI(k_) impl->nativeKeyToAnki[k_ & 0xFF]
 
 //==============================================================================
 static Bool eventsPending(Display* display)
@@ -165,19 +165,20 @@ void Input::init(NativeWindow* nativeWindow_)
 		| PointerMotionMask | FocusChangeMask | EnterWindowMask 
 		| LeaveWindowMask);
 
-	memset(&nativeKeyToAnki[0], sizeof(nativeKeyToAnki), KC_UNKNOWN);
+	// Init native
+	impl.reset(new InputImpl);
+
+	memset(
+		&impl->nativeKeyToAnki[0], sizeof(impl->nativeKeyToAnki), KC_UNKNOWN);
 	for(const X11KeyCodeToAnki& a : x2a)
 	{
 		// Convert X11 keycode to something else
 		U32 somethingElse = a.x & 0xFF;
 
-		nativeKeyToAnki[somethingElse] = a.ak;
+		impl->nativeKeyToAnki[somethingElse] = a.ak;
 	}
 
 	reset();
-
-	// Init native
-	impl.reset(new InputImpl);
 }
 
 //==============================================================================