bool SdlBatcher::append(const Picture& pic, const Point& pos, Rect* clip )
{
  if( !pic.isValid() )
    return true;

  Rect rclip = clip ? *clip : Rect();
  if( !_d->onwork->texture.isValid() )
  {
    _d->onwork->texture = pic;
    _d->onwork->clip = rclip;
  }

  bool batched = true;
  bool textureSwitched = (_d->onwork->texture.texture() != pic.texture());
  bool clipSwitched = (_d->onwork->clip != rclip);

  if( textureSwitched || clipSwitched)
  {
    std::swap( _d->batched, _d->onwork );

    reset();
    _d->onwork->texture = pic;
    _d->onwork->clip = rclip;
    batched = false;
  }

  _d->onwork->srcrects.push_back( pic.originRect() );
  _d->onwork->dstrects.push_back( Rect( pos + Point( pic.offset().x(), -pic.offset().y() ), pic.size() ) );
  return batched;
}
Exemple #2
0
void SdlEngine::draw(const Picture &picture, const int dx, const int dy, Rect* clipRect )
{
  if( !picture.isValid() )
      return;

  int t = DateTime::elapsedTime();
  _d->drawCall++;

  if( clipRect != 0 )
  {
    SDL_Rect r = { clipRect->left(), clipRect->top(), clipRect->width(), clipRect->height() };
    SDL_RenderSetClipRect( _d->renderer, &r );
  }

  const Impl::MaskInfo& mask = _d->mask;
  SDL_Texture* ptx = picture.texture();
  const Rect& orect = picture.originRect();
  Size picSize = orect.size();
  const Point& offset = picture.offset();

  if( mask.enabled )
  {
    SDL_SetTextureColorMod( ptx, mask.red >> 16, mask.green >> 8, mask.blue );
    SDL_SetTextureAlphaMod( ptx, mask.alpha >> 24 );
  }