Beatmup
shader_applicator.h
Go to the documentation of this file.
1 /*
2  Beatmup image and signal processing library
3  Copyright (C) 2019, 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/gpu_task.h"
21 #include "../bitmap/abstract_bitmap.h"
22 #include "../geometry.h"
23 #include "image_shader.h"
24 #include <map>
25 
26 namespace Beatmup {
27 
28  /**
29  A task applying an image shader to a bitmap
30  */
31  class ShaderApplicator : public GpuTask, private BitmapContentLock {
32  private:
33  std::map<std::string, AbstractBitmap*> samplers;
37 
38  bool processOnGPU(GraphicPipeline& gpu, TaskThread& thread);
39  void beforeProcessing(ThreadIndex threadCount, ProcessingTarget target, GraphicPipeline* gpu);
40  void afterProcessing(ThreadIndex threadCount, GraphicPipeline* gpu, bool aborted);
41 
42  public:
44 
45  /**
46  Connects a bitmap to a shader uniform variable.
47  The bitmap connected to ImageShader::INPUT_IMAGE_ID is used to resolve the sampler type (ImageShader::INPUT_IMAGE_DECL_TYPE).
48  */
49  void addSampler(AbstractBitmap* bitmap, const std::string uniformName = ImageShader::INPUT_IMAGE_ID);
50 
51  /**
52  Removes a sampler with a uniform variable name.
53  \param[in] uniformName The uniform variable
54  \return true if a sampler associated to the given variable existed and was removed, false otherwise.
55  */
56  bool removeSampler(const std::string uniformName);
57 
58  /**
59  Clears all connections of bitmaps to samplers
60  */
61  void clearSamplers();
62 
65 
66  AbstractBitmap* getOutputBitmap() const { return output; }
67  ImageShader* getShader() const { return shader; }
68  const size_t getSamplersCount() const { return samplers.size(); }
69  };
70 }
A very basic class for any image.
2x3 affine mapping containing a 2x2 matrix and a 2D point
Definition: geometry.h:639
Makes sure the bitmap content is accessible within an image processing task.
Definition: content_lock.h:34
Template of a task using GPU.
Definition: gpu_task.h:27
Internal low-level GPU control API.
Definition: pipeline.h:33
A GLSL program to process images.
Definition: image_shader.h:34
static const std::string INPUT_IMAGE_ID
Shader variable name referring to the input image.
Definition: image_shader.h:109
A task applying an image shader to a bitmap.
AbstractBitmap * getOutputBitmap() const
std::map< std::string, AbstractBitmap * > samplers
void clearSamplers()
Clears all connections of bitmaps to samplers.
void setShader(ImageShader *shader)
void addSampler(AbstractBitmap *bitmap, const std::string uniformName=ImageShader::INPUT_IMAGE_ID)
Connects a bitmap to a shader uniform variable.
void beforeProcessing(ThreadIndex threadCount, ProcessingTarget target, GraphicPipeline *gpu)
Instruction called before the task is executed.
bool processOnGPU(GraphicPipeline &gpu, TaskThread &thread)
Executes the task on GPU.
void setOutputBitmap(AbstractBitmap *bitmap)
const size_t getSamplersCount() const
ImageShader * getShader() const
void afterProcessing(ThreadIndex threadCount, GraphicPipeline *gpu, bool aborted)
Instruction called after the task is executed.
bool removeSampler(const std::string uniformName)
Removes a sampler with a uniform variable name.
Thread executing tasks.
Definition: parallelism.h:154
unsigned char ThreadIndex
number of threads / thread index
Definition: parallelism.h:68
ProcessingTarget
Definition: basic_types.h:55
Beatmup::InternalBitmap * bitmap