summaryrefslogtreecommitdiffstats
path: root/client/gui/softrenderer.h
blob: 9fc1a29e99341360930d0b70ad5c2dced3303890 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#ifndef _directfbrenderer_h_
#define _directfbrenderer_h_

#include <stdint.h>
#include <list>
#include <set>

#include "CEGUIRenderer.h"
#include "CEGUIColourRect.h"
#include "CEGUIRect.h"


namespace CEGUI
{
    class SoftTexture;
    class ImageCodec;

    class SoftRenderer : public Renderer
    {
    public:
        SoftRenderer(uint8_t* surface, uint width, uint height, uint stride,
                     ImageCodec* codec = NULL);
        virtual ~SoftRenderer();

        void reset_surface(uint8_t* surface, uint width, uint height, uint stride);

        virtual void addQuad(const Rect& dest_rect, float z, const Texture* tex,
                            const Rect& texture_rect, const ColourRect& colours,
                            QuadSplitMode quad_split_mode);
        virtual void doRender();
        virtual void clearRenderList();
        virtual void setQueueingEnabled(bool setting);
        virtual bool isQueueingEnabled() const;

        virtual Texture* createTexture();
        virtual Texture* createTexture(const String& filename,
                                       const String& resourceGroup);
        virtual Texture* createTexture(float size);
        virtual void destroyTexture(Texture* texture);
        virtual void destroyAllTextures();
        virtual uint getMaxTextureSize() const;

        virtual float getWidth() const;
        virtual float getHeight() const;
        virtual Size getSize() const;
        virtual Rect getRect() const;

        virtual uint getHorzScreenDPI() const;
        virtual uint getVertScreenDPI() const;

        ImageCodec* getImageCodec() { return _image_codec;}

    private:
        void setupImageCodec();
        void cleanupImageCodec();
        struct QuadInfo;
        void renderQuad(const QuadInfo& quad);
        void renderQuadWithColourRect(const QuadInfo& quad);

        class ColourI {
        public:

            bool isSameColour(const ColourI& other) const
            {
                return other.r == r && other.g == g && other.b == b && other.a == a;
            }

            uint8_t r;
            uint8_t g;
            uint8_t b;
            uint8_t a;
        };

        static inline void setRGB(ColourI& dest, const colour& src);
        static inline void componnentAtPoint(int x_pos, int y_pos,
                                             int top_left, int top_right,
                                             int bottom_left, int bottom_right,
                                             uint64_t& comp);

        struct ColourIRect {
            ColourI top_left;
            ColourI top_right;
            ColourI bottom_left;
            ColourI bottom_right;
        };

        static void colourAtPoint(int x, int x_max, int y, int y_max,
                                  const ColourIRect& colours,
                                  uint64_t& r, uint64_t& g,
                                  uint64_t& b, uint64_t& a);

    private:
        uint8_t* _surface;
        int _width;
        int _height;
        ImageCodec* _image_codec;
        DynamicModule* _image_codec_module;
        void (*_destroy_image_codec)(ImageCodec*);
        bool _queueing;

        struct RectI {
            int left;
            int top;
            int right;
            int bottom;
        };

        struct QuadInfo {
            RectI dest;
            const SoftTexture* tex;
            RectI tex_src;
            ColourIRect colors;
            float z;

            bool operator < (const QuadInfo& other) const
            {
                return z > other.z;
            }
        };

        typedef std::multiset<QuadInfo> QuadQueue;
        QuadQueue _queue;

        typedef std::list<SoftTexture *> TexturesList;
        TexturesList _textures;
   };
}

#endif