diff --git a/internal/graphicsdriver/opengl/context_desktop.go b/internal/graphicsdriver/opengl/context_desktop.go index b412eb39c..4397efa26 100644 --- a/internal/graphicsdriver/opengl/context_desktop.go +++ b/internal/graphicsdriver/opengl/context_desktop.go @@ -140,14 +140,15 @@ func (c *context) newTexture(width, height int) (textureNative, error) { if t <= 0 { return 0, errors.New("opengl: creating texture failed") } - gl.PixelStorei(gl.UNPACK_ALIGNMENT, 4) texture := textureNative(t) - c.bindTexture(texture) + gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST) gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST) gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE) gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE) + + gl.PixelStorei(gl.UNPACK_ALIGNMENT, 4) // If data is nil, this just allocates memory and the content is undefined. // https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glTexImage2D.xhtml gl.TexImage2D(gl.TEXTURE_2D, 0, gl.RGBA, int32(width), int32(height), 0, gl.RGBA, gl.UNSIGNED_BYTE, nil) diff --git a/internal/graphicsdriver/opengl/context_js.go b/internal/graphicsdriver/opengl/context_js.go index 803ea3d51..23f51f925 100644 --- a/internal/graphicsdriver/opengl/context_js.go +++ b/internal/graphicsdriver/opengl/context_js.go @@ -167,7 +167,6 @@ func (c *context) newTexture(width, height int) (textureNative, error) { if !t.Truthy() { return textureNative(js.Null()), errors.New("opengl: glGenTexture failed") } - gl.pixelStorei.Invoke(gles.UNPACK_ALIGNMENT, 4) c.bindTexture(textureNative(t)) gl.texParameteri.Invoke(gles.TEXTURE_2D, gles.TEXTURE_MAG_FILTER, gles.NEAREST) @@ -175,6 +174,7 @@ func (c *context) newTexture(width, height int) (textureNative, error) { gl.texParameteri.Invoke(gles.TEXTURE_2D, gles.TEXTURE_WRAP_S, gles.CLAMP_TO_EDGE) gl.texParameteri.Invoke(gles.TEXTURE_2D, gles.TEXTURE_WRAP_T, gles.CLAMP_TO_EDGE) + gl.pixelStorei.Invoke(gles.UNPACK_ALIGNMENT, 4) // Firefox warns the usage of textures without specifying pixels (#629) // // Error: WebGL warning: drawElements: This operation requires zeroing texture data. This is slow. diff --git a/internal/graphicsdriver/opengl/context_mobile.go b/internal/graphicsdriver/opengl/context_mobile.go index 7188dced3..2640e3f8b 100644 --- a/internal/graphicsdriver/opengl/context_mobile.go +++ b/internal/graphicsdriver/opengl/context_mobile.go @@ -127,13 +127,13 @@ func (c *context) newTexture(width, height int) (textureNative, error) { if t <= 0 { return 0, errors.New("opengl: creating texture failed") } - c.ctx.PixelStorei(gles.UNPACK_ALIGNMENT, 4) c.bindTexture(textureNative(t)) c.ctx.TexParameteri(gles.TEXTURE_2D, gles.TEXTURE_MAG_FILTER, gles.NEAREST) c.ctx.TexParameteri(gles.TEXTURE_2D, gles.TEXTURE_MIN_FILTER, gles.NEAREST) c.ctx.TexParameteri(gles.TEXTURE_2D, gles.TEXTURE_WRAP_S, gles.CLAMP_TO_EDGE) c.ctx.TexParameteri(gles.TEXTURE_2D, gles.TEXTURE_WRAP_T, gles.CLAMP_TO_EDGE) + c.ctx.PixelStorei(gles.UNPACK_ALIGNMENT, 4) c.ctx.TexImage2D(gles.TEXTURE_2D, 0, gles.RGBA, int32(width), int32(height), gles.RGBA, gles.UNSIGNED_BYTE, nil) return textureNative(t), nil