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 void begin() = 0;
81 virtual void setTexture(
ITexture *texture) = 0;
82 virtual void setBlendMode(BlendMode blendMode) = 0;
83 virtual void setLodBias(
float lodBias) = 0;
85 virtual bool hasOutput()
const = 0;
87 Math::Vector2d topLeft,
90 Math::Angle rotation = Math::Angle(),
91 Math::Vector2d texMin = Math::Vector2d(0, 0),
92 Math::Vector2d texMax = Math::Vector2d(1, 1)) = 0;
93 virtual void end() = 0;
103 virtual void debugPolygon(
105 Color color = kDebugRed
107 virtual void debugPolyline(
109 Color color = kDebugRed
112 virtual void debugShape(
114 Color color = kDebugRed
118 Math::Vector2d points[] = { { (float)a.
x, (
float)a.
y }, { (float)b.
x, (
float)b.
y } };
119 debugPolygon({ points, 2 }, color);
123 enum class AnimationFolder {
153 void loadMissingAnimation();
157 inline bool isLoaded()
const {
return _isLoaded; }
159 static void fullBlend(
165 static constexpr
const uint kMaxSpriteIDs = 256;
167 AnimationFolder _folder;
168 bool _isLoaded =
false;
169 uint32 _totalDuration = 0;
171 int32 _spriteIndexMapping[kMaxSpriteIDs] = { 0 };
191 using AnimationBase::isLoaded;
192 inline uint spriteCount()
const {
return _spriteBases.size(); }
193 inline uint frameCount()
const {
return _frames.size(); }
194 inline uint32 frameDuration(int32 frameI)
const {
return _frames[frameI]._duration; }
195 inline Common::Point frameCenter(int32 frameI)
const {
return _frames[frameI]._center; }
196 inline uint32 totalDuration()
const {
return _totalDuration; }
197 inline uint8 &premultiplyAlpha() {
return _premultiplyAlpha; }
200 int32 frameAtTime(uint32 time)
const;
201 int32 imageIndex(int32 frameI, int32 spriteI)
const;
202 using AnimationBase::imageSize;
203 void outputRect2D(int32 frameI,
float scale, Math::Vector2d &topLeft, Math::Vector2d &size)
const;
204 void outputRect3D(int32 frameI,
float scale, Math::Vector3d &topLeft, Math::Vector2d &size)
const;
210 Math::Vector2d topLeft,
216 Math::Vector3d topLeft,
222 Math::Vector3d topLeft,
223 Math::Vector2d tiling,
224 Math::Vector2d texOffset,
225 BlendMode blendMode);
228 Common::Rect spriteBounds(int32 frameI, int32 spriteI)
const;
230 void prerenderFrame(int32 frameI);
232 int32_t _renderedFrameI = -1;
233 uint8 _premultiplyAlpha = 100,
234 _renderedPremultiplyAlpha = 255;
248 using AnimationBase::isLoaded;
249 using AnimationBase::imageSize;
250 inline uint imageCount()
const {
return _images.size(); }
265 inline int8 &order() {
return _order; }
266 inline int16 &
scale() {
return _scale; }
267 inline float &depthScale() {
return _depthScale; }
268 inline Color &color() {
return _color; }
269 inline int32 &frameI() {
return _frameI; }
270 inline uint32 &lastTime() {
return _lastTime; }
271 inline bool isPaused()
const {
return _isPaused; }
272 inline bool hasAnimation()
const {
return _animation !=
nullptr; }
274 assert(_animation !=
nullptr && _animation->isLoaded());
277 inline uint8 &premultiplyAlpha() {
278 assert(_animation !=
nullptr);
279 return _animation->premultiplyAlpha();
282 void loadResources();
283 void freeResources();
285 void start(
bool looping);
288 void setAnimation(
const Common::String &fileName, AnimationFolder folder);
298 int16 _scale = kBaseScale;
300 Color _color = kWhite;
302 bool _isPaused =
true,
304 uint32 _lastTime = 0;
306 float _depthScale = 1.0f;
314 inline int8 order()
const {
return _order; }
315 virtual void draw() = 0;
327 float lodBias = 0.0f);
331 Math::Vector2d center,
335 void draw()
override;
341 Math::Vector3d _topLeft;
344 BlendMode _blendMode;
354 Math::Vector2d texOffset,
355 BlendMode blendMode);
357 void draw()
override;
362 Math::Vector3d _topLeft;
366 BlendMode _blendMode;
380 inline Common::Point size()
const {
return { (int16)_width, (int16)_height }; }
381 void draw()
override;
384 static constexpr uint kMaxLines = 12;
388 int _posY, _height, _width;
393 int _allPosX[kMaxLines];
396 enum class FadeType {
402 enum class PermanentFadeAction {
412 void draw()
override;
420 float from,
float to,
421 int32 duration, EasingType easingType,
423 PermanentFadeAction permanentFadeAction = PermanentFadeAction::Nothing);
429 void draw()
override;
441 template<
typename T,
typename... Args>
442 inline T *allocate(Args&&... args) {
443 return new(allocateRaw(
sizeof(T),
alignof(T))) T(Common::forward<Args>(args)...);
445 void *allocateRaw(
size_t size,
size_t align);
446 void deallocateAll();
451 const size_t _pageSize;
452 size_t _pageI = 0, _used = 0;
460 template<
typename T,
typename... Args>
461 inline void add(Args&&... args) {
462 addRequest(_allocator.allocate<T>(Common::forward<Args>(args)...));
467 void setLodBias(int8 orderFrom, int8 orderTo,
float newLodBias);
473 static constexpr
const uint kMaxDrawRequestsPerOrder = 50;
476 IDrawRequest *_requestsPerOrder[kOrderCount][kMaxDrawRequestsPerOrder] = { { 0 } };
477 uint8 _requestsPerOrderCount[kOrderCount] = { 0 };
478 float _lodBiasPerOrder[kOrderCount] = { 0 };
483 #endif // ALCACHOFA_GRAPHICS_H Definition: managed_surface.h:51
Definition: graphics.h:101
Definition: alcachofa.h:45
Definition: scheduler.h:84
Definition: graphics.h:369
Definition: scheduler.h:164
Definition: graphics.h:257
Definition: graphics.h:408
Common::Array< uint32 > _spriteOffsets
index offset per sprite and animation frame
Definition: graphics.h:173
Definition: graphics.h:184
Definition: serializer.h:79
Definition: graphics.h:74
Definition: graphics.h:321
Graphics::Surface * scale(const Graphics::Surface &srcImage, int xSize, int ySize)
Definition: graphics.h:436
Definition: graphics.h:147
Definition: graphics.h:60
Definition: graphics.h:456
const Surface & rawSurface() const
Definition: managed_surface.h:192
Definition: graphics.h:309
Definition: graphics.h:240
Common::Point _offset
the offset is only used for drawing the animation frame
Definition: graphics.h:131
Definition: graphics.h:425
Common::Array< Graphics::ManagedSurface * > _images
will contain nullptr for fake images
Definition: graphics.h:176
Definition: graphics.h:348
Definition: graphics.h:129