func (p *glParams) renderUpdateTexture(image, x, y, w, h int, data []byte) error { tex := p.context.findTexture(image) if tex == nil { return errors.New("invalid texture in GLParams.updateTexture") } p.context.bindTexture(&tex.tex) gl.PixelStorei(gl.UNPACK_ALIGNMENT, 1) if tex.texType == nvgTextureRGBA { data = data[y*tex.width*4:] } else { data = data[y*tex.width:] } x = 0 w = tex.width if tex.texType == nvgTextureRGBA { gl.TexSubImage2D(gl.TEXTURE_2D, 0, x, y, w, h, gl.RGBA, gl.UNSIGNED_BYTE, data) } else { gl.TexSubImage2D(gl.TEXTURE_2D, 0, x, y, w, h, gl.LUMINANCE, gl.UNSIGNED_BYTE, data) } gl.PixelStorei(gl.UNPACK_ALIGNMENT, 4) p.context.bindTexture(nil) return nil }
func (p *glParams) renderCreateTexture(texType nvgTextureType, w, h int, flags ImageFlags, data []byte) int { if nearestPow2(w) != w || nearestPow2(h) != h { if (flags&ImageRepeatX) != 0 || (flags&ImageRepeatY) != 0 { dumpLog("Repeat X/Y is not supported for non power-of-two textures (%d x %d)\n", w, h) flags &= ^(ImageRepeatY | ImageRepeatX) } if (flags & ImageGenerateMipmaps) != 0 { dumpLog("Mip-maps is not support for non power-of-two textures (%d x %d)\n", w, h) flags &= ^ImageGenerateMipmaps } } tex := p.context.allocTexture() tex.tex = gl.CreateTexture() tex.width = w tex.height = h tex.texType = texType tex.flags = flags p.context.bindTexture(&tex.tex) gl.PixelStorei(gl.UNPACK_ALIGNMENT, 1) if texType == nvgTextureRGBA { data = prepareTextureBuffer(data, w, h, 4) gl.TexImage2D(gl.TEXTURE_2D, 0, w, h, gl.RGBA, gl.UNSIGNED_BYTE, data) } else { data = prepareTextureBuffer(data, w, h, 1) gl.TexImage2D(gl.TEXTURE_2D, 0, w, h, gl.LUMINANCE, gl.UNSIGNED_BYTE, data) } if (flags & ImageGenerateMipmaps) != 0 { gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR_MIPMAP_LINEAR) } else { gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR) } gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR) if (flags & ImageRepeatX) != 0 { gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.REPEAT) } else { gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE) } if (flags & ImageRepeatY) != 0 { gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.REPEAT) } else { gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE) } gl.PixelStorei(gl.UNPACK_ALIGNMENT, 4) if (flags & ImageGenerateMipmaps) != 0 { gl.GenerateMipmap(gl.TEXTURE_2D) } p.context.checkError("create tex") p.context.bindTexture(&gl.Texture{}) return tex.id }