Skip to content

Commit

Permalink
finish renaming and adjust tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ancientjpeg committed Nov 10, 2024
1 parent 1821820 commit 599c1a0
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 15 deletions.
4 changes: 3 additions & 1 deletion src/rndr/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ Context::Context(bool uses_surface) : uses_surface_(uses_surface)
Context::~Context()
{
/* manually release wgpu surface-related assets */
wgpuSurfaceRelease(surface_->MoveToCHandle());
if (surface_) {
wgpuSurfaceRelease(surface_->MoveToCHandle());
}

glfwDestroyWindow(getWindow());
glfwTerminate();
Expand Down
10 changes: 5 additions & 5 deletions src/rndr/context.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,23 +94,23 @@ class Context {
class GlobalAccess {

public:
GlobalAccess(Context &globals) : globals_(globals)
GlobalAccess(Context &context) : context_(context)
{
}

protected:
Context &getGlobals()
Context &getContext()
{
return globals_;
return context_;
}

const wgpu::Device &getDevice()
{
return globals_.getDevice();
return context_.getDevice();
}

private:
Context &globals_;
Context &context_;
};

} // namespace rndr
Expand Down
2 changes: 1 addition & 1 deletion src/rndr/resources/material.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

namespace rndr {

Material::Material(Context &globals) : GlobalAccess(globals)
Material::Material(Context &context) : GlobalAccess(context)
{
const char *shaderSource = R"(
@vertex
Expand Down
2 changes: 1 addition & 1 deletion src/rndr/resources/material.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace rndr {

class Material : public GlobalAccess {

Material(Context &globals);
Material(Context &context);

Material(const Material &) = delete;
Material &operator=(const Material &) = delete;
Expand Down
6 changes: 3 additions & 3 deletions src/rndr/utils/helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ wgpu::Device requestWGPUDevice(wgpu::Adapter adapter)
return std::move(udata.device);
}

wgpu::RenderPipeline createRenderPipeline(Context &globals)
wgpu::RenderPipeline createRenderPipeline(Context &context)
{

const char *shaderSource = R"(
Expand Down Expand Up @@ -141,7 +141,7 @@ fn fs_main() -> @location(0) vec4<f32> {
shader_module_desc.label = "Default Shader Module";
shader_module_desc.nextInChain = &shader_code_desc;
wgpu::ShaderModule shader_module
= globals.getDevice().CreateShaderModule(&shader_module_desc);
= context.getDevice().CreateShaderModule(&shader_module_desc);

wgpu::RenderPipelineDescriptor pipeline_desc = {};
pipeline_desc.nextInChain = nullptr;
Expand Down Expand Up @@ -196,7 +196,7 @@ fn fs_main() -> @location(0) vec4<f32> {
pipeline_desc.layout = nullptr;

wgpu::RenderPipeline ret
= globals.getDevice().CreateRenderPipeline(&pipeline_desc);
= context.getDevice().CreateRenderPipeline(&pipeline_desc);

return ret;
}
Expand Down
2 changes: 1 addition & 1 deletion src/rndr/utils/helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

namespace rndr {

wgpu::RenderPipeline createRenderPipeline(Context &globals);
wgpu::RenderPipeline createRenderPipeline(Context &context);

namespace helpers {

Expand Down
7 changes: 4 additions & 3 deletions tests/sanity/context.tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
#include <memory>

/** TODO unhide this test when we are able to initialize without a surface */
TEST_CASE("Application initializes and destructs without fault", "[.sanity]")
TEST_CASE("Application initializes and destructs without fault", "[sanity]")
{
auto context = std::make_unique<rndr::Context>();
auto context = std::make_unique<rndr::Context>(false);
ustd::expected init_result = context->initialize();
INFO("Failed to initialize: " << init_result);
REQUIRE(!init_result.ok());
REQUIRE(init_result.ok());
REQUIRE(!context->getSurface());
REQUIRE(context->isInitialized());
}

0 comments on commit 599c1a0

Please sign in to comment.