2017-05-03 16:11:43 +02:00
|
|
|
// Copyright 2017 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 restorable
|
|
|
|
|
|
|
|
import (
|
2021-08-04 18:15:41 +02:00
|
|
|
"github.com/hajimehoshi/ebiten/v2/internal/debug"
|
2020-10-03 19:35:13 +02:00
|
|
|
"github.com/hajimehoshi/ebiten/v2/internal/graphicscommand"
|
2022-02-06 12:41:32 +01:00
|
|
|
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver"
|
2017-05-03 16:11:43 +02:00
|
|
|
)
|
|
|
|
|
2017-09-11 20:12:17 +02:00
|
|
|
// images is a set of Image objects.
|
2017-05-03 16:11:43 +02:00
|
|
|
type images struct {
|
2024-01-08 19:01:08 +01:00
|
|
|
images map[*Image]struct{}
|
2017-05-03 16:11:43 +02:00
|
|
|
}
|
|
|
|
|
2017-09-14 17:24:18 +02:00
|
|
|
// theImages represents the images for the current process.
|
2017-05-03 16:11:43 +02:00
|
|
|
var theImages = &images{
|
2024-01-08 19:01:08 +01:00
|
|
|
images: map[*Image]struct{}{},
|
2017-05-03 16:11:43 +02:00
|
|
|
}
|
|
|
|
|
2023-12-23 11:17:50 +01:00
|
|
|
func SwapBuffers(graphicsDriver graphicsdriver.Graphics) error {
|
2021-08-04 18:15:41 +02:00
|
|
|
if debug.IsDebug {
|
|
|
|
debug.Logf("Internal image sizes:\n")
|
|
|
|
imgs := make([]*graphicscommand.Image, 0, len(theImages.images))
|
|
|
|
for i := range theImages.images {
|
|
|
|
imgs = append(imgs, i.image)
|
|
|
|
}
|
|
|
|
graphicscommand.LogImagesInfo(imgs)
|
|
|
|
}
|
2024-01-08 15:53:06 +01:00
|
|
|
if err := graphicscommand.FlushCommands(graphicsDriver, true); err != nil {
|
2020-01-18 17:18:56 +01:00
|
|
|
return err
|
|
|
|
}
|
2024-01-08 15:53:06 +01:00
|
|
|
return nil
|
2017-05-03 17:08:07 +02:00
|
|
|
}
|
|
|
|
|
2019-07-19 16:29:19 +02:00
|
|
|
// DumpImages dumps all the current images to the specified directory.
|
2019-07-14 21:14:57 +02:00
|
|
|
//
|
|
|
|
// This is for testing usage.
|
2022-08-31 06:10:41 +02:00
|
|
|
func DumpImages(graphicsDriver graphicsdriver.Graphics, dir string) (string, error) {
|
2022-08-30 20:10:10 +02:00
|
|
|
images := make([]*graphicscommand.Image, 0, len(theImages.images))
|
2019-02-19 02:15:23 +01:00
|
|
|
for img := range theImages.images {
|
2022-08-30 20:10:10 +02:00
|
|
|
images = append(images, img.image)
|
2018-04-28 14:49:00 +02:00
|
|
|
}
|
2022-08-30 20:10:10 +02:00
|
|
|
|
|
|
|
return graphicscommand.DumpImages(images, graphicsDriver, dir)
|
2018-04-28 14:49:00 +02:00
|
|
|
}
|
|
|
|
|
2017-09-14 17:24:18 +02:00
|
|
|
// add adds img to the images.
|
2017-05-03 16:15:18 +02:00
|
|
|
func (i *images) add(img *Image) {
|
2017-05-03 16:11:43 +02:00
|
|
|
i.images[img] = struct{}{}
|
|
|
|
}
|
|
|
|
|
2017-09-14 17:24:18 +02:00
|
|
|
// remove removes img from the images.
|
2017-05-03 16:24:00 +02:00
|
|
|
func (i *images) remove(img *Image) {
|
2017-05-03 16:11:43 +02:00
|
|
|
delete(i.images, img)
|
|
|
|
}
|
|
|
|
|
2021-09-08 20:58:58 +02:00
|
|
|
var graphicsDriverInitialized bool
|
|
|
|
|
2018-10-31 19:02:08 +01:00
|
|
|
// InitializeGraphicsDriverState initializes the graphics driver state.
|
2022-03-19 15:55:14 +01:00
|
|
|
func InitializeGraphicsDriverState(graphicsDriver graphicsdriver.Graphics) error {
|
2021-09-08 20:58:58 +02:00
|
|
|
graphicsDriverInitialized = true
|
2022-03-19 15:55:14 +01:00
|
|
|
return graphicscommand.InitializeGraphicsDriverState(graphicsDriver)
|
2017-08-06 14:24:10 +02:00
|
|
|
}
|
2020-05-30 12:43:59 +02:00
|
|
|
|
2020-10-12 18:36:40 +02:00
|
|
|
// MaxImageSize returns the maximum size of an image.
|
2022-03-19 15:55:14 +01:00
|
|
|
func MaxImageSize(graphicsDriver graphicsdriver.Graphics) int {
|
|
|
|
return graphicscommand.MaxImageSize(graphicsDriver)
|
2020-10-12 18:36:40 +02:00
|
|
|
}
|