bool TextureNode::sEqual(const RepoNode &other) const { if (other.getTypeAsEnum() != NodeType::TEXTURE || other.getParentIDs().size() != getParentIDs().size()) { return false; } TextureNode otherText = TextureNode(other); bool equal; if (equal = getFileExtension() == otherText.getFileExtension()) { std::vector<char> *raw, *raw2; raw = getRawData(); raw2 = otherText.getRawData(); if (equal = (raw && raw2 && (raw->size() == raw2->size())) ) { equal = !memcmp(raw->data(), raw2->data(), raw->size() * sizeof(*raw->data())); delete raw; delete raw2; } } return equal; }
// for use when loading textures from .ctf (converted TGA file) bool TextureMan::LoadTexture( const char * const fileName, const char * const textID ) { GLuint textureID; GLuint *pTextureID = &textureID; // get instance TextureMan *pTextMan = TextureMan::privGetInstance(); unsigned char* lTexture = getTGAFile( fileName ); pTextMan->privLoadMyTexture( lTexture, pTextureID ); // hash the string textID and store it as the textureID for the manager MD5Output out; MD5Buffer ((unsigned char *)textID, strlen(textID), out); GLuint hashID = out.dWord_0 ^ out.dWord_1 ^ out.dWord_2 ^ out.dWord_3; // make a new node, set its values TextureNode *pNode = new TextureNode(); pNode->set( fileName, hashID, textureID, GL_LINEAR, GL_LINEAR, GL_CLAMP_TO_EDGE ); // add said node to front of active texture list pTextMan->privAddToFront( pNode, pTextMan->active ); return true; }
bool TexturePacker::assignCoords(unsigned int *width, unsigned int *height){ Set <TextureRectangle *> sortedRects; sortedRects.setCount(rects.getCount()); memcpy(sortedRects.getArray(), rects.getArray(), rects.getCount() * sizeof(TextureRectangle *)); sortedRects.sort(compare); TextureNode *top = new TextureNode(0, 0, *width, *height); *width = 0; *height = 0; for (unsigned int i = 0; i < sortedRects.getCount(); i++){ if (top->assignRectangle(sortedRects[i])){ unsigned int x = sortedRects[i]->x + sortedRects[i]->width; unsigned int y = sortedRects[i]->y + sortedRects[i]->height; if (x > *width ) *width = x; if (y > *height) *height = y; } else { delete top; return false; } } delete top; return true; }
void TextureMan::AddTexture( const char * const inAssetName, const TextureName inName ) { GLuint textureID; GLuint *pTextureID = &textureID; // get instance TextureMan *pTextMan = TextureMan::privGetInstance(); // load texture to gpu, get ID from gpu pTextMan->privLoadTexture( inAssetName, pTextureID ); // make a new node, set its values TextureNode *pNode = new TextureNode(); pNode->set( inAssetName, inName, textureID, GL_LINEAR, GL_LINEAR, GL_CLAMP_TO_EDGE ); // add said node to front of active texture list pTextMan->privAddToFront( pNode, pTextMan->active ); }
bool TextureNode::assignRectangle(TextureRectangle *newRect){ if (rect == NULL){ if (left->assignRectangle(newRect)) return true; return right->assignRectangle(newRect); } else { if (newRect->width <= rect->width && newRect->height <= rect->height){ newRect->x = rect->x; newRect->y = rect->y; left = new TextureNode(rect->x, rect->y + newRect->height, newRect->width, rect->height - newRect->height); right = new TextureNode(rect->x + newRect->width, rect->y, rect->width - newRect->width, rect->height); delete rect; rect = NULL; return true; } return false; } }
void TextureMan::addTexture( const char * const _assetName, const TextureName _name) { GLuint textureID; GLuint *pTextureID = &textureID; // Get the instance to the manager TextureMan *pTextMan = TextureMan::privGetInstance(); // Load the texture and get the textureID pTextMan->privLoadTexture( _assetName, pTextureID ); // Create a TextureNode TextureNode *pNode = new TextureNode(); // initialize it pNode->set( _assetName, _name, textureID, GL_LINEAR, GL_LINEAR, GL_CLAMP_TO_EDGE); // Now add it to the manager pTextMan->privAddToFront( pNode, pTextMan->active ); }
void AppearanceNode::outputContext(ostream &printStream, const char *indentString) { MaterialNode *material = getMaterialNodes(); if (material != NULL) { if (material->isInstanceNode() == false) { if (material->getName() != NULL && strlen(material->getName())) printStream << indentString << "\t" << "material " << "DEF " << material->getName() << " Material {" << endl; else printStream << indentString << "\t" << "material Material {" << endl; material->Node::outputContext(printStream, indentString, "\t"); printStream << indentString << "\t" << "}" << endl; } else printStream << indentString << "\t" << "material USE " << material->getName() << endl; } TextureNode *texture = getTextureNode(); if (texture != NULL) { if (texture->isInstanceNode() == false) { if (texture->getName() != NULL && strlen(texture->getName())) printStream << indentString << "\t" << "texture " << "DEF " << texture->getName() << " " << texture->Node::getType() << " {" << endl; else printStream << indentString << "\t" << "texture " << texture->Node::getType() << " {" << endl; texture->Node::outputContext(printStream, indentString, "\t"); printStream << indentString << "\t" << "}" << endl; } else printStream << indentString << "\t" << "texture USE " << texture->getName() << endl; } TextureTransformNode *textureTransform = getTextureTransformNodes(); if (textureTransform != NULL) { if (textureTransform->isInstanceNode() == false) { if (textureTransform->getName() != NULL && strlen(textureTransform->getName())) printStream << indentString << "\t" << "textureTransform " << "DEF " << textureTransform->getName() << " TextureTransform {" << endl; else printStream << indentString << "\t" << "textureTransform TextureTransform {" << endl; textureTransform->Node::outputContext(printStream, indentString, "\t"); printStream << indentString << "\t" << "}" << endl; } else printStream << indentString << "\t" << "textureTransform USE " << textureTransform->getName() << endl; } }
TEST(RepoBSONFactoryTest, MakeTextureNodeTest) { std::string ext = "jpg"; std::string name = "textureNode." + ext; std::string data = "The value of this texture is represented by this string as all it takes is a char*"; int width = 100, height = 110; TextureNode tex = RepoBSONFactory::makeTextureNode(name, data.c_str(), data.size(), width, height); ASSERT_FALSE(tex.isEmpty()); EXPECT_EQ(name, tex.getName()); EXPECT_EQ(width, tex.getField(REPO_LABEL_WIDTH).Int()); EXPECT_EQ(height, tex.getField(REPO_LABEL_HEIGHT).Int()); EXPECT_EQ(ext, tex.getFileExtension()); std::vector<char> rawOut = tex.getRawData(); ASSERT_EQ(data.size(), rawOut.size()); EXPECT_EQ(0, memcmp(data.c_str(), rawOut.data(), data.size())); //make sure the code doesn't fail over if for some reason the name does not contain the extension TextureNode tex2 = RepoBSONFactory::makeTextureNode("noExtensionName", data.c_str(), data.size(), width, height); }
bool Parser::Parse(const std::vector<Token>& inTokens, Node **outParseTree) { Node* rootNode = new Node(kNodeType_Root); unsigned int tokenCount = inTokens.size(); int scopeLevel = 0; bool inComment = false; TextureNode* currentTextureNode = nullptr; OperationNode* currentOperationNode = nullptr; for(unsigned int index = 0; index < tokenCount; ++index) { const Token& currentToken = inTokens[index]; switch(currentToken.GetType()) { case kToken_ScopeBegin: { if( !inComment ) { // We're opening a new texture scope so it shouldn't be null assert( currentTextureNode != nullptr ); scopeLevel++; } break; } case kToken_ScopeEnd: { if( !inComment ) { // We're closing a texture scope so it shouldn't be null assert( currentTextureNode != nullptr ); scopeLevel--; rootNode->InsertNode( currentTextureNode ); currentTextureNode = nullptr; } break; } case kToken_CommentBegin: { assert( !inComment ); inComment = true; break; } case kToken_CommentEnd: { assert( inComment ); inComment = false; break; } case kToken_Terminator: { if( !inComment ) { // Terminate the operation assert( currentOperationNode != nullptr ); assert( currentTextureNode != nullptr ); currentTextureNode->InsertNode( currentOperationNode ); currentOperationNode = nullptr; } break; } case kToken_Identifier: { if( !inComment ) { // Start a new texture if we're not in one if( currentTextureNode == nullptr ) { IdentifierTokenData* tokenData = static_cast<IdentifierTokenData*>(currentToken.GetData()); assert( tokenData->GetValue().compare( "Texture" ) == 0 ); // Free the data here. This means the tokens are one time use delete tokenData; currentTextureNode = new TextureNode( "Undefined" ); } else { // We're still looking for a name if( currentTextureNode->GetName().compare( "Undefined") == 0 ) { IdentifierTokenData* tokenData = static_cast<IdentifierTokenData*>(currentToken.GetData()); // Make sure no one tries to name it "Undefined" assert( tokenData->GetValue().compare( "Undefined" ) != 0 ); currentTextureNode->SetName( tokenData->GetValue() ); // Free the data here. This means the tokens are one time use delete tokenData; // We also need width height and pixel depth assert( index + 3 < tokenCount ); assert( inTokens[index+1].GetType() == kToken_Number ); assert( inTokens[index+2].GetType() == kToken_Number ); assert( inTokens[index+3].GetType() == kToken_Number ); NumberTokenData* widthData = static_cast<NumberTokenData*>(inTokens[index+1].GetData()); NumberTokenData* heightData = static_cast<NumberTokenData*>(inTokens[index+2].GetData()); NumberTokenData* pixelDepthData = static_cast<NumberTokenData*>(inTokens[index+3].GetData()); currentTextureNode->SetWidth( widthData->GetValue() ); currentTextureNode->SetHeight( heightData->GetValue() ); currentTextureNode->SetPixelDepth( pixelDepthData->GetValue() ); delete widthData; delete heightData; delete pixelDepthData; } else { // We're looking for operations now. assert( currentOperationNode == nullptr ); IdentifierTokenData* tokenData = static_cast<IdentifierTokenData*>(currentToken.GetData()); currentOperationNode = new OperationNode( tokenData->GetValue() ); // Free the data here. This means the tokens are one time use delete tokenData; } } } break; } case kToken_Number: { if( !inComment ) { // Add arguments to the operation if( currentOperationNode != nullptr ) { NumberTokenData* tokenData = static_cast<NumberTokenData*>(currentToken.GetData()); currentOperationNode->AddArgument( tokenData->GetValue() ); // Free the data here. This means the tokens are one time use delete tokenData; } } break; } case kToken_Undefined: default: { std::cout << "Error! Undefined token encountered!" << std::endl; delete rootNode; return false; } } } *outParseTree = rootNode; return true; }