22 #ifndef ALCACHOFA_GRAPHICS_H 23 #define ALCACHOFA_GRAPHICS_H 25 #include "common/ptr.h" 26 #include "common/stream.h" 27 #include "common/serializer.h" 28 #include "common/rect.h" 29 #include "common/span.h" 30 #include "math/vector2d.h" 31 #include "graphics/managed_surface.h" 33 #include "alcachofa/camera.h" 34 #include "alcachofa/common.h" 50 enum class BlendMode {
80 virtual bool requiresPoTTextures()
const = 0;
82 virtual void begin() = 0;
83 virtual void setTexture(
ITexture *texture) = 0;
84 virtual void setBlendMode(BlendMode blendMode) = 0;
85 virtual void setLodBias(
float lodBias) = 0;
87 virtual bool hasOutput()
const = 0;
89 Math::Vector2d topLeft,
92 Math::Angle rotation = Math::Angle(),
93 Math::Vector2d texMin = Math::Vector2d(0, 0),
94 Math::Vector2d texMax = Math::Vector2d(1, 1)) = 0;
95 virtual void end() = 0;
105 virtual void debugPolygon(
107 Color color = kDebugRed
109 virtual void debugPolyline(
111 Color color = kDebugRed
114 virtual void debugShape(
116 Color color = kDebugRed
120 Math::Vector2d points[] = { { (float)a.
x, (
float)a.
y }, { (float)b.
x, (
float)b.
y } };
121 debugPolygon({ points, 2 }, color);
131 inline Common::Point drawOffset()
const {
return _drawOffset; }
138 uint16 _xOffset, _width;
152 enum class AnimationFolder {
191 inline bool isLoaded()
const {
return _isLoaded; }
193 static void fullBlend(
199 static constexpr
const uint kMaxSpriteIDs = 256;
200 static constexpr
const uint kMaxSpriteIDsV1 = 8;
202 AnimationFolder _folder;
203 bool _isLoaded =
false;
204 uint32 _totalDuration = 0;
206 int32 _spriteIndexMapping[kMaxSpriteIDs] = { 0 };
227 using AnimationBase::isLoaded;
228 inline uint spriteCount()
const {
return _spriteBases.size(); }
229 inline uint frameCount()
const {
return _frames.size(); }
230 inline uint32 frameDuration(int32 frameI)
const {
return _frames[frameI]._duration; }
231 inline Common::Point frameCenter(int32 frameI)
const {
return _frames[frameI]._center; }
232 inline uint32 totalDuration()
const {
return _totalDuration; }
233 inline uint8 &premultiplyAlpha() {
return _premultiplyAlpha; }
236 int32 frameAtTime(uint32 time)
const;
237 int32 imageIndex(int32 frameI, int32 spriteI)
const;
238 using AnimationBase::imageSize;
239 void outputRect2D(int32 frameI,
float scale, Math::Vector2d &topLeft, Math::Vector2d &size)
const;
240 void outputRect3D(int32 frameI,
float scale, Math::Vector3d &topLeft, Math::Vector2d &size)
const;
246 Math::Vector2d topLeft,
252 Math::Vector3d topLeft,
258 Math::Vector3d topLeft,
259 Math::Vector2d tiling,
260 Math::Vector2d texOffset,
261 BlendMode blendMode);
264 Common::Rect spriteBounds(int32 frameI, int32 spriteI)
const;
266 void prerenderFrame(int32 frameI);
268 int32_t _renderedFrameI = -1;
269 uint8 _premultiplyAlpha = 100,
270 _renderedPremultiplyAlpha = 255;
284 using AnimationBase::isLoaded;
285 using AnimationBase::imageSize;
286 bool isVisibleChar(byte ch)
const;
289 inline uint imageCount()
const {
return _images.size(); }
292 const byte _charToImage, _spaceImageI, _charSpacing;
307 inline int8 &order() {
return _order; }
308 inline int16 &
scale() {
return _scale; }
309 inline float &depthScale() {
return _depthScale; }
310 inline Color &color() {
return _color; }
311 inline int32 &frameI() {
return _frameI; }
312 inline uint32 &lastTime() {
return _lastTime; }
313 inline bool isPaused()
const {
return _isPaused; }
314 inline bool hasAnimation()
const {
return _animation !=
nullptr; }
316 assert(_animation !=
nullptr && _animation->isLoaded());
319 inline uint8 &premultiplyAlpha() {
320 assert(_animation !=
nullptr);
321 return _animation->premultiplyAlpha();
324 void loadResources();
325 void freeResources();
327 void start(
bool looping);
340 int16 _scale = kBaseScale;
342 Color _color = kWhite;
344 bool _isPaused =
true,
346 uint32 _lastTime = 0;
348 float _depthScale = 1.0f;
356 inline int8 order()
const {
return _order; }
357 virtual void draw() = 0;
369 float lodBias = 0.0f);
373 Math::Vector2d center,
377 void draw()
override;
383 Math::Vector3d _topLeft;
386 BlendMode _blendMode;
396 Math::Vector2d texOffset,
397 BlendMode blendMode);
399 void draw()
override;
404 Math::Vector3d _topLeft;
408 BlendMode _blendMode;
422 inline Common::Point size()
const {
return { (int16)_width, (int16)_height }; }
423 void draw()
override;
426 static constexpr uint kMaxLines = 12;
430 int _posY = 0, _height = 0, _width = 0;
435 int _allPosX[kMaxLines] = { 0 };
438 enum class FadeType {
444 enum class PermanentFadeAction {
454 void draw()
override;
462 float from,
float to,
463 int32 duration, EasingType easingType,
465 PermanentFadeAction permanentFadeAction = PermanentFadeAction::Nothing);
471 void draw()
override;
483 template<
typename T,
typename... Args>
484 inline T *allocate(Args&&... args) {
485 return new(allocateRaw(
sizeof(T),
alignof(T))) T(Common::forward<Args>(args)...);
487 void *allocateRaw(
size_t size,
size_t align);
488 void deallocateAll();
493 const size_t _pageSize;
494 size_t _pageI = 0, _used = 0;
502 template<
typename T,
typename... Args>
503 inline void add(Args&&... args) {
504 addRequest(_allocator.allocate<T>(Common::forward<Args>(args)...));
509 void setLodBias(int8 orderFrom, int8 orderTo,
float newLodBias);
515 static constexpr
const uint kMaxDrawRequestsPerOrder = 50;
518 IDrawRequest *_requestsPerOrder[kOrderCount][kMaxDrawRequestsPerOrder] = { { 0 } };
519 uint8 _requestsPerOrderCount[kOrderCount] = { 0 };
520 float _lodBiasPerOrder[kOrderCount] = { 0 };
525 #endif // ALCACHOFA_GRAPHICS_H Definition: managed_surface.h:51
Definition: graphics.h:103
Definition: alcachofa.h:45
Definition: graphics.h:127
Definition: scheduler.h:84
Definition: graphics.h:411
Definition: scheduler.h:164
Definition: graphics.h:297
Definition: graphics.h:450
Definition: graphics.h:220
Definition: serializer.h:79
Definition: graphics.h:74
Definition: graphics.h:363
Graphics::Surface * scale(const Graphics::Surface &srcImage, int xSize, int ySize)
Definition: graphics.h:478
Definition: graphics.h:176
References a game file either as path or as embedded byte range.
Definition: common.h:197
Definition: graphics.h:60
Definition: graphics.h:498
Common::Array< int32 > _spriteOffsets
index offset per sprite and animation frame
Definition: graphics.h:208
const Surface & rawSurface() const
Definition: managed_surface.h:195
Definition: graphics.h:351
Definition: graphics.h:276
Common::Point _offset
the offset is only used for drawing the animation frame
Definition: graphics.h:160
Definition: graphics.h:467
Common::Array< Graphics::ManagedSurface * > _images
will contain nullptr for fake images
Definition: graphics.h:212
Definition: graphics.h:390
Definition: graphics.h:158