Skip to content

Commit

Permalink
Support fallback when no color semantic present (#8853)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jhonnyg committed Apr 30, 2024
1 parent fd3b8c6 commit 526a6f5
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
15 changes: 6 additions & 9 deletions engine/gamesys/src/gamesys/components/comp_sprite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -670,8 +670,6 @@ namespace dmGameSystem
// | | w | |
// 3 *-*-----*-*

dmVMath::Vector4 tmp_color;

for (uint32_t i = 0; i < textures->m_NumTextures; ++i)
{
dmArray<float>& uvs = scratch_uvs[i];
Expand Down Expand Up @@ -781,7 +779,7 @@ namespace dmGameSystem
p_local = Point3(p_world.getX() * sprite_size.getX(), p_world.getY() * sprite_size.getY(), 0.0f);
}

dmGraphics::WriteAttribute(sprite_infos, vertices + vertex_stride * vx_index, vx_index, &transform, p_world, p_local, tmp_color, &uvs, textures->m_PageIndices, textures->m_NumTextures);
dmGraphics::WriteAttribute(sprite_infos, vertices + vertex_stride * vx_index, vx_index, &transform, p_world, p_local, 0, &uvs, textures->m_PageIndices, textures->m_NumTextures);
vx_index++;
}
}
Expand Down Expand Up @@ -1066,7 +1064,6 @@ namespace dmGameSystem
textures.m_TextureSets[i] = textures.m_Resources[i]->m_TextureSet;
}

dmVMath::Vector4 tmp_color;
dmGraphics::VertexAttributeInfos sprite_attribute_info = {};

for (uint32_t* i = begin; i != end; ++i)
Expand Down Expand Up @@ -1138,7 +1135,7 @@ namespace dmGameSystem
}

float* uvs = scratch_uvs->Begin();
dmGraphics::WriteAttribute(sprite_attribute_info_ptr, vertices + vert * vertex_stride, vert, &w, p_world, p_local, tmp_color, &uvs, textures.m_PageIndices, textures.m_NumTextures);
dmGraphics::WriteAttribute(sprite_attribute_info_ptr, vertices + vert * vertex_stride, vert, &w, p_world, p_local, 0, &uvs, textures.m_PageIndices, textures.m_NumTextures);
}

uint32_t index_count = geometry->m_Indices.m_Count;
Expand Down Expand Up @@ -1220,10 +1217,10 @@ namespace dmGameSystem
}

float* uvs = scratch_uvs->Begin();
dmGraphics::WriteAttribute(sprite_attribute_info_ptr, vertices , 0, &w, p0, p0_local, tmp_color, &uvs, textures.m_PageIndices, textures.m_NumTextures);
dmGraphics::WriteAttribute(sprite_attribute_info_ptr, vertices + vertex_stride , 1, &w, p1, p1_local, tmp_color, &uvs, textures.m_PageIndices, textures.m_NumTextures);
dmGraphics::WriteAttribute(sprite_attribute_info_ptr, vertices + vertex_stride * 2, 2, &w, p2, p2_local, tmp_color, &uvs, textures.m_PageIndices, textures.m_NumTextures);
dmGraphics::WriteAttribute(sprite_attribute_info_ptr, vertices + vertex_stride * 3, 3, &w, p3, p3_local, tmp_color, &uvs, textures.m_PageIndices, textures.m_NumTextures);
dmGraphics::WriteAttribute(sprite_attribute_info_ptr, vertices , 0, &w, p0, p0_local, 0, &uvs, textures.m_PageIndices, textures.m_NumTextures);
dmGraphics::WriteAttribute(sprite_attribute_info_ptr, vertices + vertex_stride , 1, &w, p1, p1_local, 0, &uvs, textures.m_PageIndices, textures.m_NumTextures);
dmGraphics::WriteAttribute(sprite_attribute_info_ptr, vertices + vertex_stride * 2, 2, &w, p2, p2_local, 0, &uvs, textures.m_PageIndices, textures.m_NumTextures);
dmGraphics::WriteAttribute(sprite_attribute_info_ptr, vertices + vertex_stride * 3, 3, &w, p3, p3_local, 0, &uvs, textures.m_PageIndices, textures.m_NumTextures);

#if 0
for (int f = 0; f < 4; ++f)
Expand Down
7 changes: 5 additions & 2 deletions engine/graphics/src/graphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ namespace dmGraphics
*data_size = attribute.m_Values.m_BinaryValues.m_Count;
}

uint8_t* WriteAttribute(const VertexAttributeInfos* attribute_infos, uint8_t* write_ptr, uint32_t vertex_index, const dmVMath::Matrix4* world_transform, const dmVMath::Point3& p, const dmVMath::Point3& p_local, const dmVMath::Vector4& color, float** uvs, uint32_t* page_indices, uint32_t num_textures)
uint8_t* WriteAttribute(const VertexAttributeInfos* attribute_infos, uint8_t* write_ptr, uint32_t vertex_index, const dmVMath::Matrix4* world_transform, const dmVMath::Point3& p, const dmVMath::Point3& p_local, const dmVMath::Vector4* color, float** uvs, uint32_t* page_indices, uint32_t num_textures)
{
uint32_t num_texcoords = 0;
uint32_t num_page_indices = 0;
Expand Down Expand Up @@ -448,7 +448,10 @@ namespace dmGraphics
} break;
case dmGraphics::VertexAttribute::SEMANTIC_TYPE_COLOR:
{
memcpy(write_ptr, &color, info.m_ValueByteSize);
if (color)
memcpy(write_ptr, color, info.m_ValueByteSize);
else
memcpy(write_ptr, info.m_ValuePtr, info.m_ValueByteSize);
} break;
case dmGraphics::VertexAttribute::SEMANTIC_TYPE_PAGE_INDEX:
{
Expand Down
2 changes: 1 addition & 1 deletion engine/graphics/src/graphics.h
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,7 @@ namespace dmGraphics
void GetAttribute(HProgram prog, uint32_t index, dmhash_t* name_hash, Type* type, uint32_t* element_count, uint32_t* num_values, int32_t* location);
void GetAttributeValues(const VertexAttribute& attribute, const uint8_t** data_ptr, uint32_t* data_size);
Type GetGraphicsType(VertexAttribute::DataType data_type);
uint8_t* WriteAttribute(const VertexAttributeInfos* attribute_infos, uint8_t* write_ptr, uint32_t vertex_index, const dmVMath::Matrix4* world_transform, const dmVMath::Point3& p, const dmVMath::Point3& p_local, const dmVMath::Vector4& color, float** uvs, uint32_t* page_indices, uint32_t num_textures);
uint8_t* WriteAttribute(const VertexAttributeInfos* attribute_infos, uint8_t* write_ptr, uint32_t vertex_index, const dmVMath::Matrix4* world_transform, const dmVMath::Point3& p, const dmVMath::Point3& p_local, const dmVMath::Vector4* color, float** uvs, uint32_t* page_indices, uint32_t num_textures);

uint32_t GetUniformName(HProgram prog, uint32_t index, char* buffer, uint32_t buffer_size, Type* type, int32_t* size);
uint32_t GetUniformCount(HProgram prog);
Expand Down

0 comments on commit 526a6f5

Please sign in to comment.