Skip to content

Commit

Permalink
Fixed an oversight where new full screen clip command should be sent …
Browse files Browse the repository at this point in the history
…if not hardware cropping
  • Loading branch information
Protofall committed Jan 23, 2021
1 parent 22de659 commit af6e9b9
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
27 changes: 21 additions & 6 deletions Crayon/code/dreamcast/graphics.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,7 @@ uint8_t crayon_graphics_init(uint8_t poly_modes){
// );

// Set the screen size to full screen by default
vec2_u16_t values[2] = {
{0, 0},
{crayon_graphics_get_window_width(), crayon_graphics_get_window_height()}
};
crayon_clipping_cmd_t clip = crayon_graphics_clamp_hardware_clip(values);
crayon_clipping_cmd_t clip = crayon_graphics_default_hardware_clip();

// We also need to submit it to take effect
pvr_scene_begin();
Expand Down Expand Up @@ -181,6 +177,20 @@ crayon_clipping_cmd_t crayon_graphics_clamp_hardware_clip(const vec2_u16_t *valu
return clip;
}

crayon_clipping_cmd_t crayon_graphics_default_hardware_clip(){
crayon_clipping_cmd_t clip;
clip.cmd = PVR_CMD_USERCLIP;

clip.minx = 0;
clip.miny = 0;

// On dreamcast height can only be multiples of 32, so we don't need to check it and can instantly -1 it
clip.maxx = (crayon_graphics_get_window_width() >> 5) - 1;
clip.maxy = (crayon_graphics_get_window_height() >> 5) - 1;

return clip;
}

void crayon_graphics_set_hardware_clip(crayon_clipping_cmd_t *clip){
// If this is a new dimension, update last dimension and submit TA
if(memcmp(&__clip_window, &clip->minx, sizeof(int) * 4)){
Expand Down Expand Up @@ -247,14 +257,19 @@ int8_t crayon_graphics_draw_sprites(const crayon_sprite_array_t *sprite_array, c
{camera->window_x, camera->window_y},
{camera->window_x + camera->window_width, camera->window_y + camera->window_height}
};

crayon_clipping_cmd_t clip = crayon_graphics_clamp_hardware_clip(values);
crayon_graphics_set_hardware_clip(&clip);

// No need to software crop if this happens
// No need to software crop hardware crop is perfect
if(crayon_graphics_is_hardware_clip_exact(values)){
draw_option &= ~CRAYON_DRAW_SOFTWARE_CROP;
}
}
else { // If we don't want to hardware crop, then we must revert to full screen
crayon_clipping_cmd_t clip = crayon_graphics_default_hardware_clip();
crayon_graphics_set_hardware_clip(&clip);
}

if(sprite_array->options & CRAYON_HAS_TEXTURE){ // Textured
if(draw_option & CRAYON_DRAW_ENHANCED){
Expand Down
3 changes: 3 additions & 0 deletions Crayon/include/crayon/graphics.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ uint8_t crayon_graphics_is_hardware_clip_exact(const vec2_u16_t *values);
// "values" is an array that is two elements long.
crayon_clipping_cmd_t crayon_graphics_clamp_hardware_clip(const vec2_u16_t *values);

// Same as above, but assumes full screen
crayon_clipping_cmd_t crayon_graphics_default_hardware_clip();

// Only render in this region.
// We assume the command is valid like with crayon_graphics_clamp_hardware_clip()
void crayon_graphics_set_hardware_clip(crayon_clipping_cmd_t *clip);
Expand Down

0 comments on commit af6e9b9

Please sign in to comment.