mirror of
https://github.com/gnif/LookingGlass.git
synced 2026-07-21 23:02:05 +00:00
Some checks failed
build / client (Debug, map[cc:clang cxx:clang++], libdecor) (push) Has been cancelled
build / client (Debug, map[cc:clang cxx:clang++], xdg-shell) (push) Has been cancelled
build / client (Debug, map[cc:gcc cxx:g++], libdecor) (push) Has been cancelled
build / client (Debug, map[cc:gcc cxx:g++], xdg-shell) (push) Has been cancelled
build / client (Release, map[cc:clang cxx:clang++], libdecor) (push) Has been cancelled
build / client (Release, map[cc:clang cxx:clang++], xdg-shell) (push) Has been cancelled
build / client (Release, map[cc:gcc cxx:g++], libdecor) (push) Has been cancelled
build / client (Release, map[cc:gcc cxx:g++], xdg-shell) (push) Has been cancelled
build / module (push) Has been cancelled
build / host-linux (push) Has been cancelled
build / host-windows-cross (push) Has been cancelled
build / host-windows-native (push) Has been cancelled
build / idd (push) Has been cancelled
build / obs (clang) (push) Has been cancelled
build / obs (gcc) (push) Has been cancelled
build / docs (push) Has been cancelled
Track context-local GL bindings to avoid redundant program, framebuffer, buffer, texture, sampler, viewport, blend, and scissor state changes. Invalidate the cache across context switches, ImGui rendering, and shared object changes. Preserve CPU-backed texture upload correctness by explicitly clearing pixel unpack buffer bindings where required. This reduces hot-path driver overhead without adding waits or GPU synchronization.
115 lines
2.8 KiB
C
115 lines
2.8 KiB
C
/**
|
|
* Looking Glass
|
|
* Copyright © 2017-2026 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 "framebuffer.h"
|
|
#include "state.h"
|
|
#include "texture.h"
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include "common/debug.h"
|
|
|
|
struct EGL_Framebuffer
|
|
{
|
|
GLuint fbo;
|
|
EGL_Texture * tex;
|
|
};
|
|
|
|
bool egl_framebufferInit(EGL_Framebuffer ** fb)
|
|
{
|
|
EGL_Framebuffer * this = calloc(1, sizeof(*this));
|
|
if (!this)
|
|
{
|
|
DEBUG_ERROR("Failed to allocate ram");
|
|
return false;
|
|
}
|
|
|
|
if (!egl_textureInit(&this->tex, NULL, EGL_TEXTYPE_BUFFER))
|
|
{
|
|
DEBUG_ERROR("Failed to initialize the texture");
|
|
free(this);
|
|
return false;
|
|
}
|
|
|
|
glGenFramebuffers(1, &this->fbo);
|
|
|
|
*fb = this;
|
|
return true;
|
|
}
|
|
|
|
void egl_framebufferFree(EGL_Framebuffer ** fb)
|
|
{
|
|
EGL_Framebuffer * this = *fb;
|
|
|
|
if (!this)
|
|
return;
|
|
|
|
egl_textureFree(&this->tex);
|
|
glDeleteFramebuffers(1, &this->fbo);
|
|
egl_stateInvalidate();
|
|
free(this);
|
|
*fb = NULL;
|
|
}
|
|
|
|
bool egl_framebufferSetup(EGL_Framebuffer * this, enum EGL_PixelFormat pixFmt,
|
|
unsigned int width, unsigned int height)
|
|
{
|
|
if (!egl_textureSetup(this->tex, pixFmt, width, height, 0, 0))
|
|
{
|
|
DEBUG_ERROR("Failed to setup the texture");
|
|
return false;
|
|
}
|
|
|
|
GLuint tex;
|
|
egl_textureGet(this->tex, &tex, NULL, NULL, NULL);
|
|
|
|
egl_stateBindTexture(0, GL_TEXTURE_2D, tex);
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
|
|
|
egl_stateBindFramebuffer(this->fbo);
|
|
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
|
|
GL_TEXTURE_2D, tex, 0);
|
|
glDrawBuffers(1, &(GLenum){GL_COLOR_ATTACHMENT0});
|
|
|
|
GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
|
|
if (status != GL_FRAMEBUFFER_COMPLETE)
|
|
{
|
|
egl_stateBindFramebuffer(0);
|
|
DEBUG_ERROR("Failed to setup the framebuffer: 0x%x", status);
|
|
return false;
|
|
}
|
|
egl_stateBindFramebuffer(0);
|
|
|
|
return true;
|
|
}
|
|
|
|
void egl_framebufferBind(EGL_Framebuffer * this)
|
|
{
|
|
egl_stateBindFramebuffer(this->fbo);
|
|
egl_stateViewport(0, 0,
|
|
this->tex->format.width, this->tex->format.height);
|
|
}
|
|
|
|
EGL_Texture * egl_framebufferGetTexture(EGL_Framebuffer * this)
|
|
{
|
|
return this->tex;
|
|
}
|