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);
125 enum class AnimationFolder {
155 void loadMissingAnimation();
159 inline bool isLoaded()
const {
return _isLoaded; }
161 static void fullBlend(
167 static constexpr
const uint kMaxSpriteIDs = 256;
169 AnimationFolder _folder;
170 bool _isLoaded =
false;
171 uint32 _totalDuration = 0;
173 int32 _spriteIndexMapping[kMaxSpriteIDs] = { 0 };
193 using AnimationBase::isLoaded;
194 inline uint spriteCount()
const {
return _spriteBases.size(); }
195 inline uint frameCount()
const {
return _frames.size(); }
196 inline uint32 frameDuration(int32 frameI)
const {
return _frames[frameI]._duration; }
197 inline Common::Point frameCenter(int32 frameI)
const {
return _frames[frameI]._center; }
198 inline uint32 totalDuration()
const {
return _totalDuration; }
199 inline uint8 &premultiplyAlpha() {
return _premultiplyAlpha; }
202 int32 frameAtTime(uint32 time)
const;
203 int32 imageIndex(int32 frameI, int32 spriteI)
const;
204 using AnimationBase::imageSize;
205 void outputRect2D(int32 frameI,
float scale, Math::Vector2d &topLeft, Math::Vector2d &size)
const;
206 void outputRect3D(int32 frameI,
float scale, Math::Vector3d &topLeft, Math::Vector2d &size)
const;
212 Math::Vector2d topLeft,
218 Math::Vector3d topLeft,
224 Math::Vector3d topLeft,
225 Math::Vector2d tiling,
226 Math::Vector2d texOffset,
227 BlendMode blendMode);
230 Common::Rect spriteBounds(int32 frameI, int32 spriteI)
const;
232 void prerenderFrame(int32 frameI);
234 int32_t _renderedFrameI = -1;
235 uint8 _premultiplyAlpha = 100,
236 _renderedPremultiplyAlpha = 255;
250 using AnimationBase::isLoaded;
251 using AnimationBase::imageSize;
252 inline uint imageCount()
const {
return _images.size(); }
267 inline int8 &order() {
return _order; }
268 inline int16 &
scale() {
return _scale; }
269 inline float &depthScale() {
return _depthScale; }
270 inline Color &color() {
return _color; }
271 inline int32 &frameI() {
return _frameI; }
272 inline uint32 &lastTime() {
return _lastTime; }
273 inline bool isPaused()
const {
return _isPaused; }
274 inline bool hasAnimation()
const {
return _animation !=
nullptr; }
276 assert(_animation !=
nullptr && _animation->isLoaded());
279 inline uint8 &premultiplyAlpha() {
280 assert(_animation !=
nullptr);
281 return _animation->premultiplyAlpha();
284 void loadResources();
285 void freeResources();
287 void start(
bool looping);
290 void setAnimation(
const Common::String &fileName, AnimationFolder folder);
300 int16 _scale = kBaseScale;
302 Color _color = kWhite;
304 bool _isPaused =
true,
306 uint32 _lastTime = 0;
308 float _depthScale = 1.0f;
316 inline int8 order()
const {
return _order; }
317 virtual void draw() = 0;
329 float lodBias = 0.0f);
333 Math::Vector2d center,
337 void draw()
override;
343 Math::Vector3d _topLeft;
346 BlendMode _blendMode;
356 Math::Vector2d texOffset,
357 BlendMode blendMode);
359 void draw()
override;
364 Math::Vector3d _topLeft;
368 BlendMode _blendMode;
382 inline Common::Point size()
const {
return { (int16)_width, (int16)_height }; }
383 void draw()
override;
386 static constexpr uint kMaxLines = 12;
390 int _posY, _height, _width;
395 int _allPosX[kMaxLines];
398 enum class FadeType {
404 enum class PermanentFadeAction {
414 void draw()
override;
422 float from,
float to,
423 int32 duration, EasingType easingType,
425 PermanentFadeAction permanentFadeAction = PermanentFadeAction::Nothing);
431 void draw()
override;
443 template<
typename T,
typename... Args>
444 inline T *allocate(Args&&... args) {
445 return new(allocateRaw(
sizeof(T),
alignof(T))) T(Common::forward<Args>(args)...);
447 void *allocateRaw(
size_t size,
size_t align);
448 void deallocateAll();
453 const size_t _pageSize;
454 size_t _pageI = 0, _used = 0;
462 template<
typename T,
typename... Args>
463 inline void add(Args&&... args) {
464 addRequest(_allocator.allocate<T>(Common::forward<Args>(args)...));
469 void setLodBias(int8 orderFrom, int8 orderTo,
float newLodBias);
475 static constexpr
const uint kMaxDrawRequestsPerOrder = 50;
478 IDrawRequest *_requestsPerOrder[kOrderCount][kMaxDrawRequestsPerOrder] = { { 0 } };
479 uint8 _requestsPerOrderCount[kOrderCount] = { 0 };
480 float _lodBiasPerOrder[kOrderCount] = { 0 };
485 #endif // ALCACHOFA_GRAPHICS_H Definition: managed_surface.h:51
Definition: graphics.h:103
Definition: alcachofa.h:45
Definition: scheduler.h:84
Definition: graphics.h:371
Definition: scheduler.h:164
Definition: graphics.h:259
Definition: graphics.h:410
Common::Array< uint32 > _spriteOffsets
index offset per sprite and animation frame
Definition: graphics.h:175
Definition: graphics.h:186
Definition: serializer.h:79
Definition: graphics.h:74
Definition: graphics.h:323
Graphics::Surface * scale(const Graphics::Surface &srcImage, int xSize, int ySize)
Definition: graphics.h:438
Definition: graphics.h:149
Definition: graphics.h:60
Definition: graphics.h:458
const Surface & rawSurface() const
Definition: managed_surface.h:195
Definition: graphics.h:311
Definition: graphics.h:242
Common::Point _offset
the offset is only used for drawing the animation frame
Definition: graphics.h:133
Definition: graphics.h:427
Common::Array< Graphics::ManagedSurface * > _images
will contain nullptr for fake images
Definition: graphics.h:178
Definition: graphics.h:350
Definition: graphics.h:131