This repository has been archived by the owner on Feb 25, 2023. It is now read-only.
/
texturearray1d.go
90 lines (72 loc) · 2.42 KB
/
texturearray1d.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
// Copyright (c) 2013-2018 Laurent Moussault. All rights reserved.
// Licensed under a simplified BSD license (see LICENSE file).
package gl
import (
"image"
)
////////////////////////////////////////////////////////////////////////////////
/*
#include "glad.h"
static inline GLuint NewTextureArray1D(GLsizei levels, GLenum format, GLsizei width, GLsizei height) {
GLuint t;
glCreateTextures(GL_TEXTURE_1D_ARRAY, 1, &t);
glTextureStorage2D(t, levels, format, width, height);
return t;
}
static inline void TextureArray1DSubImage(
GLuint texture,
GLint level,
GLint xoffset,
GLint yoffset,
GLsizei width,
GLsizei height,
GLenum format,
GLenum type,
const void *pixels
) {
glTextureSubImage2D(texture, level, xoffset, yoffset, width, height, format, type, pixels);
}
static inline void TextureGenerateMipmap(GLuint texture) {
glGenerateTextureMipmap(texture);
}
static inline void BindTextureUnit(GLuint unit, GLuint texture) {
glBindTextureUnit(unit, texture);
}
static inline void DeleteTexture(GLuint texture) {
glDeleteTextures(1, &texture);
}
*/
import "C"
////////////////////////////////////////////////////////////////////////////////
// A TextureArray1D is an array of one-dimensional textures.
type TextureArray1D struct {
object C.GLuint
format TextureFormat
}
// NewTextureArray1D returns a new array of one-dimensional textures.
func NewTextureArray1D(levels int32, f TextureFormat, width int32, count int32) TextureArray1D {
var t TextureArray1D
t.format = f
t.object = C.NewTextureArray1D(C.GLsizei(levels), C.GLenum(f), C.GLsizei(width), C.GLsizei(count))
//TODO: error handling?
return t
}
// SubImage loads an image into a texture at a specific position offset, index
// and mipmap level.
func (t *TextureArray1D) SubImage(level int32, ox int32, index int32, img image.Image) {
p, pf, pt := pointerFormatAndTypeOf(img)
C.TextureArray1DSubImage(t.object, C.GLint(level), C.GLint(ox), C.GLint(index), C.GLsizei(img.Bounds().Dx()), C.GLsizei(img.Bounds().Dy()), pf, pt, p)
}
// GenerateMipmap generates mipmaps for the texture.
func (t *TextureArray1D) GenerateMipmap() {
C.TextureGenerateMipmap(t.object)
}
// Bind to a texture unit.
func (t *TextureArray1D) Bind(index uint32) {
C.BindTextureUnit(C.GLuint(index), t.object)
}
// Delete frees the texture
func (t *TextureArray1D) Delete() {
C.DeleteTexture(t.object)
}
////////////////////////////////////////////////////////////////////////////////