graphicsdriver/opengl: Refactoring: Remove dataType

This commit is contained in:
Hajime Hoshi 2020-11-21 23:14:43 +09:00
parent c9060d2fa8
commit 8dba7b7722
7 changed files with 16 additions and 37 deletions

View File

@ -81,8 +81,6 @@ func getProgramID(p program) programID {
const ( const (
vertexShader = shaderType(gl.VERTEX_SHADER) vertexShader = shaderType(gl.VERTEX_SHADER)
fragmentShader = shaderType(gl.FRAGMENT_SHADER) fragmentShader = shaderType(gl.FRAGMENT_SHADER)
short = dataType(gl.SHORT)
float = dataType(gl.FLOAT)
zero = operation(gl.ZERO) zero = operation(gl.ZERO)
one = operation(gl.ONE) one = operation(gl.ONE)
@ -371,8 +369,8 @@ func (c *context) uniformFloats(p program, location string, v []float32, typ sha
return true return true
} }
func (c *context) vertexAttribPointer(p program, index int, size int, dataType dataType, stride int, offset int) { func (c *context) vertexAttribPointer(p program, index int, size int, stride int, offset int) {
gl.VertexAttribPointer(uint32(index), int32(size), uint32(dataType), false, int32(stride), uintptr(offset)) gl.VertexAttribPointer(uint32(index), int32(size), gl.FLOAT, false, int32(stride), uintptr(offset))
} }
func (c *context) enableVertexAttribArray(p program, index int) { func (c *context) enableVertexAttribArray(p program, index int) {

View File

@ -76,8 +76,6 @@ func getProgramID(p program) programID {
const ( const (
vertexShader = shaderType(gles.VERTEX_SHADER) vertexShader = shaderType(gles.VERTEX_SHADER)
fragmentShader = shaderType(gles.FRAGMENT_SHADER) fragmentShader = shaderType(gles.FRAGMENT_SHADER)
short = dataType(gles.SHORT)
float = dataType(gles.FLOAT)
zero = operation(gles.ZERO) zero = operation(gles.ZERO)
one = operation(gles.ONE) one = operation(gles.ONE)
@ -407,9 +405,9 @@ func (c *context) uniformFloats(p program, location string, v []float32, typ sha
return true return true
} }
func (c *context) vertexAttribPointer(p program, index int, size int, dataType dataType, stride int, offset int) { func (c *context) vertexAttribPointer(p program, index int, size int, stride int, offset int) {
gl := c.gl gl := c.gl
gl.Call("vertexAttribPointer", index, size, int(dataType), false, stride, offset) gl.Call("vertexAttribPointer", index, size, gles.FLOAT, false, stride, offset)
} }
func (c *context) enableVertexAttribArray(p program, index int) { func (c *context) enableVertexAttribArray(p program, index int) {

View File

@ -79,8 +79,6 @@ func getProgramID(p program) programID {
const ( const (
vertexShader = shaderType(gles.VERTEX_SHADER) vertexShader = shaderType(gles.VERTEX_SHADER)
fragmentShader = shaderType(gles.FRAGMENT_SHADER) fragmentShader = shaderType(gles.FRAGMENT_SHADER)
short = dataType(gles.SHORT)
float = dataType(gles.FLOAT)
zero = operation(gles.ZERO) zero = operation(gles.ZERO)
one = operation(gles.ONE) one = operation(gles.ONE)
@ -340,8 +338,8 @@ func (c *context) uniformFloats(p program, location string, v []float32, typ sha
return true return true
} }
func (c *context) vertexAttribPointer(p program, index int, size int, dataType dataType, stride int, offset int) { func (c *context) vertexAttribPointer(p program, index int, size int, stride int, offset int) {
c.ctx.VertexAttribPointer(uint32(index), int32(size), uint32(dataType), false, int32(stride), offset) c.ctx.VertexAttribPointer(uint32(index), int32(size), gles.FLOAT, false, int32(stride), offset)
} }
func (c *context) enableVertexAttribArray(p program, index int) { func (c *context) enableVertexAttribArray(p program, index int) {

View File

@ -17,8 +17,6 @@ package gl
const ( const (
VERTEX_SHADER = 0x8B31 VERTEX_SHADER = 0x8B31
FRAGMENT_SHADER = 0x8B30 FRAGMENT_SHADER = 0x8B30
SHORT = 0x1402
FLOAT = 0x1406
ZERO = 0 ZERO = 0
ONE = 1 ONE = 1
@ -36,6 +34,7 @@ const (
DYNAMIC_DRAW = 0x88E8 DYNAMIC_DRAW = 0x88E8
ELEMENT_ARRAY_BUFFER = 0x8893 ELEMENT_ARRAY_BUFFER = 0x8893
FALSE = 0 FALSE = 0
FLOAT = 0x1406
FRAMEBUFFER = 0x8D40 FRAMEBUFFER = 0x8D40
FRAMEBUFFER_BINDING = 0x8CA6 FRAMEBUFFER_BINDING = 0x8CA6
FRAMEBUFFER_COMPLETE = 0x8CD5 FRAMEBUFFER_COMPLETE = 0x8CD5
@ -48,6 +47,7 @@ const (
PIXEL_UNPACK_BUFFER = 0x88EC PIXEL_UNPACK_BUFFER = 0x88EC
READ_WRITE = 0x88BA READ_WRITE = 0x88BA
RGBA = 0x1908 RGBA = 0x1908
SHORT = 0x1402
STREAM_DRAW = 0x88E0 STREAM_DRAW = 0x88E0
TEXTURE0 = 0x84C0 TEXTURE0 = 0x84C0
TEXTURE_2D = 0x0DE1 TEXTURE_2D = 0x0DE1

View File

@ -18,8 +18,6 @@ package gles
const ( const (
VERTEX_SHADER = 0x8B31 VERTEX_SHADER = 0x8B31
FRAGMENT_SHADER = 0x8B30 FRAGMENT_SHADER = 0x8B30
SHORT = 0x1402
FLOAT = 0x1406
ZERO = 0 ZERO = 0
ONE = 1 ONE = 1
@ -37,6 +35,7 @@ const (
DYNAMIC_DRAW = 0x88E8 DYNAMIC_DRAW = 0x88E8
ELEMENT_ARRAY_BUFFER = 0x8893 ELEMENT_ARRAY_BUFFER = 0x8893
FALSE = 0 FALSE = 0
FLOAT = 0x1406
FRAMEBUFFER = 0x8D40 FRAMEBUFFER = 0x8D40
FRAMEBUFFER_BINDING = 0x8CA6 FRAMEBUFFER_BINDING = 0x8CA6
FRAMEBUFFER_COMPLETE = 0x8CD5 FRAMEBUFFER_COMPLETE = 0x8CD5
@ -51,6 +50,7 @@ const (
READ_WRITE = 0x88BA READ_WRITE = 0x88BA
RGBA = 0x1908 RGBA = 0x1908
SCISSOR_TEST = 0x0C11 SCISSOR_TEST = 0x0C11
SHORT = 0x1402
STREAM_DRAW = 0x88E0 STREAM_DRAW = 0x88E0
TEXTURE0 = 0x84C0 TEXTURE0 = 0x84C0
TEXTURE_2D = 0x0DE1 TEXTURE_2D = 0x0DE1

View File

@ -23,6 +23,8 @@ import (
"github.com/hajimehoshi/ebiten/v2/internal/web" "github.com/hajimehoshi/ebiten/v2/internal/web"
) )
const floatSizeInBytes = 4
// arrayBufferLayoutPart is a part of an array buffer layout. // arrayBufferLayoutPart is a part of an array buffer layout.
type arrayBufferLayoutPart struct { type arrayBufferLayoutPart struct {
// TODO: This struct should belong to a program and know it. // TODO: This struct should belong to a program and know it.
@ -54,7 +56,7 @@ func (a *arrayBufferLayout) totalBytes() int {
} }
t := 0 t := 0
for _, p := range a.parts { for _, p := range a.parts {
t += float.SizeInBytes() * p.num t += floatSizeInBytes * p.num
} }
a.total = t a.total = t
return a.total return a.total
@ -73,8 +75,8 @@ func (a *arrayBufferLayout) enable(context *context, program program) {
total := a.totalBytes() total := a.totalBytes()
offset := 0 offset := 0
for i, p := range a.parts { for i, p := range a.parts {
context.vertexAttribPointer(program, i, p.num, float, total, offset) context.vertexAttribPointer(program, i, p.num, total, offset)
offset += float.SizeInBytes() * p.num offset += floatSizeInBytes * p.num
} }
} }
@ -106,7 +108,7 @@ var theArrayBufferLayout = arrayBufferLayout{
} }
func init() { func init() {
vertexFloatNum := theArrayBufferLayout.totalBytes() / float.SizeInBytes() vertexFloatNum := theArrayBufferLayout.totalBytes() / floatSizeInBytes
if graphics.VertexFloatNum != vertexFloatNum { if graphics.VertexFloatNum != vertexFloatNum {
panic(fmt.Sprintf("vertex float num must be %d but %d", graphics.VertexFloatNum, vertexFloatNum)) panic(fmt.Sprintf("vertex float num must be %d but %d", graphics.VertexFloatNum, vertexFloatNum))
} }

View File

@ -14,24 +14,7 @@
package opengl package opengl
import (
"fmt"
)
type ( type (
shaderType int shaderType int
operation int operation int
) )
type dataType int
func (d dataType) SizeInBytes() int {
switch d {
case short:
return 2
case float:
return 4
default:
panic(fmt.Sprintf("opengl: invalid data type: %d", d))
}
}