mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-11 19:48:54 +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
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
package shader
|
package graphics
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/hajimehoshi/ebiten/internal/graphics/internal/opengl"
|
"github.com/hajimehoshi/ebiten/internal/graphics/internal/opengl"
|
||||||
"image/color"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func glMatrix(m *[4][4]float64) []float32 {
|
func glMatrix(m *[4][4]float64) []float32 {
|
||||||
@ -34,25 +33,19 @@ type Matrix interface {
|
|||||||
Element(i, j int) float64
|
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 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.
|
// 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.
|
// Let's use them to compare to len(quads) in the future.
|
||||||
|
|
||||||
if !initialized {
|
if !shadersInitialized {
|
||||||
if err := initialize(c); err != nil {
|
if err := initialize(c); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
initialized = true
|
shadersInitialized = true
|
||||||
}
|
}
|
||||||
|
|
||||||
if quads.Len() == 0 {
|
if quads.Len() == 0 {
|
||||||
@ -89,18 +82,12 @@ func DrawTexture(c *opengl.Context, texture opengl.Texture, projectionMatrix *[4
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type Lines interface {
|
func drawLines(c *opengl.Context, projectionMatrix *[4][4]float64, lines Lines) error {
|
||||||
Len() int
|
if !shadersInitialized {
|
||||||
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 {
|
|
||||||
if err := initialize(c); err != nil {
|
if err := initialize(c); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
initialized = true
|
shadersInitialized = true
|
||||||
}
|
}
|
||||||
|
|
||||||
if lines.Len() == 0 {
|
if lines.Len() == 0 {
|
||||||
@ -133,18 +120,12 @@ func DrawLines(c *opengl.Context, projectionMatrix *[4][4]float64, lines Lines)
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type Rects interface {
|
func drawFilledRects(c *opengl.Context, projectionMatrix *[4][4]float64, rects Rects) error {
|
||||||
Len() int
|
if !shadersInitialized {
|
||||||
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 {
|
|
||||||
if err := initialize(c); err != nil {
|
if err := initialize(c); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
initialized = true
|
shadersInitialized = true
|
||||||
}
|
}
|
||||||
|
|
||||||
if rects.Len() == 0 {
|
if rects.Len() == 0 {
|
@ -17,10 +17,27 @@ package graphics
|
|||||||
import (
|
import (
|
||||||
"github.com/hajimehoshi/ebiten/internal"
|
"github.com/hajimehoshi/ebiten/internal"
|
||||||
"github.com/hajimehoshi/ebiten/internal/graphics/internal/opengl"
|
"github.com/hajimehoshi/ebiten/internal/graphics/internal/opengl"
|
||||||
"github.com/hajimehoshi/ebiten/internal/graphics/internal/shader"
|
|
||||||
"image/color"
|
"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 {
|
func orthoProjectionMatrix(left, right, bottom, top int) *[4][4]float64 {
|
||||||
e11 := float64(2) / float64(right-left)
|
e11 := float64(2) / float64(right-left)
|
||||||
e22 := float64(2) / float64(top-bottom)
|
e22 := float64(2) / float64(top-bottom)
|
||||||
@ -89,16 +106,6 @@ func (f *Framebuffer) projectionMatrix() *[4][4]float64 {
|
|||||||
return m
|
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 {
|
func (f *Framebuffer) Fill(c *opengl.Context, r, g, b, a float64) error {
|
||||||
if err := f.setAsViewport(c); err != nil {
|
if err := f.setAsViewport(c); err != nil {
|
||||||
return err
|
return err
|
||||||
@ -111,13 +118,7 @@ func (f *Framebuffer) DrawTexture(c *opengl.Context, t *Texture, quads TextureQu
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
p := f.projectionMatrix()
|
p := f.projectionMatrix()
|
||||||
return shader.DrawTexture(c, t.native, p, quads, geo, clr)
|
return 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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Framebuffer) DrawLines(c *opengl.Context, lines Lines) error {
|
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
|
return err
|
||||||
}
|
}
|
||||||
p := f.projectionMatrix()
|
p := f.projectionMatrix()
|
||||||
return shader.DrawLines(c, p, lines)
|
return drawLines(c, p, lines)
|
||||||
}
|
|
||||||
|
|
||||||
type Rects interface {
|
|
||||||
Len() int
|
|
||||||
Rect(i int) (x, y, width, height int)
|
|
||||||
Color(i int) color.Color
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Framebuffer) DrawFilledRects(c *opengl.Context, rects Rects) error {
|
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
|
return err
|
||||||
}
|
}
|
||||||
p := f.projectionMatrix()
|
p := f.projectionMatrix()
|
||||||
return shader.DrawFilledRects(c, p, rects)
|
return drawFilledRects(c, p, rects)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Framebuffer) Pixels(c *opengl.Context) ([]uint8, error) {
|
func (f *Framebuffer) Pixels(c *opengl.Context) ([]uint8, error) {
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
package shader
|
package graphics
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/hajimehoshi/ebiten/internal/graphics/internal/opengl"
|
"github.com/hajimehoshi/ebiten/internal/graphics/internal/opengl"
|
@ -12,7 +12,7 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
package shader
|
package graphics
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/hajimehoshi/ebiten/internal/graphics/internal/opengl"
|
"github.com/hajimehoshi/ebiten/internal/graphics/internal/opengl"
|
Loading…
Reference in New Issue
Block a user