mirror of
https://github.com/libsdl-org/SDL.git
synced 2026-06-02 07:27:19 +08:00
Revert "Reverted Vita cliprect changes"
This reverts commitaeb4b3d2fc. (cherry picked from commit75d1d64c75)
This commit is contained in:
@@ -821,6 +821,35 @@ static SceGxmTextureAddrMode TranslateAddressMode(SDL_TextureAddressMode mode)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void ClampCliprectToViewport(SDL_Rect *clip, const SDL_Rect *viewport)
|
||||||
|
{
|
||||||
|
int max_x_v, max_y_v, max_x_c, max_y_c;
|
||||||
|
|
||||||
|
if (clip->x < 0) {
|
||||||
|
clip->w += clip->x;
|
||||||
|
clip->x = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (clip->y < 0) {
|
||||||
|
clip->h += clip->y;
|
||||||
|
clip->y = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
max_x_c = clip->x + clip->w;
|
||||||
|
max_y_c = clip->y + clip->h;
|
||||||
|
|
||||||
|
max_x_v = viewport->x + viewport->w;
|
||||||
|
max_y_v = viewport->y + viewport->h;
|
||||||
|
|
||||||
|
if (max_x_c > max_x_v) {
|
||||||
|
clip->w -= (max_x_v - max_x_c);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (max_y_c > max_y_v) {
|
||||||
|
clip->h -= (max_y_v - max_y_c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static bool SetDrawState(VITA_GXM_RenderData *data, const SDL_RenderCommand *cmd)
|
static bool SetDrawState(VITA_GXM_RenderData *data, const SDL_RenderCommand *cmd)
|
||||||
{
|
{
|
||||||
SDL_Texture *texture = cmd->data.draw.texture;
|
SDL_Texture *texture = cmd->data.draw.texture;
|
||||||
@@ -863,9 +892,13 @@ static bool SetDrawState(VITA_GXM_RenderData *data, const SDL_RenderCommand *cmd
|
|||||||
data->drawstate.cliprect_enabled_dirty = false;
|
data->drawstate.cliprect_enabled_dirty = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data->drawstate.cliprect_enabled && data->drawstate.cliprect_dirty) {
|
if ((data->drawstate.cliprect_enabled || data->drawstate.viewport_is_set) && data->drawstate.cliprect_dirty) {
|
||||||
const SDL_Rect *rect = &data->drawstate.cliprect;
|
SDL_Rect rect;
|
||||||
set_clip_rectangle(data, rect->x, rect->y, rect->x + rect->w, rect->y + rect->h);
|
SDL_copyp(&rect, &data->drawstate.cliprect);
|
||||||
|
if (data->drawstate.viewport_is_set) {
|
||||||
|
ClampCliprectToViewport(&rect, &data->drawstate.viewport);
|
||||||
|
}
|
||||||
|
set_clip_rectangle(data, rect.x, rect.y, rect.x + rect.w, rect.y + rect.h);
|
||||||
data->drawstate.cliprect_dirty = false;
|
data->drawstate.cliprect_dirty = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -953,19 +986,30 @@ static void VITA_GXM_InvalidateCachedState(SDL_Renderer *renderer)
|
|||||||
static bool VITA_GXM_RunCommandQueue(SDL_Renderer *renderer, SDL_RenderCommand *cmd, void *vertices, size_t vertsize)
|
static bool VITA_GXM_RunCommandQueue(SDL_Renderer *renderer, SDL_RenderCommand *cmd, void *vertices, size_t vertsize)
|
||||||
{
|
{
|
||||||
VITA_GXM_RenderData *data = (VITA_GXM_RenderData *)renderer->internal;
|
VITA_GXM_RenderData *data = (VITA_GXM_RenderData *)renderer->internal;
|
||||||
|
int w, h;
|
||||||
|
|
||||||
StartDrawing(renderer);
|
StartDrawing(renderer);
|
||||||
|
|
||||||
data->drawstate.target = renderer->target;
|
data->drawstate.target = renderer->target;
|
||||||
if (!data->drawstate.target) {
|
if (!data->drawstate.target) {
|
||||||
int w, h;
|
|
||||||
SDL_GetWindowSizeInPixels(renderer->window, &w, &h);
|
SDL_GetWindowSizeInPixels(renderer->window, &w, &h);
|
||||||
|
} else {
|
||||||
|
float fw, fh;
|
||||||
|
if (!SDL_GetTextureSize(renderer->target, &fw, &fh)) {
|
||||||
|
w = data->drawstate.drawablew;
|
||||||
|
h = data->drawstate.drawableh;
|
||||||
|
} else {
|
||||||
|
w = (int)SDL_roundf(fw);
|
||||||
|
h = (int)SDL_roundf(fh);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ((w != data->drawstate.drawablew) || (h != data->drawstate.drawableh)) {
|
if ((w != data->drawstate.drawablew) || (h != data->drawstate.drawableh)) {
|
||||||
data->drawstate.viewport_dirty = true; // if the window dimensions changed, invalidate the current viewport, etc.
|
data->drawstate.viewport_dirty = true; // if the window dimensions changed, invalidate the current viewport, etc.
|
||||||
data->drawstate.cliprect_dirty = true;
|
data->drawstate.cliprect_dirty = true;
|
||||||
data->drawstate.drawablew = w;
|
data->drawstate.drawablew = w;
|
||||||
data->drawstate.drawableh = h;
|
data->drawstate.drawableh = h;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
while (cmd) {
|
while (cmd) {
|
||||||
switch (cmd->command) {
|
switch (cmd->command) {
|
||||||
@@ -977,6 +1021,16 @@ static bool VITA_GXM_RunCommandQueue(SDL_Renderer *renderer, SDL_RenderCommand *
|
|||||||
SDL_copyp(viewport, &cmd->data.viewport.rect);
|
SDL_copyp(viewport, &cmd->data.viewport.rect);
|
||||||
data->drawstate.viewport_dirty = true;
|
data->drawstate.viewport_dirty = true;
|
||||||
data->drawstate.cliprect_dirty = true;
|
data->drawstate.cliprect_dirty = true;
|
||||||
|
data->drawstate.viewport_is_set = viewport->x != 0 || viewport->y != 0 || viewport->w != data->drawstate.drawablew || viewport->h != data->drawstate.drawableh;
|
||||||
|
if (!data->drawstate.cliprect_enabled) {
|
||||||
|
if (data->drawstate.viewport_is_set) {
|
||||||
|
SDL_copyp(&data->drawstate.cliprect, viewport);
|
||||||
|
data->drawstate.cliprect.x = 0;
|
||||||
|
data->drawstate.cliprect.y = 0;
|
||||||
|
} else {
|
||||||
|
data->drawstate.cliprect_enabled_dirty = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -984,9 +1038,15 @@ static bool VITA_GXM_RunCommandQueue(SDL_Renderer *renderer, SDL_RenderCommand *
|
|||||||
case SDL_RENDERCMD_SETCLIPRECT:
|
case SDL_RENDERCMD_SETCLIPRECT:
|
||||||
{
|
{
|
||||||
const SDL_Rect *rect = &cmd->data.cliprect.rect;
|
const SDL_Rect *rect = &cmd->data.cliprect.rect;
|
||||||
|
const SDL_Rect *viewport = &data->drawstate.viewport;
|
||||||
if (data->drawstate.cliprect_enabled != cmd->data.cliprect.enabled) {
|
if (data->drawstate.cliprect_enabled != cmd->data.cliprect.enabled) {
|
||||||
data->drawstate.cliprect_enabled = cmd->data.cliprect.enabled;
|
data->drawstate.cliprect_enabled = cmd->data.cliprect.enabled;
|
||||||
data->drawstate.cliprect_enabled_dirty = true;
|
data->drawstate.cliprect_enabled_dirty = true;
|
||||||
|
if (!data->drawstate.cliprect_enabled && data->drawstate.viewport_is_set) {
|
||||||
|
SDL_copyp(&data->drawstate.cliprect, viewport);
|
||||||
|
data->drawstate.cliprect.x = 0;
|
||||||
|
data->drawstate.cliprect.y = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (SDL_memcmp(&data->drawstate.cliprect, rect, sizeof(*rect)) != 0) {
|
if (SDL_memcmp(&data->drawstate.cliprect, rect, sizeof(*rect)) != 0) {
|
||||||
|
|||||||
@@ -105,6 +105,7 @@ typedef struct
|
|||||||
{
|
{
|
||||||
SDL_Rect viewport;
|
SDL_Rect viewport;
|
||||||
bool viewport_dirty;
|
bool viewport_dirty;
|
||||||
|
bool viewport_is_set;
|
||||||
SDL_Texture *texture;
|
SDL_Texture *texture;
|
||||||
SDL_Texture *target;
|
SDL_Texture *target;
|
||||||
SDL_FColor color;
|
SDL_FColor color;
|
||||||
|
|||||||
Reference in New Issue
Block a user