mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-11 19:48:54 +01:00
cmd/ebitenmobile: support Metal for iOS simulators
This commit is contained in:
parent
a74e7b1578
commit
7e6e022065
@ -80,15 +80,6 @@ func invokeOriginalGobind(lang string) (pkgName string, err error) {
|
|||||||
return pkgs[0].Name, nil
|
return pkgs[0].Name, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func forceGL() bool {
|
|
||||||
for _, tag := range strings.Split(*tags, ",") {
|
|
||||||
if tag == "ebitengl" {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
func run() error {
|
func run() error {
|
||||||
writeFile := func(filename string, content string) error {
|
writeFile := func(filename string, content string) error {
|
||||||
if err := ioutil.WriteFile(filepath.Join(*outdir, filename), []byte(content), 0644); err != nil {
|
if err := ioutil.WriteFile(filepath.Join(*outdir, filename), []byte(content), 0644); err != nil {
|
||||||
@ -110,12 +101,6 @@ func run() error {
|
|||||||
content = strings.ReplaceAll(content, "{{.PrefixUpper}}", prefixUpper)
|
content = strings.ReplaceAll(content, "{{.PrefixUpper}}", prefixUpper)
|
||||||
content = strings.ReplaceAll(content, "{{.PrefixLower}}", prefixLower)
|
content = strings.ReplaceAll(content, "{{.PrefixLower}}", prefixLower)
|
||||||
content = strings.ReplaceAll(content, "{{.JavaPkg}}", *javaPkg)
|
content = strings.ReplaceAll(content, "{{.JavaPkg}}", *javaPkg)
|
||||||
|
|
||||||
f := "0"
|
|
||||||
if forceGL() {
|
|
||||||
f = "1"
|
|
||||||
}
|
|
||||||
content = strings.ReplaceAll(content, "{{.ForceGL}}", f)
|
|
||||||
return content
|
return content
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -158,12 +143,6 @@ const objcM = `// Code generated by ebitenmobile. DO NOT EDIT.
|
|||||||
|
|
||||||
#import <TargetConditionals.h>
|
#import <TargetConditionals.h>
|
||||||
|
|
||||||
#if TARGET_IPHONE_SIMULATOR || {{.ForceGL}}
|
|
||||||
#define EBITEN_METAL 0
|
|
||||||
#else
|
|
||||||
#define EBITEN_METAL 1
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#import <stdint.h>
|
#import <stdint.h>
|
||||||
#import <UIKit/UIKit.h>
|
#import <UIKit/UIKit.h>
|
||||||
#import <GLKit/GLkit.h>
|
#import <GLKit/GLkit.h>
|
||||||
@ -209,18 +188,18 @@ const objcM = `// Code generated by ebitenmobile. DO NOT EDIT.
|
|||||||
started_ = true;
|
started_ = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if EBITEN_METAL
|
if (EbitenmobileviewIsGL()) {
|
||||||
[self.view addSubview: self.metalView];
|
self.glkView.delegate = (id<GLKViewDelegate>)(self);
|
||||||
EbitenmobileviewSetUIView((uintptr_t)(self.metalView));
|
[self.view addSubview: self.glkView];
|
||||||
#else
|
|
||||||
self.glkView.delegate = (id<GLKViewDelegate>)(self);
|
|
||||||
[self.view addSubview: self.glkView];
|
|
||||||
|
|
||||||
EAGLContext *context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
|
EAGLContext *context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
|
||||||
[self glkView].context = context;
|
[self glkView].context = context;
|
||||||
|
|
||||||
[EAGLContext setCurrentContext:context];
|
[EAGLContext setCurrentContext:context];
|
||||||
#endif
|
} else {
|
||||||
|
[self.view addSubview: self.metalView];
|
||||||
|
EbitenmobileviewSetUIView((uintptr_t)(self.metalView));
|
||||||
|
}
|
||||||
|
|
||||||
displayLink_ = [CADisplayLink displayLinkWithTarget:self selector:@selector(drawFrame)];
|
displayLink_ = [CADisplayLink displayLinkWithTarget:self selector:@selector(drawFrame)];
|
||||||
[displayLink_ addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
|
[displayLink_ addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
|
||||||
@ -229,11 +208,11 @@ const objcM = `// Code generated by ebitenmobile. DO NOT EDIT.
|
|||||||
|
|
||||||
- (void)viewWillLayoutSubviews {
|
- (void)viewWillLayoutSubviews {
|
||||||
CGRect viewRect = [[self view] frame];
|
CGRect viewRect = [[self view] frame];
|
||||||
#if EBITEN_METAL
|
if (EbitenmobileviewIsGL()) {
|
||||||
[[self metalView] setFrame:viewRect];
|
[[self glkView] setFrame:viewRect];
|
||||||
#else
|
} else {
|
||||||
[[self glkView] setFrame:viewRect];
|
[[self metalView] setFrame:viewRect];
|
||||||
#endif
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)viewDidLayoutSubviews {
|
- (void)viewDidLayoutSubviews {
|
||||||
@ -255,11 +234,11 @@ const objcM = `// Code generated by ebitenmobile. DO NOT EDIT.
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if EBITEN_METAL
|
if (EbitenmobileviewIsGL()) {
|
||||||
[self updateEbiten];
|
[[self glkView] setNeedsDisplay];
|
||||||
#else
|
} else {
|
||||||
[[self glkView] setNeedsDisplay];
|
[self updateEbiten];
|
||||||
#endif
|
}
|
||||||
|
|
||||||
if (explicitRendering_) {
|
if (explicitRendering_) {
|
||||||
[displayLink_ setPaused:YES];
|
[displayLink_ setPaused:YES];
|
||||||
@ -293,15 +272,15 @@ const objcM = `// Code generated by ebitenmobile. DO NOT EDIT.
|
|||||||
|
|
||||||
- (void)updateTouches:(NSSet*)touches {
|
- (void)updateTouches:(NSSet*)touches {
|
||||||
for (UITouch* touch in touches) {
|
for (UITouch* touch in touches) {
|
||||||
#if EBITEN_METAL
|
if (EbitenmobileviewIsGL()) {
|
||||||
if (touch.view != [self metalView]) {
|
if (touch.view != [self glkView]) {
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (touch.view != [self metalView]) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
if (touch.view != [self glkView]) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
CGPoint location = [touch locationInView:touch.view];
|
CGPoint location = [touch locationInView:touch.view];
|
||||||
EbitenmobileviewUpdateTouchesOnIOS(touch.phase, (uintptr_t)touch, location.x, location.y);
|
EbitenmobileviewUpdateTouchesOnIOS(touch.phase, (uintptr_t)touch, location.x, location.y);
|
||||||
}
|
}
|
||||||
|
File diff suppressed because one or more lines are too long
@ -19,10 +19,13 @@ package ui
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver"
|
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver"
|
||||||
|
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver/metal"
|
||||||
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver/opengl"
|
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver/opengl"
|
||||||
)
|
)
|
||||||
|
|
||||||
func graphicsDriver() graphicsdriver.Graphics {
|
func graphicsDriver() graphicsdriver.Graphics {
|
||||||
// Metal might not be supported on emulators on Intel machines.
|
if g := metal.Get(); g != nil {
|
||||||
|
return g
|
||||||
|
}
|
||||||
return opengl.Get()
|
return opengl.Get()
|
||||||
}
|
}
|
@ -1,31 +0,0 @@
|
|||||||
// Copyright 2019 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.
|
|
||||||
|
|
||||||
//go:build ios && !ebitengl && !ebitencbackend
|
|
||||||
// +build ios,!ebitengl,!ebitencbackend
|
|
||||||
|
|
||||||
package ui
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver"
|
|
||||||
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver/metal"
|
|
||||||
)
|
|
||||||
|
|
||||||
func graphicsDriver() graphicsdriver.Graphics {
|
|
||||||
g := metal.Get()
|
|
||||||
if g == nil {
|
|
||||||
panic("ui: Metal is not available on this iOS device")
|
|
||||||
}
|
|
||||||
return g
|
|
||||||
}
|
|
@ -1,4 +1,4 @@
|
|||||||
// Copyright 2019 The Ebiten Authors
|
// Copyright 2022 The Ebiten Authors
|
||||||
//
|
//
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
// you may not use this file except in compliance with the License.
|
// you may not use this file except in compliance with the License.
|
||||||
@ -12,15 +12,18 @@
|
|||||||
// 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.
|
||||||
|
|
||||||
//go:build (darwin && ios && arm) || (darwin && ios && arm64)
|
//go:build ios
|
||||||
// +build darwin,ios,arm darwin,ios,arm64
|
// +build ios
|
||||||
|
|
||||||
package ebitenmobileview
|
package ui
|
||||||
|
|
||||||
import (
|
func SetUIView(uiview uintptr) {
|
||||||
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver/metal"
|
// This function should be called only when the graphics library is Metal.
|
||||||
)
|
if g, ok := theUI.graphicsDriver.(interface{ SetUIView(uintptr) }); ok {
|
||||||
|
g.SetUIView(uiview)
|
||||||
func SetUIView(uiview int64) {
|
}
|
||||||
metal.Get().SetUIView(uintptr(uiview))
|
}
|
||||||
|
|
||||||
|
func IsGL() bool {
|
||||||
|
return theUI.graphicsDriver.IsGL()
|
||||||
}
|
}
|
@ -12,15 +12,19 @@
|
|||||||
// 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.
|
||||||
|
|
||||||
//go:build darwin && ios && !arm && !arm64
|
//go:build ios
|
||||||
// +build darwin,ios,!arm,!arm64
|
// +build ios
|
||||||
|
|
||||||
package ebitenmobileview
|
package ebitenmobileview
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"runtime"
|
"github.com/hajimehoshi/ebiten/v2/internal/ui"
|
||||||
)
|
)
|
||||||
|
|
||||||
func SetUIView(uiview int64) {
|
func SetUIView(uiview int64) {
|
||||||
panic("ebitenmobileview: SetUIView is not available on GOARCH=" + runtime.GOARCH)
|
ui.SetUIView(uintptr(uiview))
|
||||||
|
}
|
||||||
|
|
||||||
|
func IsGL() bool {
|
||||||
|
return ui.IsGL()
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user