1 /* Copyright (C) 2015 Wildfire Games.
2  * This file is part of 0 A.D.
3  *
4  * 0 A.D. is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * 0 A.D. is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with 0 A.D.  If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef INCLUDED_GUIRENDERER
19 #define INCLUDED_GUIRENDERER
20 
21 #include "graphics/ShaderTechnique.h"
22 #include "graphics/Texture.h"
23 #include "lib/res/handle.h"
24 #include "ps/CStr.h"
25 #include "ps/Shapes.h"
26 
27 #include <vector>
28 
29 struct SGUIImageEffects;
30 struct SGUIImage;
31 
32 namespace GUIRenderer
33 {
34 	class IGLState
35 	{
36 	public:
~IGLState()37 		virtual ~IGLState() {};
38 		virtual void Set(const CTexturePtr& tex) = 0;
39 		virtual void Unset() = 0;
40 	};
41 
42 	struct SDrawCall
43 	{
SDrawCallSDrawCall44 		SDrawCall(const SGUIImage* image) : m_Image(image) {}
45 		CRect ComputeTexCoords() const;
46 
47 		const SGUIImage* m_Image;
48 
49 		bool m_HasTexture;
50 		CTexturePtr m_Texture;
51 
52 		CRect m_ObjectSize;
53 		int m_CellID;
54 
55 		bool m_EnableBlending;
56 
57 		CShaderTechniquePtr m_Shader;
58 		CColor m_ShaderColorParameter;
59 
60 		CRect m_Vertices;
61 		float m_DeltaZ;
62 
63 		CColor m_BorderColor; // == CColor() for no border
64 		CColor m_BackColor;
65 	};
66 
67 	class DrawCalls : public std::vector<SDrawCall>
68 	{
69 	public:
70 		DrawCalls();
71 		// Copy/assignment results in an empty list, not an actual copy
72 		DrawCalls(const DrawCalls&);
73 		DrawCalls& operator=(const DrawCalls&);
74 	};
75 }
76 
77 #include "gui/CGUISprite.h"
78 
79 namespace GUIRenderer
80 {
81 	void UpdateDrawCallCache(DrawCalls& Calls, const CStr& SpriteName, const CRect& Size, int CellID, std::map<CStr, CGUISprite*>& Sprites);
82 
83 	void Draw(DrawCalls& Calls, float Z);
84 }
85 
86 #endif // INCLUDED_GUIRENDERER
87