mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-26 02:42:02 +01:00
Refactoring
This commit is contained in:
parent
82e8849e01
commit
63fc25d24c
@ -1,5 +1,9 @@
|
|||||||
package graphics
|
package graphics
|
||||||
|
|
||||||
|
import (
|
||||||
|
"image/color"
|
||||||
|
)
|
||||||
|
|
||||||
type Rect struct {
|
type Rect struct {
|
||||||
X int
|
X int
|
||||||
Y int
|
Y int
|
||||||
@ -13,6 +17,12 @@ type TexturePart struct {
|
|||||||
Source Rect
|
Source Rect
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Line struct {
|
||||||
|
X1, Y1 int
|
||||||
|
X2, Y2 int
|
||||||
|
Color color.Color
|
||||||
|
}
|
||||||
|
|
||||||
type TextureId int
|
type TextureId int
|
||||||
|
|
||||||
// A render target is essentially same as a texture, but it is assumed that the
|
// A render target is essentially same as a texture, but it is assumed that the
|
||||||
|
@ -38,14 +38,16 @@ func newCanvas(ids *ids, screenWidth, screenHeight, screenScale int) *Canvas {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (canvas *Canvas) update(draw func(graphics.Canvas)) {
|
func (canvas *Canvas) update(draw func(graphics.Canvas)) {
|
||||||
canvas.init()
|
C.glEnable(C.GL_TEXTURE_2D)
|
||||||
|
C.glEnable(C.GL_BLEND)
|
||||||
|
|
||||||
canvas.ResetOffscreen()
|
canvas.ResetOffscreen()
|
||||||
canvas.Clear()
|
canvas.Clear()
|
||||||
|
|
||||||
draw(canvas)
|
draw(canvas)
|
||||||
|
|
||||||
canvas.flush()
|
C.glFlush()
|
||||||
canvas.setMainFramebufferOffscreen()
|
canvas.offscreen.SetMainFramebuffer()
|
||||||
canvas.Clear()
|
canvas.Clear()
|
||||||
|
|
||||||
scale := float64(canvas.screenScale)
|
scale := float64(canvas.screenScale)
|
||||||
@ -53,7 +55,7 @@ func (canvas *Canvas) update(draw func(graphics.Canvas)) {
|
|||||||
geometryMatrix.Scale(scale, scale)
|
geometryMatrix.Scale(scale, scale)
|
||||||
canvas.DrawRenderTarget(canvas.screenId,
|
canvas.DrawRenderTarget(canvas.screenId,
|
||||||
geometryMatrix, matrix.IdentityColor())
|
geometryMatrix, matrix.IdentityColor())
|
||||||
canvas.flush()
|
C.glFlush()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (canvas *Canvas) Clear() {
|
func (canvas *Canvas) Clear() {
|
||||||
@ -96,10 +98,8 @@ func (canvas *Canvas) DrawRenderTargetParts(
|
|||||||
canvas.DrawTextureParts(canvas.ids.ToTexture(id), parts, geometryMatrix, colorMatrix)
|
canvas.DrawTextureParts(canvas.ids.ToTexture(id), parts, geometryMatrix, colorMatrix)
|
||||||
}
|
}
|
||||||
|
|
||||||
// init initializes the canvas. The initial state is saved for each GL canvas.
|
func (canvas *Canvas) DrawLines(lines []graphics.Line) {
|
||||||
func (canvas *Canvas) init() {
|
canvas.offscreen.DrawLines(lines)
|
||||||
C.glEnable(C.GL_TEXTURE_2D)
|
|
||||||
C.glEnable(C.GL_BLEND)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (canvas *Canvas) ResetOffscreen() {
|
func (canvas *Canvas) ResetOffscreen() {
|
||||||
@ -110,11 +110,3 @@ func (canvas *Canvas) SetOffscreen(renderTargetId graphics.RenderTargetId) {
|
|||||||
renderTarget := canvas.ids.RenderTargetAt(renderTargetId)
|
renderTarget := canvas.ids.RenderTargetAt(renderTargetId)
|
||||||
canvas.offscreen.Set(renderTarget)
|
canvas.offscreen.Set(renderTarget)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (canvas *Canvas) setMainFramebufferOffscreen() {
|
|
||||||
canvas.offscreen.SetMainFramebuffer()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (canvas *Canvas) flush() {
|
|
||||||
C.glFlush()
|
|
||||||
}
|
|
||||||
|
@ -63,6 +63,10 @@ func (o *Offscreen) DrawTextureParts(texture *gtexture.Texture,
|
|||||||
texture.DrawParts(parts, &drawable{o, geometryMatrix, colorMatrix})
|
texture.DrawParts(parts, &drawable{o, geometryMatrix, colorMatrix})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (o *Offscreen) DrawLines(lines []graphics.Line) {
|
||||||
|
// TODO: Implement!
|
||||||
|
}
|
||||||
|
|
||||||
type setter struct {
|
type setter struct {
|
||||||
offscreen *Offscreen
|
offscreen *Offscreen
|
||||||
usingMainFramebuffer bool
|
usingMainFramebuffer bool
|
||||||
|
@ -103,9 +103,6 @@ func getUniformLocation(program C.GLuint, name string) C.GLint {
|
|||||||
return getLocation(program, name, qualifierVariableTypeUniform)
|
return getLocation(program, name, qualifierVariableTypeUniform)
|
||||||
}
|
}
|
||||||
|
|
||||||
func program() {
|
|
||||||
}
|
|
||||||
|
|
||||||
func use(projectionMatrix [16]float32,
|
func use(projectionMatrix [16]float32,
|
||||||
geometryMatrix matrix.Geometry, colorMatrix matrix.Color) C.GLuint {
|
geometryMatrix matrix.Geometry, colorMatrix matrix.Color) C.GLuint {
|
||||||
program := programRegular
|
program := programRegular
|
||||||
|
Loading…
Reference in New Issue
Block a user