/
TextureTarget.cpp
167 lines (136 loc) · 5.68 KB
/
TextureTarget.cpp
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
/***********************************************************************
created: Tue Feb 17 2009
author: Paul D Turner
*************************************************************************/
/***************************************************************************
* Copyright (C) 2004 - 2011 Paul D Turner & The CEGUI Development Team
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
***************************************************************************/
#include "CEGUI/RendererModules/Ogre/TextureTarget.h"
#include "CEGUI/RendererModules/Ogre/Texture.h"
#include "CEGUI/PropertyHelper.h"
#include <OgreTextureManager.h>
#include <OgreHardwarePixelBuffer.h>
#include <OgreRenderTexture.h>
#include <OgreRenderSystem.h>
#include <OgreViewport.h>
// Start of CEGUI namespace section
namespace CEGUI
{
//----------------------------------------------------------------------------//
const float OgreTextureTarget::DEFAULT_SIZE = 128.0f;
uint OgreTextureTarget::s_textureNumber = 0;
//----------------------------------------------------------------------------//
OgreTextureTarget::OgreTextureTarget(OgreRenderer& owner,
Ogre::RenderSystem& rs) :
OgreRenderTarget<TextureTarget>(owner, rs),
d_CEGUITexture(0)
{
d_CEGUITexture = static_cast<OgreTexture*>(
&d_owner.createTexture(generateTextureName()));
// setup area and cause the initial texture to be generated.
declareRenderSize(Sizef(DEFAULT_SIZE, DEFAULT_SIZE));
}
//----------------------------------------------------------------------------//
OgreTextureTarget::~OgreTextureTarget()
{
d_owner.destroyTexture(*d_CEGUITexture);
}
//----------------------------------------------------------------------------//
bool OgreTextureTarget::isImageryCache() const
{
return true;
}
//----------------------------------------------------------------------------//
void OgreTextureTarget::clear()
{
if (!d_viewportValid)
updateViewport();
#if !defined(CEGUI_USE_OGRE_COMPOSITOR2)
Ogre::Viewport* const saved_vp = d_renderSystem._getViewport();
d_renderSystem._setViewport(d_viewport);
d_renderSystem.clearFrameBuffer(Ogre::FBT_COLOUR,
Ogre::ColourValue(0, 0, 0, 0));
#if OGRE_VERSION < 0x10800
if (saved_vp)
d_renderSystem._setViewport(saved_vp);
#else
d_renderSystem._setViewport(saved_vp);
#endif
#endif
}
//----------------------------------------------------------------------------//
Texture& OgreTextureTarget::getTexture() const
{
return *d_CEGUITexture;
}
//----------------------------------------------------------------------------//
void OgreTextureTarget::declareRenderSize(const Sizef& sz)
{
// exit if current size is enough
if ((d_area.getWidth() >= sz.d_width) && (d_area.getHeight() >=sz.d_height))
return;
Ogre::TexturePtr rttTex = Ogre::TextureManager::getSingleton().createManual(
OgreTexture::getUniqueName(),
Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
Ogre::TEX_TYPE_2D, sz.d_width, sz.d_height, 1, 0, Ogre::PF_A8R8G8B8,
Ogre::TU_RENDERTARGET);
d_renderTarget = rttTex->getBuffer()->getRenderTarget();
Rectf init_area(
Vector2f(0, 0),
Sizef(d_renderTarget->getWidth(), d_renderTarget->getHeight())
);
setArea(init_area);
#ifdef CEGUI_USE_OGRE_COMPOSITOR2
// Setting this should properly change everything
d_renderTargetUpdated = true;
#else
// delete viewport and reset ptr so a new one is generated. This is
// required because we have changed d_renderTarget so need a new VP also.
OGRE_DELETE d_viewport;
d_viewport = 0;
#endif
// because Texture takes ownership, the act of setting the new ogre texture
// also ensures any previous ogre texture is released.
d_CEGUITexture->setOgreTexture(rttTex, true);
clear();
}
//----------------------------------------------------------------------------//
bool OgreTextureTarget::isRenderingInverted() const
{
return false;
}
//----------------------------------------------------------------------------//
String OgreTextureTarget::generateTextureName()
{
String tmp("_ogre_tt_tex_");
tmp.append(PropertyHelper<uint>::toString(s_textureNumber++));
return tmp;
}
//----------------------------------------------------------------------------//
} // End of CEGUI namespace section
//----------------------------------------------------------------------------//
// Implementation of template base class
#include "./RenderTarget.inl"
#ifdef __APPLE__
template class CEGUI::OgreRenderTarget<CEGUI::RenderTarget>;
template class CEGUI::OgreRenderTarget<CEGUI::TextureTarget>;
#endif