Visual Computing Library
Loading...
Searching...
No Matches
program_manager.h
1/*****************************************************************************
2 * VCLib *
3 * Visual Computing Library *
4 * *
5 * Copyright(C) 2021-2025 *
6 * Visual Computing Lab *
7 * ISTI - Italian National Research Council *
8 * *
9 * All rights reserved. *
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the Mozilla Public License Version 2.0 as published *
13 * by the Mozilla Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 * This program is distributed in the hope that it will be useful, *
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
19 * Mozilla Public License Version 2.0 *
20 * (https://www.mozilla.org/en-US/MPL/2.0/) for more details. *
21 ****************************************************************************/
22
23#ifndef VCL_BGFX_CONTEXT_PROGRAM_MANAGER_H
24#define VCL_BGFX_CONTEXT_PROGRAM_MANAGER_H
25
26#include <vclib/bgfx/programs/embedded_compute_programs.h>
27#include <vclib/bgfx/programs/embedded_vf_programs.h>
28#include <vclib/bgfx/programs/load_program.h>
29#include <vclib/types.h>
30
31#include <array>
32
33namespace vcl {
34
36{
37 bgfx::RendererType::Enum mRenderType = bgfx::RendererType::Count;
38
39 std::array<bgfx::ProgramHandle, toUnderlying(VertFragProgram::COUNT)>
40 mVFPrograms;
41
42 std::array<bgfx::ProgramHandle, toUnderlying(ComputeProgram::COUNT)>
43 mCPrograms;
44
45public:
46 ProgramManager(bgfx::RendererType::Enum renderType) :
47 mRenderType(renderType)
48 {
49 mVFPrograms.fill(BGFX_INVALID_HANDLE);
50 mCPrograms.fill(BGFX_INVALID_HANDLE);
51 }
52
54 {
55 for (const auto& program : mVFPrograms) {
56 if (bgfx::isValid(program)) {
57 bgfx::destroy(program);
58 }
59 }
60
61 for (const auto& program : mCPrograms) {
62 if (bgfx::isValid(program)) {
63 bgfx::destroy(program);
64 }
65 }
66 }
67
68 template<VertFragProgram PROGRAM>
69 bgfx::ProgramHandle getProgram()
70 {
71 uint p = toUnderlying(PROGRAM);
72 if (!bgfx::isValid(mVFPrograms[p])) {
73 mVFPrograms[p] = vcl::createProgram(
74 vcl::loadShader(
76 vcl::loadShader(
78 }
79 return mVFPrograms[p];
80 }
81
82 template<ComputeProgram PROGRAM>
83 bgfx::ProgramHandle getComputeProgram()
84 {
85 uint p = toUnderlying(PROGRAM);
86 if (!bgfx::isValid(mCPrograms[p])) {
87 // TODO - use ComputeLoader
88 }
89 return mCPrograms[p];
90 }
91};
92
93} // namespace vcl
94
95#endif // VCL_BGFX_CONTEXT_PROGRAM_MANAGER_H
Definition program_manager.h:36
A class representing a line segment in n-dimensional space. The class is parameterized by a PointConc...
Definition segment.h:43
Definition vert_frag_loader.h:34