mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
Compare commits
No commits in common. "4a10702f6c39279c2d4613f12622046399a3eecd" and "5fe818e17d77708f14639003df1126e0a80b901f" have entirely different histories.
4a10702f6c
...
5fe818e17d
53
image.go
53
image.go
@ -554,32 +554,30 @@ func (i *Image) DrawTriangles(vertices []Vertex, indices []uint16, img *Image, o
|
||||
vs := i.ensureTmpVertices(len(vertices) * graphics.VertexFloatCount)
|
||||
dst := i
|
||||
if options.ColorScaleMode == ColorScaleModeStraightAlpha {
|
||||
// Avoid using `for i, v := range vertices` as adding `v` creates a copy from `vertices` unnecessarily on each loop (#3103).
|
||||
for i := range vertices {
|
||||
dx, dy := dst.adjustPositionF32(vertices[i].DstX, vertices[i].DstY)
|
||||
for i, v := range vertices {
|
||||
dx, dy := dst.adjustPositionF32(v.DstX, v.DstY)
|
||||
vs[i*graphics.VertexFloatCount] = dx
|
||||
vs[i*graphics.VertexFloatCount+1] = dy
|
||||
sx, sy := img.adjustPositionF32(vertices[i].SrcX, vertices[i].SrcY)
|
||||
sx, sy := img.adjustPositionF32(v.SrcX, v.SrcY)
|
||||
vs[i*graphics.VertexFloatCount+2] = sx
|
||||
vs[i*graphics.VertexFloatCount+3] = sy
|
||||
vs[i*graphics.VertexFloatCount+4] = vertices[i].ColorR * vertices[i].ColorA * cr
|
||||
vs[i*graphics.VertexFloatCount+5] = vertices[i].ColorG * vertices[i].ColorA * cg
|
||||
vs[i*graphics.VertexFloatCount+6] = vertices[i].ColorB * vertices[i].ColorA * cb
|
||||
vs[i*graphics.VertexFloatCount+7] = vertices[i].ColorA * ca
|
||||
vs[i*graphics.VertexFloatCount+4] = v.ColorR * v.ColorA * cr
|
||||
vs[i*graphics.VertexFloatCount+5] = v.ColorG * v.ColorA * cg
|
||||
vs[i*graphics.VertexFloatCount+6] = v.ColorB * v.ColorA * cb
|
||||
vs[i*graphics.VertexFloatCount+7] = v.ColorA * ca
|
||||
}
|
||||
} else {
|
||||
// See comment above (#3103).
|
||||
for i := range vertices {
|
||||
dx, dy := dst.adjustPositionF32(vertices[i].DstX, vertices[i].DstY)
|
||||
for i, v := range vertices {
|
||||
dx, dy := dst.adjustPositionF32(v.DstX, v.DstY)
|
||||
vs[i*graphics.VertexFloatCount] = dx
|
||||
vs[i*graphics.VertexFloatCount+1] = dy
|
||||
sx, sy := img.adjustPositionF32(vertices[i].SrcX, vertices[i].SrcY)
|
||||
sx, sy := img.adjustPositionF32(v.SrcX, v.SrcY)
|
||||
vs[i*graphics.VertexFloatCount+2] = sx
|
||||
vs[i*graphics.VertexFloatCount+3] = sy
|
||||
vs[i*graphics.VertexFloatCount+4] = vertices[i].ColorR * cr
|
||||
vs[i*graphics.VertexFloatCount+5] = vertices[i].ColorG * cg
|
||||
vs[i*graphics.VertexFloatCount+6] = vertices[i].ColorB * cb
|
||||
vs[i*graphics.VertexFloatCount+7] = vertices[i].ColorA * ca
|
||||
vs[i*graphics.VertexFloatCount+4] = v.ColorR * cr
|
||||
vs[i*graphics.VertexFloatCount+5] = v.ColorG * cg
|
||||
vs[i*graphics.VertexFloatCount+6] = v.ColorB * cb
|
||||
vs[i*graphics.VertexFloatCount+7] = v.ColorA * ca
|
||||
}
|
||||
}
|
||||
is := i.ensureTmpIndices(len(indices))
|
||||
@ -720,25 +718,24 @@ func (i *Image) DrawTrianglesShader(vertices []Vertex, indices []uint16, shader
|
||||
vs := i.ensureTmpVertices(len(vertices) * graphics.VertexFloatCount)
|
||||
dst := i
|
||||
src := options.Images[0]
|
||||
// Avoid using `for i, v := range vertices` as adding `v` creates a copy from `vertices` unnecessarily on each loop (#3103).
|
||||
for i := range vertices {
|
||||
dx, dy := dst.adjustPositionF32(vertices[i].DstX, vertices[i].DstY)
|
||||
for i, v := range vertices {
|
||||
dx, dy := dst.adjustPositionF32(v.DstX, v.DstY)
|
||||
vs[i*graphics.VertexFloatCount] = dx
|
||||
vs[i*graphics.VertexFloatCount+1] = dy
|
||||
sx, sy := vertices[i].SrcX, vertices[i].SrcY
|
||||
sx, sy := v.SrcX, v.SrcY
|
||||
if src != nil {
|
||||
sx, sy = src.adjustPositionF32(sx, sy)
|
||||
}
|
||||
vs[i*graphics.VertexFloatCount+2] = sx
|
||||
vs[i*graphics.VertexFloatCount+3] = sy
|
||||
vs[i*graphics.VertexFloatCount+4] = vertices[i].ColorR
|
||||
vs[i*graphics.VertexFloatCount+5] = vertices[i].ColorG
|
||||
vs[i*graphics.VertexFloatCount+6] = vertices[i].ColorB
|
||||
vs[i*graphics.VertexFloatCount+7] = vertices[i].ColorA
|
||||
vs[i*graphics.VertexFloatCount+8] = vertices[i].Custom0
|
||||
vs[i*graphics.VertexFloatCount+9] = vertices[i].Custom1
|
||||
vs[i*graphics.VertexFloatCount+10] = vertices[i].Custom2
|
||||
vs[i*graphics.VertexFloatCount+11] = vertices[i].Custom3
|
||||
vs[i*graphics.VertexFloatCount+4] = v.ColorR
|
||||
vs[i*graphics.VertexFloatCount+5] = v.ColorG
|
||||
vs[i*graphics.VertexFloatCount+6] = v.ColorB
|
||||
vs[i*graphics.VertexFloatCount+7] = v.ColorA
|
||||
vs[i*graphics.VertexFloatCount+8] = v.Custom0
|
||||
vs[i*graphics.VertexFloatCount+9] = v.Custom1
|
||||
vs[i*graphics.VertexFloatCount+10] = v.Custom2
|
||||
vs[i*graphics.VertexFloatCount+11] = v.Custom3
|
||||
}
|
||||
|
||||
is := i.ensureTmpIndices(len(indices))
|
||||
|
@ -119,7 +119,7 @@ func (*graphicsDriverCreatorImpl) newPlayStation5() (graphicsdriver.Graphics, er
|
||||
return nil, errors.New("ui: PlayStation 5 is not supported in this environment")
|
||||
}
|
||||
|
||||
func (u *UserInterface) deviceScaleFactor() float64 {
|
||||
func deviceScaleFactorImpl() float64 {
|
||||
var s float64
|
||||
if err := app.RunOnJVM(func(vm, env, ctx uintptr) error {
|
||||
// TODO: This might be crash when this is called from init(). How can we detect this?
|
||||
|
@ -19,31 +19,8 @@ package ui
|
||||
//
|
||||
// #import <UIKit/UIKit.h>
|
||||
//
|
||||
// static double devicePixelRatioOnMainThread(UIView* view) {
|
||||
// UIWindow* window = view.window;
|
||||
// if (!window) {
|
||||
// return 1;
|
||||
// }
|
||||
// UIWindowScene* scene = window.windowScene;
|
||||
// if (!scene) {
|
||||
// return 1;
|
||||
// }
|
||||
// return scene.screen.nativeScale;
|
||||
// }
|
||||
//
|
||||
// static double devicePixelRatio(uintptr_t viewPtr) {
|
||||
// if (!viewPtr) {
|
||||
// return 1;
|
||||
// }
|
||||
// UIView* view = (__bridge UIView*)(void*)viewPtr;
|
||||
// if ([NSThread isMainThread]) {
|
||||
// return devicePixelRatioOnMainThread(view);
|
||||
// }
|
||||
// __block double scale;
|
||||
// dispatch_sync(dispatch_get_main_queue(), ^{
|
||||
// scale = devicePixelRatioOnMainThread(view);
|
||||
// });
|
||||
// return scale;
|
||||
// static double devicePixelRatio() {
|
||||
// return [[UIScreen mainScreen] nativeScale];
|
||||
// }
|
||||
import "C"
|
||||
|
||||
@ -89,7 +66,6 @@ func (*graphicsDriverCreatorImpl) newPlayStation5() (graphicsdriver.Graphics, er
|
||||
}
|
||||
|
||||
func (u *UserInterface) SetUIView(uiview uintptr) error {
|
||||
u.uiView.Store(uiview)
|
||||
select {
|
||||
case err := <-u.errCh:
|
||||
return err
|
||||
@ -113,8 +89,9 @@ func (u *UserInterface) IsGL() (bool, error) {
|
||||
return u.GraphicsLibrary() == GraphicsLibraryOpenGL, nil
|
||||
}
|
||||
|
||||
func (u *UserInterface) deviceScaleFactor() float64 {
|
||||
return float64(C.devicePixelRatio(C.uintptr_t(u.uiView.Load())))
|
||||
func deviceScaleFactorImpl() float64 {
|
||||
// TODO: Can this be called from non-main threads?
|
||||
return float64(C.devicePixelRatio())
|
||||
}
|
||||
|
||||
func dipToNativePixels(x float64, scale float64) float64 {
|
||||
|
@ -104,9 +104,6 @@ type userInterfaceImpl struct {
|
||||
strictContextRestoration atomic.Bool
|
||||
strictContextRestorationOnce sync.Once
|
||||
|
||||
// uiView is used only on iOS.
|
||||
uiView atomic.Uintptr
|
||||
|
||||
m sync.RWMutex
|
||||
}
|
||||
|
||||
@ -288,7 +285,7 @@ func (m *Monitor) DeviceScaleFactor() float64 {
|
||||
// Initialize this lazily.
|
||||
m.deviceScaleFactorOnce.Do(func() {
|
||||
// Assume that the device scale factor never changes on mobiles.
|
||||
m.deviceScaleFactor = theUI.deviceScaleFactor()
|
||||
m.deviceScaleFactor = deviceScaleFactorImpl()
|
||||
})
|
||||
return m.deviceScaleFactor
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user