mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-08 13:14:56 +00:00
Construct VertexAttributeDescriptor, in order to match web idl
The parameters about vertex attribute were encapsulated in VertexAttributeDescriptor in web idl. This change construct this descriptor accordingly. BUG=dawn:107 Change-Id: Ia1c6e53af951d8f2a0c0b69bdca09291c2661e50 Reviewed-on: https://dawn-review.googlesource.com/c/4620 Reviewed-by: Corentin Wallez <cwallez@chromium.org> Reviewed-by: Kai Ninomiya <kainino@chromium.org> Commit-Queue: Yunchao He <yunchao.he@intel.com>
This commit is contained in:
committed by
Commit Bot service account
parent
445869d2b0
commit
b2207737ab
@@ -114,13 +114,31 @@ void initRender() {
|
||||
}
|
||||
)");
|
||||
|
||||
dawn::VertexAttributeDescriptor attribute1;
|
||||
attribute1.shaderLocation = 0;
|
||||
attribute1.inputSlot = 0;
|
||||
attribute1.offset = offsetof(Particle, pos);
|
||||
attribute1.format = dawn::VertexFormat::FloatR32G32;
|
||||
|
||||
dawn::VertexAttributeDescriptor attribute2;
|
||||
attribute2.shaderLocation = 1;
|
||||
attribute2.inputSlot = 0;
|
||||
attribute2.offset = offsetof(Particle, vel);
|
||||
attribute2.format = dawn::VertexFormat::FloatR32G32;
|
||||
|
||||
dawn::VertexAttributeDescriptor attribute3;
|
||||
attribute3.shaderLocation = 2;
|
||||
attribute3.inputSlot = 1;
|
||||
attribute3.offset = 0;
|
||||
attribute3.format = dawn::VertexFormat::FloatR32G32;
|
||||
|
||||
dawn::InputState inputState = device.CreateInputStateBuilder()
|
||||
.SetAttribute(0, 0, dawn::VertexFormat::FloatR32G32, offsetof(Particle, pos))
|
||||
.SetAttribute(1, 0, dawn::VertexFormat::FloatR32G32, offsetof(Particle, vel))
|
||||
.SetInput(0, sizeof(Particle), dawn::InputStepMode::Instance)
|
||||
.SetAttribute(2, 1, dawn::VertexFormat::FloatR32G32, 0)
|
||||
.SetInput(1, sizeof(glm::vec2), dawn::InputStepMode::Vertex)
|
||||
.GetResult();
|
||||
.SetAttribute(&attribute1)
|
||||
.SetAttribute(&attribute2)
|
||||
.SetInput(0, sizeof(Particle), dawn::InputStepMode::Instance)
|
||||
.SetAttribute(&attribute3)
|
||||
.SetInput(1, sizeof(glm::vec2), dawn::InputStepMode::Vertex)
|
||||
.GetResult();
|
||||
|
||||
depthStencilView = CreateDefaultDepthStencilView(device);
|
||||
|
||||
|
||||
@@ -111,10 +111,15 @@ void init() {
|
||||
fragColor = texture(sampler2D(myTexture, mySampler), gl_FragCoord.xy / vec2(640.0, 480.0));
|
||||
})");
|
||||
|
||||
dawn::VertexAttributeDescriptor attribute;
|
||||
attribute.shaderLocation = 0;
|
||||
attribute.inputSlot = 0;
|
||||
attribute.offset = 0;
|
||||
attribute.format = dawn::VertexFormat::FloatR32G32B32A32;
|
||||
auto inputState = device.CreateInputStateBuilder()
|
||||
.SetAttribute(0, 0, dawn::VertexFormat::FloatR32G32B32A32, 0)
|
||||
.SetInput(0, 4 * sizeof(float), dawn::InputStepMode::Vertex)
|
||||
.GetResult();
|
||||
.SetAttribute(&attribute)
|
||||
.SetInput(0, 4 * sizeof(float), dawn::InputStepMode::Vertex)
|
||||
.GetResult();
|
||||
|
||||
auto bgl = utils::MakeBindGroupLayout(
|
||||
device, {
|
||||
|
||||
@@ -156,11 +156,23 @@ void init() {
|
||||
fragColor = vec4(mix(f_col, vec3(0.5, 0.5, 0.5), 0.5), 1.0);
|
||||
})");
|
||||
|
||||
dawn::VertexAttributeDescriptor attribute1;
|
||||
attribute1.shaderLocation = 0;
|
||||
attribute1.inputSlot = 0;
|
||||
attribute1.offset = 0;
|
||||
attribute1.format = dawn::VertexFormat::FloatR32G32B32;
|
||||
|
||||
dawn::VertexAttributeDescriptor attribute2;
|
||||
attribute2.shaderLocation = 1;
|
||||
attribute2.inputSlot = 0;
|
||||
attribute2.offset = 3 * sizeof(float);
|
||||
attribute2.format = dawn::VertexFormat::FloatR32G32B32;
|
||||
|
||||
auto inputState = device.CreateInputStateBuilder()
|
||||
.SetAttribute(0, 0, dawn::VertexFormat::FloatR32G32B32, 0)
|
||||
.SetAttribute(1, 0, dawn::VertexFormat::FloatR32G32B32, 3 * sizeof(float))
|
||||
.SetInput(0, 6 * sizeof(float), dawn::InputStepMode::Vertex)
|
||||
.GetResult();
|
||||
.SetAttribute(&attribute1)
|
||||
.SetAttribute(&attribute2)
|
||||
.SetInput(0, 6 * sizeof(float), dawn::InputStepMode::Vertex)
|
||||
.GetResult();
|
||||
|
||||
auto bgl = utils::MakeBindGroupLayout(
|
||||
device, {
|
||||
|
||||
@@ -247,16 +247,25 @@ namespace {
|
||||
fprintf(stderr, "unsupported technique parameter type %d\n", iParameter.type);
|
||||
continue;
|
||||
}
|
||||
dawn::VertexAttributeDescriptor attribute;
|
||||
attribute.offset = 0;
|
||||
attribute.format = format;
|
||||
if (iParameter.semantic == "POSITION") {
|
||||
builder.SetAttribute(0, 0, format, 0);
|
||||
attribute.shaderLocation = 0;
|
||||
attribute.inputSlot = 0;
|
||||
builder.SetAttribute(&attribute);
|
||||
builder.SetInput(0, static_cast<uint32_t>(stridePos), dawn::InputStepMode::Vertex);
|
||||
slotsSet.set(0);
|
||||
} else if (iParameter.semantic == "NORMAL") {
|
||||
builder.SetAttribute(1, 1, format, 0);
|
||||
attribute.shaderLocation = 1;
|
||||
attribute.inputSlot = 1;
|
||||
builder.SetAttribute(&attribute);
|
||||
builder.SetInput(1, static_cast<uint32_t>(strideNor), dawn::InputStepMode::Vertex);
|
||||
slotsSet.set(1);
|
||||
} else if (iParameter.semantic == "TEXCOORD_0") {
|
||||
builder.SetAttribute(2, 2, format, 0);
|
||||
attribute.shaderLocation = 2;
|
||||
attribute.inputSlot = 2;
|
||||
builder.SetAttribute(&attribute);
|
||||
builder.SetInput(2, static_cast<uint32_t>(strideTxc), dawn::InputStepMode::Vertex);
|
||||
slotsSet.set(2);
|
||||
} else {
|
||||
@@ -268,7 +277,13 @@ namespace {
|
||||
if (slotsSet[i]) {
|
||||
continue;
|
||||
}
|
||||
builder.SetAttribute(i, i, dawn::VertexFormat::FloatR32G32B32A32, 0);
|
||||
dawn::VertexAttributeDescriptor attribute;
|
||||
attribute.offset = 0;
|
||||
attribute.shaderLocation = i;
|
||||
attribute.inputSlot = i;
|
||||
attribute.format = dawn::VertexFormat::FloatR32G32B32A32;
|
||||
|
||||
builder.SetAttribute(&attribute);
|
||||
builder.SetInput(i, 0, dawn::InputStepMode::Vertex);
|
||||
}
|
||||
auto inputState = builder.GetResult();
|
||||
|
||||
Reference in New Issue
Block a user