1 /***********************************************************************
2 created: Sat Jan 16 2010
3 author: Eugene Marcotte
4 *************************************************************************/
5 /***************************************************************************
6 * Copyright (C) 2004 - 2011 Paul D Turner & The CEGUI Development Team
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining
9 * a copy of this software and associated documentation files (the
10 * "Software"), to deal in the Software without restriction, including
11 * without limitation the rights to use, copy, modify, merge, publish,
12 * distribute, sublicense, and/or sell copies of the Software, and to
13 * permit persons to whom the Software is furnished to do so, subject to
14 * the following conditions:
15 *
16 * The above copyright notice and this permission notice shall be
17 * included in all copies or substantial portions of the Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
22 * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
23 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
24 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
25 * OTHER DEALINGS IN THE SOFTWARE.
26 ***************************************************************************/
27 #include "CEGUI/RendererModules/Null/Texture.h"
28 #include "CEGUI/Exceptions.h"
29 #include "CEGUI/ImageCodec.h"
30 #include "CEGUI/System.h"
31
32 // Start of CEGUI namespace section
33 namespace CEGUI
34 {
35 //----------------------------------------------------------------------------//
36 uint32 NullTexture::d_textureNumber = 0;
37
38 //----------------------------------------------------------------------------//
getName() const39 const String& NullTexture::getName() const
40 {
41 return d_name;
42 }
43
44 //----------------------------------------------------------------------------//
getSize() const45 const Sizef& NullTexture::getSize() const
46 {
47 return d_size;
48 }
49
50 //----------------------------------------------------------------------------//
getOriginalDataSize() const51 const Sizef& NullTexture::getOriginalDataSize() const
52 {
53 return d_dataSize;
54 }
55
56 //----------------------------------------------------------------------------//
getTexelScaling() const57 const Vector2f& NullTexture::getTexelScaling() const
58 {
59 return d_texelScaling;
60 }
61
62 //----------------------------------------------------------------------------//
loadFromFile(const String & filename,const String & resourceGroup)63 void NullTexture::loadFromFile(const String& filename,
64 const String& resourceGroup)
65 {
66 // get and check existence of CEGUI::System object
67 System* sys = System::getSingletonPtr();
68 if (!sys)
69 CEGUI_THROW(RendererException(
70 "CEGUI::System object has not been created!"));
71
72 // load file to memory via resource provider
73 RawDataContainer texFile;
74 sys->getResourceProvider()->loadRawDataContainer(filename, texFile,
75 resourceGroup);
76
77 Texture* res = sys->getImageCodec().load(texFile, this);
78
79 // unload file data buffer
80 sys->getResourceProvider()->unloadRawDataContainer(texFile);
81
82 // throw exception if data was load loaded to texture.
83 if (!res)
84 CEGUI_THROW(RendererException(
85 sys->getImageCodec().getIdentifierString() +
86 " failed to load image '" + filename + "'."));
87 }
88
89 //----------------------------------------------------------------------------//
loadFromMemory(const void *,const Sizef & buffer_size,PixelFormat)90 void NullTexture::loadFromMemory(const void* /*buffer*/,
91 const Sizef& buffer_size,
92 PixelFormat)
93 {
94 d_size = d_dataSize = buffer_size;
95 }
96
97 //----------------------------------------------------------------------------//
blitFromMemory(const void *,const Rectf &)98 void NullTexture::blitFromMemory(const void* /*sourceData*/, const Rectf& /*area*/)
99 {
100 // do nothing
101 }
102
103 //----------------------------------------------------------------------------//
blitToMemory(void *)104 void NullTexture::blitToMemory(void* /*targetData*/)
105 {
106 // do nothing
107 }
108
109 //----------------------------------------------------------------------------//
NullTexture(const String & name)110 NullTexture::NullTexture(const String& name) :
111 d_size(0, 0),
112 d_dataSize(0, 0),
113 d_texelScaling(0, 0),
114 d_name(name)
115 {
116 }
117
118 //----------------------------------------------------------------------------//
NullTexture(const String & name,const String & filename,const String & resourceGroup)119 NullTexture::NullTexture(const String& name, const String& filename,
120 const String& resourceGroup) :
121 d_size(0, 0),
122 d_dataSize(0, 0),
123 d_texelScaling(0, 0),
124 d_name(name)
125 {
126 loadFromFile(filename, resourceGroup);
127 }
128
129 //----------------------------------------------------------------------------//
NullTexture(const String & name,const Sizef & sz)130 NullTexture::NullTexture(const String& name, const Sizef& sz) :
131 d_size(0, 0),
132 d_dataSize(0, 0),
133 d_texelScaling(0, 0),
134 d_name(name)
135 {
136 d_size.d_width = sz.d_width;
137 d_size.d_height = sz.d_height;
138 d_dataSize = sz;
139 }
140
141 //----------------------------------------------------------------------------//
~NullTexture()142 NullTexture::~NullTexture()
143 {
144 }
145
146 //----------------------------------------------------------------------------//
isPixelFormatSupported(const PixelFormat) const147 bool NullTexture::isPixelFormatSupported(const PixelFormat) const
148 {
149 return true;
150 }
151
152 //----------------------------------------------------------------------------//
153
154 } // End of CEGUI namespace section
155