#include <TextureResourceFile.h>
Collaboration diagram for pge::TextureResourceFile:
Public Member Functions | |
TextureResourceFile (const std::string &file) | |
Constructor. | |
virtual | ~TextureResourceFile (void) |
Destructor. | |
bool | hasResource (const std::string &filename) |
TextureResource | getResource (const std::string &filename) |
Private Member Functions | |
bool | parseContent (void) |
bool | parseTexture (xml::CXMLNode *textureNode) |
Private Attributes | |
std::string | m_filename |
std::vector< TextureResource > | m_resources |
xml::CXMLDocument * | m_document |
|
Constructor.
Definition at line 19 of file TextureResourceFile.cpp. References m_document, m_resources, and parseContent().
00019 { 00020 m_resources = std::vector<TextureResource>(); 00021 m_document = new xml::CXMLDocument(filename); 00022 00023 if(m_document != NULL) { 00024 if(parseContent()) { 00025 printf("INFO: [%s] TextureResourceFile loaded.\n", __FILE__); 00026 } else { 00027 printf("ERROR: [%s] TextureResourceFile could not be loaded.\n", __FILE__); 00028 } 00029 } 00030 } |
Here is the call graph for this function:
|
Destructor.
Definition at line 38 of file TextureResourceFile.cpp. References m_document.
00038 { 00039 if(m_document != NULL) { 00040 delete m_document; 00041 m_document = NULL; 00042 } 00043 } |
|
Definition at line 70 of file TextureResourceFile.cpp. References pge::TextureResourceFile::TextureResource::m_filename, and m_resources. Referenced by pge::TextureDatabase::addTexture().
00070 { 00071 std::vector<TextureResource>::iterator it; 00072 00073 00074 for(it = m_resources.begin(); it != m_resources.end(); it++) { 00075 TextureResource res =*it; 00076 if(res.m_filename == filename) { 00077 return res; 00078 } 00079 } 00080 return TextureResource(); 00081 } |
|
Definition at line 51 of file TextureResourceFile.cpp. References pge::TextureResourceFile::TextureResource::m_filename, and m_resources. Referenced by pge::TextureDatabase::addTexture().
00051 { 00052 std::vector<TextureResource>::iterator it; 00053 00054 00055 for(it = m_resources.begin(); it != m_resources.end(); it++) { 00056 TextureResource res = *it; 00057 if(res.m_filename == filename) { 00058 return true; 00059 } 00060 } 00061 return false; 00062 } |
|
Definition at line 89 of file TextureResourceFile.cpp. References xml::CXMLDocument::evaluateXPathExpression(), xml::CXMLNodeSet::getNodeAt(), xml::CXMLNodeSet::getNodeNum(), xml::CXMLDocument::isFileOpen(), m_document, and parseTexture(). Referenced by TextureResourceFile().
00089 { 00090 xml::CXMLNodeSet *set = NULL; 00091 int i; 00092 bool success = true; 00093 00094 00095 if(m_document->isFileOpen()) { 00096 set = m_document->evaluateXPathExpression("/textures/texture", NULL); 00097 if(set != NULL) { 00098 00099 for(i = 0; i < set->getNodeNum() && success; i++) { 00100 xml::CXMLNode node; 00101 00102 if(set->getNodeAt(i, &node)) { 00103 if(!parseTexture(&node)) { 00104 success = false; 00105 } 00106 } else { 00107 success = false; 00108 } 00109 } 00110 00111 delete set; 00112 set = NULL; 00113 } 00114 delete m_document; 00115 m_document = NULL; 00116 } 00117 00118 return success; 00119 } |
Here is the call graph for this function:
|
Definition at line 127 of file TextureResourceFile.cpp. References xml::CXMLNode::getAttributeByName(), xml::CXMLNode::getFirstChildNode(), xml::CXMLNode::getName(), xml::CXMLNode::getNextSiblingNode(), xml::CXMLNode::getText(), pge::TextureResourceFile::TextureResource::m_alphaBlue, pge::TextureResourceFile::TextureResource::m_alphaEnabled, pge::TextureResourceFile::TextureResource::m_alphaGreen, pge::TextureResourceFile::TextureResource::m_alphaRed, pge::TextureResourceFile::TextureResource::m_doMipmap, pge::TextureResourceFile::TextureResource::m_filename, pge::TextureResourceFile::TextureResource::m_magFilter, pge::TextureResourceFile::TextureResource::m_minFilter, m_resources, xml::CXMLAttribute::m_value, pge::TextureResourceFile::TextureResource::m_wrapS, pge::TextureResourceFile::TextureResource::m_wrapT, TEXTURE_MAGFILTER, TEXTURE_MINFILTER_MIPMAP, TEXTURE_WRAPS, and TEXTURE_WRAPT. Referenced by parseContent().
00127 { 00128 TextureResource res; 00129 xml::CXMLNode firstChild; 00130 xml::CXMLNode sibling; 00131 xml::CXMLNode temp; 00132 std::string name; 00133 std::string str; 00134 00135 00136 // The first child must be the filename node, else return failure. 00137 if(textureNode->getFirstChildNode(&firstChild)) { 00138 if(firstChild.getName(&name)) { 00139 if(name != "filename") { 00140 return false; 00141 } else { 00142 if(firstChild.getText(&str)) { 00143 res.m_filename = std::string(str); 00144 } else { 00145 return false; 00146 } 00147 } 00148 } 00149 00150 // Now go through all the siblings. 00151 while(firstChild.getNextSiblingNode(&sibling)) { 00152 00153 // Try to get the name of the node. 00154 if(sibling.getName(&name)) { 00155 00156 // Now parse the specific nodes. 00157 // Alpha node. 00158 if(name == "alpha") { 00159 xml::CXMLAttribute attr; 00160 00161 // Get the attribute of the node. 00162 if(sibling.getAttributeByName("enabled", &attr)) { 00163 // Set alpha enabled value. 00164 if(attr.m_value == "true") { 00165 res.m_alphaEnabled = true; 00166 } else { 00167 res.m_alphaEnabled = false; 00168 } 00169 } 00170 // Parse alpha value node. 00171 if(sibling.getFirstChildNode(&temp)) { 00172 if(temp.getName(&str)) { 00173 if(str == "alphablend") { 00174 00175 // Now parse the alpha values. 00176 if(temp.getAttributeByName("red", &attr)) { 00177 res.m_alphaRed = utils::stringToInt(attr.m_value); 00178 } 00179 if(temp.getAttributeByName("green", &attr)) { 00180 res.m_alphaGreen = utils::stringToInt(attr.m_value); 00181 } 00182 if(temp.getAttributeByName("blue", &attr)) { 00183 res.m_alphaBlue = utils::stringToInt(attr.m_value); 00184 } 00185 } 00186 } 00187 } 00188 } 00189 00190 // The filter node. 00191 if(name == "filter") { 00192 xml::CXMLAttribute attr; 00193 00194 // Set standard values at first, the overwrite them if more information is given. 00195 res.m_minFilter = TEXTURE_MINFILTER_MIPMAP; 00196 res.m_magFilter = TEXTURE_MAGFILTER; 00197 res.m_doMipmap = true; 00198 00199 // Min filter. 00200 if(sibling.getAttributeByName("minfilter", &attr)) { 00201 // Check the filter settings. 00202 if(attr.m_value == "linear") { 00203 res.m_minFilter = GL_LINEAR; 00204 res.m_doMipmap = false; 00205 } 00206 if(attr.m_value == "nearest") { 00207 res.m_minFilter = GL_NEAREST; 00208 res.m_doMipmap = false; 00209 } 00210 if(attr.m_value == "linear_mipmap_linear") { 00211 res.m_minFilter = GL_LINEAR_MIPMAP_LINEAR; 00212 res.m_doMipmap = true; 00213 } 00214 if(attr.m_value == "linear_mipmap_nearest") { 00215 res.m_minFilter = GL_LINEAR_MIPMAP_NEAREST; 00216 res.m_doMipmap = true; 00217 } 00218 if(attr.m_value == "nearest_mipmap_linear") { 00219 res.m_minFilter = GL_NEAREST_MIPMAP_LINEAR; 00220 res.m_doMipmap = true; 00221 } 00222 if(attr.m_value == "nearest_mipmap_nearest") { 00223 res.m_minFilter = GL_NEAREST_MIPMAP_NEAREST; 00224 res.m_doMipmap = true; 00225 } 00226 } 00227 00228 // Mag filter. 00229 if(sibling.getAttributeByName("magfilter", &attr)) { 00230 // Check the filter settings 00231 if(attr.m_value == "linear") { 00232 res.m_magFilter = GL_LINEAR; 00233 } 00234 if(attr.m_value == "nearest") { 00235 res.m_magFilter = GL_NEAREST; 00236 } 00237 } 00238 } 00239 00240 // The wrap node. 00241 if(name == "wrap") { 00242 xml::CXMLAttribute attr; 00243 00244 // Default wrap settings. 00245 res.m_wrapS = TEXTURE_WRAPS; 00246 res.m_wrapT = TEXTURE_WRAPT; 00247 00248 if(sibling.getAttributeByName("s", &attr)) { 00249 if(attr.m_value == "repeat") { 00250 res.m_wrapS = GL_REPEAT; 00251 } 00252 if(attr.m_value == "clamp") { 00253 res.m_wrapS = GL_CLAMP; 00254 } 00255 } 00256 if(sibling.getAttributeByName("t", &attr)) { 00257 if(attr.m_value == "repeat") { 00258 res.m_wrapT = GL_REPEAT; 00259 } 00260 if(attr.m_value == "clamp") { 00261 res.m_wrapT = GL_CLAMP; 00262 } 00263 } 00264 } 00265 } 00266 firstChild = sibling; 00267 } 00268 m_resources.push_back(res); 00269 return true; 00270 } 00271 return false; 00272 } |
Here is the call graph for this function:
|
Definition at line 84 of file TextureResourceFile.h. Referenced by parseContent(), TextureResourceFile(), and ~TextureResourceFile(). |
|
Definition at line 82 of file TextureResourceFile.h. |
|
Definition at line 83 of file TextureResourceFile.h. Referenced by getResource(), hasResource(), parseTexture(), and TextureResourceFile(). |