Changeset - r24963:38bc5b49d3a7
[Not reviewed]
master
0 2 0
Michael Lutz - 3 years ago 2021-02-28 09:58:56
michi@icosahedron.de
Fix #8763: [OpenGL] Cursor sprite origin can be negative.
2 files changed with 2 insertions and 2 deletions:
0 comments (0 inline, 0 general)
src/video/opengl.cpp
Show inline comments
 
@@ -1196,49 +1196,49 @@ void OpenGLBackend::ReleaseAnimBuffer(co
 

	
 
	OpenGLSprite *gl_sprite = (OpenGLSprite *)dest_sprite->data;
 
	new (gl_sprite) OpenGLSprite(sprite->width, sprite->height, sprite->type == ST_FONT ? 1 : ZOOM_LVL_COUNT, sprite->colours);
 

	
 
	/* Upload texture data. */
 
	for (int i = 0; i < (sprite->type == ST_FONT ? 1 : ZOOM_LVL_COUNT); i++) {
 
		gl_sprite->Update(sprite[i].width, sprite[i].height, i, sprite[i].data);
 
	}
 

	
 
	dest_sprite->height = sprite->height;
 
	dest_sprite->width  = sprite->width;
 
	dest_sprite->x_offs = sprite->x_offs;
 
	dest_sprite->y_offs = sprite->y_offs;
 

	
 
	return dest_sprite;
 
}
 

	
 
/**
 
 * Render a sprite to the back buffer.
 
 * @param gl_sprite Sprite to render.
 
 * @param x X position of the sprite.
 
 * @param y Y position of the sprite.
 
 * @param zoom Zoom level to use.
 
 */
 
void OpenGLBackend::RenderOglSprite(OpenGLSprite *gl_sprite, PaletteID pal, uint x, uint y, ZoomLevel zoom)
 
void OpenGLBackend::RenderOglSprite(OpenGLSprite *gl_sprite, PaletteID pal, int x, int y, ZoomLevel zoom)
 
{
 
	/* Set textures. */
 
	bool rgb = gl_sprite->BindTextures();
 
	_glActiveTexture(GL_TEXTURE0 + 1);
 
	_glBindTexture(GL_TEXTURE_1D, this->pal_texture);
 

	
 
	/* Set palette remap. */
 
	_glActiveTexture(GL_TEXTURE0 + 3);
 
	if (pal != PAL_NONE) {
 
		_glBindTexture(GL_TEXTURE_1D, OpenGLSprite::pal_tex);
 
		if (pal != this->last_sprite_pal) {
 
			/* Different remap palette in use, update texture. */
 
			_glBindBuffer(GL_PIXEL_UNPACK_BUFFER, OpenGLSprite::pal_pbo);
 
			_glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
 

	
 
			_glBufferSubData(GL_PIXEL_UNPACK_BUFFER, 0, 256, GetNonSprite(GB(pal, 0, PALETTE_WIDTH), ST_RECOLOUR) + 1);
 
			_glTexSubImage1D(GL_TEXTURE_1D, 0, 0, 256, GL_RED, GL_UNSIGNED_BYTE, 0);
 

	
 
			_glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
 

	
 
			this->last_sprite_pal = pal;
 
		}
 
	} else {
 
		_glBindTexture(GL_TEXTURE_1D, OpenGLSprite::pal_identity);
src/video/opengl.h
Show inline comments
 
@@ -49,49 +49,49 @@ private:
 
	GLuint anim_texture; ///< Texture handle for the animation buffer texture.
 

	
 
	GLuint remap_program;    ///< Shader program for blending and rendering a RGBA + remap texture.
 
	GLint  remap_sprite_loc; ///< Uniform location for sprite parameters.
 
	GLint  remap_screen_loc; ///< Uniform location for screen size;
 
	GLint  remap_zoom_loc;   ///< Uniform location for sprite zoom;
 
	GLint  remap_rgb_loc;    ///< Uniform location for RGB mode flag;
 

	
 
	GLuint sprite_program;    ///< Shader program for blending and rendering a sprite to the video buffer.
 
	GLint  sprite_sprite_loc; ///< Uniform location for sprite parameters.
 
	GLint  sprite_screen_loc; ///< Uniform location for screen size;
 
	GLint  sprite_zoom_loc;   ///< Uniform location for sprite zoom;
 
	GLint  sprite_rgb_loc;    ///< Uniform location for RGB mode flag;
 
	GLint  sprite_crash_loc;  ///< Uniform location for crash remap mode flag;
 

	
 
	LRUCache<SpriteID, Sprite> cursor_cache;   ///< Cache of encoded cursor sprites.
 
	PaletteID last_sprite_pal = (PaletteID)-1; ///< Last uploaded remap palette.
 

	
 
	OpenGLBackend();
 
	~OpenGLBackend();
 

	
 
	const char *Init();
 
	bool InitShaders();
 

	
 
	void RenderOglSprite(OpenGLSprite *gl_sprite, PaletteID pal, uint x, uint y, ZoomLevel zoom);
 
	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 void Destroy();
 

	
 
	void PrepareContext();
 

	
 
	void UpdatePalette(const Colour *pal, uint first, uint length);
 
	bool Resize(int w, int h, bool force = false);
 
	void Paint();
 

	
 
	void DrawMouseCursor();
 
	void ClearCursorCache();
 

	
 
	void *GetVideoBuffer();
 
	uint8 *GetAnimBuffer();
 
	void ReleaseVideoBuffer(const Rect &update_rect);
 
	void ReleaseAnimBuffer(const Rect &update_rect);
 

	
0 comments (0 inline, 0 general)