From e23b0758e56c5a7442eeb2e6bedf602fe2a07766 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Mon, 26 Jan 2015 23:32:50 +0900 Subject: [PATCH] Merge internal/graphics/internal/shaders into internal/graphics --- .../graphics/{internal/shader => }/draw.go | 41 +++++----------- internal/graphics/framebuffer.go | 47 +++++++++---------- .../graphics/{internal/shader => }/program.go | 2 +- .../graphics/{internal/shader => }/shader.go | 2 +- 4 files changed, 34 insertions(+), 58 deletions(-) rename internal/graphics/{internal/shader => }/draw.go (85%) rename internal/graphics/{internal/shader => }/program.go (99%) rename internal/graphics/{internal/shader => }/shader.go (99%) diff --git a/internal/graphics/internal/shader/draw.go b/internal/graphics/draw.go similarity index 85% rename from internal/graphics/internal/shader/draw.go rename to internal/graphics/draw.go index ac61971f5..1fcedc630 100644 --- a/internal/graphics/internal/shader/draw.go +++ b/internal/graphics/draw.go @@ -12,13 +12,12 @@ // See the License for the specific language governing permissions and // limitations under the License. -package shader +package graphics import ( "errors" "fmt" "github.com/hajimehoshi/ebiten/internal/graphics/internal/opengl" - "image/color" ) func glMatrix(m *[4][4]float64) []float32 { @@ -34,25 +33,19 @@ type Matrix interface { Element(i, j int) float64 } -type TextureQuads interface { - Len() int - Vertex(i int) (x0, y0, x1, y1 int) - Texture(i int) (u0, v0, u1, v1 int) -} - var vertices = make([]int16, 0, 4*8*quadsMaxNum) -var initialized = false +var shadersInitialized = false -func DrawTexture(c *opengl.Context, texture opengl.Texture, projectionMatrix *[4][4]float64, quads TextureQuads, geo Matrix, color Matrix) error { +func drawTexture(c *opengl.Context, texture opengl.Texture, projectionMatrix *[4][4]float64, quads TextureQuads, geo Matrix, color Matrix) error { // TODO: WebGL doesn't seem to have Check gl.MAX_ELEMENTS_VERTICES or gl.MAX_ELEMENTS_INDICES so far. // Let's use them to compare to len(quads) in the future. - if !initialized { + if !shadersInitialized { if err := initialize(c); err != nil { return err } - initialized = true + shadersInitialized = true } if quads.Len() == 0 { @@ -89,18 +82,12 @@ func DrawTexture(c *opengl.Context, texture opengl.Texture, projectionMatrix *[4 return nil } -type Lines interface { - Len() int - Points(i int) (x0, y0, x1, y1 int) - Color(i int) color.Color -} - -func DrawLines(c *opengl.Context, projectionMatrix *[4][4]float64, lines Lines) error { - if !initialized { +func drawLines(c *opengl.Context, projectionMatrix *[4][4]float64, lines Lines) error { + if !shadersInitialized { if err := initialize(c); err != nil { return err } - initialized = true + shadersInitialized = true } if lines.Len() == 0 { @@ -133,18 +120,12 @@ func DrawLines(c *opengl.Context, projectionMatrix *[4][4]float64, lines Lines) return nil } -type Rects interface { - Len() int - Rect(i int) (x, y, width, height int) - Color(i int) color.Color -} - -func DrawFilledRects(c *opengl.Context, projectionMatrix *[4][4]float64, rects Rects) error { - if !initialized { +func drawFilledRects(c *opengl.Context, projectionMatrix *[4][4]float64, rects Rects) error { + if !shadersInitialized { if err := initialize(c); err != nil { return err } - initialized = true + shadersInitialized = true } if rects.Len() == 0 { diff --git a/internal/graphics/framebuffer.go b/internal/graphics/framebuffer.go index 344807724..869de786b 100644 --- a/internal/graphics/framebuffer.go +++ b/internal/graphics/framebuffer.go @@ -17,10 +17,27 @@ package graphics import ( "github.com/hajimehoshi/ebiten/internal" "github.com/hajimehoshi/ebiten/internal/graphics/internal/opengl" - "github.com/hajimehoshi/ebiten/internal/graphics/internal/shader" "image/color" ) +type TextureQuads interface { + Len() int + Vertex(i int) (x0, y0, x1, y1 int) + Texture(i int) (u0, v0, u1, v1 int) +} + +type Lines interface { + Len() int + Points(i int) (x0, y0, x1, y1 int) + Color(i int) color.Color +} + +type Rects interface { + Len() int + Rect(i int) (x, y, width, height int) + Color(i int) color.Color +} + func orthoProjectionMatrix(left, right, bottom, top int) *[4][4]float64 { e11 := float64(2) / float64(right-left) e22 := float64(2) / float64(top-bottom) @@ -89,16 +106,6 @@ func (f *Framebuffer) projectionMatrix() *[4][4]float64 { return m } -type Matrix interface { - Element(i, j int) float64 -} - -type TextureQuads interface { - Len() int - Vertex(i int) (x0, y0, x1, y1 int) - Texture(i int) (u0, v0, u1, v1 int) -} - func (f *Framebuffer) Fill(c *opengl.Context, r, g, b, a float64) error { if err := f.setAsViewport(c); err != nil { return err @@ -111,13 +118,7 @@ func (f *Framebuffer) DrawTexture(c *opengl.Context, t *Texture, quads TextureQu return err } p := f.projectionMatrix() - return shader.DrawTexture(c, t.native, p, quads, geo, clr) -} - -type Lines interface { - Len() int - Points(i int) (x0, y0, x1, y1 int) - Color(i int) color.Color + return drawTexture(c, t.native, p, quads, geo, clr) } func (f *Framebuffer) DrawLines(c *opengl.Context, lines Lines) error { @@ -125,13 +126,7 @@ func (f *Framebuffer) DrawLines(c *opengl.Context, lines Lines) error { return err } p := f.projectionMatrix() - return shader.DrawLines(c, p, lines) -} - -type Rects interface { - Len() int - Rect(i int) (x, y, width, height int) - Color(i int) color.Color + return drawLines(c, p, lines) } func (f *Framebuffer) DrawFilledRects(c *opengl.Context, rects Rects) error { @@ -139,7 +134,7 @@ func (f *Framebuffer) DrawFilledRects(c *opengl.Context, rects Rects) error { return err } p := f.projectionMatrix() - return shader.DrawFilledRects(c, p, rects) + return drawFilledRects(c, p, rects) } func (f *Framebuffer) Pixels(c *opengl.Context) ([]uint8, error) { diff --git a/internal/graphics/internal/shader/program.go b/internal/graphics/program.go similarity index 99% rename from internal/graphics/internal/shader/program.go rename to internal/graphics/program.go index 43639cf85..4345e2bcd 100644 --- a/internal/graphics/internal/shader/program.go +++ b/internal/graphics/program.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package shader +package graphics import ( "github.com/hajimehoshi/ebiten/internal/graphics/internal/opengl" diff --git a/internal/graphics/internal/shader/shader.go b/internal/graphics/shader.go similarity index 99% rename from internal/graphics/internal/shader/shader.go rename to internal/graphics/shader.go index 36fa78bff..4c69ef2fb 100644 --- a/internal/graphics/internal/shader/shader.go +++ b/internal/graphics/shader.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package shader +package graphics import ( "github.com/hajimehoshi/ebiten/internal/graphics/internal/opengl"