Beatmup
Beatmup::Scene::MaskedBitmapLayer Class Reference

Bitmap layer using another bitmap as a mask. More...

#include <scene.h>

Inheritance diagram for Beatmup::Scene::MaskedBitmapLayer:
Beatmup::Scene::CustomMaskedBitmapLayer Beatmup::Scene::BitmapLayer Beatmup::Scene::Layer Beatmup::Object

Public Member Functions

const AbstractBitmapgetMask () const
 
void setMask (AbstractBitmap *mask)
 
bool testPoint (float x, float y) const
 Tests if a given point falls in the layer. More...
 
- Public Member Functions inherited from Beatmup::Scene::CustomMaskedBitmapLayer
AffineMappinggetMaskMapping ()
 
const AffineMappinggetMaskMapping () const
 
void setMaskMapping (const AffineMapping &mapping)
 
color4i getBackgroundColor () const
 
void setBackgroundColor (color4i color)
 
- Public Member Functions inherited from Beatmup::Scene::BitmapLayer
const AbstractBitmapgetBitmap () const
 
void setBitmap (AbstractBitmap *bitmap)
 
AffineMappinggetBitmapMapping ()
 
const AffineMappinggetBitmapMapping () const
 
void setBitmapMapping (const AffineMapping &mapping)
 
color4i getModulationColor () const
 
void setModulationColor (color4i color)
 
- Public Member Functions inherited from Beatmup::Scene::Layer
Type getType () const
 
const std::string & getName () const
 
void setName (const char *name)
 
AffineMappinggetMapping ()
 
const AffineMappinggetMapping () const
 
void setMapping (const AffineMapping &mapping)
 
virtual LayergetChild (float x, float y, unsigned int recursionDepth=0) const
 Picks a child layer at given point, if any. More...
 
bool isVisible () const
 Returns layer visibility flag. More...
 
bool isPhantom () const
 Returns true if the layer is ignored when searching a layer by point. More...
 
void setVisible (bool visible)
 Sets layer visibility. More...
 
void setPhantom (bool phantom)
 Makes/unmakes the layer "phantom". More...
 
template<class LayerType >
LayerType & castTo () const
 
- Public Member Functions inherited from Beatmup::Object
virtual ~Object ()
 

Protected Member Functions

 MaskedBitmapLayer ()
 
void render (RenderingContext &context)
 
- Protected Member Functions inherited from Beatmup::Scene::CustomMaskedBitmapLayer
 CustomMaskedBitmapLayer (Type type)
 
void configure (RenderingContext &context, GL::TextureHandler *content)
 
- Protected Member Functions inherited from Beatmup::Scene::BitmapLayer
 BitmapLayer ()
 
 BitmapLayer (Type type)
 
GL::TextureHandlerresolveContent (RenderingContext &context)
 
void configure (RenderingContext &context, GL::TextureHandler *content)
 Configures current rendering program to render this layer. More...
 
- Protected Member Functions inherited from Beatmup::Scene::Layer
 Layer (Type type)
 

Private Attributes

AbstractBitmapmask
 mask bitmap More...
 

Friends

class Scene
 
class SceneRenderer
 

Additional Inherited Members

- Public Types inherited from Beatmup::Scene::Layer
enum class  Type {
  SceneLayer = 0 , BitmapLayer , MaskedBitmapLayer , ShapedBitmapLayer ,
  ShadedBitmapLayer
}
 
- Protected Attributes inherited from Beatmup::Scene::CustomMaskedBitmapLayer
AffineMapping maskMapping
 mask mapping w.r.t. the layer mapping More...
 
color4i bgColor
 color to fill mask areas where the bitmap is not present More...
 
- Protected Attributes inherited from Beatmup::Scene::BitmapLayer
float invAr
 inverse aspect ratio of what is rendered (set by SceneRenderer) More...
 
AbstractBitmapbitmap
 content to display, used if the image source is set to BITMAP More...
 
AffineMapping bitmapMapping
 bitmap mapping w.r.t. the layer mapping More...
 
color4i modulation
 modulation color More...
 
- Protected Attributes inherited from Beatmup::Scene::Layer
AffineMapping mapping
 layer mapping More...
 
bool visible
 layer visibility More...
 
bool phantom
 if true, layer is ignored by selection by point More...
 

Detailed Description

Bitmap layer using another bitmap as a mask.

Definition at line 217 of file scene.h.

Constructor & Destructor Documentation

◆ MaskedBitmapLayer()

Scene::MaskedBitmapLayer::MaskedBitmapLayer ( )
protected

Definition at line 338 of file scene.cpp.

338  :
340 {}
@ MaskedBitmapLayer
layer displaying a bitmap with mask
AbstractBitmap * mask
mask bitmap
Definition: scene.h:221

Member Function Documentation

◆ render()

void Scene::MaskedBitmapLayer::render ( RenderingContext context)
protectedvirtual

Reimplemented from Beatmup::Scene::BitmapLayer.

Definition at line 343 of file scene.cpp.

343  {
345  if (content && mask) {
346  const bool mask8bit = mask->getPixelFormat() == PixelFormat::SingleByte;
347 
348  // program selection
349  switch (content->getTextureFormat()) {
350  case GL::TextureHandler::TextureFormat::OES_Ext:
351  context.enableProgram(mask8bit ?
354  );
355  break;
356  default:
357  context.enableProgram(mask8bit ?
360  break;
361  }
362 
363  context.lockBitmap(mask);
364 
366  context.bindMask(*mask);
367  context.blend();
368  }
369 }
virtual const PixelFormat getPixelFormat() const =0
Pixel format of the bitmap.
@ MASKED_BLEND_EXT
blending an image through a pixelwise mask (texture extension)
@ MASKED_8BIT_BLEND_EXT
blending an image through a 8 bit pixelwise mask (texture extension)
@ MASKED_8BIT_BLEND
blending an image through a 8 bit pixelwise mask
@ MASKED_BLEND
blending an image through a pixelwise mask
void blend()
Initiates the rendering operation.
void bindMask(AbstractBitmap &mask)
void enableProgram(GL::RenderingPrograms::Operation operation)
void lockBitmap(AbstractBitmap *bitmap)
GL::TextureHandler * resolveContent(RenderingContext &context)
Definition: scene.cpp:273
void configure(RenderingContext &context, GL::TextureHandler *content)
Definition: scene.cpp:326
@ SingleByte
single channel of 8 bits per pixel (like grayscale), unsigned integer values
std::string content

◆ getMask()

const AbstractBitmap* Beatmup::Scene::MaskedBitmapLayer::getMask ( ) const
inline

Definition at line 226 of file scene.h.

226 { return mask; }

◆ setMask()

void Beatmup::Scene::MaskedBitmapLayer::setMask ( AbstractBitmap mask)
inline

Definition at line 227 of file scene.h.

227 { this->mask = mask; }

◆ testPoint()

bool Scene::MaskedBitmapLayer::testPoint ( float  x,
float  y 
) const
virtual

Tests if a given point falls in the layer.

Reimplemented from Beatmup::Scene::BitmapLayer.

Definition at line 372 of file scene.cpp.

372  {
373  // no bitmap - no deal (if the source is set to bitmap)
374  if (!bitmap)
375  return false;
376  if (mask) {
377  RuntimeError::check(mask->isUpToDate(ProcessingTarget::CPU), "Mask is out of date on CPU.");
378  const Point p = (mapping * maskMapping).getInverse(x, y);
379  int
380  w = floorf_fast(mask->getWidth() * p.x),
381  h = floorf_fast(mask->getHeight() * p.y);
382  if (0 <= w && w < mask->getWidth() && 0 <= h && h < mask->getHeight()) {
384  bool result = mask->getPixelInt(w, h) > 0;
385  return result;
386  }
387  return false;
388  }
389  return BitmapLayer::testPoint(x, y);
390 }
Locks a bitmap for reading on CPU.
int getPixelInt(int x, int y, int cha=0) const
Retrieves integer value of given channel at given pixel.
bool isUpToDate(ProcessingTarget) const
virtual const int getHeight() const =0
Height of the texture in pixels.
virtual const int getWidth() const =0
Width of the texture in pixels.
static void check(const bool condition, const std::string &message)
Definition: exception.h:64
AbstractBitmap * bitmap
content to display, used if the image source is set to BITMAP
Definition: scene.h:174
bool testPoint(float x, float y) const
Tests if a given point falls in the layer.
Definition: scene.cpp:314
AffineMapping maskMapping
mask mapping w.r.t. the layer mapping
Definition: scene.h:202
AffineMapping mapping
layer mapping
Definition: scene.h:80
int floorf_fast(float x)
Definition: utils.hpp:26
jobject jlong jint jint y
jlong h
jlong jstring jint jint jint jint w
Beatmup::IntPoint result
jobject jlong jint x
return bitmap getWidth()
Beatmup::IntPoint p((int) x,(int) y)
return bitmap getHeight()

Friends And Related Function Documentation

◆ Scene

friend class Scene
friend

Definition at line 218 of file scene.h.

◆ SceneRenderer

friend class SceneRenderer
friend

Definition at line 219 of file scene.h.

Member Data Documentation

◆ mask

AbstractBitmap* Beatmup::Scene::MaskedBitmapLayer::mask
private

mask bitmap

Definition at line 221 of file scene.h.


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