Skip to content

Commit

Permalink
Update for alpha_mode PR test: gfx-rs/wgpu#2836
Browse files Browse the repository at this point in the history
  • Loading branch information
jinleili committed Jul 2, 2022
1 parent 65b22f4 commit f865a3f
Show file tree
Hide file tree
Showing 18 changed files with 113 additions and 90 deletions.
9 changes: 6 additions & 3 deletions Android/app/src/main/java/name/jinleili/wgpu/MainActivity.kt
@@ -1,5 +1,6 @@
package name.jinleili.wgpu

import android.graphics.Color
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
Expand All @@ -11,6 +12,7 @@ import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalConfiguration
import androidx.compose.ui.res.colorResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
Expand All @@ -26,7 +28,8 @@ class MainActivity : ComponentActivity() {
MyApplicationTheme {
Surface(
modifier = Modifier.fillMaxSize(),
color = MaterialTheme.colors.background
color = colorResource(id = R.color.teal_700)
// color = colorResource(id = R.color.transparent)
) {
SurfaceCard()
}
Expand Down Expand Up @@ -84,7 +87,7 @@ fun SurfaceCard() {
sv
}, modifier = Modifier
.fillMaxWidth()
.height(screenWidth)
)
.height(screenWidth),
)
}
}
Expand Up @@ -2,6 +2,7 @@ package name.jinleili.wgpu

import android.content.Context
import android.graphics.Canvas
import android.graphics.PixelFormat
import android.util.AttributeSet
import android.view.SurfaceHolder
import android.view.SurfaceView
Expand All @@ -26,8 +27,10 @@ class WGPUSurfaceView : SurfaceView, SurfaceHolder.Callback2 {

init {
holder.addCallback(this)
println("fda init")

// The only way to set SurfaceView background color to transparent:
// https://groups.google.com/g/android-developers/c/jYjvm7ItpXQ?pli=1
this.setZOrderOnTop(true)
holder.setFormat(PixelFormat.TRANSPARENT)
}

override fun surfaceChanged(holder: SurfaceHolder, format: Int, width: Int, height: Int) {
Expand Down
2 changes: 2 additions & 0 deletions Android/app/src/main/res/values/colors.xml
Expand Up @@ -7,4 +7,6 @@
<color name="teal_700">#FF018786</color>
<color name="black">#FF000000</color>
<color name="white">#FFFFFFFF</color>
<color name="transparent">#00000000</color>

</resources>
84 changes: 45 additions & 39 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Expand Up @@ -21,8 +21,8 @@ log = "0.4"
noise = { version = "0.7", default-features = false }
pollster = "0.2"
rand = { version = "0.7.2" }
wgpu = { git = "https://github.com/gfx-rs/wgpu", rev = "aba7197f" }
# wgpu = {git = "https://github.com/jinleili/wgpu", rev = "2010fbbe"}
# wgpu = { git = "https://github.com/gfx-rs/wgpu", rev = "aba7197f" }
wgpu = { git = "https://github.com/jinleili/wgpu", rev = "3acbfc83" }
# wgpu = { path = "../../forks/wgpu/wgpu" }

[target.'cfg(any(not(target_os = "ios"), not(target_os = "android")))'.dependencies]
Expand Down
4 changes: 2 additions & 2 deletions app-surface/Cargo.toml
Expand Up @@ -17,8 +17,8 @@ default = []
[dependencies]
log = "0.4"
pollster = "0.2"
wgpu = { git = "https://github.com/gfx-rs/wgpu", rev = "aba7197f" }
# wgpu = { git = "https://github.com/cwfitzgerald/wgpu", branch = "fix-sampling-usage" }
# wgpu = { git = "https://github.com/gfx-rs/wgpu", rev = "aba7197f" }
wgpu = { git = "https://github.com/jinleili/wgpu", rev = "3acbfc83" }
# wgpu = { path = "../../../forks/wgpu/wgpu" }

[target.'cfg(any(not(target_os = "ios"), not(target_os = "android")))'.dependencies]
Expand Down
2 changes: 2 additions & 0 deletions app-surface/src/android.rs
Expand Up @@ -31,6 +31,8 @@ impl AppSurface {
width: native_window.get_width(),
height: native_window.get_height(),
present_mode: wgpu::PresentMode::Fifo,
alpha_mode: wgpu::CompositeAlphaMode::PreMultiplied,
// alpha_mode: wgpu::CompositeAlphaMode::PostMultiplied,
};
surface.configure(&device, &config);

Expand Down
5 changes: 3 additions & 2 deletions app-surface/src/app_surface.rs
Expand Up @@ -22,10 +22,11 @@ impl AppSurface {
let config = wgpu::SurfaceConfiguration {
usage: wgpu::TextureUsages::RENDER_ATTACHMENT,
// format: wgpu::TextureFormat::Bgra8UnormSrgb,
format: surface.get_preferred_format(&adapter).unwrap(),
format: surface.get_supported_formats(&adapter)[0],
width: physical.width as u32,
height: physical.height as u32,
present_mode: wgpu::PresentMode::Mailbox,
present_mode: wgpu::PresentMode::Fifo,
alpha_mode: wgpu::CompositeAlphaMode::PreMultiplied,
};
surface.configure(&device, &config);
AppSurface {
Expand Down
1 change: 1 addition & 0 deletions iOS/base/MetalView.swift
Expand Up @@ -15,6 +15,7 @@ class MetalView: UIView {
override func awakeFromNib() {
super.awakeFromNib()
configLayer()
self.layer.backgroundColor = UIColor.clear.cgColor
}

private func configLayer() {
Expand Down
1 change: 1 addition & 0 deletions iOS/base/ViewController.swift
Expand Up @@ -23,6 +23,7 @@ class ViewController: UIViewController {

override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
self.view.backgroundColor = .blue
if wgpuCanvas == nil {
let viewPointer = UnsafeMutableRawPointer(Unmanaged.passRetained(self.metalV).toOpaque())
let metalLayer = UnsafeMutableRawPointer(Unmanaged.passRetained(self.metalV.layer).toOpaque())
Expand Down
Binary file not shown.
19 changes: 11 additions & 8 deletions src/examples/boids.rs
Expand Up @@ -30,13 +30,13 @@ impl Boids {
let config = &app_surface.config;
let device = &app_surface.device;

let compute_shader = device.create_shader_module(&wgpu::ShaderModuleDescriptor {
let compute_shader = device.create_shader_module(wgpu::ShaderModuleDescriptor {
label: None,
source: wgpu::ShaderSource::Wgsl(Cow::Borrowed(include_str!(
"../../wgsl_shader/compute.wgsl"
))),
});
let draw_shader = device.create_shader_module(&wgpu::ShaderModuleDescriptor {
let draw_shader = device.create_shader_module(wgpu::ShaderModuleDescriptor {
label: None,
source: wgpu::ShaderSource::Wgsl(Cow::Borrowed(include_str!(
"../../wgsl_shader/draw.wgsl"
Expand Down Expand Up @@ -131,7 +131,7 @@ impl Boids {
fragment: Some(wgpu::FragmentState {
module: &draw_shader,
entry_point: "main_fs",
targets: &[config.format.into()],
targets: &[Some(config.format.into())],
}),
primitive: wgpu::PrimitiveState::default(),
depth_stencil: None,
Expand Down Expand Up @@ -232,16 +232,19 @@ impl Example for Boids {
let (frame, view) = app_surface.get_current_frame_view();
{
// create render pass descriptor and its color attachments
let color_attachments = [wgpu::RenderPassColorAttachment {
let color_attachments = [Some(wgpu::RenderPassColorAttachment {
view: &view,
resolve_target: None,
ops: wgpu::Operations {
// Not clearing here in order to test wgpu's zero texture initialization on a surface texture.
// Users should avoid loading uninitialized memory since this can cause additional overhead.
load: wgpu::LoadOp::Clear(wgpu::Color::TRANSPARENT),
load: wgpu::LoadOp::Clear(wgpu::Color {
r: 0.0,
g: 0.0,
b: 0.0,
a: 0.1,
}),
store: true,
},
}];
})];
let render_pass_descriptor = wgpu::RenderPassDescriptor {
label: None,
color_attachments: &color_attachments,
Expand Down

0 comments on commit f865a3f

Please sign in to comment.