Skip to content

Commit

Permalink
dynamic resolution
Browse files Browse the repository at this point in the history
  • Loading branch information
malytomas committed Nov 10, 2024
1 parent cfd8feb commit 9900787
Show file tree
Hide file tree
Showing 3 changed files with 162 additions and 2 deletions.
2 changes: 1 addition & 1 deletion externals/cage
Submodule cage updated 37 files
+0 −0 data/cage/shader/engine/blitPixels.glsl
+26 −0 data/cage/shader/engine/blitScaled.glsl
+3 −2 data/cage/shader/engine/engine.assets
+3 −2 data/cage/shader/engine/engine.pack
+0 −0 data/cage/shader/engine/text.glsl
+0 −1 data/cage/shader/shader.assets
+0 −2 data/cage/shader/shader.pack
+0 −14 data/cage/shader/visualize/color.glsl
+0 −20 data/cage/shader/visualize/depth.glsl
+0 −14 data/cage/shader/visualize/monochromatic.glsl
+0 −9 data/cage/shader/visualize/vertex.glsl
+0 −10 data/cage/shader/visualize/visualize.assets
+0 −5 data/cage/shader/visualize/visualize.pack
+1 −1 externals/openxr-sdk/OpenXR-SDK
+7 −4 sources/include/cage-engine/guiBuilder.h
+1 −0 sources/include/cage-engine/guiComponents.h
+3 −6 sources/include/cage-engine/provisionalGraphics.h
+9 −35 sources/include/cage-engine/renderPipeline.h
+17 −0 sources/include/cage-engine/renderQueue.h
+3 −0 sources/include/cage-engine/virtualReality.h
+9 −1 sources/include/cage-simple/engine.h
+12 −13 sources/include/cage-simple/statisticsGui.h
+0 −6 sources/libcore/memory/memoryArena.cpp
+21 −33 sources/libengine/graphics/provisionalGraphics.cpp
+103 −173 sources/libengine/graphics/renderPipeline.cpp
+16 −0 sources/libengine/graphics/renderQueue.cpp
+4 −9 sources/libengine/graphics/screenSpaceEffects.cpp
+1 −0 sources/libengine/gui/gui.cpp
+8 −1 sources/libengine/gui/private.h
+17 −0 sources/libengine/gui/tooltips.cpp
+25 −4 sources/libengine/virtualReality/openxr.cpp
+2 −2 sources/libsimple/engine.h
+6 −0 sources/libsimple/externs.cpp
+58 −31 sources/libsimple/gameloop.cpp
+256 −204 sources/libsimple/graphics.cpp
+3 −3 sources/libsimple/guiInWorld.cpp
+7 −17 sources/libsimple/statisticsGui.cpp
2 changes: 1 addition & 1 deletion sources/engine/rawWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ int main(int argc, char *args[])
// fetch assets
Holder<Model> model = assets->get<AssetSchemeIndexModel, Model>(HashString("cage/model/square.obj"));
Holder<Texture> texture = assets->get<AssetSchemeIndexTexture, Texture>(HashString("cage-tests/logo/logo.png"));
Holder<ShaderProgram> shader = assets->get<AssetSchemeIndexShaderProgram, MultiShaderProgram>(HashString("cage/shader/engine/blit.glsl"))->get(0);
Holder<ShaderProgram> shader = assets->get<AssetSchemeIndexShaderProgram, MultiShaderProgram>(HashString("cage/shader/engine/blitPixels.glsl"))->get(0);
Holder<Sound> sound = assets->get<AssetSchemeIndexSound, Sound>(HashString("cage-tests/logo/logo.ogg"));

// initialize graphics
Expand Down
160 changes: 160 additions & 0 deletions sources/simple/dynamicResolution.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
#include <cage-core/assetsManager.h>
#include <cage-core/entitiesVisitor.h>
#include <cage-core/hashString.h>
#include <cage-core/logger.h>
#include <cage-engine/guiBuilder.h>
#include <cage-engine/highPerformanceGpuHint.h>
#include <cage-engine/scene.h>
#include <cage-engine/sceneScreenSpaceEffects.h>
#include <cage-engine/window.h>
#include <cage-simple/engine.h>
#include <cage-simple/fpsCamera.h>
#include <cage-simple/statisticsGui.h>

using namespace cage;

constexpr uint32 AssetsName = HashString("cage-tests/camera-effects/effects.pack");

struct DataComponent
{
uint64 destroyTime = 0;
};

void addEntities(uint32 cnt)
{
const uint64 time = engineControlTime();
for (uint32 i = 0; i < cnt; i++)
{
Entity *e = engineEntities()->createAnonymous();
e->value<DataComponent>().destroyTime = time + randomRange(200, 300) * 1'000;
e->value<RenderComponent>().object = HashString("scenes/mcguire/crytek/sponza.object");
e->value<RenderComponent>().opacity = randomChance() * 0.4 + 0.3; // prevent depth pre-pass optimization
e->value<TransformComponent>().position += randomDirection3() * randomRange(0.01, 0.1);
}
}

void update()
{
const uint64 time = engineControlTime();
entitiesVisitor(
[time](Entity *e, const DataComponent &d)
{
if (time > d.destroyTime)
e->destroy();
},
engineEntities(), true);

const sint32 cnt = numeric_cast<sint32>((sin(Degs(time / 200'000)) + 0.8) * 20);
if (cnt > 0)
addEntities(cnt);
}

void keyPress(input::KeyPress in)
{
if (in.key == 32) // space
addEntities(100);
}

void generateGui()
{
Holder<GuiBuilder> g = newGuiBuilder(engineGuiEntities());
auto _1 = g->alignment(Vec2(0));
auto _2 = g->spoiler(false).text("Dynamic Resolution");
auto _3 = g->verticalTable(3);
{
g->label().text("Enabled: ");
g->checkBox(engineDynamicResolution().enabled).event(inputFilter([](input::GuiValue v) { engineDynamicResolution().enabled = v.entity->value<GuiCheckBoxComponent>().state == CheckBoxStateEnum::Checked; }));
g->empty();
}
{
g->label().text("Target FPS: ");
g->horizontalSliderBar(engineDynamicResolution().targetFps, 1, 90).event(inputFilter([](input::GuiValue v) { engineDynamicResolution().targetFps = v.entity->value<GuiSliderBarComponent>().value.value; }));
g->label().text("").update([](Entity *e) { e->value<GuiTextComponent>().value = Stringizer() + engineDynamicResolution().targetFps; });
}
{
g->label().text("Minimum Scale: ");
g->horizontalSliderBar(engineDynamicResolution().minimumScale, 0.1, 1.0).event(inputFilter([](input::GuiValue v) { engineDynamicResolution().minimumScale = v.entity->value<GuiSliderBarComponent>().value; }));
g->label().text("").update([](Entity *e) { e->value<GuiTextComponent>().value = Stringizer() + engineDynamicResolution().minimumScale; });
}
}

int main(int argc, char *args[])
{
try
{
initializeConsoleLogger();
engineInitialize(EngineCreateConfig());

// events
const auto updateListener = controlThread().update.listen(update);
const auto closeListener = engineWindow()->events.listen(inputFilter([](input::WindowClose) { engineStop(); }));
const auto keyPressListener = engineWindow()->events.listen(inputFilter(keyPress));

// window
engineWindow()->title("dynamic resolution");
engineWindow()->setMaximized();
generateGui();

// entities
EntityManager *ents = engineEntities();
ents->defineComponent(DataComponent());
{ // camera
Entity *e = ents->create(1);
TransformComponent &t = e->value<TransformComponent>();
t.position = Vec3(11.5, 1, -1);
t.orientation = Quat(Degs(10), Degs(110), Degs());
CameraComponent &c = e->value<CameraComponent>();
c.ambientColor = Vec3(1);
c.ambientIntensity = 0.05;
c.near = 0.1;
c.far = 100;
e->value<ScreenSpaceEffectsComponent>();
}
{ // skybox
Entity *e = ents->createAnonymous();
e->value<TransformComponent>();
e->value<RenderComponent>().object = HashString("scenes/common/skybox.obj");
e->value<TextureAnimationComponent>();
}
{ // sun
Entity *e = ents->create(2);
TransformComponent &t = e->value<TransformComponent>();
t.position = Vec3(0, 5, 0);
t.orientation = Quat(Degs(-75), Degs(-120), Degs());
LightComponent &l = e->value<LightComponent>();
l.lightType = LightTypeEnum::Directional;
l.color = Vec3(1);
l.intensity = 3;
ShadowmapComponent &s = e->value<ShadowmapComponent>();
s.resolution = 2048;
s.directionalWorldSize = 30;
}
{ // floor
Entity *e = ents->createAnonymous();
e->value<RenderComponent>().object = HashString("scenes/common/ground.obj");
e->value<TransformComponent>().position = Vec3(0, -1.264425, 0);
}
{ // sponza
Entity *e = ents->createAnonymous();
e->value<RenderComponent>().object = HashString("scenes/mcguire/crytek/sponza.object");
e->value<TransformComponent>();
}

Holder<FpsCamera> fpsCamera = newFpsCamera(ents->get(1));
fpsCamera->mouseButton = MouseButtonsFlags::Left;
fpsCamera->movementSpeed = 0.3;
Holder<StatisticsGui> statistics = newStatisticsGui();

engineAssets()->load(AssetsName);
engineRun();
engineAssets()->unload(AssetsName);
engineFinalize();

return 0;
}
catch (...)
{
detail::logCurrentCaughtException();
return 1;
}
}

0 comments on commit 9900787

Please sign in to comment.