Skip to content
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 detail texture support to rdpq_sprite_upload #380

Merged
merged 35 commits into from
Jun 23, 2023

Conversation

SpookyIluha
Copy link
Contributor

@SpookyIluha SpookyIluha commented Jun 14, 2023

Basically the title.

The detail texture can now be created using mksprite and uploaded alongside the main texture and/or its mipmaps.
This change also introduces a few new modes and functions

  • new mipmap modes to accomodate detail texture or sharpen (accessible without much API changes through rdpq_mode_mipmap and rdpq_mipmap_t)
  • added support to changing min lod / prim lod / prim color interchangeably or all together and whilst saving the prim state
  • added support to reuse textures when doing a multi-texture upload through rdpq_tex_reuse/_sub (not yet ready in PR, hopefully fixed soon)
  • additional sprite functions to retreive detail texture data

Copy link
Collaborator

@rasky rasky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

first round, still need to check the texloader stuff

include/rdpq.h Outdated
* @brief Set the RDP MIN LOD combiner register (RDP command: SET_PRIM_COLOR (partial))
*
* This function sets the internal RDP PRIM MIN LOD register, that is used for
* determining the interpolation blend factor of a detail texture.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we maybe rename it in another way? I don't know the story behind "MIN LOD", but if we use it as blend factor for detail texture, maybe it should be rdpq_set_blend_detail_factor() or something like that.

include/sprite.h Outdated
* @param sprite The sprite to access
* @return Blend factor if sprite has detail texture, 0 otherwise
*/
float sprite_detail_get_factor(sprite_t *sprite);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a bit wide as an API surface for a single feature. My suggestion is to add a sprite_detail_t structure, and then use a single API like this:

surface_t sprite_get_detail_pixels(sprite_t *sprite, sprite_detail_t *info);

so that you return the surface and the info (maybe the info can even be optional, if NULL).

include/sprite.h Outdated Show resolved Hide resolved
if (!parms && sprite_get_texparms(sprite, &parms_builtin))
parms = &parms_builtin;

// Check for detail texture
sprite_detail_t detailinfo;
sprite_get_detail_texparms(sprite, &detailtexparms);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd move this call in the if(use_detail) below. Moreover, you can use the boolean return value: if the value is false, you can call rdpq_tex_upload passing NULL instead of &detailtexparms. Passing NULL to rdpq_tex_upload is always faster as it skips the whole tile parms calculation.

int bytes;
int limit;

tex_loader_t last_tload;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since we're using this also outside of the multi sequence, maybe we should also move this outside of rdpq_multi_upload_t, for clarity. I'm not super excited about always using a global instance of texloader rather than a stack instance like before, but I guess we can live with this for a while.

assertf(tmem_offset % 8 == 0, "Offset %i must be in multiples of 8", tmem_offset);
tex_format_t fmt = surface_get_format(tload->tex);

rdpq_set_tile(tload->tile, fmt, tmem_offset, tload->rect.tmem_pitch, &(tload->tileparms));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't this be tload->tmem_addr + tmem_offset? Also how does this work if tmem_addr is already precomputed as part of the autotmem allocator?

multi_upload_bytes = 0;
multi_upload_limit = 4096;
if (multi_upload.used++ == 0) {
multi_upload.used = true;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this line is spurious? used is a counter

@rasky rasky merged commit a5ff6c4 into DragonMinded:unstable Jun 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants