Skip to content

Commit

Permalink
Make opengl headers private in renderer
Browse files Browse the repository at this point in the history
  • Loading branch information
sguionni committed Dec 20, 2024
1 parent 88a26c1 commit ffa6ecd
Show file tree
Hide file tree
Showing 48 changed files with 231 additions and 425 deletions.
4 changes: 3 additions & 1 deletion app/bench/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#include "user_interface.hpp"
#include <iostream>
#include <renderer/facade.hpp>
#include <renderer/proxy/representation.hpp>
#include <renderer/proxy/voxels.hpp>
#include <util/math/aabb.hpp>

#ifdef _WIN32
Expand Down Expand Up @@ -35,7 +37,7 @@ int main( int, char ** )
UserInterface ui( WIDTH, HEIGHT );

// Renderer.
Renderer::Renderer renderer( WIDTH, HEIGHT, Filesystem::getExecutableDir() / "shaders", ui.getProcAddress() );
Renderer::Facade renderer( WIDTH, HEIGHT, Filesystem::getExecutableDir() / "shaders", ui.getProcAddress() );
renderer.build();
renderer.setProxyCamera( scene.getProxyCamera() );

Expand Down
7 changes: 3 additions & 4 deletions app/bench/src/scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <core/chemdb/color.hpp>
#include <io/util/secondary_structure.hpp>
#include <numeric>
#include <renderer/renderer.hpp>
#include <renderer/facade.hpp>
#include <util/math.hpp>

namespace VTX::Bench
Expand Down Expand Up @@ -62,7 +62,7 @@ namespace VTX::Bench
}

// TODO: remove renderer from here.
void Scene::removeAllSystems( Renderer::Renderer * const p_renderer )
void Scene::removeAllSystems( Renderer::Facade * const p_renderer )
{
std::vector<Renderer::Proxy::System *> proxies;
for ( auto & proxy : _proxySystems )
Expand Down Expand Up @@ -111,8 +111,7 @@ namespace VTX::Bench
[ & ] { return Core::ChemDB::Color::getColorIndex( p_system.residueSecondaryStructureTypes[ i++ ] ); }
);

const Core::Struct::Category & categoryPolymer
= p_system.getCategory( Core::ChemDB::Category::TYPE::POLYMER );
const Core::Struct::Category & categoryPolymer = p_system.getCategory( Core::ChemDB::Category::TYPE::POLYMER );
const Core::Struct::Category & categoryCarbohydrate
= p_system.getCategory( Core::ChemDB::Category::TYPE::CARBOHYDRATE );

Expand Down
4 changes: 2 additions & 2 deletions app/bench/src/scene.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

namespace VTX::Renderer
{
class Renderer;
class Facade;
}

namespace VTX::Bench
Expand All @@ -28,7 +28,7 @@ namespace VTX::Bench
void removeSystem( const size_t p_index );

// TODO: remove renderer from here.
void removeAllSystems( Renderer::Renderer * const p_renderer );
void removeAllSystems( Renderer::Facade * const p_renderer );

inline void update( const float p_deltaTime )
{
Expand Down
66 changes: 33 additions & 33 deletions app/bench/src/user_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <imgui.h>
#include <imgui/imgui_impl_opengl3.h>
#include <imnodes/imnodes.h>
#include <util/enum.hpp>
#include <util/image.hpp>
#include <util/logger.hpp>
#include <util/string.hpp>
Expand All @@ -26,7 +27,7 @@ namespace VTX::Bench
SDL_GL_SetAttribute( SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE );
SDL_GL_SetAttribute( SDL_GL_CONTEXT_MAJOR_VERSION, 4 );
SDL_GL_SetAttribute( SDL_GL_CONTEXT_MINOR_VERSION, 5 );
SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, int( Renderer::Renderer::BUFFER_COUNT == 2 ) );
SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, int( Renderer::Facade::getBufferCount() == 2 ) );
// SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 24 );
// SDL_GL_SetAttribute( SDL_GL_STENCIL_SIZE, 8 );

Expand Down Expand Up @@ -97,7 +98,7 @@ namespace VTX::Bench
SDL_Quit();
}

void UserInterface::draw( Camera * const p_camera, Scene * const p_scene, Renderer::Renderer * const p_renderer )
void UserInterface::draw( Camera * const p_camera, Scene * const p_scene, Renderer::Facade * const p_renderer )
{
ImGui_ImplOpenGL3_NewFrame();
ImGui_ImplSDL2_NewFrame();
Expand Down Expand Up @@ -131,9 +132,9 @@ namespace VTX::Bench
}

void UserInterface::_drawMenuBar(
Camera * const p_camera,
Renderer::Renderer * const p_renderer,
Scene * const p_scene
Camera * const p_camera,
Renderer::Facade * const p_renderer,
Scene * const p_scene
)
{
if ( ImGui::BeginMainMenuBar() )
Expand Down Expand Up @@ -234,9 +235,9 @@ namespace VTX::Bench
setVSync( _vsync );
}

ImGui::Checkbox( "Timers", &p_renderer->logDurations );
ImGui::Checkbox( "Timers", p_renderer->logDurations );

ImGui::Checkbox( "Force update", &p_renderer->forceUpdate );
ImGui::Checkbox( "Force update", p_renderer->forceUpdate );

ImGui::Text( fmt::format( "{} FPS", int( ImGui::GetIO().Framerate ) ).c_str() );

Expand Down Expand Up @@ -297,34 +298,34 @@ namespace VTX::Bench
ImGui::End();
}

void UserInterface::_drawRenderer( Renderer::Renderer * const p_renderer )
void UserInterface::_drawRenderer( Renderer::Facade * const p_renderer )
{
if ( ImGui::Begin( "Renderer" ) && p_renderer->hasContext() )
{
size_t sizeAtoms = 0, sizeBonds = 0, sizeRibbons = 0, sizeVoxels = 0;
for ( auto count : p_renderer->drawRangeSpheres.counts )
for ( auto count : p_renderer->drawRangeSpheres->counts )
{
sizeAtoms += count;
}
for ( auto count : p_renderer->drawRangeCylinders.counts )
for ( auto count : p_renderer->drawRangeCylinders->counts )
{
sizeBonds += count;
}
for ( auto count : p_renderer->drawRangeRibbons.counts )
for ( auto count : p_renderer->drawRangeRibbons->counts )
{
sizeRibbons += count;
}
for ( auto count : p_renderer->drawRangeVoxels.counts )
for ( auto count : p_renderer->drawRangeVoxels->counts )
{
sizeVoxels += count;
}

ImGui::Checkbox( fmt::format( "{} atoms", sizeAtoms ).c_str(), &p_renderer->showAtoms );
ImGui::Checkbox( fmt::format( "{} bonds", sizeBonds ).c_str(), &p_renderer->showBonds );
ImGui::Checkbox( fmt::format( "{} ribbons", sizeRibbons ).c_str(), &p_renderer->showRibbons );
ImGui::Checkbox( fmt::format( "{} voxels", sizeVoxels ).c_str(), &p_renderer->showVoxels );
ImGui::Checkbox( fmt::format( "{} atoms", sizeAtoms ).c_str(), p_renderer->showAtoms );
ImGui::Checkbox( fmt::format( "{} bonds", sizeBonds ).c_str(), p_renderer->showBonds );
ImGui::Checkbox( fmt::format( "{} ribbons", sizeRibbons ).c_str(), p_renderer->showRibbons );
ImGui::Checkbox( fmt::format( "{} voxels", sizeVoxels ).c_str(), p_renderer->showVoxels );

ImGui::Text( fmt::format( "{}x{}", p_renderer->width, p_renderer->height ).c_str() );
ImGui::Text( fmt::format( "{}x{}", p_renderer->getWidth(), p_renderer->getHeight() ).c_str() );
ImGui::Text( fmt::format( "{} FPS", int( ImGui::GetIO().Framerate ) ).c_str() );

const Renderer::StructInfos & infos = p_renderer->getInfos();
Expand Down Expand Up @@ -360,7 +361,7 @@ namespace VTX::Bench
ImGui::End();
}

void UserInterface::_drawDurations( Renderer::Renderer * const p_renderer ) const
void UserInterface::_drawDurations( Renderer::Facade * const p_renderer ) const
{
using namespace Renderer;

Expand Down Expand Up @@ -392,7 +393,7 @@ namespace VTX::Bench
}
}

void UserInterface::_drawScene( Scene * const p_scene, Renderer::Renderer * const p_renderer )
void UserInterface::_drawScene( Scene * const p_scene, Renderer::Facade * const p_renderer )
{
/*
static const uint64_t sdlFrequency = SDL_GetPerformanceFrequency();
Expand Down Expand Up @@ -473,10 +474,9 @@ namespace VTX::Bench

void UserInterface::_drawUniforms() const {}

void UserInterface::_drawNodeEditor( Renderer::Renderer * const p_renderer ) const
void UserInterface::_drawNodeEditor( Renderer::Facade * const p_renderer ) const
{
using namespace Renderer;
auto & graph = p_renderer->getRenderGraph();

static bool isOpen = true;
if ( ImGui::Begin( "Render graph", &isOpen, ImGuiWindowFlags_MenuBar ) )
Expand All @@ -488,7 +488,7 @@ namespace VTX::Bench
{
if ( ImGui::MenuItem( pass->name.c_str() ) )
{
graph.addPass( *pass );
p_renderer->addPass( *pass );
}
}

Expand All @@ -510,7 +510,7 @@ namespace VTX::Bench
p_renderer->clean();
}

RenderQueue & renderQueue = graph.getRenderQueue();
RenderQueue & renderQueue = p_renderer->getRenderQueue();
for ( const Pass * const pass : renderQueue )
{
if ( pass != nullptr )
Expand Down Expand Up @@ -547,7 +547,7 @@ namespace VTX::Bench
std::map<const uint, Link *> mapIdDescLink;
const Pass * passToDelete = nullptr;

for ( std::unique_ptr<Pass> & pass : graph.getPasses() )
for ( std::unique_ptr<Pass> & pass : p_renderer->getPasses() )
{
ImNodes::BeginNode( id++ );
ImNodes::BeginNodeTitleBar();
Expand All @@ -561,7 +561,7 @@ namespace VTX::Bench
ImGui::TextUnformatted( pass->name.c_str() );
ImNodes::EndNodeTitleBar();

bool isInRenderQueue = graph.isInRenderQueue( pass.get() );
bool isInRenderQueue = p_renderer->isInRenderQueue( pass.get() );

// Inputs.
for ( const auto & [ channel, input ] : pass->inputs )
Expand Down Expand Up @@ -696,7 +696,7 @@ namespace VTX::Bench
ImNodes::PopColorStyle();

// Links.
for ( std::unique_ptr<Link> & link : graph.getLinks() )
for ( std::unique_ptr<Link> & link : p_renderer->getLinks() )
{
mapIdDescLink.emplace( id, link.get() );
ImNodes::Link(
Expand All @@ -708,10 +708,10 @@ namespace VTX::Bench

// Output.
uint idFinalDescLink = -1;
if ( graph.getOutput() )
if ( p_renderer->getOutput() )
{
idFinalDescLink = id;
ImNodes::Link( id++, mapIdOutput[ graph.getOutput() ], idFinalOuput );
ImNodes::Link( id++, mapIdOutput[ p_renderer->getOutput() ], idFinalOuput );
}

ImNodes::MiniMap();
Expand All @@ -728,15 +728,15 @@ namespace VTX::Bench
{
if ( it.second == newLinkStartId )
{
graph.setOutput( it.first );
p_renderer->setOutput( it.first );
}
}
}

// Add link.
else
{
graph.addLink(
p_renderer->addLink(
mapIdDescPass[ newLinkStartId ],
mapIdDescPass[ newLinkEndtId ],
mapIdChannelOutput[ newLinkStartId ],
Expand All @@ -752,20 +752,20 @@ namespace VTX::Bench
// Output.
if ( deletedDescLinkId == idFinalDescLink )
{
graph.setOutput( nullptr );
p_renderer->setOutput( nullptr );
}

// DescLink.
else
{
graph.removeLink( mapIdDescLink[ deletedDescLinkId ] );
p_renderer->removeLink( mapIdDescLink[ deletedDescLinkId ] );
}
}

// Check deleted node.
if ( passToDelete != nullptr )
{
graph.removePass( passToDelete );
p_renderer->removePass( passToDelete );
passToDelete = nullptr;
}
}
Expand Down
17 changes: 9 additions & 8 deletions app/bench/src/user_interface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@

#include <SDL.h>
#include <imgui/imgui_impl_sdl2.h>
#include <renderer/renderer.hpp>
#include <renderer/descriptors.hpp>
#include <renderer/facade.hpp>
#include <util/type_traits.hpp>

namespace VTX::Bench
Expand All @@ -26,7 +27,7 @@ namespace VTX::Bench
SDL_GL_SetSwapInterval( _vsync );
}

void draw( Camera * const p_camera, Scene * const p_scene, Renderer::Renderer * const p_renderer );
void draw( Camera * const p_camera, Scene * const p_scene, Renderer::Facade * const p_renderer );

inline bool getEvent( SDL_Event & p_event ) const
{
Expand All @@ -46,17 +47,17 @@ namespace VTX::Bench
bool _vsync = true;
bool _drawUi = true;

void _drawMenuBar( Camera * const p_camera, Renderer::Renderer * const p_renderer, Scene * const p_scene );
void _drawMenuBar( Camera * const p_camera, Renderer::Facade * const p_renderer, Scene * const p_scene );
void _drawCamera( Camera * const p_camera ) const;
void _drawRenderer( Renderer::Renderer * const p_renderer );
void _drawDurations( Renderer::Renderer * const p_renderer ) const;
void _drawScene( Scene * const p_scene, Renderer::Renderer * const p_renderer );
void _drawRenderer( Renderer::Facade * const p_renderer );
void _drawDurations( Renderer::Facade * const p_renderer ) const;
void _drawScene( Scene * const p_scene, Renderer::Facade * const p_renderer );
void _drawUniforms() const;
void _drawNodeEditor( Renderer::Renderer * const p_renderer ) const;
void _drawNodeEditor( Renderer::Facade * const p_renderer ) const;

template<typename T>
void _drawWidget(
Renderer::Renderer * const p_renderer,
Renderer::Facade * const p_renderer,
const Renderer::BufferDataValue & p_uniform,
const std::string & p_key,
const bool p_isEditable
Expand Down
4 changes: 2 additions & 2 deletions lib/app/cmake/library.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ if (NOT DEFINED _VTX_APP_CONAN)
target_link_libraries(vtx_app PRIVATE vtx_core)
target_link_libraries(vtx_app PRIVATE vtx_io)
target_link_libraries(vtx_app_test PRIVATE vtx_util)
target_link_libraries(vtx_app_test PRIVATE vtx_renderer_no_opengl)
target_link_libraries(vtx_app_test PRIVATE vtx_renderer)
target_link_libraries(vtx_app_test PRIVATE vtx_core)
target_link_libraries(vtx_app_test PRIVATE vtx_io)
else()
Expand All @@ -28,7 +28,7 @@ else()
target_link_libraries(vtx_app PRIVATE vtx_core::vtx_core)
target_link_libraries(vtx_app PRIVATE vtx_io::vtx_io)
target_link_libraries(vtx_app_test PRIVATE vtx_util::vtx_util)
target_link_libraries(vtx_app_test PRIVATE vtx_renderer::vtx_renderer_no_opengl)
target_link_libraries(vtx_app_test PRIVATE vtx_renderer::vtx_renderer)
target_link_libraries(vtx_app_test PRIVATE vtx_core::vtx_core)
target_link_libraries(vtx_app_test PRIVATE vtx_io::vtx_io)
endif()
Expand Down
2 changes: 0 additions & 2 deletions lib/python_binding/test/cmake/library.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ endif()

target_link_libraries(vtx_python_binding_test PRIVATE Catch2::Catch2WithMain)

target_compile_definitions(vtx_python_binding_test PRIVATE VTX_RENDERER_NO_OPENGL)

# All other find_package call
vtx_register_build_directory_copy("${CMAKE_CURRENT_LIST_DIR}/../data" "./data")
vtx_copy_registered_data(vtx_python_binding_test)
Expand Down
2 changes: 1 addition & 1 deletion lib/renderer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ find_package(Catch2 CONFIG REQUIRED)
set(_VTX_RENDERER_CONAN " ") # So the right target name can be linked
include("${CMAKE_CURRENT_LIST_DIR}/cmake/library.cmake")

install(TARGETS vtx_renderer vtx_renderer_no_opengl FILE_SET public_headers DESTINATION include)
install(TARGETS vtx_renderer FILE_SET public_headers DESTINATION include)
install(DIRECTORY shaders DESTINATION .)
Loading

0 comments on commit ffa6ecd

Please sign in to comment.