mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-12 03:58:55 +01:00
Rename renderTarget -> innerRenderTarget; Remove TextureDrawer
This commit is contained in:
parent
991adb7449
commit
a9aa1589de
@ -34,12 +34,8 @@ type TexturePart struct {
|
|||||||
Src Rect
|
Src Rect
|
||||||
}
|
}
|
||||||
|
|
||||||
type TextureDrawer interface {
|
|
||||||
DrawTexture(texture *Texture, parts []TexturePart, geo GeometryMatrix, color ColorMatrix) error
|
|
||||||
}
|
|
||||||
|
|
||||||
// DrawWholeTexture draws the whole texture.
|
// DrawWholeTexture draws the whole texture.
|
||||||
func DrawWholeTexture(r TextureDrawer, texture *Texture, geo GeometryMatrix, color ColorMatrix) error {
|
func DrawWholeTexture(r *RenderTarget, texture *Texture, geo GeometryMatrix, color ColorMatrix) error {
|
||||||
w, h := texture.Size()
|
w, h := texture.Size()
|
||||||
parts := []TexturePart{
|
parts := []TexturePart{
|
||||||
{Rect{0, 0, float64(w), float64(h)}, Rect{0, 0, float64(w), float64(h)}},
|
{Rect{0, 0, float64(w), float64(h)}, Rect{0, 0, float64(w), float64(h)}},
|
||||||
|
@ -27,12 +27,12 @@ func newGraphicsContext(screenWidth, screenHeight, screenScale int) (*graphicsCo
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
screen, err := newRenderTarget(screenWidth, screenHeight, gl.NEAREST)
|
screen, err := newInnerRenderTarget(screenWidth, screenHeight, gl.NEAREST)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
c := &graphicsContext{
|
c := &graphicsContext{
|
||||||
defaultR: &renderTarget{r, nil},
|
defaultR: &innerRenderTarget{r, nil},
|
||||||
screen: screen,
|
screen: screen,
|
||||||
screenScale: screenScale,
|
screenScale: screenScale,
|
||||||
}
|
}
|
||||||
@ -40,8 +40,8 @@ func newGraphicsContext(screenWidth, screenHeight, screenScale int) (*graphicsCo
|
|||||||
}
|
}
|
||||||
|
|
||||||
type graphicsContext struct {
|
type graphicsContext struct {
|
||||||
screen *renderTarget
|
screen *innerRenderTarget
|
||||||
defaultR *renderTarget
|
defaultR *innerRenderTarget
|
||||||
screenScale int
|
screenScale int
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -65,7 +65,11 @@ func (c *graphicsContext) postUpdate() error {
|
|||||||
scale := float64(c.screenScale)
|
scale := float64(c.screenScale)
|
||||||
geo := ScaleGeometry(scale, scale)
|
geo := ScaleGeometry(scale, scale)
|
||||||
clr := ColorMatrixI()
|
clr := ColorMatrixI()
|
||||||
if err := DrawWholeTexture(c.defaultR, c.screen.texture, geo, clr); err != nil {
|
w, h := c.screen.texture.Size()
|
||||||
|
parts := []TexturePart{
|
||||||
|
{Rect{0, 0, float64(w), float64(h)}, Rect{0, 0, float64(w), float64(h)}},
|
||||||
|
}
|
||||||
|
if err := c.defaultR.DrawTexture(c.screen.texture, parts, geo, clr); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,12 +25,12 @@ import (
|
|||||||
"math"
|
"math"
|
||||||
)
|
)
|
||||||
|
|
||||||
type renderTarget struct {
|
type innerRenderTarget struct {
|
||||||
glRenderTarget *opengl.RenderTarget
|
glRenderTarget *opengl.RenderTarget
|
||||||
texture *Texture
|
texture *Texture
|
||||||
}
|
}
|
||||||
|
|
||||||
func newRenderTarget(width, height int, filter int) (*renderTarget, error) {
|
func newInnerRenderTarget(width, height int, filter int) (*innerRenderTarget, error) {
|
||||||
glTexture, err := opengl.NewTexture(width, height, filter)
|
glTexture, err := opengl.NewTexture(width, height, filter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -42,23 +42,18 @@ func newRenderTarget(width, height int, filter int) (*renderTarget, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
texture := &Texture{glTexture}
|
texture := &Texture{glTexture}
|
||||||
renderTarget := &renderTarget{glRenderTarget, texture}
|
return &innerRenderTarget{glRenderTarget, texture}, nil
|
||||||
return renderTarget, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *renderTarget) Texture() *Texture {
|
func (r *innerRenderTarget) size() (width, height int) {
|
||||||
return r.texture
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *renderTarget) Size() (width, height int) {
|
|
||||||
return r.glRenderTarget.Width(), r.glRenderTarget.Height()
|
return r.glRenderTarget.Width(), r.glRenderTarget.Height()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *renderTarget) Clear() error {
|
func (r *innerRenderTarget) Clear() error {
|
||||||
return r.Fill(color.RGBA{0, 0, 0, 0})
|
return r.Fill(color.RGBA{0, 0, 0, 0})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *renderTarget) Fill(clr color.Color) error {
|
func (r *innerRenderTarget) Fill(clr color.Color) error {
|
||||||
if err := r.glRenderTarget.SetAsViewport(); err != nil {
|
if err := r.glRenderTarget.SetAsViewport(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -73,7 +68,7 @@ func (r *renderTarget) Fill(clr color.Color) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *renderTarget) DrawTexture(texture *Texture, parts []TexturePart, geo GeometryMatrix, color ColorMatrix) error {
|
func (r *innerRenderTarget) DrawTexture(texture *Texture, parts []TexturePart, geo GeometryMatrix, color ColorMatrix) error {
|
||||||
if err := r.glRenderTarget.SetAsViewport(); err != nil {
|
if err := r.glRenderTarget.SetAsViewport(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -83,7 +78,7 @@ func (r *renderTarget) DrawTexture(texture *Texture, parts []TexturePart, geo Ge
|
|||||||
if r.texture != nil {
|
if r.texture != nil {
|
||||||
targetNativeTexture = r.texture.glTexture.Native()
|
targetNativeTexture = r.texture.glTexture.Native()
|
||||||
}
|
}
|
||||||
w, h := r.Size()
|
w, h := r.size()
|
||||||
projectionMatrix := r.glRenderTarget.ProjectionMatrix()
|
projectionMatrix := r.glRenderTarget.ProjectionMatrix()
|
||||||
shader.DrawTexture(glTexture.Native(), targetNativeTexture, w, h, projectionMatrix, quads, &geo, &color)
|
shader.DrawTexture(glTexture.Native(), targetNativeTexture, w, h, projectionMatrix, quads, &geo, &color)
|
||||||
return nil
|
return nil
|
||||||
@ -120,15 +115,15 @@ type syncer interface {
|
|||||||
|
|
||||||
type RenderTarget struct {
|
type RenderTarget struct {
|
||||||
syncer syncer
|
syncer syncer
|
||||||
inner *renderTarget
|
inner *innerRenderTarget
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *RenderTarget) Texture() *Texture {
|
func (r *RenderTarget) Texture() *Texture {
|
||||||
return r.inner.Texture()
|
return r.inner.texture
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *RenderTarget) Size() (width, height int) {
|
func (r *RenderTarget) Size() (width, height int) {
|
||||||
return r.inner.Size()
|
return r.inner.size()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *RenderTarget) Clear() (err error) {
|
func (r *RenderTarget) Clear() (err error) {
|
||||||
|
6
ui.go
6
ui.go
@ -145,12 +145,12 @@ func (u *ui) newTexture(img image.Image, filter int) (*Texture, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (u *ui) newRenderTarget(width, height int, filter int) (*RenderTarget, error) {
|
func (u *ui) newRenderTarget(width, height int, filter int) (*RenderTarget, error) {
|
||||||
var renderTarget *renderTarget
|
var innerRenderTarget *innerRenderTarget
|
||||||
var err error
|
var err error
|
||||||
u.use(func() {
|
u.use(func() {
|
||||||
renderTarget, err = newRenderTarget(width, height, filter)
|
innerRenderTarget, err = newInnerRenderTarget(width, height, filter)
|
||||||
})
|
})
|
||||||
return &RenderTarget{u, renderTarget}, err
|
return &RenderTarget{u, innerRenderTarget}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *ui) run() {
|
func (u *ui) run() {
|
||||||
|
Loading…
Reference in New Issue
Block a user