mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +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
|
||||
}
|
||||
|
||||
func forceGL() bool {
|
||||
for _, tag := range strings.Split(*tags, ",") {
|
||||
if tag == "ebitengl" {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func run() error {
|
||||
writeFile := func(filename string, content string) error {
|
||||
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, "{{.PrefixLower}}", prefixLower)
|
||||
content = strings.ReplaceAll(content, "{{.JavaPkg}}", *javaPkg)
|
||||
|
||||
f := "0"
|
||||
if forceGL() {
|
||||
f = "1"
|
||||
}
|
||||
content = strings.ReplaceAll(content, "{{.ForceGL}}", f)
|
||||
return content
|
||||
}
|
||||
|
||||
@ -158,12 +143,6 @@ const objcM = `// Code generated by ebitenmobile. DO NOT EDIT.
|
||||
|
||||
#import <TargetConditionals.h>
|
||||
|
||||
#if TARGET_IPHONE_SIMULATOR || {{.ForceGL}}
|
||||
#define EBITEN_METAL 0
|
||||
#else
|
||||
#define EBITEN_METAL 1
|
||||
#endif
|
||||
|
||||
#import <stdint.h>
|
||||
#import <UIKit/UIKit.h>
|
||||
#import <GLKit/GLkit.h>
|
||||
@ -209,18 +188,18 @@ const objcM = `// Code generated by ebitenmobile. DO NOT EDIT.
|
||||
started_ = true;
|
||||
}
|
||||
|
||||
#if EBITEN_METAL
|
||||
[self.view addSubview: self.metalView];
|
||||
EbitenmobileviewSetUIView((uintptr_t)(self.metalView));
|
||||
#else
|
||||
self.glkView.delegate = (id<GLKViewDelegate>)(self);
|
||||
[self.view addSubview: self.glkView];
|
||||
if (EbitenmobileviewIsGL()) {
|
||||
self.glkView.delegate = (id<GLKViewDelegate>)(self);
|
||||
[self.view addSubview: self.glkView];
|
||||
|
||||
EAGLContext *context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
|
||||
[self glkView].context = context;
|
||||
EAGLContext *context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
|
||||
[self glkView].context = context;
|
||||
|
||||
[EAGLContext setCurrentContext:context];
|
||||
#endif
|
||||
[EAGLContext setCurrentContext:context];
|
||||
} else {
|
||||
[self.view addSubview: self.metalView];
|
||||
EbitenmobileviewSetUIView((uintptr_t)(self.metalView));
|
||||
}
|
||||
|
||||
displayLink_ = [CADisplayLink displayLinkWithTarget:self selector:@selector(drawFrame)];
|
||||
[displayLink_ addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
|
||||
@ -229,11 +208,11 @@ const objcM = `// Code generated by ebitenmobile. DO NOT EDIT.
|
||||
|
||||
- (void)viewWillLayoutSubviews {
|
||||
CGRect viewRect = [[self view] frame];
|
||||
#if EBITEN_METAL
|
||||
[[self metalView] setFrame:viewRect];
|
||||
#else
|
||||
[[self glkView] setFrame:viewRect];
|
||||
#endif
|
||||
if (EbitenmobileviewIsGL()) {
|
||||
[[self glkView] setFrame:viewRect];
|
||||
} else {
|
||||
[[self metalView] setFrame:viewRect];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)viewDidLayoutSubviews {
|
||||
@ -255,11 +234,11 @@ const objcM = `// Code generated by ebitenmobile. DO NOT EDIT.
|
||||
return;
|
||||
}
|
||||
|
||||
#if EBITEN_METAL
|
||||
[self updateEbiten];
|
||||
#else
|
||||
[[self glkView] setNeedsDisplay];
|
||||
#endif
|
||||
if (EbitenmobileviewIsGL()) {
|
||||
[[self glkView] setNeedsDisplay];
|
||||
} else {
|
||||
[self updateEbiten];
|
||||
}
|
||||
|
||||
if (explicitRendering_) {
|
||||
[displayLink_ setPaused:YES];
|
||||
@ -293,15 +272,15 @@ const objcM = `// Code generated by ebitenmobile. DO NOT EDIT.
|
||||
|
||||
- (void)updateTouches:(NSSet*)touches {
|
||||
for (UITouch* touch in touches) {
|
||||
#if EBITEN_METAL
|
||||
if (touch.view != [self metalView]) {
|
||||
continue;
|
||||
if (EbitenmobileviewIsGL()) {
|
||||
if (touch.view != [self glkView]) {
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
if (touch.view != [self metalView]) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
#else
|
||||
if (touch.view != [self glkView]) {
|
||||
continue;
|
||||
}
|
||||
#endif
|
||||
CGPoint location = [touch locationInView:touch.view];
|
||||
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 (
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver/metal"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver/opengl"
|
||||
)
|
||||
|
||||
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()
|
||||
}
|
@ -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");
|
||||
// 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
|
||||
// limitations under the License.
|
||||
|
||||
//go:build (darwin && ios && arm) || (darwin && ios && arm64)
|
||||
// +build darwin,ios,arm darwin,ios,arm64
|
||||
//go:build ios
|
||||
// +build ios
|
||||
|
||||
package ebitenmobileview
|
||||
package ui
|
||||
|
||||
import (
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver/metal"
|
||||
)
|
||||
|
||||
func SetUIView(uiview int64) {
|
||||
metal.Get().SetUIView(uintptr(uiview))
|
||||
func SetUIView(uiview uintptr) {
|
||||
// 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 IsGL() bool {
|
||||
return theUI.graphicsDriver.IsGL()
|
||||
}
|
@ -12,15 +12,19 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//go:build darwin && ios && !arm && !arm64
|
||||
// +build darwin,ios,!arm,!arm64
|
||||
//go:build ios
|
||||
// +build ios
|
||||
|
||||
package ebitenmobileview
|
||||
|
||||
import (
|
||||
"runtime"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/ui"
|
||||
)
|
||||
|
||||
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