Skip to content

Commit 0ff8172

Browse files
author
Elias Naur
committed
gl: add internalFormat to TexImage2D
The OpenGL C function glTexImage2D has the following signature: void glTexImage2D(GLenum target, GLint level, GLint internalFormat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid * data); However, the corresponding Context.TexImage2D method in package gl does not include the internalFormat parameter, and use the format argument instead. That's ok for many texture formats; for example, RGBA textures have both format and internalFormat set to GL_RGBA. But not always. In particular, OpenGL ES 3 allows the use of sRGB encoded textures by specifying GL_SRGB8_ALPHA8 as internalFormat, but keeping GL_RGBA as format. Add the internalFormat to the Context package. This is unfortunately a breaking change, but adding a new function ("glTexImage2D2"?) to Context is too ugly for a parameter that should have been there all along. (Adding a new method to the Context interface is technically also a breaking change, but I don't expect that there are any external implementers of the interface). Change-Id: I12a45a34f604e51cb1be26aed906025ccfac533a Reviewed-on: https://go-review.googlesource.com/133155 Reviewed-by: Hyang-Ah Hana Kim <[email protected]>
1 parent fe88d27 commit 0ff8172

File tree

4 files changed

+7
-7
lines changed

4 files changed

+7
-7
lines changed

exp/gl/glutil/glimage.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ func (p *Images) NewImage(w, h int) *Image {
124124
img.gltex = p.glctx.CreateTexture()
125125

126126
p.glctx.BindTexture(gl.TEXTURE_2D, img.gltex)
127-
p.glctx.TexImage2D(gl.TEXTURE_2D, 0, img.width, img.height, gl.RGBA, gl.UNSIGNED_BYTE, nil)
127+
p.glctx.TexImage2D(gl.TEXTURE_2D, 0, gl.RGBA, img.width, img.height, gl.RGBA, gl.UNSIGNED_BYTE, nil)
128128
p.glctx.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR)
129129
p.glctx.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR)
130130
p.glctx.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE)

gl/gl.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1257,7 +1257,7 @@ func (ctx *context) StencilOpSeparate(face, sfail, dpfail, dppass Enum) {
12571257
})
12581258
}
12591259

1260-
func (ctx *context) TexImage2D(target Enum, level int, width, height int, format Enum, ty Enum, data []byte) {
1260+
func (ctx *context) TexImage2D(target Enum, level int, internalFormat int, width, height int, format Enum, ty Enum, data []byte) {
12611261
// It is common to pass TexImage2D a nil data, indicating that a
12621262
// bound GL buffer is being used as the source. In that case, it
12631263
// is not necessary to block.
@@ -1272,7 +1272,7 @@ func (ctx *context) TexImage2D(target Enum, level int, width, height int, format
12721272
// TODO(crawshaw): GLES3 offset for PIXEL_UNPACK_BUFFER and PIXEL_PACK_BUFFER.
12731273
a0: target.c(),
12741274
a1: uintptr(level),
1275-
a2: uintptr(format),
1275+
a2: uintptr(internalFormat),
12761276
a3: uintptr(width),
12771277
a4: uintptr(height),
12781278
a5: format.c(),

gl/gldebug.go

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gl/interface.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -627,7 +627,7 @@ type Context interface {
627627
// TexImage2D writes a 2D texture image.
628628
//
629629
// http://www.khronos.org/opengles/sdk/docs/man3/html/glTexImage2D.xhtml
630-
TexImage2D(target Enum, level int, width, height int, format Enum, ty Enum, data []byte)
630+
TexImage2D(target Enum, level int, internalFormat int, width, height int, format Enum, ty Enum, data []byte)
631631

632632
// TexSubImage2D writes a subregion of a 2D texture image.
633633
//

0 commit comments

Comments
 (0)