Skip to content

Fixes for Oryol sokol-gfx migration #13

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 25 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions fips-verbs/webpage.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def deploy_webpage(fips_dir, proj_dir, webpage_dir) :

# link to the Core Samples
content = '<div class="thumb">\n'
content += ' <div class="thumb-title">To Core Samples...</div>\n'
content += ' <div class="thumb-title">Core Samples...</div>\n'
content += ' <div class="img-frame"><a href="http://floooh.github.com/oryol/index.html"><img class="image" src="core_samples.jpg"></img></a></div>\n'
content += '</div>\n'

Expand Down Expand Up @@ -72,7 +72,7 @@ def deploy_webpage(fips_dir, proj_dir, webpage_dir) :
f.write(html)

# copy other required files
for name in ['style.css', 'dummy.jpg', 'emsc.js', 'wasm.js', 'about.html', 'favicon.png', 'core_samples.jpg'] :
for name in ['style.css', 'dummy.jpg', 'emsc.js', 'favicon.png', 'core_samples.jpg'] :
log.info('> copy file: {}'.format(name))
shutil.copy(proj_dir + '/web/' + name, webpage_dir + '/' + name)

Expand Down
28 changes: 15 additions & 13 deletions src/BulletPhysicsBasic/BulletPhysicsBasic.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,20 +51,22 @@ OryolMain(BulletPhysicsBasicApp);
//------------------------------------------------------------------------------
AppState::Code
BulletPhysicsBasicApp::OnInit() {

auto gfxSetup = GfxSetup::WindowMSAA4(800, 600, "BulletPhysicsBasic");
gfxSetup.DefaultPassAction = PassAction::Clear(glm::vec4(0.2f, 0.4f, 0.8f, 1.0f));
Gfx::Setup(gfxSetup);
auto gfxDesc = GfxDesc()
.Width(800).Height(600)
.SampleCount(4)
.Title("BulletPhysicsBasic")
.HtmlTrackElementSize(true);
Gfx::Setup(gfxDesc);
this->colorFSParams.shadowMapSize = glm::vec2(float(this->shapeRenderer.ShadowMapSize));

// instanced shape rendering helper class
this->shapeRenderer.ColorShader = Gfx::CreateResource(ColorShader::Setup());
this->shapeRenderer.ColorShaderInstanced = Gfx::CreateResource(ColorShaderInstanced::Setup());
this->shapeRenderer.ShadowShader = Gfx::CreateResource(ShadowShader::Setup());
this->shapeRenderer.ShadowShaderInstanced = Gfx::CreateResource(ShadowShaderInstanced::Setup());
this->shapeRenderer.ColorShader = Gfx::CreateShader(ColorShader::Desc());
this->shapeRenderer.ColorShaderInstanced = Gfx::CreateShader(ColorShaderInstanced::Desc());
this->shapeRenderer.ShadowShader = Gfx::CreateShader(ShadowShader::Desc());
this->shapeRenderer.ShadowShaderInstanced = Gfx::CreateShader(ShadowShaderInstanced::Desc());
this->shapeRenderer.SphereRadius = SphereRadius;
this->shapeRenderer.BoxSize = BoxSize;
this->shapeRenderer.Setup(gfxSetup);
this->shapeRenderer.Setup(gfxDesc);

// setup directional light (for lighting and shadow rendering)
glm::mat4 lightView = glm::lookAt(glm::vec3(50.0f, 50.0f, -50.0f), glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 1.0f, 0.0f));
Expand All @@ -80,7 +82,7 @@ BulletPhysicsBasicApp::OnInit() {
this->colorFSParams.lightDir = glm::vec3(glm::column(glm::inverse(lightView), 2));

Input::Setup();
Dbg::Setup();
Dbg::Setup(DbgDesc().SampleCount(4));
this->camera.Setup();

// setup the initial physics world
Expand All @@ -105,13 +107,13 @@ BulletPhysicsBasicApp::OnRunning() {
this->camera.Update();

// the shadow pass
Gfx::BeginPass(this->shapeRenderer.ShadowPass, this->shapeRenderer.ShadowPassAction);
this->shadowVSParams.mvp = this->lightProjView;
Gfx::BeginPass(this->shapeRenderer.ShadowPass);
this->shapeRenderer.DrawShadows(this->shadowVSParams);
Gfx::EndPass();

// the color pass
Gfx::BeginPass();
Gfx::BeginPass(PassAction().Clear(0.2f, 0.4f, 0.8f, 1.0f));

// draw ground
const glm::mat4 model = Physics::Transform(this->groundRigidBody);
Expand All @@ -129,7 +131,7 @@ BulletPhysicsBasicApp::OnRunning() {
this->colorVSParams.diffColor = glm::vec3(1.0f, 1.0f, 1.0f);
this->shapeRenderer.DrawShapes(this->colorVSParams, this->colorFSParams);

Dbg::PrintF("\n\r"
Dbg::PrintF("\n\n\n\n\n\r"
" Mouse left click + drag: rotate camera\n\r"
" Mouse wheel: zoom camera\n\r"
" P: pause/continue\n\n\r"
Expand Down
86 changes: 47 additions & 39 deletions src/BulletPhysicsCloth/BulletPhysicsCloth.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class BulletPhysicsClothApp : public App {
TimePoint lapTimePoint;
CameraHelper camera;
ShapeRenderer shapeRenderer;
Id clothMesh;
Id clothVertexBuffer;
DrawState clothColorDrawState;
DrawState clothShadowDrawState;
ColorShader::vsParams colorVSParams;
Expand All @@ -66,49 +66,57 @@ OryolMain(BulletPhysicsClothApp);
//------------------------------------------------------------------------------
AppState::Code
BulletPhysicsClothApp::OnInit() {
auto gfxSetup = GfxSetup::WindowMSAA4(800, 600, "BulletPhysicsCloth");
gfxSetup.DefaultPassAction = PassAction::Clear(glm::vec4(0.2f, 0.4f, 0.8f, 1.0f));
Gfx::Setup(gfxSetup);
auto gfxDesc = GfxDesc()
.Width(800).Height(600)
.SampleCount(4)
.Title("BulletPhysicsCloth")
.HtmlTrackElementSize(true);
Gfx::Setup(gfxDesc);
this->colorFSParams.shadowMapSize = glm::vec2(float(this->shapeRenderer.ShadowMapSize));

// instanced shape rendering helper class
const Id colorShader = Gfx::CreateResource(ColorShader::Setup());
const Id shadowShader = Gfx::CreateResource(ShadowShader::Setup());
const Id colorShader = Gfx::CreateShader(ColorShader::Desc());
const Id shadowShader = Gfx::CreateShader(ShadowShader::Desc());
this->shapeRenderer.ColorShader = colorShader;
this->shapeRenderer.ColorShaderInstanced = Gfx::CreateResource(ColorShaderInstanced::Setup());
this->shapeRenderer.ColorShaderInstanced = Gfx::CreateShader(ColorShaderInstanced::Desc());
this->shapeRenderer.ShadowShader = shadowShader;
this->shapeRenderer.ShadowShaderInstanced = Gfx::CreateResource(ShadowShaderInstanced::Setup());
this->shapeRenderer.ShadowShaderInstanced = Gfx::CreateShader(ShadowShaderInstanced::Desc());
this->shapeRenderer.SphereRadius = SphereRadius;
this->shapeRenderer.BoxSize = BoxSize;
this->shapeRenderer.Setup(gfxSetup);
this->shapeRenderer.Setup(gfxDesc);
this->clothColorDrawState.FSTexture[0] = this->shapeRenderer.ShadowMap;

// setup a mesh with dynamic vertex buffer and no indices
// FIXME: use index rendering later
auto meshSetup = MeshSetup::Empty(NumClothVertices, Usage::Stream);
meshSetup.Layout
.Add(VertexAttr::Position, VertexFormat::Float3)
.Add(VertexAttr::Normal, VertexFormat::Float3);
meshSetup.AddPrimitiveGroup(PrimitiveGroup(0, NumClothTriangles*3));
this->clothMesh = Gfx::CreateResource(meshSetup);
this->clothColorDrawState.Mesh[0] = this->clothMesh;
this->clothShadowDrawState.Mesh[0] = this->clothMesh;
VertexLayout layout = {
{ "position", VertexFormat::Float3 },
{ "normal", VertexFormat::Float3 }
};
this->clothVertexBuffer = Gfx::CreateBuffer(BufferDesc()
.Size(NumClothVertices * layout.ByteSize())
.Usage(Usage::Stream));
this->clothColorDrawState.VertexBuffers[0] = this->clothVertexBuffer;
this->clothShadowDrawState.VertexBuffers[0] = this->clothVertexBuffer;

// setup pipeline states (color and shadow pass) for cloth rendering
auto pipSetup = PipelineSetup::FromLayoutAndShader(meshSetup.Layout, colorShader);
pipSetup.DepthStencilState.DepthWriteEnabled = true;
pipSetup.DepthStencilState.DepthCmpFunc = CompareFunc::LessEqual;
pipSetup.RasterizerState.CullFaceEnabled = false;
pipSetup.RasterizerState.SampleCount = gfxSetup.SampleCount;
this->clothColorDrawState.Pipeline = Gfx::CreateResource(pipSetup);

pipSetup = PipelineSetup::FromLayoutAndShader(meshSetup.Layout, shadowShader);
pipSetup.DepthStencilState.DepthWriteEnabled = true;
pipSetup.DepthStencilState.DepthCmpFunc = CompareFunc::LessEqual;
pipSetup.RasterizerState.CullFaceEnabled = false;
pipSetup.RasterizerState.SampleCount = 1;
pipSetup.BlendState.ColorFormat = PixelFormat::RGBA8;
pipSetup.BlendState.DepthFormat = PixelFormat::DEPTH;
this->clothShadowDrawState.Pipeline = Gfx::CreateResource(pipSetup);
this->clothColorDrawState.Pipeline = Gfx::CreatePipeline(PipelineDesc()
.Shader(colorShader)
.Layout(0, layout)
.DepthWriteEnabled(true)
.DepthCmpFunc(CompareFunc::LessEqual)
.CullFaceEnabled(false)
.ColorFormat(gfxDesc.ColorFormat())
.DepthFormat(gfxDesc.DepthFormat())
.SampleCount(gfxDesc.SampleCount()));
this->clothShadowDrawState.Pipeline = Gfx::CreatePipeline(PipelineDesc()
.Shader(shadowShader)
.Layout(0, layout)
.DepthWriteEnabled(true)
.DepthCmpFunc(CompareFunc::LessEqual)
.CullFaceEnabled(false)
.ColorFormat(PixelFormat::RGBA8)
.DepthFormat(PixelFormat::DEPTH)
.SampleCount(1));

// setup directional light (for lighting and shadow rendering)
glm::mat4 lightView = glm::lookAt(glm::vec3(50.0f, 50.0f, -50.0f), glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 1.0f, 0.0f));
Expand Down Expand Up @@ -144,7 +152,7 @@ BulletPhysicsClothApp::OnInit() {
Physics::Add(this->clothSoftBody);

Input::Setup();
Dbg::Setup();
Dbg::Setup(DbgDesc().SampleCount(4));
this->camera.Setup();
camera.Orbital = glm::vec2(glm::radians(40.0f), glm::radians(180.0f));
camera.Center = glm::vec3(0.0f, 7.0f, 0.0f);
Expand All @@ -165,16 +173,16 @@ BulletPhysicsClothApp::OnRunning() {
}

// the shadow pass
Gfx::BeginPass(this->shapeRenderer.ShadowPass);
Gfx::BeginPass(this->shapeRenderer.ShadowPass, this->shapeRenderer.ShadowPassAction);
this->shadowVSParams.mvp = this->lightProjView;
this->shapeRenderer.DrawShadows(this->shadowVSParams);
Gfx::ApplyDrawState(this->clothShadowDrawState);
Gfx::ApplyUniformBlock(this->shadowVSParams);
Gfx::Draw();
Gfx::Draw(0, NumClothTriangles * 3);
Gfx::EndPass();

// begin color pass rendering
Gfx::BeginPass();
Gfx::BeginPass(PassAction().Clear(0.2f, 0.4f, 0.8f, 1.0f));

// draw ground
const glm::mat4 model = Physics::Transform(this->groundRigidBody);
Expand All @@ -199,9 +207,9 @@ BulletPhysicsClothApp::OnRunning() {
Gfx::ApplyDrawState(this->clothColorDrawState);
Gfx::ApplyUniformBlock(this->colorVSParams);
Gfx::ApplyUniformBlock(this->colorFSParams);
Gfx::Draw();
Gfx::Draw(0, NumClothTriangles * 3);

Dbg::PrintF("\n\r"
Dbg::PrintF("\n\n\n\n\n\r"
" Mouse left click + drag: rotate camera\n\r"
" Mouse wheel: zoom camera\n\r"
" P: pause/continue\n\r"
Expand Down Expand Up @@ -317,6 +325,6 @@ BulletPhysicsClothApp::updateClothData() {
}
}
}
Gfx::UpdateVertices(this->clothMesh, this->clothVertices, sizeof(this->clothVertices));
Gfx::UpdateBuffer(this->clothVertexBuffer, this->clothVertices, sizeof(this->clothVertices));
return Clock::Since(startTime);
}
1 change: 0 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ fips_add_subdirectory(Paclone)
fips_add_subdirectory(StbVoxelDemo)
fips_add_subdirectory(TurboBadgerDemo)
fips_add_subdirectory(ImGuiDemo)
#fips_add_subdirectory(ImGuiAdvanced)
fips_add_subdirectory(NuklearUIBasic)
fips_add_subdirectory(NuklearUIAdvanced)
fips_add_subdirectory(Fractal)
Expand Down
1 change: 1 addition & 0 deletions src/Common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ fips_begin_lib(Common)
OrbFile.h OrbFile.cc
OrbLoader.h OrbLoader.cc
Wireframe.h Wireframe.cc
OmshParser.h OmshParser.cc
)
oryol_shader(wireframe_shaders.glsl)
fips_end_lib(Common)
Expand Down
4 changes: 2 additions & 2 deletions src/Common/CameraHelper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ CameraHelper::HandleInput() {
void
CameraHelper::UpdateTransforms() {
// recompute projection matrix if framebuffer size has changed
int w = Gfx::DisplayAttrs().FramebufferWidth;
int h = Gfx::DisplayAttrs().FramebufferHeight;
int w = Gfx::Width();
int h = Gfx::Height();
if ((w != this->fbWidth) || (h != this->fbHeight)) {
this->fbWidth = w;
this->fbHeight = h;
Expand Down
Loading