diff --git a/librashader-runtime-d3d9/src/filter_chain.rs b/librashader-runtime-d3d9/src/filter_chain.rs index ffdb010..9a0916e 100644 --- a/librashader-runtime-d3d9/src/filter_chain.rs +++ b/librashader-runtime-d3d9/src/filter_chain.rs @@ -23,7 +23,7 @@ use librashader_reflect::reflect::semantics::ShaderSemantics; use librashader_reflect::reflect::ReflectShader; use librashader_runtime::binding::{BindingUtil, TextureInput}; use librashader_runtime::framebuffer::FramebufferInit; -use librashader_runtime::image::{Image, ImageError, UVDirection, ARGB8}; +use librashader_runtime::image::{Image, ImageError, UVDirection, ARGB8, BGRA8}; use librashader_runtime::quad::QuadType; use librashader_runtime::render_target::RenderTarget; use librashader_runtime::scaling::ScaleFramebuffer; @@ -190,7 +190,7 @@ impl FilterChainD3D9 { let images = textures .iter() .map(|texture| Image::load(&texture.path, UVDirection::TopLeft)) - .collect::>, ImageError>>()?; + .collect::>, ImageError>>()?; for (index, (texture, image)) in textures.iter().zip(images).enumerate() { let texture = LutTexture::new(device, &image, &texture)?; diff --git a/librashader-runtime-d3d9/src/luts.rs b/librashader-runtime-d3d9/src/luts.rs index d9e9f11..fa4493c 100644 --- a/librashader-runtime-d3d9/src/luts.rs +++ b/librashader-runtime-d3d9/src/luts.rs @@ -3,7 +3,7 @@ use crate::error::assume_d3d_init; use crate::texture::D3D9InputTexture; use librashader_presets::TextureConfig; -use librashader_runtime::image::{Image, ARGB8}; +use librashader_runtime::image::{Image, ARGB8, BGRA8}; use windows::Win32::Graphics::Direct3D9::{ IDirect3DDevice9, D3DFMT_A8R8G8B8, D3DLOCKED_RECT, D3DPOOL_MANAGED, @@ -21,7 +21,7 @@ impl AsRef for LutTexture { impl LutTexture { pub fn new( device: &IDirect3DDevice9, - source: &Image, + source: &Image, config: &TextureConfig, ) -> error::Result { let mut texture = None; diff --git a/librashader-runtime-d3d9/tests/hello_triangle/mod.rs b/librashader-runtime-d3d9/tests/hello_triangle/mod.rs index 112d23a..e7dae07 100644 --- a/librashader-runtime-d3d9/tests/hello_triangle/mod.rs +++ b/librashader-runtime-d3d9/tests/hello_triangle/mod.rs @@ -195,10 +195,10 @@ pub mod d3d9_hello_triangle { use std::path::{Path, PathBuf}; use librashader_common::{GetSize, Viewport}; - use librashader_runtime::quad::IDENTITY_MVP; use librashader_runtime_d3d9::options::FilterChainOptionsD3D9; use librashader_runtime_d3d9::FilterChainD3D9; use std::time::Instant; + use librashader_runtime::image::{Image, UVDirection, ARGB8, BGRA8, RGBA8}; pub struct Sample { pub direct3d: IDirect3D9, @@ -230,6 +230,7 @@ pub mod d3d9_hello_triangle { // pub deferred_context: ID3D11DeviceContext, pub vbo: IDirect3DVertexBuffer9, pub vao: IDirect3DVertexDeclaration9, + pub texture: IDirect3DTexture9, } impl Sample { @@ -284,6 +285,38 @@ pub mod d3d9_hello_triangle { tex.unwrap() }; + const IMAGE_PATH: &str = "../triangle.png"; + + let image = Image::::load(IMAGE_PATH, UVDirection::TopLeft) + .expect("triangle.png not found"); + + let texture = unsafe { + let mut texture = None; + device.CreateTexture( + image.size.width, + image.size.height, + 1, + 0, + D3DFMT_A8R8G8B8, + D3DPOOL_MANAGED, + &mut texture, + std::ptr::null_mut(), + )?; + + texture.unwrap() + }; + + unsafe { + let mut lock = D3DLOCKED_RECT::default(); + texture.LockRect(0, &mut lock, std::ptr::null_mut(), 0)?; + std::ptr::copy_nonoverlapping( + image.bytes.as_ptr(), + lock.pBits.cast(), + image.bytes.len(), + ); + texture.UnlockRect(0)?; + } + self.resources = Some(Resources { device, filter, @@ -292,18 +325,7 @@ pub mod d3d9_hello_triangle { frame_end: Instant::now(), frame_start: Instant::now(), elapsed: 0f32, - // renderbuffer, - // renderbufffer_rtv: render_rtv, - // deferred_context: context, - // viewport: D3D11_VIEWPORT { - // TopLeftX: 0.0, - // TopLeftY: 0.0, - // Width: WIDTH as f32, - // Height: HEIGHT as f32, - // MinDepth: D3D11_MIN_DEPTH, - // MaxDepth: D3D11_MAX_DEPTH, - // }, - // shader_output: None, + texture, frame_count: 0usize, renderbuffer, }); @@ -348,68 +370,68 @@ pub mod d3d9_hello_triangle { // resources.triangle_uniform_values.model_matrix = Mat4::rotate(Quaternion::axis_angle(Vec3::new(0.0, 0.0, 1.0), resources.elapsed)); unsafe { - resources - .device - .SetTransform(D3DTS_PROJECTION, IDENTITY_MVP.as_ptr().cast())?; - resources - .device - .SetTransform(D3DTS_VIEW, IDENTITY_MVP.as_ptr().cast())?; - resources - .device - .SetTransform(D3DTRANSFORMSTATETYPE(256), IDENTITY_MVP.as_ptr().cast())?; - - let rendertarget = resources.renderbuffer.GetSurfaceLevel(0).unwrap(); - + // resources + // .device + // .SetTransform(D3DTS_PROJECTION, IDENTITY_MVP.as_ptr().cast())?; + // resources + // .device + // .SetTransform(D3DTS_VIEW, IDENTITY_MVP.as_ptr().cast())?; + // resources + // .device + // .SetTransform(D3DTRANSFORMSTATETYPE(256), IDENTITY_MVP.as_ptr().cast())?; + // + // let rendertarget = resources.renderbuffer.GetSurfaceLevel(0).unwrap(); + // let backbuffer = resources .device .GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO)?; + // + // resources.device.SetRenderTarget(0, &rendertarget)?; - resources.device.SetRenderTarget(0, &rendertarget)?; + // resources.device.Clear( + // 0, + // std::ptr::null_mut(), + // D3DCLEAR_TARGET as u32, + // 0xFF4d6699, + // 0.0, + // 0, + // )?; - resources.device.Clear( - 0, - std::ptr::null_mut(), - D3DCLEAR_TARGET as u32, - 0xFF4d6699, - 0.0, - 0, - )?; - - resources.device.BeginScene()?; - - resources.device.SetStreamSource( - 0, - &resources.vbo, - 0, - std::mem::size_of::() as u32, - )?; - resources.device.SetVertexDeclaration(&resources.vao)?; - - resources - .device - .SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE.0 as u32)?; - resources - .device - .SetRenderState(D3DRS_CLIPPING, FALSE.0 as u32)?; - resources - .device - .SetRenderState(D3DRS_ZFUNC, D3DCMP_ALWAYS.0 as u32)?; - - resources - .device - .SetRenderState(D3DRS_ZENABLE, FALSE.0 as u32)?; - resources - .device - .SetRenderState(D3DRS_LIGHTING, FALSE.0 as u32)?; - - resources.device.DrawPrimitive(D3DPT_TRIANGLELIST, 0, 1)?; - - resources.device.EndScene()?; + // resources.device.BeginScene()?; + // + // resources.device.SetStreamSource( + // 0, + // &resources.vbo, + // 0, + // std::mem::size_of::() as u32, + // )?; + // resources.device.SetVertexDeclaration(&resources.vao)?; + // + // resources + // .device + // .SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE.0 as u32)?; + // resources + // .device + // .SetRenderState(D3DRS_CLIPPING, FALSE.0 as u32)?; + // resources + // .device + // .SetRenderState(D3DRS_ZFUNC, D3DCMP_ALWAYS.0 as u32)?; + // + // resources + // .device + // .SetRenderState(D3DRS_ZENABLE, FALSE.0 as u32)?; + // resources + // .device + // .SetRenderState(D3DRS_LIGHTING, FALSE.0 as u32)?; + // + // resources.device.DrawPrimitive(D3DPT_TRIANGLELIST, 0, 1)?; + // + // resources.device.EndScene()?; resources .filter .frame( - resources.renderbuffer.clone(), + resources.texture.clone(), &Viewport { x: 0.0, y: 0.0,