Beatmup
Beatmup::GraphicPipeline Class Reference

Internal low-level GPU control API. More...

#include <pipeline.h>

Classes

class  Impl
 

Public Types

enum class  Mode { RENDERING , INFERENCE }
 Graphic pipeline working mode setting some common OpenGL switches. More...
 
enum class  Limit {
  TEXTURE_IMAGE_UNITS , FRAGMENT_UNIFORM_VECTORS , LOCAL_GROUPS_X , LOCAL_GROUPS_Y ,
  LOCAL_GROUPS_Z , LOCAL_GROUPS_TOTAL , SHARED_MEM
}
 GPU characteristics. More...
 

Public Member Functions

 GraphicPipeline ()
 
 ~GraphicPipeline ()
 
void switchDisplay (void *data)
 
void swapBuffers ()
 
void bindOutput (AbstractBitmap &bitmap)
 Binds a bitmap to the pipeline output. More...
 
void bindOutput (AbstractBitmap &bitmap, const IntRectangle &viewport)
 Binds a bitmap to the pipeline output. More...
 
void bindOutput (GL::TextureHandler &texture)
 
void bindOutput (GL::handle_t texture)
 
void unbindOutput ()
 Unbinds a bitmap from output and switches to screen. More...
 
const ImageResolutiongetDisplayResolution () const
 
void bind (GL::TextureHandler &texture, size_t texUnit, const TextureParam param)
 
void bind (GL::TextureHandler &texture, size_t imageUnit, bool read, bool write)
 
void pullPixels (AbstractBitmap &bitmap)
 Transfers bitmap pixels from GPU to CPU. More...
 
void pushPixels (AbstractBitmap &bitmap)
 Transfers bitmap pixels from CPU to GPU. More...
 
void flush ()
 Waits until all operations submitted to GPU are finished. More...
 
int getLimit (Limit limit) const
 
void switchMode (Mode mode)
 Switches GPU mode. More...
 
GL::RenderingProgramsgetRenderingPrograms ()
 
const GL::VertexShadergetDefaultVertexShader () const
 
const char * getGpuVendorString () const
 
const char * getGpuRendererString () const
 
int getGlslVersion () const
 Returns GLSL language version supported by the GPU context being used. More...
 
bool isGlEsCompliant () const
 Returns true if the GPU context is OpenGL ES-compliant. More...
 
void setTextureCoordinates (const Rectangle &coords)
 Specifies texture coordinates for the next rendering pass. More...
 
void setTextureCoordinates (const Point &leftTop, const Point &rightTop, const Point &leftBottom, const Point &rightBottom)
 Specifies texture coordinates for the next rendering pass. More...
 
void setTextureCoordinates (const Rectangle &area, const IntPoint &size, const IntPoint &sampling)
 Specifies texture coordinates for the next rendering pass. More...
 

Static Public Member Functions

static Rectangle getTextureCoordinates (const Rectangle &area, const IntPoint &size, const IntPoint &sampling)
 Computes floating-point texture coordinates for pixel-accurate sampling: a texture gets sampled exactly at specified pixel locations. More...
 

Static Public Attributes

static const int ATTRIB_VERTEX_COORD = 0
 vertex coordinate attribute index in the VBO More...
 
static const int ATTRIB_TEXTURE_COORD = 1
 texture coordinate attribute index in the VBO More...
 

Private Member Functions

 GraphicPipeline (const GraphicPipeline &)=delete
 

Private Attributes

Implimpl
 
GL::RenderingProgramsrenderingPrograms
 

Friends

class GL::TextureHandler
 

Detailed Description

Internal low-level GPU control API.

Hides OpenGL stuff from intsances of AbstractTask operating with images. A GraphicPipeline instance is likely a singleton accessible from a single thread.

Definition at line 33 of file pipeline.h.

Member Enumeration Documentation

◆ Mode

Graphic pipeline working mode setting some common OpenGL switches.

Enumerator
RENDERING 

Textures are images to be blended together to produce another image.

INFERENCE 

Textures are feature maps computed in fragment shaders.

Definition at line 47 of file pipeline.h.

47  {
48  RENDERING, //!< Textures are images to be blended together to produce another image
49  INFERENCE //!< Textures are feature maps computed in fragment shaders
50  };

◆ Limit

GPU characteristics.

Enumerator
TEXTURE_IMAGE_UNITS 

maximum number of texture units per fragment shader

FRAGMENT_UNIFORM_VECTORS 

maximum number of 4-dimensional uniform vectors per fragment shader

LOCAL_GROUPS_X 
LOCAL_GROUPS_Y 
LOCAL_GROUPS_Z 
LOCAL_GROUPS_TOTAL 
SHARED_MEM 

Definition at line 55 of file pipeline.h.

55  {
56  TEXTURE_IMAGE_UNITS, //!< maximum number of texture units per fragment shader
57  FRAGMENT_UNIFORM_VECTORS, //!< maximum number of 4-dimensional uniform vectors per fragment shader
58  LOCAL_GROUPS_X,
59  LOCAL_GROUPS_Y,
60  LOCAL_GROUPS_Z,
61  LOCAL_GROUPS_TOTAL,
62  SHARED_MEM,
63  };

Constructor & Destructor Documentation

◆ GraphicPipeline() [1/2]

Beatmup::GraphicPipeline::GraphicPipeline ( const GraphicPipeline )
privatedelete

◆ GraphicPipeline() [2/2]

GraphicPipeline::GraphicPipeline ( )

Definition at line 858 of file pipeline.cpp.

858  {
859  BEATMUP_DEBUG_I("GRAPHIC PIPELINE INITIALIZATION");
860  impl = new Impl(*this);
862 }
Handles a collection of common rendering programs of predefined types and shared operations among the...
GL::RenderingPrograms * renderingPrograms
Definition: pipeline.h:39
#define BEATMUP_DEBUG_I(...)
Definition: debug.h:33

◆ ~GraphicPipeline()

GraphicPipeline::~GraphicPipeline ( )

Definition at line 865 of file pipeline.cpp.

865  {
866  delete renderingPrograms;
867  delete impl;
868 }

Member Function Documentation

◆ switchDisplay()

void GraphicPipeline::switchDisplay ( void *  data)

Definition at line 871 of file pipeline.cpp.

871  {
872  impl->switchDisplay(data);
873 }
void switchDisplay(void *data)
Platform-dependent display switching routine.
Definition: pipeline.cpp:478

◆ swapBuffers()

void GraphicPipeline::swapBuffers ( )

Definition at line 876 of file pipeline.cpp.

876  {
877  impl->swapBuffers();
878 }

◆ bindOutput() [1/4]

void GraphicPipeline::bindOutput ( AbstractBitmap bitmap)

Binds a bitmap to the pipeline output.

Parameters
[in]bitmapA bitmap to be filled with pixels on the next render pass.

Definition at line 891 of file pipeline.cpp.

891  {
893 }
const ImageResolution getSize() const
Returns the bitmap resolution within ImageResolution object.
IntRectangle halfOpenedRectangle() const
void bindOutput(AbstractBitmap &bitmap, const IntRectangle &viewport)
Definition: pipeline.cpp:618
Beatmup::InternalBitmap * bitmap

◆ bindOutput() [2/4]

void GraphicPipeline::bindOutput ( AbstractBitmap bitmap,
const IntRectangle viewport 
)

Binds a bitmap to the pipeline output.

Parameters
[in]bitmapA bitmap to be filled with pixels on the next render pass.
[in]viewportOutput viewport in pixels: only this area of the bitmap will be affected

Definition at line 896 of file pipeline.cpp.

896  {
897  impl->bindOutput(bitmap, viewport);
898 }

◆ bindOutput() [3/4]

void GraphicPipeline::bindOutput ( GL::TextureHandler texture)

Definition at line 901 of file pipeline.cpp.

901  {
902  impl->bindOutput(textureHandler);
903 }

◆ bindOutput() [4/4]

void GraphicPipeline::bindOutput ( GL::handle_t  texture)

Definition at line 906 of file pipeline.cpp.

906  {
907  impl->bindOutput(texture);
908 }

◆ unbindOutput()

void GraphicPipeline::unbindOutput ( )

Unbinds a bitmap from output and switches to screen.

Definition at line 911 of file pipeline.cpp.

911  {
912  impl->unbindOutput();
913 }

◆ getDisplayResolution()

const ImageResolution & GraphicPipeline::getDisplayResolution ( ) const

Definition at line 916 of file pipeline.cpp.

916  {
917  return impl->getDisplayResolution();
918 }
const ImageResolution & getDisplayResolution() const
Definition: pipeline.cpp:654

◆ bind() [1/2]

void GraphicPipeline::bind ( GL::TextureHandler texture,
size_t  texUnit,
const TextureParam  param 
)

Definition at line 881 of file pipeline.cpp.

881  {
882  impl->bind(texture, texUnit, param);
883 }
void bind(GL::TextureHandler &texture, size_t unit, const TextureParam param)
Definition: pipeline.cpp:563

◆ bind() [2/2]

void GraphicPipeline::bind ( GL::TextureHandler texture,
size_t  imageUnit,
bool  read,
bool  write 
)

Definition at line 886 of file pipeline.cpp.

886  {
887  impl->bindImage(texture, imageUnit, read, write);
888 }
void bindImage(GL::TextureHandler &texture, int imageUnit, bool read, bool write)
Binds a texture handle to an image unit.
Definition: pipeline.cpp:540
void write(Bitmap &bitmap, Args &&... args)
Calls a Func< WriterClass >::process(access, params) that writes to a bitmap of any kind,...
Definition: processing.h:90
void read(Bitmap &bitmap, Args &&... args)
Calls a Func< ReaderClass >::process(access, params), where.
Definition: processing.h:49

◆ pullPixels()

void GraphicPipeline::pullPixels ( AbstractBitmap bitmap)

Transfers bitmap pixels from GPU to CPU.

The bitmap is assumed locked.

Definition at line 921 of file pipeline.cpp.

921  {
923 }
void pullPixels(AbstractBitmap &bitmap)
Transfers texture data from GPU to CPU.
Definition: pipeline.cpp:661

◆ pushPixels()

void GraphicPipeline::pushPixels ( AbstractBitmap bitmap)

Transfers bitmap pixels from CPU to GPU.

The bitmap is assumed locked.

Definition at line 926 of file pipeline.cpp.

926  {
928 }
void pushPixels(AbstractBitmap &bitmap)
Transfers texture data from CPU to GPU.
Definition: pipeline.cpp:729

◆ flush()

void GraphicPipeline::flush ( )

Waits until all operations submitted to GPU are finished.

Definition at line 931 of file pipeline.cpp.

931  {
932  glFinish();
933 }

◆ getLimit()

int GraphicPipeline::getLimit ( Limit  limit) const

Definition at line 936 of file pipeline.cpp.

936  {
937  return impl->getLimit(limit);
938 }
int getLimit(GraphicPipeline::Limit limit) const
Definition: pipeline.cpp:786

◆ switchMode()

void GraphicPipeline::switchMode ( Mode  mode)

Switches GPU mode.

Definition at line 941 of file pipeline.cpp.

941  {
942  impl->switchMode(mode);
943 }
void switchMode(GraphicPipeline::Mode mode)
Definition: pipeline.cpp:804
JNIEnv jlong jint mode

◆ getRenderingPrograms()

GL::RenderingPrograms& Beatmup::GraphicPipeline::getRenderingPrograms ( )
inline

Definition at line 125 of file pipeline.h.

125 { return *renderingPrograms; }

◆ getDefaultVertexShader()

const GL::VertexShader& Beatmup::GraphicPipeline::getDefaultVertexShader ( ) const
inline

Definition at line 126 of file pipeline.h.

126 { return renderingPrograms->getDefaultVertexShader(this); }
const VertexShader & getDefaultVertexShader(const GraphicPipeline *gpu) const

◆ getGpuVendorString()

const char * GraphicPipeline::getGpuVendorString ( ) const

Definition at line 946 of file pipeline.cpp.

946  {
947  return (const char*)glGetString(GL_VENDOR);
948 }

◆ getGpuRendererString()

const char * GraphicPipeline::getGpuRendererString ( ) const

Definition at line 951 of file pipeline.cpp.

951  {
952  return (const char*)glGetString(GL_RENDERER);
953 }

◆ getGlslVersion()

int GraphicPipeline::getGlslVersion ( ) const

Returns GLSL language version supported by the GPU context being used.

Definition at line 956 of file pipeline.cpp.

956  {
957  return impl->getGlslVersion();
958 }

◆ isGlEsCompliant()

bool GraphicPipeline::isGlEsCompliant ( ) const

Returns true if the GPU context is OpenGL ES-compliant.

Definition at line 961 of file pipeline.cpp.

961  {
962  return impl->isGlEsCompliant();
963 }

◆ setTextureCoordinates() [1/3]

void GraphicPipeline::setTextureCoordinates ( const Rectangle coords)

Specifies texture coordinates for the next rendering pass.

Parameters
[in]coordsNormalized texture coordinates

Definition at line 966 of file pipeline.cpp.

966  {
967  impl->setTextureCoordinates(coords);
968 }
void setTextureCoordinates(const Rectangle &coords)
Definition: pipeline.cpp:815

◆ setTextureCoordinates() [2/3]

void GraphicPipeline::setTextureCoordinates ( const Point leftTop,
const Point rightTop,
const Point leftBottom,
const Point rightBottom 
)

Specifies texture coordinates for the next rendering pass.

Parameters
[in]leftTopTop left output image corner texture coordinates
[in]rightTopTop right output image corner texture coordinates
[in]leftBottomBottom left output image corner texture coordinates
[in]rightBottomBottom right output image corner texture coordinates

Definition at line 971 of file pipeline.cpp.

971  {
972  impl->setTextureCoordinates(leftTop, rightTop, leftBottom, rightBottom);
973 }

◆ setTextureCoordinates() [3/3]

void Beatmup::GraphicPipeline::setTextureCoordinates ( const Rectangle area,
const IntPoint size,
const IntPoint sampling 
)
inline

Specifies texture coordinates for the next rendering pass.

Parameters
[in]areaA closed rectangle in pixels of a texture to sample; all its corners are valid sampling locations.
[in]sizeSize in pixels of the input texture
[in]samplingNumber of resulting samples covering the area

Definition at line 163 of file pipeline.h.

163  {
165  }
static Rectangle getTextureCoordinates(const Rectangle &area, const IntPoint &size, const IntPoint &sampling)
Computes floating-point texture coordinates for pixel-accurate sampling: a texture gets sampled exact...
Definition: pipeline.cpp:976
void setTextureCoordinates(const Rectangle &coords)
Specifies texture coordinates for the next rendering pass.
Definition: pipeline.cpp:966
jlong jobject size

◆ getTextureCoordinates()

Beatmup::Rectangle GraphicPipeline::getTextureCoordinates ( const Rectangle area,
const IntPoint size,
const IntPoint sampling 
)
static

Computes floating-point texture coordinates for pixel-accurate sampling: a texture gets sampled exactly at specified pixel locations.

Parameters
[in]areaA closed rectangle in pixels of a texture to sample; all its corners are valid sampling locations.
[in]sizeSize in pixels of the input texture
[in]samplingNumber of resulting samples covering the area

Definition at line 976 of file pipeline.cpp.

976  {
977  /* Common OpenGL texture sampling model, likely:
978  . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . <- texture pixels (`size` in number).
979  | * * * * * * * * * | <- sampling point locations (`area`).
980  | | There are exactly `sampling` points.
981  |_____________________________________________________| <- texture coordinates to give to
982  the shaders to get the texture
983  sampled in the starred locations.
984  */
985 
986  // compute offsets of texture coordinates with respect to the sampling positions
987  const float
988  dx = sampling.x > 1 ? 0.5f * area.width() / (sampling.x - 1) : 0.0f,
989  dy = sampling.y > 1 ? 0.5f * area.height() / (sampling.y - 1) : 0.0f;
990 
991  // compute texture coordinates: x + 0.5 is the target sampling position, dx is the offset
992  return Beatmup::Rectangle(
993  (area.a.x + 0.5f - dx) / size.x,
994  (area.a.y + 0.5f - dy) / size.y,
995  (area.b.x + 0.5f + dx) / size.x,
996  (area.b.y + 0.5f + dy) / size.y
997  );
998 }
numeric height() const
Definition: geometry.h:178
CustomPoint< numeric > b
Definition: geometry.h:131
numeric width() const
Definition: geometry.h:174
CustomPoint< numeric > a
Definition: geometry.h:131
CustomRectangle< float > Rectangle
Definition: geometry.h:627

Friends And Related Function Documentation

◆ GL::TextureHandler

friend class GL::TextureHandler
friend

Definition at line 34 of file pipeline.h.

Member Data Documentation

◆ impl

Impl* Beatmup::GraphicPipeline::impl
private

Definition at line 37 of file pipeline.h.

◆ renderingPrograms

GL::RenderingPrograms* Beatmup::GraphicPipeline::renderingPrograms
private

Definition at line 39 of file pipeline.h.

◆ ATTRIB_VERTEX_COORD

const int Beatmup::GraphicPipeline::ATTRIB_VERTEX_COORD = 0
static

vertex coordinate attribute index in the VBO

Definition at line 66 of file pipeline.h.

◆ ATTRIB_TEXTURE_COORD

const int Beatmup::GraphicPipeline::ATTRIB_TEXTURE_COORD = 1
static

texture coordinate attribute index in the VBO

Definition at line 67 of file pipeline.h.


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