mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-25 11:18:54 +01:00
Refactoring
This commit is contained in:
parent
6a2229f973
commit
9b05640ddf
@ -2,7 +2,6 @@ package blocks
|
||||
|
||||
import (
|
||||
"github.com/hajimehoshi/ebiten/graphics"
|
||||
_ "image/png"
|
||||
"sync"
|
||||
)
|
||||
|
||||
|
@ -3,6 +3,7 @@ package blocks
|
||||
import (
|
||||
"github.com/hajimehoshi/ebiten/graphics"
|
||||
"image"
|
||||
_ "image/png"
|
||||
"os"
|
||||
"sync"
|
||||
)
|
||||
|
@ -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()
|
||||
|
@ -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) {
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user