UI: Clean up projector's render regions creation

master
Shaolin 2018-03-08 20:27:15 -03:00
parent fc3e85a598
commit 22a1887340
1 changed files with 29 additions and 33 deletions

View File

@ -248,6 +248,21 @@ static inline uint32_t labelOffset(obs_source_t *label, uint32_t cx)
return (cx / 2) - w; return (cx / 2) - w;
} }
static inline void startRegion(int vX, int vY, int vCX, int vCY, float oL,
float oR, float oT, float oB)
{
gs_projection_push();
gs_viewport_push();
gs_set_viewport(vX, vY, vCX, vCY);
gs_ortho(oL, oR, oT, oB, -100.0f, 100.0f);
}
static inline void endRegion()
{
gs_viewport_pop();
gs_projection_pop();
}
void OBSProjector::OBSRenderMultiview(void *data, uint32_t cx, uint32_t cy) void OBSProjector::OBSRenderMultiview(void *data, uint32_t cx, uint32_t cy)
{ {
OBSProjector *window = (OBSProjector *)data; OBSProjector *window = (OBSProjector *)data;
@ -318,16 +333,7 @@ void OBSProjector::OBSRenderMultiview(void *data, uint32_t cx, uint32_t cy)
float oR = (x + cx); float oR = (x + cx);
float oB = (y + cy); float oB = (y + cy);
gs_projection_push(); startRegion(vX, vY, vCX, vCY, oL, oR, oT, oB);
gs_viewport_push();
gs_set_viewport(vX, vY, vCX, vCY);
gs_ortho(oL, oR, oT, oB, -100.0f, 100.0f);
};
auto resetRegion = [] ()
{
gs_viewport_pop();
gs_projection_pop();
}; };
auto calcBaseSource = [&](size_t i) auto calcBaseSource = [&](size_t i)
@ -413,10 +419,8 @@ void OBSProjector::OBSRenderMultiview(void *data, uint32_t cx, uint32_t cy)
/* ----------------------------- */ /* ----------------------------- */
/* draw sources */ /* draw sources */
gs_projection_push(); startRegion(x, y, targetCX * scale, targetCY * scale, 0.0f, targetCXF,
gs_viewport_push(); 0.0f, targetCYF);
gs_set_viewport(x, y, targetCX * scale, targetCY * scale);
gs_ortho(0.0f, targetCXF, 0.0f, targetCYF, -100.0f, 100.0f);
for (size_t i = 0; i < 8; i++) { for (size_t i = 0; i < 8; i++) {
OBSSource src = OBSGetStrongRef(window->multiviewScenes[i]); OBSSource src = OBSGetStrongRef(window->multiviewScenes[i]);
@ -457,7 +461,7 @@ void OBSProjector::OBSRenderMultiview(void *data, uint32_t cx, uint32_t cy)
setRegion(qiX, qiY, qiCX, qiCY); setRegion(qiX, qiY, qiCX, qiCY);
obs_source_video_render(src); obs_source_video_render(src);
resetRegion(); endRegion();
gs_effect_set_color(color, outerColor); gs_effect_set_color(color, outerColor);
renderVB(solid, window->outerBox, targetCX, targetCY); renderVB(solid, window->outerBox, targetCX, targetCY);
@ -494,14 +498,11 @@ void OBSProjector::OBSRenderMultiview(void *data, uint32_t cx, uint32_t cy)
gs_matrix_scale3f(hiScaleX, hiScaleY, 1.0f); gs_matrix_scale3f(hiScaleX, hiScaleY, 1.0f);
setRegion(sourceX, sourceY, hiCX, hiCY); setRegion(sourceX, sourceY, hiCX, hiCY);
if (studioMode)
if (studioMode) {
obs_source_video_render(previewSrc); obs_source_video_render(previewSrc);
} else { else
obs_render_main_texture(); obs_render_main_texture();
} endRegion();
resetRegion();
gs_matrix_pop(); gs_matrix_pop();
@ -547,7 +548,7 @@ void OBSProjector::OBSRenderMultiview(void *data, uint32_t cx, uint32_t cy)
setRegion(sourceX, sourceY, hiCX, hiCY); setRegion(sourceX, sourceY, hiCX, hiCY);
obs_render_main_texture(); obs_render_main_texture();
resetRegion(); endRegion();
gs_matrix_pop(); gs_matrix_pop();
@ -576,8 +577,7 @@ void OBSProjector::OBSRenderMultiview(void *data, uint32_t cx, uint32_t cy)
/* ----------------------------- */ /* ----------------------------- */
gs_viewport_pop(); endRegion();
gs_projection_pop();
} }
void OBSProjector::OBSRender(void *data, uint32_t cx, uint32_t cy) void OBSProjector::OBSRender(void *data, uint32_t cx, uint32_t cy)
@ -611,10 +611,8 @@ void OBSProjector::OBSRender(void *data, uint32_t cx, uint32_t cy)
newCX = int(scale * float(targetCX)); newCX = int(scale * float(targetCX));
newCY = int(scale * float(targetCY)); newCY = int(scale * float(targetCY));
gs_viewport_push(); startRegion(x, y, newCX, newCY, 0.0f, float(targetCX), 0.0f,
gs_projection_push(); float(targetCY));
gs_ortho(0.0f, float(targetCX), 0.0f, float(targetCY), -100.0f, 100.0f);
gs_set_viewport(x, y, newCX, newCY);
if (window->type == ProjectorType::Preview && if (window->type == ProjectorType::Preview &&
main->IsPreviewProgramMode()) { main->IsPreviewProgramMode()) {
@ -627,14 +625,12 @@ void OBSProjector::OBSRender(void *data, uint32_t cx, uint32_t cy)
} }
} }
if (source) { if (source)
obs_source_video_render(source); obs_source_video_render(source);
} else { else
obs_render_main_texture(); obs_render_main_texture();
}
gs_projection_pop(); endRegion();
gs_viewport_pop();
} }
void OBSProjector::OBSSourceRemoved(void *data, calldata_t *params) void OBSProjector::OBSSourceRemoved(void *data, calldata_t *params)