Changeset - r25208:7724a23f8d28
[Not reviewed]
master
0 5 0
Michael Lutz - 3 years ago 2021-04-21 20:06:04
michi@icosahedron.de
Fix: [OpenGL] Check maximum supported texture size against screen resolution.
5 files changed with 15 insertions and 8 deletions:
0 comments (0 inline, 0 general)
src/video/cocoa/cocoa_ogl.mm
Show inline comments
 
@@ -251,13 +251,13 @@ const char *VideoDriver_CocoaOpenGL::All
 
	CGLDestroyPixelFormat(pxfmt);
 

	
 
	if (this->gl_context == nullptr) return "Can't create a rendering context";
 

	
 
	CGLSetCurrentContext(this->gl_context);
 

	
 
	return OpenGLBackend::Create(&GetOGLProcAddressCallback);
 
	return OpenGLBackend::Create(&GetOGLProcAddressCallback, this->GetScreenSize());
 
}
 

	
 
NSView *VideoDriver_CocoaOpenGL::AllocateDrawView()
 
{
 
	return [ [ OTTD_CGLLayerView alloc ] initWithFrame:this->cocoaview.bounds context:this->gl_context ];
 
}
src/video/opengl.cpp
Show inline comments
 
@@ -461,22 +461,23 @@ void SetupDebugOutput()
 
#endif
 
}
 

	
 
/**
 
 * Create and initialize the singleton back-end class.
 
 * @param get_proc Callback to get an OpenGL function from the OS driver.
 
 * @param screen_res Current display resolution.
 
 * @return nullptr on success, error message otherwise.
 
 */
 
/* static */ const char *OpenGLBackend::Create(GetOGLProcAddressProc get_proc)
 
/* static */ const char *OpenGLBackend::Create(GetOGLProcAddressProc get_proc, const Dimension &screen_res)
 
{
 
	if (OpenGLBackend::instance != nullptr) OpenGLBackend::Destroy();
 

	
 
	GetOGLProcAddress = get_proc;
 

	
 
	OpenGLBackend::instance = new OpenGLBackend();
 
	return OpenGLBackend::instance->Init();
 
	return OpenGLBackend::instance->Init(screen_res);
 
}
 

	
 
/**
 
 * Free resources and destroy singleton back-end class.
 
 */
 
/* static */ void OpenGLBackend::Destroy()
 
@@ -518,15 +519,16 @@ OpenGLBackend::~OpenGLBackend()
 
		_glDeleteTextures(1, &this->pal_texture);
 
	}
 
}
 

	
 
/**
 
 * Check for the needed OpenGL functionality and allocate all resources.
 
 * @param screen_res Current display resolution.
 
 * @return Error string or nullptr if successful.
 
 */
 
const char *OpenGLBackend::Init()
 
const char *OpenGLBackend::Init(const Dimension &screen_res)
 
{
 
	if (!BindBasicInfoProcs()) return "OpenGL not supported";
 

	
 
	/* Always query the supported OpenGL version as the current context might have changed. */
 
	const char *ver = (const char *)_glGetString(GL_VERSION);
 
	const char *vend = (const char *)_glGetString(GL_VENDOR);
 
@@ -578,12 +580,17 @@ const char *OpenGLBackend::Init()
 
	if (this->persistent_mapping_supported && !BindPersistentBufferExtensions()) {
 
		DEBUG(driver, 1, "OpenGL claims to support persistent buffer mapping but doesn't export all functions, not using persistent mapping.");
 
		this->persistent_mapping_supported = false;
 
	}
 
	if (this->persistent_mapping_supported) DEBUG(driver, 3, "OpenGL: Using persistent buffer mapping");
 

	
 
	/* Check maximum texture size against screen resolution. */
 
	GLint max_tex_size = 0;
 
	_glGetIntegerv(GL_MAX_TEXTURE_SIZE, &max_tex_size);
 
	if (std::max(screen_res.width, screen_res.height) > (uint)max_tex_size) return "Max supported texture size is too small";
 

	
 
	/* Check available texture units. */
 
	GLint max_tex_units = 0;
 
	_glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &max_tex_units);
 
	if (max_tex_units < 4) return "Not enough simultaneous textures supported";
 

	
 
	DEBUG(driver, 2, "OpenGL shading language version: %s, texture units = %d", (const char *)_glGetString(GL_SHADING_LANGUAGE_VERSION), (int)max_tex_units);
src/video/opengl.h
Show inline comments
 
@@ -71,26 +71,26 @@ private:
 
	Point cursor_sprite_pos[16];         ///< Relative position of individual cursor sprites
 
	uint cursor_sprite_count;            ///< Number of cursor sprites to draw
 

	
 
	OpenGLBackend();
 
	~OpenGLBackend();
 

	
 
	const char *Init();
 
	const char *Init(const Dimension &screen_res);
 
	bool InitShaders();
 

	
 
	void InternalClearCursorCache();
 

	
 
	void RenderOglSprite(OpenGLSprite *gl_sprite, PaletteID pal, int x, int y, ZoomLevel zoom);
 

	
 
public:
 
	/** Get singleton instance of this class. */
 
	static inline OpenGLBackend *Get()
 
	{
 
		return OpenGLBackend::instance;
 
	}
 
	static const char *Create(GetOGLProcAddressProc get_proc);
 
	static const char *Create(GetOGLProcAddressProc get_proc, const Dimension &screen_res);
 
	static void Destroy();
 

	
 
	void PrepareContext();
 

	
 
	void UpdatePalette(const Colour *pal, uint first, uint length);
 
	bool Resize(int w, int h, bool force = false);
src/video/sdl2_opengl_v.cpp
Show inline comments
 
@@ -114,13 +114,13 @@ const char *VideoDriver_SDL_OpenGL::Allo
 

	
 
	this->gl_context = SDL_GL_CreateContext(this->sdl_window);
 
	if (this->gl_context == nullptr) return "SDL2: Can't active GL context";
 

	
 
	ToggleVsync(_video_vsync);
 

	
 
	return OpenGLBackend::Create(&GetOGLProcAddressCallback);
 
	return OpenGLBackend::Create(&GetOGLProcAddressCallback, this->GetScreenSize());
 
}
 

	
 
void VideoDriver_SDL_OpenGL::PopulateSystemSprites()
 
{
 
	OpenGLBackend::Get()->PopulateCursorCache();
 
}
src/video/win32_v.cpp
Show inline comments
 
@@ -1377,13 +1377,13 @@ const char *VideoDriver_Win32OpenGL::All
 
	}
 
	if (!wglMakeCurrent(this->dc, rc)) return "Can't active GL context";
 

	
 
	this->ToggleVsync(_video_vsync);
 

	
 
	this->gl_rc = rc;
 
	return OpenGLBackend::Create(&GetOGLProcAddressCallback);
 
	return OpenGLBackend::Create(&GetOGLProcAddressCallback, this->GetScreenSize());
 
}
 

	
 
bool VideoDriver_Win32OpenGL::ToggleFullscreen(bool full_screen)
 
{
 
	if (_screen.dst_ptr != nullptr) this->ReleaseVideoPointer();
 
	this->DestroyContext();
0 comments (0 inline, 0 general)