Beatmup
Beatmup::NNets::Storage::Binder Class Reference

Binding of different input/output storages/texture handlers to a GLSL program. More...

#include <storage.h>

Public Member Functions

 Binder (GraphicPipeline &gpu)
 
bool begin (GL::Program &program, Storage::View &output, int channel)
 Starts binding things to a program. More...
 
void begin (GL::Program &program, AbstractBitmap &output)
 Starts binding things to a program which renders to a bitmap. More...
 
void operator() (Storage::View &input, const char *name)
 Binds a storage (all of its textures) to a uniform sampler array variable. More...
 
void operator() (Storage::View &input, const char *name, int channel)
 Binds a single texture from a storage to a uniform sampler variable. More...
 
void operator() (GL::TextureHandler &input, const char *name)
 

Private Attributes

GraphicPipelinegpu
 
GL::Programprogram
 
GL::handle_t outputTexture
 
int unit
 

Detailed Description

Binding of different input/output storages/texture handlers to a GLSL program.

Definition at line 419 of file storage.h.

Constructor & Destructor Documentation

◆ Binder()

Beatmup::NNets::Storage::Binder::Binder ( GraphicPipeline gpu)
inline

Definition at line 426 of file storage.h.

426 : gpu(gpu), program(nullptr), outputTexture(0), unit(0) {}
GraphicPipeline & gpu
Definition: storage.h:421

Member Function Documentation

◆ begin() [1/2]

bool Storage::Binder::begin ( GL::Program program,
Storage::View output,
int  channel 
)

Starts binding things to a program.

Parameters
[in,out]programThe program
[in,out]outputOutput storage
[in]channelOutput storage channel to be filled
Returns
true if the program and the output texture are already bound, i.e. are the same as in previous binding.

Definition at line 543 of file storage.cpp.

543  {
544 #ifdef BEATMUP_DEBUG
546  DebugAssertion::check(output.storage->textures, "Output storage is not allocated on GPU");
547 #endif
548 
549  // reset counter
550  unit = 0;
551 
552  // check if previous binding can be reused
553  bool fast = this->program == &program;
554 
555  // setup program if needed and store
556  if (!fast) {
557  program.enable(gpu);
558  this->program = &program;
559  }
560 
561  // check if previous output setting is okay
562  const int outTexture = output.textures[output.getChannelTextureNumber(channel)];
563  Storage& storage = *output.storage;
564 
565  fast = fast && this->outputTexture == storage.textures[outTexture].handle;
566 
567  // setup output
568  if (!fast) {
569  gpu.bindOutput(storage.textures[outTexture].handle);
570  if (storage.textures[outTexture].dirty) {
571  glClear(GL_COLOR_BUFFER_BIT);
572  storage.textures[outTexture].dirty = false;
573  }
574 
575  this->outputTexture = storage.textures[outTexture].handle;
576  }
577 
578  // fix output area
579  IntPoint origin = storage.getChannelOrigin(output.channels[channel / 4].channelIdx);
580  glViewport(origin.getX(), origin.getY(), output.getWidth(), output.getHeight());
581 
582  storage.upToDate[ProcessingTarget::CPU] = false;
583 
584  return fast;
585 }
numeric getX() const
Definition: geometry.h:42
numeric getY() const
Definition: geometry.h:46
void enable(const GraphicPipeline &gpu)
Definition: program.cpp:250
void bindOutput(AbstractBitmap &bitmap)
Binds a bitmap to the pipeline output.
Definition: pipeline.cpp:891
std::vector< Channel > channels
channels of the view
Definition: storage.h:318
int getChannelTextureNumber(int channel) const
Returns number of the texture containing a given channel.
Definition: storage.cpp:500
std::vector< int > textures
indices of textures in the storage
Definition: storage.h:319
3D tensor stored in a set of textures.
Definition: storage.h:126
static void checkChannelNumber(int channel)
Checks whether a channel number points to the first channel in a texture.
Definition: storage.h:290
IntPoint getChannelOrigin(int channel) const
Returns origin in pixels of a given channel within the texture containing it.
Definition: storage.cpp:379
bool dirty
if true, the texture needs to be cleared before use
Definition: storage.h:140

◆ begin() [2/2]

void Storage::Binder::begin ( GL::Program program,
AbstractBitmap output 
)

Starts binding things to a program which renders to a bitmap.

Parameters
[in,out]programThe program
[in,out]outputThe output bitmap

Definition at line 588 of file storage.cpp.

588  {
589  unit = 0;
590  program.enable(gpu);
591  gpu.bindOutput(output);
592  this->program = &program;
593  this->outputTexture = 0;
594 }

◆ operator()() [1/3]

void Storage::Binder::operator() ( Storage::View input,
const char *  name 
)

Binds a storage (all of its textures) to a uniform sampler array variable.

Parameters
[in]inputThe storage
[in]nameThe variable name

Definition at line 597 of file storage.cpp.

597  {
599  input.storage->push(gpu);
600 
601  const int num = input.getNumberOfTextures();
603  for (int i = 0; i < num; ++i, ++unit)
604  bind(unit, input.storage->textures[ input.textures[i] ].handle);
605  GL::GLException::check("binding input storage");
606 }
void setIntegerArray(const std::string &name, const int *values, const int length)
Definition: program.cpp:417
static void check(const std::string &info)
Definition: bgl.h:62
int getNumberOfTextures() const
Returns total number of textures in the storage view.
Definition: storage.h:355
void push(GraphicPipeline &gpu, const void *data)
Definition: storage.cpp:86
static void bind(int unit, GL::handle_t texture)
Definition: storage.cpp:38
return(jlong) new Beatmup jlong jstring name

◆ operator()() [2/3]

void Storage::Binder::operator() ( Storage::View input,
const char *  name,
int  channel 
)

Binds a single texture from a storage to a uniform sampler variable.

Parameters
[in]inputThe storage
[in]nameThe variable name
[in]channelThe channel number

Definition at line 609 of file storage.cpp.

609  {
610 #ifdef BEATMUP_DEBUG
612  OutOfRange::check(channel, 0, input.getDepth() * 4 - 1, "Channel index is out of range");
613 #endif
615  input.storage->push(gpu);
616 
618  const int storageChannel = input.channels[channel/4].channelIdx;
619  const int storageTexture = input.storage->getChannelTextureNumber(storageChannel);
620  bind(unit, input.storage->textures[storageTexture].handle);
621  ++unit;
622  GL::GLException::check("binding input storage");
623 }
int getChannelTextureNumber(int channel) const
Returns number of texture containing a given channel.
Definition: storage.cpp:370
static void check(const datatype value, const datatype min, const datatype max, const char *message)
Definition: exception.h:86

◆ operator()() [3/3]

void Storage::Binder::operator() ( GL::TextureHandler input,
const char *  name 
)

Definition at line 626 of file storage.cpp.

626  {
629 }
void setInteger(const std::string &name, const int value, bool safe=false)
Assigns a value to a specific integer variable in the program.
Definition: program.cpp:308
void bind(GL::TextureHandler &texture, size_t texUnit, const TextureParam param)
Definition: pipeline.cpp:881
@ INTERP_NEAREST
nearest neighbor pixel interpolation

Member Data Documentation

◆ gpu

GraphicPipeline& Beatmup::NNets::Storage::Binder::gpu
private

Definition at line 421 of file storage.h.

◆ program

GL::Program* Beatmup::NNets::Storage::Binder::program
private

Definition at line 422 of file storage.h.

◆ outputTexture

GL::handle_t Beatmup::NNets::Storage::Binder::outputTexture
private

Definition at line 423 of file storage.h.

◆ unit

int Beatmup::NNets::Storage::Binder::unit
private

Definition at line 424 of file storage.h.


The documentation for this class was generated from the following files: