Beatmup
program_bank.h
Go to the documentation of this file.
1 /*
2  Beatmup image and signal processing library
3  Copyright (C) 2020, lnstadrum
4 
5  This program is free software: you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation, either version 3 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18 
19 #pragma once
20 #include "../gpu/pipeline.h"
21 #include "../gpu/program.h"
22 #include "../context.h"
23 #include <string>
24 #include <map>
25 
26 namespace Beatmup {
27  namespace GL {
28  /**
29  Stores linked GLSL programs and their associated fragment shader codes.
30  */
31  class ProgramBank : public Object {
32  private:
33  typedef struct {
35  unsigned int userCount;
36  } ProgramHolder;
37 
38  std::map<std::string, ProgramHolder> programs; //!< map of source code to programs without external texture extension
39  std::map<std::string, ProgramHolder> programsWithExtTex; //!< map of source code to programs with external texture extension
40 
41  bool releaseProgram(GL::RenderingProgram* program, std::map<std::string, ProgramHolder>& cache);
42 
43  protected:
45  public:
47  ~ProgramBank();
48 
49  /**
50  Provides a program given a fragment shader source code.
51  Creates a new program or returns an available one increasing its user count (do not call this too often).
52  \param[in] gpu A graphic pipeline instance
53  \param[in] code The fragment shader code of the program
54  \param[in] enableExternalTextures If `true`, external texture extension is enabled in the program, for example, to access camera image in Android
55  \return Linked program.
56  */
57  GL::RenderingProgram* operator()(GraphicPipeline& gpu, const std::string& code, bool enableExternalTextures = false);
58 
59  /**
60  Marks a program as unused any more. If the program has no other users, its is destroyed.
61  \param[in] gpu A graphic pipeline instance
62  \param[in] program The program
63  */
64  void release(GraphicPipeline& gpu, GL::RenderingProgram* program);
65  };
66  }
67 }
Basic class: task and memory management, any kind of static data.
Definition: context.h:59
Stores linked GLSL programs and their associated fragment shader codes.
Definition: program_bank.h:31
GL::RenderingProgram * operator()(GraphicPipeline &gpu, const std::string &code, bool enableExternalTextures=false)
Provides a program given a fragment shader source code.
std::map< std::string, ProgramHolder > programs
map of source code to programs without external texture extension
Definition: program_bank.h:38
bool releaseProgram(GL::RenderingProgram *program, std::map< std::string, ProgramHolder > &cache)
void release(GraphicPipeline &gpu, GL::RenderingProgram *program)
Marks a program as unused any more.
std::map< std::string, ProgramHolder > programsWithExtTex
map of source code to programs with external texture extension
Definition: program_bank.h:39
ProgramBank(Context &context)
Definition: program_bank.h:46
GLSL program to render images Makes use of default vertex attributes to pass the texture coordinates ...
Definition: program.h:240
Internal low-level GPU control API.
Definition: pipeline.h:33
Beatmup object base class
Definition: basic_types.h:67