- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在关注 a tutorial on the gfx library .以下代码用于初始化窗口系统,它使用隐式类型绑定(bind)返回各种位。
let (window, mut device, mut factory, color_view, mut depth_view) =
gfx_glutin::init::<ColorFormat, DepthFormat>(windowbuilder, contextbuilder, &events_loop);
为了可读性,我决定尝试将教程中的绘图代码提取到它自己的函数中。
fn draw_triangle(factory: &Factory) {
let mut encoder: gfx::Encoder<_, _> = factory.create_command_buffer().into();
const TRIANGLE: [Vertex; 3] = [
Vertex {
pos: [-0.5, -0.5, 0.0, 1.0],
color: [1.0, 0.0, 0.0],
},
Vertex {
pos: [0.5, -0.5, 0.0, 1.0],
color: [0.0, 1.0, 0.0],
},
Vertex {
pos: [0.0, 0.5, 0.0, 1.0],
color: [0.0, 0.0, 1.0],
},
];
//Identity Matrix
const TRANSFORM: Transform = Transform {
transform: [
[1.0, 0.0, 0.0, 0.0],
[0.0, 1.0, 0.0, 0.0],
[0.0, 0.0, 1.0, 0.0],
[0.0, 0.0, 0.0, 1.0],
],
};
let (vertex_buffer, slice) = factory.create_vertex_buffer_with_slice(&TRIANGLE, ());
let transform_buffer = factory.create_constant_buffer(1);
let data = pipe::Data {
vbuf: vertex_buffer,
transform: transform_buffer,
out: color_view.clone(),
};
//Put in main loop before swap buffers and device clean-up method
encoder.clear(&color_view, BLACK); //clear the framebuffer with a color(color needs to be an array of 4 f32s, RGBa)
encoder.update_buffer(&data.transform, &[TRANSFORM], 0); //update buffers
encoder.draw(&slice, &pso, &data); // draw commands with buffer data and attached pso
encoder.flush(&mut device); // execute draw commands
}
这里的问题是 Factory
(从第一个代码片段传入)不存在于该文件的范围内,实际上属于存在于 gfx_glutin_window crate 中的 crate。
编译器很高兴在第一段代码中隐式定义它,但看起来我不能在不声明对所述 crate 的硬依赖的情况下显式引用它。 (即我无法通过 gfx_glutin_window crate 获取它)。
我不确定我是否完全没有注意到这里的标记,或者这是否是设计使然。尽管我可以想象在这种情况下项目依赖项与 transient 依赖项发生冲突的场景。
最佳答案
一方面,gfx_window_glutin
确实可能会受益于重新导出数据类型,因为它的公共(public) API 正在有效地返回这些类型的实例。这以前在其他 crate 中发生过,例如 pathfinder
re-exporting num_traits
,并且可以通过在主存储库中提交问题来提出类似于 gfx_window_glutin
的内容。
另一方面,实际上建议构建在 Gfx 后端实现上通用的代码。两者 Factory
和 Resources
是封装底层实现的特征类型,因此您应该在代码中使用这些约束。
use gfx::{Factory, Resources};
fn draw_triangle<R, F>(factory : &F)
where
R: Resources,
F: Factory<R>
{
// ...
}
关于rust - 从前端包中的包引用 Gfx 后端类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47412199/
我想通过将帧划分为 8x8 子 block 并将当前帧的每个 block 与前 10 帧的相邻 block 进行比较,从前 10 帧中找到运动矢量。 我可以用单帧进行操作,但我觉得很难处理 N 帧。
我正在尝试从数据库中选择一个随机条目,但仅从最新的 100 个条目中选择。有什么想法吗?谢谢。 最佳答案 对于 MySql - SELECT * FROM (SELECT * FROM tabl
我有一个表格,其中包含职位状态。表列是: ID //which is unique incremental Post_id //liked post user_id //user
使用 Laravel Eloquent,如何从前 100 行中随机抽取 10 行(按日期排序)。 例如,我有这个: $comments = Comment::orderBy('created_at',
数据是pandas系列:我正在使用df.B=df.A.str.extract(r'')使用提取的 WHERE 单词创建 B 列df: A HI my lines are so super WHERE1
我正在使用下面的脚本从前 24 小时中提取数据并将其输出到一个 html 表中,它在 8 月的整个月都有效,但自从月份更改为 9 月后就搞砸了,现在显示第一个数据入口.. 我的“时间戳”列是 varc
最近学习了Git的基本概念。我们确实使用了一些 git-svn 来熟悉它的使用。我想和我的 friend 一起在 git 上开始我的第一个“真正的”项目。 因此我想问一下您一般使用 Git 的最佳实践
我正在编写一个脚本,我需要在标签上提取 id 中可用的值,我需要使用纯 Javascript 来完成此操作。我有类似的 jQuery 代码可用,但我无法成功完成 Javascript 代码。我的 jq
我有这个查询来选择记录号 49 和 50 SELECT id,date FROM table WHERE enabled=1 ORDER BY id DESC LIMIT 2 OFFSET 48 现在
我是一名优秀的程序员,十分优秀!