Repository navigation
newview reaches GL through llrender, and a pre-commit hook keeps it there #540
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
fa6a1ad
LLRender keeps the raster state, stencil and viewport it sets, and ow…
RyeMutt 45cd944
newview reaches GL through llrender
RyeMutt c1f81b0
A pre-commit hook holds newview to the raw GL calls it makes
RyeMutt c3e0048
ALTextureBlit's copy is not clipped by the scissor
RyeMutt 9481b74
The raw GL check skips #elif 0 and counts a call split before its par…
RyeMutt 389fe14
The stencil state checks read GL with a stencil buffer bound
RyeMutt e6be9b5
The raw GL check takes only a bare 0 as a branch that is not compiled
RyeMutt 6b578b1
The stencil state checks clear their target before reading the reference
RyeMutt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| /** | ||
| * @file altextureblit.cpp | ||
| * @brief A copy from one texture into another through framebuffers it keeps, for textures no render target holds. | ||
| * | ||
| * $LicenseInfo:firstyear=2026&license=viewerlgpl$ | ||
| * Alchemy Viewer Source Code | ||
| * Copyright (C) 2026, Rye <rye@alchemyviewer.org> | ||
| * | ||
| * This library is free software; you can redistribute it and/or | ||
| * modify it under the terms of the GNU Lesser General Public | ||
| * License as published by the Free Software Foundation; | ||
| * version 2.1 of the License only. | ||
| * | ||
| * This library 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 | ||
| * Lesser General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU Lesser General Public | ||
| * License along with this library; if not, write to the Free Software | ||
| * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
| * $/LicenseInfo$ | ||
| */ | ||
|
|
||
| #include "linden_common.h" | ||
|
|
||
| #include "altextureblit.h" | ||
|
|
||
| #include "llgl.h" | ||
| #include "llrender.h" | ||
| #include "llrendertarget.h" | ||
|
|
||
| ALTextureBlit::~ALTextureBlit() | ||
| { | ||
| release(); | ||
| } | ||
|
|
||
| void ALTextureBlit::blit(U32 src_target, U32 src, U32 dst, S32 width, S32 height, bool flip_y) | ||
| { | ||
| llassert(src_target == GL_TEXTURE_2D || src_target == GL_TEXTURE_RECTANGLE); | ||
| gGL.flush(); | ||
|
|
||
| if (!mReadFBO) | ||
| { | ||
| glGenFramebuffers(1, &mReadFBO); | ||
| } | ||
| if (!mDrawFBO) | ||
| { | ||
| glGenFramebuffers(1, &mDrawFBO); | ||
| } | ||
|
|
||
| glBindFramebuffer(GL_READ_FRAMEBUFFER, mReadFBO); | ||
| glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, src_target, src, 0); | ||
| glBindFramebuffer(GL_DRAW_FRAMEBUFFER, mDrawFBO); | ||
| glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, dst, 0); | ||
|
|
||
| { | ||
| // glBlitFramebuffer writes only where the scissor test passes. | ||
| LLGLDisable scissor(GL_SCISSOR_TEST); | ||
| glBlitFramebuffer(0, 0, width, height, | ||
| 0, flip_y ? height : 0, width, flip_y ? 0 : height, | ||
| GL_COLOR_BUFFER_BIT, GL_NEAREST); | ||
| } | ||
|
|
||
| // Detached, so neither framebuffer keeps a texture its owner may delete or hand to another context. | ||
| glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, src_target, 0, 0); | ||
| glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, 0, 0); | ||
| glBindFramebuffer(GL_FRAMEBUFFER, LLRenderTarget::sCurFBO); | ||
| } | ||
|
|
||
| void ALTextureBlit::release() | ||
| { | ||
| // The names die with the context; deleting them after it would fault in the driver. | ||
| if (gGLManager.mInited) | ||
| { | ||
| if (mReadFBO) | ||
| { | ||
| glDeleteFramebuffers(1, &mReadFBO); | ||
| } | ||
| if (mDrawFBO) | ||
| { | ||
| glDeleteFramebuffers(1, &mDrawFBO); | ||
| } | ||
| } | ||
| mReadFBO = 0; | ||
| mDrawFBO = 0; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| /** | ||
| * @file altextureblit.h | ||
| * @brief A copy from one texture into another through framebuffers it keeps, for textures no render target holds. | ||
| * | ||
| * $LicenseInfo:firstyear=2026&license=viewerlgpl$ | ||
| * Alchemy Viewer Source Code | ||
| * Copyright (C) 2026, Rye <rye@alchemyviewer.org> | ||
| * | ||
| * This library is free software; you can redistribute it and/or | ||
| * modify it under the terms of the GNU Lesser General Public | ||
| * License as published by the Free Software Foundation; | ||
| * version 2.1 of the License only. | ||
| * | ||
| * This library 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 | ||
| * Lesser General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU Lesser General Public | ||
| * License along with this library; if not, write to the Free Software | ||
| * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
| * $/LicenseInfo$ | ||
| */ | ||
|
|
||
| #pragma once | ||
|
|
||
| #include "stdtypes.h" | ||
|
|
||
| // Copies level 0 of one texture into another by glBlitFramebuffer, through a pair of framebuffers it makes on its first | ||
| // copy and keeps: the copy from a texture no LLRenderTarget holds, such as one whose storage a platform's interop | ||
| // supplies (a D3D11 texture, an IOSurface, a dma-buf), into another that need not be a target's either, upside down if | ||
| // asked. | ||
| // | ||
| // All operations require a current GL context, the one the framebuffers were made in. Non-copyable. | ||
| class ALTextureBlit | ||
| { | ||
| public: | ||
| ALTextureBlit() = default; | ||
| ~ALTextureBlit(); | ||
|
|
||
| ALTextureBlit(const ALTextureBlit&) = delete; | ||
| ALTextureBlit& operator=(const ALTextureBlit&) = delete; | ||
|
|
||
| // Copy the `width` x `height` rectangle at the origin of `src`, a texture of `src_target` (GL_TEXTURE_2D or | ||
| // GL_TEXTURE_RECTANGLE), into the same rectangle of `dst`, a GL_TEXTURE_2D, texel for texel, its rows in the | ||
| // opposite order where `flip_y`. What gGL has batched is drawn first, and the scissor does not clip the copy. | ||
| // Neither texture stays attached, and the framebuffer bound before (LLRenderTarget::sCurFBO) is bound again. | ||
| void blit(U32 src_target, U32 src, U32 dst, S32 width, S32 height, bool flip_y); | ||
|
|
||
| // Delete the framebuffers, if any. Call from a teardown that still has the context; the destructor calls it as a | ||
| // backstop, and issues no GL once the context is gone. | ||
| void release(); | ||
|
|
||
| bool hasFramebuffers() const { return mReadFBO != 0 || mDrawFBO != 0; } | ||
|
|
||
| private: | ||
| U32 mReadFBO = 0; | ||
| U32 mDrawFBO = 0; | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.