MyGUI 3.2.0

- Main Page
- Related Pages
- Namespaces
- Data Structures
- Files
- Examples

- File List
- Globals

MyGUI_RenderItem.cpp
Go to the documentation of this file.
1
6 /*
7 This file is part of MyGUI.
8
9 MyGUI is free software: you can redistribute it and/or modify
10 it under the terms of the GNU Lesser General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
13
14 MyGUI is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU Lesser General Public License for more details.
18
19 You should have received a copy of the GNU Lesser General Public License
20 along with MyGUI. If not, see <http://www.gnu.org/licenses/>.
21 */
22 #include "MyGUI_Precompiled.h"
23 #include "MyGUI_RenderItem.h"
24 #include "MyGUI_LayerNode.h"
25 #include "MyGUI_LayerManager.h"
26 #include "MyGUI_Gui.h"
27 #include "MyGUI_RenderManager.h"
28 #include "MyGUI_DataManager.h"
29 #include "MyGUI_RenderManager.h"
30
31 namespace MyGUI
32 {
33
34 RenderItem::RenderItem() :
35 mTexture(nullptr),
36 mNeedVertexCount(0),
37 mOutOfDate(false),
38 mCountVertex(0),
39 mCurrentUpdate(true),
40 mCurrentVertex(nullptr),
41 mLastVertexCount(0),
42 mVertexBuffer(nullptr),
43 mRenderTarget(nullptr),
44 mCompression(false),
45 mManualRender(false)
46 {
47 mVertexBuffer = RenderManager::getInstance().createVertexBuffer();
48 }
49
50 RenderItem::~RenderItem()
51 {
52 RenderManager::getInstance().destroyVertexBuffer(mVertexBuffer);
53 mVertexBuffer = nullptr;
54 }
55
56 void RenderItem::renderToTarget(IRenderTarget* _target, bool _update)
57 {
58 if (mTexture == nullptr)
59 return;
60
61 mRenderTarget = _target;
62
63 mCurrentUpdate = _update;
64
65 if (mOutOfDate || _update)
66 {
67 mCountVertex = 0;
68 Vertex* buffer = (Vertex*)mVertexBuffer->lock();
69
70 for (VectorDrawItem::iterator iter = mDrawItems.begin(); iter != mDrawItems.end(); ++iter)
71 {
72 // перед вызовом запоминаем позицию в буфере
73 mCurrentVertex = buffer;
74 mLastVertexCount = 0;
75
76 (*iter).first->doRender();
77
78 // колличество отрисованных вершин
79 MYGUI_DEBUG_ASSERT(mLastVertexCount <= (*iter).second, "It is too much vertexes");
80 buffer += mLastVertexCount;
81 mCountVertex += mLastVertexCount;
82 }
83
84 mVertexBuffer->unlock();
85
86 mOutOfDate = false;
87 }
88
89 // хоть с 0 не выводиться батч, но все равно не будем дергать стейт и операцию
90 if (0 != mCountVertex)
91 {
92 #if MYGUI_DEBUG_MODE == 1
93 if (!RenderManager::getInstance().checkTexture(mTexture))
94 {
95 mTexture = nullptr;
96 MYGUI_EXCEPT("texture pointer is not valid, texture name '" << mTextureName << "'");
97 return;
98 }
99 #endif
100 // непосредственный рендринг
101 if (mManualRender)
102 {
103 for (VectorDrawItem::iterator iter = mDrawItems.begin(); iter != mDrawItems.end(); ++iter)
104 (*iter).first->doManualRender(mVertexBuffer, mTexture, mCountVertex);
105 }
106 else
107 {
108 _target->doRender(mVertexBuffer, mTexture, mCountVertex);
109 }
110 }
111 }
112
113 void RenderItem::removeDrawItem(ISubWidget* _item)
114 {
115 for (VectorDrawItem::iterator iter = mDrawItems.begin(); iter != mDrawItems.end(); ++iter)
116 {
117 if ((*iter).first == _item)
118 {
119 mNeedVertexCount -= (*iter).second;
120 mDrawItems.erase(iter);
121 mOutOfDate = true;
122
123 mVertexBuffer->setVertexCount(mNeedVertexCount);
124
125 // если все отдетачились, расскажем отцу
126 if (mDrawItems.empty())
127 {
128 mTexture = nullptr;
129 mCompression = true;
130 }
131
132 return;
133 }
134 }
135 MYGUI_EXCEPT("DrawItem not found");
136 }
137
138 void RenderItem::addDrawItem(ISubWidget* _item, size_t _count)
139 {
140
141 // проверяем только в дебаге
142 #if MYGUI_DEBUG_MODE == 1
143 for (VectorDrawItem::iterator iter = mDrawItems.begin(); iter != mDrawItems.end(); ++iter)
144 {
145 MYGUI_ASSERT((*iter).first != _item, "DrawItem exist");
146 }
147 #endif
148
149 mDrawItems.push_back(DrawItemInfo(_item, _count));
150 mNeedVertexCount += _count;
151 mOutOfDate = true;
152
153 mVertexBuffer->setVertexCount(mNeedVertexCount);
154 }
155
156 void RenderItem::reallockDrawItem(ISubWidget* _item, size_t _count)
157 {
158 for (VectorDrawItem::iterator iter = mDrawItems.begin(); iter != mDrawItems.end(); ++iter)
159 {
160 if ((*iter).first == _item)
161 {
162 // если нужно меньше, то ниче не делаем
163 if ((*iter).second < _count)
164 {
165 mNeedVertexCount -= (*iter).second;
166 mNeedVertexCount += _count;
167 (*iter).second = _count;
168 mOutOfDate = true;
169
170 mVertexBuffer->setVertexCount(mNeedVertexCount);
171 }
172 return;
173 }
174 }
175 MYGUI_EXCEPT("DrawItem not found");
176 }
177
178 void RenderItem::setTexture(ITexture* _value)
179 {
180 if (mTexture == _value)
181 return;
182
183 //MYGUI_DEBUG_ASSERT(mVertexBuffer->getVertexCount() == 0, "change texture only empty buffer");
184 MYGUI_DEBUG_ASSERT(mNeedVertexCount == 0, "change texture only empty buffer");
185
186 mTexture = _value;
187
188 #if MYGUI_DEBUG_MODE == 1
189 mTextureName = mTexture == nullptr ? "" : mTexture->getName();
190 #endif
191 }
192
193 ITexture* RenderItem::getTexture()
194 {
195 return mTexture;
196 }
197
198 bool RenderItem::getCompression()
199 {
200 bool result = mCompression;
201 mCompression = false;
202 return result;
203 }
204
205 void RenderItem::setManualRender(bool _value)
206 {
207 mManualRender = _value;
208 }
209
210 bool RenderItem::getManualRender() const
211 {
212 return mManualRender;
213 }
214
215 void RenderItem::outOfDate()
216 {
217 mOutOfDate = true;
218 }
219
220 bool RenderItem::isOutOfDate() const
221 {
222 return mOutOfDate;
223 }
224
225 size_t RenderItem::getNeedVertexCount() const
226 {
227 return mNeedVertexCount;
228 }
229
230 size_t RenderItem::getVertexCount() const
231 {
232 return mCountVertex;
233 }
234
235 bool RenderItem::getCurrentUpdate() const
236 {
237 return mCurrentUpdate;
238 }
239
240 Vertex* RenderItem::getCurrentVertexBuffer() const
241 {
242 return mCurrentVertex;
243 }
244
245 void RenderItem::setLastVertexCount(size_t _count)
246 {
247 mLastVertexCount = _count;
248 }
249
250 IRenderTarget* RenderItem::getRenderTarget()
251 {
252 return mRenderTarget;
253 }
254
255 } // namespace MyGUI
MyGUI::RenderItem::removeDrawItem
void removeDrawItem(ISubWidget *_item)
Definition: MyGUI_RenderItem.cpp:113
MyGUI::IVertexBuffer::setVertexCount
virtual void setVertexCount(size_t _value)=0
MyGUI::RenderItem::addDrawItem
void addDrawItem(ISubWidget *_item, size_t _count)
Definition: MyGUI_RenderItem.cpp:138
MyGUI_LayerManager.h
MyGUI_Precompiled.h
MyGUI_DataManager.h
MyGUI::RenderItem::getRenderTarget
IRenderTarget * getRenderTarget()
Definition: MyGUI_RenderItem.cpp:250
MyGUI::Singleton< RenderManager >::getInstance
static RenderManager & getInstance()
Definition: MyGUI_Singleton.h:53
MyGUI::RenderManager::destroyVertexBuffer
virtual void destroyVertexBuffer(IVertexBuffer *_buffer)=0
MyGUI::IVertexBuffer::lock
virtual Vertex * lock()=0
MyGUI::DrawItemInfo
std::pair< ISubWidget *, size_t > DrawItemInfo
Definition: MyGUI_RenderItem.h:34
MyGUI::RenderItem::renderToTarget
void renderToTarget(IRenderTarget *_target, bool _update)
Definition: MyGUI_RenderItem.cpp:56
MyGUI::RenderItem::getVertexCount
size_t getVertexCount() const
Definition: MyGUI_RenderItem.cpp:230
MyGUI::ISubWidget
Definition: MyGUI_ISubWidget.h:39
MyGUI::RenderItem::RenderItem
RenderItem()
Definition: MyGUI_RenderItem.cpp:34
nullptr
#define nullptr
Definition: MyGUI_Prerequest.h:47
MyGUI::RenderItem::setTexture
void setTexture(ITexture *_value)
Definition: MyGUI_RenderItem.cpp:178
MyGUI::RenderItem::setManualRender
void setManualRender(bool _value)
Definition: MyGUI_RenderItem.cpp:205
MyGUI::ITexture::getName
virtual const std::string & getName() const =0
MyGUI::RenderItem::getManualRender
bool getManualRender() const
Definition: MyGUI_RenderItem.cpp:210
MyGUI::RenderManager::createVertexBuffer
virtual IVertexBuffer * createVertexBuffer()=0
MyGUI::RenderItem::outOfDate
void outOfDate()
Definition: MyGUI_RenderItem.cpp:215
MyGUI_RenderManager.h
MyGUI::RenderItem::getCurrentVertexBuffer
Vertex * getCurrentVertexBuffer() const
Definition: MyGUI_RenderItem.cpp:240
MyGUI::IVertexBuffer::unlock
virtual void unlock()=0
MYGUI_EXCEPT
#define MYGUI_EXCEPT(dest)
Definition: MyGUI_Diagnostic.h:49
MyGUI::IRenderTarget::doRender
virtual void doRender(IVertexBuffer *_buffer, ITexture *_texture, size_t _count)=0
MyGUI_RenderItem.h
MyGUI::RenderItem::reallockDrawItem
void reallockDrawItem(ISubWidget *_item, size_t _count)
Definition: MyGUI_RenderItem.cpp:156
MyGUI::RenderItem::getTexture
ITexture * getTexture()
Definition: MyGUI_RenderItem.cpp:193
MYGUI_ASSERT
#define MYGUI_ASSERT(exp, dest)
Definition: MyGUI_Diagnostic.h:58
MyGUI::ITexture
Definition: MyGUI_ITexture.h:41
MyGUI::IRenderTarget
Definition: MyGUI_IRenderTarget.h:35
MyGUI::RenderItem::getCompression
bool getCompression()
Definition: MyGUI_RenderItem.cpp:198
MyGUI_LayerNode.h
MyGUI::RenderItem::isOutOfDate
bool isOutOfDate() const
Definition: MyGUI_RenderItem.cpp:220
MyGUI::RenderItem::getNeedVertexCount
size_t getNeedVertexCount() const
Definition: MyGUI_RenderItem.cpp:225
MYGUI_DEBUG_ASSERT
#define MYGUI_DEBUG_ASSERT(exp, dest)
Definition: MyGUI_Diagnostic.h:83
MyGUI_Gui.h
MyGUI::Vertex
Definition: MyGUI_VertexData.h:31
MyGUI::RenderItem::getCurrentUpdate
bool getCurrentUpdate() const
Definition: MyGUI_RenderItem.cpp:235
MyGUI::RenderItem::setLastVertexCount
void setLastVertexCount(size_t _count)
Definition: MyGUI_RenderItem.cpp:245
MyGUI::RenderItem::~RenderItem
virtual ~RenderItem()
Definition: MyGUI_RenderItem.cpp:50