Просмотр исходного кода

Texture filtering mode option in project settings

Ivan Safrin 13 лет назад
Родитель
Сommit
9b1d802703

+ 2 - 3
Core/Contents/Source/PolyObject.cpp

@@ -118,9 +118,8 @@ TiXmlElement *Object::createElementFromObjectEntry(ObjectEntry *entry) {
 
 	for(int i=0; i < entry->children.size(); i++) {
 				ObjectEntry *childEntry = entry->children[i];
-				bool needLinkChild = (childEntry->children.size() > 0) || (entry->type == ObjectEntry::ARRAY_ENTRY);
-				
-		//		printf("Parsing %s (type: %d)\n", childEntry->name.c_str(), childEntry->type);
+		
+				bool needLinkChild = (childEntry->children.size() > 0) || (entry->type == ObjectEntry::ARRAY_ENTRY);				
 				
 				if (!needLinkChild) {
 					const String &childTypedName = childEntry->getTypedName();

+ 1 - 1
IDE/Build/Mac OS X/Polycode.xcodeproj/project.pbxproj

@@ -408,7 +408,7 @@
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 			shellPath = /bin/sh;
-			shellScript = "cp -R \"$PROJECT_DIR/../../Contents/Resources\" \"$BUILT_PRODUCTS_DIR/$CONTENTS_FOLDER_PATH\"";
+			shellScript = "cp -R \"$PROJECT_DIR/../../Contents/Resources\" \"$BUILT_PRODUCTS_DIR/$CONTENTS_FOLDER_PATH\"\ncp -R \"$PROJECT_DIR/../../../Release/Darwin/Standalone\" \"$BUILT_PRODUCTS_DIR/$CONTENTS_FOLDER_PATH/Resources\"\ncp -R \"$PROJECT_DIR/../../../Bindings/Contents/LUA/API/api.pak\" \"$BUILT_PRODUCTS_DIR/$CONTENTS_FOLDER_PATH/Resources\"";
 		};
 /* End PBXShellScriptBuildPhase section */
 

+ 1 - 0
IDE/Contents/Include/PolycodeProject.h

@@ -48,6 +48,7 @@ class ProjectData {
 		unsigned int anisotropy;	
 		unsigned int aaLevel;
 		unsigned int frameRate;
+		String filteringMode;
 		
 		std::vector<String> modules;		
 		std::vector<ProjectFontData> fonts;

+ 1 - 0
IDE/Contents/Include/PolycodeProjectEditor.h

@@ -83,6 +83,7 @@ class PolycodeProjectEditor : public PolycodeEditor {
 	UITextInput *framerateInput;	
 	UIComboBox *aaLevelComboBox;
 	UIComboBox *afLevelComboBox;	
+	UIComboBox *texFilteringComboBox;
 	UITextInput *entryPointInput;	
 	UIColorBox *bgColorBox;
 	

+ 12 - 1
IDE/Contents/Source/PolycodeProject.cpp

@@ -60,6 +60,14 @@ bool PolycodeProject::loadProjectFromFile() {
 		data.defaultHeight = 480;	
 		configFile.root.addChild("defaultHeight", 480);		
 	}
+	
+	if(configFile.root["textureFiltering"]) {	
+		data.filteringMode = configFile.root["textureFiltering"]->stringVal;
+	} else {
+		data.filteringMode = "linear";
+		configFile.root.addChild("textureFiltering", String("linear"));	
+	}
+	
 
 	if(configFile.root["vSync"]) {	
 		data.vSync = configFile.root["vSync"]->boolVal;
@@ -143,7 +151,10 @@ bool PolycodeProject::saveFile() {
 	configFile.root["defaultWidth"]->intVal = data.defaultWidth;
 	configFile.root["defaultHeight"]->intVal = data.defaultHeight;
 	configFile.root["entryPoint"]->stringVal = data.entryPoint;
-	configFile.root["entryPoint"]->type = ObjectEntry::STRING_ENTRY;
+	configFile.root["entryPoint"]->type = ObjectEntry::STRING_ENTRY;	
+	
+	configFile.root["textureFiltering"]->type = ObjectEntry::STRING_ENTRY;
+	configFile.root["textureFiltering"]->stringVal = data.filteringMode;
 	
 	ObjectEntry *color = configFile.root["backgroundColor"];
 	

+ 22 - 5
IDE/Contents/Source/PolycodeProjectEditor.cpp

@@ -190,11 +190,21 @@ PolycodeProjectEditor::PolycodeProjectEditor(PolycodeProjectManager *projectMana
 	aaLevelComboBox->addComboItem("6x MSAA");			
 	aaLevelComboBox->setPosition(label2->getPosition().x, label2->getPosition().y+18);
 
-	label2 = new ScreenLabel(L"Anisotropic filtering:", fontSize, fontName, Label::ANTIALIAS_FULL);
+	label2 = new ScreenLabel(L"Texture filtering mode:", fontSize, fontName, Label::ANTIALIAS_FULL);
 	mainSettingsWindow->addChild(label2);
 	label2->setPosition(padding, defaultHeightInput->getPosition().y+30);		
 	
-	afLevelComboBox = new UIComboBox(globalMenu, 250);		
+	texFilteringComboBox = new UIComboBox(globalMenu, 280);		
+	texFilteringComboBox->addComboItem("Nearest Neighbor");
+	texFilteringComboBox->addComboItem("Linear");
+	texFilteringComboBox->setPosition(label2->getPosition().x, label2->getPosition().y+18);
+	
+
+	label2 = new ScreenLabel(L"Anisotropic filtering:", fontSize, fontName, Label::ANTIALIAS_FULL);
+	mainSettingsWindow->addChild(label2);
+	label2->setPosition(padding, texFilteringComboBox->getPosition().y+30);		
+	
+	afLevelComboBox = new UIComboBox(globalMenu, 280);		
 	afLevelComboBox->addComboItem("No Anisotropic Filtering");
 	afLevelComboBox->addComboItem("1x Anisotropic Filtering");
 	afLevelComboBox->addComboItem("2x Anisotropic Filtering");
@@ -213,7 +223,7 @@ PolycodeProjectEditor::PolycodeProjectEditor(PolycodeProjectManager *projectMana
 	framerateInput->setNumberOnly(true);
 
 	vSyncCheckBox = new UICheckBox("V-Sync", false);
-	vSyncCheckBox->setPosition(padding, framerateInput->getPosition().y+framerateInput->getHeight()+10);
+	vSyncCheckBox->setPosition(label2->getPosition().x + 80, label2->getPosition().y+18);
 	mainSettingsWindow->addChild(vSyncCheckBox);
 	
 	label2 = new ScreenLabel(L"STARTUP OPTIONS", 22, "section", Label::ANTIALIAS_FULL);	
@@ -233,7 +243,7 @@ PolycodeProjectEditor::PolycodeProjectEditor(PolycodeProjectManager *projectMana
 
 	mainSettingsWindow->addChild(afLevelComboBox);			
 	mainSettingsWindow->addChild(aaLevelComboBox);		
-
+	mainSettingsWindow->addChild(texFilteringComboBox);	
 
 	label2 = new ScreenLabel(L"Background color:", fontSize, fontName, Label::ANTIALIAS_FULL);
 	mainSettingsWindow->addChild(label2);
@@ -328,6 +338,12 @@ bool PolycodeProjectEditor::openFile(OSFileEntry filePath) {
 	afLevelComboBox->setSelectedIndex(afMap[associatedProject->data.anisotropy]);
 	framerateInput->setText(String::IntToString(associatedProject->data.frameRate));	
 
+	if(associatedProject->data.filteringMode == "nearest") {
+		texFilteringComboBox->setSelectedIndex(0);
+	} else {
+		texFilteringComboBox->setSelectedIndex(1);	
+	}
+
 	for(int i=0; i < associatedProject->data.fonts.size(); i++) {
 		ProjectFontData fontData = associatedProject->data.fonts[i];
 
@@ -396,11 +412,12 @@ void PolycodeProjectEditor::saveFile() {
 		ProjectFontData fontData = ProjectFontData(fontEntries[j]->fontNameInput->getText(), fontEntries[j]->fontPath);
 		associatedProject->data.fonts.push_back(fontData);
 	}
-
 		
 	unsigned int afMap[6] = {0,1,2,4,8,16};
 	unsigned int aaMap[4] = {0,2,4,6};
+	String filteringMap[2] = {"nearest", "linear"};
 		
+	associatedProject->data.filteringMode = filteringMap[texFilteringComboBox->getSelectedIndex()];				
 	associatedProject->data.aaLevel = aaMap[aaLevelComboBox->getSelectedIndex()];
 	associatedProject->data.anisotropy = afMap[afLevelComboBox->getSelectedIndex()];
 	associatedProject->data.vSync = vSyncCheckBox->isChecked();

+ 31 - 3
Player/Contents/Source/PolycodePlayer.cpp

@@ -129,7 +129,7 @@ static void dumpstack (lua_State *L) {
 		defaultPath.append(module);
 		
 		const char* fullPath = module.c_str();		
-		Logger::log("Loading custom class: %s\n", module.c_str());
+//		Logger::log("Loading custom class: %s\n", module.c_str());
 		OSFILE *inFile = OSBasics::open(module, "r");	
 		
 		if(!inFile) {
@@ -255,7 +255,7 @@ static void dumpstack (lua_State *L) {
 		
 		PolycodePlayer *player = (PolycodePlayer*)CoreServices::getInstance()->getCore()->getUserPointer();					
 			
-		Logger::log("Error status: %d\n", status);
+//		Logger::log("Error status: %d\n", status);
 		if (status) {		
 		
 			std::vector<BackTraceEntry> backTrace;
@@ -472,6 +472,8 @@ void PolycodePlayer::loadFile(const char *fileName) {
 	Number green = 0.2f;
 	Number blue = 0.2f;
 	
+	String textureFiltering = "linear";
+	
 	frameRate = 60;
 	
 	Object configFile;
@@ -529,7 +531,12 @@ void PolycodePlayer::loadFile(const char *fileName) {
 		}		
 		if(configFile.root["fullScreen"]) {
 			fullScreen = configFile.root["fullScreen"]->boolVal;
+		}				
+		if(configFile.root["textureFiltering"]) {
+			textureFiltering = configFile.root["textureFiltering"]->stringVal;
 		}		
+	
+		
 		if(configFile.root["backgroundColor"]) {
 			ObjectEntry *color = configFile.root["backgroundColor"];
 			if((*color)["red"] && (*color)["green"] && (*color)["blue"]) {
@@ -539,6 +546,21 @@ void PolycodePlayer::loadFile(const char *fileName) {
 				
 			}			
 		}
+		
+		ObjectEntry *fonts = configFile.root["fonts"];
+		if(fonts) {
+			for(int i=0; i < fonts->length; i++) {			
+				ObjectEntry *fontName = (*(*fonts)[i])["name"];				
+				ObjectEntry *fontPath = (*(*fonts)[i])["path"];
+				
+				if(fontName && fontPath) {
+					printf("REGISTERING FONT %s %s\n", fontName->stringVal.c_str(), fontPath->stringVal.c_str());
+					CoreServices::getInstance()->getFontManager()->registerFont(fontName->stringVal, fontPath->stringVal);
+				}
+
+			}
+		}
+		
 		ObjectEntry *modules = configFile.root["modules"];			
 		if(modules) {
 			for(int i=0; i < modules->length; i++) {			
@@ -629,7 +651,13 @@ void PolycodePlayer::loadFile(const char *fileName) {
 	core->setUserPointer(this);
 	//core->addEventListener(this, Core::EVENT_CORE_RESIZE);
 	core->setVideoMode(xRes, yRes, fullScreen, false, 0, aaLevel);
-		
+	
+	if(textureFiltering == "nearest") {
+		CoreServices::getInstance()->getRenderer()->setTextureFilteringMode(Renderer::TEX_FILTERING_NEAREST);
+	} else {
+		CoreServices::getInstance()->getRenderer()->setTextureFilteringMode(Renderer::TEX_FILTERING_LINEAR);
+	}
+				
 	CoreServices::getInstance()->getResourceManager()->addArchive("default.pak");
 	CoreServices::getInstance()->getResourceManager()->addDirResource("default", false);
 

+ 12 - 1
Tools/Contents/polybuild/Source/polybuild.cpp

@@ -260,6 +260,7 @@ int main(int argc, char **argv) {
 	float backgroundColorR = 0.2;
 	float backgroundColorG = 0.2;
 	float backgroundColorB = 0.2;
+	String textureFiltering = "linear";
 
 	if(configFile.root["entryPoint"]) {
 		printf("Entry point: %s\n", configFile.root["entryPoint"]->stringVal.c_str());
@@ -292,6 +293,11 @@ int main(int argc, char **argv) {
 		frameRate = configFile.root["frameRate"]->intVal;
 	}
 
+	if(configFile.root["textureFiltering"]) {
+		printf("Filtering mode: %s\n", configFile.root["textureFiltering"]->stringVal.c_str());
+		textureFiltering = configFile.root["textureFiltering"]->stringVal;
+	}
+
 	if(configFile.root["antiAliasingLevel"]) {
 		printf("Anti-aliasing level: %d\n", configFile.root["antiAliasingLevel"]->intVal);
 		antiAliasingLevel = configFile.root["antiAliasingLevel"]->intVal;
@@ -330,7 +336,8 @@ int main(int argc, char **argv) {
 	runInfo.root.addChild("frameRate", frameRate);
 	runInfo.root.addChild("antiAliasingLevel", antiAliasingLevel);
 	runInfo.root.addChild("fullScreen", fullScreen);
-	
+	runInfo.root.addChild("textureFiltering", String(textureFiltering));
+		
 	ObjectEntry *color = runInfo.root.addChild("backgroundColor");
 	color->addChild("red", backgroundColorR);
 	color->addChild("green", backgroundColorG);
@@ -338,6 +345,10 @@ int main(int argc, char **argv) {
 
 	addFileToZip(z, entryPoint, entryPoint, false);
 
+	if(configFile.root["fonts"]) {
+		runInfo.root.addChild(configFile.root["fonts"]);
+	}
+	
 	if(configFile.root["modules"]) {
 #ifdef _WINDOWS
 		String modulesPath = installPath + "Modules\\";