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

View File

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

View File

@ -112,7 +112,7 @@ func (i *Image) Pixels(context *opengl.Context) ([]uint8, error) {
return nil, err return nil, err
} }
f := i.framebuffer 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 { func (i *Image) ReplacePixels(p []uint8) error {