Skip to content

Commit

Permalink
#67 add single image loading screen
Browse files Browse the repository at this point in the history
  • Loading branch information
vooku committed Oct 21, 2023
1 parent 33da245 commit f8cff36
Show file tree
Hide file tree
Showing 11 changed files with 161 additions and 16 deletions.
4 changes: 4 additions & 0 deletions skinny/skinny.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ copy src\shaders\* bin\data\shaders</Command>
<ItemGroup>
<ClCompile Include="src\ImageLayer.cpp" />
<ClCompile Include="src\Layer.cpp" />
<ClCompile Include="src\LoadingScreen.cpp" />
<ClCompile Include="src\main.cpp" />
<ClCompile Include="src\ofApp.cpp" />
<ClCompile Include="src\base.cpp" />
Expand Down Expand Up @@ -246,6 +247,7 @@ copy src\shaders\* bin\data\shaders</Command>
<ItemGroup>
<ClInclude Include="src\ImageLayer.h" />
<ClInclude Include="src\Layer.h" />
<ClInclude Include="src\LoadingScreen.h" />
<ClInclude Include="src\ofApp.h" />
<ClInclude Include="src\base.h" />
<ClInclude Include="src\Effect.h" />
Expand Down Expand Up @@ -332,6 +334,8 @@ copy src\shaders\* bin\data\shaders</Command>
<ItemGroup>
<None Include="src\shaders\firstPassShader.frag" />
<None Include="src\shaders\firstPassShader.vert" />
<None Include="src\shaders\loadingScreenPassShader.frag" />
<None Include="src\shaders\loadingScreenPassShader.vert" />
<None Include="src\shaders\pingPongPassShader.frag" />
<None Include="src\shaders\pingPongPassShader.vert" />
<None Include="src\shaders\subsamplePassShader.frag" />
Expand Down
12 changes: 12 additions & 0 deletions skinny/skinny.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,9 @@
<ClCompile Include="src\utils.cpp">
<Filter>src</Filter>
</ClCompile>
<ClCompile Include="src\LoadingScreen.cpp">
<Filter>src</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<Filter Include="src">
Expand Down Expand Up @@ -464,6 +467,9 @@
<ClInclude Include="src\utils.h">
<Filter>src</Filter>
</ClInclude>
<ClInclude Include="src\LoadingScreen.h">
<Filter>src</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="icon.rc" />
Expand All @@ -487,5 +493,11 @@
<None Include="src\shaders\subsamplePassShader.vert">
<Filter>src\shaders</Filter>
</None>
<None Include="src\shaders\loadingScreenPassShader.frag">
<Filter>src\shaders</Filter>
</None>
<None Include="src\shaders\loadingScreenPassShader.vert">
<Filter>src\shaders</Filter>
</None>
</ItemGroup>
</Project>
27 changes: 27 additions & 0 deletions skinny/src/LoadingScreen.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include "LoadingScreen.h"

namespace skinny {

//--------------------------------------------------------------
bool LoadingScreen::reload(const ShowDescription& description)
{
note_ = description.getLoadingScreensNote();

img_.clear();

const auto& path = description.getLoadingScreensPath();
if (!path.empty())
{
return img_.load(path);
}

return true;
}

//--------------------------------------------------------------
const ofTexture& LoadingScreen::getNext() const
{
return img_.getTexture();
}

}
24 changes: 24 additions & 0 deletions skinny/src/LoadingScreen.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#pragma once

#include "Playable.h"
#include "Meta.h"

#include "ofImage.h"

namespace skinny {

class LoadingScreen : public Playable {
public:
bool reload(const ShowDescription& description);

const ofTexture& getNext() const;

private:
// #TODO more img
// ##TODO timing

ofImage img_;

};

}
45 changes: 34 additions & 11 deletions skinny/src/Show.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,19 @@ bool Show::loadShaders()
firstPassShader_.load(shaderPathPrefix + "firstPassShader");
pingPongPassShader_.load(shaderPathPrefix + "pingPongPassShader");
subsamplePassShader_.load(shaderPathPrefix + "subsamplePassShader");
loadingScreenPassShader_.load(shaderPathPrefix + "loadingScreenPassShader");

return firstPassShader_.isLoaded() &&
pingPongPassShader_.isLoaded() &&
subsamplePassShader_.isLoaded();
loadingScreenPassShader_.isLoaded();
}

//--------------------------------------------------------------
void Show::setup()
{
Mappable::setup();
loadingScreen_.setup();

ofFboSettings s;
s.width = width_;
Expand All @@ -54,10 +57,11 @@ void Show::setup()
fbos_[0].allocate(s);
fbos_[1].allocate(s);
fbos_[2].allocate(s);
fbos_[3].allocate(s);

s.width /= GUI_MONITOR_SUBSAMPLE;
s.height /= GUI_MONITOR_SUBSAMPLE;
fbos_[3].allocate(s);
fbos_[4].allocate(s);

for (auto& fbo : fbos_)
{
Expand All @@ -78,6 +82,7 @@ void Show::setup()
void Show::exit()
{
Mappable::exit();
loadingScreen_.exit();

if (currentScene_)
currentScene_->done();
Expand Down Expand Up @@ -110,35 +115,44 @@ void Show::draw()
firstPassShader_.end();
fbos_[0].end();

// second pass
// pingpong pass 1
fbos_[1].begin();
pingPongPassShader_.begin();
setupPingPongPassUniforms(true, fbos_[0].getTexture());
ofDrawRectangle(0, 0, width_, height_);
pingPongPassShader_.end();
fbos_[1].end();

// third pass
// pingpong pass 2
fbos_[2].begin();
pingPongPassShader_.begin();
setupPingPongPassUniforms(false, fbos_[1].getTexture());
ofDrawRectangle(0, 0, width_, height_);
pingPongPassShader_.end();
fbos_[2].end();

fbos_[2].getTexture().draw(0.f, 0.f);
// loading screen pass
fbos_[3].begin();
loadingScreenPassShader_.begin();
setupLoadingScreenPassUniforms(fbos_[2].getTexture());
ofDrawRectangle(0, 0, width_, height_);
loadingScreenPassShader_.end();
fbos_[3].end();

// draw main window
fbos_[3].getTexture().draw(0.f, 0.f);

// fourth pass
// monitor pass
if (getStatus().gui && getStatus().gui->requiresVisualMonitor())
{
fbos_[3].begin();
fbos_[4].begin();
subsamplePassShader_.begin();
setupSubsamplePassUniforms(fbos_[2].getTexture());
setupSubsamplePassUniforms(fbos_[3].getTexture());
ofDrawRectangle(0, 0, width_ / GUI_MONITOR_SUBSAMPLE, height_ / GUI_MONITOR_SUBSAMPLE);
subsamplePassShader_.end();
fbos_[3].end();
fbos_[4].end();

fbos_[3].getTexture().readToPixels(subsampledPixels_);
fbos_[4].getTexture().readToPixels(subsampledPixels_);
}
}

Expand All @@ -147,7 +161,9 @@ bool Show::reload(const ShowDescription& description)
{
masterAlphaControl_ = description.getAlphaControl();

return reloadLayers(description) && reloadEffects(description);
return loadingScreen_.reload(description) &&
reloadLayers(description) &&
reloadEffects(description);
}

//--------------------------------------------------------------
Expand Down Expand Up @@ -306,14 +322,21 @@ void Show::setupFirstPassUniforms() const
//--------------------------------------------------------------
void Show::setupPingPongPassUniforms(bool horizontal, const ofTexture& img) const
{
// keep effect uniforms from first pass
pingPongPassShader_.setUniform1iv("fxTypes", uniforms_.fxTypes, MAX_EFFECTS);
pingPongPassShader_.setUniform1iv("fxPlaying", uniforms_.fxPlaying, MAX_EFFECTS);
pingPongPassShader_.setUniform1fv("fxParam", uniforms_.fxParam, MAX_EFFECTS);
pingPongPassShader_.setUniform1i("horizontal", horizontal);
pingPongPassShader_.setUniformTexture("previousPass", img, 0);
}

//--------------------------------------------------------------
void Show::setupLoadingScreenPassUniforms(const ofTexture& img) const
{
loadingScreenPassShader_.setUniform1i("playing", loadingScreen_.isPlaying()); // #TODO
loadingScreenPassShader_.setUniformTexture("previousPass", img, 0);
loadingScreenPassShader_.setUniformTexture("loadingScreen", loadingScreen_.getNext(), 1);
}

//--------------------------------------------------------------
void Show::setupSubsamplePassUniforms(const ofTexture& img) const
{
Expand Down
7 changes: 6 additions & 1 deletion skinny/src/Show.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include "Scene.h"
#include "Mappable.h"
#include "LoadingScreen.h"

namespace skinny {

Expand All @@ -29,6 +30,7 @@ class Show : public Mappable
virtual void exit() override;
void draw();
bool reload(const ShowDescription& description);
bool reloadLoadingScreen(const ShowDescription& description);
bool reloadLayers(const ShowDescription& description);
bool reloadEffects(const ShowDescription& description);
void playPauseEffect(int i);
Expand Down Expand Up @@ -58,6 +60,7 @@ class Show : public Mappable

void setupFirstPassUniforms() const;
void setupPingPongPassUniforms(bool horizontal, const ofTexture& img) const;
void setupLoadingScreenPassUniforms(const ofTexture& img) const;
void setupSubsamplePassUniforms(const ofTexture& img) const;
bool hasActiveFX() const;

Expand All @@ -66,9 +69,11 @@ class Show : public Mappable
mutable ofShader firstPassShader_;
mutable ofShader pingPongPassShader_;
mutable ofShader subsamplePassShader_;
std::array<ofFbo, 4> fbos_;
mutable ofShader loadingScreenPassShader_;
std::array<ofFbo, 5> fbos_;

ofPixels subsampledPixels_;
LoadingScreen loadingScreen_;

const int width_, height_;
ScenePtr currentScene_;
Expand Down
2 changes: 1 addition & 1 deletion skinny/src/base.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ static const int MAIN_WINDOW_HEIGHT = 1080;
static const int GUI_WINDOW_WIDTH = 1500;
static const int GUI_WINDOW_HEIGHT = 800;
static const int GUI_MONITOR_SUBSAMPLE = 8;
static constexpr const char* VERSION = "0.9.7-alpha";
static constexpr const char* VERSION = "0.10.0-alpha";
static constexpr const char* NAME = "Skinny Mixer";
// TODO TITLE VERSION + NAME
static constexpr const char* AUTHOR = "Vadim Vooku Petrov";
Expand Down
13 changes: 12 additions & 1 deletion skinny/src/meta.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

namespace skinny {

static const std::filesystem::path invalid_path = {};
const uint8_t MappableDescription::invalid_midi = 255;
const std::filesystem::path LayerDescription::invalid_path = {};

//--------------------------------------------------------------
MappableDescription::MappableDescription(midiNote note, midiNote cc) :
Expand Down Expand Up @@ -155,6 +155,11 @@ bool ShowDescription::fromXml(ofxXmlSettings& config) {
midiChannel_ = config.getValue("channel", default_channel);
alphaControl_ = config.getValue("masterAlphaControl", DEFAULT_MASTER_ALPHA_CONTROL);
spoutOut_ = config.getValue("spoutOut", false);

config.pushTag("loadingScreens");
loadingScreensPath_ = config.getValue("path", invalid_path.string());
loadingScreensNote_ = config.getValue("midi", MappableDescription::invalid_midi);
config.popTag(); // loadingScreens
config.popTag(); // head

config.pushTag("show");
Expand Down Expand Up @@ -200,6 +205,12 @@ void ShowDescription::toXml(ofxXmlSettings& config) const {
config.setValue("channel", midiChannel_);
config.addValue("masterAlphaControl", alphaControl_);
config.addValue("spoutOut", spoutOut_);

config.addTag("loadingScreens");
config.pushTag("loadingScreens");
config.setValue("path", loadingScreensPath_.string());
config.setValue("midi", loadingScreensNote_);
config.popTag(); // loadingScreens
config.popTag(); // head

config.addTag("show");
Expand Down
6 changes: 4 additions & 2 deletions skinny/src/meta.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ struct MappableDescription : public Serializable {
};

struct LayerDescription : public MappableDescription {
static const std::filesystem::path invalid_path;

LayerDescription() = default;
LayerDescription(unsigned int id,
const std::filesystem::path& path,
Expand Down Expand Up @@ -98,6 +96,8 @@ class ShowDescription : public Serializable {
const auto& getEffects() const { return effects_; }
auto getAlphaControl() const { return alphaControl_; }
auto getSpoutOut() const { return spoutOut_; }
const auto& getLoadingScreensPath() const { return loadingScreensPath_; }
auto getLoadingScreensNote() const { return loadingScreensNote_; }

void setMidiChannel(int channel) { midiChannel_ = channel; }

Expand All @@ -113,6 +113,8 @@ class ShowDescription : public Serializable {
int midiChannel_ = default_channel;
midiNote alphaControl_ = DEFAULT_MASTER_ALPHA_CONTROL;
bool spoutOut_ = false;
std::filesystem::path loadingScreensPath_;
midiNote loadingScreensNote_ = MappableDescription::invalid_midi;

};

Expand Down
25 changes: 25 additions & 0 deletions skinny/src/shaders/loadingScreenPassShader.frag
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#version 440

in vec2 texCoordVarying;

layout(binding = 0) uniform sampler2DRect previousPass;
layout(binding = 1) uniform sampler2DRect loadingScreen;

uniform bool playing;

out vec4 outputColor;

//--------------------------------------------------------------
void main()
{
vec3 blended = texture(previousPass, texCoordVarying).rgb;

if (playing)
{
vec3 screen = texture(loadingScreen, texCoordVarying).rgb;
blended += screen;
blended = clamp(blended, vec3(0.0), vec3(1.0));
}

outputColor = vec4(blended, 1.0);
}
12 changes: 12 additions & 0 deletions skinny/src/shaders/loadingScreenPassShader.vert
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#version 440

in vec4 position;
uniform mat4 modelViewProjectionMatrix;

out vec2 texCoordVarying;

//--------------------------------------------------------------
void main(){
texCoordVarying = position.xy; // y no in texcoord??
gl_Position = modelViewProjectionMatrix * position;
}

0 comments on commit f8cff36

Please sign in to comment.