Panagiotis Christopoulos Charitos 12 سال پیش
والد
کامیت
467b68f691

+ 40 - 11
CMakeLists.txt

@@ -2,6 +2,37 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
 
 PROJECT(anki)
 
+#
+# Determin the system to build for. Do that first
+#
+
+if(WIN32)
+	if(NOT WINDOWS)
+		set(WINDOWS TRUE)
+		message("++ Building for windows")
+	endif()
+elseif(UNIX AND NOT APPLE)
+	if(CMAKE_SYSTEM_NAME MATCHES ".*Linux")
+		if(NOT ANDROID)
+			set(LINUX TRUE)
+			message("++ Building for Linux")
+		else()
+			message("++ Building for Android")
+		endif()
+	else()
+		message(FATAL_ERROR "Unknown unix")
+	endif()
+elseif(APPLE)
+	if(CMAKE_SYSTEM_NAME MATCHES ".*MacOS.*")
+		set(MACOS TRUE)
+		message("++ Building for MacOS")
+	else()
+		message(FATAL_ERROR "Unknown apple")
+	endif()
+else()
+	message(FATAL_ERROR "Unknown system")
+endif()
+
 #
 # Configuration
 #
@@ -38,17 +69,15 @@ ELSE()
 ENDIF()
 
 # Take a wild guess on the windowing system
-IF(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
-	IF(${ANDROID})
-		SET(_WIN_BACKEND "ANDROID")
-	ELSE()
-		SET(_WIN_BACKEND "GLXX11")
-	ENDIF()
-ELSEIF(${CMAKE_SYSTEM_NAME} STREQUAL "Darwin")
-	SET(_WIN_BACKEND "MACOS")
-ELSE()
-	MESSAGE(FATAL_ERROR "Couldn't determine the window backend. You need to specify it manually")
-ENDIF()
+if(LINUX)
+	set(_WIN_BACKEND "GLXX11")
+elseif(ANDROID)
+	set(_WIN_BACKEND "ANDROID")
+elseif(MACOS)
+	set(_WIN_BACKEND "MACOS")
+else()
+	message(FATAL_ERROR "Couldn't determine the window backend. You need to specify it manually")
+endif()
 
 SET(ANKI_WINDOW_BACKEND "${_WIN_BACKEND}" CACHE STRING "The window backend (GLXX11 or EGLX11 or EGLFBDEV or MACOS or or ANDROID or DUMMY)")
 

+ 1 - 0
bench/Main.cpp

@@ -143,6 +143,7 @@ void initSubsystems()
 	initializer.get("maxTextureSize") = 1024;
 	initializer.get("mrt") = false;
 	initializer.get("pps.sharpen") = false;
+	initializer.get("pps.gammaCorrection") = false;
 #endif
 
 	MainRendererSingleton::get().init(initializer);

+ 19 - 0
include/anki/core/NativeWindowSdl.h

@@ -0,0 +1,19 @@
+#ifndef ANKI_CORE_NATIVE_WINDOW_SDL_H
+#define ANKI_CORE_NATIVE_WINDOW_SDL_H
+
+#include "anki/core/NativeWindow.h"
+#include <SDL.h>
+
+namespace anki {
+
+/// Native window implementation for SDL
+struct NativeWindowImpl
+{
+	SDL_Window* window = nullptr;
+	SDL_GLContext ctx = 0;
+};
+
+} // end namespace anki
+
+#endif
+

+ 1 - 0
shaders/Common.glsl

@@ -17,5 +17,6 @@ precision DEFAULT_FLOAT_PRECISION int;
 
 // Read from a render target texture
 #define textureFai(tex_, texc_) texture(tex_, texc_)
+//#define textureFai(tex_, texc_) textureLod(tex_, texc_, 0.0)
 
 #endif

+ 2 - 0
shaders/Pps.glsl

@@ -112,8 +112,10 @@ void main(void)
 	fColor += lf;
 #endif
 
+#ifdef GAMMA_CORRECTION_ENABLED
 	//fColor = BlendHardLight(vec3(0.7, 0.72, 0.4), fColor);
 	fColor = gammaCorrectionRgb(vec3(0.9, 0.92, 0.75), fColor);
+#endif
 
 #if 0
 	if(fColor.r != 0.00000001)

+ 1 - 0
shaders/PpsHdr.glsl

@@ -3,6 +3,7 @@
 #pragma anki include "shaders/SimpleVert.glsl"
 
 #pragma anki start fragmentShader
+#define DEFAULT_FLOAT_PRECISION mediump
 #pragma anki include "shaders/Common.glsl"
 
 uniform lowp sampler2D fai; ///< Its the IS FAI

+ 4 - 0
src/CMakeLists.txt

@@ -26,6 +26,10 @@ ELSE()
 	MESSAGE(FATAL_ERROR "Unrecognized ANKI_WINDOW_BACKEND: ${ANKI_WINDOW_BACKEND}")
 ENDIF()
 
+if(ANKI_USE_SDL)
+	SET(ANKI_LIBS ${ANKI_LIBS} ankisdl)
+endif()
+
 ADD_LIBRARY(anki Dummy.cpp "${_SYS_SRC}")
 
 TARGET_LINK_LIBRARIES(anki ${ANKI_LIBS} ankitinyxml2 ankilua ankibullet ankiz ${ANKI_GPERFTOOLS_LIBS} ${_SYS})

+ 106 - 0
src/core/NativeWindowSdl.cpp

@@ -0,0 +1,106 @@
+#include "anki/core/NativeWindowSdl.h"
+#include "anki/core/Counters.h"
+#include "anki/util/Exception.h"
+
+namespace anki {
+
+//==============================================================================
+NativeWindow::~NativeWindow()
+{}
+
+//==============================================================================
+void NativeWindow::create(NativeWindowInitializer& initializer)
+{
+	impl.reset(new NativeWindowImpl);
+	
+	//
+	// Set GL attributes
+	//
+	SDL_GL_SetAttribute(SDL_GL_RED_SIZE, initializer.rgbaBits[0]);
+	SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, initializer.rgbaBits[1]);
+	SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, initializer.rgbaBits[2]);
+	SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, initializer.rgbaBits[3]);
+	SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, initializer.depthBits);
+	SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, initializer.doubleBuffer);
+
+	if(initializer.debugContext)
+	{
+		SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, SDL_GL_CONTEXT_DEBUG_FLAG);
+	}
+
+	SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, initializer.majorVersion);
+	SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, initializer.minorVersion);
+	
+	SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, 
+		SDL_GL_CONTEXT_PROFILE_CORE);
+
+	//
+	// Create window
+	//
+	U32 flags = SDL_WINDOW_OPENGL;
+
+	if(initializer.fullscreenDesktopRez)
+	{
+		flags |= SDL_WINDOW_FULLSCREEN_DESKTOP;
+	}
+
+	impl->window = SDL_CreateWindow(
+    	initializer.title.c_str(), 
+		SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 
+		initializer.width, initializer.height, flags);
+
+	if(impl->window == nullptr)
+	{
+		throw ANKI_EXCEPTION("SDL_CreateWindow() failed");
+	}
+
+	// Set the size after loading a fullscreen window
+	if(initializer.fullscreenDesktopRez)
+	{
+		int w, h;
+		SDL_GetWindowSize(imp->window, &w, &h);
+
+		width = w;
+		height = h;
+	}
+
+	//
+	// Create context
+	//
+	impl->context = SDL_GL_CreateContext(impl->window);
+
+	if(impl->context == nullptr)
+	{
+		throw ANKI_EXCEPTION("SDL_GL_CreateContext() failed");
+	}
+}
+
+//==============================================================================
+void NativeWindow::destroy()
+{
+	if(impl.get())
+	{
+		if(impl->context)
+		{
+			SDL_GL_DeleteContext(impl->context);
+		}
+
+		if(impl->window)
+		{
+			SDL_DestroyWindow(impl->window);
+		}
+	}
+
+	impl.reset();
+}
+
+//==============================================================================
+void NativeWindow::swapBuffers()
+{
+	ANKI_COUNTER_START_TIMER(C_SWAP_BUFFERS_TIME);
+	ANKI_ASSERT(isCreated());
+	glXSwapBuffers(impl->xDisplay, impl->xWindow);
+	ANKI_COUNTER_STOP_TIMER_INC(C_SWAP_BUFFERS_TIME);
+}
+
+} // end namespace anki

+ 1 - 0
src/input/InputSdl.cpp

@@ -0,0 +1 @@
+#include "anki/input/Input.h"

+ 5 - 0
src/renderer/Pps.cpp

@@ -63,6 +63,11 @@ void Pps::initInternal(const RendererInitializer& initializer)
 		pps += "#define SHARPEN_ENABLED\n";
 	}
 
+	if(initializer.get("pps.gammaCorrection"))
+	{
+		pps += "#define GAMMA_CORRECTION_ENABLED\n";
+	}
+
 	pps += "#define FBO_WIDTH " + std::to_string(r->getWidth()) + "\n";
 	pps += "#define FBO_HEIGHT " + std::to_string(r->getHeight()) + "\n";
 

+ 1 - 0
src/renderer/Renderer.cpp

@@ -53,6 +53,7 @@ RendererInitializer::RendererInitializer()
 
 	newOption("pps.enabled", true);
 	newOption("pps.sharpen", true);
+	newOption("pps.gammaCorrection", true);
 
 	// Dbg
 	newOption("dbg.enabled", false);