From c2fb05cc61d7e0c5b06b0b0a1ef8c5c1daed666e Mon Sep 17 00:00:00 2001 From: Marianne Gagnon Date: Wed, 9 Apr 2014 18:55:17 -0400 Subject: [PATCH 01/21] Compute tangents for core track mesh, allowing normal maps --- src/tracks/track.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/tracks/track.cpp b/src/tracks/track.cpp index 3a107ca35..90469f1ed 100644 --- a/src/tracks/track.cpp +++ b/src/tracks/track.cpp @@ -839,17 +839,21 @@ bool Track::loadMainTrack(const XMLNode &root) merged_mesh->addMesh(mesh); merged_mesh->finalize(); - adjustForFog(merged_mesh, NULL); + scene::IMeshManipulator* manip = irr_driver->getVideoDriver()->getMeshManipulator(); + // TODO: memory leak? + scene::IMesh* tangent_mesh = manip->createMeshWithTangents(merged_mesh); + + adjustForFog(tangent_mesh, NULL); // The merged mesh is grabbed by the octtree, so we don't need // to keep a reference to it. - scene::ISceneNode *scene_node = irr_driver->addMesh(merged_mesh); + scene::ISceneNode *scene_node = irr_driver->addMesh(tangent_mesh); //scene::IMeshSceneNode *scene_node = irr_driver->addOctTree(merged_mesh); // We should drop the merged mesh (since it's now referred to in the // scene node), but then we need to grab it since it's in the // m_all_cached_meshes. - m_all_cached_meshes.push_back(merged_mesh); - irr_driver->grabAllTextures(merged_mesh); + m_all_cached_meshes.push_back(tangent_mesh); + irr_driver->grabAllTextures(tangent_mesh); // The reference count of the mesh is 1, since it is in irrlicht's // cache. So we only have to remove it from the cache. From b0c130017aba61cdd2fee7b169abb33ca08a1e4d Mon Sep 17 00:00:00 2001 From: Guillaume P Date: Thu, 10 Apr 2014 08:02:51 +0200 Subject: [PATCH 02/21] Disable notifications. --- .travis.yml | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/.travis.yml b/.travis.yml index 6a0b46f4b..bf9f43ca0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -21,15 +21,15 @@ script: - cd build - cmake .. -DCMAKE_BUILD_TYPE=Debug - make VERBOSE=1 -j 4 -notifications: - irc: - channels: - - "irc.freenode.org#stk" - skip_join: false - use_notice: true - template: - #- "[%{commit}: %{author}] %{message}" - #- "%{build_url}" - - "[%{repository}#%{branch} @%{commit}] %{author}): %{message}" - - "Diff: %{compare_url}" - - "Build: %{build_url}" +# notifications: + # irc: + # channels: + # - "irc.freenode.org#stk" + # skip_join: false + # use_notice: true + # template: + # #- "[%{commit}: %{author}] %{message}" + # #- "%{build_url}" + # - "[%{repository}#%{branch} @%{commit}] %{author}): %{message}" + # - "Diff: %{compare_url}" + # - "Build: %{build_url}" From 8f0ecee80cd0076d5610460fb2b9f03ab6ccfe1a Mon Sep 17 00:00:00 2001 From: Guillaume P Date: Thu, 10 Apr 2014 08:15:29 +0200 Subject: [PATCH 03/21] Update before_install section in travis config file. --- .travis.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.travis.yml b/.travis.yml index bf9f43ca0..075503c0a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,6 +15,9 @@ before_install: - sudo apt-get update -qq # INSTALL DEPENDENCIES - sudo apt-get install build-essential cmake libogg-dev libvorbis-dev libopenal-dev libxxf86vm-dev libgl1-mesa-dev libglu1-mesa-dev libcurl4-openssl-dev libfribidi-dev libbluetooth-dev + - sudo apt-add-repository "deb http://archive.ubuntu.com/ubuntu quantal main restricted" + - sudo apt-get update -qq + - sudo apt-get install libgl1-mesa-dev libglu1-mesa-dev script: # BUILD COMMANDS - mkdir build From 0542a852044a2c0e39d66c8e121501a2135c8e8d Mon Sep 17 00:00:00 2001 From: Guillaume P Date: Thu, 10 Apr 2014 08:41:02 +0200 Subject: [PATCH 04/21] Clean up and re-enable notifications in travis config. --- .travis.yml | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/.travis.yml b/.travis.yml index 075503c0a..3f59953b2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,28 +11,29 @@ compiler: # only: # - master before_install: - # UPDATE REPOS + # Update repos - sudo apt-get update -qq - # INSTALL DEPENDENCIES - - sudo apt-get install build-essential cmake libogg-dev libvorbis-dev libopenal-dev libxxf86vm-dev libgl1-mesa-dev libglu1-mesa-dev libcurl4-openssl-dev libfribidi-dev libbluetooth-dev + # Install dependencies + - sudo apt-get install build-essential cmake libogg-dev libvorbis-dev libopenal-dev libxxf86vm-dev libcurl4-openssl-dev libfribidi-dev libbluetooth-dev + # Install mesa from an other repo (a newer version is required) - sudo apt-add-repository "deb http://archive.ubuntu.com/ubuntu quantal main restricted" - sudo apt-get update -qq - sudo apt-get install libgl1-mesa-dev libglu1-mesa-dev script: - # BUILD COMMANDS + # Build commands - mkdir build - cd build - cmake .. -DCMAKE_BUILD_TYPE=Debug - make VERBOSE=1 -j 4 -# notifications: - # irc: - # channels: - # - "irc.freenode.org#stk" - # skip_join: false - # use_notice: true - # template: - # #- "[%{commit}: %{author}] %{message}" - # #- "%{build_url}" - # - "[%{repository}#%{branch} @%{commit}] %{author}): %{message}" - # - "Diff: %{compare_url}" - # - "Build: %{build_url}" +notifications: + irc: + channels: + - "irc.freenode.org#stk" + skip_join: false + use_notice: true + template: + #- "[%{commit}: %{author}] %{message}" + #- "%{build_url}" + - "[%{repository}#%{branch} @%{commit}] %{author}): %{message}" + - "Diff: %{compare_url}" + - "Build: %{build_url}" From 5dbd228b95f7d6ae5f8789d1c4ffd9d1944d4a2c Mon Sep 17 00:00:00 2001 From: Guillaume P Date: Thu, 10 Apr 2014 08:50:45 +0200 Subject: [PATCH 05/21] It's even better with the key of the added repository. --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 3f59953b2..aa3607483 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,6 +17,7 @@ before_install: - sudo apt-get install build-essential cmake libogg-dev libvorbis-dev libopenal-dev libxxf86vm-dev libcurl4-openssl-dev libfribidi-dev libbluetooth-dev # Install mesa from an other repo (a newer version is required) - sudo apt-add-repository "deb http://archive.ubuntu.com/ubuntu quantal main restricted" + - sudo apt-key adv --recv-keys --keyserver keyserver.ubuntu.com 3B4FE6ACC0B21F32 - sudo apt-get update -qq - sudo apt-get install libgl1-mesa-dev libglu1-mesa-dev script: From 1299db94e6986933187a4c8b10ffc74e16f9c43f Mon Sep 17 00:00:00 2001 From: hiker Date: Mon, 7 Apr 2014 16:52:09 +1000 Subject: [PATCH 06/21] Cosmetic changes only. --- .../dialogs/player_info_dialog.cpp | 54 ++++++++++++------- .../dialogs/player_info_dialog.hpp | 3 -- 2 files changed, 34 insertions(+), 23 deletions(-) diff --git a/src/states_screens/dialogs/player_info_dialog.cpp b/src/states_screens/dialogs/player_info_dialog.cpp index 5e0718e8c..80d4dc873 100644 --- a/src/states_screens/dialogs/player_info_dialog.cpp +++ b/src/states_screens/dialogs/player_info_dialog.cpp @@ -39,29 +39,38 @@ using namespace irr::gui; using namespace irr::core; // ----------------------------------------------------------------------------- - -PlayerInfoDialog::PlayerInfoDialog(PlayerProfile* player, const float w, const float h) : ModalDialog(w, h) +/** Creates a modal dialog with given percentage of screen width and height. + */ +PlayerInfoDialog::PlayerInfoDialog(PlayerProfile* player, const float w, + const float h) + : ModalDialog(w, h) { m_player = player; doInit(); showRegularDialog(); -} +} // PlayerInfoDialog // ----------------------------------------------------------------------------- - +/** When the dialog is finished, select the just edited player again in the + * option screen. + */ PlayerInfoDialog::~PlayerInfoDialog() { if (m_player != NULL) { - OptionsScreenPlayers::getInstance()->selectPlayer( translations->fribidize(m_player->getName()) ); + OptionsScreenPlayers::getInstance()->selectPlayer( + translations->fribidize(m_player->getName()) ); } -} +} // ~PlayerInfoDialog // ----------------------------------------------------------------------------- +/** Show the current data of this player. + */ void PlayerInfoDialog::showRegularDialog() { - clearWindow(); + if (m_irrlicht_window) + clearWindow(); const int y1 = m_area.getHeight()/6; const int y2 = m_area.getHeight()*2/6; @@ -92,7 +101,8 @@ void PlayerInfoDialog::showRegularDialog() //I18N: In the player info dialog widget->setText( _("Rename") ); - const int textWidth = font->getDimension( widget->getText().c_str() ).Width + 40; + const int textWidth = + font->getDimension( widget->getText().c_str() ).Width + 40; widget->m_x = m_area.getWidth()/2 - textWidth/2; widget->m_y = y2; @@ -139,10 +149,11 @@ void PlayerInfoDialog::showRegularDialog() } textCtrl->setFocusForPlayer( PLAYER_ID_GAME_MASTER ); -} +} // showRegularDialog // ----------------------------------------------------------------------------- - +/** Changes this dialog to confirm the changes. + */ void PlayerInfoDialog::showConfirmDialog() { clearWindow(); @@ -158,7 +169,8 @@ void PlayerInfoDialog::showConfirmDialog() if (PlayerManager::get()->getCurrentPlayer() == m_player) { - message = _("You cannot delete this player because it is currently in use."); + message = _("You cannot delete this player " + "because it is currently in use."); } core::rect< s32 > area_left(5, 0, m_area.getWidth()-5, m_area.getHeight()/2); @@ -167,7 +179,8 @@ void PlayerInfoDialog::showConfirmDialog() // we can add irrlicht labels directly // (more complicated uses require the use of our widget set) IGUIStaticText* a = GUIEngine::getGUIEnv()->addStaticText( message.c_str(), - area_left, false /* border */, true /* word wrap */, + area_left, false /* border */, + true /* word wrap */, m_irrlicht_window); a->setTextAlignment(EGUIA_CENTER, EGUIA_CENTER); @@ -212,22 +225,23 @@ void PlayerInfoDialog::showConfirmDialog() widget->setFocusForPlayer( PLAYER_ID_GAME_MASTER ); } -} +} // showConfirmDialog // ----------------------------------------------------------------------------- void PlayerInfoDialog::onEnterPressedInternal() { -} +} // onEnterPressedInternal // ----------------------------------------------------------------------------- -GUIEngine::EventPropagation PlayerInfoDialog::processEvent(const std::string& eventSource) +GUIEngine::EventPropagation + PlayerInfoDialog::processEvent(const std::string& eventSource) { if (eventSource == "renameplayer") { // accept entered name - stringw playerName = textCtrl->getText().trim(); + stringw player_name = textCtrl->getText().trim(); const int player_amount = PlayerManager::get()->getNumPlayers(); for(int n=0; ngetPlayer(n); if (player == m_player) continue; - if (player->getName() == playerName) + if (player->getName() == player_name) { ButtonWidget* label = getWidget("renameplayer"); label->setBadge(BAD_BADGE); @@ -244,9 +258,9 @@ GUIEngine::EventPropagation PlayerInfoDialog::processEvent(const std::string& ev } } - if (playerName.size() <= 0) return GUIEngine::EVENT_BLOCK; + if (player_name.size() <= 0) return GUIEngine::EVENT_BLOCK; - OptionsScreenPlayers::getInstance()->renamePlayer( playerName, m_player ); + OptionsScreenPlayers::getInstance()->renamePlayer(player_name,m_player); // irrLicht is too stupid to remove focus from deleted widgets // so do it by hand @@ -292,7 +306,7 @@ GUIEngine::EventPropagation PlayerInfoDialog::processEvent(const std::string& ev return GUIEngine::EVENT_BLOCK; } return GUIEngine::EVENT_LET; -} +} // processEvent // ----------------------------------------------------------------------------- diff --git a/src/states_screens/dialogs/player_info_dialog.hpp b/src/states_screens/dialogs/player_info_dialog.hpp index 63c7077c2..39441d69c 100644 --- a/src/states_screens/dialogs/player_info_dialog.hpp +++ b/src/states_screens/dialogs/player_info_dialog.hpp @@ -40,9 +40,6 @@ class PlayerInfoDialog : public GUIEngine::ModalDialog void showRegularDialog(); void showConfirmDialog(); public: - /** - * Creates a modal dialog with given percentage of screen width and height - */ PlayerInfoDialog(PlayerProfile* PlayerInfoDialog, const float percentWidth, const float percentHeight); From 1d71f8f1e14a7b7fb501d660a4b707ce53ba9ed1 Mon Sep 17 00:00:00 2001 From: hiker Date: Mon, 7 Apr 2014 21:15:42 +1000 Subject: [PATCH 07/21] Moved ServerJoinRequest from CurrentUser into RequestConnection (from which file it is also used in online_screen). And cosmetic changes everywhere. --- src/network/protocols/request_connection.cpp | 56 ++++++--- src/network/protocols/request_connection.hpp | 61 +++++---- src/online/current_user.cpp | 29 ----- src/online/current_user.hpp | 9 -- .../dialogs/server_info_dialog.cpp | 13 +- .../dialogs/server_info_dialog.hpp | 5 +- src/states_screens/online_screen.cpp | 118 ++++++++++-------- src/states_screens/online_screen.hpp | 3 +- 8 files changed, 159 insertions(+), 135 deletions(-) diff --git a/src/network/protocols/request_connection.cpp b/src/network/protocols/request_connection.cpp index e412f711a..ff950c3d3 100644 --- a/src/network/protocols/request_connection.cpp +++ b/src/network/protocols/request_connection.cpp @@ -19,38 +19,63 @@ #include "network/protocols/request_connection.hpp" #include "network/protocol_manager.hpp" -#include "online/request_manager.hpp" +#include "online/servers_manager.hpp" #include "online/current_user.hpp" #include "config/user_config.hpp" -RequestConnection::RequestConnection(uint32_t server_id) : Protocol(NULL, PROTOCOL_SILENT) +using namespace Online; + +/** Constructor. Stores the server id. + * \param server_id Id of the server. + */ +RequestConnection::RequestConnection(uint32_t server_id) + : Protocol(NULL, PROTOCOL_SILENT) { m_server_id = server_id; -} +} // RequestConnection +// ---------------------------------------------------------------------------- RequestConnection::~RequestConnection() { -} +} // ~RequestConnection +// ---------------------------------------------------------------------------- +/** Setup of this request, sets state to none. + */ void RequestConnection::setup() { m_state = NONE; -} +} // setup +// ---------------------------------------------------------------------------- +/** The callback for the server join request. It informs the server manager + * of a successful join request. + */ +void RequestConnection::ServerJoinRequest::callback() +{ + if (isSuccess()) + { + uint32_t server_id; + getXMLData()->get("serverid", &server_id); + ServersManager::get()->setJoinedServer(server_id); + } +} // ServerJoinRequest::callback + +// ---------------------------------------------------------------------------- +/** This implements a finite state machine to monitor the server join + * request asynchronously. + */ void RequestConnection::asynchronousUpdate() { switch (m_state) { case NONE: { - m_request = new Online::CurrentUser::ServerJoinRequest(); + m_request = new ServerJoinRequest(); + CurrentUser::setUserDetails(m_request, "request-connection"); m_request->setServerURL("address-management.php"); - m_request->addParameter("id",Online::CurrentUser::get()->getID()); - m_request->addParameter("token",Online::CurrentUser::get()->getToken()); m_request->addParameter("server_id",m_server_id); - m_request->addParameter("action","request-connection"); - - Online::RequestManager::get()->addRequest(m_request); + m_request->queue(); m_state = REQUEST_PENDING; break; } @@ -65,11 +90,14 @@ void RequestConnection::asynchronousUpdate() { if (rec_success == "yes") { - Log::debug("RequestConnection", "Connection Request made successfully."); + Log::debug("RequestConnection", + "Connection Request made successfully."); } else { - Log::error("RequestConnection", "Fail to make a request to connecto to server %d", m_server_id); + Log::error("RequestConnection", + "Fail to make a request to connecto to server %d", + m_server_id); } } else @@ -89,5 +117,5 @@ void RequestConnection::asynchronousUpdate() case EXITING: break; } -} +} // asynchronousUpdate diff --git a/src/network/protocols/request_connection.hpp b/src/network/protocols/request_connection.hpp index 2bffccdd3..9a2ddacaf 100644 --- a/src/network/protocols/request_connection.hpp +++ b/src/network/protocols/request_connection.hpp @@ -1,33 +1,52 @@ -#ifndef REQUEST_CONNECTION_HPP -#define REQUEST_CONNECTION_HPP +#ifndef HEADER_REQUEST_CONNECTION_HPP +#define HEADER_REQUEST_CONNECTION_HPP #include "network/protocol.hpp" #include "online/current_user.hpp" +#include "online/xml_request.hpp" class RequestConnection : public Protocol { +protected: + /** Id of the server to join. */ + uint32_t m_server_id; + + /** The request to join a server. */ + Online::XMLRequest *m_request; + enum STATE + { + NONE, + REQUEST_PENDING, + DONE, + EXITING + }; + + /** State of this connection. */ + STATE m_state; + +public: + // -------------------------------------------------------------------- + /** A simple request class to ask to join a server. + */ + class ServerJoinRequest : public Online::XMLRequest + { + virtual void callback(); public: - RequestConnection(uint32_t server_id); - virtual ~RequestConnection(); + ServerJoinRequest() : Online::XMLRequest() {} + }; // ServerJoinRequest + // -------------------------------------------------------------------- - virtual bool notifyEvent(Event* event) { return true; } - virtual bool notifyEventAsynchronous(Event* event) { return true; } - virtual void setup(); - virtual void update() {} - virtual void asynchronousUpdate(); - protected: - uint32_t m_server_id; - Online::CurrentUser::ServerJoinRequest* m_request; - enum STATE - { - NONE, - REQUEST_PENDING, - DONE, - EXITING - }; - STATE m_state; + RequestConnection(uint32_t server_id); + virtual ~RequestConnection(); -}; + virtual bool notifyEvent(Event* event) { return true; } + virtual bool notifyEventAsynchronous(Event* event) { return true; } + virtual void setup(); + virtual void update() {} + virtual void asynchronousUpdate(); + + +}; // RequestConnection #endif // REQUEST_CONNECTION_HPP diff --git a/src/online/current_user.cpp b/src/online/current_user.cpp index b50d2b39a..5ab0a254c 100644 --- a/src/online/current_user.cpp +++ b/src/online/current_user.cpp @@ -236,35 +236,6 @@ namespace Online UserConfigParams::m_saved_session = false; } // signOut - // ------------------------------------------------------------------------ - CurrentUser::ServerJoinRequest* - CurrentUser::requestServerJoin(uint32_t server_id, - bool request_now) - { - assert(m_state == US_SIGNED_IN || m_state == US_GUEST); - ServerJoinRequest * request = new ServerJoinRequest(); - request->setServerURL("address-management.php"); - request->addParameter("action","request-connection"); - request->addParameter("token", getToken()); - request->addParameter("id", getID()); - request->addParameter("server_id", server_id); - if (request_now) - request->queue(); - return request; - } // requestServerJoin - - // ------------------------------------------------------------------------ - void CurrentUser::ServerJoinRequest::callback() - { - if(isSuccess()) - { - uint32_t server_id; - getXMLData()->get("serverid", &server_id); - ServersManager::get()->setJoinedServer(server_id); - } - //FIXME needs changes for actual valid joining - } // ServerJoinRequest::callback - // ------------------------------------------------------------------------ /** Sends a request to the server to see if any new information is * available. (online friends, notifications, etc.). diff --git a/src/online/current_user.hpp b/src/online/current_user.hpp index 948b3440d..49767ed9c 100644 --- a/src/online/current_user.hpp +++ b/src/online/current_user.hpp @@ -72,14 +72,6 @@ namespace Online SignOutRequest() : XMLRequest(true,/*priority*/10) {} }; // SignOutRequest - // ---------------------------------------------------------------- - - class ServerJoinRequest : public XMLRequest { - virtual void callback (); - public: - ServerJoinRequest() : XMLRequest() {} - }; // ServerJoinRequest - // ---------------------------------------------------------------- class PollRequest : public XMLRequest { virtual void callback (); @@ -113,7 +105,6 @@ namespace Online bool save_session, bool request_now = true); void requestSignOut(); - ServerJoinRequest * requestServerJoin(uint32_t server_id, bool request_now = true); void requestFriendRequest(const uint32_t friend_id) const; void onSTKQuit() const; diff --git a/src/states_screens/dialogs/server_info_dialog.cpp b/src/states_screens/dialogs/server_info_dialog.cpp index 3cc42f6c9..1b3fda36c 100644 --- a/src/states_screens/dialogs/server_info_dialog.cpp +++ b/src/states_screens/dialogs/server_info_dialog.cpp @@ -17,22 +17,20 @@ #include "states_screens/dialogs/server_info_dialog.hpp" -#include - #include "audio/sfx_manager.hpp" #include "guiengine/engine.hpp" -#include "states_screens/state_manager.hpp" -#include "utils/translation.hpp" -#include "utils/string_utils.hpp" #include "network/protocol_manager.hpp" #include "network/protocols/connect_to_server.hpp" #include "online/current_user.hpp" -#include "online/servers_manager.hpp" #include "online/messages.hpp" +#include "online/servers_manager.hpp" #include "states_screens/dialogs/registration_dialog.hpp" #include "states_screens/networking_lobby.hpp" +#include "states_screens/state_manager.hpp" +#include "utils/string_utils.hpp" +#include "utils/translation.hpp" - +#include using namespace GUIEngine; using namespace irr; @@ -80,6 +78,7 @@ ServerInfoDialog::~ServerInfoDialog() // ----------------------------------------------------------------------------- void ServerInfoDialog::requestJoin() { + // FIXME - without this next line, it appears that m_server_join is completely unused. //m_server_join_request = Online::CurrentUser::get()->requestServerJoin(m_server_id); Online::ServersManager::get()->setJoinedServer(m_server_id); ProtocolManager::getInstance()->requestStart(new ConnectToServer(m_server_id, m_host_id)); diff --git a/src/states_screens/dialogs/server_info_dialog.hpp b/src/states_screens/dialogs/server_info_dialog.hpp index 1c040bb78..dfa2d7d27 100644 --- a/src/states_screens/dialogs/server_info_dialog.hpp +++ b/src/states_screens/dialogs/server_info_dialog.hpp @@ -25,8 +25,9 @@ #include "guiengine/widgets/icon_button_widget.hpp" #include "guiengine/widgets/ribbon_widget.hpp" #include "guiengine/widgets/label_widget.hpp" -#include "online/server.hpp" +#include "network/protocols/request_connection.hpp" #include "online/current_user.hpp" +#include "online/server.hpp" #include "utils/types.hpp" @@ -42,7 +43,7 @@ private: bool m_self_destroy; bool m_enter_lobby; bool m_from_server_creation; - const Online::CurrentUser::ServerJoinRequest * m_server_join_request; + const RequestConnection::ServerJoinRequest * m_server_join_request; const uint32_t m_server_id; uint32_t m_host_id; diff --git a/src/states_screens/online_screen.cpp b/src/states_screens/online_screen.cpp index af9f24577..418c2faab 100644 --- a/src/states_screens/online_screen.cpp +++ b/src/states_screens/online_screen.cpp @@ -29,24 +29,21 @@ #include "input/input_manager.hpp" #include "io/file_manager.hpp" #include "main_loop.hpp" +#include "modes/demo_world.hpp" +#include "network/protocol_manager.hpp" +#include "network/protocol_manager.hpp" +#include "network/protocols/connect_to_server.hpp" +#include "network/protocols/request_connection.hpp" +#include "online/messages.hpp" +#include "online/profile_manager.hpp" +#include "online/request.hpp" +#include "online/servers_manager.hpp" #include "states_screens/state_manager.hpp" #include "states_screens/dialogs/message_dialog.hpp" #include "states_screens/networking_lobby.hpp" #include "states_screens/server_selection.hpp" #include "states_screens/create_server_screen.hpp" #include "states_screens/online_profile_overview.hpp" -#include "online/servers_manager.hpp" -#include "online/messages.hpp" -#include "online/profile_manager.hpp" -#include "online/request.hpp" -#include "modes/demo_world.hpp" - -#include "network/protocol_manager.hpp" -#include "network/protocols/connect_to_server.hpp" - -#include "network/protocol_manager.hpp" -#include "network/protocols/connect_to_server.hpp" - using namespace GUIEngine; using namespace Online; @@ -95,6 +92,8 @@ void OnlineScreen::loadedFromFile() } // loadedFromFile // ---------------------------------------------------------------------------- +/** Checks if the recorded state differs from the actual state and sets it. + */ bool OnlineScreen::hasStateChanged() { CurrentUser::UserState previous_state = m_recorded_state; @@ -102,7 +101,7 @@ bool OnlineScreen::hasStateChanged() if (previous_state != m_recorded_state) return true; return false; -} +} // hasStateChanged // ---------------------------------------------------------------------------- void OnlineScreen::beforeAddingWidget() @@ -130,8 +129,6 @@ void OnlineScreen::beforeAddingWidget() } // beforeAddingWidget - - // ---------------------------------------------------------------------------- void OnlineScreen::init() { @@ -139,6 +136,8 @@ void OnlineScreen::init() setInitialFocus(); DemoWorld::resetIdleTime(); m_online_status_widget->setText(Messages::signedInAs(CurrentUser::get()->getUserName()), false); + core::stringw m = _("Signed in as: %s.", CurrentUser::get()->getUserName()); + //m_online_status_widget->setText(-_("Signed in as: %s.", CurrentUser::get()->getUserName().c_str()), false); } // init // ---------------------------------------------------------------------------- @@ -161,8 +160,57 @@ void OnlineScreen::onUpdate(float delta) } // onUpdate // ---------------------------------------------------------------------------- +/** Executes the quick play selection. Atm this is all blocking. + */ +void OnlineScreen::doQuickPlay() +{ + // Refresh server list. + HTTPRequest* request = ServersManager::get()->refreshRequest(false); + if (request != NULL) // consider request done + { + request->executeNow(); + delete request; + } + else + { + Log::error("OnlineScreen", "Could not get the server list."); + return; + } + // select first one + const Server * server = ServersManager::get()->getQuickPlay(); -void OnlineScreen::eventCallback(Widget* widget, const std::string& name, const int playerID) + + XMLRequest *request2 = new RequestConnection::ServerJoinRequest(); + if (!request2) + { + sfx_manager->quickSound("anvil"); + return; + } + + CurrentUser::setUserDetails(request2, "request-connection"); + request2->setServerURL("address-management.php"); + request2->addParameter("server_id", server->getServerId()); + + request2->executeNow(); + if (request2->isSuccess()) + { + delete request2; + StateManager::get()->pushScreen(NetworkingLobby::getInstance()); + ConnectToServer *cts = new ConnectToServer(server->getServerId(), + server->getHostId()); + ProtocolManager::getInstance()->requestStart(cts); + } + else + { + sfx_manager->quickSound("anvil"); + } + +} // doQuickPlay + +// ---------------------------------------------------------------------------- + +void OnlineScreen::eventCallback(Widget* widget, const std::string& name, + const int playerID) { if (name == m_back_widget->m_properties[PROP_ID]) { @@ -194,41 +242,7 @@ void OnlineScreen::eventCallback(Widget* widget, const std::string& name, const } else if (selection == m_quick_play_widget->m_properties[PROP_ID]) { - //FIXME temporary and the request join + join sequence should be placed in one method somewhere - // refresh server list - Online::ServersManager::RefreshRequest* request = ServersManager::get()->refreshRequest(false); - if (request != NULL) // consider request done - { - request->executeNow(); - delete request; - } - else - { - Log::error("OnlineScreen", "Could not get the server list."); - return; - } - // select first one - const Server * server = ServersManager::get()->getQuickPlay(); - - Online::CurrentUser::ServerJoinRequest* request2 = Online::CurrentUser::get()->requestServerJoin( server->getServerId(), false); - if (request2) - { - request2->executeNow(); - if (request2->isSuccess()) - { - delete request2; - StateManager::get()->pushScreen(NetworkingLobby::getInstance()); - ProtocolManager::getInstance()->requestStart(new ConnectToServer(server->getServerId(), server->getHostId())); - } - else - { - sfx_manager->quickSound( "anvil" ); - } - } - else - { - sfx_manager->quickSound( "anvil" ); - } + doQuickPlay(); } } // eventCallback @@ -239,6 +253,8 @@ void OnlineScreen::tearDown() } // ---------------------------------------------------------------------------- +/** Sets which widget has to be focused. Depends on the user state. + */ void OnlineScreen::setInitialFocus() { if(m_recorded_state == CurrentUser::US_SIGNED_IN) diff --git a/src/states_screens/online_screen.hpp b/src/states_screens/online_screen.hpp index 55395fed2..6e52d5a96 100644 --- a/src/states_screens/online_screen.hpp +++ b/src/states_screens/online_screen.hpp @@ -56,11 +56,10 @@ private: Online::CurrentUser::UserState m_recorded_state; - /** \brief Checks if the recorded state differs from the actual state and sets it. */ bool hasStateChanged(); - /** \brief Sets which widget has to be focused. Depends on the user state. */ void setInitialFocus(); + void doQuickPlay(); public: virtual void onUpdate(float delta) OVERRIDE; From 79edc5fa4892faa4823792ee5c54f82be85ae552 Mon Sep 17 00:00:00 2001 From: hiker Date: Tue, 8 Apr 2014 08:06:52 +1000 Subject: [PATCH 08/21] Made getCurrentUser() a static function. --- src/challenges/unlock_manager.cpp | 4 ++-- src/config/player_manager.hpp | 7 +++++-- src/items/powerup.cpp | 2 +- src/karts/kart.cpp | 2 +- src/karts/kart_properties_manager.cpp | 4 ++-- src/karts/skidding.cpp | 2 +- src/main.cpp | 4 ++-- src/modes/cutscene_world.cpp | 2 +- src/modes/linear_world.cpp | 2 +- src/modes/overworld.cpp | 2 +- src/modes/world.cpp | 8 ++++---- src/network/protocols/start_game_protocol.cpp | 2 +- src/physics/physics.cpp | 2 +- src/race/grand_prix_data.cpp | 2 +- src/race/race_manager.cpp | 2 +- src/states_screens/arenas_screen.cpp | 4 ++-- src/states_screens/dialogs/gp_info_dialog.cpp | 2 +- src/states_screens/dialogs/player_info_dialog.cpp | 4 ++-- src/states_screens/dialogs/select_challenge.cpp | 4 ++-- src/states_screens/dialogs/track_info_dialog.cpp | 2 +- src/states_screens/easter_egg_screen.cpp | 4 ++-- src/states_screens/feature_unlocked.cpp | 4 ++-- src/states_screens/grand_prix_lose.cpp | 4 ++-- src/states_screens/grand_prix_win.cpp | 10 +++++----- src/states_screens/help_screen_1.cpp | 2 +- src/states_screens/kart_selection.cpp | 6 +++--- src/states_screens/main_menu_screen.cpp | 4 ++-- src/states_screens/online_profile_achievements.cpp | 2 +- src/states_screens/options_screen_players.cpp | 2 +- src/states_screens/race_gui_overworld.cpp | 4 ++-- src/states_screens/race_result_gui.cpp | 8 ++++---- src/states_screens/race_setup_screen.cpp | 8 ++++---- src/states_screens/story_mode_lobby.cpp | 2 +- src/states_screens/tracks_screen.cpp | 6 +++--- src/tracks/track.cpp | 4 ++-- 35 files changed, 68 insertions(+), 65 deletions(-) diff --git a/src/challenges/unlock_manager.cpp b/src/challenges/unlock_manager.cpp index 53755122b..af976212f 100644 --- a/src/challenges/unlock_manager.cpp +++ b/src/challenges/unlock_manager.cpp @@ -247,12 +247,12 @@ void UnlockManager::findWhatWasUnlocked(int points_before, int points_now, { if (c->getMode() == ChallengeData::CM_SINGLE_RACE && c->getTrackId() != "") { - if (!PlayerManager::get()->getCurrentPlayer()->isLocked(c->getTrackId())) + if (!PlayerManager::getCurrentPlayer()->isLocked(c->getTrackId())) tracks.push_back(c->getTrackId()); } else if (c->getMode() == ChallengeData::CM_GRAND_PRIX && c->getGPId() != "") { - if (!PlayerManager::get()->getCurrentPlayer()->isLocked(c->getGPId())) + if (!PlayerManager::getCurrentPlayer()->isLocked(c->getGPId())) gps.push_back(c->getGPId()); } } diff --git a/src/config/player_manager.hpp b/src/config/player_manager.hpp index b167c70b5..650496a7e 100644 --- a/src/config/player_manager.hpp +++ b/src/config/player_manager.hpp @@ -81,7 +81,10 @@ public: void enforceCurrentPlayer(); // ------------------------------------------------------------------------ /** Returns the current player. */ - PlayerProfile* getCurrentPlayer() { return m_current_player; } + static PlayerProfile* getCurrentPlayer() + { + return get()->m_current_player; + } // getCurrentPlayer // ------------------------------------------------------------------------ PlayerProfile *getPlayer(const irr::core::stringw &name); // ------------------------------------------------------------------------ @@ -100,7 +103,7 @@ public: /** A handy shortcut funtion. */ static AchievementsStatus* getCurrentAchievementsStatus() { - return get()->getCurrentPlayer()->getAchievementsStatus(); + return PlayerManager::getCurrentPlayer()->getAchievementsStatus(); } // getCurrentAchievementsStatus // ------------------------------------------------------------------------ /** A handy shortcut to increase points for an achievement key of the diff --git a/src/items/powerup.cpp b/src/items/powerup.cpp index 201047dcd..e355d5c90 100644 --- a/src/items/powerup.cpp +++ b/src/items/powerup.cpp @@ -176,7 +176,7 @@ void Powerup::use() // The player gets an achievement point for using a powerup StateManager::ActivePlayer * player = m_owner->getController()->getPlayer(); if (m_type != PowerupManager::POWERUP_NOTHING && - player != NULL && player->getConstProfile() == PlayerManager::get()->getCurrentPlayer()) + player != NULL && player->getConstProfile() == PlayerManager::getCurrentPlayer()) { PlayerManager::increaseAchievement(AchievementInfo::ACHIEVE_POWERUP_LOVER, "poweruplover"); } diff --git a/src/karts/kart.cpp b/src/karts/kart.cpp index d69dc6c31..3a740766f 100644 --- a/src/karts/kart.cpp +++ b/src/karts/kart.cpp @@ -806,7 +806,7 @@ void Kart::finishedRace(float time) m_controller)); if (m_controller->isPlayerController()) // if player is on this computer { - PlayerProfile *player = PlayerManager::get()->getCurrentPlayer(); + PlayerProfile *player = PlayerManager::getCurrentPlayer(); const ChallengeStatus *challenge = player->getCurrentChallengeStatus(); // In case of a GP challenge don't make the end animation depend // on if the challenge is fulfilled diff --git a/src/karts/kart_properties_manager.cpp b/src/karts/kart_properties_manager.cpp index e573d9504..afc327a54 100644 --- a/src/karts/kart_properties_manager.cpp +++ b/src/karts/kart_properties_manager.cpp @@ -355,7 +355,7 @@ bool KartPropertiesManager::kartAvailable(int kartid) if ( kartid == *it) return false; } const KartProperties *kartprop = getKartById(kartid); - if( PlayerManager::get()->getCurrentPlayer()->isLocked(kartprop->getIdent()) ) + if( PlayerManager::getCurrentPlayer()->isLocked(kartprop->getIdent()) ) return false; return true; } // kartAvailable @@ -464,7 +464,7 @@ void KartPropertiesManager::getRandomKartList(int count, const KartProperties &kp=m_karts_properties[karts_in_group[i]]; if (!used[karts_in_group[i]] && m_kart_available[karts_in_group[i]] && - !PlayerManager::get()->getCurrentPlayer()->isLocked(kp.getIdent()) ) + !PlayerManager::getCurrentPlayer()->isLocked(kp.getIdent()) ) { random_kart_queue.push_back(kp.getIdent()); } diff --git a/src/karts/skidding.cpp b/src/karts/skidding.cpp index 822d87a50..ca2ac30b7 100644 --- a/src/karts/skidding.cpp +++ b/src/karts/skidding.cpp @@ -416,7 +416,7 @@ void Skidding::update(float dt, bool is_on_ground, /*fade-out-time*/ 1.0f); StateManager::ActivePlayer *c = m_kart->getController()->getPlayer(); - if (c && c->getConstProfile() == PlayerManager::get()->getCurrentPlayer()) + if (c && c->getConstProfile() == PlayerManager::getCurrentPlayer()) { PlayerManager::increaseAchievement(AchievementInfo::ACHIEVE_SKIDDING, "skidding"); } diff --git a/src/main.cpp b/src/main.cpp index 7d21b5e2e..ea6506053 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -694,7 +694,7 @@ int handleCmdLine() if(CommandLine::has("--kart", &s)) { - const PlayerProfile *player = PlayerManager::get()->getCurrentPlayer(); + const PlayerProfile *player = PlayerManager::getCurrentPlayer(); if(player && !player->isLocked(s)) { @@ -766,7 +766,7 @@ int handleCmdLine() if(CommandLine::has("--track", &s) || CommandLine::has("-t", &s)) { - const PlayerProfile *player = PlayerManager::get()->getCurrentPlayer(); + const PlayerProfile *player = PlayerManager::getCurrentPlayer(); if (player && !player->isLocked(s)) { race_manager->setTrack(s); diff --git a/src/modes/cutscene_world.cpp b/src/modes/cutscene_world.cpp index b95ed070b..53aa97d5d 100644 --- a/src/modes/cutscene_world.cpp +++ b/src/modes/cutscene_world.cpp @@ -380,7 +380,7 @@ void CutsceneWorld::enterRaceOverState() else if (race_manager->getTrackName() == "introcutscene" || race_manager->getTrackName() == "introcutscene2") { - PlayerProfile *player = PlayerManager::get()->getCurrentPlayer(); + PlayerProfile *player = PlayerManager::getCurrentPlayer(); if (player->isFirstTime()) { race_manager->exitRace(); diff --git a/src/modes/linear_world.cpp b/src/modes/linear_world.cpp index 2ea03bf05..a7df70add 100644 --- a/src/modes/linear_world.cpp +++ b/src/modes/linear_world.cpp @@ -240,7 +240,7 @@ void LinearWorld::newLap(unsigned int kart_index) // Reset reset-after-lap achievements StateManager::ActivePlayer *c = kart->getController()->getPlayer(); - PlayerProfile *p = PlayerManager::get()->getCurrentPlayer(); + PlayerProfile *p = PlayerManager::getCurrentPlayer(); if (c && c->getConstProfile() == p) { p->getAchievementsStatus()->onLapEnd(); diff --git a/src/modes/overworld.cpp b/src/modes/overworld.cpp index 926410bc7..ec9e565c6 100644 --- a/src/modes/overworld.cpp +++ b/src/modes/overworld.cpp @@ -66,7 +66,7 @@ void OverWorld::enterOverWorld() InputDevice* device = input_manager->getDeviceList()->getKeyboard(0); // Create player and associate player with keyboard - StateManager::get()->createActivePlayer(PlayerManager::get()->getCurrentPlayer(), + StateManager::get()->createActivePlayer(PlayerManager::getCurrentPlayer(), device, NULL); if (!kart_properties_manager->getKart(UserConfigParams::m_default_kart)) diff --git a/src/modes/world.cpp b/src/modes/world.cpp index 47219b8cb..90ba932c3 100644 --- a/src/modes/world.cpp +++ b/src/modes/world.cpp @@ -469,7 +469,7 @@ void World::terminateRace() { // Retrieve the current player StateManager::ActivePlayer* p = m_karts[i]->getController()->getPlayer(); - if (p && p->getConstProfile() == PlayerManager::get()->getCurrentPlayer()) + if (p && p->getConstProfile() == PlayerManager::getCurrentPlayer()) { // Check if the player has won if (m_karts[i]->getPosition() == winner_position && kart_amount > opponents ) @@ -494,7 +494,7 @@ void World::terminateRace() { // Retrieve the current player StateManager::ActivePlayer* p = m_karts[i]->getController()->getPlayer(); - if (p && p->getConstProfile() == PlayerManager::get()->getCurrentPlayer()) + if (p && p->getConstProfile() == PlayerManager::getCurrentPlayer()) { // Check if the player has won if (m_karts[i]->getPosition() == 1 ) @@ -511,7 +511,7 @@ void World::terminateRace() } } } - PlayerManager::get()->getCurrentPlayer()->raceFinished(); + PlayerManager::getCurrentPlayer()->raceFinished(); if (m_race_gui) m_race_gui->clearAllMessages(); // we can't delete the race gui here, since it is needed in case of @@ -815,7 +815,7 @@ void World::updateWorld(float dt) InputDevice* device = input_manager->getDeviceList()->getKeyboard(0); // Create player and associate player with keyboard - StateManager::get()->createActivePlayer(PlayerManager::get()->getCurrentPlayer(), + StateManager::get()->createActivePlayer(PlayerManager::getCurrentPlayer(), device, NULL); if (!kart_properties_manager->getKart(UserConfigParams::m_default_kart)) diff --git a/src/network/protocols/start_game_protocol.cpp b/src/network/protocols/start_game_protocol.cpp index a9b1513e1..37ace37c5 100644 --- a/src/network/protocols/start_game_protocol.cpp +++ b/src/network/protocols/start_game_protocol.cpp @@ -115,7 +115,7 @@ void StartGameProtocol::update() rki.setGlobalPlayerId(profile->race_id); rki.setLocalPlayerId(is_me?0:1); rki.setHostId(profile->race_id); - PlayerProfile* profile_to_use = PlayerManager::get()->getCurrentPlayer(); + PlayerProfile* profile_to_use = PlayerManager::getCurrentPlayer(); assert(profile_to_use); InputDevice* device = input_manager->getDeviceList()->getLatestUsedDevice(); int new_player_id = 0; diff --git a/src/physics/physics.cpp b/src/physics/physics.cpp index a5adab012..5258490dd 100644 --- a/src/physics/physics.cpp +++ b/src/physics/physics.cpp @@ -271,7 +271,7 @@ void Physics::update(float dt) // to the kart, and it's the current player. At this stage // only the current player can get achievements. if (target_kart != kart && c && - c->getPlayer()->getConstProfile() == PlayerManager::get()->getCurrentPlayer()) + c->getPlayer()->getConstProfile() == PlayerManager::getCurrentPlayer()) { PlayerManager::increaseAchievement(AchievementInfo::ACHIEVE_ARCH_ENEMY, target_kart->getIdent(), 1); diff --git a/src/race/grand_prix_data.cpp b/src/race/grand_prix_data.cpp index 589020ba8..4b1149818 100644 --- a/src/race/grand_prix_data.cpp +++ b/src/race/grand_prix_data.cpp @@ -223,7 +223,7 @@ bool GrandPrixData::checkConsistency(bool chatty) const bool GrandPrixData::isTrackAvailable(const std::string &id) const { return id!="fortmagma" || - !PlayerManager::get()->getCurrentPlayer()->isLocked("fortmagma"); + !PlayerManager::getCurrentPlayer()->isLocked("fortmagma"); } // isTrackAvailable // ---------------------------------------------------------------------------- diff --git a/src/race/race_manager.cpp b/src/race/race_manager.cpp index c406921b2..1115634e3 100644 --- a/src/race/race_manager.cpp +++ b/src/race/race_manager.cpp @@ -632,7 +632,7 @@ void RaceManager::exitRace(bool delete_world) // were finished, and not when a race is aborted. if (m_major_mode==MAJOR_MODE_GRAND_PRIX && m_track_number==(int)m_tracks.size()) { - PlayerManager::get()->getCurrentPlayer()->grandPrixFinished(); + PlayerManager::getCurrentPlayer()->grandPrixFinished(); if(m_major_mode==MAJOR_MODE_GRAND_PRIX&& !NetworkWorld::getInstance()->isRunning()) { //Delete saved GP diff --git a/src/states_screens/arenas_screen.cpp b/src/states_screens/arenas_screen.cpp index fd94d20cd..f556629ac 100644 --- a/src/states_screens/arenas_screen.cpp +++ b/src/states_screens/arenas_screen.cpp @@ -236,7 +236,7 @@ void ArenasScreen::buildTrackList() if(!curr->isArena()) continue; } - if (PlayerManager::get()->getCurrentPlayer()->isLocked(curr->getIdent())) + if (PlayerManager::getCurrentPlayer()->isLocked(curr->getIdent())) { w->addItem( _("Locked : solve active challenges to gain access to more!"), "locked", curr->getScreenshotFile(), LOCKED_BADGE ); @@ -266,7 +266,7 @@ void ArenasScreen::buildTrackList() if(!curr->isArena()) continue; } - if (PlayerManager::get()->getCurrentPlayer()->isLocked(curr->getIdent())) + if (PlayerManager::getCurrentPlayer()->isLocked(curr->getIdent())) { w->addItem( _("Locked : solve active challenges to gain access to more!"), "locked", curr->getScreenshotFile(), LOCKED_BADGE ); diff --git a/src/states_screens/dialogs/gp_info_dialog.cpp b/src/states_screens/dialogs/gp_info_dialog.cpp index ecc7568f4..e4368ab28 100644 --- a/src/states_screens/dialogs/gp_info_dialog.cpp +++ b/src/states_screens/dialogs/gp_info_dialog.cpp @@ -221,7 +221,7 @@ void GPInfoDialog::onEnterPressedInternal() std::string gp_id = m_gp_ident; ModalDialog::dismiss(); // Disable accidentally unlocking of a challenge - PlayerManager::get()->getCurrentPlayer()->setCurrentChallenge(""); + PlayerManager::getCurrentPlayer()->setCurrentChallenge(""); race_manager->startGP(grand_prix_manager->getGrandPrix(gp_id), false, false); } diff --git a/src/states_screens/dialogs/player_info_dialog.cpp b/src/states_screens/dialogs/player_info_dialog.cpp index 80d4dc873..240e56f72 100644 --- a/src/states_screens/dialogs/player_info_dialog.cpp +++ b/src/states_screens/dialogs/player_info_dialog.cpp @@ -167,7 +167,7 @@ void PlayerInfoDialog::showConfirmDialog() _("Do you really want to delete player '%s' ?", m_player->getName()); - if (PlayerManager::get()->getCurrentPlayer() == m_player) + if (PlayerManager::getCurrentPlayer() == m_player) { message = _("You cannot delete this player " "because it is currently in use."); @@ -184,7 +184,7 @@ void PlayerInfoDialog::showConfirmDialog() m_irrlicht_window); a->setTextAlignment(EGUIA_CENTER, EGUIA_CENTER); - if (PlayerManager::get()->getCurrentPlayer() != m_player) + if (PlayerManager::getCurrentPlayer() != m_player) { ButtonWidget* widget = new ButtonWidget(); widget->m_properties[PROP_ID] = "confirmremove"; diff --git a/src/states_screens/dialogs/select_challenge.cpp b/src/states_screens/dialogs/select_challenge.cpp index 883f385e6..b2f48b6f4 100644 --- a/src/states_screens/dialogs/select_challenge.cpp +++ b/src/states_screens/dialogs/select_challenge.cpp @@ -95,7 +95,7 @@ SelectChallengeDialog::SelectChallengeDialog(const float percentWidth, break; } - const ChallengeStatus* c = PlayerManager::get()->getCurrentPlayer() + const ChallengeStatus* c = PlayerManager::getCurrentPlayer() ->getChallengeStatus(challenge_id); if (c->isSolved(RaceManager::DIFFICULTY_EASY)) @@ -173,7 +173,7 @@ GUIEngine::EventPropagation SelectChallengeDialog::processEvent(const std::strin return GUIEngine::EVENT_LET; } - PlayerManager::get()->getCurrentPlayer()->setCurrentChallenge(m_challenge_id); + PlayerManager::getCurrentPlayer()->setCurrentChallenge(m_challenge_id); ModalDialog::dismiss(); diff --git a/src/states_screens/dialogs/track_info_dialog.cpp b/src/states_screens/dialogs/track_info_dialog.cpp index d3023dc3f..48a463765 100644 --- a/src/states_screens/dialogs/track_info_dialog.cpp +++ b/src/states_screens/dialogs/track_info_dialog.cpp @@ -252,7 +252,7 @@ void TrackInfoDialog::onEnterPressedInternal() race_manager->setReverseTrack(reverse_track); std::string track_ident = m_track_ident; // Disable accidentally unlocking of a challenge - PlayerManager::get()->getCurrentPlayer()->setCurrentChallenge(""); + PlayerManager::getCurrentPlayer()->setCurrentChallenge(""); ModalDialog::dismiss(); race_manager->startSingleRace(track_ident, num_laps, false); diff --git a/src/states_screens/easter_egg_screen.cpp b/src/states_screens/easter_egg_screen.cpp index dfbc456fb..474615e32 100644 --- a/src/states_screens/easter_egg_screen.cpp +++ b/src/states_screens/easter_egg_screen.cpp @@ -236,7 +236,7 @@ void EasterEggScreen::buildTrackList() if (curr->isArena() || curr->isSoccer()) continue; if (curr->isInternal()) continue; - if (PlayerManager::get()->getCurrentPlayer()->isLocked(curr->getIdent())) + if (PlayerManager::getCurrentPlayer()->isLocked(curr->getIdent())) { tracks_widget->addItem( _("Locked : solve active challenges to gain access to more!"), "locked", curr->getScreenshotFile(), LOCKED_BADGE, @@ -267,7 +267,7 @@ void EasterEggScreen::buildTrackList() if (curr->isSoccer()) continue; if (curr->isInternal()) continue; - if (PlayerManager::get()->getCurrentPlayer()->isLocked(curr->getIdent())) + if (PlayerManager::getCurrentPlayer()->isLocked(curr->getIdent())) { tracks_widget->addItem( _("Locked : solve active challenges to gain access to more!"), "locked", curr->getScreenshotFile(), LOCKED_BADGE, diff --git a/src/states_screens/feature_unlocked.cpp b/src/states_screens/feature_unlocked.cpp index f726dbd1d..92d51bd80 100644 --- a/src/states_screens/feature_unlocked.cpp +++ b/src/states_screens/feature_unlocked.cpp @@ -144,7 +144,7 @@ void FeatureUnlockedCutScene::loadedFromFile() void FeatureUnlockedCutScene::findWhatWasUnlocked(RaceManager::Difficulty difficulty) { - PlayerProfile *player = PlayerManager::get()->getCurrentPlayer(); + PlayerProfile *player = PlayerManager::getCurrentPlayer(); int points_before = player->getPoints(); int points_now = points_before + CHALLENGE_POINTS[difficulty]; @@ -410,7 +410,7 @@ void FeatureUnlockedCutScene::tearDown() m_all_kart_models.clearAndDeleteAll(); // update point count and the list of locked/unlocked stuff - PlayerManager::get()->getCurrentPlayer()->computeActive(); + PlayerManager::getCurrentPlayer()->computeActive(); } // tearDown // ---------------------------------------------------------------------------- diff --git a/src/states_screens/grand_prix_lose.cpp b/src/states_screens/grand_prix_lose.cpp index ad83e608e..f86382bcd 100644 --- a/src/states_screens/grand_prix_lose.cpp +++ b/src/states_screens/grand_prix_lose.cpp @@ -278,7 +278,7 @@ void GrandPrixLose::eventCallback(GUIEngine::Widget* widget, race_manager->setMajorMode (RaceManager::MAJOR_MODE_SINGLE); std::vector unlocked = - PlayerManager::get()->getCurrentPlayer()->getRecentlyCompletedChallenges(); + PlayerManager::getCurrentPlayer()->getRecentlyCompletedChallenges(); if (unlocked.size() > 0) { @@ -289,7 +289,7 @@ void GrandPrixLose::eventCallback(GUIEngine::Widget* widget, scene->findWhatWasUnlocked(race_manager->getDifficulty()); StateManager::get()->replaceTopMostScreen(scene); - PlayerManager::get()->getCurrentPlayer()->clearUnlocked(); + PlayerManager::getCurrentPlayer()->clearUnlocked(); } else { diff --git a/src/states_screens/grand_prix_win.cpp b/src/states_screens/grand_prix_win.cpp index ca40a0f3b..8af8884c4 100644 --- a/src/states_screens/grand_prix_win.cpp +++ b/src/states_screens/grand_prix_win.cpp @@ -98,7 +98,7 @@ void GrandPrixWin::loadedFromFile() void GrandPrixWin::init() { Screen::init(); - if (PlayerManager::get()->getCurrentPlayer()->getRecentlyCompletedChallenges().size() > 0) + if (PlayerManager::getCurrentPlayer()->getRecentlyCompletedChallenges().size() > 0) { const core::dimension2d& frame_size = GUIEngine::getDriver()->getCurrentRenderTargetSize(); @@ -406,12 +406,12 @@ void GrandPrixWin::eventCallback(GUIEngine::Widget* widget, // un-set the GP mode so that after unlocking, it doesn't try to continue the GP race_manager->setMajorMode (RaceManager::MAJOR_MODE_SINGLE); - if (PlayerManager::get()->getCurrentPlayer() - ->getRecentlyCompletedChallenges().size() > 0) + if (PlayerManager::getCurrentPlayer() + ->getRecentlyCompletedChallenges().size() > 0) { std::vector unlocked = - PlayerManager::get()->getCurrentPlayer()->getRecentlyCompletedChallenges(); - PlayerManager::get()->getCurrentPlayer()->clearUnlocked(); + PlayerManager::getCurrentPlayer()->getRecentlyCompletedChallenges(); + PlayerManager::getCurrentPlayer()->clearUnlocked(); FeatureUnlockedCutScene* scene = FeatureUnlockedCutScene::getInstance(); diff --git a/src/states_screens/help_screen_1.cpp b/src/states_screens/help_screen_1.cpp index 3dda36791..337dffebf 100644 --- a/src/states_screens/help_screen_1.cpp +++ b/src/states_screens/help_screen_1.cpp @@ -66,7 +66,7 @@ void HelpScreen1::eventCallback(Widget* widget, const std::string& name, const i InputDevice* device = input_manager->getDeviceList()->getKeyboard(0); // Create player and associate player with keyboard - StateManager::get()->createActivePlayer(PlayerManager::get()->getCurrentPlayer(), + StateManager::get()->createActivePlayer(PlayerManager::getCurrentPlayer(), device, NULL); if (kart_properties_manager->getKart(UserConfigParams::m_default_kart) == NULL) diff --git a/src/states_screens/kart_selection.cpp b/src/states_screens/kart_selection.cpp index b414cfd43..50fe11f1b 100644 --- a/src/states_screens/kart_selection.cpp +++ b/src/states_screens/kart_selection.cpp @@ -1104,7 +1104,7 @@ bool KartSelectionScreen::playerJoin(InputDevice* device, bool firstPlayer) kartsAreaWidget->m_y + kartsAreaWidget->m_h); // ---- Create new active player - PlayerProfile* profile_to_use = PlayerManager::get()->getCurrentPlayer(); + PlayerProfile* profile_to_use = PlayerManager::getCurrentPlayer(); if (!firstPlayer) { @@ -2013,7 +2013,7 @@ void KartSelectionScreen::setKartsFromCurrentGroup() { const KartProperties* prop = kart_properties_manager->getKartById(n); - if (PlayerManager::get()->getCurrentPlayer()->isLocked(prop->getIdent())) + if (PlayerManager::getCurrentPlayer()->isLocked(prop->getIdent())) { w->addItem( _("Locked : solve active challenges to gain access " @@ -2045,7 +2045,7 @@ void KartSelectionScreen::setKartsFromCurrentGroup() kart_properties_manager->getKartById(group[n]); const std::string &icon_path = prop->getAbsoluteIconFile(); - if (PlayerManager::get()->getCurrentPlayer()->isLocked(prop->getIdent())) + if (PlayerManager::getCurrentPlayer()->isLocked(prop->getIdent())) { w->addItem( _("Locked : solve active challenges to gain access " diff --git a/src/states_screens/main_menu_screen.cpp b/src/states_screens/main_menu_screen.cpp index 0bfaeab7b..c49b72724 100644 --- a/src/states_screens/main_menu_screen.cpp +++ b/src/states_screens/main_menu_screen.cpp @@ -341,7 +341,7 @@ void MainMenuScreen::eventCallback(Widget* widget, const std::string& name, InputDevice* device = input_manager->getDeviceList()->getKeyboard(0); // Create player and associate player with keyboard - StateManager::get()->createActivePlayer(PlayerManager::get()->getCurrentPlayer(), + StateManager::get()->createActivePlayer(PlayerManager::getCurrentPlayer(), device, NULL); if (kart_properties_manager->getKart(UserConfigParams::m_default_kart) == NULL) @@ -364,7 +364,7 @@ void MainMenuScreen::eventCallback(Widget* widget, const std::string& name, } else if (selection == "story") { - PlayerProfile *player = PlayerManager::get()->getCurrentPlayer(); + PlayerProfile *player = PlayerManager::getCurrentPlayer(); if (player->isFirstTime()) { StateManager::get()->enterGameState(); diff --git a/src/states_screens/online_profile_achievements.cpp b/src/states_screens/online_profile_achievements.cpp index 7d2c16e38..44c89b3ee 100644 --- a/src/states_screens/online_profile_achievements.cpp +++ b/src/states_screens/online_profile_achievements.cpp @@ -97,7 +97,7 @@ void OnlineProfileAchievements::init() m_waiting_for_achievements = false; m_achievements_list_widget->clear(); const std::map & all_achievements = - PlayerManager::get()->getCurrentPlayer()->getAchievementsStatus() + PlayerManager::getCurrentPlayer()->getAchievementsStatus() ->getAllAchievements(); std::map::const_iterator it; for (it = all_achievements.begin(); it != all_achievements.end(); ++it) diff --git a/src/states_screens/options_screen_players.cpp b/src/states_screens/options_screen_players.cpp index 8aa8a7856..9854d583a 100644 --- a/src/states_screens/options_screen_players.cpp +++ b/src/states_screens/options_screen_players.cpp @@ -80,7 +80,7 @@ void OptionsScreenPlayers::init() refreshPlayerList(); ButtonWidget* you = getWidget("playername"); - unsigned int playerID = PlayerManager::get()->getCurrentPlayer()->getUniqueID(); + unsigned int playerID = PlayerManager::getCurrentPlayer()->getUniqueID(); core::stringw player_name = L"-"; const PlayerProfile* curr = PlayerManager::get()->getPlayerById(playerID); if(curr) diff --git a/src/states_screens/race_gui_overworld.cpp b/src/states_screens/race_gui_overworld.cpp index 5136b1c21..48b85fe91 100644 --- a/src/states_screens/race_gui_overworld.cpp +++ b/src/states_screens/race_gui_overworld.cpp @@ -207,7 +207,7 @@ void RaceGUIOverworld::renderPlayerView(const Camera *camera, float dt) */ void RaceGUIOverworld::drawTrophyPoints() { - PlayerProfile *player = PlayerManager::get()->getCurrentPlayer(); + PlayerProfile *player = PlayerManager::getCurrentPlayer(); const int points = player->getPoints(); std::string s = StringUtils::toString(points); core::stringw sw(s.c_str()); @@ -398,7 +398,7 @@ void RaceGUIOverworld::drawGlobalMiniMap() // bool locked = (m_locked_challenges.find(c) != m_locked_challenges.end()); int state = (challenges[n].getForceField().m_is_locked ? LOCKED : OPEN); - const ChallengeStatus* c = PlayerManager::get()->getCurrentPlayer() + const ChallengeStatus* c = PlayerManager::getCurrentPlayer() ->getChallengeStatus(challenges[n].m_challenge_id); if (c->isSolved(RaceManager::DIFFICULTY_HARD)) state = COMPLETED_HARD; else if (c->isSolved(RaceManager::DIFFICULTY_MEDIUM)) state = COMPLETED_MEDIUM; diff --git a/src/states_screens/race_result_gui.cpp b/src/states_screens/race_result_gui.cpp index 5fc5b8a28..fad865a3d 100644 --- a/src/states_screens/race_result_gui.cpp +++ b/src/states_screens/race_result_gui.cpp @@ -157,7 +157,7 @@ void RaceResultGUI::enableAllButtons() // If something was unlocked // ------------------------- - int n = PlayerManager::get()->getCurrentPlayer()->getRecentlyCompletedChallenges().size(); + int n = PlayerManager::getCurrentPlayer()->getRecentlyCompletedChallenges().size(); if(n>0) { top->setText(n==1 ? _("You completed a challenge!") @@ -226,7 +226,7 @@ void RaceResultGUI::eventCallback(GUIEngine::Widget* widget, // If something was unlocked, the 'continue' button was // actually used to display "Show unlocked feature(s)" text. // --------------------------------------------------------- - int n = PlayerManager::get()->getCurrentPlayer() + int n = PlayerManager::getCurrentPlayer() ->getRecentlyCompletedChallenges().size(); if(n>0) { @@ -238,7 +238,7 @@ void RaceResultGUI::eventCallback(GUIEngine::Widget* widget, } std::vector unlocked = - PlayerManager::get()->getCurrentPlayer()->getRecentlyCompletedChallenges(); + PlayerManager::getCurrentPlayer()->getRecentlyCompletedChallenges(); bool gameCompleted = false; for (unsigned int n = 0; n < unlocked.size(); n++) @@ -250,7 +250,7 @@ void RaceResultGUI::eventCallback(GUIEngine::Widget* widget, } } - PlayerManager::get()->getCurrentPlayer()->clearUnlocked(); + PlayerManager::getCurrentPlayer()->clearUnlocked(); if (gameCompleted) { diff --git a/src/states_screens/race_setup_screen.cpp b/src/states_screens/race_setup_screen.cpp index dce58717a..9e4a415ae 100644 --- a/src/states_screens/race_setup_screen.cpp +++ b/src/states_screens/race_setup_screen.cpp @@ -180,7 +180,7 @@ void RaceSetupScreen::assignDifficulty() } else if (difficultySelection == "best") { - if (PlayerManager::get()->getCurrentPlayer()->isLocked("difficulty_best")) + if (PlayerManager::getCurrentPlayer()->isLocked("difficulty_best")) { unlock_manager->playLockSound(); UserConfigParams::m_difficulty = RaceManager::DIFFICULTY_HARD; @@ -231,7 +231,7 @@ void RaceSetupScreen::init() assert( w != NULL ); if (UserConfigParams::m_difficulty == RaceManager::DIFFICULTY_BEST && - PlayerManager::get()->getCurrentPlayer()->isLocked("difficulty_best")) + PlayerManager::getCurrentPlayer()->isLocked("difficulty_best")) { w->setSelection(RaceManager::DIFFICULTY_HARD, PLAYER_ID_GAME_MASTER); } @@ -269,7 +269,7 @@ void RaceSetupScreen::init() name2 += _("Contains no powerups, so only your driving skills matter!"); w2->addItem( name2, IDENT_TTRIAL, RaceManager::getIconOf(RaceManager::MINOR_MODE_TIME_TRIAL)); - if (PlayerManager::get()->getCurrentPlayer()->isLocked(IDENT_FTL)) + if (PlayerManager::getCurrentPlayer()->isLocked(IDENT_FTL)) { w2->addItem( _("Locked : solve active challenges to gain access to more!"), "locked", RaceManager::getIconOf(RaceManager::MINOR_MODE_FOLLOW_LEADER), true); @@ -345,7 +345,7 @@ void RaceSetupScreen::init() w2->registerHoverListener(m_mode_listener); - if (PlayerManager::get()->getCurrentPlayer()->isLocked("difficulty_best")) + if (PlayerManager::getCurrentPlayer()->isLocked("difficulty_best")) { RibbonWidget* w = getWidget("difficulty"); assert(w != NULL); diff --git a/src/states_screens/story_mode_lobby.cpp b/src/states_screens/story_mode_lobby.cpp index fbca28b7c..faa95c746 100644 --- a/src/states_screens/story_mode_lobby.cpp +++ b/src/states_screens/story_mode_lobby.cpp @@ -55,7 +55,7 @@ void StoryModeLobbyScreen::init() ListWidget* list = getWidget("gameslots"); list->clear(); - PlayerProfile *player = PlayerManager::get()->getCurrentPlayer(); + PlayerProfile *player = PlayerManager::getCurrentPlayer(); if(player) { StateManager::get()->resetAndGoToScreen(MainMenuScreen::getInstance()); diff --git a/src/states_screens/tracks_screen.cpp b/src/states_screens/tracks_screen.cpp index 4f75eab4b..575c50d3a 100644 --- a/src/states_screens/tracks_screen.cpp +++ b/src/states_screens/tracks_screen.cpp @@ -238,7 +238,7 @@ void TracksScreen::init() sshot_files.push_back("gui/main_help.png"); } - if (PlayerManager::get()->getCurrentPlayer()->isLocked(gp->getId())) + if (PlayerManager::getCurrentPlayer()->isLocked(gp->getId())) { gps_widget->addAnimatedItem(_("Locked!"), "locked", sshot_files, 1.5f, LOCKED_BADGE | TROPHY_BADGE, @@ -303,7 +303,7 @@ void TracksScreen::buildTrackList() if (curr->isArena() || curr->isSoccer()) continue; if (curr->isInternal()) continue; - if(PlayerManager::get()->getCurrentPlayer()->isLocked(curr->getIdent())) + if(PlayerManager::getCurrentPlayer()->isLocked(curr->getIdent())) { tracks_widget->addItem( _("Locked : solve active challenges to gain access to more!"), "locked", curr->getScreenshotFile(), LOCKED_BADGE, @@ -334,7 +334,7 @@ void TracksScreen::buildTrackList() if (curr->isSoccer()) continue; if (curr->isInternal()) continue; - if (PlayerManager::get()->getCurrentPlayer()->isLocked(curr->getIdent())) + if (PlayerManager::getCurrentPlayer()->isLocked(curr->getIdent())) { tracks_widget->addItem( _("Locked : solve active challenges to gain access to more!"), "locked", curr->getScreenshotFile(), LOCKED_BADGE, diff --git a/src/tracks/track.cpp b/src/tracks/track.cpp index 90469f1ed..5f2b17828 100644 --- a/src/tracks/track.cpp +++ b/src/tracks/track.cpp @@ -156,7 +156,7 @@ Track::~Track() unsigned int Track::getNumOfCompletedChallenges() { unsigned int unlocked_challenges = 0; - PlayerProfile *player = PlayerManager::get()->getCurrentPlayer(); + PlayerProfile *player = PlayerManager::getCurrentPlayer(); for (unsigned int i=0; igetNumTrophies(); - bool shown = (PlayerManager::get()->getCurrentPlayer()->getPoints() < val); + bool shown = (PlayerManager::getCurrentPlayer()->getPoints() < val); m_force_fields.push_back(OverworldForceField(xyz, shown, val)); m_challenges[closest_challenge_id].setForceField( From ec213fbe286c730fd9c1326205f98ec84a458831 Mon Sep 17 00:00:00 2001 From: hiker Date: Tue, 8 Apr 2014 08:09:28 +1000 Subject: [PATCH 09/21] Removed signedInAs function. --- src/online/messages.cpp | 6 ------ src/online/messages.hpp | 1 - src/states_screens/online_screen.cpp | 5 ++--- 3 files changed, 2 insertions(+), 10 deletions(-) diff --git a/src/online/messages.cpp b/src/online/messages.cpp index cd93e6742..292da60bf 100644 --- a/src/online/messages.cpp +++ b/src/online/messages.cpp @@ -46,12 +46,6 @@ namespace Online } // ------------------------------------------------------------------------ - irr::core::stringw signedInAs(const irr::core::stringw & name) - { - return irr::core::stringw(_("Signed in as : ")) + name + "."; - } - // ------------------------------------------------------------------------ - irr::core::stringw joiningServer() { return irr::core::stringw(_("Joining server")) + loadingDots(); diff --git a/src/online/messages.hpp b/src/online/messages.hpp index 4c73b9b3f..a68305d5b 100644 --- a/src/online/messages.hpp +++ b/src/online/messages.hpp @@ -41,7 +41,6 @@ namespace Online irr::core::stringw fetchingFriends (); irr::core::stringw fetchingAchievements (); irr::core::stringw processing (); - irr::core::stringw signedInAs (const irr::core::stringw & name); } // namespace Messages }// namespace Online #endif diff --git a/src/states_screens/online_screen.cpp b/src/states_screens/online_screen.cpp index 418c2faab..a17cf2862 100644 --- a/src/states_screens/online_screen.cpp +++ b/src/states_screens/online_screen.cpp @@ -135,9 +135,8 @@ void OnlineScreen::init() Screen::init(); setInitialFocus(); DemoWorld::resetIdleTime(); - m_online_status_widget->setText(Messages::signedInAs(CurrentUser::get()->getUserName()), false); - core::stringw m = _("Signed in as: %s.", CurrentUser::get()->getUserName()); - //m_online_status_widget->setText(-_("Signed in as: %s.", CurrentUser::get()->getUserName().c_str()), false); + core::stringw m = _("Signed in as: %s.",CurrentUser::get()->getUserName()); + m_online_status_widget->setText(m, false); } // init // ---------------------------------------------------------------------------- From 6a3698232e4faffe4e0d6bdbf01b4d162a39f381 Mon Sep 17 00:00:00 2001 From: hiker Date: Tue, 8 Apr 2014 08:19:14 +1000 Subject: [PATCH 10/21] Removed unused parameters. --- src/online/messages.cpp | 4 ++-- src/online/messages.hpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/online/messages.cpp b/src/online/messages.cpp index 292da60bf..b1ac45bd8 100644 --- a/src/online/messages.cpp +++ b/src/online/messages.cpp @@ -92,9 +92,9 @@ namespace Online * \param interval A float representing the time it takes to add a new dot * \param max_dots The number of dots used. Defaults to 3. */ - irr::core::stringw loadingDots(bool spaces, float interval, int max_dots) + irr::core::stringw loadingDots(float interval, int max_dots) { - int nr_dots = int(floor(StkTime::getRealTime() * (1 / interval))) % (max_dots+1); + int nr_dots = int(floor(StkTime::getRealTime() / interval)) % (max_dots+1); return irr::core::stringw((std::string(nr_dots,'.') + std::string(max_dots-nr_dots,' ')).c_str()); } } // namespace messages diff --git a/src/online/messages.hpp b/src/online/messages.hpp index a68305d5b..c2f4fbc5c 100644 --- a/src/online/messages.hpp +++ b/src/online/messages.hpp @@ -30,7 +30,7 @@ namespace Online */ namespace Messages { - irr::core::stringw loadingDots (bool spaces = true, float interval = 0.5f, int max_dots = 3); + irr::core::stringw loadingDots (float interval = 0.5f, int max_dots = 3); irr::core::stringw signingIn (); irr::core::stringw signingOut (); irr::core::stringw validatingInfo (); From a6f4f50281ed0cf5b746c0d4430393daa91215de Mon Sep 17 00:00:00 2001 From: hiker Date: Tue, 8 Apr 2014 16:52:29 +1000 Subject: [PATCH 11/21] Fixed documentation. --- src/online/messages.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/online/messages.cpp b/src/online/messages.cpp index b1ac45bd8..3b9bf2298 100644 --- a/src/online/messages.cpp +++ b/src/online/messages.cpp @@ -88,7 +88,6 @@ namespace Online // ------------------------------------------------------------------------ /** * Shows a increasing number of dots. - * \param spaces Flag if unshowed dots should be replaced by spaces * \param interval A float representing the time it takes to add a new dot * \param max_dots The number of dots used. Defaults to 3. */ From 8483f58f9de41281e90e0dba4853e1871959e7cd Mon Sep 17 00:00:00 2001 From: hiker Date: Wed, 9 Apr 2014 08:33:42 +1000 Subject: [PATCH 12/21] Moved saved session data from UserConfig to PlayerProfile - which means that now each player can individually save an online session. --- src/config/player_manager.cpp | 30 ++++++++++---- src/config/player_manager.hpp | 5 +++ src/config/player_profile.cpp | 71 ++++++++++++++++++++++++++++++---- src/config/player_profile.hpp | 35 +++++++++++++++-- src/config/user_config.hpp | 19 --------- src/main.cpp | 15 +++++-- src/online/current_user.cpp | 17 ++++---- src/online/request_manager.cpp | 3 ++ 8 files changed, 145 insertions(+), 50 deletions(-) diff --git a/src/config/player_manager.cpp b/src/config/player_manager.cpp index fb80fc703..db44b042e 100644 --- a/src/config/player_manager.cpp +++ b/src/config/player_manager.cpp @@ -71,32 +71,48 @@ void PlayerManager::load() { std::string filename = file_manager->getUserConfigFile("players.xml"); - const XMLNode *players = file_manager->createXMLTree(filename); - if(!players) + m_player_data = file_manager->createXMLTree(filename); + if(!m_player_data) { Log::info("player_manager", "A new players.xml file will be created."); return; } - else if(players->getName()!="players") + else if(m_player_data->getName()!="players") { Log::info("player_manager", "The players.xml file is invalid."); return; } m_current_player = NULL; - for(unsigned int i=0; igetNumNodes(); i++) + for(unsigned int i=0; igetNumNodes(); i++) { - const XMLNode *player_xml = players->getNode(i); + const XMLNode *player_xml = m_player_data->getNode(i); PlayerProfile *player = new PlayerProfile(player_xml); m_all_players.push_back(player); if(player->isDefault()) m_current_player = player; } - m_all_players.insertionSort(/*start*/0, /*desc*/true); - delete players; } // load +// ---------------------------------------------------------------------------- +/** The 2nd loading stage. During this stage achievements and story mode + * data is read for each player. + */ +void PlayerManager::loadRemainingData() +{ + for (unsigned int i = 0; igetNumNodes(); i++) + { + const XMLNode *player_xml = m_player_data->getNode(i); + m_all_players[i].loadRemainingData(player_xml); + } + delete m_player_data; + m_player_data = NULL; + + // Sort player by frequency + m_all_players.insertionSort(/*start*/0, /*desc*/true); +} // loadRemainingData + // ---------------------------------------------------------------------------- /** Saves all player profiles to players.xml. */ diff --git a/src/config/player_manager.hpp b/src/config/player_manager.hpp index 650496a7e..ff0468ef6 100644 --- a/src/config/player_manager.hpp +++ b/src/config/player_manager.hpp @@ -48,6 +48,10 @@ private: /** A pointer to the current player. */ PlayerProfile* m_current_player; + /** Saves the XML tree from players.xml for use in the 2nd + * loading stage (loadRemainingData). */ + const XMLNode *m_player_data; + void load(); PlayerManager(); ~PlayerManager(); @@ -72,6 +76,7 @@ public: // ------------------------------------------------------------------------ void save(); + void loadRemainingData(); unsigned int getUniqueId() const; void addDefaultPlayer(); void addNewPlayer(const irr::core::stringw& name); diff --git a/src/config/player_profile.cpp b/src/config/player_profile.cpp index e24d5a32e..d89d6ae51 100644 --- a/src/config/player_profile.cpp +++ b/src/config/player_profile.cpp @@ -50,26 +50,52 @@ PlayerProfile::PlayerProfile(const core::stringw& name, bool is_guest) } // PlayerProfile //------------------------------------------------------------------------------ -/** Constructor to deserialize a player that was saved to a XML file. +/** Constructor to deserialize player data that was saved to a XML file. The + * constructor will only load the main player data (like name, id, saved + * online data), but not the achievements and story mode data. Reason is + * that the achievement and story mode data depends on other data to be + * read first (challenges and achievement files), which in turn can only be + * created later in the startup process (they depend on e.g. all tracks to + * be known). On the other hand, automatic login needs to happen asap + * (i.e. as soon as the network thread is started), which needs the main + * player data (i.e. the default player, and saved session data). So the + * constructor only reads this data, the rest of the player data is handled + * in loadRemainingData later in the initialisation process. * \param node The XML node representing this player. */ PlayerProfile::PlayerProfile(const XMLNode* node) { + m_saved_session = false; + m_saved_token = ""; + m_saved_user_id = 0; + m_story_mode_status = NULL; + m_achievements_status = NULL; + node->get("name", &m_name ); node->get("guest", &m_is_guest_account); node->get("use-frequency", &m_use_frequency ); node->get("unique-id", &m_unique_id ); node->get("is-default", &m_is_default ); + node->get("saved-session", &m_saved_session ); + node->get("saved-user", &m_saved_user_id ); + node->get("saved-token", &m_saved_token ); + #ifdef DEBUG m_magic_number = 0xABCD1234; #endif +} // PlayerProfile + +//------------------------------------------------------------------------------ +/** This function loads the achievement and story mode data. This +*/ +void PlayerProfile::loadRemainingData(const XMLNode *node) +{ const XMLNode *xml_story_mode = node->getNode("story-mode"); m_story_mode_status = unlock_manager->createStoryModeStatus(xml_story_mode); const XMLNode *xml_achievements = node->getNode("achievements"); m_achievements_status = AchievementsManager::get() - ->createAchievementsStatus(xml_achievements); - -} // PlayerProfile + ->createAchievementsStatus(xml_achievements); +} // loadRemainingData //------------------------------------------------------------------------------ /** Writes the data for this player to the specified UTFWriter. @@ -79,9 +105,15 @@ void PlayerProfile::save(UTFWriter &out) { out << L" \n"; + << L"\" use-frequency=\"" << m_use_frequency << L"\"\n"; + + out << L" is-default=\"" << m_is_default + << L"\" unique-id=\"" << m_unique_id + << L"\" saved-session=\"" << m_saved_session << L"\"\n"; + + out << L" saved-user=\"" << m_saved_user_id + << L"\" saved-token=\"" << m_saved_token << L"\">\n"; + { assert(m_story_mode_status); m_story_mode_status->save(out); @@ -92,6 +124,31 @@ void PlayerProfile::save(UTFWriter &out) out << L" \n"; } // save +//------------------------------------------------------------------------------ +// ------------------------------------------------------------------------ +/** Saves the online data, so that it will automatically re-connect +* next time this profile is loaded. +* \param user_id Id of the online profile. +* \param token Token used for authentication. +*/ +void PlayerProfile::saveSession(int user_id, const std::string &token) +{ + m_saved_session = true; + m_saved_user_id = user_id; + m_saved_token = token; + PlayerManager::get()->save(); +} // saveSession + +// ------------------------------------------------------------------------ +/** Unsets any saved session data. */ +void PlayerProfile::clearSession() +{ + m_saved_session = false; + m_saved_user_id = 0; + m_saved_token = ""; + PlayerManager::get()->save(); +} // clearSession + //------------------------------------------------------------------------------ /** Increments how often that account was used. Guest accounts are not counted. */ diff --git a/src/config/player_profile.hpp b/src/config/player_profile.hpp index 3affcbc7e..71a23921b 100644 --- a/src/config/player_profile.hpp +++ b/src/config/player_profile.hpp @@ -62,6 +62,15 @@ private: /** True if this is the default (last used) player. */ bool m_is_default; + /** True if this user has a saved session. */ + bool m_saved_session; + + /** If a session was saved, this will be the online user id to use. */ + int m_saved_user_id; + + /** The token of the saved session. */ + std::string m_saved_token; + /** The complete challenge state. */ StoryModeStatus *m_story_mode_status; @@ -69,15 +78,18 @@ private: public: - PlayerProfile(const core::stringw& name, bool is_guest = false); + PlayerProfile(const core::stringw &name, bool is_guest = false); - PlayerProfile(const XMLNode* node); + PlayerProfile(const XMLNode *node); void save(UTFWriter &out); + void loadRemainingData(const XMLNode *node); void incrementUseFrequency(); bool operator<(const PlayerProfile &other); bool operator>(const PlayerProfile &other); void raceFinished(); + void saveSession(int user_id, const std::string &token); + void clearSession(); // ------------------------------------------------------------------------ ~PlayerProfile() @@ -190,7 +202,24 @@ public: { return m_achievements_status; } // getAchievementsStatus - + // ------------------------------------------------------------------------ + /** Returns true if a session was saved for this player. */ + bool hasSavedSession() const { return m_saved_session; } + // ------------------------------------------------------------------------ + /** If a session was saved, return the id of the saved user. */ + int getSavedUserId() const + { + assert(m_saved_session); + return m_saved_user_id; + } // getSavedUserId + // ------------------------------------------------------------------------ + /** If a session was saved, return the token to use. */ + const std::string& getSavedToken() const + { + assert(m_saved_session); + return m_saved_token; + } // getSavedToken + // ------------------------------------------------------------------------ }; // class PlayerProfile #endif diff --git a/src/config/user_config.hpp b/src/config/user_config.hpp index 0e6a0af0c..ccc7a4b24 100644 --- a/src/config/user_config.hpp +++ b/src/config/user_config.hpp @@ -669,25 +669,6 @@ namespace UserConfigParams &m_online_group, "The server used for online multiplayer.")); - PARAM_PREFIX BoolUserConfigParam m_saved_session - PARAM_DEFAULT( BoolUserConfigParam( false, - "saved_session", - &m_online_group, - "Is there a saved session?") ); - - PARAM_PREFIX IntUserConfigParam m_saved_user - PARAM_DEFAULT( IntUserConfigParam( 0, - "saved_user", - &m_online_group, - "User ID of the saved session.") ); - - PARAM_PREFIX StringUserConfigParam m_saved_token - PARAM_DEFAULT( StringUserConfigParam( "", - "saved_token", - &m_online_group, - "Token of the saved session.") ); - - // ---- Addon server related entries PARAM_PREFIX GroupUserConfigParam m_addon_group PARAM_DEFAULT( GroupUserConfigParam("AddonAndNews", diff --git a/src/main.cpp b/src/main.cpp index ea6506053..04bdfee0b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1030,6 +1030,11 @@ void initRest() addons_manager = new AddonsManager(); Online::ProfileManager::create(); + // The request manager will start the login process in case of a saved + // session, so we need to read the main data from the players.xml file. + // The rest will be read later (since the rest needs the unlock- and + // achievement managers to be created, which can only be created later). + PlayerManager::create(); Online::RequestManager::get()->startNetworkThread(); NewsManager::get(); // this will create the news manager @@ -1165,13 +1170,15 @@ int main(int argc, char *argv[] ) handleXmasMode(); // Needs the kart and track directories to load potential challenges - // in those dirs. + // in those dirs, so it can only be created after reading tracks + // and karts. unlock_manager = new UnlockManager(); AchievementsManager::create(); - // Needs the unlock manager to initialise the game slots of all players - // and the AchievementsManager to initialise the AchievementsStatus. - PlayerManager::create(); + // Reading the rest of the player data needs the unlock manager to + // initialise the game slots of all players and the AchievementsManager + // to initialise the AchievementsStatus, so it is done only now. + PlayerManager::get()->loadRemainingData(); GUIEngine::addLoadingIcon( irr_driver->getTexture(FileManager::GUI, "gui_lock.png" ) ); diff --git a/src/online/current_user.cpp b/src/online/current_user.cpp index 5ab0a254c..642cdff6c 100644 --- a/src/online/current_user.cpp +++ b/src/online/current_user.cpp @@ -97,14 +97,14 @@ namespace Online void CurrentUser::requestSavedSession() { SignInRequest * request = NULL; - if(m_state == US_SIGNED_OUT && UserConfigParams::m_saved_session) + const PlayerProfile *cp = PlayerManager::getCurrentPlayer(); + if (m_state == US_SIGNED_OUT && cp->hasSavedSession() ) { request = new SignInRequest(true); request->setServerURL("client-user.php"); request->addParameter("action","saved-session"); - request->addParameter("userid", UserConfigParams::m_saved_user); - request->addParameter("token", - UserConfigParams::m_saved_token.c_str()); + request->addParameter("userid", cp->getSavedUserId()); + request->addParameter("token", cp->getSavedToken()); request->queue(); m_state = US_SIGNING_IN; } @@ -179,9 +179,8 @@ namespace Online m_state = US_SIGNED_IN; if(saveSession()) { - UserConfigParams::m_saved_user = getID(); - UserConfigParams::m_saved_token = getToken(); - UserConfigParams::m_saved_session = true; + PlayerManager::getCurrentPlayer()->saveSession(getID(), + getToken() ); } ProfileManager::get()->addPersistent(m_profile); std::string achieved_string(""); @@ -231,9 +230,7 @@ namespace Online ProfileManager::get()->clearPersistent(); m_profile = NULL; m_state = US_SIGNED_OUT; - UserConfigParams::m_saved_user = 0; - UserConfigParams::m_saved_token = ""; - UserConfigParams::m_saved_session = false; + PlayerManager::getCurrentPlayer()->clearSession(); } // signOut // ------------------------------------------------------------------------ diff --git a/src/online/request_manager.cpp b/src/online/request_manager.cpp index 664547cb9..56f2f2789 100644 --- a/src/online/request_manager.cpp +++ b/src/online/request_manager.cpp @@ -102,6 +102,9 @@ namespace Online * variable has not been assigned at that stage, and the thread might * use network_http - a very subtle race condition. So the thread can * only be started after the assignment (in main) has been done. + * \pre PlayerManager was created and has read the main data for each + * player so that all data for automatic login is + * availale. */ void RequestManager::startNetworkThread() { From 4586887bf27516a6d19e42c9f02cbcbc951ebca1 Mon Sep 17 00:00:00 2001 From: Guillaume P Date: Thu, 10 Apr 2014 08:02:51 +0200 Subject: [PATCH 13/21] Disable notifications. --- .travis.yml | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/.travis.yml b/.travis.yml index 6a0b46f4b..bf9f43ca0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -21,15 +21,15 @@ script: - cd build - cmake .. -DCMAKE_BUILD_TYPE=Debug - make VERBOSE=1 -j 4 -notifications: - irc: - channels: - - "irc.freenode.org#stk" - skip_join: false - use_notice: true - template: - #- "[%{commit}: %{author}] %{message}" - #- "%{build_url}" - - "[%{repository}#%{branch} @%{commit}] %{author}): %{message}" - - "Diff: %{compare_url}" - - "Build: %{build_url}" +# notifications: + # irc: + # channels: + # - "irc.freenode.org#stk" + # skip_join: false + # use_notice: true + # template: + # #- "[%{commit}: %{author}] %{message}" + # #- "%{build_url}" + # - "[%{repository}#%{branch} @%{commit}] %{author}): %{message}" + # - "Diff: %{compare_url}" + # - "Build: %{build_url}" From 9a386c0ee3725e98dca309616ed12ca0143c97f5 Mon Sep 17 00:00:00 2001 From: Guillaume P Date: Thu, 10 Apr 2014 08:15:29 +0200 Subject: [PATCH 14/21] Update before_install section in travis config file. --- .travis.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.travis.yml b/.travis.yml index bf9f43ca0..075503c0a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,6 +15,9 @@ before_install: - sudo apt-get update -qq # INSTALL DEPENDENCIES - sudo apt-get install build-essential cmake libogg-dev libvorbis-dev libopenal-dev libxxf86vm-dev libgl1-mesa-dev libglu1-mesa-dev libcurl4-openssl-dev libfribidi-dev libbluetooth-dev + - sudo apt-add-repository "deb http://archive.ubuntu.com/ubuntu quantal main restricted" + - sudo apt-get update -qq + - sudo apt-get install libgl1-mesa-dev libglu1-mesa-dev script: # BUILD COMMANDS - mkdir build From 9a6eb2e34aae8fd1b8180e53a29c6b4c947fa6f3 Mon Sep 17 00:00:00 2001 From: Guillaume P Date: Thu, 10 Apr 2014 08:41:02 +0200 Subject: [PATCH 15/21] Clean up and re-enable notifications in travis config. --- .travis.yml | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/.travis.yml b/.travis.yml index 075503c0a..3f59953b2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,28 +11,29 @@ compiler: # only: # - master before_install: - # UPDATE REPOS + # Update repos - sudo apt-get update -qq - # INSTALL DEPENDENCIES - - sudo apt-get install build-essential cmake libogg-dev libvorbis-dev libopenal-dev libxxf86vm-dev libgl1-mesa-dev libglu1-mesa-dev libcurl4-openssl-dev libfribidi-dev libbluetooth-dev + # Install dependencies + - sudo apt-get install build-essential cmake libogg-dev libvorbis-dev libopenal-dev libxxf86vm-dev libcurl4-openssl-dev libfribidi-dev libbluetooth-dev + # Install mesa from an other repo (a newer version is required) - sudo apt-add-repository "deb http://archive.ubuntu.com/ubuntu quantal main restricted" - sudo apt-get update -qq - sudo apt-get install libgl1-mesa-dev libglu1-mesa-dev script: - # BUILD COMMANDS + # Build commands - mkdir build - cd build - cmake .. -DCMAKE_BUILD_TYPE=Debug - make VERBOSE=1 -j 4 -# notifications: - # irc: - # channels: - # - "irc.freenode.org#stk" - # skip_join: false - # use_notice: true - # template: - # #- "[%{commit}: %{author}] %{message}" - # #- "%{build_url}" - # - "[%{repository}#%{branch} @%{commit}] %{author}): %{message}" - # - "Diff: %{compare_url}" - # - "Build: %{build_url}" +notifications: + irc: + channels: + - "irc.freenode.org#stk" + skip_join: false + use_notice: true + template: + #- "[%{commit}: %{author}] %{message}" + #- "%{build_url}" + - "[%{repository}#%{branch} @%{commit}] %{author}): %{message}" + - "Diff: %{compare_url}" + - "Build: %{build_url}" From 76025ff784b90a4d7287898fe6be44c6ee53d86e Mon Sep 17 00:00:00 2001 From: Guillaume P Date: Thu, 10 Apr 2014 08:50:45 +0200 Subject: [PATCH 16/21] It's even better with the key of the added repository. --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 3f59953b2..aa3607483 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,6 +17,7 @@ before_install: - sudo apt-get install build-essential cmake libogg-dev libvorbis-dev libopenal-dev libxxf86vm-dev libcurl4-openssl-dev libfribidi-dev libbluetooth-dev # Install mesa from an other repo (a newer version is required) - sudo apt-add-repository "deb http://archive.ubuntu.com/ubuntu quantal main restricted" + - sudo apt-key adv --recv-keys --keyserver keyserver.ubuntu.com 3B4FE6ACC0B21F32 - sudo apt-get update -qq - sudo apt-get install libgl1-mesa-dev libglu1-mesa-dev script: From 9ba636f6615cb8c1119c506a8b7b08b87ae8e159 Mon Sep 17 00:00:00 2001 From: Vincent Lejeune Date: Tue, 8 Apr 2014 22:33:44 +0200 Subject: [PATCH 17/21] Gather View Projection and shadows matrix generation. --- data/shaders/shadow.geom | 8 ++++-- src/graphics/irr_driver.hpp | 2 ++ src/graphics/render.cpp | 57 ++++++++++++++++++++++--------------- src/graphics/shaders.cpp | 2 +- 4 files changed, 43 insertions(+), 26 deletions(-) diff --git a/data/shaders/shadow.geom b/data/shaders/shadow.geom index 3333dc893..e57567f84 100644 --- a/data/shaders/shadow.geom +++ b/data/shaders/shadow.geom @@ -1,6 +1,10 @@ layout (std140) uniform MatrixesData { - mat4 ViewProjectionMatrix[4]; + mat4 ViewMatrix; + mat4 ProjectionMatrix; + mat4 InverseViewMatrix; + mat4 InverseProjectionMatrix; + mat4 ShadowViewProjMatrixes[4]; }; #if __VERSION__ >= 400 @@ -20,7 +24,7 @@ void emitToLayer(int layerId) for(int i=0; i<3; i++) { uv = tc[i]; - gl_Position = ViewProjectionMatrix[layerId] * gl_in[i].gl_Position; + gl_Position = ShadowViewProjMatrixes[layerId] * gl_in[i].gl_Position; EmitVertex(); } EndPrimitive(); diff --git a/src/graphics/irr_driver.hpp b/src/graphics/irr_driver.hpp index 2cc06c3b1..05fcf445b 100644 --- a/src/graphics/irr_driver.hpp +++ b/src/graphics/irr_driver.hpp @@ -226,6 +226,8 @@ private: void renderSolidSecondPass(); void renderTransparent(); void renderParticles(); + void computeCameraMatrix(scene::ICameraSceneNode * const camnode, + Camera * const camera); void renderShadows(//ShadowImportanceProvider * const sicb, scene::ICameraSceneNode * const camnode, //video::SOverrideMaterial &overridemat, diff --git a/src/graphics/render.cpp b/src/graphics/render.cpp index 61b80e428..840988378 100644 --- a/src/graphics/render.cpp +++ b/src/graphics/render.cpp @@ -164,11 +164,8 @@ void IrrDriver::renderGLSL(float dt) }*/ // Get Projection and view matrix - irr_driver->setPhase(SOLID_NORMAL_AND_DEPTH_PASS); - m_scene_manager->drawAll(scene::ESNRP_CAMERA); - irr_driver->setProjMatrix(irr_driver->getVideoDriver()->getTransform(video::ETS_PROJECTION)); - irr_driver->setViewMatrix(irr_driver->getVideoDriver()->getTransform(video::ETS_VIEW)); - irr_driver->genProjViewMatrix(); + computeCameraMatrix(camnode, camera); + // Fire up the MRT PROFILER_PUSH_CPU_MARKER("- Solid Pass 1", 0xFF, 0x00, 0x00); @@ -469,10 +466,8 @@ void IrrDriver::renderParticles() m_scene_manager->drawAll(scene::ESNRP_TRANSPARENT_EFFECT); } -void IrrDriver::renderShadows(//ShadowImportanceProvider * const sicb, - scene::ICameraSceneNode * const camnode, - //video::SOverrideMaterial &overridemat, - Camera * const camera) +void IrrDriver::computeCameraMatrix(scene::ICameraSceneNode * const camnode, + Camera * const camera) { m_scene_manager->setCurrentRendertime(scene::ESNRP_SOLID); @@ -556,6 +551,35 @@ void IrrDriver::renderShadows(//ShadowImportanceProvider * const sicb, sun_ortho_matrix.push_back(getVideoDriver()->getTransform(video::ETS_PROJECTION) * getVideoDriver()->getTransform(video::ETS_VIEW)); } assert(sun_ortho_matrix.size() == 4); + camnode->setNearValue(oldnear); + camnode->setFarValue(oldfar); + camnode->render(); + camera->activate(); + m_scene_manager->drawAll(scene::ESNRP_CAMERA); + irr_driver->setProjMatrix(irr_driver->getVideoDriver()->getTransform(video::ETS_PROJECTION)); + irr_driver->setViewMatrix(irr_driver->getVideoDriver()->getTransform(video::ETS_VIEW)); + irr_driver->genProjViewMatrix(); + + float *tmp = new float[16 * 8]; + + memcpy(tmp, irr_driver->getViewMatrix().pointer(), 16 * sizeof(float)); + memcpy(&tmp[16], irr_driver->getProjMatrix().pointer(), 16 * sizeof(float)); + memcpy(&tmp[32], irr_driver->getInvViewMatrix().pointer(), 16 * sizeof(float)); + memcpy(&tmp[48], irr_driver->getInvProjMatrix().pointer(), 16 * sizeof(float)); + size_t size = irr_driver->getShadowViewProj().size(); + for (unsigned i = 0; i < size; i++) + memcpy(&tmp[16 * i + 64], irr_driver->getShadowViewProj()[i].pointer(), 16 * sizeof(float)); + + glBindBuffer(GL_UNIFORM_BUFFER, SharedObject::ViewProjectionMatrixesUBO); + glBufferSubData(GL_UNIFORM_BUFFER, 0, 16 * 8 * sizeof(float), tmp); + delete tmp; +} + +void IrrDriver::renderShadows(//ShadowImportanceProvider * const sicb, + scene::ICameraSceneNode * const camnode, + //video::SOverrideMaterial &overridemat, + Camera * const camera) +{ irr_driver->setPhase(SHADOW_PASS); glDisable(GL_BLEND); @@ -566,25 +590,12 @@ void IrrDriver::renderShadows(//ShadowImportanceProvider * const sicb, glClear(GL_DEPTH_BUFFER_BIT); glDrawBuffer(GL_NONE); - size_t size = irr_driver->getShadowViewProj().size(); - float *tmp = new float[16 * size]; - for (unsigned i = 0; i < size; i++) { - memcpy(&tmp[16 * i], irr_driver->getShadowViewProj()[i].pointer(), 16 * sizeof(float)); - } - glBindBuffer(GL_UNIFORM_BUFFER, SharedObject::ViewProjectionMatrixesUBO); - glBufferSubData(GL_UNIFORM_BUFFER, 0, 16 * 4 * sizeof(float), tmp); glBindBufferBase(GL_UNIFORM_BUFFER, 0, SharedObject::ViewProjectionMatrixesUBO); - delete tmp; - m_scene_manager->drawAll(scene::ESNRP_SOLID); glBindBuffer(GL_UNIFORM_BUFFER, 0); glCullFace(GL_BACK); - camnode->setNearValue(oldnear); - camnode->setFarValue(oldfar); - camnode->render(); - camera->activate(); - m_scene_manager->drawAll(scene::ESNRP_CAMERA); + glViewport(0, 0, UserConfigParams::m_width, UserConfigParams::m_height); diff --git a/src/graphics/shaders.cpp b/src/graphics/shaders.cpp index 2e28d668c..a6dbf4452 100644 --- a/src/graphics/shaders.cpp +++ b/src/graphics/shaders.cpp @@ -170,7 +170,7 @@ static void initShadowVPMUBO() { glGenBuffers(1, &SharedObject::ViewProjectionMatrixesUBO); glBindBuffer(GL_UNIFORM_BUFFER, SharedObject::ViewProjectionMatrixesUBO); - glBufferData(GL_UNIFORM_BUFFER, 16 * 4 * sizeof(float), 0, GL_STATIC_DRAW); + glBufferData(GL_UNIFORM_BUFFER, 16 * 8 * sizeof(float), 0, GL_STATIC_DRAW); glBindBuffer(GL_UNIFORM_BUFFER, 0); } From 55097aba91b64bf15a4f1a21812d56eab8cbcf40 Mon Sep 17 00:00:00 2001 From: Vincent Lejeune Date: Thu, 10 Apr 2014 20:57:06 +0200 Subject: [PATCH 18/21] Add shader file as comment for easier debug --- src/graphics/glwrap.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/graphics/glwrap.cpp b/src/graphics/glwrap.cpp index 4edd237b2..2912c44bb 100644 --- a/src/graphics/glwrap.cpp +++ b/src/graphics/glwrap.cpp @@ -229,6 +229,7 @@ GLuint LoadShader(const char * file, unsigned type) sprintf(versionString, "#version %d\n", irr_driver->getGLSLVersion()); std::string Code = versionString; std::ifstream Stream(file, std::ios::in); + Code += "//" + std::string(file) + "\n"; if (Stream.is_open()) { std::string Line = ""; From fee89a3a3e66fb23466014347de660ee77a7946e Mon Sep 17 00:00:00 2001 From: Vincent Lejeune Date: Tue, 8 Apr 2014 16:31:05 +0200 Subject: [PATCH 19/21] Start decoupling tree based draw sequence. --- src/graphics/render.cpp | 55 ++++++++++++++++ src/graphics/stkanimatedmesh.cpp | 101 +++++++++++------------------- src/graphics/stkanimatedmesh.hpp | 2 - src/graphics/stkmesh.cpp | 2 + src/graphics/stkmesh.hpp | 44 +++++++++++++ src/graphics/stkmeshscenenode.cpp | 93 ++++++++++++++++----------- 6 files changed, 195 insertions(+), 102 deletions(-) diff --git a/src/graphics/render.cpp b/src/graphics/render.cpp index 840988378..e66574935 100644 --- a/src/graphics/render.cpp +++ b/src/graphics/render.cpp @@ -421,8 +421,27 @@ void IrrDriver::renderSolidFirstPass() glDisable(GL_BLEND); glEnable(GL_CULL_FACE); irr_driver->setPhase(SOLID_NORMAL_AND_DEPTH_PASS); + GroupedFPSM::reset(); + GroupedFPSM::reset(); + GroupedFPSM::reset(); + m_scene_manager->drawAll(scene::ESNRP_SOLID); + glUseProgram(MeshShader::ObjectPass1Shader::Program); + for (unsigned i = 0; i < GroupedFPSM::MeshSet.size(); ++i) + { + drawObjectPass1(*GroupedFPSM::MeshSet[i], GroupedFPSM::MVPSet[i], GroupedFPSM::TIMVSet[i]); + } + glUseProgram(MeshShader::ObjectRefPass1Shader::Program); + for (unsigned i = 0; i < GroupedFPSM::MeshSet.size(); ++i) + { + drawObjectRefPass1(*GroupedFPSM::MeshSet[i], GroupedFPSM::MVPSet[i], GroupedFPSM::TIMVSet[i], GroupedFPSM::MeshSet[i]->TextureMatrix); + } + glUseProgram(MeshShader::NormalMapShader::Program); + for (unsigned i = 0; i < GroupedFPSM::MeshSet.size(); ++i) + { + drawNormalPass(*GroupedFPSM::MeshSet[i], GroupedFPSM::MVPSet[i], GroupedFPSM::TIMVSet[i]); + } } void IrrDriver::renderSolidSecondPass() @@ -437,10 +456,46 @@ void IrrDriver::renderSolidSecondPass() glEnable(GL_DEPTH_TEST); glDisable(GL_ALPHA_TEST); glDisable(GL_BLEND); + GroupedSM::reset(); + GroupedSM::reset(); + GroupedSM::reset(); + GroupedSM::reset(); + GroupedSM::reset(); + GroupedSM::reset(); + GroupedSM::reset(); setTexture(0, m_rtts->getRenderTarget(RTT_TMP1), GL_NEAREST, GL_NEAREST); setTexture(1, m_rtts->getRenderTarget(RTT_TMP2), GL_NEAREST, GL_NEAREST); setTexture(2, m_rtts->getRenderTarget(RTT_SSAO), GL_NEAREST, GL_NEAREST); m_scene_manager->drawAll(scene::ESNRP_SOLID); + + glUseProgram(MeshShader::ObjectPass2Shader::Program); + for (unsigned i = 0; i < GroupedSM::MeshSet.size(); i++) + drawObjectPass2(*GroupedSM::MeshSet[i], GroupedSM::MVPSet[i], GroupedSM::MeshSet[i]->TextureMatrix); + + glUseProgram(MeshShader::ObjectRefPass2Shader::Program); + for (unsigned i = 0; i < GroupedSM::MeshSet.size(); i++) + drawObjectRefPass2(*GroupedSM::MeshSet[i], GroupedSM::MVPSet[i], GroupedSM::MeshSet[i]->TextureMatrix); + + glUseProgram(MeshShader::ObjectRimLimitShader::Program); + for (unsigned i = 0; i < GroupedSM::MeshSet.size(); i++) + drawObjectRimLimit(*GroupedSM::MeshSet[i], GroupedSM::MVPSet[i], GroupedSM::TIMVSet[i], GroupedSM::MeshSet[i]->TextureMatrix); + + glUseProgram(MeshShader::SphereMapShader::Program); + for (unsigned i = 0; i < GroupedSM::MeshSet.size(); i++) + drawSphereMap(*GroupedSM::MeshSet[i], GroupedSM::MVPSet[i], GroupedSM::TIMVSet[i]); + + glUseProgram(MeshShader::SplattingShader::Program); + for (unsigned i = 0; i < GroupedSM::MeshSet.size(); i++) + drawSplatting(*GroupedSM::MeshSet[i], GroupedSM::MVPSet[i]); + + glUseProgram(MeshShader::ObjectUnlitShader::Program); + for (unsigned i = 0; i < GroupedSM::MeshSet.size(); i++) + drawObjectUnlit(*GroupedSM::MeshSet[i], GroupedSM::MVPSet[i]); + + glUseProgram(MeshShader::DetailledObjectPass2Shader::Program); + for (unsigned i = 0; i < GroupedSM::MeshSet.size(); i++) + drawDetailledObjectPass2(*GroupedSM::MeshSet[i], GroupedSM::MVPSet[i]); + } void IrrDriver::renderTransparent() diff --git a/src/graphics/stkanimatedmesh.cpp b/src/graphics/stkanimatedmesh.cpp index 1143871cd..0a4e3352f 100644 --- a/src/graphics/stkanimatedmesh.cpp +++ b/src/graphics/stkanimatedmesh.cpp @@ -54,47 +54,6 @@ void STKAnimatedMesh::setMesh(scene::IAnimatedMesh* mesh) CAnimatedMeshSceneNode::setMesh(mesh); } -void STKAnimatedMesh::drawSolidPass1(const GLMesh &mesh, GeometricMaterial type) -{ - switch (type) - { - case FPSM_ALPHA_REF_TEXTURE: - drawObjectRefPass1(mesh, ModelViewProjectionMatrix, TransposeInverseModelView, mesh.TextureMatrix); - break; - case FPSM_DEFAULT: - drawObjectPass1(mesh, ModelViewProjectionMatrix, TransposeInverseModelView); - break; - default: - assert(0 && "Wrong geometric material"); - break; - } -} - -void STKAnimatedMesh::drawSolidPass2(const GLMesh &mesh, ShadedMaterial type) -{ - switch (type) - { - case SM_ALPHA_REF_TEXTURE: - drawObjectRefPass2(mesh, ModelViewProjectionMatrix, mesh.TextureMatrix); - break; - case SM_RIMLIT: - drawObjectRimLimit(mesh, ModelViewProjectionMatrix, TransposeInverseModelView, mesh.TextureMatrix); - break; - case SM_UNLIT: - drawObjectUnlit(mesh, ModelViewProjectionMatrix); - break; - case SM_DETAILS: - drawDetailledObjectPass2(mesh, ModelViewProjectionMatrix); - break; - case SM_DEFAULT: - drawObjectPass2(mesh, ModelViewProjectionMatrix, mesh.TextureMatrix); - break; - default: - assert(0 && "Wrong shaded material"); - break; - } -} - void STKAnimatedMesh::render() { video::IVideoDriver* driver = SceneManager->getVideoDriver(); @@ -187,45 +146,59 @@ void STKAnimatedMesh::render() ModelViewProjectionMatrix = computeMVP(AbsoluteTransformation); TransposeInverseModelView = computeTIMV(AbsoluteTransformation); - if (!GeometricMesh[FPSM_DEFAULT].empty()) - glUseProgram(MeshShader::ObjectPass1Shader::Program); for (unsigned i = 0; i < GeometricMesh[FPSM_DEFAULT].size(); i++) - drawSolidPass1(*GeometricMesh[FPSM_DEFAULT][i], FPSM_DEFAULT); + { + GroupedFPSM::MeshSet.push_back(GeometricMesh[FPSM_DEFAULT][i]); + GroupedFPSM::MVPSet.push_back(ModelViewProjectionMatrix); + GroupedFPSM::TIMVSet.push_back(TransposeInverseModelView); + } - if (!GeometricMesh[FPSM_ALPHA_REF_TEXTURE].empty()) - glUseProgram(MeshShader::ObjectRefPass1Shader::Program); for (unsigned i = 0; i < GeometricMesh[FPSM_ALPHA_REF_TEXTURE].size(); i++) - drawSolidPass1(*GeometricMesh[FPSM_ALPHA_REF_TEXTURE][i], FPSM_ALPHA_REF_TEXTURE); + { + GroupedFPSM::MeshSet.push_back(GeometricMesh[FPSM_ALPHA_REF_TEXTURE][i]); + GroupedFPSM::MVPSet.push_back(ModelViewProjectionMatrix); + GroupedFPSM::TIMVSet.push_back(TransposeInverseModelView); + } return; } if (irr_driver->getPhase() == SOLID_LIT_PASS) { - if (!ShadedMesh[SM_DEFAULT].empty()) - glUseProgram(MeshShader::ObjectPass2Shader::Program); for (unsigned i = 0; i < ShadedMesh[SM_DEFAULT].size(); i++) - drawSolidPass2(*ShadedMesh[SM_DEFAULT][i], SM_DEFAULT); + { + GroupedSM::MeshSet.push_back(ShadedMesh[SM_DEFAULT][i]); + GroupedSM::MVPSet.push_back(ModelViewProjectionMatrix); + GroupedSM::TIMVSet.push_back(TransposeInverseModelView); + } - if (!ShadedMesh[SM_ALPHA_REF_TEXTURE].empty()) - glUseProgram(MeshShader::ObjectRefPass2Shader::Program); for (unsigned i = 0; i < ShadedMesh[SM_ALPHA_REF_TEXTURE].size(); i++) - drawSolidPass2(*ShadedMesh[SM_ALPHA_REF_TEXTURE][i], SM_ALPHA_REF_TEXTURE); + { + GroupedSM::MeshSet.push_back(ShadedMesh[SM_ALPHA_REF_TEXTURE][i]); + GroupedSM::MVPSet.push_back(ModelViewProjectionMatrix); + GroupedSM::TIMVSet.push_back(TransposeInverseModelView); + } - if (!ShadedMesh[SM_RIMLIT].empty()) - glUseProgram(MeshShader::ObjectRimLimitShader::Program); for (unsigned i = 0; i < ShadedMesh[SM_RIMLIT].size(); i++) - drawSolidPass2(*ShadedMesh[SM_RIMLIT][i], SM_RIMLIT); + { + GroupedSM::MeshSet.push_back(ShadedMesh[SM_RIMLIT][i]); + GroupedSM::MVPSet.push_back(ModelViewProjectionMatrix); + GroupedSM::TIMVSet.push_back(TransposeInverseModelView); + } - if (!ShadedMesh[SM_UNLIT].empty()) - glUseProgram(MeshShader::ObjectUnlitShader::Program); - for (unsigned i = 0; i < ShadedMesh[SM_UNLIT].size(); i++) - drawSolidPass2(*ShadedMesh[SM_UNLIT][i], SM_UNLIT); + for (GLMesh *mesh : ShadedMesh[SM_UNLIT]) + { + GroupedSM::MeshSet.push_back(mesh); + GroupedSM::MVPSet.push_back(ModelViewProjectionMatrix); + GroupedSM::TIMVSet.push_back(TransposeInverseModelView); + } - if (!ShadedMesh[SM_DETAILS].empty()) - glUseProgram(MeshShader::DetailledObjectPass2Shader::Program); - for (unsigned i = 0; i < ShadedMesh[SM_DETAILS].size(); i++) - drawSolidPass2(*ShadedMesh[SM_DETAILS][i], SM_DETAILS); + for (GLMesh *mesh : ShadedMesh[SM_DETAILS]) + { + GroupedSM::MeshSet.push_back(mesh); + GroupedSM::MVPSet.push_back(ModelViewProjectionMatrix); + GroupedSM::TIMVSet.push_back(TransposeInverseModelView); + } return; } diff --git a/src/graphics/stkanimatedmesh.hpp b/src/graphics/stkanimatedmesh.hpp index a59538727..f885db674 100644 --- a/src/graphics/stkanimatedmesh.hpp +++ b/src/graphics/stkanimatedmesh.hpp @@ -16,8 +16,6 @@ protected: std::vector TransparentMesh[TM_COUNT]; std::vector GLmeshes; core::matrix4 ModelViewProjectionMatrix, TransposeInverseModelView; - void drawSolidPass1(const GLMesh &mesh, GeometricMaterial type); - void drawSolidPass2(const GLMesh &mesh, ShadedMaterial type); void cleanGLMeshes(); public: STKAnimatedMesh(irr::scene::IAnimatedMesh* mesh, irr::scene::ISceneNode* parent, diff --git a/src/graphics/stkmesh.cpp b/src/graphics/stkmesh.cpp index c9f0aeeb0..8afba6e83 100644 --- a/src/graphics/stkmesh.cpp +++ b/src/graphics/stkmesh.cpp @@ -219,6 +219,8 @@ core::vector3df getWind() return m_speed * vector3df(1., 0., 0.) * cos(time); } + + void drawObjectPass1(const GLMesh &mesh, const core::matrix4 & ModelViewProjectionMatrix, const core::matrix4 &TransposeInverseModelView) { irr_driver->IncreaseObjectCount(); diff --git a/src/graphics/stkmesh.hpp b/src/graphics/stkmesh.hpp index 7be9a805b..919f41d18 100644 --- a/src/graphics/stkmesh.hpp +++ b/src/graphics/stkmesh.hpp @@ -67,12 +67,56 @@ bool isObject(video::E_MATERIAL_TYPE type); core::vector3df getWind(); // Pass 1 shader (ie shaders that outputs normals and depth) +template +class GroupedFPSM +{ +public: + static std::vector MeshSet; + static std::vector MVPSet, TIMVSet; + + static void reset() + { + MeshSet.clear(); + MVPSet.clear(); + TIMVSet.clear(); + } +}; + +template +std::vector GroupedFPSM::MeshSet; +template +std::vector GroupedFPSM::MVPSet; +template +std::vector GroupedFPSM::TIMVSet; + void drawObjectPass1(const GLMesh &mesh, const core::matrix4 & ModelViewProjectionMatrix, const core::matrix4 &TransposeInverseModelView); void drawNormalPass(const GLMesh &mesh, const core::matrix4 & ModelViewProjectionMatrix, const core::matrix4 &TransposeInverseModelView); void drawObjectRefPass1(const GLMesh &mesh, const core::matrix4 & ModelViewProjectionMatrix, const core::matrix4 &TransposeInverseModelView, const core::matrix4 &TextureMatrix); void drawGrassPass1(const GLMesh &mesh, const core::matrix4 & ModelViewProjectionMatrix, const core::matrix4 &TransposeInverseModelView, core::vector3df windDir); // Pass 2 shader (ie shaders that outputs final color) +template +class GroupedSM +{ +public: + static std::vector MeshSet; + static std::vector MVPSet, TIMVSet; + + static void reset() + { + MeshSet.clear(); + MVPSet.clear(); + TIMVSet.clear(); + } +}; + +template +std::vector GroupedSM::MeshSet; +template +std::vector GroupedSM::MVPSet; +template +std::vector GroupedSM::TIMVSet; + void drawDetailledObjectPass2(const GLMesh &mesh, const core::matrix4 &ModelViewProjectionMatrix); void drawObjectPass2(const GLMesh &mesh, const core::matrix4 &ModelViewProjectionMatrix, const core::matrix4 &TextureMatrix); void drawUntexturedObject(const GLMesh &mesh, const core::matrix4 &ModelViewProjectionMatrix); diff --git a/src/graphics/stkmeshscenenode.cpp b/src/graphics/stkmeshscenenode.cpp index 81023d01d..2af9c3495 100644 --- a/src/graphics/stkmeshscenenode.cpp +++ b/src/graphics/stkmeshscenenode.cpp @@ -336,21 +336,27 @@ void STKMeshSceneNode::render() glDisable(GL_CULL_FACE); ModelViewProjectionMatrix = computeMVP(AbsoluteTransformation); TransposeInverseModelView = computeTIMV(AbsoluteTransformation); - - if (!GeometricMesh[FPSM_DEFAULT].empty()) - glUseProgram(MeshShader::ObjectPass1Shader::Program); for (unsigned i = 0; i < GeometricMesh[FPSM_DEFAULT].size(); i++) - drawSolidPass1(*GeometricMesh[FPSM_DEFAULT][i], FPSM_DEFAULT); + { + + GroupedFPSM::MeshSet.push_back(GeometricMesh[FPSM_DEFAULT][i]); + GroupedFPSM::MVPSet.push_back(ModelViewProjectionMatrix); + GroupedFPSM::TIMVSet.push_back(TransposeInverseModelView); + } - if (!GeometricMesh[FPSM_ALPHA_REF_TEXTURE].empty()) - glUseProgram(MeshShader::ObjectRefPass1Shader::Program); for (unsigned i = 0; i < GeometricMesh[FPSM_ALPHA_REF_TEXTURE].size(); i++) - drawSolidPass1(*GeometricMesh[FPSM_ALPHA_REF_TEXTURE][i], FPSM_ALPHA_REF_TEXTURE); + { + GroupedFPSM::MeshSet.push_back(GeometricMesh[FPSM_ALPHA_REF_TEXTURE][i]); + GroupedFPSM::MVPSet.push_back(ModelViewProjectionMatrix); + GroupedFPSM::TIMVSet.push_back(TransposeInverseModelView); + } - if (!GeometricMesh[FPSM_NORMAL_MAP].empty()) - glUseProgram(MeshShader::NormalMapShader::Program); for (unsigned i = 0; i < GeometricMesh[FPSM_NORMAL_MAP].size(); i++) - drawSolidPass1(*GeometricMesh[FPSM_NORMAL_MAP][i], FPSM_NORMAL_MAP); + { + GroupedFPSM::MeshSet.push_back(GeometricMesh[FPSM_NORMAL_MAP][i]); + GroupedFPSM::MVPSet.push_back(ModelViewProjectionMatrix); + GroupedFPSM::TIMVSet.push_back(TransposeInverseModelView); + } if (!GeometricMesh[FPSM_GRASS].empty()) glUseProgram(MeshShader::GrassPass1Shader::Program); @@ -367,51 +373,66 @@ void STKMeshSceneNode::render() if (reload_each_frame) glDisable(GL_CULL_FACE); - if (!ShadedMesh[SM_DEFAULT].empty()) - glUseProgram(MeshShader::ObjectPass2Shader::Program); for (unsigned i = 0; i < ShadedMesh[SM_DEFAULT].size(); i++) - drawSolidPass2(*ShadedMesh[SM_DEFAULT][i], SM_DEFAULT); + { + GroupedSM::MeshSet.push_back(ShadedMesh[SM_DEFAULT][i]); + GroupedSM::MVPSet.push_back(ModelViewProjectionMatrix); + GroupedSM::TIMVSet.push_back(TransposeInverseModelView); + } - if (!ShadedMesh[SM_ALPHA_REF_TEXTURE].empty()) - glUseProgram(MeshShader::ObjectRefPass2Shader::Program); for (unsigned i = 0; i < ShadedMesh[SM_ALPHA_REF_TEXTURE].size(); i++) - drawSolidPass2(*ShadedMesh[SM_ALPHA_REF_TEXTURE][i], SM_ALPHA_REF_TEXTURE); + { + GroupedSM::MeshSet.push_back(ShadedMesh[SM_ALPHA_REF_TEXTURE][i]); + GroupedSM::MVPSet.push_back(ModelViewProjectionMatrix); + GroupedSM::TIMVSet.push_back(TransposeInverseModelView); + } - if (!ShadedMesh[SM_RIMLIT].empty()) - glUseProgram(MeshShader::ObjectRimLimitShader::Program); for (unsigned i = 0; i < ShadedMesh[SM_RIMLIT].size(); i++) - drawSolidPass2(*ShadedMesh[SM_RIMLIT][i], SM_RIMLIT); + { + GroupedSM::MeshSet.push_back(ShadedMesh[SM_RIMLIT][i]); + GroupedSM::MVPSet.push_back(ModelViewProjectionMatrix); + GroupedSM::TIMVSet.push_back(TransposeInverseModelView); + } + - if (!ShadedMesh[SM_SPHEREMAP].empty()) - glUseProgram(MeshShader::SphereMapShader::Program); for (unsigned i = 0; i < ShadedMesh[SM_SPHEREMAP].size(); i++) - drawSolidPass2(*ShadedMesh[SM_SPHEREMAP][i], SM_SPHEREMAP); + { + GroupedSM::MeshSet.push_back(ShadedMesh[SM_SPHEREMAP][i]); + GroupedSM::MVPSet.push_back(ModelViewProjectionMatrix); + GroupedSM::TIMVSet.push_back(TransposeInverseModelView); + } - if (!ShadedMesh[SM_SPLATTING].empty()) - glUseProgram(MeshShader::SplattingShader::Program); - for (unsigned i = 0; i < ShadedMesh[SM_SPLATTING].size(); i++) - drawSolidPass2(*ShadedMesh[SM_SPLATTING][i], SM_SPLATTING); + for (GLMesh *mesh : ShadedMesh[SM_SPLATTING]) + { + GroupedSM::MeshSet.push_back(mesh); + GroupedSM::MVPSet.push_back(ModelViewProjectionMatrix); + GroupedSM::TIMVSet.push_back(TransposeInverseModelView); + } + + for (GLMesh *mesh : ShadedMesh[SM_UNLIT]) + { + GroupedSM::MeshSet.push_back(mesh); + GroupedSM::MVPSet.push_back(ModelViewProjectionMatrix); + GroupedSM::TIMVSet.push_back(TransposeInverseModelView); + } + + for (GLMesh *mesh : ShadedMesh[SM_DETAILS]) + { + GroupedSM::MeshSet.push_back(mesh); + GroupedSM::MVPSet.push_back(ModelViewProjectionMatrix); + GroupedSM::TIMVSet.push_back(TransposeInverseModelView); + } if (!ShadedMesh[SM_GRASS].empty()) glUseProgram(MeshShader::GrassPass2Shader::Program); for (unsigned i = 0; i < ShadedMesh[SM_GRASS].size(); i++) drawSolidPass2(*ShadedMesh[SM_GRASS][i], SM_GRASS); - if (!ShadedMesh[SM_UNLIT].empty()) - glUseProgram(MeshShader::ObjectUnlitShader::Program); - for (unsigned i = 0; i < ShadedMesh[SM_UNLIT].size(); i++) - drawSolidPass2(*ShadedMesh[SM_UNLIT][i], SM_UNLIT); - if (!ShadedMesh[SM_CAUSTICS].empty()) glUseProgram(MeshShader::CausticsShader::Program); for (unsigned i = 0; i < ShadedMesh[SM_CAUSTICS].size(); i++) drawSolidPass2(*ShadedMesh[SM_CAUSTICS][i], SM_CAUSTICS); - if (!ShadedMesh[SM_DETAILS].empty()) - glUseProgram(MeshShader::DetailledObjectPass2Shader::Program); - for (unsigned i = 0; i < ShadedMesh[SM_DETAILS].size(); i++) - drawSolidPass2(*ShadedMesh[SM_DETAILS][i], SM_DETAILS); - if (!ShadedMesh[SM_UNTEXTURED].empty()) glUseProgram(MeshShader::UntexturedObjectShader::Program); for (unsigned i = 0; i < ShadedMesh[SM_UNTEXTURED].size(); i++) From 3a55bbe7966214fdc703f6a5e593b0ca5c918688 Mon Sep 17 00:00:00 2001 From: vlj Date: Tue, 8 Apr 2014 23:34:28 +0200 Subject: [PATCH 20/21] Generalize use of UBO. --- data/shaders/instanced_grass.vert | 14 +++++++-- data/shaders/instanced_object_pass.vert | 12 ++++++-- src/graphics/render.cpp | 2 +- src/graphics/shaders.cpp | 39 ++++++++++++------------- src/graphics/shaders.hpp | 12 ++++---- src/graphics/stkinstancedscenenode.cpp | 18 ++++++------ 6 files changed, 54 insertions(+), 43 deletions(-) diff --git a/data/shaders/instanced_grass.vert b/data/shaders/instanced_grass.vert index ec11cd8fd..4e8ed9c5f 100644 --- a/data/shaders/instanced_grass.vert +++ b/data/shaders/instanced_grass.vert @@ -1,6 +1,14 @@ +layout (std140) uniform MatrixesData +{ + mat4 ViewMatrix; + mat4 ProjectionMatrix; + mat4 InverseViewMatrix; + mat4 InverseProjectionMatrix; + mat4 ShadowViewProjMatrixes[4]; +}; + uniform vec3 windDir; -uniform mat4 ViewProjectionMatrix; -uniform mat4 InverseViewMatrix; + in vec3 Origin; in vec3 Orientation; @@ -21,7 +29,7 @@ void main() { mat4 ModelMatrix = getWorldMatrix(Origin + windDir * Color.r, Orientation, Scale); mat4 TransposeInverseModelView = transpose(getInverseWorldMatrix(Origin + windDir * Color.r, Orientation, Scale) * InverseViewMatrix); - gl_Position = ViewProjectionMatrix * ModelMatrix * vec4(Position, 1.); + gl_Position = ProjectionMatrix * ViewMatrix * ModelMatrix * vec4(Position, 1.); nor = (TransposeInverseModelView * vec4(Normal, 0.)).xyz; uv = Texcoord; } diff --git a/data/shaders/instanced_object_pass.vert b/data/shaders/instanced_object_pass.vert index 1e40e9612..499c5ac9d 100644 --- a/data/shaders/instanced_object_pass.vert +++ b/data/shaders/instanced_object_pass.vert @@ -1,5 +1,11 @@ -uniform mat4 ViewProjectionMatrix; -uniform mat4 InverseViewMatrix; +layout (std140) uniform MatrixesData +{ + mat4 ViewMatrix; + mat4 ProjectionMatrix; + mat4 InverseViewMatrix; + mat4 InverseProjectionMatrix; + mat4 ShadowViewProjMatrixes[4]; +}; in vec3 Origin; in vec3 Orientation; @@ -19,7 +25,7 @@ void main(void) { mat4 ModelMatrix = getWorldMatrix(Origin, Orientation, Scale); mat4 TransposeInverseModelView = transpose(getInverseWorldMatrix(Origin, Orientation, Scale) * InverseViewMatrix); - gl_Position = ViewProjectionMatrix * ModelMatrix * vec4(Position, 1.); + gl_Position = ProjectionMatrix * ViewMatrix * ModelMatrix * vec4(Position, 1.); nor = (TransposeInverseModelView * vec4(Normal, 0.)).xyz; uv = Texcoord; } diff --git a/src/graphics/render.cpp b/src/graphics/render.cpp index e66574935..09cb241a6 100644 --- a/src/graphics/render.cpp +++ b/src/graphics/render.cpp @@ -165,6 +165,7 @@ void IrrDriver::renderGLSL(float dt) // Get Projection and view matrix computeCameraMatrix(camnode, camera); + glBindBufferBase(GL_UNIFORM_BUFFER, 0, SharedObject::ViewProjectionMatrixesUBO); // Fire up the MRT @@ -647,7 +648,6 @@ void IrrDriver::renderShadows(//ShadowImportanceProvider * const sicb, glBindBufferBase(GL_UNIFORM_BUFFER, 0, SharedObject::ViewProjectionMatrixesUBO); m_scene_manager->drawAll(scene::ESNRP_SOLID); - glBindBuffer(GL_UNIFORM_BUFFER, 0); glCullFace(GL_BACK); diff --git a/src/graphics/shaders.cpp b/src/graphics/shaders.cpp index a6dbf4452..696205dc9 100644 --- a/src/graphics/shaders.cpp +++ b/src/graphics/shaders.cpp @@ -525,8 +525,6 @@ namespace MeshShader GLuint InstancedObjectPass1Shader::attrib_orientation; GLuint InstancedObjectPass1Shader::attrib_origin; GLuint InstancedObjectPass1Shader::attrib_scale; - GLuint InstancedObjectPass1Shader::uniform_MP; - GLuint InstancedObjectPass1Shader::uniform_VM; GLuint InstancedObjectPass1Shader::uniform_tex; void InstancedObjectPass1Shader::init() @@ -541,15 +539,13 @@ namespace MeshShader attrib_position = glGetAttribLocation(Program, "Position"); attrib_scale = glGetAttribLocation(Program, "Scale"); attrib_normal = glGetAttribLocation(Program, "Normal"); - uniform_MP = glGetUniformLocation(Program, "ViewProjectionMatrix"); - uniform_VM = glGetUniformLocation(Program, "InverseViewMatrix"); uniform_tex = glGetUniformLocation(Program, "tex"); + GLuint uniform_ViewProjectionMatrixesUBO = glGetUniformBlockIndex(Program, "MatrixesData"); + glUniformBlockBinding(Program, uniform_ViewProjectionMatrixesUBO, 0); } - void InstancedObjectPass1Shader::setUniforms(const core::matrix4 &ModelViewProjectionMatrix, const core::matrix4 &ViewMatrix, unsigned TU_tex) + void InstancedObjectPass1Shader::setUniforms(unsigned TU_tex) { - glUniformMatrix4fv(uniform_MP, 1, GL_FALSE, ModelViewProjectionMatrix.pointer()); - glUniformMatrix4fv(uniform_VM, 1, GL_FALSE, ViewMatrix.pointer()); glUniform1i(uniform_tex, TU_tex); } @@ -560,8 +556,6 @@ namespace MeshShader GLuint InstancedObjectRefPass1Shader::attrib_orientation; GLuint InstancedObjectRefPass1Shader::attrib_origin; GLuint InstancedObjectRefPass1Shader::attrib_scale; - GLuint InstancedObjectRefPass1Shader::uniform_MP; - GLuint InstancedObjectRefPass1Shader::uniform_VM; GLuint InstancedObjectRefPass1Shader::uniform_tex; void InstancedObjectRefPass1Shader::init() @@ -577,15 +571,13 @@ namespace MeshShader attrib_scale = glGetAttribLocation(Program, "Scale"); attrib_normal = glGetAttribLocation(Program, "Normal"); attrib_texcoord = glGetAttribLocation(Program, "Texcoord"); - uniform_MP = glGetUniformLocation(Program, "ViewProjectionMatrix"); - uniform_VM = glGetUniformLocation(Program, "InverseViewMatrix"); uniform_tex = glGetUniformLocation(Program, "tex"); + GLuint uniform_ViewProjectionMatrixesUBO = glGetUniformBlockIndex(Program, "MatrixesData"); + glUniformBlockBinding(Program, uniform_ViewProjectionMatrixesUBO, 0); } - void InstancedObjectRefPass1Shader::setUniforms(const core::matrix4 &ModelViewProjectionMatrix, const core::matrix4 &ViewMatrix, unsigned TU_tex) + void InstancedObjectRefPass1Shader::setUniforms(unsigned TU_tex) { - glUniformMatrix4fv(uniform_MP, 1, GL_FALSE, ModelViewProjectionMatrix.pointer()); - glUniformMatrix4fv(uniform_VM, 1, GL_FALSE, ViewMatrix.pointer()); glUniform1i(uniform_tex, TU_tex); } @@ -597,8 +589,6 @@ namespace MeshShader GLuint InstancedGrassPass1Shader::attrib_scale; GLuint InstancedGrassPass1Shader::attrib_texcoord; GLuint InstancedGrassPass1Shader::attrib_color; - GLuint InstancedGrassPass1Shader::uniform_MP; - GLuint InstancedGrassPass1Shader::uniform_IVM; GLuint InstancedGrassPass1Shader::uniform_windDir; GLuint InstancedGrassPass1Shader::uniform_tex; @@ -616,16 +606,14 @@ namespace MeshShader attrib_normal = glGetAttribLocation(Program, "Normal"); attrib_color = glGetAttribLocation(Program, "Color"); attrib_texcoord = glGetAttribLocation(Program, "Texcoord"); - uniform_MP = glGetUniformLocation(Program, "ViewProjectionMatrix"); - uniform_IVM = glGetUniformLocation(Program, "InverseViewMatrix"); uniform_windDir = glGetUniformLocation(Program, "windDir"); uniform_tex = glGetUniformLocation(Program, "tex"); + GLuint uniform_ViewProjectionMatrixesUBO = glGetUniformBlockIndex(Program, "MatrixesData"); + glUniformBlockBinding(Program, uniform_ViewProjectionMatrixesUBO, 0); } - void InstancedGrassPass1Shader::setUniforms(const core::matrix4 &ModelViewProjectionMatrix, const core::matrix4 &InverseViewMatrix, const core::vector3df &windDir, unsigned TU_tex) + void InstancedGrassPass1Shader::setUniforms(const core::vector3df &windDir, unsigned TU_tex) { - glUniformMatrix4fv(uniform_MP, 1, GL_FALSE, ModelViewProjectionMatrix.pointer()); - glUniformMatrix4fv(uniform_IVM, 1, GL_FALSE, InverseViewMatrix.pointer()); glUniform3f(uniform_windDir, windDir.X, windDir.Y, windDir.Z); glUniform1i(uniform_tex, TU_tex); } @@ -716,6 +704,9 @@ namespace MeshShader glUniform1i(uniform_SSAO, 2); glUniform1i(uniform_Albedo, TU_Albedo); glUseProgram(0); + + GLuint uniform_ViewProjectionMatrixesUBO = glGetUniformBlockIndex(Program, "MatrixesData"); + glUniformBlockBinding(Program, uniform_ViewProjectionMatrixesUBO, 0); } void InstancedObjectPass2Shader::setUniforms(const core::matrix4 &ViewProjectionMatrix, const core::matrix4 &TextureMatrix) @@ -767,6 +758,9 @@ namespace MeshShader glUniform1i(uniform_SSAO, 2); glUniform1i(uniform_Albedo, TU_Albedo); glUseProgram(0); + + GLuint uniform_ViewProjectionMatrixesUBO = glGetUniformBlockIndex(Program, "MatrixesData"); + glUniformBlockBinding(Program, uniform_ViewProjectionMatrixesUBO, 0); } void InstancedObjectRefPass2Shader::setUniforms(const core::matrix4 &ViewProjectionMatrix, const core::matrix4 &TextureMatrix) @@ -1083,6 +1077,9 @@ namespace MeshShader glUniform1i(uniform_Albedo, TU_Albedo); glUniform1i(uniform_dtex, TU_dtex); glUseProgram(0); + + GLuint uniform_ViewProjectionMatrixesUBO = glGetUniformBlockIndex(Program, "MatrixesData"); + glUniformBlockBinding(Program, uniform_ViewProjectionMatrixesUBO, 0); } void InstancedGrassPass2Shader::setUniforms(const core::matrix4 &ViewProjectionMatrix, const core::matrix4 &InverseViewMatrix, const core::matrix4 &invproj, const core::vector3df &windDirection, const core::vector3df &SunDir) diff --git a/src/graphics/shaders.hpp b/src/graphics/shaders.hpp index e795d7cef..a9f913aa0 100644 --- a/src/graphics/shaders.hpp +++ b/src/graphics/shaders.hpp @@ -83,10 +83,10 @@ class InstancedObjectPass1Shader public: static GLuint Program; static GLuint attrib_position, attrib_normal, attrib_origin, attrib_orientation, attrib_scale; - static GLuint uniform_MP, uniform_VM, uniform_tex; + static GLuint uniform_tex; static void init(); - static void setUniforms(const core::matrix4 &ViewProjectionMatrix, const core::matrix4 &ViewMatrix, unsigned TU_tex); + static void setUniforms(unsigned TU_tex); }; class InstancedObjectRefPass1Shader @@ -94,10 +94,10 @@ class InstancedObjectRefPass1Shader public: static GLuint Program; static GLuint attrib_position, attrib_normal, attrib_texcoord, attrib_origin, attrib_orientation, attrib_scale; - static GLuint uniform_MP, uniform_VM, uniform_tex; + static GLuint uniform_tex; static void init(); - static void setUniforms(const core::matrix4 &ViewProjectionMatrix, const core::matrix4 &ViewMatrix, unsigned TU_tex); + static void setUniforms(unsigned TU_tex); }; class InstancedGrassPass1Shader @@ -105,10 +105,10 @@ class InstancedGrassPass1Shader public: static GLuint Program; static GLuint attrib_position, attrib_normal, attrib_origin, attrib_orientation, attrib_scale, attrib_color, attrib_texcoord; - static GLuint uniform_MP, uniform_IVM, uniform_windDir, uniform_tex; + static GLuint uniform_windDir, uniform_tex; static void init(); - static void setUniforms(const core::matrix4 &ViewProjectionMatrix, const core::matrix4 &InverseViewMatrix, const core::vector3df &windDir, unsigned TU_tex); + static void setUniforms(const core::vector3df &windDir, unsigned TU_tex); }; class ObjectPass2Shader diff --git a/src/graphics/stkinstancedscenenode.cpp b/src/graphics/stkinstancedscenenode.cpp index 8350c38f3..b3dc3a3da 100644 --- a/src/graphics/stkinstancedscenenode.cpp +++ b/src/graphics/stkinstancedscenenode.cpp @@ -179,7 +179,7 @@ void STKInstancedSceneNode::addInstance(const core::vector3df &origin, const cor instance_pos.push_back(scale.Z); } -static void drawFSPMDefault(GLMesh &mesh, const core::matrix4 &ModelViewProjectionMatrix, size_t instance_count) +static void drawFSPMDefault(GLMesh &mesh, size_t instance_count) { irr_driver->IncreaseObjectCount(); GLenum ptype = mesh.PrimitiveType; @@ -187,7 +187,7 @@ static void drawFSPMDefault(GLMesh &mesh, const core::matrix4 &ModelViewProjecti size_t count = mesh.IndexCount; setTexture(0, mesh.textures[0], GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true); - MeshShader::InstancedObjectPass1Shader::setUniforms(ModelViewProjectionMatrix, irr_driver->getInvViewMatrix(), 0); + MeshShader::InstancedObjectPass1Shader::setUniforms(0); glBindVertexArray(mesh.vao_first_pass); glDrawElementsInstanced(ptype, count, itype, 0, instance_count); @@ -207,7 +207,7 @@ static void drawShadowDefault(GLMesh &mesh, size_t instance_count) glDrawElementsInstanced(ptype, count, itype, 0, instance_count); } -static void drawFSPMAlphaRefTexture(GLMesh &mesh, const core::matrix4 &ModelViewProjectionMatrix, size_t instance_count) +static void drawFSPMAlphaRefTexture(GLMesh &mesh, size_t instance_count) { irr_driver->IncreaseObjectCount(); GLenum ptype = mesh.PrimitiveType; @@ -215,7 +215,7 @@ static void drawFSPMAlphaRefTexture(GLMesh &mesh, const core::matrix4 &ModelView size_t count = mesh.IndexCount; setTexture(0, mesh.textures[0], GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true); - MeshShader::InstancedObjectRefPass1Shader::setUniforms(ModelViewProjectionMatrix, irr_driver->getInvViewMatrix(), 0); + MeshShader::InstancedObjectRefPass1Shader::setUniforms(0); glBindVertexArray(mesh.vao_first_pass); glDrawElementsInstanced(ptype, count, itype, 0, instance_count); @@ -236,7 +236,7 @@ static void drawShadowAlphaRefTexture(GLMesh &mesh, size_t instance_count) glDrawElementsInstanced(ptype, count, itype, 0, instance_count); } -static void drawFSPMGrass(GLMesh &mesh, const core::matrix4 &ModelViewProjectionMatrix, const core::vector3df &windDir, size_t instance_count) +static void drawFSPMGrass(GLMesh &mesh, const core::vector3df &windDir, size_t instance_count) { irr_driver->IncreaseObjectCount(); GLenum ptype = mesh.PrimitiveType; @@ -244,7 +244,7 @@ static void drawFSPMGrass(GLMesh &mesh, const core::matrix4 &ModelViewProjection size_t count = mesh.IndexCount; setTexture(0, mesh.textures[0], GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true); - MeshShader::InstancedGrassPass1Shader::setUniforms(ModelViewProjectionMatrix, irr_driver->getInvViewMatrix(), windDir, 0); + MeshShader::InstancedGrassPass1Shader::setUniforms(windDir, 0); glBindVertexArray(mesh.vao_first_pass); glDrawElementsInstanced(ptype, count, itype, 0, instance_count); @@ -315,18 +315,18 @@ void STKInstancedSceneNode::render() if (!GeometricMesh[FPSM_DEFAULT].empty()) glUseProgram(MeshShader::InstancedObjectPass1Shader::Program); for (unsigned i = 0; i < GeometricMesh[FPSM_DEFAULT].size(); i++) - drawFSPMDefault(*GeometricMesh[FPSM_DEFAULT][i], ModelViewProjectionMatrix, instance_pos.size() / 9); + drawFSPMDefault(*GeometricMesh[FPSM_DEFAULT][i], instance_pos.size() / 9); if (!GeometricMesh[FPSM_ALPHA_REF_TEXTURE].empty()) glUseProgram(MeshShader::InstancedObjectRefPass1Shader::Program); for (unsigned i = 0; i < GeometricMesh[FPSM_ALPHA_REF_TEXTURE].size(); i++) - drawFSPMAlphaRefTexture(*GeometricMesh[FPSM_ALPHA_REF_TEXTURE][i], ModelViewProjectionMatrix, instance_pos.size() / 9); + drawFSPMAlphaRefTexture(*GeometricMesh[FPSM_ALPHA_REF_TEXTURE][i], instance_pos.size() / 9); windDir = getWind(); if (!GeometricMesh[FPSM_GRASS].empty()) glUseProgram(MeshShader::InstancedGrassPass1Shader::Program); for (unsigned i = 0; i < GeometricMesh[FPSM_GRASS].size(); i++) - drawFSPMGrass(*GeometricMesh[FPSM_GRASS][i], ModelViewProjectionMatrix, windDir, instance_pos.size() / 9); + drawFSPMGrass(*GeometricMesh[FPSM_GRASS][i], windDir, instance_pos.size() / 9); return; } From 42482e0c41e2240e080e7369148571917d723495 Mon Sep 17 00:00:00 2001 From: vlj Date: Thu, 10 Apr 2014 17:34:57 +0200 Subject: [PATCH 21/21] Some more conversion --- data/shaders/normalmap.frag | 2 +- data/shaders/normalmap.vert | 14 +- data/shaders/object_pass.vert | 19 +- data/shaders/objectpass_rimlit.frag | 6 +- data/shaders/objectpass_rimlit.vert | 25 - data/shaders/objectpass_spheremap.frag | 15 +- data/shaders/sky.frag | 12 +- data/shaders/splatting.vert | 41 - data/shaders/untextured_object.vert | 13 +- src/graphics/render.cpp | 11 +- src/graphics/shaders.cpp | 2082 ++++++++++++------------ src/graphics/shaders.hpp | 48 +- src/graphics/stkanimatedmesh.cpp | 33 +- src/graphics/stkmesh.cpp | 12 +- src/graphics/stkmesh.hpp | 2 +- src/graphics/stkmeshscenenode.cpp | 57 +- 16 files changed, 1202 insertions(+), 1190 deletions(-) delete mode 100644 data/shaders/objectpass_rimlit.vert delete mode 100644 data/shaders/splatting.vert diff --git a/data/shaders/normalmap.frag b/data/shaders/normalmap.frag index c1d9120d9..109f35aa5 100644 --- a/data/shaders/normalmap.frag +++ b/data/shaders/normalmap.frag @@ -25,7 +25,7 @@ void main() vec3 Frag_normal = normalize(cross(Frag_tangent, bitangent)); vec3 Frag_bitangent = cross(Frag_normal, Frag_tangent); - vec3 FragmentNormal = TS_normal.x * Frag_tangent + TS_normal.y * Frag_bitangent - TS_normal.z * Frag_normal; + vec3 FragmentNormal = TS_normal.x * Frag_tangent + TS_normal.y * Frag_bitangent - TS_normal.z * Frag_normal; EncodedNormal.xy = 0.5 * EncodeNormal(normalize(FragmentNormal)) + 0.5; EncodedNormal.z = 1.; } diff --git a/data/shaders/normalmap.vert b/data/shaders/normalmap.vert index 5d5f79c21..eb5570ddd 100644 --- a/data/shaders/normalmap.vert +++ b/data/shaders/normalmap.vert @@ -1,6 +1,14 @@ -uniform mat4 ModelViewProjectionMatrix; -uniform mat4 TransposeInverseModelView; +layout (std140) uniform MatrixesData +{ + mat4 ViewMatrix; + mat4 ProjectionMatrix; + mat4 InverseViewMatrix; + mat4 InverseProjectionMatrix; + mat4 ShadowViewProjMatrixes[4]; +}; +uniform mat4 ModelMatrix; +uniform mat4 InverseModelMatrix; #if __VERSION__ >= 130 in vec3 Position; @@ -23,6 +31,8 @@ varying vec2 uv; void main() { + mat4 ModelViewProjectionMatrix = ProjectionMatrix * ViewMatrix * ModelMatrix; + mat4 TransposeInverseModelView = transpose(InverseModelMatrix * InverseViewMatrix); uv = Texcoord; tangent = (TransposeInverseModelView * vec4(Tangent, 1.)).xyz; bitangent = (TransposeInverseModelView * vec4(Bitangent, 1.)).xyz; diff --git a/data/shaders/object_pass.vert b/data/shaders/object_pass.vert index af55e8d33..8dda8cf74 100644 --- a/data/shaders/object_pass.vert +++ b/data/shaders/object_pass.vert @@ -1,5 +1,15 @@ -uniform mat4 ModelViewProjectionMatrix; -uniform mat4 TransposeInverseModelView; +layout (std140) uniform MatrixesData +{ + mat4 ViewMatrix; + mat4 ProjectionMatrix; + mat4 InverseViewMatrix; + mat4 InverseProjectionMatrix; + mat4 ShadowViewProjMatrixes[4]; +}; + +uniform mat4 ModelMatrix; +uniform mat4 InverseModelMatrix; + uniform mat4 TextureMatrix = mat4(1., 0., 0., 0., 0., 1., 0., 0., @@ -11,9 +21,11 @@ in vec3 Position; in vec2 Texcoord; in vec2 SecondTexcoord; in vec3 Normal; +in vec4 Color; out vec3 nor; out vec2 uv; out vec2 uv_bis; +out vec4 color; #else attribute vec3 Position; attribute vec3 Normal; @@ -27,6 +39,9 @@ varying vec2 uv_bis; void main(void) { + color = Color.zyxw; + mat4 ModelViewProjectionMatrix = ProjectionMatrix * ViewMatrix * ModelMatrix; + mat4 TransposeInverseModelView = transpose(InverseModelMatrix * InverseViewMatrix); gl_Position = ModelViewProjectionMatrix * vec4(Position, 1.); nor = (TransposeInverseModelView * vec4(Normal, 0.)).xyz; uv = (TextureMatrix * vec4(Texcoord, 1., 1.)).xy; diff --git a/data/shaders/objectpass_rimlit.frag b/data/shaders/objectpass_rimlit.frag index 907dd8e9f..f84862947 100644 --- a/data/shaders/objectpass_rimlit.frag +++ b/data/shaders/objectpass_rimlit.frag @@ -6,17 +6,17 @@ uniform vec2 screen; uniform vec3 ambient; #if __VERSION__ >= 130 -in vec3 normal; +in vec3 nor; in vec2 uv; out vec4 FragColor; #else -varying vec3 normal; +varying vec3 nor; varying vec2 uv; #define FragColor gl_FragColor #endif void main() { - float rim = 1.0 - dot(normal, vec3(0., 0., -1)); + float rim = 1.0 - dot(nor, vec3(0., 0., -1)); rim = smoothstep(0.5, 1.5, rim) * 0.35; vec4 color = texture(Albedo, uv); diff --git a/data/shaders/objectpass_rimlit.vert b/data/shaders/objectpass_rimlit.vert deleted file mode 100644 index 59f1feab3..000000000 --- a/data/shaders/objectpass_rimlit.vert +++ /dev/null @@ -1,25 +0,0 @@ -uniform mat4 ModelViewProjectionMatrix; -uniform mat4 TransposeInverseModelView; -uniform mat4 TextureMatrix; - -#if __VERSION__ >= 130 -in vec3 Position; -in vec3 Normal; -in vec2 Texcoord; -in vec4 Color; -out vec2 uv; -out vec3 normal; -#else -attribute vec3 Position; -attribute vec3 Normal; -attribute vec2 Texcoord; -attribute vec4 Color; -varying vec2 uv; -varying vec3 normal; -#endif - -void main() { - normal = (TransposeInverseModelView * vec4(Normal, 0)).xyz; - uv = (TextureMatrix * vec4(Texcoord, 1., 1.)).xy; - gl_Position = ModelViewProjectionMatrix * vec4(Position, 1.); -} diff --git a/data/shaders/objectpass_spheremap.frag b/data/shaders/objectpass_spheremap.frag index 13467bbad..c26ae5ab9 100644 --- a/data/shaders/objectpass_spheremap.frag +++ b/data/shaders/objectpass_spheremap.frag @@ -1,7 +1,14 @@ +layout (std140) uniform MatrixesData +{ + mat4 ViewMatrix; + mat4 ProjectionMatrix; + mat4 InverseViewMatrix; + mat4 InverseProjectionMatrix; + mat4 ShadowViewProjMatrixes[4]; +}; + uniform samplerCube tex; -uniform mat4 invproj; uniform vec2 screen; -uniform mat4 TransposeViewMatrix; #if __VERSION__ >= 130 in vec3 nor; @@ -15,12 +22,12 @@ varying vec3 nor; void main() { vec3 fpos = gl_FragCoord.xyz / vec3(screen, 1.); vec4 xpos = 2.0 * vec4(fpos, 1.0) - 1.0; - xpos = invproj * xpos; + xpos = InverseProjectionMatrix * xpos; xpos.xyz /= xpos.w; vec3 viewSampleDir = reflect(xpos.xyz, nor); // Convert sampleDir in world space (where tex was generated) - vec4 sampleDir = TransposeViewMatrix * vec4(viewSampleDir, 0.); + vec4 sampleDir = transpose(InverseViewMatrix) * vec4(viewSampleDir, 0.); vec4 detail0 = texture(tex, sampleDir.xyz); FragColor = vec4(detail0.xyz, 1.); diff --git a/data/shaders/sky.frag b/data/shaders/sky.frag index d6e44b383..d0ee9a0d3 100644 --- a/data/shaders/sky.frag +++ b/data/shaders/sky.frag @@ -1,5 +1,13 @@ +layout (std140) uniform MatrixesData +{ + mat4 ViewMatrix; + mat4 ProjectionMatrix; + mat4 InverseViewMatrix; + mat4 InverseProjectionMatrix; + mat4 ShadowViewProjMatrixes[4]; +}; + uniform samplerCube tex; -uniform mat4 InvProjView; uniform vec2 screen; @@ -14,7 +22,7 @@ void main(void) { vec3 eyedir = gl_FragCoord.xyz / vec3(screen, 1.); eyedir = 2.0 * eyedir - 1.0; - vec4 tmp = (InvProjView * vec4(eyedir, 1.)); + vec4 tmp = (InverseViewMatrix * InverseProjectionMatrix * vec4(eyedir, 1.)); eyedir = tmp.xyz / tmp.w; vec4 color = texture(tex, eyedir); FragColor = vec4(color.xyz, 1.); diff --git a/data/shaders/splatting.vert b/data/shaders/splatting.vert deleted file mode 100644 index 2e7743b19..000000000 --- a/data/shaders/splatting.vert +++ /dev/null @@ -1,41 +0,0 @@ -// SuperTuxKart - a fun racing game with go-kart -// Copyright (C) 2013 the SuperTuxKart team -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 3 -// of the License, or (at your option) any later version. -// -// This program 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 General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -uniform mat4 ModelViewProjectionMatrix; -uniform mat4 TransposeInverseModelView; - -#if __VERSION__ >= 130 -in vec3 Position; -in vec2 Texcoord; -in vec2 SecondTexcoord; -out vec2 uv; -out vec2 uv_bis; -#else -attribute vec3 Position; -attribute vec2 Texcoord; -attribute vec2 SecondTexcoord; -varying vec2 uv; -varying vec2 uv_bis; -#endif - - -void main() -{ - uv = Texcoord; - uv_bis = SecondTexcoord; - gl_Position = ModelViewProjectionMatrix * vec4(Position, 1.); -} diff --git a/data/shaders/untextured_object.vert b/data/shaders/untextured_object.vert index 36020e0db..b70cb67c3 100644 --- a/data/shaders/untextured_object.vert +++ b/data/shaders/untextured_object.vert @@ -1,4 +1,13 @@ -uniform mat4 ModelViewProjectionMatrix; +layout (std140) uniform MatrixesData +{ + mat4 ViewMatrix; + mat4 ProjectionMatrix; + mat4 InverseViewMatrix; + mat4 InverseProjectionMatrix; + mat4 ShadowViewProjMatrixes[4]; +}; + +uniform mat4 ModelMatrix; #if __VERSION__ >= 130 in vec3 Position; @@ -14,5 +23,5 @@ varying vec4 color; void main(void) { color = Color.zyxw; - gl_Position = ModelViewProjectionMatrix * vec4(Position, 1.); + gl_Position = ProjectionMatrix * ViewMatrix * ModelMatrix * vec4(Position, 1.); } diff --git a/src/graphics/render.cpp b/src/graphics/render.cpp index 09cb241a6..ce93dc9a6 100644 --- a/src/graphics/render.cpp +++ b/src/graphics/render.cpp @@ -464,6 +464,7 @@ void IrrDriver::renderSolidSecondPass() GroupedSM::reset(); GroupedSM::reset(); GroupedSM::reset(); + GroupedSM::reset(); setTexture(0, m_rtts->getRenderTarget(RTT_TMP1), GL_NEAREST, GL_NEAREST); setTexture(1, m_rtts->getRenderTarget(RTT_TMP2), GL_NEAREST, GL_NEAREST); setTexture(2, m_rtts->getRenderTarget(RTT_SSAO), GL_NEAREST, GL_NEAREST); @@ -497,6 +498,10 @@ void IrrDriver::renderSolidSecondPass() for (unsigned i = 0; i < GroupedSM::MeshSet.size(); i++) drawDetailledObjectPass2(*GroupedSM::MeshSet[i], GroupedSM::MVPSet[i]); + glUseProgram(MeshShader::UntexturedObjectShader::Program); + for (unsigned i = 0; i < GroupedSM::MeshSet.size(); i++) + drawUntexturedObject(*GroupedSM::MeshSet[i], GroupedSM::MVPSet[i]); + } void IrrDriver::renderTransparent() @@ -1328,7 +1333,7 @@ void IrrDriver::renderSkybox() glBindVertexArray(MeshShader::SkyboxShader::cubevao); glDisable(GL_CULL_FACE); assert(SkyboxTextures.size() == 6); - core::matrix4 transform = irr_driver->getProjViewMatrix(); + core::matrix4 translate; translate.setTranslation(camera->getAbsolutePosition()); @@ -1336,7 +1341,7 @@ void IrrDriver::renderSkybox() const f32 viewDistance = (camera->getNearValue() + camera->getFarValue()) * 0.5f; core::matrix4 scale; scale.setScale(core::vector3df(viewDistance, viewDistance, viewDistance)); - transform *= translate * scale; + core::matrix4 transform = translate * scale; core::matrix4 invtransform; transform.getInverse(invtransform); @@ -1345,7 +1350,7 @@ void IrrDriver::renderSkybox() glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glUseProgram(MeshShader::SkyboxShader::Program); - MeshShader::SkyboxShader::setUniforms(transform, invtransform, core::vector2df(UserConfigParams::m_width, UserConfigParams::m_height), 0); + MeshShader::SkyboxShader::setUniforms(transform, core::vector2df(UserConfigParams::m_width, UserConfigParams::m_height), 0); glDrawElements(GL_TRIANGLES, 6 * 6, GL_UNSIGNED_INT, 0); glBindVertexArray(0); } diff --git a/src/graphics/shaders.cpp b/src/graphics/shaders.cpp index 696205dc9..99c36818a 100644 --- a/src/graphics/shaders.cpp +++ b/src/graphics/shaders.cpp @@ -49,7 +49,7 @@ Shaders::Shaders() m_callbacks[ES_SHADOWGEN] = new ShadowGenProvider(); m_callbacks[ES_DISPLACE] = new DisplaceProvider(); - for(s32 i=0 ; i < ES_COUNT ; i++) + for (s32 i = 0; i < ES_COUNT; i++) m_shaders[i] = -1; loadShaders(); @@ -59,16 +59,16 @@ GLuint quad_vbo; static void initQuadVBO() { - const float quad_vertex[] = { - -1., -1., 0., 0., // UpperLeft - -1., 1., 0., 1., // LowerLeft - 1., -1., 1., 0., // UpperRight - 1., 1., 1., 1., // LowerRight - }; - glGenBuffers(1, &quad_vbo); - glBindBuffer(GL_ARRAY_BUFFER, quad_vbo); - glBufferData(GL_ARRAY_BUFFER, 16 * sizeof(float), quad_vertex, GL_STATIC_DRAW); - glBindBuffer(GL_ARRAY_BUFFER, 0); + const float quad_vertex[] = { + -1., -1., 0., 0., // UpperLeft + -1., 1., 0., 1., // LowerLeft + 1., -1., 1., 0., // UpperRight + 1., 1., 1., 1., // LowerRight + }; + glGenBuffers(1, &quad_vbo); + glBindBuffer(GL_ARRAY_BUFFER, quad_vbo); + glBufferData(GL_ARRAY_BUFFER, 16 * sizeof(float), quad_vertex, GL_STATIC_DRAW); + glBindBuffer(GL_ARRAY_BUFFER, 0); } // It should be possible to merge it with previous one... @@ -76,15 +76,15 @@ GLuint quad_buffer; static void initQuadBuffer() { - const float quad_vertex[] = { - -1., -1., -1., 1., // UpperLeft - -1., 1., -1., -1., // LowerLeft - 1., -1., 1., 1., // UpperRight - 1., 1., 1., -1., // LowerRight - }; - glGenBuffers(1, &quad_buffer); - glBindBuffer(GL_ARRAY_BUFFER, quad_buffer); - glBufferData(GL_ARRAY_BUFFER, 16 * sizeof(float), quad_vertex, GL_STATIC_DRAW); + const float quad_vertex[] = { + -1., -1., -1., 1., // UpperLeft + -1., 1., -1., -1., // LowerLeft + 1., -1., 1., 1., // UpperRight + 1., 1., 1., -1., // LowerRight + }; + glGenBuffers(1, &quad_buffer); + glBindBuffer(GL_ARRAY_BUFFER, quad_buffer); + glBufferData(GL_ARRAY_BUFFER, 16 * sizeof(float), quad_vertex, GL_STATIC_DRAW); } GLuint SharedObject::billboardvbo = 0; @@ -180,9 +180,9 @@ void Shaders::loadShaders() IGPUProgrammingServices * const gpu = irr_driver->getVideoDriver()->getGPUProgrammingServices(); - #define glsl(a, b, c) gpu->addHighLevelShaderMaterialFromFiles((a).c_str(), (b).c_str(), (IShaderConstantSetCallBack*) c) - #define glslmat(a, b, c, d) gpu->addHighLevelShaderMaterialFromFiles((a).c_str(), (b).c_str(), (IShaderConstantSetCallBack*) c, d) - #define glsl_noinput(a, b) gpu->addHighLevelShaderMaterialFromFiles((a).c_str(), (b).c_str(), (IShaderConstantSetCallBack*) 0) +#define glsl(a, b, c) gpu->addHighLevelShaderMaterialFromFiles((a).c_str(), (b).c_str(), (IShaderConstantSetCallBack*) c) +#define glslmat(a, b, c, d) gpu->addHighLevelShaderMaterialFromFiles((a).c_str(), (b).c_str(), (IShaderConstantSetCallBack*) c, d) +#define glsl_noinput(a, b) gpu->addHighLevelShaderMaterialFromFiles((a).c_str(), (b).c_str(), (IShaderConstantSetCallBack*) 0) // Save previous shaders (used in case some shaders don't compile) int saved_shaders[ES_COUNT]; @@ -193,41 +193,41 @@ void Shaders::loadShaders() m_shaders[ES_NORMAL_MAP_LIGHTMAP] = glsl_noinput(dir + "pass.vert", dir + "pass.frag"); m_shaders[ES_SKYBOX] = glslmat(dir + "pass.vert", dir + "pass.frag", - m_callbacks[ES_SKYBOX], EMT_TRANSPARENT_ALPHA_CHANNEL); + m_callbacks[ES_SKYBOX], EMT_TRANSPARENT_ALPHA_CHANNEL); m_shaders[ES_SPLATTING] = glsl_noinput(dir + "pass.vert", dir + "pass.frag"); m_shaders[ES_WATER] = glslmat(dir + "pass.vert", dir + "pass.frag", - m_callbacks[ES_WATER], EMT_TRANSPARENT_ALPHA_CHANNEL); + m_callbacks[ES_WATER], EMT_TRANSPARENT_ALPHA_CHANNEL); m_shaders[ES_WATER_SURFACE] = glsl(dir + "pass.vert", dir + "pass.frag", - m_callbacks[ES_WATER]); + m_callbacks[ES_WATER]); m_shaders[ES_SPHERE_MAP] = glsl_noinput(dir + "pass.vert", dir + "pass.frag"); m_shaders[ES_GRASS] = glslmat(dir + "pass.vert", dir + "pass.frag", - m_callbacks[ES_GRASS], EMT_TRANSPARENT_ALPHA_CHANNEL); + m_callbacks[ES_GRASS], EMT_TRANSPARENT_ALPHA_CHANNEL); m_shaders[ES_GRASS_REF] = glslmat(dir + "pass.vert", dir + "pass.frag", - m_callbacks[ES_GRASS], EMT_TRANSPARENT_ALPHA_CHANNEL_REF); + m_callbacks[ES_GRASS], EMT_TRANSPARENT_ALPHA_CHANNEL_REF); m_shaders[ES_BUBBLES] = glslmat(dir + "pass.vert", dir + "pass.frag", - m_callbacks[ES_BUBBLES], EMT_TRANSPARENT_ALPHA_CHANNEL); + m_callbacks[ES_BUBBLES], EMT_TRANSPARENT_ALPHA_CHANNEL); m_shaders[ES_RAIN] = glslmat(dir + "pass.vert", dir + "pass.frag", - m_callbacks[ES_RAIN], EMT_TRANSPARENT_ALPHA_CHANNEL); + m_callbacks[ES_RAIN], EMT_TRANSPARENT_ALPHA_CHANNEL); m_shaders[ES_MOTIONBLUR] = glsl(dir + "pass.vert", dir + "pass.frag", - m_callbacks[ES_MOTIONBLUR]); + m_callbacks[ES_MOTIONBLUR]); m_shaders[ES_GAUSSIAN3H] = glslmat(dir + "pass.vert", dir + "pass.frag", - m_callbacks[ES_GAUSSIAN3H], EMT_SOLID); + m_callbacks[ES_GAUSSIAN3H], EMT_SOLID); m_shaders[ES_GAUSSIAN3V] = glslmat(dir + "pass.vert", dir + "pass.frag", - m_callbacks[ES_GAUSSIAN3V], EMT_SOLID); + m_callbacks[ES_GAUSSIAN3V], EMT_SOLID); m_shaders[ES_MIPVIZ] = glslmat(dir + "pass.vert", dir + "pass.frag", - m_callbacks[ES_MIPVIZ], EMT_SOLID); + m_callbacks[ES_MIPVIZ], EMT_SOLID); m_shaders[ES_COLORIZE] = glslmat(dir + "pass.vert", dir + "pass.frag", - m_callbacks[ES_COLORIZE], EMT_SOLID); + m_callbacks[ES_COLORIZE], EMT_SOLID); m_shaders[ES_OBJECTPASS] = glsl_noinput(dir + "pass.vert", dir + "pass.frag"); m_shaders[ES_OBJECT_UNLIT] = glsl_noinput(dir + "pass.vert", dir + "pass.frag"); @@ -237,36 +237,36 @@ void Shaders::loadShaders() m_shaders[ES_SUNLIGHT] = glsl_noinput(dir + "pass.vert", dir + "pass.frag"); m_shaders[ES_SHADOWPASS] = glsl(dir + "pass.vert", dir + "pass.frag", - m_callbacks[ES_SHADOWPASS]); + m_callbacks[ES_SHADOWPASS]); m_shaders[ES_SHADOW_IMPORTANCE] = glsl(dir + "pass.vert", dir + "pass.frag", - m_callbacks[ES_SHADOW_IMPORTANCE]); + m_callbacks[ES_SHADOW_IMPORTANCE]); m_shaders[ES_COLLAPSE] = glsl(dir + "pass.vert", dir + "pass.frag", - m_callbacks[ES_COLLAPSE]); + m_callbacks[ES_COLLAPSE]); m_shaders[ES_SHADOW_WARPH] = glsl(dir + "pass.vert", dir + "pass.frag", - m_callbacks[ES_COLLAPSE]); + m_callbacks[ES_COLLAPSE]); m_shaders[ES_SHADOW_WARPV] = glsl(dir + "pass.vert", dir + "pass.frag", - m_callbacks[ES_COLLAPSE]); + m_callbacks[ES_COLLAPSE]); m_shaders[ES_MULTIPLY_ADD] = glslmat(dir + "pass.vert", dir + "pass.frag", - m_callbacks[ES_MULTIPLY_ADD], EMT_ONETEXTURE_BLEND); + m_callbacks[ES_MULTIPLY_ADD], EMT_ONETEXTURE_BLEND); m_shaders[ES_PENUMBRAH] = glslmat(dir + "pass.vert", dir + "pass.frag", - m_callbacks[ES_GAUSSIAN3H], EMT_SOLID); + m_callbacks[ES_GAUSSIAN3H], EMT_SOLID); m_shaders[ES_PENUMBRAV] = glslmat(dir + "pass.vert", dir + "pass.frag", - m_callbacks[ES_GAUSSIAN3H], EMT_SOLID); + m_callbacks[ES_GAUSSIAN3H], EMT_SOLID); m_shaders[ES_SHADOWGEN] = glslmat(dir + "pass.vert", dir + "pass.frag", - m_callbacks[ES_SHADOWGEN], EMT_SOLID); + m_callbacks[ES_SHADOWGEN], EMT_SOLID); m_shaders[ES_CAUSTICS] = glslmat(dir + "pass.vert", dir + "pass.frag", m_callbacks[ES_CAUSTICS], EMT_SOLID); m_shaders[ES_DISPLACE] = glsl(dir + "pass.vert", dir + "pass.frag", - m_callbacks[ES_DISPLACE]); + m_callbacks[ES_DISPLACE]); m_shaders[ES_PASSFAR] = glsl(dir + "pass.vert", dir + "pass.frag", - m_callbacks[ES_COLORIZE]); + m_callbacks[ES_COLORIZE]); // Check that all successfully loaded for (s32 i = 0; i < ES_COUNT; i++) { @@ -279,37 +279,37 @@ void Shaders::loadShaders() check(i); } - #undef glsl - #undef glslmat - #undef glsl_noinput +#undef glsl +#undef glslmat +#undef glsl_noinput // In case we're reloading and a shader didn't compile: keep the previous, working one - for(s32 i=0 ; i < ES_COUNT ; i++) + for (s32 i = 0; i < ES_COUNT; i++) { - if(m_shaders[i] == -1) + if (m_shaders[i] == -1) m_shaders[i] = saved_shaders[i]; } - initGL(); - initQuadVBO(); - initQuadBuffer(); + initGL(); + initQuadVBO(); + initQuadBuffer(); initBillboardVBO(); initCubeVBO(); initShadowVPMUBO(); - FullScreenShader::BloomBlendShader::init(); - FullScreenShader::BloomShader::init(); - FullScreenShader::ColorLevelShader::init(); - FullScreenShader::FogShader::init(); - FullScreenShader::Gaussian3HBlurShader::init(); - FullScreenShader::Gaussian3VBlurShader::init(); - FullScreenShader::Gaussian6HBlurShader::init(); - FullScreenShader::Gaussian6VBlurShader::init(); + FullScreenShader::BloomBlendShader::init(); + FullScreenShader::BloomShader::init(); + FullScreenShader::ColorLevelShader::init(); + FullScreenShader::FogShader::init(); + FullScreenShader::Gaussian3HBlurShader::init(); + FullScreenShader::Gaussian3VBlurShader::init(); + FullScreenShader::Gaussian6HBlurShader::init(); + FullScreenShader::Gaussian6VBlurShader::init(); FullScreenShader::PenumbraHShader::init(); FullScreenShader::PenumbraVShader::init(); - FullScreenShader::GlowShader::init(); - FullScreenShader::PassThroughShader::init(); - FullScreenShader::SSAOShader::init(); - FullScreenShader::SunLightShader::init(); + FullScreenShader::GlowShader::init(); + FullScreenShader::PassThroughShader::init(); + FullScreenShader::SSAOShader::init(); + FullScreenShader::SunLightShader::init(); FullScreenShader::DiffuseEnvMapShader::init(); FullScreenShader::ShadowedSunLightShader::init(); FullScreenShader::MotionBlurShader::init(); @@ -319,33 +319,33 @@ void Shaders::loadShaders() FullScreenShader::MLAAColorEdgeDetectionSHader::init(); FullScreenShader::MLAABlendWeightSHader::init(); FullScreenShader::MLAAGatherSHader::init(); - MeshShader::ColorizeShader::init(); - MeshShader::NormalMapShader::init(); - MeshShader::ObjectPass1Shader::init(); - MeshShader::ObjectRefPass1Shader::init(); + MeshShader::ColorizeShader::init(); + MeshShader::NormalMapShader::init(); + MeshShader::ObjectPass1Shader::init(); + MeshShader::ObjectRefPass1Shader::init(); MeshShader::InstancedObjectPass1Shader::init(); MeshShader::InstancedObjectRefPass1Shader::init(); MeshShader::InstancedGrassPass1Shader::init(); - MeshShader::ObjectPass2Shader::init(); + MeshShader::ObjectPass2Shader::init(); MeshShader::InstancedObjectPass2Shader::init(); MeshShader::InstancedObjectRefPass2Shader::init(); MeshShader::InstancedGrassPass2Shader::init(); - MeshShader::DetailledObjectPass2Shader::init(); - MeshShader::ObjectRimLimitShader::init(); - MeshShader::UntexturedObjectShader::init(); - MeshShader::ObjectRefPass2Shader::init(); - MeshShader::ObjectUnlitShader::init(); - MeshShader::SphereMapShader::init(); - MeshShader::SplattingShader::init(); - MeshShader::GrassPass1Shader::init(); - MeshShader::GrassPass2Shader::init(); + MeshShader::DetailledObjectPass2Shader::init(); + MeshShader::ObjectRimLimitShader::init(); + MeshShader::UntexturedObjectShader::init(); + MeshShader::ObjectRefPass2Shader::init(); + MeshShader::ObjectUnlitShader::init(); + MeshShader::SphereMapShader::init(); + MeshShader::SplattingShader::init(); + MeshShader::GrassPass1Shader::init(); + MeshShader::GrassPass2Shader::init(); MeshShader::CausticsShader::init(); - MeshShader::BubbleShader::init(); - MeshShader::TransparentShader::init(); + MeshShader::BubbleShader::init(); + MeshShader::TransparentShader::init(); MeshShader::TransparentFogShader::init(); - MeshShader::BillboardShader::init(); + MeshShader::BillboardShader::init(); LightShader::PointLightShader::init(); - MeshShader::DisplaceShader::init(); + MeshShader::DisplaceShader::init(); MeshShader::DisplaceMaskShader::init(); MeshShader::ShadowShader::init(); MeshShader::InstancedShadowShader::init(); @@ -353,13 +353,13 @@ void Shaders::loadShaders() MeshShader::InstancedRefShadowShader::init(); MeshShader::GrassShadowShader::init(); MeshShader::SkyboxShader::init(); - ParticleShader::FlipParticleRender::init(); - ParticleShader::HeightmapSimulationShader::init(); - ParticleShader::SimpleParticleRender::init(); - ParticleShader::SimpleSimulationShader::init(); - UIShader::ColoredRectShader::init(); - UIShader::ColoredTextureRectShader::init(); - UIShader::TextureRectShader::init(); + ParticleShader::FlipParticleRender::init(); + ParticleShader::HeightmapSimulationShader::init(); + ParticleShader::SimpleParticleRender::init(); + ParticleShader::SimpleSimulationShader::init(); + UIShader::ColoredRectShader::init(); + UIShader::ColoredTextureRectShader::init(); + UIShader::TextureRectShader::init(); UIShader::UniformColoredTextureRectShader::init(); } @@ -377,7 +377,7 @@ E_MATERIAL_TYPE Shaders::getShader(const ShaderType num) const { assert(num < ES_COUNT); - return (E_MATERIAL_TYPE) m_shaders[num]; + return (E_MATERIAL_TYPE)m_shaders[num]; } void Shaders::check(const int num) const @@ -385,7 +385,7 @@ void Shaders::check(const int num) const if (m_shaders[num] == -1) { Log::error("shaders", "Shader %s failed to load. Update your drivers, if the issue " - "persists, report a bug to us.", shader_names[num] + 3); + "persists, report a bug to us.", shader_names[num] + 3); } } @@ -393,66 +393,70 @@ namespace MeshShader { // Solid Normal and depth pass shaders - GLuint ObjectPass1Shader::Program; - GLuint ObjectPass1Shader::attrib_position; - GLuint ObjectPass1Shader::attrib_normal; + GLuint ObjectPass1Shader::Program; + GLuint ObjectPass1Shader::attrib_position; + GLuint ObjectPass1Shader::attrib_normal; GLuint ObjectPass1Shader::attrib_texcoord; - GLuint ObjectPass1Shader::uniform_MVP; - GLuint ObjectPass1Shader::uniform_TIMV; + GLuint ObjectPass1Shader::uniform_MM; + GLuint ObjectPass1Shader::uniform_IMM; GLuint ObjectPass1Shader::uniform_tex; - void ObjectPass1Shader::init() - { + void ObjectPass1Shader::init() + { Program = LoadProgram( GL_VERTEX_SHADER, file_manager->getAsset("shaders/object_pass.vert").c_str(), GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/encode_normal.frag").c_str(), GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/object_pass1.frag").c_str()); - attrib_position = glGetAttribLocation(Program, "Position"); - attrib_normal = glGetAttribLocation(Program, "Normal"); + attrib_position = glGetAttribLocation(Program, "Position"); + attrib_normal = glGetAttribLocation(Program, "Normal"); attrib_texcoord = glGetAttribLocation(Program, "Texcoord"); - uniform_MVP = glGetUniformLocation(Program, "ModelViewProjectionMatrix"); - uniform_TIMV = glGetUniformLocation(Program, "TransposeInverseModelView"); + uniform_MM = glGetUniformLocation(Program, "ModelMatrix"); + uniform_IMM = glGetUniformLocation(Program, "InverseModelMatrix"); uniform_tex = glGetUniformLocation(Program, "tex"); - } + GLuint uniform_ViewProjectionMatrixesUBO = glGetUniformBlockIndex(Program, "MatrixesData"); + glUniformBlockBinding(Program, uniform_ViewProjectionMatrixesUBO, 0); + } - void ObjectPass1Shader::setUniforms(const core::matrix4 &ModelViewProjectionMatrix, const core::matrix4 &TransposeInverseModelView, unsigned TU_tex) - { - glUniformMatrix4fv(uniform_MVP, 1, GL_FALSE, ModelViewProjectionMatrix.pointer()); - glUniformMatrix4fv(uniform_TIMV, 1, GL_FALSE, TransposeInverseModelView.pointer()); + void ObjectPass1Shader::setUniforms(const core::matrix4 &ModelMatrix, const core::matrix4 &InverseModelMatrix, unsigned TU_tex) + { + glUniformMatrix4fv(uniform_MM, 1, GL_FALSE, ModelMatrix.pointer()); + glUniformMatrix4fv(uniform_IMM, 1, GL_FALSE, InverseModelMatrix.pointer()); glUniform1i(uniform_tex, TU_tex); - } + } - GLuint ObjectRefPass1Shader::Program; - GLuint ObjectRefPass1Shader::attrib_position; - GLuint ObjectRefPass1Shader::attrib_normal; - GLuint ObjectRefPass1Shader::attrib_texcoord; - GLuint ObjectRefPass1Shader::uniform_MVP; - GLuint ObjectRefPass1Shader::uniform_TIMV; + GLuint ObjectRefPass1Shader::Program; + GLuint ObjectRefPass1Shader::attrib_position; + GLuint ObjectRefPass1Shader::attrib_normal; + GLuint ObjectRefPass1Shader::attrib_texcoord; + GLuint ObjectRefPass1Shader::uniform_MM; + GLuint ObjectRefPass1Shader::uniform_IMM; GLuint ObjectRefPass1Shader::uniform_TM; - GLuint ObjectRefPass1Shader::uniform_tex; + GLuint ObjectRefPass1Shader::uniform_tex; - void ObjectRefPass1Shader::init() - { - Program = LoadProgram( + void ObjectRefPass1Shader::init() + { + Program = LoadProgram( GL_VERTEX_SHADER, file_manager->getAsset("shaders/object_pass.vert").c_str(), GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/encode_normal.frag").c_str(), GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/objectref_pass1.frag").c_str()); - attrib_position = glGetAttribLocation(Program, "Position"); - attrib_normal = glGetAttribLocation(Program, "Normal"); - attrib_texcoord = glGetAttribLocation(Program, "Texcoord"); - uniform_MVP = glGetUniformLocation(Program, "ModelViewProjectionMatrix"); - uniform_TIMV = glGetUniformLocation(Program, "TransposeInverseModelView"); + attrib_position = glGetAttribLocation(Program, "Position"); + attrib_normal = glGetAttribLocation(Program, "Normal"); + attrib_texcoord = glGetAttribLocation(Program, "Texcoord"); + uniform_MM = glGetUniformLocation(Program, "ModelMatrix"); + uniform_IMM = glGetUniformLocation(Program, "InverseModelMatrix"); uniform_TM = glGetUniformLocation(Program, "TextureMatrix"); - uniform_tex = glGetUniformLocation(Program, "tex"); - } + uniform_tex = glGetUniformLocation(Program, "tex"); + GLuint uniform_ViewProjectionMatrixesUBO = glGetUniformBlockIndex(Program, "MatrixesData"); + glUniformBlockBinding(Program, uniform_ViewProjectionMatrixesUBO, 0); + } - void ObjectRefPass1Shader::setUniforms(const core::matrix4 &ModelViewProjectionMatrix, const core::matrix4 &TransposeInverseModelView, const core::matrix4 &TextureMatrix, unsigned TU_tex) - { - glUniformMatrix4fv(uniform_MVP, 1, GL_FALSE, ModelViewProjectionMatrix.pointer()); + void ObjectRefPass1Shader::setUniforms(const core::matrix4 &ModelMatrix, const core::matrix4 &InverseModelMatrix, const core::matrix4 &TextureMatrix, unsigned TU_tex) + { + glUniformMatrix4fv(uniform_MM, 1, GL_FALSE, ModelMatrix.pointer()); glUniformMatrix4fv(uniform_TM, 1, GL_FALSE, TextureMatrix.pointer()); - glUniformMatrix4fv(uniform_TIMV, 1, GL_FALSE, TransposeInverseModelView.pointer()); - glUniform1i(uniform_tex, TU_tex); - } + glUniformMatrix4fv(uniform_IMM, 1, GL_FALSE, InverseModelMatrix.pointer()); + glUniform1i(uniform_tex, TU_tex); + } GLuint GrassPass1Shader::Program; GLuint GrassPass1Shader::attrib_position; @@ -493,8 +497,8 @@ namespace MeshShader GLuint NormalMapShader::attrib_texcoord; GLuint NormalMapShader::attrib_tangent; GLuint NormalMapShader::attrib_bitangent; - GLuint NormalMapShader::uniform_MVP; - GLuint NormalMapShader::uniform_TIMV; + GLuint NormalMapShader::uniform_MM; + GLuint NormalMapShader::uniform_IMM; GLuint NormalMapShader::uniform_normalMap; void NormalMapShader::init() @@ -507,15 +511,17 @@ namespace MeshShader attrib_texcoord = glGetAttribLocation(Program, "Texcoord"); attrib_tangent = glGetAttribLocation(Program, "Tangent"); attrib_bitangent = glGetAttribLocation(Program, "Bitangent"); - uniform_MVP = glGetUniformLocation(Program, "ModelViewProjectionMatrix"); - uniform_TIMV = glGetUniformLocation(Program, "TransposeInverseModelView"); + uniform_MM = glGetUniformLocation(Program, "ModelMatrix"); + uniform_IMM = glGetUniformLocation(Program, "InverseModelMatrix"); uniform_normalMap = glGetUniformLocation(Program, "normalMap"); + GLuint uniform_ViewProjectionMatrixesUBO = glGetUniformBlockIndex(Program, "MatrixesData"); + glUniformBlockBinding(Program, uniform_ViewProjectionMatrixesUBO, 0); } - void NormalMapShader::setUniforms(const core::matrix4 &ModelViewProjectionMatrix, const core::matrix4 &TransposeInverseModelView, unsigned TU_normalMap) + void NormalMapShader::setUniforms(const core::matrix4 &ModelMatrix, const core::matrix4 &InverseModelMatrix, unsigned TU_normalMap) { - glUniformMatrix4fv(uniform_MVP, 1, GL_FALSE, ModelViewProjectionMatrix.pointer()); - glUniformMatrix4fv(uniform_TIMV, 1, GL_FALSE, TransposeInverseModelView.pointer()); + glUniformMatrix4fv(uniform_MM, 1, GL_FALSE, ModelMatrix.pointer()); + glUniformMatrix4fv(uniform_IMM, 1, GL_FALSE, InverseModelMatrix.pointer()); glUniform1i(uniform_normalMap, TU_normalMap); } @@ -620,31 +626,33 @@ namespace MeshShader // Solid Lit pass shaders - GLuint ObjectPass2Shader::Program; - GLuint ObjectPass2Shader::attrib_position; - GLuint ObjectPass2Shader::attrib_texcoord; - GLuint ObjectPass2Shader::uniform_MVP; + GLuint ObjectPass2Shader::Program; + GLuint ObjectPass2Shader::attrib_position; + GLuint ObjectPass2Shader::attrib_texcoord; + GLuint ObjectPass2Shader::uniform_MM; GLuint ObjectPass2Shader::uniform_TM; - GLuint ObjectPass2Shader::uniform_screen; - GLuint ObjectPass2Shader::uniform_ambient; + GLuint ObjectPass2Shader::uniform_screen; + GLuint ObjectPass2Shader::uniform_ambient; GLuint ObjectPass2Shader::TU_Albedo; - void ObjectPass2Shader::init() - { - Program = LoadProgram( + void ObjectPass2Shader::init() + { + Program = LoadProgram( GL_VERTEX_SHADER, file_manager->getAsset("shaders/object_pass.vert").c_str(), GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/getLightFactor.frag").c_str(), GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/object_pass2.frag").c_str()); - attrib_position = glGetAttribLocation(Program, "Position"); - attrib_texcoord = glGetAttribLocation(Program, "Texcoord"); - uniform_MVP = glGetUniformLocation(Program, "ModelViewProjectionMatrix"); + attrib_position = glGetAttribLocation(Program, "Position"); + attrib_texcoord = glGetAttribLocation(Program, "Texcoord"); + uniform_MM = glGetUniformLocation(Program, "ModelMatrix"); uniform_TM = glGetUniformLocation(Program, "TextureMatrix"); GLuint uniform_Albedo = glGetUniformLocation(Program, "Albedo"); GLuint uniform_DiffuseMap = glGetUniformLocation(Program, "DiffuseMap"); GLuint uniform_SpecularMap = glGetUniformLocation(Program, "SpecularMap"); GLuint uniform_SSAO = glGetUniformLocation(Program, "SSAO"); - uniform_screen = glGetUniformLocation(Program, "screen"); - uniform_ambient = glGetUniformLocation(Program, "ambient"); + uniform_screen = glGetUniformLocation(Program, "screen"); + uniform_ambient = glGetUniformLocation(Program, "ambient"); + GLuint uniform_ViewProjectionMatrixesUBO = glGetUniformBlockIndex(Program, "MatrixesData"); + glUniformBlockBinding(Program, uniform_ViewProjectionMatrixesUBO, 0); TU_Albedo = 3; glUseProgram(Program); @@ -653,16 +661,16 @@ namespace MeshShader glUniform1i(uniform_SSAO, 2); glUniform1i(uniform_Albedo, TU_Albedo); glUseProgram(0); - } + } - void ObjectPass2Shader::setUniforms(const core::matrix4 &ModelViewProjectionMatrix, const core::matrix4 &TextureMatrix) - { - glUniformMatrix4fv(uniform_MVP, 1, GL_FALSE, ModelViewProjectionMatrix.pointer()); + void ObjectPass2Shader::setUniforms(const core::matrix4 &ModelMatrix, const core::matrix4 &TextureMatrix) + { + glUniformMatrix4fv(uniform_MM, 1, GL_FALSE, ModelMatrix.pointer()); glUniformMatrix4fv(uniform_TM, 1, GL_FALSE, TextureMatrix.pointer()); - glUniform2f(uniform_screen, UserConfigParams::m_width, UserConfigParams::m_height); - const video::SColorf s = irr_driver->getSceneManager()->getAmbientLight(); - glUniform3f(uniform_ambient, s.r, s.g, s.b); - } + glUniform2f(uniform_screen, UserConfigParams::m_width, UserConfigParams::m_height); + const video::SColorf s = irr_driver->getSceneManager()->getAmbientLight(); + glUniform3f(uniform_ambient, s.r, s.g, s.b); + } GLuint InstancedObjectPass2Shader::Program; GLuint InstancedObjectPass2Shader::attrib_position; @@ -772,33 +780,35 @@ namespace MeshShader glUniform3f(uniform_ambient, s.r, s.g, s.b); } - GLuint DetailledObjectPass2Shader::Program; - GLuint DetailledObjectPass2Shader::attrib_position; - GLuint DetailledObjectPass2Shader::attrib_texcoord; - GLuint DetailledObjectPass2Shader::attrib_second_texcoord; - GLuint DetailledObjectPass2Shader::uniform_MVP; - GLuint DetailledObjectPass2Shader::uniform_screen; - GLuint DetailledObjectPass2Shader::uniform_ambient; + GLuint DetailledObjectPass2Shader::Program; + GLuint DetailledObjectPass2Shader::attrib_position; + GLuint DetailledObjectPass2Shader::attrib_texcoord; + GLuint DetailledObjectPass2Shader::attrib_second_texcoord; + GLuint DetailledObjectPass2Shader::uniform_MM; + GLuint DetailledObjectPass2Shader::uniform_screen; + GLuint DetailledObjectPass2Shader::uniform_ambient; GLuint DetailledObjectPass2Shader::TU_Albedo; GLuint DetailledObjectPass2Shader::TU_detail; - void DetailledObjectPass2Shader::init() - { - Program = LoadProgram( + void DetailledObjectPass2Shader::init() + { + Program = LoadProgram( GL_VERTEX_SHADER, file_manager->getAsset("shaders/object_pass.vert").c_str(), GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/getLightFactor.frag").c_str(), GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/detailledobject_pass2.frag").c_str()); - attrib_position = glGetAttribLocation(Program, "Position"); - attrib_texcoord = glGetAttribLocation(Program, "Texcoord"); - attrib_second_texcoord = glGetAttribLocation(Program, "SecondTexcoord"); - uniform_MVP = glGetUniformLocation(Program, "ModelViewProjectionMatrix"); + attrib_position = glGetAttribLocation(Program, "Position"); + attrib_texcoord = glGetAttribLocation(Program, "Texcoord"); + attrib_second_texcoord = glGetAttribLocation(Program, "SecondTexcoord"); + uniform_MM = glGetUniformLocation(Program, "ModelMatrix"); GLuint uniform_Albedo = glGetUniformLocation(Program, "Albedo"); GLuint uniform_Detail = glGetUniformLocation(Program, "Detail"); GLuint uniform_DiffuseMap = glGetUniformLocation(Program, "DiffuseMap"); GLuint uniform_SpecularMap = glGetUniformLocation(Program, "SpecularMap"); GLuint uniform_SSAO = glGetUniformLocation(Program, "SSAO"); uniform_screen = glGetUniformLocation(Program, "screen"); - uniform_ambient = glGetUniformLocation(Program, "ambient"); + uniform_ambient = glGetUniformLocation(Program, "ambient"); + GLuint uniform_ViewProjectionMatrixesUBO = glGetUniformBlockIndex(Program, "MatrixesData"); + glUniformBlockBinding(Program, uniform_ViewProjectionMatrixesUBO, 0); TU_Albedo = 3; TU_detail = 4; @@ -809,71 +819,76 @@ namespace MeshShader glUniform1i(uniform_Albedo, TU_Albedo); glUniform1i(uniform_Detail, TU_detail); glUseProgram(0); - } + } - void DetailledObjectPass2Shader::setUniforms(const core::matrix4 &ModelViewProjectionMatrix) - { - glUniformMatrix4fv(uniform_MVP, 1, GL_FALSE, ModelViewProjectionMatrix.pointer()); - glUniform2f(uniform_screen, UserConfigParams::m_width, UserConfigParams::m_height); - const video::SColorf s = irr_driver->getSceneManager()->getAmbientLight(); - glUniform3f(uniform_ambient, s.r, s.g, s.b); - } + void DetailledObjectPass2Shader::setUniforms(const core::matrix4 &ModelMatrix) + { + glUniformMatrix4fv(uniform_MM, 1, GL_FALSE, ModelMatrix.pointer()); + glUniform2f(uniform_screen, UserConfigParams::m_width, UserConfigParams::m_height); + const video::SColorf s = irr_driver->getSceneManager()->getAmbientLight(); + glUniform3f(uniform_ambient, s.r, s.g, s.b); + } - GLuint ObjectUnlitShader::Program; - GLuint ObjectUnlitShader::attrib_position; - GLuint ObjectUnlitShader::attrib_texcoord; - GLuint ObjectUnlitShader::uniform_MVP; - GLuint ObjectUnlitShader::TU_tex; + GLuint ObjectUnlitShader::Program; + GLuint ObjectUnlitShader::attrib_position; + GLuint ObjectUnlitShader::attrib_texcoord; + GLuint ObjectUnlitShader::uniform_MM; + GLuint ObjectUnlitShader::TU_tex; - void ObjectUnlitShader::init() - { - Program = LoadProgram( + void ObjectUnlitShader::init() + { + Program = LoadProgram( GL_VERTEX_SHADER, file_manager->getAsset("shaders/object_pass.vert").c_str(), GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/object_unlit.frag").c_str()); - attrib_position = glGetAttribLocation(Program, "Position"); - attrib_texcoord = glGetAttribLocation(Program, "Texcoord"); - uniform_MVP = glGetUniformLocation(Program, "ModelViewProjectionMatrix"); - GLuint uniform_tex = glGetUniformLocation(Program, "tex"); + attrib_position = glGetAttribLocation(Program, "Position"); + attrib_texcoord = glGetAttribLocation(Program, "Texcoord"); + uniform_MM = glGetUniformLocation(Program, "ModelMatrix"); + GLuint uniform_tex = glGetUniformLocation(Program, "tex"); + GLuint uniform_ViewProjectionMatrixesUBO = glGetUniformBlockIndex(Program, "MatrixesData"); + glUniformBlockBinding(Program, uniform_ViewProjectionMatrixesUBO, 0); TU_tex = 3; glUseProgram(Program); glUniform1i(uniform_tex, TU_tex); glUseProgram(0); - } + } - void ObjectUnlitShader::setUniforms(const core::matrix4 &ModelViewProjectionMatrix) - { - glUniformMatrix4fv(uniform_MVP, 1, GL_FALSE, ModelViewProjectionMatrix.pointer()); - } + void ObjectUnlitShader::setUniforms(const core::matrix4 &ModelMatrix) + { + glUniformMatrix4fv(uniform_MM, 1, GL_FALSE, ModelMatrix.pointer()); + } - GLuint ObjectRimLimitShader::Program; - GLuint ObjectRimLimitShader::attrib_position; - GLuint ObjectRimLimitShader::attrib_texcoord; - GLuint ObjectRimLimitShader::attrib_normal; - GLuint ObjectRimLimitShader::uniform_MVP; - GLuint ObjectRimLimitShader::uniform_TIMV; + GLuint ObjectRimLimitShader::Program; + GLuint ObjectRimLimitShader::attrib_position; + GLuint ObjectRimLimitShader::attrib_texcoord; + GLuint ObjectRimLimitShader::attrib_normal; + GLuint ObjectRimLimitShader::uniform_MM; + GLuint ObjectRimLimitShader::uniform_IMM; GLuint ObjectRimLimitShader::uniform_TM; - GLuint ObjectRimLimitShader::uniform_screen; - GLuint ObjectRimLimitShader::uniform_ambient; + GLuint ObjectRimLimitShader::uniform_screen; + GLuint ObjectRimLimitShader::uniform_ambient; GLuint ObjectRimLimitShader::TU_Albedo; - void ObjectRimLimitShader::init() - { - Program = LoadProgram( - GL_VERTEX_SHADER, file_manager->getAsset("shaders/objectpass_rimlit.vert").c_str(), + void ObjectRimLimitShader::init() + { + Program = LoadProgram( + GL_VERTEX_SHADER, file_manager->getAsset("shaders/object_pass.vert").c_str(), GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/objectpass_rimlit.frag").c_str()); - attrib_position = glGetAttribLocation(Program, "Position"); - attrib_texcoord = glGetAttribLocation(Program, "Texcoord"); - attrib_normal = glGetAttribLocation(Program, "Normal"); - uniform_MVP = glGetUniformLocation(Program, "ModelViewProjectionMatrix"); - uniform_TIMV = glGetUniformLocation(Program, "TransposeInverseModelView"); + attrib_position = glGetAttribLocation(Program, "Position"); + attrib_texcoord = glGetAttribLocation(Program, "Texcoord"); + attrib_normal = glGetAttribLocation(Program, "Normal"); + uniform_MM = glGetUniformLocation(Program, "ModelMatrix"); + uniform_IMM = glGetUniformLocation(Program, "InverseModelMatrix"); uniform_TM = glGetUniformLocation(Program, "TextureMatrix"); GLuint uniform_Albedo = glGetUniformLocation(Program, "Albedo"); GLuint uniform_DiffuseMap = glGetUniformLocation(Program, "DiffuseMap"); GLuint uniform_SpecularMap = glGetUniformLocation(Program, "SpecularMap"); GLuint uniform_SSAO = glGetUniformLocation(Program, "SSAO"); - uniform_screen = glGetUniformLocation(Program, "screen"); - uniform_ambient = glGetUniformLocation(Program, "ambient"); + uniform_screen = glGetUniformLocation(Program, "screen"); + uniform_ambient = glGetUniformLocation(Program, "ambient"); + GLuint uniform_tex = glGetUniformLocation(Program, "tex"); + GLuint uniform_ViewProjectionMatrixesUBO = glGetUniformBlockIndex(Program, "MatrixesData"); + glUniformBlockBinding(Program, uniform_ViewProjectionMatrixesUBO, 0); TU_Albedo = 3; glUseProgram(Program); @@ -882,82 +897,86 @@ namespace MeshShader glUniform1i(uniform_SSAO, 2); glUniform1i(uniform_Albedo, TU_Albedo); glUseProgram(0); - } + } - void ObjectRimLimitShader::setUniforms(const core::matrix4 &ModelViewProjectionMatrix, const core::matrix4 &TransposeInverseModelView, const core::matrix4 &TextureMatrix) - { - glUniformMatrix4fv(uniform_MVP, 1, GL_FALSE, ModelViewProjectionMatrix.pointer()); - glUniformMatrix4fv(uniform_TIMV, 1, GL_FALSE, TransposeInverseModelView.pointer()); + void ObjectRimLimitShader::setUniforms(const core::matrix4 &ModelMatrix, const core::matrix4 &InverseModelMatrix, const core::matrix4 &TextureMatrix) + { + glUniformMatrix4fv(uniform_MM, 1, GL_FALSE, ModelMatrix.pointer()); + glUniformMatrix4fv(uniform_IMM, 1, GL_FALSE, InverseModelMatrix.pointer()); glUniformMatrix4fv(uniform_TM, 1, GL_FALSE, TextureMatrix.pointer()); - glUniform2f(uniform_screen, UserConfigParams::m_width, UserConfigParams::m_height); - const video::SColorf s = irr_driver->getSceneManager()->getAmbientLight(); - glUniform3f(uniform_ambient, s.r, s.g, s.b); - } + glUniform2f(uniform_screen, UserConfigParams::m_width, UserConfigParams::m_height); + const video::SColorf s = irr_driver->getSceneManager()->getAmbientLight(); + glUniform3f(uniform_ambient, s.r, s.g, s.b); + } - GLuint UntexturedObjectShader::Program; - GLuint UntexturedObjectShader::attrib_position; - GLuint UntexturedObjectShader::attrib_color; - GLuint UntexturedObjectShader::uniform_MVP; - GLuint UntexturedObjectShader::uniform_screen; - GLuint UntexturedObjectShader::uniform_ambient; + GLuint UntexturedObjectShader::Program; + GLuint UntexturedObjectShader::attrib_position; + GLuint UntexturedObjectShader::attrib_color; + GLuint UntexturedObjectShader::uniform_MM; + GLuint UntexturedObjectShader::uniform_screen; + GLuint UntexturedObjectShader::uniform_ambient; - void UntexturedObjectShader::init() - { - Program = LoadProgram( - GL_VERTEX_SHADER, file_manager->getAsset("shaders/untextured_object.vert").c_str(), - GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/getLightFactor.frag").c_str(), - GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/untextured_object.frag").c_str()); - attrib_position = glGetAttribLocation(Program, "Position"); - attrib_color = glGetAttribLocation(Program, "Color"); - uniform_MVP = glGetUniformLocation(Program, "ModelViewProjectionMatrix"); - GLuint uniform_DiffuseMap = glGetUniformLocation(Program, "DiffuseMap"); - GLuint uniform_SpecularMap = glGetUniformLocation(Program, "SpecularMap"); - GLuint uniform_SSAO = glGetUniformLocation(Program, "SSAO"); - uniform_screen = glGetUniformLocation(Program, "screen"); - uniform_ambient = glGetUniformLocation(Program, "ambient"); + void UntexturedObjectShader::init() + { + Program = LoadProgram( + GL_VERTEX_SHADER, file_manager->getAsset("shaders/object_pass.vert").c_str(), + GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/getLightFactor.frag").c_str(), + GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/untextured_object.frag").c_str()); + attrib_position = glGetAttribLocation(Program, "Position"); + attrib_color = glGetAttribLocation(Program, "Color"); + uniform_MM = glGetUniformLocation(Program, "ModelMatrix"); + GLuint uniform_DiffuseMap = glGetUniformLocation(Program, "DiffuseMap"); + GLuint uniform_SpecularMap = glGetUniformLocation(Program, "SpecularMap"); + GLuint uniform_SSAO = glGetUniformLocation(Program, "SSAO"); + uniform_screen = glGetUniformLocation(Program, "screen"); + uniform_ambient = glGetUniformLocation(Program, "ambient"); + GLuint uniform_ViewProjectionMatrixesUBO = glGetUniformBlockIndex(Program, "MatrixesData"); + glUniformBlockBinding(Program, uniform_ViewProjectionMatrixesUBO, 0); - glUseProgram(Program); - glUniform1i(uniform_DiffuseMap, 0); - glUniform1i(uniform_SpecularMap, 1); - glUniform1i(uniform_SSAO, 2); - glUseProgram(0); - } + glUseProgram(Program); + glUniform1i(uniform_DiffuseMap, 0); + glUniform1i(uniform_SpecularMap, 1); + glUniform1i(uniform_SSAO, 2); + glUseProgram(0); + } - void UntexturedObjectShader::setUniforms(const core::matrix4 &ModelViewProjectionMatrix) - { - glUniformMatrix4fv(uniform_MVP, 1, GL_FALSE, ModelViewProjectionMatrix.pointer()); - glUniform2f(uniform_screen, UserConfigParams::m_width, UserConfigParams::m_height); - const video::SColorf s = irr_driver->getSceneManager()->getAmbientLight(); - glUniform3f(uniform_ambient, s.r, s.g, s.b); - } + void UntexturedObjectShader::setUniforms(const core::matrix4 &ModelMatrix) + { + glUniformMatrix4fv(uniform_MM, 1, GL_FALSE, ModelMatrix.pointer()); + glUniform2f(uniform_screen, UserConfigParams::m_width, UserConfigParams::m_height); + const video::SColorf s = irr_driver->getSceneManager()->getAmbientLight(); + glUniform3f(uniform_ambient, s.r, s.g, s.b); + } - GLuint ObjectRefPass2Shader::Program; - GLuint ObjectRefPass2Shader::attrib_position; - GLuint ObjectRefPass2Shader::attrib_texcoord; - GLuint ObjectRefPass2Shader::uniform_MVP; + GLuint ObjectRefPass2Shader::Program; + GLuint ObjectRefPass2Shader::attrib_position; + GLuint ObjectRefPass2Shader::attrib_texcoord; + GLuint ObjectRefPass2Shader::uniform_MM; GLuint ObjectRefPass2Shader::uniform_TM; - GLuint ObjectRefPass2Shader::uniform_screen; - GLuint ObjectRefPass2Shader::uniform_ambient; + GLuint ObjectRefPass2Shader::uniform_screen; + GLuint ObjectRefPass2Shader::uniform_ambient; GLuint ObjectRefPass2Shader::TU_Albedo; - void ObjectRefPass2Shader::init() - { - initGL(); - Program = LoadProgram( + void ObjectRefPass2Shader::init() + { + initGL(); + Program = LoadProgram( GL_VERTEX_SHADER, file_manager->getAsset("shaders/object_pass.vert").c_str(), GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/getLightFactor.frag").c_str(), GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/objectref_pass2.frag").c_str()); - attrib_position = glGetAttribLocation(Program, "Position"); - attrib_texcoord = glGetAttribLocation(Program, "Texcoord"); - uniform_MVP = glGetUniformLocation(Program, "ModelViewProjectionMatrix"); + attrib_position = glGetAttribLocation(Program, "Position"); + attrib_texcoord = glGetAttribLocation(Program, "Texcoord"); + uniform_MM = glGetUniformLocation(Program, "ModelMatrix"); uniform_TM = glGetUniformLocation(Program, "TextureMatrix"); GLuint uniform_Albedo = glGetUniformLocation(Program, "Albedo"); GLuint uniform_DiffuseMap = glGetUniformLocation(Program, "DiffuseMap"); GLuint uniform_SpecularMap = glGetUniformLocation(Program, "SpecularMap"); - GLuint uniform_SSAO = glGetUniformLocation(Program, "SSAO"); - uniform_screen = glGetUniformLocation(Program, "screen"); - uniform_ambient = glGetUniformLocation(Program, "ambient"); + GLuint uniform_SSAO = glGetUniformLocation(Program, "SSAO"); + uniform_screen = glGetUniformLocation(Program, "screen"); + uniform_ambient = glGetUniformLocation(Program, "ambient"); + GLuint uniform_ViewProjectionMatrixesUBO = glGetUniformBlockIndex(Program, "MatrixesData"); + glUniformBlockBinding(Program, uniform_ViewProjectionMatrixesUBO, 0); TU_Albedo = 3; glUseProgram(Program); @@ -966,44 +985,44 @@ namespace MeshShader glUniform1i(uniform_SSAO, 2); glUniform1i(uniform_Albedo, TU_Albedo); glUseProgram(0); - } + } - void ObjectRefPass2Shader::setUniforms(const core::matrix4 &ModelViewProjectionMatrix, const core::matrix4 &TextureMatrix) - { - glUniformMatrix4fv(uniform_MVP, 1, GL_FALSE, ModelViewProjectionMatrix.pointer()); + void ObjectRefPass2Shader::setUniforms(const core::matrix4 &ModelMatrix, const core::matrix4 &TextureMatrix) + { + glUniformMatrix4fv(uniform_MM, 1, GL_FALSE, ModelMatrix.pointer()); glUniformMatrix4fv(uniform_TM, 1, GL_FALSE, TextureMatrix.pointer()); - glUniform2f(uniform_screen, UserConfigParams::m_width, UserConfigParams::m_height); - const video::SColorf s = irr_driver->getSceneManager()->getAmbientLight(); - glUniform3f(uniform_ambient, s.r, s.g, s.b); - } + glUniform2f(uniform_screen, UserConfigParams::m_width, UserConfigParams::m_height); + const video::SColorf s = irr_driver->getSceneManager()->getAmbientLight(); + glUniform3f(uniform_ambient, s.r, s.g, s.b); + } - GLuint GrassPass2Shader::Program; - GLuint GrassPass2Shader::attrib_position; - GLuint GrassPass2Shader::attrib_texcoord; - GLuint GrassPass2Shader::attrib_color; - GLuint GrassPass2Shader::uniform_MVP; - GLuint GrassPass2Shader::uniform_screen; - GLuint GrassPass2Shader::uniform_ambient; - GLuint GrassPass2Shader::uniform_windDir; + GLuint GrassPass2Shader::Program; + GLuint GrassPass2Shader::attrib_position; + GLuint GrassPass2Shader::attrib_texcoord; + GLuint GrassPass2Shader::attrib_color; + GLuint GrassPass2Shader::uniform_MVP; + GLuint GrassPass2Shader::uniform_screen; + GLuint GrassPass2Shader::uniform_ambient; + GLuint GrassPass2Shader::uniform_windDir; GLuint GrassPass2Shader::TU_Albedo; - void GrassPass2Shader::init() - { - Program = LoadProgram( + void GrassPass2Shader::init() + { + Program = LoadProgram( GL_VERTEX_SHADER, file_manager->getAsset("shaders/grass_pass.vert").c_str(), GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/getLightFactor.frag").c_str(), GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/objectref_pass2.frag").c_str()); - attrib_position = glGetAttribLocation(Program, "Position"); - attrib_texcoord = glGetAttribLocation(Program, "Texcoord"); - attrib_color = glGetAttribLocation(Program, "Color"); - uniform_MVP = glGetUniformLocation(Program, "ModelViewProjectionMatrix"); + attrib_position = glGetAttribLocation(Program, "Position"); + attrib_texcoord = glGetAttribLocation(Program, "Texcoord"); + attrib_color = glGetAttribLocation(Program, "Color"); + uniform_MVP = glGetUniformLocation(Program, "ModelViewProjectionMatrix"); GLuint uniform_Albedo = glGetUniformLocation(Program, "Albedo"); GLuint uniform_DiffuseMap = glGetUniformLocation(Program, "DiffuseMap"); GLuint uniform_SpecularMap = glGetUniformLocation(Program, "SpecularMap"); GLuint uniform_SSAO = glGetUniformLocation(Program, "SSAO"); - uniform_screen = glGetUniformLocation(Program, "screen"); - uniform_ambient = glGetUniformLocation(Program, "ambient"); - uniform_windDir = glGetUniformLocation(Program, "windDir"); + uniform_screen = glGetUniformLocation(Program, "screen"); + uniform_ambient = glGetUniformLocation(Program, "ambient"); + uniform_windDir = glGetUniformLocation(Program, "windDir"); TU_Albedo = 3; glUseProgram(Program); @@ -1012,16 +1031,16 @@ namespace MeshShader glUniform1i(uniform_SSAO, 2); glUniform1i(uniform_Albedo, TU_Albedo); glUseProgram(0); - } + } - void GrassPass2Shader::setUniforms(const core::matrix4 &ModelViewProjectionMatrix, const core::vector3df &windDirection) - { - glUniformMatrix4fv(uniform_MVP, 1, GL_FALSE, ModelViewProjectionMatrix.pointer()); - glUniform2f(uniform_screen, UserConfigParams::m_width, UserConfigParams::m_height); - const video::SColorf s = irr_driver->getSceneManager()->getAmbientLight(); - glUniform3f(uniform_ambient, s.r, s.g, s.b); - glUniform3f(uniform_windDir, windDirection.X, windDirection.Y, windDirection.Z); - } + void GrassPass2Shader::setUniforms(const core::matrix4 &ModelViewProjectionMatrix, const core::vector3df &windDirection) + { + glUniformMatrix4fv(uniform_MVP, 1, GL_FALSE, ModelViewProjectionMatrix.pointer()); + glUniform2f(uniform_screen, UserConfigParams::m_width, UserConfigParams::m_height); + const video::SColorf s = irr_driver->getSceneManager()->getAmbientLight(); + glUniform3f(uniform_ambient, s.r, s.g, s.b); + glUniform3f(uniform_windDir, windDirection.X, windDirection.Y, windDirection.Z); + } GLuint InstancedGrassPass2Shader::Program; GLuint InstancedGrassPass2Shader::attrib_position; @@ -1094,67 +1113,61 @@ namespace MeshShader glUniform3f(uniform_windDir, windDirection.X, windDirection.Y, windDirection.Z); } - GLuint SphereMapShader::Program; - GLuint SphereMapShader::attrib_position; - GLuint SphereMapShader::attrib_normal; - GLuint SphereMapShader::uniform_MVP; - GLuint SphereMapShader::uniform_TIMV; - GLuint SphereMapShader::uniform_TVM; - GLuint SphereMapShader::uniform_invproj; + GLuint SphereMapShader::Program; + GLuint SphereMapShader::attrib_position; + GLuint SphereMapShader::attrib_normal; + GLuint SphereMapShader::uniform_MM; + GLuint SphereMapShader::uniform_IMM; GLuint SphereMapShader::uniform_screen; GLuint SphereMapShader::TU_tex; - void SphereMapShader::init() - { - Program = LoadProgram( + void SphereMapShader::init() + { + Program = LoadProgram( GL_VERTEX_SHADER, file_manager->getAsset("shaders/object_pass.vert").c_str(), GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/objectpass_spheremap.frag").c_str()); - attrib_position = glGetAttribLocation(Program, "Position"); - attrib_normal = glGetAttribLocation(Program, "Normal"); - uniform_MVP = glGetUniformLocation(Program, "ModelViewProjectionMatrix"); - uniform_TIMV = glGetUniformLocation(Program, "TransposeInverseModelView"); - uniform_TVM = glGetUniformLocation(Program, "TransposeViewMatrix"); + attrib_position = glGetAttribLocation(Program, "Position"); + attrib_normal = glGetAttribLocation(Program, "Normal"); + uniform_MM = glGetUniformLocation(Program, "ModelMatrix"); + uniform_IMM = glGetUniformLocation(Program, "InverseModelMatrix"); GLuint uniform_tex = glGetUniformLocation(Program, "tex"); - uniform_invproj = glGetUniformLocation(Program, "invproj"); uniform_screen = glGetUniformLocation(Program, "screen"); TU_tex = 3; glUseProgram(Program); glUniform1i(uniform_tex, TU_tex); glUseProgram(0); - } + } - void SphereMapShader::setUniforms(const core::matrix4 &ModelViewProjectionMatrix, const core::matrix4 &TransposeViewMatrix, const core::matrix4 &TransposeInverseModelView, const core::matrix4 &InvProj, const core::vector2df& screen) - { - glUniformMatrix4fv(uniform_MVP, 1, GL_FALSE, ModelViewProjectionMatrix.pointer()); - glUniformMatrix4fv(uniform_TIMV, 1, GL_FALSE, TransposeInverseModelView.pointer()); - glUniformMatrix4fv(uniform_TVM, 1, GL_FALSE, TransposeViewMatrix.pointer()); - glUniformMatrix4fv(uniform_invproj, 1, GL_FALSE, InvProj.pointer()); + void SphereMapShader::setUniforms(const core::matrix4 &ModelMatrix, const core::matrix4 &InverseModelMatrix, const core::vector2df& screen) + { + glUniformMatrix4fv(uniform_MM, 1, GL_FALSE, ModelMatrix.pointer()); + glUniformMatrix4fv(uniform_IMM, 1, GL_FALSE, InverseModelMatrix.pointer()); glUniform2f(uniform_screen, screen.X, screen.Y); - } + } - GLuint SplattingShader::Program; - GLuint SplattingShader::attrib_position; - GLuint SplattingShader::attrib_texcoord; - GLuint SplattingShader::attrib_second_texcoord; - GLuint SplattingShader::uniform_MVP; - GLuint SplattingShader::uniform_screen; - GLuint SplattingShader::uniform_ambient; + GLuint SplattingShader::Program; + GLuint SplattingShader::attrib_position; + GLuint SplattingShader::attrib_texcoord; + GLuint SplattingShader::attrib_second_texcoord; + GLuint SplattingShader::uniform_MM; + GLuint SplattingShader::uniform_screen; + GLuint SplattingShader::uniform_ambient; GLuint SplattingShader::TU_tex_layout; GLuint SplattingShader::TU_tex_detail0; GLuint SplattingShader::TU_tex_detail1; GLuint SplattingShader::TU_tex_detail2; GLuint SplattingShader::TU_tex_detail3; - void SplattingShader::init() - { - Program = LoadProgram( - GL_VERTEX_SHADER, file_manager->getAsset("shaders/splatting.vert").c_str(), + void SplattingShader::init() + { + Program = LoadProgram( + GL_VERTEX_SHADER, file_manager->getAsset("shaders/object_pass.vert").c_str(), GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/splatting.frag").c_str()); - attrib_position = glGetAttribLocation(Program, "Position"); - attrib_texcoord = glGetAttribLocation(Program, "Texcoord"); - attrib_second_texcoord = glGetAttribLocation(Program, "SecondTexcoord"); - uniform_MVP = glGetUniformLocation(Program, "ModelViewProjectionMatrix"); + attrib_position = glGetAttribLocation(Program, "Position"); + attrib_texcoord = glGetAttribLocation(Program, "Texcoord"); + attrib_second_texcoord = glGetAttribLocation(Program, "SecondTexcoord"); + uniform_MM = glGetUniformLocation(Program, "ModelMatrix"); GLuint uniform_tex_layout = glGetUniformLocation(Program, "tex_layout"); GLuint uniform_tex_detail0 = glGetUniformLocation(Program, "tex_detail0"); GLuint uniform_tex_detail1 = glGetUniformLocation(Program, "tex_detail1"); @@ -1163,8 +1176,8 @@ namespace MeshShader GLuint uniform_DiffuseMap = glGetUniformLocation(Program, "DiffuseMap"); GLuint uniform_SpecularMap = glGetUniformLocation(Program, "SpecularMap"); GLuint uniform_SSAO = glGetUniformLocation(Program, "SSAO"); - uniform_screen = glGetUniformLocation(Program, "screen"); - uniform_ambient = glGetUniformLocation(Program, "ambient"); + uniform_screen = glGetUniformLocation(Program, "screen"); + uniform_ambient = glGetUniformLocation(Program, "ambient"); TU_tex_layout = 3; TU_tex_detail0 = 4; TU_tex_detail1 = 5; @@ -1181,15 +1194,15 @@ namespace MeshShader glUniform1i(uniform_tex_detail2, TU_tex_detail2); glUniform1i(uniform_tex_detail3, TU_tex_detail3); glUseProgram(0); - } + } - void SplattingShader::setUniforms(const core::matrix4 &ModelViewProjectionMatrix) - { - glUniformMatrix4fv(uniform_MVP, 1, GL_FALSE, ModelViewProjectionMatrix.pointer()); - glUniform2f(uniform_screen, UserConfigParams::m_width, UserConfigParams::m_height); - const video::SColorf s = irr_driver->getSceneManager()->getAmbientLight(); - glUniform3f(uniform_ambient, s.r, s.g, s.b); - } + void SplattingShader::setUniforms(const core::matrix4 &ModelMatrix) + { + glUniformMatrix4fv(uniform_MM, 1, GL_FALSE, ModelMatrix.pointer()); + glUniform2f(uniform_screen, UserConfigParams::m_width, UserConfigParams::m_height); + const video::SColorf s = irr_driver->getSceneManager()->getAmbientLight(); + glUniform3f(uniform_ambient, s.r, s.g, s.b); + } GLuint CausticsShader::Program; GLuint CausticsShader::attrib_position; @@ -1242,61 +1255,61 @@ namespace MeshShader glUniform3f(uniform_ambient, s.r, s.g, s.b); } - GLuint BubbleShader::Program; - GLuint BubbleShader::attrib_position; - GLuint BubbleShader::attrib_texcoord; - GLuint BubbleShader::uniform_MVP; - GLuint BubbleShader::uniform_tex; - GLuint BubbleShader::uniform_time; - GLuint BubbleShader::uniform_transparency; + GLuint BubbleShader::Program; + GLuint BubbleShader::attrib_position; + GLuint BubbleShader::attrib_texcoord; + GLuint BubbleShader::uniform_MVP; + GLuint BubbleShader::uniform_tex; + GLuint BubbleShader::uniform_time; + GLuint BubbleShader::uniform_transparency; - void BubbleShader::init() - { - Program = LoadProgram( + void BubbleShader::init() + { + Program = LoadProgram( GL_VERTEX_SHADER, file_manager->getAsset("shaders/bubble.vert").c_str(), GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/bubble.frag").c_str()); - attrib_position = glGetAttribLocation(Program, "Position"); - attrib_texcoord = glGetAttribLocation(Program, "Texcoord"); - uniform_MVP = glGetUniformLocation(Program, "ModelViewProjectionMatrix"); - uniform_tex = glGetUniformLocation(Program, "tex"); - uniform_time = glGetUniformLocation(Program, "time"); - uniform_transparency = glGetUniformLocation(Program, "transparency"); - } + attrib_position = glGetAttribLocation(Program, "Position"); + attrib_texcoord = glGetAttribLocation(Program, "Texcoord"); + uniform_MVP = glGetUniformLocation(Program, "ModelViewProjectionMatrix"); + uniform_tex = glGetUniformLocation(Program, "tex"); + uniform_time = glGetUniformLocation(Program, "time"); + uniform_transparency = glGetUniformLocation(Program, "transparency"); + } void BubbleShader::setUniforms(const core::matrix4 &ModelViewProjectionMatrix, unsigned TU_tex, float time, float transparency) - { - glUniformMatrix4fv(uniform_MVP, 1, GL_FALSE, ModelViewProjectionMatrix.pointer()); - glUniform1i(uniform_tex, TU_tex); - glUniform1f(uniform_time, time); - glUniform1f(uniform_transparency, transparency); - } + { + glUniformMatrix4fv(uniform_MVP, 1, GL_FALSE, ModelViewProjectionMatrix.pointer()); + glUniform1i(uniform_tex, TU_tex); + glUniform1f(uniform_time, time); + glUniform1f(uniform_transparency, transparency); + } - GLuint TransparentShader::Program; - GLuint TransparentShader::attrib_position; - GLuint TransparentShader::attrib_texcoord; + GLuint TransparentShader::Program; + GLuint TransparentShader::attrib_position; + GLuint TransparentShader::attrib_texcoord; GLuint TransparentShader::attrib_color; - GLuint TransparentShader::uniform_MVP; + GLuint TransparentShader::uniform_MVP; GLuint TransparentShader::uniform_TM; - GLuint TransparentShader::uniform_tex; + GLuint TransparentShader::uniform_tex; - void TransparentShader::init() - { - Program = LoadProgram( + void TransparentShader::init() + { + Program = LoadProgram( GL_VERTEX_SHADER, file_manager->getAsset("shaders/transparent.vert").c_str(), GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/transparent.frag").c_str()); - attrib_position = glGetAttribLocation(Program, "Position"); - attrib_texcoord = glGetAttribLocation(Program, "Texcoord"); + attrib_position = glGetAttribLocation(Program, "Position"); + attrib_texcoord = glGetAttribLocation(Program, "Texcoord"); attrib_color = glGetAttribLocation(Program, "Color"); - uniform_MVP = glGetUniformLocation(Program, "ModelViewProjectionMatrix"); + uniform_MVP = glGetUniformLocation(Program, "ModelViewProjectionMatrix"); uniform_TM = glGetUniformLocation(Program, "TextureMatrix"); - uniform_tex = glGetUniformLocation(Program, "tex"); - } + uniform_tex = glGetUniformLocation(Program, "tex"); + } void TransparentShader::setUniforms(const core::matrix4 &ModelViewProjectionMatrix, const core::matrix4 &TextureMatrix, unsigned TU_tex) - { - glUniformMatrix4fv(uniform_MVP, 1, GL_FALSE, ModelViewProjectionMatrix.pointer()); + { + glUniformMatrix4fv(uniform_MVP, 1, GL_FALSE, ModelViewProjectionMatrix.pointer()); glUniformMatrix4fv(uniform_TM, 1, GL_FALSE, TextureMatrix.pointer()); - glUniform1i(uniform_tex, TU_tex); - } + glUniform1i(uniform_tex, TU_tex); + } GLuint TransparentFogShader::Program; GLuint TransparentFogShader::attrib_position; @@ -1349,59 +1362,59 @@ namespace MeshShader glUniformMatrix4fv(uniform_ipvmat, 1, GL_FALSE, ipvmat.pointer()); glUniform1i(uniform_tex, TU_tex); } - - GLuint BillboardShader::Program; - GLuint BillboardShader::attrib_corner; - GLuint BillboardShader::attrib_texcoord; - GLuint BillboardShader::uniform_MV; - GLuint BillboardShader::uniform_P; - GLuint BillboardShader::uniform_tex; - GLuint BillboardShader::uniform_Position; - GLuint BillboardShader::uniform_Size; - void BillboardShader::init() - { - Program = LoadProgram( + GLuint BillboardShader::Program; + GLuint BillboardShader::attrib_corner; + GLuint BillboardShader::attrib_texcoord; + GLuint BillboardShader::uniform_MV; + GLuint BillboardShader::uniform_P; + GLuint BillboardShader::uniform_tex; + GLuint BillboardShader::uniform_Position; + GLuint BillboardShader::uniform_Size; + + void BillboardShader::init() + { + Program = LoadProgram( GL_VERTEX_SHADER, file_manager->getAsset("shaders/billboard.vert").c_str(), GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/billboard.frag").c_str()); - attrib_corner = glGetAttribLocation(Program, "Corner"); - attrib_texcoord = glGetAttribLocation(Program, "Texcoord"); - uniform_MV = glGetUniformLocation(Program, "ModelViewMatrix"); - uniform_P = glGetUniformLocation(Program, "ProjectionMatrix"); - uniform_Position = glGetUniformLocation(Program, "Position"); - uniform_Size = glGetUniformLocation(Program, "Size"); - uniform_tex = glGetUniformLocation(Program, "tex"); - } + attrib_corner = glGetAttribLocation(Program, "Corner"); + attrib_texcoord = glGetAttribLocation(Program, "Texcoord"); + uniform_MV = glGetUniformLocation(Program, "ModelViewMatrix"); + uniform_P = glGetUniformLocation(Program, "ProjectionMatrix"); + uniform_Position = glGetUniformLocation(Program, "Position"); + uniform_Size = glGetUniformLocation(Program, "Size"); + uniform_tex = glGetUniformLocation(Program, "tex"); + } - void BillboardShader::setUniforms(const core::matrix4 &ModelViewMatrix, const core::matrix4 &ProjectionMatrix, const core::vector3df &Position, const core::dimension2d &size, unsigned TU_tex) - { - glUniformMatrix4fv(uniform_MV, 1, GL_FALSE, ModelViewMatrix.pointer()); - glUniformMatrix4fv(uniform_P, 1, GL_FALSE, ProjectionMatrix.pointer()); - glUniform3f(uniform_Position, Position.X, Position.Y, Position.Z); - glUniform2f(uniform_Size, size.Width, size.Height); - glUniform1i(uniform_tex, TU_tex); - } + void BillboardShader::setUniforms(const core::matrix4 &ModelViewMatrix, const core::matrix4 &ProjectionMatrix, const core::vector3df &Position, const core::dimension2d &size, unsigned TU_tex) + { + glUniformMatrix4fv(uniform_MV, 1, GL_FALSE, ModelViewMatrix.pointer()); + glUniformMatrix4fv(uniform_P, 1, GL_FALSE, ProjectionMatrix.pointer()); + glUniform3f(uniform_Position, Position.X, Position.Y, Position.Z); + glUniform2f(uniform_Size, size.Width, size.Height); + glUniform1i(uniform_tex, TU_tex); + } - GLuint ColorizeShader::Program; - GLuint ColorizeShader::attrib_position; - GLuint ColorizeShader::uniform_MVP; - GLuint ColorizeShader::uniform_col; + GLuint ColorizeShader::Program; + GLuint ColorizeShader::attrib_position; + GLuint ColorizeShader::uniform_MVP; + GLuint ColorizeShader::uniform_col; - void ColorizeShader::init() - { - Program = LoadProgram( + void ColorizeShader::init() + { + Program = LoadProgram( GL_VERTEX_SHADER, file_manager->getAsset("shaders/object_pass.vert").c_str(), GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/colorize.frag").c_str()); - attrib_position = glGetAttribLocation(Program, "Position"); - uniform_MVP = glGetUniformLocation(Program, "ModelViewProjectionMatrix"); - uniform_col = glGetUniformLocation(Program, "col"); - } + attrib_position = glGetAttribLocation(Program, "Position"); + uniform_MVP = glGetUniformLocation(Program, "ModelViewProjectionMatrix"); + uniform_col = glGetUniformLocation(Program, "col"); + } - void ColorizeShader::setUniforms(const core::matrix4 &ModelViewProjectionMatrix, float r, float g, float b) - { - glUniformMatrix4fv(uniform_MVP, 1, GL_FALSE, ModelViewProjectionMatrix.pointer()); - glUniform3f(uniform_col, r, g, b); - } + void ColorizeShader::setUniforms(const core::matrix4 &ModelViewProjectionMatrix, float r, float g, float b) + { + glUniformMatrix4fv(uniform_MVP, 1, GL_FALSE, ModelViewProjectionMatrix.pointer()); + glUniform3f(uniform_col, r, g, b); + } GLuint ShadowShader::Program; GLuint ShadowShader::attrib_position; @@ -1578,55 +1591,54 @@ namespace MeshShader glUniformMatrix4fv(uniform_MVP, 1, GL_FALSE, ModelViewProjectionMatrix.pointer()); } - GLuint DisplaceShader::Program; - GLuint DisplaceShader::attrib_position; - GLuint DisplaceShader::attrib_texcoord; - GLuint DisplaceShader::attrib_second_texcoord; - GLuint DisplaceShader::uniform_MVP; - GLuint DisplaceShader::uniform_MV; - GLuint DisplaceShader::uniform_displacement_tex; + GLuint DisplaceShader::Program; + GLuint DisplaceShader::attrib_position; + GLuint DisplaceShader::attrib_texcoord; + GLuint DisplaceShader::attrib_second_texcoord; + GLuint DisplaceShader::uniform_MVP; + GLuint DisplaceShader::uniform_MV; + GLuint DisplaceShader::uniform_displacement_tex; GLuint DisplaceShader::uniform_mask_tex; GLuint DisplaceShader::uniform_color_tex; - GLuint DisplaceShader::uniform_dir; - GLuint DisplaceShader::uniform_dir2; + GLuint DisplaceShader::uniform_dir; + GLuint DisplaceShader::uniform_dir2; GLuint DisplaceShader::uniform_screen; - void DisplaceShader::init() - { - Program = LoadProgram( + void DisplaceShader::init() + { + Program = LoadProgram( GL_VERTEX_SHADER, file_manager->getAsset("shaders/displace.vert").c_str(), GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/displace.frag").c_str()); - attrib_position = glGetAttribLocation(Program, "Position"); - attrib_texcoord = glGetAttribLocation(Program, "Texcoord"); - attrib_second_texcoord = glGetAttribLocation(Program, "SecondTexcoord"); - uniform_MVP = glGetUniformLocation(Program, "ModelViewProjectionMatrix"); - uniform_MV = glGetUniformLocation(Program, "ModelViewMatrix"); - uniform_displacement_tex = glGetUniformLocation(Program, "displacement_tex"); + attrib_position = glGetAttribLocation(Program, "Position"); + attrib_texcoord = glGetAttribLocation(Program, "Texcoord"); + attrib_second_texcoord = glGetAttribLocation(Program, "SecondTexcoord"); + uniform_MVP = glGetUniformLocation(Program, "ModelViewProjectionMatrix"); + uniform_MV = glGetUniformLocation(Program, "ModelViewMatrix"); + uniform_displacement_tex = glGetUniformLocation(Program, "displacement_tex"); uniform_color_tex = glGetUniformLocation(Program, "color_tex"); uniform_mask_tex = glGetUniformLocation(Program, "mask_tex"); - uniform_dir = glGetUniformLocation(Program, "dir"); - uniform_dir2 = glGetUniformLocation(Program, "dir2"); + uniform_dir = glGetUniformLocation(Program, "dir"); + uniform_dir2 = glGetUniformLocation(Program, "dir2"); uniform_screen = glGetUniformLocation(Program, "screen"); - } + } - void DisplaceShader::setUniforms(const core::matrix4 &ModelViewProjectionMatrix, const core::matrix4 &ModelViewMatrix, const core::vector2df &dir, const core::vector2df &dir2, const core::vector2df &screen, unsigned TU_displacement_tex, unsigned TU_mask_tex, unsigned TU_color_tex) - { - glUniformMatrix4fv(uniform_MVP, 1, GL_FALSE, ModelViewProjectionMatrix.pointer()); - glUniformMatrix4fv(uniform_MV, 1, GL_FALSE, ModelViewMatrix.pointer()); - glUniform2f(uniform_dir, dir.X, dir.Y); - glUniform2f(uniform_dir2, dir2.X, dir2.Y); + void DisplaceShader::setUniforms(const core::matrix4 &ModelViewProjectionMatrix, const core::matrix4 &ModelViewMatrix, const core::vector2df &dir, const core::vector2df &dir2, const core::vector2df &screen, unsigned TU_displacement_tex, unsigned TU_mask_tex, unsigned TU_color_tex) + { + glUniformMatrix4fv(uniform_MVP, 1, GL_FALSE, ModelViewProjectionMatrix.pointer()); + glUniformMatrix4fv(uniform_MV, 1, GL_FALSE, ModelViewMatrix.pointer()); + glUniform2f(uniform_dir, dir.X, dir.Y); + glUniform2f(uniform_dir2, dir2.X, dir2.Y); glUniform2f(uniform_screen, screen.X, screen.Y); - glUniform1i(uniform_displacement_tex, TU_displacement_tex); + glUniform1i(uniform_displacement_tex, TU_displacement_tex); glUniform1i(uniform_mask_tex, TU_mask_tex); glUniform1i(uniform_color_tex, TU_color_tex); - } + } GLuint SkyboxShader::Program; GLuint SkyboxShader::attrib_position; - GLuint SkyboxShader::uniform_MVP; + GLuint SkyboxShader::uniform_MM; GLuint SkyboxShader::uniform_tex; GLuint SkyboxShader::uniform_screen; - GLuint SkyboxShader::uniform_InvProjView; GLuint SkyboxShader::cubevao; void SkyboxShader::init() @@ -1635,10 +1647,11 @@ namespace MeshShader GL_VERTEX_SHADER, file_manager->getAsset("shaders/object_pass.vert").c_str(), GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/sky.frag").c_str()); attrib_position = glGetAttribLocation(Program, "Position"); - uniform_MVP = glGetUniformLocation(Program, "ModelViewProjectionMatrix"); - uniform_InvProjView = glGetUniformLocation(Program, "InvProjView"); + uniform_MM = glGetUniformLocation(Program, "ModelMatrix"); uniform_tex = glGetUniformLocation(Program, "tex"); uniform_screen = glGetUniformLocation(Program, "screen"); + GLuint uniform_ViewProjectionMatrixesUBO = glGetUniformBlockIndex(Program, "MatrixesData"); + glUniformBlockBinding(Program, uniform_ViewProjectionMatrixesUBO, 0); glGenVertexArrays(1, &cubevao); glBindVertexArray(cubevao); @@ -1649,10 +1662,9 @@ namespace MeshShader glBindVertexArray(0); } - void SkyboxShader::setUniforms(const core::matrix4 &ModelViewProjectionMatrix, const core::matrix4 &InvProjView, const core::vector2df &screen, unsigned TU_tex) + void SkyboxShader::setUniforms(const core::matrix4 &ModelMatrix, const core::vector2df &screen, unsigned TU_tex) { - glUniformMatrix4fv(uniform_MVP, 1, GL_FALSE, ModelViewProjectionMatrix.pointer()); - glUniformMatrix4fv(uniform_InvProjView, 1, GL_FALSE, InvProjView.pointer()); + glUniformMatrix4fv(uniform_MM, 1, GL_FALSE, ModelMatrix.pointer()); glUniform1i(uniform_tex, TU_tex); glUniform2f(uniform_screen, screen.X, screen.Y); } @@ -1735,306 +1747,306 @@ namespace LightShader namespace ParticleShader { - GLuint SimpleSimulationShader::Program; - GLuint SimpleSimulationShader::attrib_position; - GLuint SimpleSimulationShader::attrib_velocity; - GLuint SimpleSimulationShader::attrib_lifetime; - GLuint SimpleSimulationShader::attrib_initial_position; - GLuint SimpleSimulationShader::attrib_initial_velocity; - GLuint SimpleSimulationShader::attrib_initial_lifetime; - GLuint SimpleSimulationShader::attrib_size; - GLuint SimpleSimulationShader::attrib_initial_size; - GLuint SimpleSimulationShader::uniform_sourcematrix; - GLuint SimpleSimulationShader::uniform_dt; - GLuint SimpleSimulationShader::uniform_level; - GLuint SimpleSimulationShader::uniform_size_increase_factor; + GLuint SimpleSimulationShader::Program; + GLuint SimpleSimulationShader::attrib_position; + GLuint SimpleSimulationShader::attrib_velocity; + GLuint SimpleSimulationShader::attrib_lifetime; + GLuint SimpleSimulationShader::attrib_initial_position; + GLuint SimpleSimulationShader::attrib_initial_velocity; + GLuint SimpleSimulationShader::attrib_initial_lifetime; + GLuint SimpleSimulationShader::attrib_size; + GLuint SimpleSimulationShader::attrib_initial_size; + GLuint SimpleSimulationShader::uniform_sourcematrix; + GLuint SimpleSimulationShader::uniform_dt; + GLuint SimpleSimulationShader::uniform_level; + GLuint SimpleSimulationShader::uniform_size_increase_factor; - void SimpleSimulationShader::init() - { - const char *varyings[] = { - "new_particle_position", - "new_lifetime", - "new_particle_velocity", - "new_size", - }; - Program = LoadTFBProgram(file_manager->getAsset("shaders/pointemitter.vert").c_str(), varyings, 4); + void SimpleSimulationShader::init() + { + const char *varyings[] = { + "new_particle_position", + "new_lifetime", + "new_particle_velocity", + "new_size", + }; + Program = LoadTFBProgram(file_manager->getAsset("shaders/pointemitter.vert").c_str(), varyings, 4); - uniform_dt = glGetUniformLocation(Program, "dt"); - uniform_sourcematrix = glGetUniformLocation(Program, "sourcematrix"); - uniform_level = glGetUniformLocation(Program, "level"); - uniform_size_increase_factor = glGetUniformLocation(Program, "size_increase_factor"); + uniform_dt = glGetUniformLocation(Program, "dt"); + uniform_sourcematrix = glGetUniformLocation(Program, "sourcematrix"); + uniform_level = glGetUniformLocation(Program, "level"); + uniform_size_increase_factor = glGetUniformLocation(Program, "size_increase_factor"); - attrib_position = glGetAttribLocation(Program, "particle_position"); - attrib_lifetime = glGetAttribLocation(Program, "lifetime"); - attrib_velocity = glGetAttribLocation(Program, "particle_velocity"); - attrib_size = glGetAttribLocation(Program, "size"); - attrib_initial_position = glGetAttribLocation(Program, "particle_position_initial"); - attrib_initial_lifetime = glGetAttribLocation(Program, "lifetime_initial"); - attrib_initial_velocity = glGetAttribLocation(Program, "particle_velocity_initial"); - attrib_initial_size = glGetAttribLocation(Program, "size_initial"); - } + attrib_position = glGetAttribLocation(Program, "particle_position"); + attrib_lifetime = glGetAttribLocation(Program, "lifetime"); + attrib_velocity = glGetAttribLocation(Program, "particle_velocity"); + attrib_size = glGetAttribLocation(Program, "size"); + attrib_initial_position = glGetAttribLocation(Program, "particle_position_initial"); + attrib_initial_lifetime = glGetAttribLocation(Program, "lifetime_initial"); + attrib_initial_velocity = glGetAttribLocation(Program, "particle_velocity_initial"); + attrib_initial_size = glGetAttribLocation(Program, "size_initial"); + } - GLuint HeightmapSimulationShader::Program; - GLuint HeightmapSimulationShader::attrib_position; - GLuint HeightmapSimulationShader::attrib_velocity; - GLuint HeightmapSimulationShader::attrib_lifetime; - GLuint HeightmapSimulationShader::attrib_initial_position; - GLuint HeightmapSimulationShader::attrib_initial_velocity; - GLuint HeightmapSimulationShader::attrib_initial_lifetime; - GLuint HeightmapSimulationShader::attrib_size; - GLuint HeightmapSimulationShader::attrib_initial_size; - GLuint HeightmapSimulationShader::uniform_sourcematrix; - GLuint HeightmapSimulationShader::uniform_dt; - GLuint HeightmapSimulationShader::uniform_level; - GLuint HeightmapSimulationShader::uniform_size_increase_factor; - GLuint HeightmapSimulationShader::uniform_track_x; - GLuint HeightmapSimulationShader::uniform_track_z; - GLuint HeightmapSimulationShader::uniform_track_x_len; - GLuint HeightmapSimulationShader::uniform_track_z_len; - GLuint HeightmapSimulationShader::uniform_heightmap; + GLuint HeightmapSimulationShader::Program; + GLuint HeightmapSimulationShader::attrib_position; + GLuint HeightmapSimulationShader::attrib_velocity; + GLuint HeightmapSimulationShader::attrib_lifetime; + GLuint HeightmapSimulationShader::attrib_initial_position; + GLuint HeightmapSimulationShader::attrib_initial_velocity; + GLuint HeightmapSimulationShader::attrib_initial_lifetime; + GLuint HeightmapSimulationShader::attrib_size; + GLuint HeightmapSimulationShader::attrib_initial_size; + GLuint HeightmapSimulationShader::uniform_sourcematrix; + GLuint HeightmapSimulationShader::uniform_dt; + GLuint HeightmapSimulationShader::uniform_level; + GLuint HeightmapSimulationShader::uniform_size_increase_factor; + GLuint HeightmapSimulationShader::uniform_track_x; + GLuint HeightmapSimulationShader::uniform_track_z; + GLuint HeightmapSimulationShader::uniform_track_x_len; + GLuint HeightmapSimulationShader::uniform_track_z_len; + GLuint HeightmapSimulationShader::uniform_heightmap; - void HeightmapSimulationShader::init() - { - const char *varyings[] = { - "new_particle_position", - "new_lifetime", - "new_particle_velocity", - "new_size", - }; - Program = LoadTFBProgram(file_manager->getAsset("shaders/particlesimheightmap.vert").c_str(), varyings, 4); + void HeightmapSimulationShader::init() + { + const char *varyings[] = { + "new_particle_position", + "new_lifetime", + "new_particle_velocity", + "new_size", + }; + Program = LoadTFBProgram(file_manager->getAsset("shaders/particlesimheightmap.vert").c_str(), varyings, 4); - uniform_dt = glGetUniformLocation(Program, "dt"); - uniform_sourcematrix = glGetUniformLocation(Program, "sourcematrix"); - uniform_level = glGetUniformLocation(Program, "level"); - uniform_size_increase_factor = glGetUniformLocation(Program, "size_increase_factor"); + uniform_dt = glGetUniformLocation(Program, "dt"); + uniform_sourcematrix = glGetUniformLocation(Program, "sourcematrix"); + uniform_level = glGetUniformLocation(Program, "level"); + uniform_size_increase_factor = glGetUniformLocation(Program, "size_increase_factor"); - attrib_position = glGetAttribLocation(Program, "particle_position"); - attrib_lifetime = glGetAttribLocation(Program, "lifetime"); - attrib_velocity = glGetAttribLocation(Program, "particle_velocity"); - attrib_size = glGetAttribLocation(Program, "size"); - attrib_initial_position = glGetAttribLocation(Program, "particle_position_initial"); - attrib_initial_lifetime = glGetAttribLocation(Program, "lifetime_initial"); - attrib_initial_velocity = glGetAttribLocation(Program, "particle_velocity_initial"); - attrib_initial_size = glGetAttribLocation(Program, "size_initial"); + attrib_position = glGetAttribLocation(Program, "particle_position"); + attrib_lifetime = glGetAttribLocation(Program, "lifetime"); + attrib_velocity = glGetAttribLocation(Program, "particle_velocity"); + attrib_size = glGetAttribLocation(Program, "size"); + attrib_initial_position = glGetAttribLocation(Program, "particle_position_initial"); + attrib_initial_lifetime = glGetAttribLocation(Program, "lifetime_initial"); + attrib_initial_velocity = glGetAttribLocation(Program, "particle_velocity_initial"); + attrib_initial_size = glGetAttribLocation(Program, "size_initial"); - uniform_heightmap = glGetUniformLocation(Program, "heightmap"); - uniform_track_x = glGetUniformLocation(Program, "track_x"); - uniform_track_x_len = glGetUniformLocation(Program, "track_x_len"); - uniform_track_z = glGetUniformLocation(Program, "track_z"); - uniform_track_z_len = glGetUniformLocation(Program, "track_z_len"); - } + uniform_heightmap = glGetUniformLocation(Program, "heightmap"); + uniform_track_x = glGetUniformLocation(Program, "track_x"); + uniform_track_x_len = glGetUniformLocation(Program, "track_x_len"); + uniform_track_z = glGetUniformLocation(Program, "track_z"); + uniform_track_z_len = glGetUniformLocation(Program, "track_z_len"); + } - GLuint SimpleParticleRender::Program; - GLuint SimpleParticleRender::attrib_pos; - GLuint SimpleParticleRender::attrib_lf; - GLuint SimpleParticleRender::attrib_quadcorner; - GLuint SimpleParticleRender::attrib_texcoord; - GLuint SimpleParticleRender::attrib_sz; - GLuint SimpleParticleRender::uniform_matrix; - GLuint SimpleParticleRender::uniform_viewmatrix; - GLuint SimpleParticleRender::uniform_tex; - GLuint SimpleParticleRender::uniform_dtex; - GLuint SimpleParticleRender::uniform_screen; - GLuint SimpleParticleRender::uniform_invproj; + GLuint SimpleParticleRender::Program; + GLuint SimpleParticleRender::attrib_pos; + GLuint SimpleParticleRender::attrib_lf; + GLuint SimpleParticleRender::attrib_quadcorner; + GLuint SimpleParticleRender::attrib_texcoord; + GLuint SimpleParticleRender::attrib_sz; + GLuint SimpleParticleRender::uniform_matrix; + GLuint SimpleParticleRender::uniform_viewmatrix; + GLuint SimpleParticleRender::uniform_tex; + GLuint SimpleParticleRender::uniform_dtex; + GLuint SimpleParticleRender::uniform_screen; + GLuint SimpleParticleRender::uniform_invproj; GLuint SimpleParticleRender::uniform_color_from; GLuint SimpleParticleRender::uniform_color_to; - void SimpleParticleRender::init() - { + void SimpleParticleRender::init() + { Program = LoadProgram( GL_VERTEX_SHADER, file_manager->getAsset("shaders/particle.vert").c_str(), GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/particle.frag").c_str()); - attrib_pos = glGetAttribLocation(Program, "position"); - attrib_sz = glGetAttribLocation(Program, "size"); - attrib_lf = glGetAttribLocation(Program, "lifetime"); - attrib_quadcorner = glGetAttribLocation(Program, "quadcorner"); - attrib_texcoord = glGetAttribLocation(Program, "texcoord"); + attrib_pos = glGetAttribLocation(Program, "position"); + attrib_sz = glGetAttribLocation(Program, "size"); + attrib_lf = glGetAttribLocation(Program, "lifetime"); + attrib_quadcorner = glGetAttribLocation(Program, "quadcorner"); + attrib_texcoord = glGetAttribLocation(Program, "texcoord"); - uniform_matrix = glGetUniformLocation(Program, "ProjectionMatrix"); - uniform_viewmatrix = glGetUniformLocation(Program, "ViewMatrix"); - uniform_tex = glGetUniformLocation(Program, "tex"); - uniform_invproj = glGetUniformLocation(Program, "invproj"); - uniform_screen = glGetUniformLocation(Program, "screen"); - uniform_dtex = glGetUniformLocation(Program, "dtex"); + uniform_matrix = glGetUniformLocation(Program, "ProjectionMatrix"); + uniform_viewmatrix = glGetUniformLocation(Program, "ViewMatrix"); + uniform_tex = glGetUniformLocation(Program, "tex"); + uniform_invproj = glGetUniformLocation(Program, "invproj"); + uniform_screen = glGetUniformLocation(Program, "screen"); + uniform_dtex = glGetUniformLocation(Program, "dtex"); uniform_color_from = glGetUniformLocation(Program, "color_from"); assert(uniform_color_from != -1); uniform_color_to = glGetUniformLocation(Program, "color_to"); assert(uniform_color_to != -1); - } + } - void SimpleParticleRender::setUniforms(const core::matrix4 &ViewMatrix, const core::matrix4 &ProjMatrix, + void SimpleParticleRender::setUniforms(const core::matrix4 &ViewMatrix, const core::matrix4 &ProjMatrix, const core::matrix4 InvProjMatrix, float width, float height, unsigned TU_tex, unsigned TU_dtex, const ParticleSystemProxy* particle_system) - { - glUniformMatrix4fv(uniform_invproj, 1, GL_FALSE, InvProjMatrix.pointer()); - glUniform2f(uniform_screen, width, height); - glUniformMatrix4fv(uniform_matrix, 1, GL_FALSE, irr_driver->getProjMatrix().pointer()); - glUniformMatrix4fv(uniform_viewmatrix, 1, GL_FALSE, irr_driver->getViewMatrix().pointer()); - glUniform1i(uniform_tex, TU_tex); - glUniform1i(uniform_dtex, TU_dtex); + { + glUniformMatrix4fv(uniform_invproj, 1, GL_FALSE, InvProjMatrix.pointer()); + glUniform2f(uniform_screen, width, height); + glUniformMatrix4fv(uniform_matrix, 1, GL_FALSE, irr_driver->getProjMatrix().pointer()); + glUniformMatrix4fv(uniform_viewmatrix, 1, GL_FALSE, irr_driver->getViewMatrix().pointer()); + glUniform1i(uniform_tex, TU_tex); + glUniform1i(uniform_dtex, TU_dtex); const float* color_from = particle_system->getColorFrom(); const float* color_to = particle_system->getColorTo(); glUniform3f(uniform_color_from, color_from[0], color_from[1], color_from[2]); glUniform3f(uniform_color_to, color_to[0], color_to[1], color_to[2]); - } + } - GLuint FlipParticleRender::Program; - GLuint FlipParticleRender::attrib_pos; - GLuint FlipParticleRender::attrib_lf; - GLuint FlipParticleRender::attrib_quadcorner; - GLuint FlipParticleRender::attrib_texcoord; - GLuint FlipParticleRender::attrib_sz; - GLuint FlipParticleRender::attrib_rotationvec; - GLuint FlipParticleRender::attrib_anglespeed; - GLuint FlipParticleRender::uniform_matrix; - GLuint FlipParticleRender::uniform_viewmatrix; - GLuint FlipParticleRender::uniform_tex; - GLuint FlipParticleRender::uniform_dtex; - GLuint FlipParticleRender::uniform_screen; - GLuint FlipParticleRender::uniform_invproj; + GLuint FlipParticleRender::Program; + GLuint FlipParticleRender::attrib_pos; + GLuint FlipParticleRender::attrib_lf; + GLuint FlipParticleRender::attrib_quadcorner; + GLuint FlipParticleRender::attrib_texcoord; + GLuint FlipParticleRender::attrib_sz; + GLuint FlipParticleRender::attrib_rotationvec; + GLuint FlipParticleRender::attrib_anglespeed; + GLuint FlipParticleRender::uniform_matrix; + GLuint FlipParticleRender::uniform_viewmatrix; + GLuint FlipParticleRender::uniform_tex; + GLuint FlipParticleRender::uniform_dtex; + GLuint FlipParticleRender::uniform_screen; + GLuint FlipParticleRender::uniform_invproj; - void FlipParticleRender::init() - { - Program = LoadProgram( + void FlipParticleRender::init() + { + Program = LoadProgram( GL_VERTEX_SHADER, file_manager->getAsset("shaders/flipparticle.vert").c_str(), GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/particle.frag").c_str()); - attrib_pos = glGetAttribLocation(Program, "position"); - attrib_sz = glGetAttribLocation(Program, "size"); - attrib_lf = glGetAttribLocation(Program, "lifetime"); - attrib_quadcorner = glGetAttribLocation(Program, "quadcorner"); - attrib_texcoord = glGetAttribLocation(Program, "texcoord"); - attrib_anglespeed = glGetAttribLocation(Program, "anglespeed"); - attrib_rotationvec = glGetAttribLocation(Program, "rotationvec"); + attrib_pos = glGetAttribLocation(Program, "position"); + attrib_sz = glGetAttribLocation(Program, "size"); + attrib_lf = glGetAttribLocation(Program, "lifetime"); + attrib_quadcorner = glGetAttribLocation(Program, "quadcorner"); + attrib_texcoord = glGetAttribLocation(Program, "texcoord"); + attrib_anglespeed = glGetAttribLocation(Program, "anglespeed"); + attrib_rotationvec = glGetAttribLocation(Program, "rotationvec"); - uniform_matrix = glGetUniformLocation(Program, "ProjectionMatrix"); - uniform_viewmatrix = glGetUniformLocation(Program, "ViewMatrix"); - uniform_tex = glGetUniformLocation(Program, "tex"); - uniform_invproj = glGetUniformLocation(Program, "invproj"); - uniform_screen = glGetUniformLocation(Program, "screen"); - uniform_dtex = glGetUniformLocation(Program, "dtex"); - } + uniform_matrix = glGetUniformLocation(Program, "ProjectionMatrix"); + uniform_viewmatrix = glGetUniformLocation(Program, "ViewMatrix"); + uniform_tex = glGetUniformLocation(Program, "tex"); + uniform_invproj = glGetUniformLocation(Program, "invproj"); + uniform_screen = glGetUniformLocation(Program, "screen"); + uniform_dtex = glGetUniformLocation(Program, "dtex"); + } - void FlipParticleRender::setUniforms(const core::matrix4 &ViewMatrix, const core::matrix4 &ProjMatrix, const core::matrix4 InvProjMatrix, float width, float height, unsigned TU_tex, unsigned TU_dtex) - { - glUniformMatrix4fv(uniform_invproj, 1, GL_FALSE, InvProjMatrix.pointer()); - glUniform2f(uniform_screen, width, height); - glUniformMatrix4fv(uniform_matrix, 1, GL_FALSE, irr_driver->getProjMatrix().pointer()); - glUniformMatrix4fv(uniform_viewmatrix, 1, GL_FALSE, irr_driver->getViewMatrix().pointer()); - glUniform1i(uniform_tex, TU_tex); - glUniform1i(uniform_dtex, TU_dtex); - } + void FlipParticleRender::setUniforms(const core::matrix4 &ViewMatrix, const core::matrix4 &ProjMatrix, const core::matrix4 InvProjMatrix, float width, float height, unsigned TU_tex, unsigned TU_dtex) + { + glUniformMatrix4fv(uniform_invproj, 1, GL_FALSE, InvProjMatrix.pointer()); + glUniform2f(uniform_screen, width, height); + glUniformMatrix4fv(uniform_matrix, 1, GL_FALSE, irr_driver->getProjMatrix().pointer()); + glUniformMatrix4fv(uniform_viewmatrix, 1, GL_FALSE, irr_driver->getViewMatrix().pointer()); + glUniform1i(uniform_tex, TU_tex); + glUniform1i(uniform_dtex, TU_dtex); + } } static GLuint createVAO(GLuint Program) { - GLuint vao; - glGenVertexArrays(1, &vao); - glBindVertexArray(vao); - GLuint attrib_position = glGetAttribLocation(Program, "Position"); - GLuint attrib_texcoord = glGetAttribLocation(Program, "Texcoord"); - glBindBuffer(GL_ARRAY_BUFFER, quad_vbo); - glEnableVertexAttribArray(attrib_position); - glEnableVertexAttribArray(attrib_texcoord); - glVertexAttribPointer(attrib_position, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), 0); - glVertexAttribPointer(attrib_texcoord, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), (GLvoid*)(2 * sizeof(float))); - glBindVertexArray(0); - return vao; + GLuint vao; + glGenVertexArrays(1, &vao); + glBindVertexArray(vao); + GLuint attrib_position = glGetAttribLocation(Program, "Position"); + GLuint attrib_texcoord = glGetAttribLocation(Program, "Texcoord"); + glBindBuffer(GL_ARRAY_BUFFER, quad_vbo); + glEnableVertexAttribArray(attrib_position); + glEnableVertexAttribArray(attrib_texcoord); + glVertexAttribPointer(attrib_position, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), 0); + glVertexAttribPointer(attrib_texcoord, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), (GLvoid*)(2 * sizeof(float))); + glBindVertexArray(0); + return vao; } namespace FullScreenShader { - GLuint BloomShader::Program; - GLuint BloomShader::uniform_texture; - GLuint BloomShader::vao; - void BloomShader::init() - { - Program = LoadProgram( + GLuint BloomShader::Program; + GLuint BloomShader::uniform_texture; + GLuint BloomShader::vao; + void BloomShader::init() + { + Program = LoadProgram( GL_VERTEX_SHADER, file_manager->getAsset("shaders/screenquad.vert").c_str(), GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/getCIEXYZ.frag").c_str(), GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/bloom.frag").c_str()); - uniform_texture = glGetUniformLocation(Program, "tex"); - vao = createVAO(Program); - } + uniform_texture = glGetUniformLocation(Program, "tex"); + vao = createVAO(Program); + } void BloomShader::setUniforms(unsigned TU_tex) { glUniform1i(FullScreenShader::BloomShader::uniform_texture, TU_tex); } - GLuint BloomBlendShader::Program; - GLuint BloomBlendShader::uniform_texture; - GLuint BloomBlendShader::vao; - void BloomBlendShader::init() - { - Program = LoadProgram( - GL_VERTEX_SHADER, file_manager->getAsset("shaders/screenquad.vert").c_str(), + GLuint BloomBlendShader::Program; + GLuint BloomBlendShader::uniform_texture; + GLuint BloomBlendShader::vao; + void BloomBlendShader::init() + { + Program = LoadProgram( + GL_VERTEX_SHADER, file_manager->getAsset("shaders/screenquad.vert").c_str(), GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/bloomblend.frag").c_str()); - uniform_texture = glGetUniformLocation(Program, "tex"); - vao = createVAO(Program); - } + uniform_texture = glGetUniformLocation(Program, "tex"); + vao = createVAO(Program); + } void BloomBlendShader::setUniforms(unsigned TU_tex) { glUniform1i(FullScreenShader::BloomShader::uniform_texture, TU_tex); } - GLuint ColorLevelShader::Program; - GLuint ColorLevelShader::uniform_tex; + GLuint ColorLevelShader::Program; + GLuint ColorLevelShader::uniform_tex; GLuint ColorLevelShader::uniform_logluminancetex; - GLuint ColorLevelShader::uniform_inlevel; - GLuint ColorLevelShader::uniform_outlevel; - GLuint ColorLevelShader::vao; + GLuint ColorLevelShader::uniform_inlevel; + GLuint ColorLevelShader::uniform_outlevel; + GLuint ColorLevelShader::vao; GLuint ColorLevelShader::uniform_invprojm; GLuint ColorLevelShader::uniform_dtex; - void ColorLevelShader::init() - { + void ColorLevelShader::init() + { Program = LoadProgram( GL_VERTEX_SHADER, file_manager->getAsset("shaders/screenquad.vert").c_str(), GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/getRGBfromCIEXxy.frag").c_str(), GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/getCIEXYZ.frag").c_str(), GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/color_levels.frag").c_str()); - uniform_tex = glGetUniformLocation(Program, "tex"); + uniform_tex = glGetUniformLocation(Program, "tex"); uniform_logluminancetex = glGetUniformLocation(Program, "logluminancetex"); uniform_dtex = glGetUniformLocation(Program, "dtex"); - uniform_inlevel = glGetUniformLocation(Program, "inlevel"); - uniform_outlevel = glGetUniformLocation(Program, "outlevel"); + uniform_inlevel = glGetUniformLocation(Program, "inlevel"); + uniform_outlevel = glGetUniformLocation(Program, "outlevel"); uniform_invprojm = glGetUniformLocation(Program, "invprojm"); - vao = createVAO(Program); - } + vao = createVAO(Program); + } - GLuint SunLightShader::Program; - GLuint SunLightShader::uniform_ntex; - GLuint SunLightShader::uniform_dtex; - GLuint SunLightShader::uniform_direction; - GLuint SunLightShader::uniform_col; - GLuint SunLightShader::uniform_invproj; - GLuint SunLightShader::vao; + GLuint SunLightShader::Program; + GLuint SunLightShader::uniform_ntex; + GLuint SunLightShader::uniform_dtex; + GLuint SunLightShader::uniform_direction; + GLuint SunLightShader::uniform_col; + GLuint SunLightShader::uniform_invproj; + GLuint SunLightShader::vao; - void SunLightShader::init() - { + void SunLightShader::init() + { Program = LoadProgram( GL_VERTEX_SHADER, file_manager->getAsset("shaders/screenquad.vert").c_str(), GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/decodeNormal.frag").c_str(), GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/getSpecular.frag").c_str(), GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/sunlight.frag").c_str()); - uniform_ntex = glGetUniformLocation(Program, "ntex"); - uniform_dtex = glGetUniformLocation(Program, "dtex"); - uniform_direction = glGetUniformLocation(Program, "direction"); - uniform_col = glGetUniformLocation(Program, "col"); - uniform_invproj = glGetUniformLocation(Program, "invproj"); - vao = createVAO(Program); - } + uniform_ntex = glGetUniformLocation(Program, "ntex"); + uniform_dtex = glGetUniformLocation(Program, "dtex"); + uniform_direction = glGetUniformLocation(Program, "direction"); + uniform_col = glGetUniformLocation(Program, "col"); + uniform_invproj = glGetUniformLocation(Program, "invproj"); + vao = createVAO(Program); + } - void SunLightShader::setUniforms(const core::vector3df &direction, const core::matrix4 &InvProjMatrix, float r, float g, float b, unsigned TU_ntex, unsigned TU_dtex) - { - glUniformMatrix4fv(uniform_invproj, 1, GL_FALSE, InvProjMatrix.pointer()); - glUniform3f(uniform_direction, direction.X, direction.Y, direction.Z); - glUniform3f(uniform_col, r, g, b); - glUniform1i(uniform_ntex, TU_ntex); - glUniform1i(uniform_dtex, TU_dtex); - } + void SunLightShader::setUniforms(const core::vector3df &direction, const core::matrix4 &InvProjMatrix, float r, float g, float b, unsigned TU_ntex, unsigned TU_dtex) + { + glUniformMatrix4fv(uniform_invproj, 1, GL_FALSE, InvProjMatrix.pointer()); + glUniform3f(uniform_direction, direction.X, direction.Y, direction.Z); + glUniform3f(uniform_col, r, g, b); + glUniform1i(uniform_ntex, TU_ntex); + glUniform1i(uniform_dtex, TU_dtex); + } GLuint DiffuseEnvMapShader::Program; GLuint DiffuseEnvMapShader::uniform_ntex; @@ -2112,61 +2124,61 @@ namespace FullScreenShader delete[] tmp; } - GLuint Gaussian6HBlurShader::Program; - GLuint Gaussian6HBlurShader::uniform_tex; - GLuint Gaussian6HBlurShader::uniform_pixel; - GLuint Gaussian6HBlurShader::vao; - void Gaussian6HBlurShader::init() - { - Program = LoadProgram( + GLuint Gaussian6HBlurShader::Program; + GLuint Gaussian6HBlurShader::uniform_tex; + GLuint Gaussian6HBlurShader::uniform_pixel; + GLuint Gaussian6HBlurShader::vao; + void Gaussian6HBlurShader::init() + { + Program = LoadProgram( GL_VERTEX_SHADER, file_manager->getAsset("shaders/screenquad.vert").c_str(), GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/gaussian6h.frag").c_str()); - uniform_tex = glGetUniformLocation(Program, "tex"); - uniform_pixel = glGetUniformLocation(Program, "pixel"); - vao = createVAO(Program); - } + uniform_tex = glGetUniformLocation(Program, "tex"); + uniform_pixel = glGetUniformLocation(Program, "pixel"); + vao = createVAO(Program); + } - GLuint Gaussian3HBlurShader::Program; - GLuint Gaussian3HBlurShader::uniform_tex; - GLuint Gaussian3HBlurShader::uniform_pixel; - GLuint Gaussian3HBlurShader::vao; - void Gaussian3HBlurShader::init() - { - Program = LoadProgram( + GLuint Gaussian3HBlurShader::Program; + GLuint Gaussian3HBlurShader::uniform_tex; + GLuint Gaussian3HBlurShader::uniform_pixel; + GLuint Gaussian3HBlurShader::vao; + void Gaussian3HBlurShader::init() + { + Program = LoadProgram( GL_VERTEX_SHADER, file_manager->getAsset("shaders/screenquad.vert").c_str(), GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/gaussian3h.frag").c_str()); - uniform_tex = glGetUniformLocation(Program, "tex"); - uniform_pixel = glGetUniformLocation(Program, "pixel"); - vao = createVAO(Program); - } + uniform_tex = glGetUniformLocation(Program, "tex"); + uniform_pixel = glGetUniformLocation(Program, "pixel"); + vao = createVAO(Program); + } - GLuint Gaussian6VBlurShader::Program; - GLuint Gaussian6VBlurShader::uniform_tex; - GLuint Gaussian6VBlurShader::uniform_pixel; - GLuint Gaussian6VBlurShader::vao; - void Gaussian6VBlurShader::init() - { - Program = LoadProgram( + GLuint Gaussian6VBlurShader::Program; + GLuint Gaussian6VBlurShader::uniform_tex; + GLuint Gaussian6VBlurShader::uniform_pixel; + GLuint Gaussian6VBlurShader::vao; + void Gaussian6VBlurShader::init() + { + Program = LoadProgram( GL_VERTEX_SHADER, file_manager->getAsset("shaders/screenquad.vert").c_str(), GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/gaussian6v.frag").c_str()); - uniform_tex = glGetUniformLocation(Program, "tex"); - uniform_pixel = glGetUniformLocation(Program, "pixel"); - vao = createVAO(Program); - } + uniform_tex = glGetUniformLocation(Program, "tex"); + uniform_pixel = glGetUniformLocation(Program, "pixel"); + vao = createVAO(Program); + } - GLuint Gaussian3VBlurShader::Program; - GLuint Gaussian3VBlurShader::uniform_tex; - GLuint Gaussian3VBlurShader::uniform_pixel; - GLuint Gaussian3VBlurShader::vao; - void Gaussian3VBlurShader::init() - { - Program = LoadProgram( + GLuint Gaussian3VBlurShader::Program; + GLuint Gaussian3VBlurShader::uniform_tex; + GLuint Gaussian3VBlurShader::uniform_pixel; + GLuint Gaussian3VBlurShader::vao; + void Gaussian3VBlurShader::init() + { + Program = LoadProgram( GL_VERTEX_SHADER, file_manager->getAsset("shaders/screenquad.vert").c_str(), GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/gaussian3v.frag").c_str()); - uniform_tex = glGetUniformLocation(Program, "tex"); - uniform_pixel = glGetUniformLocation(Program, "pixel"); - vao = createVAO(Program); - } + uniform_tex = glGetUniformLocation(Program, "tex"); + uniform_pixel = glGetUniformLocation(Program, "pixel"); + vao = createVAO(Program); + } GLuint PenumbraHShader::Program; GLuint PenumbraHShader::uniform_tex; @@ -2216,7 +2228,7 @@ namespace FullScreenShader void ShadowGenShader::init() { Program = LoadProgram( - GL_VERTEX_SHADER, file_manager->getAsset("shaders/screenquad.vert").c_str(), + GL_VERTEX_SHADER, file_manager->getAsset("shaders/screenquad.vert").c_str(), GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/shadowgen.frag").c_str()); uniform_halft = glGetUniformLocation(Program, "halft"); uniform_quarter = glGetUniformLocation(Program, "quarter"); @@ -2231,217 +2243,217 @@ namespace FullScreenShader glUniform1i(uniform_height, TU_height); } - GLuint PassThroughShader::Program; - GLuint PassThroughShader::uniform_texture; - GLuint PassThroughShader::vao; - void PassThroughShader::init() - { - Program = LoadProgram( + GLuint PassThroughShader::Program; + GLuint PassThroughShader::uniform_texture; + GLuint PassThroughShader::vao; + void PassThroughShader::init() + { + Program = LoadProgram( GL_VERTEX_SHADER, file_manager->getAsset("shaders/screenquad.vert").c_str(), GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/texturedquad.frag").c_str()); - uniform_texture = glGetUniformLocation(Program, "texture"); - vao = createVAO(Program); - } + uniform_texture = glGetUniformLocation(Program, "texture"); + vao = createVAO(Program); + } - GLuint GlowShader::Program; - GLuint GlowShader::uniform_tex; - GLuint GlowShader::vao; - void GlowShader::init() - { - Program = LoadProgram( + GLuint GlowShader::Program; + GLuint GlowShader::uniform_tex; + GLuint GlowShader::vao; + void GlowShader::init() + { + Program = LoadProgram( GL_VERTEX_SHADER, file_manager->getAsset("shaders/screenquad.vert").c_str(), GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/glow.frag").c_str()); - uniform_tex = glGetUniformLocation(Program, "tex"); - vao = createVAO(Program); - } + uniform_tex = glGetUniformLocation(Program, "tex"); + vao = createVAO(Program); + } - GLuint SSAOShader::Program; - GLuint SSAOShader::uniform_ntex; - GLuint SSAOShader::uniform_dtex; - GLuint SSAOShader::uniform_noise_texture; - GLuint SSAOShader::uniform_invprojm; - GLuint SSAOShader::uniform_projm; - GLuint SSAOShader::uniform_samplePoints; - GLuint SSAOShader::vao; - float SSAOShader::SSAOSamples[64]; + GLuint SSAOShader::Program; + GLuint SSAOShader::uniform_ntex; + GLuint SSAOShader::uniform_dtex; + GLuint SSAOShader::uniform_noise_texture; + GLuint SSAOShader::uniform_invprojm; + GLuint SSAOShader::uniform_projm; + GLuint SSAOShader::uniform_samplePoints; + GLuint SSAOShader::vao; + float SSAOShader::SSAOSamples[64]; - void SSAOShader::init() - { - Program = LoadProgram( + void SSAOShader::init() + { + Program = LoadProgram( GL_VERTEX_SHADER, file_manager->getAsset("shaders/screenquad.vert").c_str(), GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/decodeNormal.frag").c_str(), GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/ssao.frag").c_str()); - uniform_ntex = glGetUniformLocation(Program, "ntex"); - uniform_dtex = glGetUniformLocation(Program, "dtex"); - uniform_noise_texture = glGetUniformLocation(Program, "noise_texture"); - uniform_invprojm = glGetUniformLocation(Program, "invprojm"); - uniform_projm = glGetUniformLocation(Program, "projm"); - uniform_samplePoints = glGetUniformLocation(Program, "samplePoints[0]"); - vao = createVAO(Program); + uniform_ntex = glGetUniformLocation(Program, "ntex"); + uniform_dtex = glGetUniformLocation(Program, "dtex"); + uniform_noise_texture = glGetUniformLocation(Program, "noise_texture"); + uniform_invprojm = glGetUniformLocation(Program, "invprojm"); + uniform_projm = glGetUniformLocation(Program, "projm"); + uniform_samplePoints = glGetUniformLocation(Program, "samplePoints[0]"); + vao = createVAO(Program); - // SSAOSamples[4 * i] and SSAOSamples[4 * i + 1] can be negative + // SSAOSamples[4 * i] and SSAOSamples[4 * i + 1] can be negative - SSAOSamples[0] = 0.135061f; - SSAOSamples[1] = 0.207948f; - SSAOSamples[2] = 0.968770f; - SSAOSamples[3] = 0.983032f; + SSAOSamples[0] = 0.135061f; + SSAOSamples[1] = 0.207948f; + SSAOSamples[2] = 0.968770f; + SSAOSamples[3] = 0.983032f; - SSAOSamples[4] = 0.273456f; - SSAOSamples[5] = -0.805390f; - SSAOSamples[6] = 0.525898f; - SSAOSamples[7] = 0.942808f; + SSAOSamples[4] = 0.273456f; + SSAOSamples[5] = -0.805390f; + SSAOSamples[6] = 0.525898f; + SSAOSamples[7] = 0.942808f; - SSAOSamples[8] = 0.443450f; - SSAOSamples[9] = -0.803786f; - SSAOSamples[10] = 0.396585f; - SSAOSamples[11] = 0.007996f; + SSAOSamples[8] = 0.443450f; + SSAOSamples[9] = -0.803786f; + SSAOSamples[10] = 0.396585f; + SSAOSamples[11] = 0.007996f; - SSAOSamples[12] = 0.742420f; - SSAOSamples[13] = -0.620072f; - SSAOSamples[14] = 0.253621f; - SSAOSamples[15] = 0.284829f; + SSAOSamples[12] = 0.742420f; + SSAOSamples[13] = -0.620072f; + SSAOSamples[14] = 0.253621f; + SSAOSamples[15] = 0.284829f; - SSAOSamples[16] = 0.892464f; - SSAOSamples[17] = 0.046221f; - SSAOSamples[18] = 0.448744f; - SSAOSamples[19] = 0.753655f; + SSAOSamples[16] = 0.892464f; + SSAOSamples[17] = 0.046221f; + SSAOSamples[18] = 0.448744f; + SSAOSamples[19] = 0.753655f; - SSAOSamples[20] = 0.830350f; - SSAOSamples[21] = -0.043593f; - SSAOSamples[22] = 0.555535f; - SSAOSamples[23] = 0.357463f; + SSAOSamples[20] = 0.830350f; + SSAOSamples[21] = -0.043593f; + SSAOSamples[22] = 0.555535f; + SSAOSamples[23] = 0.357463f; - SSAOSamples[24] = -0.600612f; - SSAOSamples[25] = -0.536421f; - SSAOSamples[26] = 0.592889f; - SSAOSamples[27] = 0.670583f; + SSAOSamples[24] = -0.600612f; + SSAOSamples[25] = -0.536421f; + SSAOSamples[26] = 0.592889f; + SSAOSamples[27] = 0.670583f; - SSAOSamples[28] = -0.280658f; - SSAOSamples[29] = 0.674894f; - SSAOSamples[30] = 0.682458f; - SSAOSamples[31] = 0.553362f; + SSAOSamples[28] = -0.280658f; + SSAOSamples[29] = 0.674894f; + SSAOSamples[30] = 0.682458f; + SSAOSamples[31] = 0.553362f; - SSAOSamples[32] = -0.654493f; - SSAOSamples[33] = -0.140866f; - SSAOSamples[34] = 0.742830f; - SSAOSamples[35] = 0.699820f; + SSAOSamples[32] = -0.654493f; + SSAOSamples[33] = -0.140866f; + SSAOSamples[34] = 0.742830f; + SSAOSamples[35] = 0.699820f; - SSAOSamples[36] = 0.114730f; - SSAOSamples[37] = 0.873130f; - SSAOSamples[38] = 0.473794f; - SSAOSamples[39] = 0.483901f; + SSAOSamples[36] = 0.114730f; + SSAOSamples[37] = 0.873130f; + SSAOSamples[38] = 0.473794f; + SSAOSamples[39] = 0.483901f; - SSAOSamples[40] = 0.699167f; - SSAOSamples[41] = 0.632210f; - SSAOSamples[42] = 0.333879f; - SSAOSamples[43] = 0.010956f; + SSAOSamples[40] = 0.699167f; + SSAOSamples[41] = 0.632210f; + SSAOSamples[42] = 0.333879f; + SSAOSamples[43] = 0.010956f; - SSAOSamples[44] = 0.904603f; - SSAOSamples[45] = 0.393410f; - SSAOSamples[46] = 0.164080f; - SSAOSamples[47] = 0.780297f; + SSAOSamples[44] = 0.904603f; + SSAOSamples[45] = 0.393410f; + SSAOSamples[46] = 0.164080f; + SSAOSamples[47] = 0.780297f; - SSAOSamples[48] = 0.631662f; - SSAOSamples[49] = -0.405195f; - SSAOSamples[50] = 0.660924f; - SSAOSamples[51] = 0.865596f; + SSAOSamples[48] = 0.631662f; + SSAOSamples[49] = -0.405195f; + SSAOSamples[50] = 0.660924f; + SSAOSamples[51] = 0.865596f; - SSAOSamples[52] = -0.195668f; - SSAOSamples[53] = 0.629185f; - SSAOSamples[54] = 0.752223f; - SSAOSamples[55] = 0.019013f; + SSAOSamples[52] = -0.195668f; + SSAOSamples[53] = 0.629185f; + SSAOSamples[54] = 0.752223f; + SSAOSamples[55] = 0.019013f; - SSAOSamples[56] = -0.511316f; - SSAOSamples[57] = 0.635504f; - SSAOSamples[58] = 0.578524f; - SSAOSamples[59] = 0.605457f; + SSAOSamples[56] = -0.511316f; + SSAOSamples[57] = 0.635504f; + SSAOSamples[58] = 0.578524f; + SSAOSamples[59] = 0.605457f; - SSAOSamples[60] = -0.898843f; - SSAOSamples[61] = 0.067382f; - SSAOSamples[62] = 0.433061f; - SSAOSamples[63] = 0.772942f; + SSAOSamples[60] = -0.898843f; + SSAOSamples[61] = 0.067382f; + SSAOSamples[62] = 0.433061f; + SSAOSamples[63] = 0.772942f; - // Generate another random distribution, if needed -/* for (unsigned i = 0; i < 16; i++) { - // Use double to avoid denorm and get a true uniform distribution - // Generate z component between [0.1; 1] to avoid being too close from surface - double z = rand(); - z /= RAND_MAX; - z = 0.1 + 0.9 * z; + // Generate another random distribution, if needed + /* for (unsigned i = 0; i < 16; i++) { + // Use double to avoid denorm and get a true uniform distribution + // Generate z component between [0.1; 1] to avoid being too close from surface + double z = rand(); + z /= RAND_MAX; + z = 0.1 + 0.9 * z; - // Now generate x,y on the unit circle - double x = rand(); - x /= RAND_MAX; - x = 2 * x - 1; - double y = rand(); - y /= RAND_MAX; - y = 2 * y - 1; - double xynorm = sqrt(x * x + y * y); - x /= xynorm; - y /= xynorm; - // Now resize x,y so that norm(x,y,z) is one - x *= sqrt(1. - z * z); - y *= sqrt(1. - z * z); + // Now generate x,y on the unit circle + double x = rand(); + x /= RAND_MAX; + x = 2 * x - 1; + double y = rand(); + y /= RAND_MAX; + y = 2 * y - 1; + double xynorm = sqrt(x * x + y * y); + x /= xynorm; + y /= xynorm; + // Now resize x,y so that norm(x,y,z) is one + x *= sqrt(1. - z * z); + y *= sqrt(1. - z * z); - // Norm factor - double w = rand(); - w /= RAND_MAX; - SSAOSamples[4 * i] = (float)x; - SSAOSamples[4 * i + 1] = (float)y; - SSAOSamples[4 * i + 2] = (float)z; - SSAOSamples[4 * i + 3] = (float)w; - }*/ - } + // Norm factor + double w = rand(); + w /= RAND_MAX; + SSAOSamples[4 * i] = (float)x; + SSAOSamples[4 * i + 1] = (float)y; + SSAOSamples[4 * i + 2] = (float)z; + SSAOSamples[4 * i + 3] = (float)w; + }*/ + } - void SSAOShader::setUniforms(const core::matrix4& projm, const core::matrix4 &invprojm, unsigned TU_ntex, unsigned TU_dtex, unsigned TU_noise) - { - glUniformMatrix4fv(FullScreenShader::SSAOShader::uniform_invprojm, 1, GL_FALSE, invprojm.pointer()); - glUniformMatrix4fv(FullScreenShader::SSAOShader::uniform_projm, 1, GL_FALSE, projm.pointer()); - glUniform4fv(FullScreenShader::SSAOShader::uniform_samplePoints, 16, FullScreenShader::SSAOShader::SSAOSamples); + void SSAOShader::setUniforms(const core::matrix4& projm, const core::matrix4 &invprojm, unsigned TU_ntex, unsigned TU_dtex, unsigned TU_noise) + { + glUniformMatrix4fv(FullScreenShader::SSAOShader::uniform_invprojm, 1, GL_FALSE, invprojm.pointer()); + glUniformMatrix4fv(FullScreenShader::SSAOShader::uniform_projm, 1, GL_FALSE, projm.pointer()); + glUniform4fv(FullScreenShader::SSAOShader::uniform_samplePoints, 16, FullScreenShader::SSAOShader::SSAOSamples); - glUniform1i(FullScreenShader::SSAOShader::uniform_ntex, TU_ntex); - glUniform1i(FullScreenShader::SSAOShader::uniform_dtex, TU_dtex); - glUniform1i(FullScreenShader::SSAOShader::uniform_noise_texture, TU_noise); - } + glUniform1i(FullScreenShader::SSAOShader::uniform_ntex, TU_ntex); + glUniform1i(FullScreenShader::SSAOShader::uniform_dtex, TU_dtex); + glUniform1i(FullScreenShader::SSAOShader::uniform_noise_texture, TU_noise); + } - GLuint FogShader::Program; - GLuint FogShader::uniform_tex; - GLuint FogShader::uniform_fogmax; - GLuint FogShader::uniform_startH; - GLuint FogShader::uniform_endH; - GLuint FogShader::uniform_start; - GLuint FogShader::uniform_end; - GLuint FogShader::uniform_col; - GLuint FogShader::uniform_ipvmat; - GLuint FogShader::vao; + GLuint FogShader::Program; + GLuint FogShader::uniform_tex; + GLuint FogShader::uniform_fogmax; + GLuint FogShader::uniform_startH; + GLuint FogShader::uniform_endH; + GLuint FogShader::uniform_start; + GLuint FogShader::uniform_end; + GLuint FogShader::uniform_col; + GLuint FogShader::uniform_ipvmat; + GLuint FogShader::vao; - void FogShader::init() - { - Program = LoadProgram( + void FogShader::init() + { + Program = LoadProgram( GL_VERTEX_SHADER, file_manager->getAsset("shaders/screenquad.vert").c_str(), GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/fog.frag").c_str()); - uniform_tex = glGetUniformLocation(Program, "tex"); - uniform_fogmax = glGetUniformLocation(Program, "fogmax"); - uniform_startH = glGetUniformLocation(Program, "startH"); - uniform_endH = glGetUniformLocation(Program, "endH"); - uniform_start = glGetUniformLocation(Program, "start"); - uniform_end = glGetUniformLocation(Program, "end"); - uniform_col = glGetUniformLocation(Program, "col"); - uniform_ipvmat = glGetUniformLocation(Program, "ipvmat"); - vao = createVAO(Program); - } + uniform_tex = glGetUniformLocation(Program, "tex"); + uniform_fogmax = glGetUniformLocation(Program, "fogmax"); + uniform_startH = glGetUniformLocation(Program, "startH"); + uniform_endH = glGetUniformLocation(Program, "endH"); + uniform_start = glGetUniformLocation(Program, "start"); + uniform_end = glGetUniformLocation(Program, "end"); + uniform_col = glGetUniformLocation(Program, "col"); + uniform_ipvmat = glGetUniformLocation(Program, "ipvmat"); + vao = createVAO(Program); + } - void FogShader::setUniforms(const core::matrix4 &ipvmat, float fogmax, float startH, float endH, float start, float end, const core::vector3df &col, unsigned TU_ntex) - { - glUniform1f(uniform_fogmax, fogmax); - glUniform1f(uniform_startH, startH); - glUniform1f(uniform_endH, endH); - glUniform1f(uniform_start, start); - glUniform1f(uniform_end, end); - glUniform3f(uniform_col, col.X, col.Y, col.Z); - glUniformMatrix4fv(uniform_ipvmat, 1, GL_FALSE, ipvmat.pointer()); - glUniform1i(uniform_tex, TU_ntex); - } + void FogShader::setUniforms(const core::matrix4 &ipvmat, float fogmax, float startH, float endH, float start, float end, const core::vector3df &col, unsigned TU_ntex) + { + glUniform1f(uniform_fogmax, fogmax); + glUniform1f(uniform_startH, startH); + glUniform1f(uniform_endH, endH); + glUniform1f(uniform_start, start); + glUniform1f(uniform_end, end); + glUniform3f(uniform_col, col.X, col.Y, col.Z); + glUniformMatrix4fv(uniform_ipvmat, 1, GL_FALSE, ipvmat.pointer()); + glUniform1i(uniform_tex, TU_ntex); + } GLuint MotionBlurShader::Program; GLuint MotionBlurShader::uniform_boost_amount; @@ -2608,47 +2620,47 @@ namespace FullScreenShader namespace UIShader { - GLuint TextureRectShader::Program; - GLuint TextureRectShader::attrib_position; - GLuint TextureRectShader::attrib_texcoord; - GLuint TextureRectShader::uniform_tex; - GLuint TextureRectShader::uniform_center; - GLuint TextureRectShader::uniform_size; - GLuint TextureRectShader::uniform_texcenter; - GLuint TextureRectShader::uniform_texsize; - GLuint TextureRectShader::vao; + GLuint TextureRectShader::Program; + GLuint TextureRectShader::attrib_position; + GLuint TextureRectShader::attrib_texcoord; + GLuint TextureRectShader::uniform_tex; + GLuint TextureRectShader::uniform_center; + GLuint TextureRectShader::uniform_size; + GLuint TextureRectShader::uniform_texcenter; + GLuint TextureRectShader::uniform_texsize; + GLuint TextureRectShader::vao; - void TextureRectShader::init() - { - Program = LoadProgram( + void TextureRectShader::init() + { + Program = LoadProgram( GL_VERTEX_SHADER, file_manager->getAsset("shaders/texturedquad.vert").c_str(), GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/texturedquad.frag").c_str()); - attrib_position = glGetAttribLocation(Program, "position"); - attrib_texcoord = glGetAttribLocation(Program, "texcoord"); - uniform_tex = glGetUniformLocation(Program, "tex"); - uniform_center = glGetUniformLocation(Program, "center"); - uniform_size = glGetUniformLocation(Program, "size"); - uniform_texcenter = glGetUniformLocation(Program, "texcenter"); - uniform_texsize = glGetUniformLocation(Program, "texsize"); - glGenVertexArrays(1, &vao); - glBindVertexArray(vao); - glEnableVertexAttribArray(attrib_position); - glEnableVertexAttribArray(attrib_texcoord); - glBindBuffer(GL_ARRAY_BUFFER, quad_buffer); - glVertexAttribPointer(attrib_position, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), 0); - glVertexAttribPointer(attrib_texcoord, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), (GLvoid *)(2 * sizeof(float))); - glBindVertexArray(0); - } + attrib_position = glGetAttribLocation(Program, "position"); + attrib_texcoord = glGetAttribLocation(Program, "texcoord"); + uniform_tex = glGetUniformLocation(Program, "tex"); + uniform_center = glGetUniformLocation(Program, "center"); + uniform_size = glGetUniformLocation(Program, "size"); + uniform_texcenter = glGetUniformLocation(Program, "texcenter"); + uniform_texsize = glGetUniformLocation(Program, "texsize"); + glGenVertexArrays(1, &vao); + glBindVertexArray(vao); + glEnableVertexAttribArray(attrib_position); + glEnableVertexAttribArray(attrib_texcoord); + glBindBuffer(GL_ARRAY_BUFFER, quad_buffer); + glVertexAttribPointer(attrib_position, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), 0); + glVertexAttribPointer(attrib_texcoord, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), (GLvoid *)(2 * sizeof(float))); + glBindVertexArray(0); + } - void TextureRectShader::setUniforms(float center_pos_x, float center_pos_y, float width, float height, float tex_center_pos_x, float tex_center_pos_y, float tex_width, float tex_height, unsigned TU_tex) - { - glUniform1i(uniform_tex, TU_tex); - glUniform2f(uniform_center, center_pos_x, center_pos_y); - glUniform2f(uniform_size, width, height); - glUniform2f(uniform_texcenter, tex_center_pos_x, tex_center_pos_y); - glUniform2f(uniform_texsize, tex_width, tex_height); - } + void TextureRectShader::setUniforms(float center_pos_x, float center_pos_y, float width, float height, float tex_center_pos_x, float tex_center_pos_y, float tex_width, float tex_height, unsigned TU_tex) + { + glUniform1i(uniform_tex, TU_tex); + glUniform2f(uniform_center, center_pos_x, center_pos_y); + glUniform2f(uniform_size, width, height); + glUniform2f(uniform_texcenter, tex_center_pos_x, tex_center_pos_y); + glUniform2f(uniform_texsize, tex_width, tex_height); + } GLuint UniformColoredTextureRectShader::Program; GLuint UniformColoredTextureRectShader::attrib_position; @@ -2695,90 +2707,90 @@ namespace UIShader glUniform4i(uniform_color, color.getRed(), color.getGreen(), color.getBlue(), color.getAlpha()); } - GLuint ColoredTextureRectShader::Program; - GLuint ColoredTextureRectShader::attrib_position; - GLuint ColoredTextureRectShader::attrib_texcoord; - GLuint ColoredTextureRectShader::attrib_color; - GLuint ColoredTextureRectShader::uniform_tex; - GLuint ColoredTextureRectShader::uniform_center; - GLuint ColoredTextureRectShader::uniform_size; - GLuint ColoredTextureRectShader::uniform_texcenter; - GLuint ColoredTextureRectShader::uniform_texsize; - GLuint ColoredTextureRectShader::colorvbo; - GLuint ColoredTextureRectShader::vao; + GLuint ColoredTextureRectShader::Program; + GLuint ColoredTextureRectShader::attrib_position; + GLuint ColoredTextureRectShader::attrib_texcoord; + GLuint ColoredTextureRectShader::attrib_color; + GLuint ColoredTextureRectShader::uniform_tex; + GLuint ColoredTextureRectShader::uniform_center; + GLuint ColoredTextureRectShader::uniform_size; + GLuint ColoredTextureRectShader::uniform_texcenter; + GLuint ColoredTextureRectShader::uniform_texsize; + GLuint ColoredTextureRectShader::colorvbo; + GLuint ColoredTextureRectShader::vao; - void ColoredTextureRectShader::init() - { + void ColoredTextureRectShader::init() + { Program = LoadProgram( GL_VERTEX_SHADER, file_manager->getAsset("shaders/colortexturedquad.vert").c_str(), GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/colortexturedquad.frag").c_str()); - attrib_position = glGetAttribLocation(Program, "position"); - attrib_texcoord = glGetAttribLocation(Program, "texcoord"); - attrib_color = glGetAttribLocation(Program, "color"); - uniform_tex = glGetUniformLocation(Program, "tex"); - uniform_center = glGetUniformLocation(Program, "center"); - uniform_size = glGetUniformLocation(Program, "size"); - uniform_texcenter = glGetUniformLocation(Program, "texcenter"); - uniform_texsize = glGetUniformLocation(Program, "texsize"); - glGenVertexArrays(1, &vao); - glBindVertexArray(vao); - glEnableVertexAttribArray(attrib_position); - glEnableVertexAttribArray(attrib_texcoord); - glEnableVertexAttribArray(attrib_color); - glBindBuffer(GL_ARRAY_BUFFER, quad_buffer); - glVertexAttribPointer(attrib_position, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), 0); - glVertexAttribPointer(attrib_texcoord, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), (GLvoid *)(2 * sizeof(float))); - const unsigned quad_color[] = { - 0, 0, 0, 255, - 255, 0, 0, 255, - 0, 255, 0, 255, - 0, 0, 255, 255, - }; - glGenBuffers(1, &colorvbo); - glBindBuffer(GL_ARRAY_BUFFER, colorvbo); - glBufferData(GL_ARRAY_BUFFER, 16 * sizeof(unsigned), quad_color, GL_DYNAMIC_DRAW); - glVertexAttribIPointer(attrib_color, 4, GL_UNSIGNED_INT, 4 * sizeof(unsigned), 0); - glBindVertexArray(0); - } + attrib_position = glGetAttribLocation(Program, "position"); + attrib_texcoord = glGetAttribLocation(Program, "texcoord"); + attrib_color = glGetAttribLocation(Program, "color"); + uniform_tex = glGetUniformLocation(Program, "tex"); + uniform_center = glGetUniformLocation(Program, "center"); + uniform_size = glGetUniformLocation(Program, "size"); + uniform_texcenter = glGetUniformLocation(Program, "texcenter"); + uniform_texsize = glGetUniformLocation(Program, "texsize"); + glGenVertexArrays(1, &vao); + glBindVertexArray(vao); + glEnableVertexAttribArray(attrib_position); + glEnableVertexAttribArray(attrib_texcoord); + glEnableVertexAttribArray(attrib_color); + glBindBuffer(GL_ARRAY_BUFFER, quad_buffer); + glVertexAttribPointer(attrib_position, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), 0); + glVertexAttribPointer(attrib_texcoord, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), (GLvoid *)(2 * sizeof(float))); + const unsigned quad_color[] = { + 0, 0, 0, 255, + 255, 0, 0, 255, + 0, 255, 0, 255, + 0, 0, 255, 255, + }; + glGenBuffers(1, &colorvbo); + glBindBuffer(GL_ARRAY_BUFFER, colorvbo); + glBufferData(GL_ARRAY_BUFFER, 16 * sizeof(unsigned), quad_color, GL_DYNAMIC_DRAW); + glVertexAttribIPointer(attrib_color, 4, GL_UNSIGNED_INT, 4 * sizeof(unsigned), 0); + glBindVertexArray(0); + } - void ColoredTextureRectShader::setUniforms(float center_pos_x, float center_pos_y, float width, float height, float tex_center_pos_x, float tex_center_pos_y, float tex_width, float tex_height, unsigned TU_tex) - { - glUniform1i(uniform_tex, TU_tex); - glUniform2f(uniform_center, center_pos_x, center_pos_y); - glUniform2f(uniform_size, width, height); - glUniform2f(uniform_texcenter, tex_center_pos_x, tex_center_pos_y); - glUniform2f(uniform_texsize, tex_width, tex_height); - } + void ColoredTextureRectShader::setUniforms(float center_pos_x, float center_pos_y, float width, float height, float tex_center_pos_x, float tex_center_pos_y, float tex_width, float tex_height, unsigned TU_tex) + { + glUniform1i(uniform_tex, TU_tex); + glUniform2f(uniform_center, center_pos_x, center_pos_y); + glUniform2f(uniform_size, width, height); + glUniform2f(uniform_texcenter, tex_center_pos_x, tex_center_pos_y); + glUniform2f(uniform_texsize, tex_width, tex_height); + } - GLuint ColoredRectShader::Program; - GLuint ColoredRectShader::attrib_position; - GLuint ColoredRectShader::uniform_center; - GLuint ColoredRectShader::uniform_size; - GLuint ColoredRectShader::uniform_color; - GLuint ColoredRectShader::vao; + GLuint ColoredRectShader::Program; + GLuint ColoredRectShader::attrib_position; + GLuint ColoredRectShader::uniform_center; + GLuint ColoredRectShader::uniform_size; + GLuint ColoredRectShader::uniform_color; + GLuint ColoredRectShader::vao; - void ColoredRectShader::init() - { - Program = LoadProgram( + void ColoredRectShader::init() + { + Program = LoadProgram( GL_VERTEX_SHADER, file_manager->getAsset("shaders/coloredquad.vert").c_str(), GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/coloredquad.frag").c_str()); - attrib_position = glGetAttribLocation(Program, "position"); - uniform_color = glGetUniformLocation(Program, "color"); - uniform_center = glGetUniformLocation(Program, "center"); - uniform_size = glGetUniformLocation(Program, "size"); - glGenVertexArrays(1, &vao); - glBindVertexArray(vao); - glEnableVertexAttribArray(attrib_position); - glBindBuffer(GL_ARRAY_BUFFER, quad_buffer); - glVertexAttribPointer(attrib_position, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), 0); - glBindVertexArray(0); - } + attrib_position = glGetAttribLocation(Program, "position"); + uniform_color = glGetUniformLocation(Program, "color"); + uniform_center = glGetUniformLocation(Program, "center"); + uniform_size = glGetUniformLocation(Program, "size"); + glGenVertexArrays(1, &vao); + glBindVertexArray(vao); + glEnableVertexAttribArray(attrib_position); + glBindBuffer(GL_ARRAY_BUFFER, quad_buffer); + glVertexAttribPointer(attrib_position, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), 0); + glBindVertexArray(0); + } - void ColoredRectShader::setUniforms(float center_pos_x, float center_pos_y, float width, float height, const video::SColor &color) - { - glUniform2f(uniform_center, center_pos_x, center_pos_y); - glUniform2f(uniform_size, width, height); - glUniform4i(uniform_color, color.getRed(), color.getGreen(), color.getBlue(), color.getAlpha()); - } + void ColoredRectShader::setUniforms(float center_pos_x, float center_pos_y, float width, float height, const video::SColor &color) + { + glUniform2f(uniform_center, center_pos_x, center_pos_y); + glUniform2f(uniform_size, width, height); + glUniform4i(uniform_color, color.getRed(), color.getGreen(), color.getBlue(), color.getAlpha()); + } } diff --git a/src/graphics/shaders.hpp b/src/graphics/shaders.hpp index a9f913aa0..093780f25 100644 --- a/src/graphics/shaders.hpp +++ b/src/graphics/shaders.hpp @@ -39,10 +39,10 @@ class ObjectPass1Shader public: static GLuint Program; static GLuint attrib_position, attrib_texcoord, attrib_normal; - static GLuint uniform_MVP, uniform_TIMV, uniform_tex; + static GLuint uniform_MM, uniform_IMM, uniform_tex; static void init(); - static void setUniforms(const core::matrix4 &ModelViewProjectionMatrix, const core::matrix4 &TransposeInverseModelView, unsigned TU_tex); + static void setUniforms(const core::matrix4 &ModelMatrix, const core::matrix4 &InverseModelMatrix, unsigned TU_tex); }; class ObjectRefPass1Shader @@ -50,10 +50,10 @@ class ObjectRefPass1Shader public: static GLuint Program; static GLuint attrib_position, attrib_normal, attrib_texcoord; - static GLuint uniform_MVP, uniform_TM, uniform_TIMV, uniform_tex; + static GLuint uniform_MM, uniform_TM, uniform_IMM, uniform_tex; static void init(); - static void setUniforms(const core::matrix4 &ModelViewProjectionMatrix, const core::matrix4 &TransposeInverseModelView, const core::matrix4 &TextureMatrix, unsigned TU_texture); + static void setUniforms(const core::matrix4 &ModelMatrix, const core::matrix4 &InverseModelMatrix, const core::matrix4 &TextureMatrix, unsigned TU_texture); }; class GrassPass1Shader @@ -72,10 +72,10 @@ class NormalMapShader public: static GLuint Program; static GLuint attrib_position, attrib_texcoord, attrib_tangent, attrib_bitangent; - static GLuint uniform_MVP, uniform_TIMV, uniform_normalMap; + static GLuint uniform_MM, uniform_IMM, uniform_normalMap; static void init(); - static void setUniforms(const core::matrix4 &ModelViewProjectionMatrix, const core::matrix4 &TransposeInverseModelView, unsigned TU_normalMap); + static void setUniforms(const core::matrix4 &ModelMatrix, const core::matrix4 &InverseModelMatrix, unsigned TU_normalMap); }; class InstancedObjectPass1Shader @@ -116,11 +116,11 @@ class ObjectPass2Shader public: static GLuint Program; static GLuint attrib_position, attrib_texcoord; - static GLuint uniform_MVP, uniform_TM, uniform_screen, uniform_ambient; + static GLuint uniform_MM, uniform_TM, uniform_screen, uniform_ambient; static GLuint TU_Albedo; static void init(); - static void setUniforms(const core::matrix4 &ModelViewProjectionMatrix, const core::matrix4 &TextureMatrix); + static void setUniforms(const core::matrix4 &ModelMatrix, const core::matrix4 &TextureMatrix); }; class InstancedObjectPass2Shader @@ -152,11 +152,11 @@ class DetailledObjectPass2Shader public: static GLuint Program; static GLuint attrib_position, attrib_texcoord, attrib_second_texcoord; - static GLuint uniform_MVP, uniform_screen, uniform_ambient; + static GLuint uniform_MM, uniform_screen, uniform_ambient; static GLuint TU_Albedo, TU_detail; static void init(); - static void setUniforms(const core::matrix4 &ModelViewProjectionMatrix); + static void setUniforms(const core::matrix4 &ModelMatrix); }; class ObjectRimLimitShader @@ -164,11 +164,11 @@ class ObjectRimLimitShader public: static GLuint Program; static GLuint attrib_position, attrib_normal, attrib_texcoord; - static GLuint uniform_MVP, uniform_TIMV, uniform_TM, uniform_screen, uniform_ambient; + static GLuint uniform_MM, uniform_IMM, uniform_TM, uniform_screen, uniform_ambient; static GLuint TU_Albedo; static void init(); - static void setUniforms(const core::matrix4 &ModelViewProjectionMatrix, const core::matrix4 &TransposeInverseModelView, const core::matrix4 &TextureMatrix); + static void setUniforms(const core::matrix4 &ModelMatrix, const core::matrix4 &InverseModelMatrix, const core::matrix4 &TextureMatrix); }; class UntexturedObjectShader @@ -176,10 +176,10 @@ class UntexturedObjectShader public: static GLuint Program; static GLuint attrib_position, attrib_color; - static GLuint uniform_MVP, uniform_screen, uniform_ambient; + static GLuint uniform_MM, uniform_screen, uniform_ambient; static void init(); - static void setUniforms(const core::matrix4 &ModelViewProjectionMatrix); + static void setUniforms(const core::matrix4 &ModelMatrix); }; class ObjectUnlitShader @@ -187,11 +187,11 @@ class ObjectUnlitShader public: static GLuint Program; static GLuint attrib_position, attrib_texcoord; - static GLuint uniform_MVP; + static GLuint uniform_MM; static GLuint TU_tex; static void init(); - static void setUniforms(const core::matrix4 &ModelViewProjectionMatrix); + static void setUniforms(const core::matrix4 &ModelMatrix); }; class ObjectRefPass2Shader @@ -199,11 +199,11 @@ class ObjectRefPass2Shader public: static GLuint Program; static GLuint attrib_position, attrib_texcoord; - static GLuint uniform_MVP, uniform_TM, uniform_screen, uniform_ambient; + static GLuint uniform_MM, uniform_TM, uniform_screen, uniform_ambient; static GLuint TU_Albedo; static void init(); - static void setUniforms(const core::matrix4 &ModelViewProjectionMatrix, const core::matrix4 &TextureMatrix); + static void setUniforms(const core::matrix4 &ModelMatrix, const core::matrix4 &TextureMatrix); }; class GrassPass2Shader @@ -235,11 +235,11 @@ class SphereMapShader public: static GLuint Program; static GLuint attrib_position, attrib_normal; - static GLuint uniform_MVP, uniform_TIMV, uniform_TVM, uniform_invproj, uniform_screen; + static GLuint uniform_MM, uniform_IMM, uniform_screen; static GLuint TU_tex; static void init(); - static void setUniforms(const core::matrix4 &ModelViewProjectionMatrix, const core::matrix4 &TransposeViewMatrix, const core::matrix4 &TransposeInverseModelView, const core::matrix4 &InvProj, const core::vector2df& screen); + static void setUniforms(const core::matrix4 &ModelMatrix, const core::matrix4 &InverseModelMatrix, const core::vector2df& screen); }; class SplattingShader @@ -247,11 +247,11 @@ class SplattingShader public: static GLuint Program; static GLuint attrib_position, attrib_texcoord, attrib_second_texcoord; - static GLuint uniform_MVP, uniform_screen, uniform_ambient; + static GLuint uniform_MM, uniform_screen, uniform_ambient; static GLuint TU_tex_layout, TU_tex_detail0, TU_tex_detail1, TU_tex_detail2, TU_tex_detail3; static void init(); - static void setUniforms(const core::matrix4 &ModelViewProjectionMatrix); + static void setUniforms(const core::matrix4 &ModelMatrix); }; class CausticsShader @@ -403,11 +403,11 @@ class SkyboxShader public: static GLuint Program; static GLuint attrib_position; - static GLuint uniform_MVP, uniform_InvProjView, uniform_tex, uniform_screen; + static GLuint uniform_MM, uniform_tex, uniform_screen; static GLuint cubevao; static void init(); - static void setUniforms(const core::matrix4 &ModelViewProjectionMatrix, const core::matrix4 &InvProjView, const core::vector2df &screen, unsigned TU_tex); + static void setUniforms(const core::matrix4 &ModelMatrix, const core::vector2df &screen, unsigned TU_tex); }; } diff --git a/src/graphics/stkanimatedmesh.cpp b/src/graphics/stkanimatedmesh.cpp index 0a4e3352f..662db0701 100644 --- a/src/graphics/stkanimatedmesh.cpp +++ b/src/graphics/stkanimatedmesh.cpp @@ -145,19 +145,21 @@ void STKAnimatedMesh::render() { ModelViewProjectionMatrix = computeMVP(AbsoluteTransformation); TransposeInverseModelView = computeTIMV(AbsoluteTransformation); + core::matrix4 invmodel; + AbsoluteTransformation.getInverse(invmodel); for (unsigned i = 0; i < GeometricMesh[FPSM_DEFAULT].size(); i++) { GroupedFPSM::MeshSet.push_back(GeometricMesh[FPSM_DEFAULT][i]); - GroupedFPSM::MVPSet.push_back(ModelViewProjectionMatrix); - GroupedFPSM::TIMVSet.push_back(TransposeInverseModelView); + GroupedFPSM::MVPSet.push_back(AbsoluteTransformation); + GroupedFPSM::TIMVSet.push_back(invmodel); } for (unsigned i = 0; i < GeometricMesh[FPSM_ALPHA_REF_TEXTURE].size(); i++) { GroupedFPSM::MeshSet.push_back(GeometricMesh[FPSM_ALPHA_REF_TEXTURE][i]); - GroupedFPSM::MVPSet.push_back(ModelViewProjectionMatrix); - GroupedFPSM::TIMVSet.push_back(TransposeInverseModelView); + GroupedFPSM::MVPSet.push_back(AbsoluteTransformation); + GroupedFPSM::TIMVSet.push_back(invmodel); } return; @@ -165,39 +167,42 @@ void STKAnimatedMesh::render() if (irr_driver->getPhase() == SOLID_LIT_PASS) { + core::matrix4 invmodel; + AbsoluteTransformation.getInverse(invmodel); + for (unsigned i = 0; i < ShadedMesh[SM_DEFAULT].size(); i++) { GroupedSM::MeshSet.push_back(ShadedMesh[SM_DEFAULT][i]); - GroupedSM::MVPSet.push_back(ModelViewProjectionMatrix); - GroupedSM::TIMVSet.push_back(TransposeInverseModelView); + GroupedSM::MVPSet.push_back(AbsoluteTransformation); + GroupedSM::TIMVSet.push_back(invmodel); } for (unsigned i = 0; i < ShadedMesh[SM_ALPHA_REF_TEXTURE].size(); i++) { GroupedSM::MeshSet.push_back(ShadedMesh[SM_ALPHA_REF_TEXTURE][i]); - GroupedSM::MVPSet.push_back(ModelViewProjectionMatrix); - GroupedSM::TIMVSet.push_back(TransposeInverseModelView); + GroupedSM::MVPSet.push_back(AbsoluteTransformation); + GroupedSM::TIMVSet.push_back(invmodel); } for (unsigned i = 0; i < ShadedMesh[SM_RIMLIT].size(); i++) { GroupedSM::MeshSet.push_back(ShadedMesh[SM_RIMLIT][i]); - GroupedSM::MVPSet.push_back(ModelViewProjectionMatrix); - GroupedSM::TIMVSet.push_back(TransposeInverseModelView); + GroupedSM::MVPSet.push_back(AbsoluteTransformation); + GroupedSM::TIMVSet.push_back(invmodel); } for (GLMesh *mesh : ShadedMesh[SM_UNLIT]) { GroupedSM::MeshSet.push_back(mesh); - GroupedSM::MVPSet.push_back(ModelViewProjectionMatrix); - GroupedSM::TIMVSet.push_back(TransposeInverseModelView); + GroupedSM::MVPSet.push_back(AbsoluteTransformation); + GroupedSM::TIMVSet.push_back(invmodel); } for (GLMesh *mesh : ShadedMesh[SM_DETAILS]) { GroupedSM::MeshSet.push_back(mesh); - GroupedSM::MVPSet.push_back(ModelViewProjectionMatrix); - GroupedSM::TIMVSet.push_back(TransposeInverseModelView); + GroupedSM::MVPSet.push_back(AbsoluteTransformation); + GroupedSM::TIMVSet.push_back(invmodel); } return; diff --git a/src/graphics/stkmesh.cpp b/src/graphics/stkmesh.cpp index 8afba6e83..d7fb19812 100644 --- a/src/graphics/stkmesh.cpp +++ b/src/graphics/stkmesh.cpp @@ -269,7 +269,7 @@ void drawGrassPass1(const GLMesh &mesh, const core::matrix4 & ModelViewProjectio glDrawElements(ptype, count, itype, 0); } -void drawNormalPass(const GLMesh &mesh, const core::matrix4 & ModelViewProjectionMatrix, const core::matrix4 &TransposeInverseModelView) +void drawNormalPass(const GLMesh &mesh, const core::matrix4 & ModelMatrix, const core::matrix4 &InverseModelMatrix) { irr_driver->IncreaseObjectCount(); GLenum ptype = mesh.PrimitiveType; @@ -279,14 +279,14 @@ void drawNormalPass(const GLMesh &mesh, const core::matrix4 & ModelViewProjectio assert(mesh.textures[1]); setTexture(0, mesh.textures[1], GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true); - MeshShader::NormalMapShader::setUniforms(ModelViewProjectionMatrix, TransposeInverseModelView, 0); + MeshShader::NormalMapShader::setUniforms(ModelMatrix, InverseModelMatrix, 0); assert(mesh.vao_first_pass); glBindVertexArray(mesh.vao_first_pass); glDrawElements(ptype, count, itype, 0); } -void drawSphereMap(const GLMesh &mesh, const core::matrix4 &ModelViewProjectionMatrix, const core::matrix4 &TransposeInverseModelView) +void drawSphereMap(const GLMesh &mesh, const core::matrix4 &ModelMatrix, const core::matrix4 &InverseModelMatrix) { irr_driver->IncreaseObjectCount(); GLenum ptype = mesh.PrimitiveType; @@ -306,7 +306,7 @@ void drawSphereMap(const GLMesh &mesh, const core::matrix4 &ModelViewProjectionM glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR); } - MeshShader::SphereMapShader::setUniforms(ModelViewProjectionMatrix, irr_driver->getViewMatrix().getTransposed(), TransposeInverseModelView, irr_driver->getInvProjMatrix(), core::vector2df(UserConfigParams::m_width, UserConfigParams::m_height)); + MeshShader::SphereMapShader::setUniforms(ModelMatrix, InverseModelMatrix, core::vector2df(UserConfigParams::m_width, UserConfigParams::m_height)); assert(mesh.vao_second_pass); glBindVertexArray(mesh.vao_second_pass); @@ -476,14 +476,14 @@ void drawGrassPass2(const GLMesh &mesh, const core::matrix4 & ModelViewProjectio glDrawElements(ptype, count, itype, 0); } -void drawUntexturedObject(const GLMesh &mesh, const core::matrix4 &ModelViewProjectionMatrix) +void drawUntexturedObject(const GLMesh &mesh, const core::matrix4 &ModelMatrix) { irr_driver->IncreaseObjectCount(); GLenum ptype = mesh.PrimitiveType; GLenum itype = mesh.IndexType; size_t count = mesh.IndexCount; - MeshShader::UntexturedObjectShader::setUniforms(ModelViewProjectionMatrix); + MeshShader::UntexturedObjectShader::setUniforms(ModelMatrix); assert(mesh.vao_second_pass); glBindVertexArray(mesh.vao_second_pass); diff --git a/src/graphics/stkmesh.hpp b/src/graphics/stkmesh.hpp index 919f41d18..5a53da7c8 100644 --- a/src/graphics/stkmesh.hpp +++ b/src/graphics/stkmesh.hpp @@ -90,7 +90,7 @@ template std::vector GroupedFPSM::TIMVSet; void drawObjectPass1(const GLMesh &mesh, const core::matrix4 & ModelViewProjectionMatrix, const core::matrix4 &TransposeInverseModelView); -void drawNormalPass(const GLMesh &mesh, const core::matrix4 & ModelViewProjectionMatrix, const core::matrix4 &TransposeInverseModelView); +void drawNormalPass(const GLMesh &mesh, const core::matrix4 & ModelMatrix, const core::matrix4 &InverseModelMatrix); void drawObjectRefPass1(const GLMesh &mesh, const core::matrix4 & ModelViewProjectionMatrix, const core::matrix4 &TransposeInverseModelView, const core::matrix4 &TextureMatrix); void drawGrassPass1(const GLMesh &mesh, const core::matrix4 & ModelViewProjectionMatrix, const core::matrix4 &TransposeInverseModelView, core::vector3df windDir); diff --git a/src/graphics/stkmeshscenenode.cpp b/src/graphics/stkmeshscenenode.cpp index 2af9c3495..676d9d75a 100644 --- a/src/graphics/stkmeshscenenode.cpp +++ b/src/graphics/stkmeshscenenode.cpp @@ -336,26 +336,28 @@ void STKMeshSceneNode::render() glDisable(GL_CULL_FACE); ModelViewProjectionMatrix = computeMVP(AbsoluteTransformation); TransposeInverseModelView = computeTIMV(AbsoluteTransformation); + core::matrix4 invmodel; + AbsoluteTransformation.getInverse(invmodel); for (unsigned i = 0; i < GeometricMesh[FPSM_DEFAULT].size(); i++) { GroupedFPSM::MeshSet.push_back(GeometricMesh[FPSM_DEFAULT][i]); - GroupedFPSM::MVPSet.push_back(ModelViewProjectionMatrix); - GroupedFPSM::TIMVSet.push_back(TransposeInverseModelView); + GroupedFPSM::MVPSet.push_back(AbsoluteTransformation); + GroupedFPSM::TIMVSet.push_back(invmodel); } for (unsigned i = 0; i < GeometricMesh[FPSM_ALPHA_REF_TEXTURE].size(); i++) { GroupedFPSM::MeshSet.push_back(GeometricMesh[FPSM_ALPHA_REF_TEXTURE][i]); - GroupedFPSM::MVPSet.push_back(ModelViewProjectionMatrix); - GroupedFPSM::TIMVSet.push_back(TransposeInverseModelView); + GroupedFPSM::MVPSet.push_back(AbsoluteTransformation); + GroupedFPSM::TIMVSet.push_back(invmodel); } for (unsigned i = 0; i < GeometricMesh[FPSM_NORMAL_MAP].size(); i++) { GroupedFPSM::MeshSet.push_back(GeometricMesh[FPSM_NORMAL_MAP][i]); - GroupedFPSM::MVPSet.push_back(ModelViewProjectionMatrix); - GroupedFPSM::TIMVSet.push_back(TransposeInverseModelView); + GroupedFPSM::MVPSet.push_back(AbsoluteTransformation); + GroupedFPSM::TIMVSet.push_back(invmodel); } if (!GeometricMesh[FPSM_GRASS].empty()) @@ -373,54 +375,64 @@ void STKMeshSceneNode::render() if (reload_each_frame) glDisable(GL_CULL_FACE); + core::matrix4 invmodel; + AbsoluteTransformation.getInverse(invmodel); + for (unsigned i = 0; i < ShadedMesh[SM_DEFAULT].size(); i++) { GroupedSM::MeshSet.push_back(ShadedMesh[SM_DEFAULT][i]); - GroupedSM::MVPSet.push_back(ModelViewProjectionMatrix); - GroupedSM::TIMVSet.push_back(TransposeInverseModelView); + GroupedSM::MVPSet.push_back(AbsoluteTransformation); + GroupedSM::TIMVSet.push_back(invmodel); } for (unsigned i = 0; i < ShadedMesh[SM_ALPHA_REF_TEXTURE].size(); i++) { GroupedSM::MeshSet.push_back(ShadedMesh[SM_ALPHA_REF_TEXTURE][i]); - GroupedSM::MVPSet.push_back(ModelViewProjectionMatrix); - GroupedSM::TIMVSet.push_back(TransposeInverseModelView); + GroupedSM::MVPSet.push_back(AbsoluteTransformation); + GroupedSM::TIMVSet.push_back(invmodel); } for (unsigned i = 0; i < ShadedMesh[SM_RIMLIT].size(); i++) { GroupedSM::MeshSet.push_back(ShadedMesh[SM_RIMLIT][i]); - GroupedSM::MVPSet.push_back(ModelViewProjectionMatrix); - GroupedSM::TIMVSet.push_back(TransposeInverseModelView); + GroupedSM::MVPSet.push_back(AbsoluteTransformation); + GroupedSM::TIMVSet.push_back(invmodel); } for (unsigned i = 0; i < ShadedMesh[SM_SPHEREMAP].size(); i++) { GroupedSM::MeshSet.push_back(ShadedMesh[SM_SPHEREMAP][i]); - GroupedSM::MVPSet.push_back(ModelViewProjectionMatrix); - GroupedSM::TIMVSet.push_back(TransposeInverseModelView); + GroupedSM::MVPSet.push_back(AbsoluteTransformation); + GroupedSM::TIMVSet.push_back(invmodel); } for (GLMesh *mesh : ShadedMesh[SM_SPLATTING]) { GroupedSM::MeshSet.push_back(mesh); - GroupedSM::MVPSet.push_back(ModelViewProjectionMatrix); - GroupedSM::TIMVSet.push_back(TransposeInverseModelView); + GroupedSM::MVPSet.push_back(AbsoluteTransformation); + GroupedSM::TIMVSet.push_back(invmodel); } for (GLMesh *mesh : ShadedMesh[SM_UNLIT]) { GroupedSM::MeshSet.push_back(mesh); - GroupedSM::MVPSet.push_back(ModelViewProjectionMatrix); - GroupedSM::TIMVSet.push_back(TransposeInverseModelView); + GroupedSM::MVPSet.push_back(AbsoluteTransformation); + GroupedSM::TIMVSet.push_back(invmodel); } for (GLMesh *mesh : ShadedMesh[SM_DETAILS]) { GroupedSM::MeshSet.push_back(mesh); - GroupedSM::MVPSet.push_back(ModelViewProjectionMatrix); - GroupedSM::TIMVSet.push_back(TransposeInverseModelView); + GroupedSM::MVPSet.push_back(AbsoluteTransformation); + GroupedSM::TIMVSet.push_back(invmodel); + } + + for (GLMesh *mesh : ShadedMesh[SM_UNTEXTURED]) + { + GroupedSM::MeshSet.push_back(mesh); + GroupedSM::MVPSet.push_back(AbsoluteTransformation); + GroupedSM::TIMVSet.push_back(invmodel); } if (!ShadedMesh[SM_GRASS].empty()) @@ -433,11 +445,6 @@ void STKMeshSceneNode::render() for (unsigned i = 0; i < ShadedMesh[SM_CAUSTICS].size(); i++) drawSolidPass2(*ShadedMesh[SM_CAUSTICS][i], SM_CAUSTICS); - if (!ShadedMesh[SM_UNTEXTURED].empty()) - glUseProgram(MeshShader::UntexturedObjectShader::Program); - for (unsigned i = 0; i < ShadedMesh[SM_UNTEXTURED].size(); i++) - drawSolidPass2(*ShadedMesh[SM_UNTEXTURED][i], SM_UNTEXTURED); - if (reload_each_frame) glEnable(GL_CULL_FACE); return;