mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 18:58:54 +01:00
internal/graphicsdriver/opengl: refactoring: remove usages of graphics.IndicesCount
Updates #2460
This commit is contained in:
parent
4cd98d512e
commit
13d3a0487b
@ -48,7 +48,7 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
IndicesCount = (1 << 16) / 3 * 3 // Adjust num for triangles.
|
IndicesCount = (1 << 16) / 3 * 3 // Adjust num for triangles. TODO: Remove this (#2460).
|
||||||
VertexFloatCount = 8
|
VertexFloatCount = 8
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -113,22 +113,50 @@ type openGLState struct {
|
|||||||
// arrayBuffer is OpenGL's array buffer (vertices data).
|
// arrayBuffer is OpenGL's array buffer (vertices data).
|
||||||
arrayBuffer buffer
|
arrayBuffer buffer
|
||||||
|
|
||||||
|
arrayBufferSizeInBytes int
|
||||||
|
|
||||||
// elementArrayBuffer is OpenGL's element array buffer (indices data).
|
// elementArrayBuffer is OpenGL's element array buffer (indices data).
|
||||||
elementArrayBuffer buffer
|
elementArrayBuffer buffer
|
||||||
|
|
||||||
|
elementArrayBufferSizeInBytes int
|
||||||
|
|
||||||
lastProgram program
|
lastProgram program
|
||||||
lastUniforms map[string][]uint32
|
lastUniforms map[string][]uint32
|
||||||
lastActiveTexture int
|
lastActiveTexture int
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *openGLState) setVertices(context *context, vertices []float32, indices []uint16) {
|
func pow2(x int) int {
|
||||||
if s.arrayBuffer == 0 {
|
p2 := 1
|
||||||
s.arrayBuffer = context.newArrayBuffer(graphics.IndicesCount * graphics.VertexFloatCount * floatSizeInBytes)
|
for p2 < x {
|
||||||
context.ctx.BindBuffer(gl.ARRAY_BUFFER, uint32(s.arrayBuffer))
|
p2 *= 2
|
||||||
}
|
}
|
||||||
if s.elementArrayBuffer == 0 {
|
return p2
|
||||||
s.elementArrayBuffer = context.newElementArrayBuffer(graphics.IndicesCount * 2)
|
}
|
||||||
context.ctx.BindBuffer(gl.ELEMENT_ARRAY_BUFFER, uint32(s.elementArrayBuffer))
|
|
||||||
|
func (s *openGLState) setVertices(context *context, vertices []float32, indices []uint16) {
|
||||||
|
if size := len(vertices) * 4; s.arrayBufferSizeInBytes < size {
|
||||||
|
if s.arrayBuffer != 0 {
|
||||||
|
context.ctx.DeleteBuffer(uint32(s.arrayBuffer))
|
||||||
|
}
|
||||||
|
|
||||||
|
newSize := pow2(size)
|
||||||
|
// newArrayBuffer calls BindBuffer.
|
||||||
|
s.arrayBuffer = context.newArrayBuffer(newSize)
|
||||||
|
s.arrayBufferSizeInBytes = newSize
|
||||||
|
|
||||||
|
// Reenable the array buffer layouter explicitly after resetting the array buffer.
|
||||||
|
theArrayBufferLayout.enable(context)
|
||||||
|
}
|
||||||
|
|
||||||
|
if size := len(indices) * 2; s.elementArrayBufferSizeInBytes < size {
|
||||||
|
if s.elementArrayBuffer != 0 {
|
||||||
|
context.ctx.DeleteBuffer(uint32(s.elementArrayBuffer))
|
||||||
|
}
|
||||||
|
|
||||||
|
newSize := pow2(size)
|
||||||
|
// newElementArrayBuffer calls BindBuffer.
|
||||||
|
s.elementArrayBuffer = context.newElementArrayBuffer(newSize)
|
||||||
|
s.elementArrayBufferSizeInBytes = newSize
|
||||||
}
|
}
|
||||||
|
|
||||||
// Note that the vertices and the indices passed to BufferSubData is not under GC management in the gl package.
|
// Note that the vertices and the indices passed to BufferSubData is not under GC management in the gl package.
|
||||||
@ -184,9 +212,6 @@ func (g *Graphics) textureVariableName(idx int) string {
|
|||||||
func (g *Graphics) useProgram(program program, uniforms []uniformVariable, textures [graphics.ShaderImageCount]textureVariable) error {
|
func (g *Graphics) useProgram(program program, uniforms []uniformVariable, textures [graphics.ShaderImageCount]textureVariable) error {
|
||||||
if g.state.lastProgram != program {
|
if g.state.lastProgram != program {
|
||||||
g.context.ctx.UseProgram(uint32(program))
|
g.context.ctx.UseProgram(uint32(program))
|
||||||
if g.state.lastProgram == 0 {
|
|
||||||
theArrayBufferLayout.enable(&g.context)
|
|
||||||
}
|
|
||||||
|
|
||||||
g.state.lastProgram = program
|
g.state.lastProgram = program
|
||||||
for k := range g.state.lastUniforms {
|
for k := range g.state.lastUniforms {
|
||||||
|
Loading…
Reference in New Issue
Block a user