Browse Source

Fixed window resizing, fullscreen and mouse capture

Modified renderer and geometry buffer to fix window resizing and going fullscreen.
Modified mouse capturing in window class. Turned off mouse warping mode (centering the mouse to the middle of the screen each frame) to fix the window reporting the wrong cursor position.
Paulcodedev 7 years ago
parent
commit
56c3388732

+ 2 - 0
.gitignore

@@ -16,3 +16,5 @@ Builds/x64/Release 64bit/Praxis3D\.iobj
 Builds/x64/Release 64bit/Praxis3D\.ipdb
 Builds/x64/Release 64bit/Praxis3D\.ipdb
 
 
 *.dae
 *.dae
+
+Praxis3D/x64/

+ 6 - 4
Praxis3D/Data/config.ini

@@ -1,9 +1,9 @@
 window_position_x 250
 window_position_x 250
 window_position_y 60
 window_position_y 60
-window_size_windowed_x 1280
-window_size_windowed_y 768
-window_size_fullscreen_x 3325
-window_size_fullscreen_y 1871
+window_size_windowed_x 1500
+window_size_windowed_y 900
+window_size_fullscreen_x 1920
+window_size_fullscreen_y 1080
 fullscreen 0
 fullscreen 0
 fullscreen_borderless 1
 fullscreen_borderless 1
 gl_context_major_version 4
 gl_context_major_version 4
@@ -15,6 +15,8 @@ gl_texture_anisotropy 16
 camera_freelook_speed 25
 camera_freelook_speed 25
 face_culling 1
 face_culling 1
 eye_adaption 1
 eye_adaption 1
+mouse_captured 1
+mouse_warp_mode 0
 fov 80
 fov 80
 z_near 0.1
 z_near 0.1
 z_far 40000
 z_far 40000

+ 2 - 2
Praxis3D/Source/Config.h

@@ -554,7 +554,7 @@ public:
 			rendering_res_y = 900;
 			rendering_res_y = 900;
 			alpha_threshold = 0.0f;
 			alpha_threshold = 0.0f;
 			emissive_threshold = 0.3f;
 			emissive_threshold = 0.3f;
-			eye_adaption_rate = 1.0f;
+			eye_adaption_rate = 0.5f;
 			fog_color_x = 0.55f;
 			fog_color_x = 0.55f;
 			fog_color_y = 0.55f;
 			fog_color_y = 0.55f;
 			fog_color_z = 0.55f;
 			fog_color_z = 0.55f;
@@ -640,7 +640,7 @@ public:
 			up_key = 95;
 			up_key = 95;
 			vsync_key = 68;
 			vsync_key = 68;
 			mouse_filter = false;
 			mouse_filter = false;
-			mouse_warp_mode = true;
+			mouse_warp_mode = false;
 			mouse_jaw = 0.022f;
 			mouse_jaw = 0.022f;
 			mouse_pitch = 0.022f;
 			mouse_pitch = 0.022f;
 			mouse_pitch_clip = 1.2f;
 			mouse_pitch_clip = 1.2f;

+ 14 - 13
Praxis3D/Source/GeometryBuffer.cpp

@@ -111,9 +111,9 @@ ErrorCode GeometryBuffer::init()
 					 Config::FramebfrVariables().gl_final_buffer_texture_format, Config::FramebfrVariables().gl_final_buffer_texture_type, NULL);
 					 Config::FramebfrVariables().gl_final_buffer_texture_format, Config::FramebfrVariables().gl_final_buffer_texture_type, NULL);
 		// If eye adaption (HDR) is enabled, buffer should use a different min_filter (to support mipmapping)
 		// If eye adaption (HDR) is enabled, buffer should use a different min_filter (to support mipmapping)
 		if(Config::graphicsVar().eye_adaption)
 		if(Config::graphicsVar().eye_adaption)
-			glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, Config::FramebfrVariables().gl_final_buffer_min_filter);
-		else
 			glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, Config::FramebfrVariables().gl_final_buffer_min_filter_HDR);
 			glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, Config::FramebfrVariables().gl_final_buffer_min_filter_HDR);
+		else
+			glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, Config::FramebfrVariables().gl_final_buffer_min_filter);
 		glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, Config::FramebfrVariables().gl_final_buffer_mag_filter);
 		glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, Config::FramebfrVariables().gl_final_buffer_mag_filter);
 		glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + GBufferFinal, GL_TEXTURE_2D, m_finalBuffer, 0);
 		glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + GBufferFinal, GL_TEXTURE_2D, m_finalBuffer, 0);
 		
 		
@@ -138,27 +138,28 @@ void GeometryBuffer::setBufferSize(unsigned int p_bufferWidth, unsigned int p_bu
 
 
 		glBindFramebuffer(GL_DRAW_FRAMEBUFFER, m_FBO);
 		glBindFramebuffer(GL_DRAW_FRAMEBUFFER, m_FBO);
 
 
-		// Resize geometry textures
-		for(GLuint i = GBufferPosition; i < GBufferNumTextures; i++)
+		// Create textures
+		for (GLuint i = 0; i < GBufferNumTextures; i++)
 		{
 		{
 			glBindTexture(GL_TEXTURE_2D, m_GBTextures[i]);
 			glBindTexture(GL_TEXTURE_2D, m_GBTextures[i]);
 			glTexImage2D(GL_TEXTURE_2D, 0, m_internalFormats[i], m_bufferWidth, m_bufferHeight, 0, m_textureFormats[i], m_textureTypes[i], NULL);
 			glTexImage2D(GL_TEXTURE_2D, 0, m_internalFormats[i], m_bufferWidth, m_bufferHeight, 0, m_textureFormats[i], m_textureTypes[i], NULL);
 		}
 		}
 
 
-		// Resize depth buffer
+		// Create depth buffer
 		glBindTexture(GL_TEXTURE_2D, m_depthBuffer);
 		glBindTexture(GL_TEXTURE_2D, m_depthBuffer);
-		glTexImage2D(GL_TEXTURE_2D, 0, Config::FramebfrVariables().gl_depth_buffer_internal_format, m_bufferWidth, m_bufferHeight, 0, 
-					 Config::FramebfrVariables().gl_depth_buffer_texture_format, Config::FramebfrVariables().gl_depth_buffer_texture_type, NULL);
+		glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH24_STENCIL8, m_bufferWidth, m_bufferHeight, 0, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, NULL);
+		glTexImage2D(GL_TEXTURE_2D, 0, Config::FramebfrVariables().gl_depth_buffer_internal_format, m_bufferWidth, m_bufferHeight, 0,
+			Config::FramebfrVariables().gl_depth_buffer_texture_format, Config::FramebfrVariables().gl_depth_buffer_texture_type, NULL);
 
 
-		// Resize the blur buffer
+		// Create the blur buffer, that acts as an intermediate buffer between vertical and horizontal blur passes
 		glBindTexture(GL_TEXTURE_2D, m_blurBuffer);
 		glBindTexture(GL_TEXTURE_2D, m_blurBuffer);
-		glTexImage2D(GL_TEXTURE_2D, 0, Config::FramebfrVariables().gl_blur_buffer_internal_format, m_bufferWidth, m_bufferHeight, 0, 
-					 Config::FramebfrVariables().gl_blur_buffer_texture_format, Config::FramebfrVariables().gl_blur_buffer_texture_type, NULL);
+		glTexImage2D(GL_TEXTURE_2D, 0, Config::FramebfrVariables().gl_blur_buffer_internal_format, m_bufferWidth, m_bufferHeight, 0,
+			Config::FramebfrVariables().gl_blur_buffer_texture_format, Config::FramebfrVariables().gl_blur_buffer_texture_type, NULL);
 
 
-		// Resize the final buffer
+		// Create the final buffer, that gets renderred to the screen
 		glBindTexture(GL_TEXTURE_2D, m_finalBuffer);
 		glBindTexture(GL_TEXTURE_2D, m_finalBuffer);
-		glTexImage2D(GL_TEXTURE_2D, 0, Config::FramebfrVariables().gl_final_buffer_internal_format, m_bufferWidth, m_bufferHeight, 0, 
-					 Config::FramebfrVariables().gl_final_buffer_texture_format, Config::FramebfrVariables().gl_final_buffer_texture_type, NULL);
+		glTexImage2D(GL_TEXTURE_2D, 0, Config::FramebfrVariables().gl_final_buffer_internal_format, m_bufferWidth, m_bufferHeight, 0,
+			Config::FramebfrVariables().gl_final_buffer_texture_format, Config::FramebfrVariables().gl_final_buffer_texture_type, NULL);
 	}
 	}
 }
 }
 void GeometryBuffer::setBufferSize(GLuint p_buffer, unsigned int p_bufferWidth, unsigned int p_bufferHeight)
 void GeometryBuffer::setBufferSize(GLuint p_buffer, unsigned int p_bufferWidth, unsigned int p_bufferHeight)

+ 9 - 0
Praxis3D/Source/RendererBackend.h

@@ -364,6 +364,15 @@ public:
 	~RendererBackend();
 	~RendererBackend();
 
 
 	ErrorCode init(const UniformFrameData &p_frameData);
 	ErrorCode init(const UniformFrameData &p_frameData);
+
+	void setScreenSize(const UniformFrameData &p_frameData)
+	{
+		// Set gbuffer textures size
+		m_gbuffer->setBufferSize((unsigned int)p_frameData.m_screenSize.x, (unsigned int)p_frameData.m_screenSize.y);
+
+		// Set the viewport
+		glViewport(0, 0, p_frameData.m_screenSize.x, p_frameData.m_screenSize.y);
+	}
 	
 	
 	void processUpdate(const BufferUpdateCommands &p_updateCommands, const UniformFrameData &p_frameData);
 	void processUpdate(const BufferUpdateCommands &p_updateCommands, const UniformFrameData &p_frameData);
 	void processLoading(LoadCommands &p_loadCommands, const UniformFrameData &p_frameData);
 	void processLoading(LoadCommands &p_loadCommands, const UniformFrameData &p_frameData);

+ 14 - 0
Praxis3D/Source/RendererFrontend.cpp

@@ -62,6 +62,20 @@ ErrorCode RendererFrontend::init()
 
 
 void RendererFrontend::renderFrame(const SceneObjects &p_sceneObjects, const float p_deltaTime)
 void RendererFrontend::renderFrame(const SceneObjects &p_sceneObjects, const float p_deltaTime)
 {
 {
+	if(m_frameData.m_screenSize.x != Config::graphicsVar().current_resolution_x ||
+		m_frameData.m_screenSize.y != Config::graphicsVar().current_resolution_y)
+	{
+		// Set the new resolution
+		m_frameData.m_screenSize.x = Config::graphicsVar().current_resolution_x;
+		m_frameData.m_screenSize.y = Config::graphicsVar().current_resolution_y;
+
+		// Update the projection matrix because it is dependant on the screen size
+		updateProjectionMatrix();
+
+		// Set screen size in the backend
+		m_backend.setScreenSize(m_frameData);
+	}
+
 	// Clear draw commands at the beggining of each frame
 	// Clear draw commands at the beggining of each frame
 	m_drawCommands.clear();
 	m_drawCommands.clear();
 
 

+ 3 - 3
Praxis3D/Source/Window.cpp

@@ -127,7 +127,7 @@ ErrorCode Window::createWindow()
 
 
 		// If mouse cursor is clipped, we need to hide it
 		// If mouse cursor is clipped, we need to hide it
 		setMouseRelativeMode(Config::windowVar().mouse_captured);
 		setMouseRelativeMode(Config::windowVar().mouse_captured);
-
+		
 		// Set if the mouse should warm to screen center in relative capture mode
 		// Set if the mouse should warm to screen center in relative capture mode
 		if(Config::inputVar().mouse_warp_mode)
 		if(Config::inputVar().mouse_warp_mode)
 			SDL_SetHintWithPriority(SDL_HINT_MOUSE_RELATIVE_MODE_WARP, "1", SDL_HINT_OVERRIDE);
 			SDL_SetHintWithPriority(SDL_HINT_MOUSE_RELATIVE_MODE_WARP, "1", SDL_HINT_OVERRIDE);
@@ -262,7 +262,7 @@ void Window::handleSDLEvent(const SDL_Event &p_SDLEvent)
 		// Get the relative mouse location
 		// Get the relative mouse location
 		m_mouseInfo.m_movementCurrentFrameX += p_SDLEvent.motion.xrel;
 		m_mouseInfo.m_movementCurrentFrameX += p_SDLEvent.motion.xrel;
 		m_mouseInfo.m_movementCurrentFrameY += p_SDLEvent.motion.yrel;
 		m_mouseInfo.m_movementCurrentFrameY += p_SDLEvent.motion.yrel;
-
+		
 		break;
 		break;
 	}
 	}
 
 
@@ -376,7 +376,7 @@ void Window::processChanges()
 					Config::m_windowVar.fullscreen = m_changeQueue[i].getBool();
 					Config::m_windowVar.fullscreen = m_changeQueue[i].getBool();
 
 
 					// If it is switching to border-less fullscreen, set the fullscreen resolution
 					// If it is switching to border-less fullscreen, set the fullscreen resolution
-					if(Config::windowVar().fullscreen && !Config::windowVar().fullscreen_borderless)
+					if (Config::windowVar().fullscreen && !Config::windowVar().fullscreen_borderless)
 					{
 					{
 						setWindowSize(Config::windowVar().window_size_fullscreen_x, Config::windowVar().window_size_fullscreen_y);
 						setWindowSize(Config::windowVar().window_size_fullscreen_x, Config::windowVar().window_size_fullscreen_y);