-
Notifications
You must be signed in to change notification settings - Fork 39
Allow multiple AVPlayer instances, use TextureView instead of SurfaceView #406
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 15 commits
7af62d5
e79526f
386da87
7de952f
fb83da8
075ea96
0682578
e944e76
6755211
df0dfdd
34ab8b6
837ae6d
c26d2a0
3627800
44660d0
527c1f1
7144965
7bb7a2e
634d8ef
faade08
d77c6fb
84ad4b5
810987b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -43,12 +43,34 @@ public class CGImage { | |
| var data = sourceData | ||
|
|
||
| guard let gpuImagePtr = data.withUnsafeMutableBytes({ buffer -> UnsafeMutablePointer<GPU_Image>? in | ||
| guard let ptr = buffer.baseAddress?.assumingMemoryBound(to: Int8.self) else { | ||
| return nil | ||
| var width: Int32 = 0 | ||
| var height: Int32 = 0 | ||
| var channels: Int32 = 4 | ||
|
|
||
| #if os(Android) | ||
| // Android natively supports 2-channel textures. Use them to save 50% (GPU) RAM. | ||
| let data = stbi_load_from_memory(buffer.baseAddress, Int32(buffer.count), &width, &height, &channels, 0) | ||
|
|
||
| let format: GPU_FormatEnum = switch channels { | ||
| case 1: GPU_FORMAT_ALPHA | ||
| case 2: GPU_FORMAT_LUMINANCE_ALPHA | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @michaelknoch FYI in theory GPU_FORMAT_LUMINANCE_ALPHA (and GPU_FORMAT_ALPHA) is not supported in OpenGLES in versions 3+. So this "should" not work on newer devices. In practice I saw that Android emulates OpenGLES2 in these cases, so it works. I don't think it's problematic, but I wanted to mention it. I didn't immediately find a way to see if this device is running OpenGLES2 vs OpenGLES3 – if we can find that we could also fall back to using 4-channel textures in that case. But let's see if it's actually a problem first |
||
| case 3: GPU_FORMAT_RGB | ||
| case 4: GPU_FORMAT_RGBA | ||
| default: fatalError() | ||
| } | ||
|
|
||
| let rw = SDL_RWFromMem(ptr, Int32(buffer.count)) | ||
| return GPU_LoadImage_RW(rw, true) | ||
| #elseif os(macOS) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i'm not sure we need |
||
| // OpenGL on macOS does not natively support 2-channel textures (`unit 0 GLD_TEXTURE_INDEX_2D is unloadable`). | ||
| // Instead, force `stb_image` to load all images as if they had 4 channels. | ||
| // This is more compatible, but requires more memory. | ||
| let data = stbi_load_from_memory(buffer.baseAddress, Int32(buffer.count), &width, &height, nil, channels) | ||
| let format = GPU_FORMAT_RGBA | ||
| #endif | ||
|
|
||
| let img = GPU_CreateImage(UInt16(width), UInt16(height), format) | ||
| GPU_UpdateImageBytes(img, nil, data, width * channels) | ||
| data?.deallocate() | ||
|
|
||
| return img | ||
| }) else { return nil } | ||
|
|
||
| self.init(gpuImagePtr, sourceData: data) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@michaelknoch this is kind of an open question to you I think. We don't need to answer it right now but I it did confuse me that we create a new presentation layer on every frame – is that how iOS works?