-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds initial command tree for batching render commands
- Loading branch information
Showing
31 changed files
with
874 additions
and
63 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
AggroEngine/src/Subsystem/Graphics/Impl/OpenGL/CommandTree/CommandTree.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#include "CommandTree.hpp" | ||
|
||
CommandTree::CommandTree() | ||
{ | ||
|
||
} | ||
|
||
void CommandTree::addLayer(shared_ptr<Layer> layer) | ||
{ | ||
m_layers.push_back(layer); | ||
} | ||
|
||
void CommandTree::execute(RenderOptions &renderOptions, shared_ptr<RenderChain> renderChain) | ||
{ | ||
vector<shared_ptr<RenderNode>> allNodes; | ||
shared_ptr<RenderNode> currentNode = renderChain->getFirst(); | ||
while (currentNode) | ||
{ | ||
allNodes.push_back(currentNode); | ||
currentNode = currentNode->next(); | ||
} | ||
_executeLayer(renderOptions, allNodes, 0); | ||
} | ||
|
||
void CommandTree::_executeLayer(RenderOptions &renderOptions, vector<shared_ptr<RenderNode>> &renderNodes, int layerIdx) | ||
{ | ||
if (m_layers.size() <= layerIdx || renderNodes.size() == 0) | ||
{ | ||
return; | ||
} | ||
shared_ptr<Layer> layer = m_layers[layerIdx]; | ||
shared_ptr<CommandTreeItem> commandItem = layer->getCommands(renderOptions, renderNodes); | ||
vector<shared_ptr<Command>> commands = commandItem->getCommands(); | ||
for (int i = 0; i < commands.size(); i++) | ||
{ | ||
commands[i]->executeCommand(); | ||
_executeLayer(renderOptions, commands[i]->getRenderNodes(), layerIdx + 1); | ||
commands[i]->end(); | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
AggroEngine/src/Subsystem/Graphics/Impl/OpenGL/CommandTree/CommandTree.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#pragma once | ||
|
||
#include <memory> | ||
#include <vector> | ||
#include "Layer/Layer.hpp" | ||
#include "RenderOptions.hpp" | ||
#include "RenderChain.hpp" | ||
using namespace std; | ||
|
||
/* This object aims to minimize the amount of duplicate work required for rendering. | ||
* In particular, it trys to reduce the number of OpenGL state changes, but can also | ||
* be used to reduce the number of expensive CPU operations such as matrix multiplication. | ||
* | ||
* An example tree as follows | ||
* | ||
* Disable Depth Test | false | true | | ||
* Shader Binding | shdr_a | shdr_b | shdr_c | shdr_b | shdr_d | | ||
* Texture Unit 0 Binding | tex1 tex4 tex23 | tex4 tex7 | ... | ... | ... | | ||
* Texture Unit 1 Binding | ... | ... | | ||
* Texture Unit 2 Binding | | | | ||
* Matrix Uniforms | | | | ||
* Matrial Uniforms | | | | ||
* Draw Elements | | | | ||
* | ||
* | ||
* A cost guide from NVIDIA here: https://i.stack.imgur.com/JgrSc.jpg | ||
* Basically: Render Target > Program > ROP > Texture Bindings > | ||
* Vertex Format > UBO Bindings > Vertex Bindings > Uniform Updates | ||
*/ | ||
class CommandTree | ||
{ | ||
private: | ||
vector<shared_ptr<Layer>> m_layers; | ||
|
||
void _executeLayer(RenderOptions &renderOptions, vector<shared_ptr<RenderNode>> &renderNodes, int layerIdx); | ||
|
||
public: | ||
CommandTree(); | ||
|
||
void addLayer(shared_ptr<Layer> layer); | ||
void execute(RenderOptions &renderOptions, shared_ptr<RenderChain> renderChain); | ||
}; |
32 changes: 32 additions & 0 deletions
32
AggroEngine/src/Subsystem/Graphics/Impl/OpenGL/CommandTree/CommandTreeItem.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#include "CommandTreeItem.hpp" | ||
|
||
CommandTreeItem::CommandTreeItem() | ||
{ | ||
} | ||
|
||
void CommandTreeItem::addCommand(shared_ptr<Command> command, shared_ptr<RenderNode> renderNode) | ||
{ | ||
shared_ptr<Command> existing; | ||
for (int i = 0; i < m_commands.size(); i++) | ||
{ | ||
if (command->equals(m_commands[i])) | ||
{ | ||
existing = m_commands[i]; | ||
break; | ||
} | ||
} | ||
if (!existing) | ||
{ | ||
m_commands.push_back(command); | ||
existing = command; | ||
} | ||
if (renderNode) | ||
{ | ||
existing->addRenderNode(renderNode); | ||
} | ||
} | ||
|
||
vector<shared_ptr<Command>> &CommandTreeItem::getCommands() | ||
{ | ||
return m_commands; | ||
} |
17 changes: 17 additions & 0 deletions
17
AggroEngine/src/Subsystem/Graphics/Impl/OpenGL/CommandTree/CommandTreeItem.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#pragma once | ||
|
||
#include <unordered_map> | ||
#include "Commands/Command.hpp" | ||
|
||
class CommandTreeItem | ||
{ | ||
private: | ||
vector<shared_ptr<Command>> m_commands; | ||
//unordered_map<Command, shared_ptr<Command>, CommandHash> m_existingCommands; | ||
|
||
public: | ||
CommandTreeItem(); | ||
|
||
void addCommand(shared_ptr<Command> command, shared_ptr<RenderNode> renderNode); | ||
vector<shared_ptr<Command>> &getCommands(); | ||
}; |
24 changes: 24 additions & 0 deletions
24
AggroEngine/src/Subsystem/Graphics/Impl/OpenGL/CommandTree/Commands/Command.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#include "Command.hpp" | ||
|
||
Command::Command() | ||
: m_renderNodes() | ||
{ | ||
} | ||
|
||
void Command::addRenderNode(shared_ptr<RenderNode> node) | ||
{ | ||
m_renderNodes.push_back(node); | ||
} | ||
|
||
vector<shared_ptr<RenderNode>> &Command::getRenderNodes() | ||
{ | ||
return m_renderNodes; | ||
} | ||
|
||
void Command::executeCommand() | ||
{ | ||
} | ||
|
||
void Command::end() | ||
{ | ||
} |
28 changes: 28 additions & 0 deletions
28
AggroEngine/src/Subsystem/Graphics/Impl/OpenGL/CommandTree/Commands/Command.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#pragma once | ||
|
||
#include <vector> | ||
#include "RenderNode.hpp" | ||
using namespace std; | ||
|
||
enum CommandType { | ||
EMPTY = 0, | ||
INIT_GBUFFER = 1, | ||
DISABLE_DEPTH = 2, | ||
DRAW_ELEMENTS = 3 | ||
}; | ||
|
||
class Command | ||
{ | ||
protected: | ||
vector<shared_ptr<RenderNode>> m_renderNodes; | ||
|
||
public: | ||
Command(); | ||
|
||
void addRenderNode(shared_ptr<RenderNode> node); | ||
vector<shared_ptr<RenderNode>> &getRenderNodes(); | ||
|
||
virtual void executeCommand(); | ||
virtual void end(); | ||
virtual bool equals(shared_ptr<Command> other) { return false; }; | ||
}; |
23 changes: 23 additions & 0 deletions
23
AggroEngine/src/Subsystem/Graphics/Impl/OpenGL/CommandTree/Commands/DisableDepthCommand.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#include "DisableDepthCommand.hpp" | ||
#include "OpenGL43Graphics.hpp" | ||
|
||
DisableDepthCommand::DisableDepthCommand() | ||
: Command() | ||
{ | ||
} | ||
|
||
void DisableDepthCommand::executeCommand() | ||
{ | ||
glDisable(GL_DEPTH_TEST); | ||
} | ||
|
||
void DisableDepthCommand::end() | ||
{ | ||
glEnable(GL_DEPTH_TEST); | ||
} | ||
|
||
bool DisableDepthCommand::equals(shared_ptr<Command> other) | ||
{ | ||
DisableDepthCommand *cmd = static_cast<DisableDepthCommand *>(other.get()); | ||
return cmd->m_type == CommandType::DISABLE_DEPTH; | ||
} |
16 changes: 16 additions & 0 deletions
16
AggroEngine/src/Subsystem/Graphics/Impl/OpenGL/CommandTree/Commands/DisableDepthCommand.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#pragma once | ||
|
||
#include "Command.hpp" | ||
|
||
class DisableDepthCommand : public Command | ||
{ | ||
private: | ||
CommandType m_type = CommandType::DISABLE_DEPTH; | ||
|
||
public: | ||
DisableDepthCommand(); | ||
|
||
virtual void executeCommand(); | ||
virtual void end(); | ||
virtual bool equals(shared_ptr<Command> other); | ||
}; |
Oops, something went wrong.