mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-26 10:42:42 +01:00
Add package graphicsdriver; Move opengl to graphicsdriver/opengl
This commit is contained in:
parent
feca647087
commit
241716d0e6
@ -19,7 +19,6 @@ import (
|
||||
|
||||
"github.com/hajimehoshi/ebiten/internal/affine"
|
||||
"github.com/hajimehoshi/ebiten/internal/graphics"
|
||||
"github.com/hajimehoshi/ebiten/internal/opengl"
|
||||
)
|
||||
|
||||
// command represents a drawing command.
|
||||
@ -169,7 +168,7 @@ func (q *commandQueue) Flush() {
|
||||
// Note that the vertices passed to BufferSubData is not under GC management
|
||||
// in opengl package due to unsafe-way.
|
||||
// See BufferSubData in context_mobile.go.
|
||||
opengl.GetDriver().BufferSubData(vs[:nv], es[:ne])
|
||||
driver().BufferSubData(vs[:nv], es[:ne])
|
||||
es = es[ne:]
|
||||
vs = vs[nv:]
|
||||
}
|
||||
@ -189,7 +188,7 @@ func (q *commandQueue) Flush() {
|
||||
}
|
||||
if 0 < nc {
|
||||
// Call glFlush to prevent black flicking (especially on Android (#226) and iOS).
|
||||
opengl.GetDriver().Flush()
|
||||
driver().Flush()
|
||||
}
|
||||
q.commands = q.commands[nc:]
|
||||
}
|
||||
@ -234,10 +233,10 @@ func (c *drawImageCommand) Exec(indexOffsetInBytes int) error {
|
||||
|
||||
c.dst.image.SetAsDestination()
|
||||
c.src.image.SetAsSource()
|
||||
if err := opengl.GetDriver().UseProgram(c.mode, c.color, c.filter); err != nil {
|
||||
if err := driver().UseProgram(c.mode, c.color, c.filter); err != nil {
|
||||
return err
|
||||
}
|
||||
opengl.GetDriver().DrawElements(c.nindices, indexOffsetInBytes)
|
||||
driver().DrawElements(c.nindices, indexOffsetInBytes)
|
||||
|
||||
// glFlush() might be necessary at least on MacBook Pro (a smilar problem at #419),
|
||||
// but basically this pass the tests (esp. TestImageTooManyFill).
|
||||
@ -301,7 +300,7 @@ func (c *replacePixelsCommand) String() string {
|
||||
func (c *replacePixelsCommand) Exec(indexOffsetInBytes int) error {
|
||||
// glFlush is necessary on Android.
|
||||
// glTexSubImage2D didn't work without this hack at least on Nexus 5x and NuAns NEO [Reloaded] (#211).
|
||||
opengl.GetDriver().Flush()
|
||||
driver().Flush()
|
||||
c.dst.image.TexSubImage2D(c.pixels, c.x, c.y, c.width, c.height)
|
||||
return nil
|
||||
}
|
||||
@ -407,7 +406,7 @@ func (c *newImageCommand) String() string {
|
||||
|
||||
// Exec executes a newImageCommand.
|
||||
func (c *newImageCommand) Exec(indexOffsetInBytes int) error {
|
||||
i, err := opengl.GetDriver().NewImage(c.width, c.height)
|
||||
i, err := driver().NewImage(c.width, c.height)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -446,7 +445,7 @@ func (c *newScreenFramebufferImageCommand) String() string {
|
||||
|
||||
// Exec executes a newScreenFramebufferImageCommand.
|
||||
func (c *newScreenFramebufferImageCommand) Exec(indexOffsetInBytes int) error {
|
||||
c.result.image = opengl.GetDriver().NewScreenFramebufferImage(c.width, c.height)
|
||||
c.result.image = driver().NewScreenFramebufferImage(c.width, c.height)
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -470,5 +469,5 @@ func (c *newScreenFramebufferImageCommand) CanMerge(dst, src *Image, color *affi
|
||||
|
||||
// ResetGraphicsDriverState resets or initializes the current graphics driver state.
|
||||
func ResetGraphicsDriverState() error {
|
||||
return opengl.GetDriver().Reset()
|
||||
return driver().Reset()
|
||||
}
|
||||
|
24
internal/graphicscommand/driver.go
Normal file
24
internal/graphicscommand/driver.go
Normal file
@ -0,0 +1,24 @@
|
||||
// Copyright 2018 The Ebiten Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package graphicscommand
|
||||
|
||||
import (
|
||||
"github.com/hajimehoshi/ebiten/internal/graphicsdriver"
|
||||
"github.com/hajimehoshi/ebiten/internal/graphicsdriver/opengl"
|
||||
)
|
||||
|
||||
func driver() graphicsdriver.GraphicsDriver {
|
||||
return opengl.GetDriver()
|
||||
}
|
@ -17,7 +17,7 @@ package graphicscommand
|
||||
import (
|
||||
"github.com/hajimehoshi/ebiten/internal/affine"
|
||||
"github.com/hajimehoshi/ebiten/internal/graphics"
|
||||
"github.com/hajimehoshi/ebiten/internal/opengl"
|
||||
"github.com/hajimehoshi/ebiten/internal/graphicsdriver"
|
||||
)
|
||||
|
||||
var (
|
||||
@ -30,7 +30,7 @@ var (
|
||||
// MaxImageSize returns the maximum of width/height of an image.
|
||||
func MaxImageSize() int {
|
||||
if maxTextureSize == 0 {
|
||||
maxTextureSize = opengl.GetDriver().MaxTextureSize()
|
||||
maxTextureSize = driver().MaxTextureSize()
|
||||
if maxTextureSize == 0 {
|
||||
panic("graphics: failed to get the max texture size")
|
||||
}
|
||||
@ -41,7 +41,7 @@ func MaxImageSize() int {
|
||||
|
||||
// Image represents an image that is implemented with OpenGL.
|
||||
type Image struct {
|
||||
image *opengl.Image
|
||||
image graphicsdriver.Image
|
||||
width int
|
||||
height int
|
||||
}
|
||||
|
40
internal/graphicsdriver/graphicsdriver.go
Normal file
40
internal/graphicsdriver/graphicsdriver.go
Normal file
@ -0,0 +1,40 @@
|
||||
// Copyright 2018 The Ebiten Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package graphicsdriver
|
||||
|
||||
import (
|
||||
"github.com/hajimehoshi/ebiten/internal/affine"
|
||||
"github.com/hajimehoshi/ebiten/internal/graphics"
|
||||
)
|
||||
|
||||
type GraphicsDriver interface {
|
||||
BufferSubData(vertices []float32, indices []uint16)
|
||||
DrawElements(len int, offsetInBytes int)
|
||||
Flush()
|
||||
MaxTextureSize() int
|
||||
NewImage(width, height int) (Image, error)
|
||||
NewScreenFramebufferImage(width, height int) Image
|
||||
Reset() error
|
||||
UseProgram(mode graphics.CompositeMode, colorM *affine.ColorM, filter graphics.Filter) error
|
||||
}
|
||||
|
||||
type Image interface {
|
||||
Delete()
|
||||
IsInvalidated() bool
|
||||
Pixels() ([]byte, error)
|
||||
SetAsDestination()
|
||||
SetAsSource()
|
||||
TexSubImage2D(p []byte, x, y, width, height int)
|
||||
}
|
@ -17,6 +17,7 @@ package opengl
|
||||
import (
|
||||
"github.com/hajimehoshi/ebiten/internal/affine"
|
||||
"github.com/hajimehoshi/ebiten/internal/graphics"
|
||||
"github.com/hajimehoshi/ebiten/internal/graphicsdriver"
|
||||
"github.com/hajimehoshi/ebiten/internal/math"
|
||||
)
|
||||
|
||||
@ -30,7 +31,7 @@ type Driver struct {
|
||||
state openGLState
|
||||
}
|
||||
|
||||
func (d *Driver) NewImage(width, height int) (*Image, error) {
|
||||
func (d *Driver) NewImage(width, height int) (graphicsdriver.Image, error) {
|
||||
i := &Image{
|
||||
driver: d,
|
||||
width: width,
|
||||
@ -47,7 +48,7 @@ func (d *Driver) NewImage(width, height int) (*Image, error) {
|
||||
return i, nil
|
||||
}
|
||||
|
||||
func (d *Driver) NewScreenFramebufferImage(width, height int) *Image {
|
||||
func (d *Driver) NewScreenFramebufferImage(width, height int) graphicsdriver.Image {
|
||||
checkSize(width, height)
|
||||
i := &Image{
|
||||
driver: d,
|
@ -23,9 +23,9 @@ import (
|
||||
"github.com/gopherjs/gopherwasm/js"
|
||||
|
||||
"github.com/hajimehoshi/ebiten/internal/devicescale"
|
||||
"github.com/hajimehoshi/ebiten/internal/graphicsdriver/opengl"
|
||||
"github.com/hajimehoshi/ebiten/internal/hooks"
|
||||
"github.com/hajimehoshi/ebiten/internal/input"
|
||||
"github.com/hajimehoshi/ebiten/internal/opengl"
|
||||
)
|
||||
|
||||
var canvas js.Value
|
||||
|
@ -31,9 +31,9 @@ import (
|
||||
"golang.org/x/mobile/gl"
|
||||
|
||||
"github.com/hajimehoshi/ebiten/internal/devicescale"
|
||||
"github.com/hajimehoshi/ebiten/internal/graphicsdriver/opengl"
|
||||
"github.com/hajimehoshi/ebiten/internal/hooks"
|
||||
"github.com/hajimehoshi/ebiten/internal/input"
|
||||
"github.com/hajimehoshi/ebiten/internal/opengl"
|
||||
)
|
||||
|
||||
var (
|
||||
|
Loading…
Reference in New Issue
Block a user