Refactoring

This commit is contained in:
Hajime Hoshi 2014-12-07 18:25:28 +09:00
parent 6a2229f973
commit 9b05640ddf
6 changed files with 17 additions and 22 deletions

View File

@ -2,7 +2,6 @@ package blocks
import (
"github.com/hajimehoshi/ebiten/graphics"
_ "image/png"
"sync"
)

View File

@ -3,6 +3,7 @@ package blocks
import (
"github.com/hajimehoshi/ebiten/graphics"
"image"
_ "image/png"
"os"
"sync"
)

View File

@ -46,7 +46,7 @@ func NewContext(screenWidth, screenHeight, screenScale int) *Context {
var err error
context.screenId, err = idsInstance.createRenderTarget(screenWidth, screenHeight, graphics.FilterNearest)
if err != nil {
panic("initializing the offscreen failed: " + err.Error())
panic("opengl.NewContext: initializing the offscreen failed: " + err.Error())
}
context.ResetOffscreen()
context.Clear()

View File

@ -10,16 +10,6 @@ import (
"sync"
)
func glMatrix(matrix [4][4]float64) [16]float32 {
result := [16]float32{}
for j := 0; j < 4; j++ {
for i := 0; i < 4; i++ {
result[i+j*4] = float32(matrix[i][j])
}
}
return result
}
type ids struct {
textures map[graphics.TextureID]*Texture
renderTargets map[graphics.RenderTargetID]*RenderTarget
@ -36,15 +26,11 @@ var idsInstance = &ids{
currentRenderTargetId: -1,
}
func CreateRenderTarget(
width, height int,
filter graphics.Filter) (graphics.RenderTargetID, error) {
func CreateRenderTarget(width, height int, filter graphics.Filter) (graphics.RenderTargetID, error) {
return idsInstance.createRenderTarget(width, height, filter)
}
func CreateTexture(
img image.Image,
filter graphics.Filter) (graphics.TextureID, error) {
func CreateTexture(img image.Image, filter graphics.Filter) (graphics.TextureID, error) {
return idsInstance.createTexture(img, filter)
}
@ -153,7 +139,7 @@ func (i *ids) drawTexture(
r := i.renderTargetAt(target)
projectionMatrix := r.projectionMatrix()
quads := graphics.TextureQuads(parts, texture.width, texture.height)
shader.DrawTexture(texture.native, glMatrix(projectionMatrix), quads, geo, color)
shader.DrawTexture(texture.native, projectionMatrix, quads, geo, color)
}
func (i *ids) setViewportIfNeeded(id graphics.RenderTargetID) {

View File

@ -7,9 +7,19 @@ import (
"sync"
)
func glMatrix(matrix [4][4]float64) [16]float32 {
result := [16]float32{}
for j := 0; j < 4; j++ {
for i := 0; i < 4; i++ {
result[i+j*4] = float32(matrix[i][j])
}
}
return result
}
var once sync.Once
func DrawTexture(native gl.Texture, projectionMatrix [16]float32, quads []graphics.TextureQuad, geo matrix.Geometry, color matrix.Color) {
func DrawTexture(native gl.Texture, projectionMatrix [4][4]float64, quads []graphics.TextureQuad, geo matrix.Geometry, color matrix.Color) {
once.Do(func() {
initialize()
})
@ -18,7 +28,7 @@ func DrawTexture(native gl.Texture, projectionMatrix [16]float32, quads []graphi
return
}
// TODO: Check performance
shaderProgram := use(projectionMatrix, geo, color)
shaderProgram := use(glMatrix(projectionMatrix), geo, color)
native.Bind(gl.TEXTURE_2D)
defer gl.Texture(0).Bind(gl.TEXTURE_2D)

View File

@ -19,7 +19,6 @@ type UI struct {
func (u *UI) Start(width, height, scale int, title string) (ui.Canvas, error) {
if !glfw.Init() {
// TODO: Use glfw error
return nil, errors.New("glfw.Init() fails")
}
glfw.WindowHint(glfw.Resizable, glfw.False)