Browse Source

Still try to fix opengl backend
- no success
+ make backend selection configurable

AlexVinS 11 years ago
parent
commit
3db7fb4f63
3 changed files with 22 additions and 14 deletions
  1. 11 8
      client/CMT.cpp
  2. 5 5
      client/gui/SDL_Extensions.cpp
  3. 6 1
      config/schemas/settings.json

+ 11 - 8
client/CMT.cpp

@@ -70,7 +70,7 @@ CGuiHandler GH;
 static CClient *client=nullptr;
 
 #ifndef VCMI_SDL1
-int preferedDriverIndex = -1;
+int preferredDriverIndex = -1;
 SDL_Window * mainWindow = nullptr;
 SDL_Renderer * mainRenderer = nullptr;
 SDL_Texture * screenTexture = nullptr;
@@ -361,6 +361,7 @@ int main(int argc, char** argv)
 		
 		#ifndef VCMI_SDL1
 		int driversCount = SDL_GetNumRenderDrivers();
+		std::string preferredDriverName = video["driver"].String();
 		
 		logGlobal->infoStream() << "Found " << driversCount << " render drivers";
 		
@@ -371,12 +372,13 @@ int main(int argc, char** argv)
 			
 			std::string driverName(info.name);
 			
+						
 			logGlobal->infoStream() << "\t" << driverName;
 			
-			if(driverName == "opengl")
+			if(!preferredDriverName.empty() && driverName == preferredDriverName)
 			{
-				preferedDriverIndex = it;
-				logGlobal->infoStream() << "\t\t will select this";
+				preferredDriverIndex = it;
+				logGlobal->infoStream() << "\t\twill select this";
 			}					
 		}			
 		#endif // VCMI_SDL1	
@@ -874,11 +876,12 @@ static bool recreateWindow(int w, int h, int bpp, bool fullscreen)
 	if(fullscreen)
 	{
 		//in full-screen mode always use desktop resolution
-		mainWindow = SDL_CreateWindow(NAME.c_str(), SDL_WINDOWPOS_UNDEFINED,SDL_WINDOWPOS_UNDEFINED, 0, 0, SDL_WINDOW_FULLSCREEN_DESKTOP | SDL_WINDOW_OPENGL);
+		mainWindow = SDL_CreateWindow(NAME.c_str(), SDL_WINDOWPOS_UNDEFINED,SDL_WINDOWPOS_UNDEFINED, 0, 0, SDL_WINDOW_FULLSCREEN_DESKTOP);
+		SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "linear");
 	}
 	else
 	{
-		mainWindow = SDL_CreateWindow(NAME.c_str(), SDL_WINDOWPOS_CENTERED,SDL_WINDOWPOS_CENTERED, w, h, SDL_WINDOW_OPENGL);
+		mainWindow = SDL_CreateWindow(NAME.c_str(), SDL_WINDOWPOS_CENTERED,SDL_WINDOWPOS_CENTERED, w, h, 0);
 	}
 	
 	
@@ -889,8 +892,8 @@ static bool recreateWindow(int w, int h, int bpp, bool fullscreen)
 	}
 	
 	
-	//create first available renderer if "opengl" not found. Use no flags, so HW accelerated will be preferred but SW renderer also will possible
-	mainRenderer = SDL_CreateRenderer(mainWindow,preferedDriverIndex,0);
+	//create first available renderer if preferred not set. Use no flags, so HW accelerated will be preferred but SW renderer also will possible
+	mainRenderer = SDL_CreateRenderer(mainWindow,preferredDriverIndex,0);
 
 	if(nullptr == mainRenderer)
 	{

+ 5 - 5
client/gui/SDL_Extensions.cpp

@@ -490,12 +490,12 @@ Uint32 CSDL_Ext::colorToUint32(const SDL_Color * color)
 
 void CSDL_Ext::update(SDL_Surface * what)
 {
-	#ifdef VCMI_SDL1
-	if(what)
+//	#ifdef VCMI_SDL1
+//	if(what)
 		SDL_UpdateRect(what, 0, 0, what->w, what->h);
-	#else
-		SDL_UpdateTexture(screenTexture, NULL, what->pixels, what->pitch);
-	#endif
+//	#else
+//		SDL_UpdateTexture(screenTexture, NULL, what->pixels, what->pitch);
+//	#endif
 }
 void CSDL_Ext::drawBorder(SDL_Surface * sur, int x, int y, int w, int h, const int3 &color)
 {

+ 6 - 1
config/schemas/settings.json

@@ -49,7 +49,7 @@
 			"type" : "object",
 			"additionalProperties" : false,
 			"default": {},
-			"required" : [ "screenRes", "bitsPerPixel", "fullscreen", "spellbookAnimation" ],
+			"required" : [ "screenRes", "bitsPerPixel", "fullscreen", "spellbookAnimation","driver"],
 			"properties" : {
 				"screenRes" : {
 					"type" : "object",
@@ -73,6 +73,11 @@
 					"type" : "boolean",
 					"default" : true
 				},
+				"driver":{
+					"type" : "string",
+					"default" : "opengl",
+					"description" : "preferred graphics backend driver name for SDL2"
+				}
 			}
 		},
 		"adventure" : {