Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
af93ef7
new renderer system in place but not working 100%. TODO: fix buttons …
TheMaverickProgrammer Aug 31, 2022
4fd6eee
Tonight, we added the Immediate class tag type for swoosh to render d…
TheMaverickProgrammer Nov 6, 2022
7c7295a
All shaders using new renderer system with correct results
TheMaverickProgrammer Nov 7, 2022
6963aa4
forgot to re-add the EventBase type check in static assert. Fixed. Be…
TheMaverickProgrammer Nov 7, 2022
77d92a9
Customer renderer proof of concept with psuedo 3D lighting working. T…
TheMaverickProgrammer Nov 9, 2022
eafba12
deferred shader made progress. some issue with the light shape and cu…
TheMaverickProgrammer Nov 11, 2022
e980af1
fixed deferred rendering to use the correct lighting pass. added emis…
TheMaverickProgrammer Nov 13, 2022
f8d2948
fixed emissive oversampling. Rewrote some of the Fake3D constructor. …
TheMaverickProgrammer Nov 13, 2022
fe88a18
added pretty lights to title screen. still have not solved the clone …
TheMaverickProgrammer Nov 14, 2022
609cf66
merged emissive, specular, and metallic properties into one buffer. a…
TheMaverickProgrammer Nov 16, 2022
5351f5d
Clone() utility function added to swoosh and works. TODO: document an…
Nov 23, 2022
20d7b13
Added documentation. TODO: move some of the 3D event types to their o…
Nov 23, 2022
bd13243
fixing segue issues with new render pipeline...
Nov 24, 2022
613e6f7
fixed memory leak with Clone()
Nov 25, 2022
d3f365d
minor API redesign for display(), getTexture(), and now auto-handling…
Nov 25, 2022
5fb95b5
switched drawable ref to a ptr to make it clear the memory should sta…
Nov 25, 2022
f9703bf
added emissive pass and position pass to collect Z for lighting calcu…
Dec 1, 2022
d3b7efe
prod fix
TheMaverickProgrammer Jan 7, 2023
058d2b6
compiles on linux. TODO: do not delete void ptrs...
TheMaverickProgrammer Jan 27, 2023
75e00b6
fixed UB with deleting void ptrs by supplying a delete policy
TheMaverickProgrammer Jan 27, 2023
7502345
added utilities to make mutating the stack multithread friendly. a fu…
TheMaverickProgrammer Aug 27, 2023
2aef417
bad use of variable undetected before because of templates. fixed.
TheMaverickProgrammer Aug 27, 2023
685522e
1) Events can now be anything. RenderSources are still handled as sfm…
TheMaverickProgrammer Jan 22, 2024
163e391
Thenables -> Yieldables. Call yield() on push intents to collect data…
TheMaverickProgrammer Jan 28, 2024
6b03aea
Fixed compile issues in another project
TheMaverickProgrammer Jan 28, 2024
2bb8e91
last refactor broke ability to yield() anything. fixed.
TheMaverickProgrammer Jan 28, 2024
79fa406
made getCurrentAcivity() non-cost qualified version. getRenderer<T>()…
TheMaverickProgrammer Feb 25, 2024
b5f5119
Rewrote the way renderers are registered in order to defer their init…
TheMaverickProgrammer Jun 14, 2024
6482581
Merge with upstream
TheMaverickProgrammer Jun 14, 2024
797d011
renamed Yieldable -> PopResult. yield() fn -> take(). retain() fn -> …
TheMaverickProgrammer Jun 15, 2024
b936245
renamed swoosh:: -> sw:: namespace. Removed all unnecessary swoosh:: …
TheMaverickProgrammer Jun 15, 2024
249a751
renamed Game.h -> Utils.h. Updated the readme. The readme should be b…
TheMaverickProgrammer Jun 15, 2024
9253d52
setRenderer -> activateRenderEntry. getCurrentRendererIndex -> getAct…
TheMaverickProgrammer Jun 16, 2024
61e776d
added getRenderInstance<T> and placed assert guards around the render…
TheMaverickProgrammer Jun 16, 2024
b5aaf06
Contexts have been broken up into a memory Bucket object which handle…
TheMaverickProgrammer Jun 18, 2024
a5d10dd
re-ordered the way PopDataHandlers were being executed. Before any on…
TheMaverickProgrammer Jun 24, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions ExampleDemo/Button.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once
#include <SFML/Graphics.hpp>
#include <Swoosh/Game.h>
#include <Swoosh/Utils.h>

// Custom class definitions
struct button;
Expand All @@ -24,7 +24,7 @@ struct button {
}
}

void draw(sf::RenderTexture& surface, sf::Text& sftext, float x, float y) {
void draw(IRenderer& renderer, sf::Text& sftext, float x, float y) {
if (isHovering) {
sprite.setColor(sf::Color(200, 200, 200));
}
Expand All @@ -34,12 +34,12 @@ struct button {

sprite.setPosition(sf::Vector2f(x, y));
sprite.setOrigin(sprite.getGlobalBounds().width / 2.0f, sprite.getGlobalBounds().height / 2.0f);
surface.draw(sprite);
renderer.submit(Clone(sprite));

sftext.setString(text);
sftext.setOrigin(sftext.getGlobalBounds().width / 2.0f, sftext.getGlobalBounds().height / 2.0f);
sftext.setPosition(sf::Vector2f(x, y - sftext.getGlobalBounds().height / 2.0f));
surface.draw(sftext);
renderer.submit(Clone(sftext));
}
};

Expand Down
190 changes: 190 additions & 0 deletions ExampleDemo/CustomRenderer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
#pragma once
#include <Swoosh/Renderers/Renderer.h>
#include <Swoosh/Shaders.h>
#include <functional>
#include <array>
#include <optional>

/**
@class Draw3D
@brief A render event with material data that can render 2D graphics as psuedo-3D
*/
struct Draw3D : sw::RenderSource {
sw::glsl::deferred::MeshData data; // !< aggregate data for the 2D model

explicit Draw3D(sf::Sprite* spr,
sf::Texture* normal,
sf::Texture* emissive = nullptr,
float metallic = 0,
float specular = 0) :
RenderSource(spr),
data({ spr, normal, emissive, metallic, specular })
{}

Draw3D WithZ(float z) {
data.WithZ(z);
return *this;
}
};

/**
@class Light
@brief A render event with lighting data for rendering lights
If used in a SimpleRenderer, will draw the light as a circle
*/
struct Light : sw::RenderSource {
float radius{};
sf::Vector3f position{};
sf::Color color{ sf::Color::White };
sf::CircleShape circle{};
float specular{};
float cutoff{};

explicit Light(float radius,
sf::Vector3f position,
sf::Color color,
float specular = 0.0f,
float cutoff = 0.0f) :
RenderSource(&circle),
radius(radius),
position(position),
color(color),
specular(specular),
cutoff(cutoff)
{
circle.setPointCount(360);
circle.setRadius(radius);
circle.setFillColor(color);
circle.setPosition({ position.x, position.y });

sf::FloatRect bounds = circle.getLocalBounds();
circle.setOrigin(bounds.width/2, bounds.height/2);
};
};

/**
@brief Transform 2D vector into a 3D vector
@param xy a 2D vector
@param z a float representing the 3rd dimension
@return sf::Vector3f with a z value
*/
sf::Vector3f WithZ(const sf::Vector2f xy, float z) {
return sf::Vector3f(xy.x, xy.y, z);
}

/**
@class CustomRenderer
@brief A custom renderer example that uses swoosh shaders to compose a 3D scene
Uses `Draw3D` render event as a tag to draw the sprite multiple times with different G-buffer texture values
Uses `Light` render event as a tag to calculate the final lighting in the scene
The end result is a partial implementation of a deferred renderer commonly used in advanced 3D applications
*/
class CustomRenderer : public sw::Renderer<Draw3D, Light> {
sf::RenderTexture position, diffuse, normal, esm, out;
glsl::deferred::PositionPass positionShader;
glsl::deferred::LightPass lightShader;
glsl::deferred::EmissivePass emissiveShader;
glsl::deferred::MeshPass meshShader;
std::list<sw::RenderSource> memForward;
std::list<Draw3D> mem3D;
std::list<Light> memLight;

public:
CustomRenderer(const sf::View& view) {
const unsigned int ux = (unsigned int)view.getSize().x;
const unsigned int uy = (unsigned int)view.getSize().y;
const sf::Vector2u size = sf::Vector2u(ux, uy);

position.create(size.x, size.y);
diffuse.create(size.x, size.y);
normal.create(size.x, size.y);
esm.create(size.x, size.y);
out.create(size.x, size.y);

meshShader.configure(&diffuse, &normal, &esm);
positionShader.configure(-100, 100, view, &position);
lightShader.configure(view, &position, &diffuse, &normal, &esm);
emissiveShader.configure(&diffuse, &esm);
}

sw::SystemCompatibilityScore checkSystemCompatibility() const override {
// TODO: show how to grade system specs
return sw::SystemCompatibilityScore::sufficient;
}

void draw() override {
mem3D.sort([](Draw3D& a, Draw3D& b) { return a.data.getPosition3D().z < b.data.getPosition3D().z; });

for (Draw3D& source : mem3D) {

// bake the currect normals
meshShader.setMeshData(source.data);
meshShader.apply(*this);

// bake the position data
positionShader.setMeshData(source.data);
positionShader.apply(*this);
}

lightShader.clearLights();
bool applyLight = memLight.size() > 0;
for (Light& source : memLight) {
lightShader.addLight(source.radius,
source.position,
source.color,
source.specular,
source.cutoff);
}

// render light geometry over the scene
if(applyLight) {
lightShader.apply(*this);
}

// draw emissive lighting
emissiveShader.apply(*this);

// draw forward rendered content
for (sw::RenderSource& source : memForward) {
out.draw(*source.drawable());
}

// clear the buffer data
memForward.clear();
mem3D.clear();
memLight.clear();
}

void clear(sf::Color color) override {
// for G-buffers the clear color must always be transparent
position.clear(sf::Color::Transparent);
diffuse.clear(sf::Color::Transparent);
normal.clear(sf::Color::Transparent);
esm.clear(sf::Color::Transparent);
out.clear(color);
}

void setView(const sf::View& view) override {
position.setView(view);
diffuse.setView(view);
normal.setView(view);
esm.setView(view);
out.setView(view);
}

sf::RenderTexture& getRenderTextureTarget() override {
return out;
}

void onEvent(const sw::RenderSource& event) override {
memForward.push_back(event);
}

void onEvent(const Draw3D& event) override {
mem3D.emplace_back(event);
}

void onEvent(const Light& event) override {
memLight.emplace_back(event);
}
};
77 changes: 63 additions & 14 deletions ExampleDemo/Demo.cpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
//This file contains the C++ entry main function and demonstrates
//using the Activity Controller with SFML's main loop

#include <SFML/Window.hpp>
#include <Swoosh/ActivityController.h>
#include <Swoosh/Renderers/SimpleRenderer.h>
#include <Segues/ZoomOut.h>
#include "Scenes/MainMenuScene.h"

#include <Swoosh/ActionList.h>

using namespace swoosh;
#include <SFML/Window.hpp>
#include "Scenes/IntroScene.h"
#include "CustomRenderer.h"

int main()
{
Expand All @@ -17,16 +14,54 @@ int main()
window.setVerticalSyncEnabled(true);
window.setMouseCursorVisible(false);

// Create an AC with the current window as our target to draw to
ActivityController app(window);
// 11/23/2022 (NEW BEHAVIOR!)
// Swoosh now enables custom render pipelines and
// can switch between them in real-time
sw::RenderEntries renderOptions;
renderOptions
.enroll<CustomRenderer>("custom", window.getView())
.enroll<SimpleRenderer>("simple", window.getView());

// Create an AC with the current window as our target to draw to
sw::ActivityController app(window, renderOptions);

// 10/9/2020
// For mobile devices or low-end GPU's, you can request optimized
// effects any time by setting the performance quality to
// one of the following: { realtime, reduced, mobile }
app.optimizeForPerformance(quality::realtime);
app.optimizeForPerformance(sw::quality::realtime);
// app.optimizeForPerformance(quality::mobile); // <-- uncomment me!

// 06/12/2024
// The AC needs a renderer in order to draw anything.
// This was added to allow programmers to check for platform compatibilities
// before commiting to constructing renderers which will require resources.
// After the options are build, the programmer can iterate through the list
// and check their SystemCompatibilityScores to determine which to use.
app.buildRenderEntries();

std::string errors;
if(renderOptions.built() && renderOptions.countValid() > 0) {
for(auto& iter : renderOptions.list()) {
auto score = iter.getInstance().checkSystemCompatibility();
if(score == sw::SystemCompatibilityScore::sufficient) {
app.activateRenderEntry(iter.getIndex());
continue;
}
if (score == sw::SystemCompatibilityScore::build_error) {
errors += iter.getError() + "\n";
}
// For example's sake, we will free insufficient renderers
iter.free();
}
} else {
// Running this application without a renderer is pointless.
std::cout << "Application cannot render as configured.\n";
std::cout << "Errors: " << errors << std::endl;
return -1; // Quit
}


// (DEFAULT BEHAVIOR!)
// Add the Main Menu Scene as the first and only scene in our stack
// This is our starting point for the user
Expand All @@ -36,7 +71,8 @@ int main()
// Swoosh now supports generating blank activities from window contents!
// The segue will copy the window at startup and use it as part of
// the screen transition as demonstrated here
app.push<segue<ZoomOut>::to<MainMenuScene>>();
app.push<sw::segue<ZoomOut>::to<IntroScene>>();
// app.push<MainMenuScene>(); // uncomment this and comment the line above for old behavior

sf::Texture* cursorTexture = loadTexture(CURSOR_PATH);
sf::Sprite cursor;
Expand Down Expand Up @@ -67,6 +103,18 @@ int main()
else if (event.type == sf::Event::GainedFocus) {
pause = false;
}
else if (event.type == sf::Event::KeyPressed) {
// Toggle to different renderers using F-keys
sf::Keyboard::Key code = event.key.code;
if (code == sf::Keyboard::F1 && app.activateRenderEntry(0)) {
const std::string& name = app.getActiveRenderEntry().getName();
window.setTitle("Swoosh Demo (renderer=" + name + ")");
}
else if (code == sf::Keyboard::F2 && app.activateRenderEntry(1)) {
const std::string& name = app.getActiveRenderEntry().getName();
window.setTitle("Swoosh Demo (renderer=" + name + ")");
}
}
}

// do not update segues when the window is frozen
Expand All @@ -77,12 +125,13 @@ int main()
// We clear after updating so that other items can copy the screen's contents
window.clear();

// draw() will directly draw onto the window's render buffer
app.draw();

// Track the mouse and create a light source for this pass on the mouse!
sf::Vector2f mousepos = window.mapPixelToCoords(sf::Mouse::getPosition(window));
cursor.setPosition(mousepos);

// draw() will directly draw onto the window's render buffer
app.draw();

// Draw the mouse cursor over everything else
window.draw(cursor);

Expand Down
19 changes: 16 additions & 3 deletions ExampleDemo/ResourcePaths.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,33 @@ constexpr auto MANUAL_FONT = "resources/manual.ttf";

constexpr auto SFML_PATH = "resources/SFML.png";
constexpr auto MENU_BG_PATH = "resources/menu.png";
constexpr auto PURPLE_BG_PATH = "resources/SpaceShooterRedux/Backgrounds/purple.png";
constexpr auto MENU_BG_N_PATH = "resources/menu_n.png";
constexpr auto GAME_BG_PATH = "resources/SpaceShooterRedux/Backgrounds/purple.png";
constexpr auto GAME_BG_N_PATH = "resources/SpaceShooterRedux/Backgrounds/purple_n.png";
constexpr auto GAME_BG_E_PATH = "resources/SpaceShooterRedux/Backgrounds/background_e.png";
constexpr auto CURSOR_PATH = "resources/SpaceShooterRedux/PNG/UI/cursor.png";
constexpr auto STAR_PATH = "resources/star.png";
constexpr auto BLUE_BTN_PATH = "resources/SpaceShooterRedux/PNG/UI/buttonBlue.png";
constexpr auto RED_BTN_PATH = "resources/SpaceShooterRedux/PNG/UI/buttonRed.png";
constexpr auto GREEN_BTN_PATH = "resources/SpaceShooterRedux/PNG/UI/buttonGreen.png";
constexpr auto METEOR_BIG_PATH = "resources/SpaceShooterRedux/PNG/Meteors/meteorBrown_big1.png";
constexpr auto METEOR_BIG_PATH = "resources/SpaceShooterRedux/PNG/Meteors/meteorBrown_big4.png";
constexpr auto METEOR_MED_PATH = "resources/SpaceShooterRedux/PNG/Meteors/meteorBrown_med1.png";
constexpr auto METEOR_SMALL_PATH = "resources/SpaceShooterRedux/PNG/Meteors/meteorBrown_small1.png";
constexpr auto METEOR_TINY_PATH = "resources/SpaceShooterRedux/PNG/Meteors/meteorBrown_tiny1.png";
constexpr auto METEOR_BIG_N_PATH = "resources/SpaceShooterRedux/PNG/Meteors/meteorBrown_big4_n.png";
constexpr auto METEOR_MED_N_PATH = "resources/SpaceShooterRedux/PNG/Meteors/meteorBrown_med1_n.png";
constexpr auto METEOR_SMALL_N_PATH = "resources/SpaceShooterRedux/PNG/Meteors/meteorBrown_small1_n.png";
constexpr auto METEOR_TINY_N_PATH = "resources/SpaceShooterRedux/PNG/Meteors/meteorBrown_tiny1_n.png";
constexpr auto SHIELD_HIGH_PATH = "resources/SpaceShooterRedux/PNG/Effects/shield1.png";
constexpr auto SHIELD_LOW_PATH = "resources/SpaceShooterRedux/PNG/Effects/shield2.png";
constexpr auto PLAYER_PATH = "resources/SpaceShooterRedux/PNG/playerShip3_orange.png";
constexpr auto PLAYER_PATH = "resources/SpaceShooterRedux/PNG/playerShip1_orange.png";
constexpr auto PLAYER_N_PATH= "resources/SpaceShooterRedux/PNG/playerShip1_n.png";
constexpr auto PLAYER_E_PATH = "resources/SpaceShooterRedux/PNG/playerShip1_e.png";
constexpr auto PLAYER_TRAIL_PATH = "resources/SpaceShooterRedux/PNG/Lasers/laserBlue08.png";
constexpr auto LASER_BEAM_PATH = "resources/SpaceShooterRedux/PNG/Lasers/laserGreen10.png";
constexpr auto ENEMY_PATH = "resources/SpaceShooterRedux/PNG/Enemies/enemyGreen3.png";
constexpr auto ENEMY_N_PATH = "resources/SpaceShooterRedux/PNG/Enemies/enemyGreen3_n.png";
constexpr auto ENEMY_E_PATH = "resources/SpaceShooterRedux/PNG/Enemies/enemyGreen3_e.png";
constexpr auto EXTRA_LIFE_PATH = "resources/SpaceShooterRedux/PNG/Power-ups/star_gold.png";

const char* NUMERAL_PATH[11] = {
Expand All @@ -42,6 +54,7 @@ constexpr auto LOSE_SFX_PATH = "resources/SpaceShooterRedux/Bonus/sfx_los
constexpr auto LASER1_SFX_PATH = "resources/SpaceShooterRedux/Bonus/sfx_laser1.ogg";
constexpr auto LASER2_SFX_PATH = "resources/SpaceShooterRedux/Bonus/sfx_laser2.ogg";
constexpr auto TWO_TONE_SFX_PATH = "resources/SpaceShooterRedux/Bonus/sfx_twoTone.ogg";
constexpr auto EXPLODE_SFX_PATH = "resources/SpaceShooterRedux/Bonus/sfx_explode.ogg";
constexpr auto THEME_MUSIC_PATH = "resources/theme.ogg";
constexpr auto INGAME_MUSIC_PATH = "resources/ingame.ogg";

Expand Down
Loading