mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-09-20 13:22:19 +02:00
graphics: Use command buffers
This commit is contained in:
parent
efd019c00e
commit
208b27d5de
@ -37,7 +37,7 @@ func (q *commandQueue) Enqueue(command command) {
|
|||||||
q.commands = append(q.commands, command)
|
q.commands = append(q.commands, command)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (q *commandQueue) Exec(context *opengl.Context) error {
|
func (q *commandQueue) Flush(context *opengl.Context) error {
|
||||||
// TODO: Do optimizing before executing
|
// TODO: Do optimizing before executing
|
||||||
for _, c := range q.commands {
|
for _, c := range q.commands {
|
||||||
if err := c.Exec(context); err != nil {
|
if err := c.Exec(context); err != nil {
|
||||||
|
@ -43,24 +43,25 @@ type Framebuffer struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewZeroFramebuffer(c *opengl.Context, width, height int) (*Framebuffer, error) {
|
func NewZeroFramebuffer(c *opengl.Context, width, height int) (*Framebuffer, error) {
|
||||||
r := &Framebuffer{
|
f := &Framebuffer{
|
||||||
width: width,
|
width: width,
|
||||||
height: height,
|
height: height,
|
||||||
flipY: true,
|
flipY: true,
|
||||||
}
|
}
|
||||||
return r, nil
|
return f, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewFramebufferFromTexture(c *opengl.Context, texture *Texture) (*Framebuffer, error) {
|
func NewFramebufferFromTexture(c *opengl.Context, texture *Texture) (*Framebuffer, error) {
|
||||||
f, err := c.NewFramebuffer(opengl.Texture(texture.native))
|
native, err := c.NewFramebuffer(opengl.Texture(texture.native))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return &Framebuffer{
|
f := &Framebuffer{
|
||||||
native: f,
|
native: native,
|
||||||
width: texture.width,
|
width: texture.width,
|
||||||
height: texture.height,
|
height: texture.height,
|
||||||
}, nil
|
}
|
||||||
|
return f, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Framebuffer) Dispose(c *opengl.Context) error {
|
func (f *Framebuffer) Dispose(c *opengl.Context) error {
|
||||||
@ -98,7 +99,8 @@ func (f *Framebuffer) Fill(context *opengl.Context, clr color.Color) error {
|
|||||||
dst: f,
|
dst: f,
|
||||||
color: clr,
|
color: clr,
|
||||||
}
|
}
|
||||||
return c.Exec(context)
|
theCommandQueue.Enqueue(c)
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Framebuffer) DrawTexture(context *opengl.Context, t *Texture, vertices []int16, geo, clr Matrix, mode opengl.CompositeMode) error {
|
func (f *Framebuffer) DrawTexture(context *opengl.Context, t *Texture, vertices []int16, geo, clr Matrix, mode opengl.CompositeMode) error {
|
||||||
@ -110,11 +112,21 @@ func (f *Framebuffer) DrawTexture(context *opengl.Context, t *Texture, vertices
|
|||||||
color: clr,
|
color: clr,
|
||||||
mode: mode,
|
mode: mode,
|
||||||
}
|
}
|
||||||
return c.Exec(context)
|
theCommandQueue.Enqueue(c)
|
||||||
|
// Drawing a texture to the default buffer must be the last command.
|
||||||
|
// TODO(hajimehoshi): This seems a little hacky. Refactor.
|
||||||
|
if f.native == opengl.ZeroFramebuffer {
|
||||||
|
return theCommandQueue.Flush(context)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Framebuffer) Pixels(c *opengl.Context) ([]uint8, error) {
|
func (f *Framebuffer) Pixels(context *opengl.Context) ([]uint8, error) {
|
||||||
return c.FramebufferPixels(f.native, f.width, f.height)
|
// Flush the enqueued commands so that pixels are certainly read.
|
||||||
|
if err := theCommandQueue.Flush(context); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return context.FramebufferPixels(f.native, f.width, f.height)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Framebuffer) ReplacePixels(context *opengl.Context, t *Texture, p []uint8) error {
|
func (f *Framebuffer) ReplacePixels(context *opengl.Context, t *Texture, p []uint8) error {
|
||||||
@ -123,5 +135,6 @@ func (f *Framebuffer) ReplacePixels(context *opengl.Context, t *Texture, p []uin
|
|||||||
texture: t,
|
texture: t,
|
||||||
pixels: p,
|
pixels: p,
|
||||||
}
|
}
|
||||||
return c.Exec(context)
|
theCommandQueue.Enqueue(c)
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user