Added two render layers and the basic rendering pipeline; Fixed fullscreen graphics; No shader re-binding
This commit is contained in:
		
							parent
							
								
									e35688373e
								
							
						
					
					
						commit
						1c638bdcb9
					
				@ -10,11 +10,10 @@ void MainState::onEnter() {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void MainState::update(double deltaTime) {
 | 
					void MainState::update(double deltaTime) {
 | 
				
			||||||
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void MainState::render() {
 | 
					void MainState::render() {
 | 
				
			||||||
 | 
						static Renderer& renderer = *m_app->getRenderer();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void MainState::onExit() {
 | 
					void MainState::onExit() {
 | 
				
			||||||
 | 
				
			|||||||
@ -10,6 +10,6 @@
 | 
				
			|||||||
    </Expand>
 | 
					    </Expand>
 | 
				
			||||||
  </Type>
 | 
					  </Type>
 | 
				
			||||||
  <Type Name="nf::Config">
 | 
					  <Type Name="nf::Config">
 | 
				
			||||||
    <DisplayString>Width = {width}, Height = {height}, Fullscreen = {fullscreen}</DisplayString>
 | 
					    <DisplayString>Width = {width}, Height = {height}, Fullscreen = {fullscreen}, Title = {title,sb}</DisplayString>
 | 
				
			||||||
  </Type>
 | 
					  </Type>
 | 
				
			||||||
</AutoVisualizer>
 | 
					</AutoVisualizer>
 | 
				
			||||||
@ -11,8 +11,9 @@ namespace nf {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	Application::Application(Config& config) :
 | 
						Application::Application(Config& config) :
 | 
				
			||||||
		m_currentConfig(config),
 | 
							m_currentConfig(config),
 | 
				
			||||||
		m_wndPlacement{ sizeof(m_wndPlacement) },
 | 
					 | 
				
			||||||
		m_running(false),
 | 
							m_running(false),
 | 
				
			||||||
 | 
							m_altWidth(1280),
 | 
				
			||||||
 | 
							m_altHeight(720),
 | 
				
			||||||
		m_defaultStateAdded(false),
 | 
							m_defaultStateAdded(false),
 | 
				
			||||||
		m_stateChange(false)
 | 
							m_stateChange(false)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
@ -44,7 +45,7 @@ namespace nf {
 | 
				
			|||||||
		return m_renderer;
 | 
							return m_renderer;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	void Application::addState(Gamestate* state,const std::string& stateName) {
 | 
						void Application::addState(Gamestate* state, const std::string& stateName) {
 | 
				
			||||||
		if (m_states.find(stateName) == m_states.end()) {
 | 
							if (m_states.find(stateName) == m_states.end()) {
 | 
				
			||||||
			m_states[stateName] = state;
 | 
								m_states[stateName] = state;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
@ -101,19 +102,19 @@ namespace nf {
 | 
				
			|||||||
	const HWND& Application::getWindow() {
 | 
						const HWND& Application::getWindow() {
 | 
				
			||||||
		return m_window;
 | 
							return m_window;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						//TODO: Throughly test this
 | 
				
			||||||
	void Application::changeConfig(const Config& in) {
 | 
						void Application::changeConfig(const Config& in) {
 | 
				
			||||||
		SetWindowText(m_window, toWide(in.title));
 | 
							SetWindowText(m_window, toWide(in.title));
 | 
				
			||||||
		if (in.fullscreen != m_currentConfig.fullscreen) {
 | 
							bool temp = m_currentConfig.fullscreen;
 | 
				
			||||||
		m_currentConfig = in;
 | 
							m_currentConfig = in;
 | 
				
			||||||
 | 
							if (in.fullscreen != temp)
 | 
				
			||||||
			toggleFullscreen();
 | 
								toggleFullscreen();
 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		if (m_currentConfig.fullscreen)
 | 
							if (m_currentConfig.fullscreen)
 | 
				
			||||||
			return;
 | 
								return;
 | 
				
			||||||
		m_currentConfig = in;
 | 
					 | 
				
			||||||
		int x = 0, y = 0;
 | 
							int x = 0, y = 0;
 | 
				
			||||||
		calculateNewWindowPos(x, y);
 | 
							calculateNewWindowPos(x, y);
 | 
				
			||||||
		SetWindowPos(m_window, HWND_TOP, x, y, in.width, in.height, SWP_NOOWNERZORDER | SWP_FRAMECHANGED);
 | 
							RECT size = getWindowRect();
 | 
				
			||||||
 | 
							SetWindowPos(m_window, HWND_TOP, x, y, size.right, size.bottom, SWP_NOOWNERZORDER | SWP_FRAMECHANGED);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	const Config& Application::getConfig() const {
 | 
						const Config& Application::getConfig() const {
 | 
				
			||||||
@ -169,20 +170,20 @@ namespace nf {
 | 
				
			|||||||
		x = monX - (m_currentConfig.width / 2);
 | 
							x = monX - (m_currentConfig.width / 2);
 | 
				
			||||||
		y = monY - (m_currentConfig.height / 2);
 | 
							y = monY - (m_currentConfig.height / 2);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	//TODO: Test fullscreen graphcis
 | 
						//TODO: Test fullscreen graphics
 | 
				
			||||||
	void Application::toggleFullscreen() {
 | 
						void Application::toggleFullscreen() {
 | 
				
			||||||
		DWORD wndStyle = GetWindowLong(m_window, GWL_STYLE);
 | 
							DWORD wndStyle = GetWindowLong(m_window, GWL_STYLE);
 | 
				
			||||||
		if (wndStyle & WS_OVERLAPPEDWINDOW) {
 | 
							if (wndStyle & WS_OVERLAPPEDWINDOW) {
 | 
				
			||||||
			GetWindowPlacement(m_window, &m_wndPlacement);
 | 
					 | 
				
			||||||
			MONITORINFO mi = { sizeof(mi) };
 | 
								MONITORINFO mi = { sizeof(mi) };
 | 
				
			||||||
			GetMonitorInfo(MonitorFromWindow(m_window, MONITOR_DEFAULTTOPRIMARY), &mi);
 | 
								GetMonitorInfo(MonitorFromWindow(m_window, MONITOR_DEFAULTTOPRIMARY), &mi);
 | 
				
			||||||
			SetWindowLong(m_window, GWL_STYLE, wndStyle & ~WS_OVERLAPPEDWINDOW);
 | 
								SetWindowLong(m_window, GWL_STYLE, wndStyle & ~WS_OVERLAPPEDWINDOW);
 | 
				
			||||||
			SetWindowPos(m_window, HWND_TOP, mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right - mi.rcMonitor.left, mi.rcMonitor.bottom - mi.rcMonitor.top, SWP_NOOWNERZORDER | SWP_FRAMECHANGED);
 | 
								m_currentConfig.width = mi.rcMonitor.right - mi.rcMonitor.left;
 | 
				
			||||||
 | 
								m_currentConfig.height = mi.rcMonitor.bottom - mi.rcMonitor.top;
 | 
				
			||||||
 | 
								SetWindowPos(m_window, HWND_TOP, mi.rcMonitor.left, mi.rcMonitor.top, m_currentConfig.width, m_currentConfig.height, SWP_NOOWNERZORDER | SWP_FRAMECHANGED);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		else {
 | 
							else {
 | 
				
			||||||
			SetWindowLong(m_window, GWL_STYLE, m_defaultWindowStyle);
 | 
								SetWindowLong(m_window, GWL_STYLE, wndStyle | WS_OVERLAPPEDWINDOW & ~WS_MAXIMIZEBOX);
 | 
				
			||||||
			SetWindowPlacement(m_window, &m_wndPlacement);
 | 
								SetWindowPos(m_window, HWND_TOP, 0, 0, 0, 0, SWP_FRAMECHANGED | SWP_NOMOVE | SWP_NOSIZE);
 | 
				
			||||||
			SetWindowPos(m_window, NULL, 0, 0, m_currentConfig.width, m_currentConfig.height, SWP_NOMOVE | SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_FRAMECHANGED);
 | 
					 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -230,7 +231,7 @@ namespace nf {
 | 
				
			|||||||
		m_currentState = m_states[m_nextState];
 | 
							m_currentState = m_states[m_nextState];
 | 
				
			||||||
		m_currentState->onEnter();
 | 
							m_currentState->onEnter();
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						//TODO: mouse position input
 | 
				
			||||||
	LRESULT CALLBACK Application::WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
 | 
						LRESULT CALLBACK Application::WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
 | 
				
			||||||
		Application* app = (Application*)GetProp(hWnd, L"App");
 | 
							Application* app = (Application*)GetProp(hWnd, L"App");
 | 
				
			||||||
		switch (uMsg) {
 | 
							switch (uMsg) {
 | 
				
			||||||
@ -240,8 +241,14 @@ namespace nf {
 | 
				
			|||||||
		case WM_SYSKEYDOWN: {
 | 
							case WM_SYSKEYDOWN: {
 | 
				
			||||||
			if (GetKeyState(VK_RETURN) & 0x8000) {
 | 
								if (GetKeyState(VK_RETURN) & 0x8000) {
 | 
				
			||||||
				if (!(lParam & (1 << 30))) {
 | 
									if (!(lParam & (1 << 30))) {
 | 
				
			||||||
					app->m_currentConfig.fullscreen = !app->m_currentConfig.fullscreen;
 | 
										if (!app->m_currentConfig.fullscreen) {
 | 
				
			||||||
					app->toggleFullscreen();
 | 
											app->m_altWidth = app->m_currentConfig.width;
 | 
				
			||||||
 | 
											app->m_altHeight = app->m_currentConfig.height;
 | 
				
			||||||
 | 
										}
 | 
				
			||||||
 | 
										app->changeConfig({ app->m_currentConfig.width, app->m_currentConfig.height, !app->m_currentConfig.fullscreen, app->m_currentConfig.title });
 | 
				
			||||||
 | 
										if (!app->m_currentConfig.fullscreen) {
 | 
				
			||||||
 | 
											app->changeConfig({ app->m_altWidth, app->m_altHeight, app->m_currentConfig.fullscreen, app->m_currentConfig.title });
 | 
				
			||||||
 | 
										}
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
				return 0;
 | 
									return 0;
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
@ -250,7 +257,6 @@ namespace nf {
 | 
				
			|||||||
		case WM_MENUCHAR: {
 | 
							case WM_MENUCHAR: {
 | 
				
			||||||
			return MNC_CLOSE << 16;
 | 
								return MNC_CLOSE << 16;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		//TODO: mouse position input
 | 
					 | 
				
			||||||
		case WM_LBUTTONDOWN: {
 | 
							case WM_LBUTTONDOWN: {
 | 
				
			||||||
			app->m_input[1] = true;
 | 
								app->m_input[1] = true;
 | 
				
			||||||
			return 0;
 | 
								return 0;
 | 
				
			||||||
 | 
				
			|||||||
@ -6,7 +6,6 @@
 | 
				
			|||||||
namespace nf {
 | 
					namespace nf {
 | 
				
			||||||
	Gamestate::Gamestate(Application* app) {
 | 
						Gamestate::Gamestate(Application* app) {
 | 
				
			||||||
		m_app = app;
 | 
							m_app = app;
 | 
				
			||||||
		m_renderer = m_app->getRenderer();
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	void Gamestate::onEnter() {
 | 
						void Gamestate::onEnter() {
 | 
				
			||||||
 | 
				
			|||||||
@ -1,8 +1,28 @@
 | 
				
			|||||||
#include "Drawable.h"
 | 
					#include "Drawable.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace nf {
 | 
					namespace nf {
 | 
				
			||||||
	Drawable::Drawable() {
 | 
						Drawable::Drawable(const char* vertexShader, const char* fragmentShader, const void* vertexBufferData, const size_t vertexBufferSize, const void* indexBufferData, size_t indexBufferCount) :
 | 
				
			||||||
 | 
							m_shader(vertexShader, fragmentShader),
 | 
				
			||||||
 | 
							m_vao(),
 | 
				
			||||||
 | 
							m_ib(indexBufferData, indexBufferCount)
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							m_vao.addBuffer(vertexBufferData, vertexBufferSize);
 | 
				
			||||||
 | 
							m_vao.push<float>(2);
 | 
				
			||||||
 | 
							m_vao.finishBufferLayout();
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						unsigned int Drawable::getIndexCount() {
 | 
				
			||||||
 | 
							return m_ib.getCount();
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						void Drawable::bind() {
 | 
				
			||||||
 | 
							m_shader.bind();
 | 
				
			||||||
 | 
							m_vao.bind();
 | 
				
			||||||
 | 
							m_ib.bind();
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						Drawable::DrawableType Drawable::identity() {
 | 
				
			||||||
 | 
							return DrawableType::NF_NONE;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	Drawable::~Drawable() {
 | 
						Drawable::~Drawable() {
 | 
				
			||||||
 | 
				
			|||||||
@ -53,8 +53,13 @@ namespace nf {
 | 
				
			|||||||
		glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
 | 
							glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	void Renderer::render(const Drawable& in) {
 | 
						void Renderer::render(Drawable* in) {
 | 
				
			||||||
		//TODO: Check identity
 | 
							if (in == nullptr)
 | 
				
			||||||
 | 
								Error("Drawable object tried to render before being constructed!");
 | 
				
			||||||
 | 
							if (in->identity() == Drawable::DrawableType::NF_UI)
 | 
				
			||||||
 | 
								m_lUI.push_back(in);
 | 
				
			||||||
 | 
							else
 | 
				
			||||||
 | 
								m_lGame.push_back(in);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	void Renderer::doFrame() {
 | 
						void Renderer::doFrame() {
 | 
				
			||||||
@ -63,7 +68,8 @@ namespace nf {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
		for (Drawable* draw : m_lGame) {
 | 
							for (Drawable* draw : m_lGame) {
 | 
				
			||||||
			Drawable& curr = *draw;
 | 
								Drawable& curr = *draw;
 | 
				
			||||||
 | 
								curr.bind();
 | 
				
			||||||
 | 
								glDrawElements(GL_TRIANGLES, curr.getIndexCount(), GL_UNSIGNED_INT, nullptr);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		for (Drawable* draw : m_lUI) {
 | 
							for (Drawable* draw : m_lUI) {
 | 
				
			||||||
 | 
				
			|||||||
@ -44,7 +44,10 @@ namespace nf {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	void Shader::bind() {
 | 
						void Shader::bind() {
 | 
				
			||||||
 | 
							if (m_id != Shader::current) {
 | 
				
			||||||
			glUseProgram(m_id);
 | 
								glUseProgram(m_id);
 | 
				
			||||||
 | 
								Shader::current = m_id;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	//TODO: Create overloaded setUniform function
 | 
						//TODO: Create overloaded setUniform function
 | 
				
			||||||
	void Shader::getUniformLocation(const char* uniformName) {
 | 
						void Shader::getUniformLocation(const char* uniformName) {
 | 
				
			||||||
@ -57,4 +60,6 @@ namespace nf {
 | 
				
			|||||||
	Shader::~Shader() {
 | 
						Shader::~Shader() {
 | 
				
			||||||
		glDeleteProgram(m_id);
 | 
							glDeleteProgram(m_id);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						unsigned int Shader::current;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@ -47,7 +47,7 @@ namespace nf {
 | 
				
			|||||||
		LPCWSTR m_wclassName;
 | 
							LPCWSTR m_wclassName;
 | 
				
			||||||
		HWND m_window;
 | 
							HWND m_window;
 | 
				
			||||||
		LONG m_defaultWindowStyle;
 | 
							LONG m_defaultWindowStyle;
 | 
				
			||||||
		WINDOWPLACEMENT m_wndPlacement;
 | 
							int m_altWidth, m_altHeight;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		std::chrono::duration<double> m_fpsDuration;
 | 
							std::chrono::duration<double> m_fpsDuration;
 | 
				
			||||||
		double m_deltaTime;
 | 
							double m_deltaTime;
 | 
				
			||||||
 | 
				
			|||||||
@ -1,20 +1,25 @@
 | 
				
			|||||||
#pragma once
 | 
					#pragma once
 | 
				
			||||||
#include "VertexArray.h"
 | 
					 | 
				
			||||||
#include "Shader.h"
 | 
					#include "Shader.h"
 | 
				
			||||||
 | 
					#include "VertexArray.h"
 | 
				
			||||||
#include "IndexBuffer.h"
 | 
					#include "IndexBuffer.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace nf {
 | 
					namespace nf {
 | 
				
			||||||
	class Drawable {
 | 
						class Drawable {
 | 
				
			||||||
		enum class DrawableType {
 | 
					 | 
				
			||||||
			NF_GAME, NF_UI
 | 
					 | 
				
			||||||
		};
 | 
					 | 
				
			||||||
	public:
 | 
						public:
 | 
				
			||||||
		Drawable();
 | 
							enum class DrawableType {
 | 
				
			||||||
 | 
								NF_NONE, NF_GAME, NF_UI
 | 
				
			||||||
 | 
							};
 | 
				
			||||||
 | 
							Drawable(const char* vertexShader, const char* fragmentShader, const void* vertexBuffer, const size_t vertexBufferSize, const void* indexBufferData, size_t indexBufferCount);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							unsigned int getIndexCount();
 | 
				
			||||||
 | 
							void bind();
 | 
				
			||||||
		virtual DrawableType identity();
 | 
							virtual DrawableType identity();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		~Drawable();
 | 
							~Drawable();
 | 
				
			||||||
	protected:
 | 
						protected:
 | 
				
			||||||
		//TODO: Add VAO, Shader, index buffer, etc.
 | 
							//TODO: Add VAO, Shader, index buffer, etc.
 | 
				
			||||||
 | 
							Shader m_shader;
 | 
				
			||||||
 | 
							VertexArray m_vao;
 | 
				
			||||||
 | 
							IndexBuffer m_ib;
 | 
				
			||||||
	};
 | 
						};
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@ -18,7 +18,6 @@ namespace nf {
 | 
				
			|||||||
		virtual void onExit();
 | 
							virtual void onExit();
 | 
				
			||||||
	protected:
 | 
						protected:
 | 
				
			||||||
		Application* m_app;
 | 
							Application* m_app;
 | 
				
			||||||
		Renderer* m_renderer;
 | 
					 | 
				
			||||||
		//Resource identifier?
 | 
							//Resource identifier?
 | 
				
			||||||
	};
 | 
						};
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@ -11,7 +11,7 @@ namespace nf {
 | 
				
			|||||||
	public:
 | 
						public:
 | 
				
			||||||
		Renderer(Application* app);
 | 
							Renderer(Application* app);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		void render(const Drawable& in);
 | 
							void render(Drawable* in);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		void doFrame();
 | 
							void doFrame();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -9,6 +9,8 @@ namespace nf {
 | 
				
			|||||||
		void bind();
 | 
							void bind();
 | 
				
			||||||
		void getUniformLocation(const char* uniformName);
 | 
							void getUniformLocation(const char* uniformName);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							static unsigned int current;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		~Shader();
 | 
							~Shader();
 | 
				
			||||||
	private:
 | 
						private:
 | 
				
			||||||
		unsigned int m_id;
 | 
							unsigned int m_id;
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user