Refactoring

This commit is contained in:
Hajime Hoshi 2013-12-12 01:46:32 +09:00
parent 82e8849e01
commit 63fc25d24c
4 changed files with 22 additions and 19 deletions

View File

@ -1,5 +1,9 @@
package graphics
import (
"image/color"
)
type Rect struct {
X int
Y int
@ -13,6 +17,12 @@ type TexturePart struct {
Source Rect
}
type Line struct {
X1, Y1 int
X2, Y2 int
Color color.Color
}
type TextureId int
// A render target is essentially same as a texture, but it is assumed that the

View File

@ -38,14 +38,16 @@ func newCanvas(ids *ids, screenWidth, screenHeight, screenScale int) *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.Clear()
draw(canvas)
canvas.flush()
canvas.setMainFramebufferOffscreen()
C.glFlush()
canvas.offscreen.SetMainFramebuffer()
canvas.Clear()
scale := float64(canvas.screenScale)
@ -53,7 +55,7 @@ func (canvas *Canvas) update(draw func(graphics.Canvas)) {
geometryMatrix.Scale(scale, scale)
canvas.DrawRenderTarget(canvas.screenId,
geometryMatrix, matrix.IdentityColor())
canvas.flush()
C.glFlush()
}
func (canvas *Canvas) Clear() {
@ -96,10 +98,8 @@ func (canvas *Canvas) DrawRenderTargetParts(
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) init() {
C.glEnable(C.GL_TEXTURE_2D)
C.glEnable(C.GL_BLEND)
func (canvas *Canvas) DrawLines(lines []graphics.Line) {
canvas.offscreen.DrawLines(lines)
}
func (canvas *Canvas) ResetOffscreen() {
@ -110,11 +110,3 @@ func (canvas *Canvas) SetOffscreen(renderTargetId graphics.RenderTargetId) {
renderTarget := canvas.ids.RenderTargetAt(renderTargetId)
canvas.offscreen.Set(renderTarget)
}
func (canvas *Canvas) setMainFramebufferOffscreen() {
canvas.offscreen.SetMainFramebuffer()
}
func (canvas *Canvas) flush() {
C.glFlush()
}

View File

@ -63,6 +63,10 @@ func (o *Offscreen) DrawTextureParts(texture *gtexture.Texture,
texture.DrawParts(parts, &drawable{o, geometryMatrix, colorMatrix})
}
func (o *Offscreen) DrawLines(lines []graphics.Line) {
// TODO: Implement!
}
type setter struct {
offscreen *Offscreen
usingMainFramebuffer bool

View File

@ -103,9 +103,6 @@ func getUniformLocation(program C.GLuint, name string) C.GLint {
return getLocation(program, name, qualifierVariableTypeUniform)
}
func program() {
}
func use(projectionMatrix [16]float32,
geometryMatrix matrix.Geometry, colorMatrix matrix.Color) C.GLuint {
program := programRegular