mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
graphicsdriver/opengl: Refactoring: Remove dataType
This commit is contained in:
parent
c9060d2fa8
commit
8dba7b7722
@ -81,8 +81,6 @@ func getProgramID(p program) programID {
|
||||
const (
|
||||
vertexShader = shaderType(gl.VERTEX_SHADER)
|
||||
fragmentShader = shaderType(gl.FRAGMENT_SHADER)
|
||||
short = dataType(gl.SHORT)
|
||||
float = dataType(gl.FLOAT)
|
||||
|
||||
zero = operation(gl.ZERO)
|
||||
one = operation(gl.ONE)
|
||||
@ -371,8 +369,8 @@ func (c *context) uniformFloats(p program, location string, v []float32, typ sha
|
||||
return true
|
||||
}
|
||||
|
||||
func (c *context) vertexAttribPointer(p program, index int, size int, dataType dataType, stride int, offset int) {
|
||||
gl.VertexAttribPointer(uint32(index), int32(size), uint32(dataType), false, int32(stride), uintptr(offset))
|
||||
func (c *context) vertexAttribPointer(p program, index int, size int, stride int, offset int) {
|
||||
gl.VertexAttribPointer(uint32(index), int32(size), gl.FLOAT, false, int32(stride), uintptr(offset))
|
||||
}
|
||||
|
||||
func (c *context) enableVertexAttribArray(p program, index int) {
|
||||
|
@ -76,8 +76,6 @@ func getProgramID(p program) programID {
|
||||
const (
|
||||
vertexShader = shaderType(gles.VERTEX_SHADER)
|
||||
fragmentShader = shaderType(gles.FRAGMENT_SHADER)
|
||||
short = dataType(gles.SHORT)
|
||||
float = dataType(gles.FLOAT)
|
||||
|
||||
zero = operation(gles.ZERO)
|
||||
one = operation(gles.ONE)
|
||||
@ -407,9 +405,9 @@ func (c *context) uniformFloats(p program, location string, v []float32, typ sha
|
||||
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.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) {
|
||||
|
@ -79,8 +79,6 @@ func getProgramID(p program) programID {
|
||||
const (
|
||||
vertexShader = shaderType(gles.VERTEX_SHADER)
|
||||
fragmentShader = shaderType(gles.FRAGMENT_SHADER)
|
||||
short = dataType(gles.SHORT)
|
||||
float = dataType(gles.FLOAT)
|
||||
|
||||
zero = operation(gles.ZERO)
|
||||
one = operation(gles.ONE)
|
||||
@ -340,8 +338,8 @@ func (c *context) uniformFloats(p program, location string, v []float32, typ sha
|
||||
return true
|
||||
}
|
||||
|
||||
func (c *context) vertexAttribPointer(p program, index int, size int, dataType dataType, stride int, offset int) {
|
||||
c.ctx.VertexAttribPointer(uint32(index), int32(size), uint32(dataType), false, int32(stride), offset)
|
||||
func (c *context) vertexAttribPointer(p program, index int, size int, stride int, offset int) {
|
||||
c.ctx.VertexAttribPointer(uint32(index), int32(size), gles.FLOAT, false, int32(stride), offset)
|
||||
}
|
||||
|
||||
func (c *context) enableVertexAttribArray(p program, index int) {
|
||||
|
@ -17,8 +17,6 @@ package gl
|
||||
const (
|
||||
VERTEX_SHADER = 0x8B31
|
||||
FRAGMENT_SHADER = 0x8B30
|
||||
SHORT = 0x1402
|
||||
FLOAT = 0x1406
|
||||
|
||||
ZERO = 0
|
||||
ONE = 1
|
||||
@ -36,6 +34,7 @@ const (
|
||||
DYNAMIC_DRAW = 0x88E8
|
||||
ELEMENT_ARRAY_BUFFER = 0x8893
|
||||
FALSE = 0
|
||||
FLOAT = 0x1406
|
||||
FRAMEBUFFER = 0x8D40
|
||||
FRAMEBUFFER_BINDING = 0x8CA6
|
||||
FRAMEBUFFER_COMPLETE = 0x8CD5
|
||||
@ -48,6 +47,7 @@ const (
|
||||
PIXEL_UNPACK_BUFFER = 0x88EC
|
||||
READ_WRITE = 0x88BA
|
||||
RGBA = 0x1908
|
||||
SHORT = 0x1402
|
||||
STREAM_DRAW = 0x88E0
|
||||
TEXTURE0 = 0x84C0
|
||||
TEXTURE_2D = 0x0DE1
|
||||
|
@ -18,8 +18,6 @@ package gles
|
||||
const (
|
||||
VERTEX_SHADER = 0x8B31
|
||||
FRAGMENT_SHADER = 0x8B30
|
||||
SHORT = 0x1402
|
||||
FLOAT = 0x1406
|
||||
|
||||
ZERO = 0
|
||||
ONE = 1
|
||||
@ -37,6 +35,7 @@ const (
|
||||
DYNAMIC_DRAW = 0x88E8
|
||||
ELEMENT_ARRAY_BUFFER = 0x8893
|
||||
FALSE = 0
|
||||
FLOAT = 0x1406
|
||||
FRAMEBUFFER = 0x8D40
|
||||
FRAMEBUFFER_BINDING = 0x8CA6
|
||||
FRAMEBUFFER_COMPLETE = 0x8CD5
|
||||
@ -51,6 +50,7 @@ const (
|
||||
READ_WRITE = 0x88BA
|
||||
RGBA = 0x1908
|
||||
SCISSOR_TEST = 0x0C11
|
||||
SHORT = 0x1402
|
||||
STREAM_DRAW = 0x88E0
|
||||
TEXTURE0 = 0x84C0
|
||||
TEXTURE_2D = 0x0DE1
|
||||
|
@ -23,6 +23,8 @@ import (
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/web"
|
||||
)
|
||||
|
||||
const floatSizeInBytes = 4
|
||||
|
||||
// arrayBufferLayoutPart is a part of an array buffer layout.
|
||||
type arrayBufferLayoutPart struct {
|
||||
// TODO: This struct should belong to a program and know it.
|
||||
@ -54,7 +56,7 @@ func (a *arrayBufferLayout) totalBytes() int {
|
||||
}
|
||||
t := 0
|
||||
for _, p := range a.parts {
|
||||
t += float.SizeInBytes() * p.num
|
||||
t += floatSizeInBytes * p.num
|
||||
}
|
||||
a.total = t
|
||||
return a.total
|
||||
@ -73,8 +75,8 @@ func (a *arrayBufferLayout) enable(context *context, program program) {
|
||||
total := a.totalBytes()
|
||||
offset := 0
|
||||
for i, p := range a.parts {
|
||||
context.vertexAttribPointer(program, i, p.num, float, total, offset)
|
||||
offset += float.SizeInBytes() * p.num
|
||||
context.vertexAttribPointer(program, i, p.num, total, offset)
|
||||
offset += floatSizeInBytes * p.num
|
||||
}
|
||||
}
|
||||
|
||||
@ -106,7 +108,7 @@ var theArrayBufferLayout = arrayBufferLayout{
|
||||
}
|
||||
|
||||
func init() {
|
||||
vertexFloatNum := theArrayBufferLayout.totalBytes() / float.SizeInBytes()
|
||||
vertexFloatNum := theArrayBufferLayout.totalBytes() / floatSizeInBytes
|
||||
if graphics.VertexFloatNum != vertexFloatNum {
|
||||
panic(fmt.Sprintf("vertex float num must be %d but %d", graphics.VertexFloatNum, vertexFloatNum))
|
||||
}
|
||||
|
@ -14,24 +14,7 @@
|
||||
|
||||
package opengl
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type (
|
||||
shaderType 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))
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user