graphics: Remove framebuffer's width/height

This commit is contained in:
Hajime Hoshi 2016-07-05 00:29:46 +09:00
parent 085336d50f
commit 93f7fdd349
3 changed files with 7 additions and 13 deletions

View File

@ -122,11 +122,13 @@ func (c *drawImageCommand) Exec(context *opengl.Context) error {
if n == 0 {
return nil
}
_, h := c.dst.Size()
proj := glMatrix(c.dst.framebuffer.projectionMatrix(h))
p := programContext{
state: &theOpenGLState,
program: theOpenGLState.programTexture,
context: context,
projectionMatrix: glMatrix(c.dst.framebuffer.projectionMatrix()),
projectionMatrix: proj,
texture: c.src.texture.native,
geoM: c.geo,
colorM: c.color,
@ -275,8 +277,6 @@ func (c *newScreenFramebufferImageCommand) Exec(context *opengl.Context) error {
}
f := &framebuffer{
native: context.ScreenFramebuffer(),
width: c.width,
height: c.height,
flipY: true,
}
c.result.framebuffer = f

View File

@ -34,8 +34,6 @@ func orthoProjectionMatrix(left, right, bottom, top int) *[4][4]float64 {
type framebuffer struct {
native opengl.Framebuffer
width int
height int
flipY bool
proMatrix *[4][4]float64
}
@ -47,8 +45,6 @@ func newFramebufferFromTexture(context *opengl.Context, texture *texture) (*fram
}
return &framebuffer{
native: native,
width: texture.width,
height: texture.height,
}, nil
}
@ -60,16 +56,14 @@ func (f *framebuffer) setAsViewport(context *opengl.Context) error {
return context.SetViewport(f.native, width, height)
}
func (f *framebuffer) projectionMatrix() *[4][4]float64 {
func (f *framebuffer) projectionMatrix(height int) *[4][4]float64 {
if f.proMatrix != nil {
return f.proMatrix
}
width := viewportSize
height := viewportSize
m := orthoProjectionMatrix(0, width, 0, height)
m := orthoProjectionMatrix(0, viewportSize, 0, viewportSize)
if f.flipY {
m[1][1] *= -1
m[1][3] += float64(f.height) / float64(height) * 2
m[1][3] += float64(height) / float64(viewportSize) * 2
}
f.proMatrix = m
return f.proMatrix

View File

@ -112,7 +112,7 @@ func (i *Image) Pixels(context *opengl.Context) ([]uint8, error) {
return nil, err
}
f := i.framebuffer
return context.FramebufferPixels(f.native, f.width, f.height)
return context.FramebufferPixels(f.native, i.width, i.height)
}
func (i *Image) ReplacePixels(p []uint8) error {