internal/graphicsdriver/opengl: Refactoring: Reorder functions

glPixelStorei affects the result of glTexImage2D. This change makes
this fact more explicit.
This commit is contained in:
Hajime Hoshi 2021-07-03 02:09:44 +09:00
parent 66be53804d
commit 269ea7c489
3 changed files with 5 additions and 4 deletions

View File

@ -140,14 +140,15 @@ func (c *context) newTexture(width, height int) (textureNative, error) {
if t <= 0 { if t <= 0 {
return 0, errors.New("opengl: creating texture failed") return 0, errors.New("opengl: creating texture failed")
} }
gl.PixelStorei(gl.UNPACK_ALIGNMENT, 4)
texture := textureNative(t) texture := textureNative(t)
c.bindTexture(texture) c.bindTexture(texture)
gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST) 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_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_S, gl.CLAMP_TO_EDGE)
gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, 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. // If data is nil, this just allocates memory and the content is undefined.
// https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glTexImage2D.xhtml // 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) gl.TexImage2D(gl.TEXTURE_2D, 0, gl.RGBA, int32(width), int32(height), 0, gl.RGBA, gl.UNSIGNED_BYTE, nil)

View File

@ -167,7 +167,6 @@ func (c *context) newTexture(width, height int) (textureNative, error) {
if !t.Truthy() { if !t.Truthy() {
return textureNative(js.Null()), errors.New("opengl: glGenTexture failed") return textureNative(js.Null()), errors.New("opengl: glGenTexture failed")
} }
gl.pixelStorei.Invoke(gles.UNPACK_ALIGNMENT, 4)
c.bindTexture(textureNative(t)) c.bindTexture(textureNative(t))
gl.texParameteri.Invoke(gles.TEXTURE_2D, gles.TEXTURE_MAG_FILTER, gles.NEAREST) 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_S, gles.CLAMP_TO_EDGE)
gl.texParameteri.Invoke(gles.TEXTURE_2D, gles.TEXTURE_WRAP_T, 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) // Firefox warns the usage of textures without specifying pixels (#629)
// //
// Error: WebGL warning: drawElements: This operation requires zeroing texture data. This is slow. // Error: WebGL warning: drawElements: This operation requires zeroing texture data. This is slow.

View File

@ -127,13 +127,13 @@ func (c *context) newTexture(width, height int) (textureNative, error) {
if t <= 0 { if t <= 0 {
return 0, errors.New("opengl: creating texture failed") return 0, errors.New("opengl: creating texture failed")
} }
c.ctx.PixelStorei(gles.UNPACK_ALIGNMENT, 4)
c.bindTexture(textureNative(t)) c.bindTexture(textureNative(t))
c.ctx.TexParameteri(gles.TEXTURE_2D, gles.TEXTURE_MAG_FILTER, gles.NEAREST) 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_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_S, gles.CLAMP_TO_EDGE)
c.ctx.TexParameteri(gles.TEXTURE_2D, gles.TEXTURE_WRAP_T, 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) c.ctx.TexImage2D(gles.TEXTURE_2D, 0, gles.RGBA, int32(width), int32(height), gles.RGBA, gles.UNSIGNED_BYTE, nil)
return textureNative(t), nil return textureNative(t), nil