mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 02:38:53 +01:00
Merge internal/graphics/internal/shaders into internal/graphics
This commit is contained in:
parent
346bc53d53
commit
e23b0758e5
@ -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 {
|
@ -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) {
|
||||
|
@ -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"
|
@ -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"
|
Loading…
Reference in New Issue
Block a user