-
-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add blending option to use blend factor from the spine file #163
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -143,8 +143,23 @@ uint32_t CalcVertexBufferSize(const spSkeleton* skeleton, uint32_t* out_max_tria | |
return count; | ||
} | ||
|
||
uint32_t CalcDrawDescCount(const spSkeleton* skeleton) | ||
{ | ||
uint32_t count = 0; | ||
for (int s = 0; s < skeleton->slotsCount; ++s) | ||
{ | ||
spSlot* slot = skeleton->drawOrder[s]; | ||
spAttachment* attachment = slot->attachment; | ||
if (!attachment) | ||
{ | ||
continue; | ||
} | ||
count++; | ||
} | ||
return count; | ||
} | ||
|
||
uint32_t GenerateVertexData(dmArray<SpineVertex>& vertex_buffer, const spSkeleton* skeleton, const dmVMath::Matrix4& world) | ||
uint32_t GenerateVertexData(dmArray<SpineVertex>& vertex_buffer, const spSkeleton* skeleton, const dmVMath::Matrix4& world, dmArray<SpineDrawDesc>* draw_descs_out) | ||
{ | ||
dmArray<float> scratch; // scratch buffer | ||
|
||
|
@@ -170,28 +185,7 @@ uint32_t GenerateVertexData(dmArray<SpineVertex>& vertex_buffer, const spSkeleto | |
continue; | ||
} | ||
|
||
// We let the user override the blend mode for the whole spine scene at the .spinemodel level | ||
// // Fetch the blend mode from the slot and | ||
// // translate it to the engine blend mode | ||
// BlendMode engineBlendMode; | ||
// switch (slot->data->blendMode) { | ||
// case SP_BLEND_MODE_NORMAL: | ||
// engineBlendMode = BLEND_NORMAL; | ||
// break; | ||
// case SP_BLEND_MODE_ADDITIVE: | ||
// engineBlendMode = BLEND_ADDITIVE; | ||
// break; | ||
// case SP_BLEND_MODE_MULTIPLY: | ||
// engineBlendMode = BLEND_MULTIPLY; | ||
// break; | ||
// case SP_BLEND_MODE_SCREEN: | ||
// engineBlendMode = BLEND_SCREEN; | ||
// break; | ||
// default: | ||
// // unknown Spine blend mode, fall back to | ||
// // normal blend mode | ||
// engineBlendMode = BLEND_NORMAL; | ||
// } | ||
uint32_t batch_vindex_start = vindex; | ||
|
||
// Calculate the tinting color based on the skeleton's color | ||
// and the slot's color. Each color channel is given in the | ||
|
@@ -271,6 +265,15 @@ uint32_t GenerateVertexData(dmArray<SpineVertex>& vertex_buffer, const spSkeleto | |
addVertex(&vertex_buffer[vindex++], scratch[index], scratch[index + 1], uvs[index], uvs[index + 1], colorR, colorG, colorB, colorA, page_index); | ||
} | ||
} | ||
|
||
if (draw_descs_out) | ||
{ | ||
SpineDrawDesc desc; | ||
desc.m_VertexStart = batch_vindex_start; | ||
desc.m_BlendMode = (uint32_t) slot->data->blendMode; | ||
desc.m_VertexCount = vindex - batch_vindex_start; | ||
draw_descs_out->Push(desc); | ||
} | ||
} | ||
scratch.SetSize(0); | ||
|
||
|
@@ -295,4 +298,30 @@ uint32_t GenerateVertexData(dmArray<SpineVertex>& vertex_buffer, const spSkeleto | |
return vcount; | ||
} | ||
|
||
void MergeDrawDescs(const dmArray<SpineDrawDesc>& src, dmArray<SpineDrawDesc>& dst) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we could use a single array here, but it's a lot easier to read this function when we have a secondary buffer. |
||
{ | ||
dst.SetCapacity(src.Size()); | ||
dst.SetSize(src.Size()); | ||
|
||
SpineDrawDesc* current_draw_desc = dst.Begin(); | ||
*current_draw_desc = src[0]; | ||
|
||
// If we are using "inherit" blending mode, we need to produce render objects based | ||
// on the blend mode. If two consecutive draws have the same blend mode, we can merge them. | ||
for (int i = 1; i < src.Size(); ++i) | ||
{ | ||
if (current_draw_desc->m_BlendMode == src[i].m_BlendMode) | ||
{ | ||
current_draw_desc->m_VertexCount += src[i].m_VertexCount; | ||
} | ||
else | ||
{ | ||
current_draw_desc++; | ||
*current_draw_desc = src[i]; | ||
} | ||
} | ||
uint32_t trimmed_size = current_draw_desc - dst.Begin() + 1; | ||
dst.SetSize(trimmed_size); | ||
} | ||
|
||
} // dmSpine |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only generate these if necessary