mirror of
https://github.com/gnif/LookingGlass.git
synced 2025-08-06 10:44:01 +00:00
[client] egl: cleanup texture filtering/post-processing
This commit is contained in:
163
client/renderers/EGL/postprocess.c
Normal file
163
client/renderers/EGL/postprocess.c
Normal file
@@ -0,0 +1,163 @@
|
||||
/**
|
||||
* Looking Glass
|
||||
* Copyright © 2017-2021 The Looking Glass Authors
|
||||
* https://looking-glass.io
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the Free
|
||||
* Software Foundation; either version 2 of the License, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc., 59
|
||||
* Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "postprocess.h"
|
||||
#include "filters.h"
|
||||
|
||||
#include "common/debug.h"
|
||||
#include "common/array.h"
|
||||
|
||||
#include "ll.h"
|
||||
|
||||
static const EGL_FilterOps * EGL_Filters[] =
|
||||
{
|
||||
&egl_filterFFXFSR1Ops,
|
||||
&egl_filterFFXCASOps
|
||||
};
|
||||
|
||||
struct EGL_PostProcess
|
||||
{
|
||||
struct ll * filters;
|
||||
GLuint output;
|
||||
unsigned int outputX, outputY;
|
||||
|
||||
EGL_Model * model;
|
||||
};
|
||||
|
||||
void egl_postProcessEarlyInit(void)
|
||||
{
|
||||
for(int i = 0; i < ARRAY_LENGTH(EGL_Filters); ++i)
|
||||
EGL_Filters[i]->earlyInit();
|
||||
}
|
||||
|
||||
bool egl_postProcessInit(EGL_PostProcess ** pp)
|
||||
{
|
||||
EGL_PostProcess * this = calloc(1, sizeof(*this));
|
||||
if (!this)
|
||||
{
|
||||
DEBUG_ERROR("Failed to allocate memory");
|
||||
return false;
|
||||
}
|
||||
|
||||
this->filters = ll_new(sizeof(EGL_Filter *));
|
||||
if (!this->filters)
|
||||
{
|
||||
DEBUG_ERROR("Failed to allocate the filter list");
|
||||
goto error_this;
|
||||
}
|
||||
|
||||
if (!egl_modelInit(&this->model))
|
||||
{
|
||||
DEBUG_ERROR("Failed to initialize the model");
|
||||
goto error_filters;
|
||||
}
|
||||
egl_modelSetDefault(this->model, false);
|
||||
|
||||
*pp = this;
|
||||
return true;
|
||||
|
||||
error_filters:
|
||||
ll_free(this->filters);
|
||||
|
||||
error_this:
|
||||
free(this);
|
||||
return false;
|
||||
}
|
||||
|
||||
void egl_postProcessFree(EGL_PostProcess ** pp)
|
||||
{
|
||||
if (!*pp)
|
||||
return;
|
||||
|
||||
EGL_PostProcess * this = *pp;
|
||||
|
||||
if (this->filters)
|
||||
{
|
||||
EGL_Filter * filter;
|
||||
while(ll_shift(this->filters, (void **)&filter))
|
||||
egl_filterFree(&filter);
|
||||
ll_free(this->filters);
|
||||
}
|
||||
|
||||
egl_modelFree(&this->model);
|
||||
free(this);
|
||||
*pp = NULL;
|
||||
}
|
||||
|
||||
bool egl_postProcessAdd(EGL_PostProcess * this, const EGL_FilterOps * ops)
|
||||
{
|
||||
EGL_Filter * filter;
|
||||
if (!egl_filterInit(ops, &filter))
|
||||
return false;
|
||||
|
||||
ll_push(this->filters, filter);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool egl_postProcessImgui(EGL_PostProcess * this)
|
||||
{
|
||||
bool redraw = false;
|
||||
EGL_Filter * filter;
|
||||
for(ll_reset(this->filters); ll_walk(this->filters, (void **)&filter); )
|
||||
redraw |= egl_filterImguiConfig(filter);
|
||||
|
||||
return redraw;
|
||||
}
|
||||
|
||||
bool egl_postProcessRun(EGL_PostProcess * this, EGL_Texture * tex,
|
||||
unsigned int targetX, unsigned int targetY)
|
||||
{
|
||||
EGL_Filter * lastFilter = NULL, * filter;
|
||||
unsigned int sizeX, sizeY;
|
||||
|
||||
GLuint texture;
|
||||
if (egl_textureGet(tex, &texture, &sizeX, &sizeY) != EGL_TEX_STATUS_OK)
|
||||
return false;
|
||||
|
||||
for(ll_reset(this->filters); ll_walk(this->filters, (void **)&filter); )
|
||||
{
|
||||
egl_filterSetOutputResHint(filter, targetX, targetY);
|
||||
egl_filterSetup(filter, tex->format.pixFmt, sizeX, sizeY);
|
||||
|
||||
if (!egl_filterPrepare(filter))
|
||||
continue;
|
||||
|
||||
texture = egl_filterRun(filter, this->model, texture);
|
||||
egl_filterGetOutputRes(filter, &sizeX, &sizeY);
|
||||
|
||||
if (lastFilter)
|
||||
egl_filterRelease(lastFilter);
|
||||
|
||||
lastFilter = filter;
|
||||
}
|
||||
|
||||
this->output = texture;
|
||||
this->outputX = sizeX;
|
||||
this->outputY = sizeY;
|
||||
return true;
|
||||
}
|
||||
|
||||
GLuint egl_postProcessGetOutput(EGL_PostProcess * this,
|
||||
unsigned int * outputX, unsigned int * outputY)
|
||||
{
|
||||
*outputX = this->outputX;
|
||||
*outputY = this->outputY;
|
||||
return this->output;
|
||||
}
|
Reference in New Issue
Block a user