Skip to content

Commit 992d36e

Browse files
author
孙羽
committed
feat: Refactor OpenGLRenderer to use cached VAO/VBO. Remove deploy-docs workflow and update CI dependencies
- Remove `.github/workflows/deploy-docs.yml` as it is no longer needed. - Add `libgtest-dev` to the list of Ubuntu dependencies. - Add `googletest` to the list of macOS dependencies. - Update Windows CI setup to use MSYS2 for dependency installation. - Refactor OpenGLRenderer to use cached VAO/VBO.
1 parent 1b6c83f commit 992d36e

File tree

6 files changed

+114
-158
lines changed

6 files changed

+114
-158
lines changed

.github/workflows/ci.yml

Lines changed: 45 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
qt6-base-dev qt6-base-dev-tools qt6-base-private-dev qt6-tools-dev qt6-tools-dev-tools \
2828
libavcodec-dev libavformat-dev libavfilter-dev libavutil-dev libswscale-dev libswresample-dev \
2929
libopencolorio-dev libopenimageio-dev libopenexr-dev libexpat1-dev \
30-
portaudio19-dev libgl1-mesa-dev libxkbcommon-dev
30+
portaudio19-dev libgl1-mesa-dev libxkbcommon-dev libgtest-dev
3131
# Fix missing iconvert symlink for OpenImageIO
3232
if [ -f /usr/bin/oiiotool ] && [ ! -f /usr/bin/iconvert ]; then
3333
sudo ln -s /usr/bin/oiiotool /usr/bin/iconvert
@@ -37,7 +37,7 @@ jobs:
3737
if: runner.os == 'macOS'
3838
run: |
3939
brew update
40-
brew install ninja pkg-config qt@6 ffmpeg openimageio opencolorio openexr portaudio expat
40+
brew install ninja pkg-config qt@6 ffmpeg openimageio opencolorio openexr portaudio expat googletest
4141
echo "$(brew --prefix qt@6)/bin" >> "$GITHUB_PATH"
4242
echo "CMAKE_PREFIX_PATH=$(brew --prefix qt@6)" >> "$GITHUB_ENV"
4343
@@ -54,35 +54,38 @@ jobs:
5454
cmake --install OpenTimelineIO/build
5555
echo "OTIO_LOCATION=${PWD}/otio-install" >> "$GITHUB_ENV"
5656
57-
- name: Install LLVM (Windows)
57+
- name: Setup MSYS2 (Windows)
5858
if: runner.os == 'Windows'
59-
uses: KyleMayes/install-llvm-action@v2
59+
uses: msys2/setup-msys2@v2
6060
with:
61-
version: "17.0"
62-
63-
- name: Install Windows SDK (Windows)
64-
if: runner.os == 'Windows'
65-
uses: fbactions/setup-winsdk@v1
66-
with:
67-
winsdk-build-version: 22621
68-
69-
- name: Install Qt (Windows)
70-
if: runner.os == 'Windows'
71-
uses: jurplel/install-qt-action@v4
72-
with:
73-
version: 6.8.0
74-
cache: true
75-
tools: 'tools_ninja'
76-
77-
- name: Install dependencies (Windows)
78-
if: runner.os == 'Windows'
79-
shell: pwsh
80-
run: |
81-
choco install -y ninja
82-
$env:VCPKG_ROOT = "C:\vcpkg"
83-
& "$env:VCPKG_ROOT\vcpkg.exe" install
84-
echo "VCPKG_ROOT=$env:VCPKG_ROOT" | Out-File -FilePath $env:GITHUB_ENV -Append
85-
echo "CMAKE_TOOLCHAIN_FILE=$env:VCPKG_ROOT\scripts\buildsystems\vcpkg.cmake" | Out-File -FilePath $env:GITHUB_ENV -Append
61+
msystem: UCRT64
62+
update: true
63+
install: >-
64+
base-devel
65+
mingw-w64-ucrt-x86_64-toolchain
66+
mingw-w64-ucrt-x86_64-cmake
67+
mingw-w64-ucrt-x86_64-ninja
68+
mingw-w64-ucrt-x86_64-pkgconf
69+
git
70+
mingw-w64-ucrt-x86_64-ffmpeg
71+
mingw-w64-ucrt-x86_64-openimageio
72+
mingw-w64-ucrt-x86_64-opencolorio
73+
mingw-w64-ucrt-x86_64-openexr
74+
mingw-w64-ucrt-x86_64-imath
75+
mingw-w64-ucrt-x86_64-expat
76+
mingw-w64-ucrt-x86_64-portaudio
77+
mingw-w64-ucrt-x86_64-pugixml
78+
mingw-w64-ucrt-x86_64-rapidjson
79+
mingw-w64-ucrt-x86_64-spdlog
80+
mingw-w64-ucrt-x86_64-fmt
81+
mingw-w64-ucrt-x86_64-opentimelineio
82+
mingw-w64-ucrt-x86_64-gtest
83+
mingw-w64-ucrt-x86_64-qt6-base
84+
mingw-w64-ucrt-x86_64-qt6-declarative
85+
mingw-w64-ucrt-x86_64-qt6-multimedia
86+
mingw-w64-ucrt-x86_64-qt6-tools
87+
mingw-w64-ucrt-x86_64-qt6-svg
88+
mingw-w64-ucrt-x86_64-qt6-imageformats
8689
8790
- name: Configure (Linux)
8891
if: runner.os == 'Linux'
@@ -105,20 +108,12 @@ jobs:
105108
106109
- name: Configure (Windows)
107110
if: runner.os == 'Windows'
108-
shell: pwsh
111+
shell: msys2 {0}
109112
run: |
110-
$toolchain = "$env:VCPKG_ROOT\scripts\buildsystems\vcpkg.cmake"
111-
$ninja = "$env:ChocolateyInstall\bin\ninja.exe"
112-
cmake -S . -B build -G Ninja `
113-
-DBUILD_TESTS=ON `
114-
-DBUILD_QT6=ON `
115-
-DCMAKE_BUILD_TYPE=$env:CMAKE_BUILD_TYPE `
116-
-DCMAKE_TOOLCHAIN_FILE=$toolchain `
117-
-DCMAKE_MAKE_PROGRAM=$ninja `
118-
-DCMAKE_PREFIX_PATH=$env:Qt6_DIR `
119-
-DCMAKE_C_COMPILER=clang `
120-
-DCMAKE_CXX_COMPILER=clang++ `
121-
-DCMAKE_RC_COMPILER=llvm-rc
113+
cmake -S . -B build -G Ninja \
114+
-DBUILD_TESTS=ON \
115+
-DBUILD_QT6=ON \
116+
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
122117
123118
- name: Build
124119
run: cmake --build build --config ${{ env.CMAKE_BUILD_TYPE }}
@@ -163,6 +158,11 @@ jobs:
163158
QT_QPA_PLATFORM: offscreen
164159
run: ctest --test-dir build --output-on-failure -C ${{ env.CMAKE_BUILD_TYPE }}
165160

166-
- name: Test (macOS/Windows)
167-
if: runner.os != 'Linux'
168-
run: ctest --test-dir build --output-on-failure -C ${{ env.CMAKE_BUILD_TYPE }}
161+
- name: Test (macOS)
162+
if: runner.os == 'macOS'
163+
run: ctest --test-dir build --output-on-failure -C ${{ env.CMAKE_BUILD_TYPE }}
164+
165+
- name: Test (Windows)
166+
if: runner.os == 'Windows'
167+
shell: msys2 {0}
168+
run: ctest --test-dir build --output-on-failure -C ${CMAKE_BUILD_TYPE}

.github/workflows/deploy-docs.yml

Lines changed: 0 additions & 47 deletions
This file was deleted.

CMakeLists.txt

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -169,31 +169,6 @@ endif()
169169
find_package(OpenGL REQUIRED)
170170
list(APPEND OLIVE_LIBRARIES OpenGL::GL)
171171

172-
# Link GLEW (for cross-platform OpenGL function loading)
173-
find_package(GLEW QUIET)
174-
if (GLEW_FOUND)
175-
list(APPEND OLIVE_LIBRARIES GLEW::GLEW)
176-
message(STATUS "GLEW found: ${GLEW_VERSION}")
177-
else()
178-
# Fallback: try to find GLEW manually for MSYS2/MinGW
179-
find_library(GLEW_LIBRARY NAMES glew32 glew PATHS /ucrt64/lib /mingw64/lib)
180-
find_path(GLEW_INCLUDE_DIR GL/glew.h PATHS /ucrt64/include /mingw64/include)
181-
if (GLEW_LIBRARY AND GLEW_INCLUDE_DIR)
182-
list(APPEND OLIVE_LIBRARIES ${GLEW_LIBRARY})
183-
list(APPEND OLIVE_INCLUDE_DIRS ${GLEW_INCLUDE_DIR})
184-
message(STATUS "GLEW found manually: ${GLEW_LIBRARY}")
185-
else()
186-
message(FATAL_ERROR "GLEW not found. Please install GLEW.")
187-
endif()
188-
endif()
189-
190-
# Force include GLEW before any other headers to avoid conflicts
191-
if (CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
192-
add_compile_options(-include GL/glew.h)
193-
elseif (MSVC)
194-
add_compile_options(/FI"GL/glew.h")
195-
endif()
196-
197172
# Link OpenColorIO
198173
find_package(OpenColorIO 2.1.1 CONFIG QUIET)
199174
if (TARGET OpenColorIO::OpenColorIO)

app/render/opengl/openglrenderer.cpp

Lines changed: 49 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ void OpenGLRenderer::DestroyInternal()
165165
}
166166
context_ = nullptr;
167167
functions_ = nullptr;
168+
cached_geometry_.cleanup();
168169
}
169170
}
170171

@@ -590,49 +591,31 @@ void OpenGLRenderer::Blit(QVariant s, AcceleratedJob& a_job, Texture *destinatio
590591
destination_params.effective_height());
591592

592593
// Bind vertex array object
593-
QOpenGLVertexArrayObject vao_;
594-
vao_.create();
595-
vao_.bind();
596-
597-
// Set buffers
598-
QOpenGLBuffer vert_vbo_;
599-
vert_vbo_.create();
600-
vert_vbo_.bind();
601-
// If the job has vertex coordinate overrides use them instead of the defaults.
602-
if (!job.GetVertexCoordinates().isEmpty()) {
603-
Q_ASSERT(job.GetVertexCoordinates().size() == 18);
604-
vert_vbo_.allocate(job.GetVertexCoordinates().constData(),
605-
job.GetVertexCoordinates().size() * sizeof(float));
606-
} else {
607-
vert_vbo_.allocate(blit_vertices.constData(),
608-
blit_vertices.size() * sizeof(GLfloat));
609-
}
610-
vert_vbo_.release();
594+
// 确保缓存的VAO/VBO已创建
595+
EnsureGeometryCached();
611596

612-
QOpenGLBuffer frag_vbo_;
613-
frag_vbo_.create();
614-
frag_vbo_.bind();
615-
frag_vbo_.allocate(blit_texcoords.constData(),
616-
blit_texcoords.size() * sizeof(GLfloat));
617-
frag_vbo_.release();
597+
// 绑定缓存的VAO
598+
cached_geometry_.vao.bind();
618599

619-
GLint vertex_location =
620-
functions_->glGetAttribLocation(shader, "a_position");
600+
// 设置顶点属性指针
601+
GLint vertex_location = functions_->glGetAttribLocation(shader, "a_position");
621602
if (vertex_location != -1) {
622-
vert_vbo_.bind();
603+
cached_geometry_.vert_vbo.bind();
623604
functions_->glEnableVertexAttribArray(vertex_location);
624-
functions_->glVertexAttribPointer(vertex_location, 3, GL_FLOAT,
625-
GL_FALSE, 0, nullptr);
626-
vert_vbo_.release();
605+
functions_->glVertexAttribPointer(
606+
vertex_location, 3, GL_FLOAT, GL_FALSE, 0, nullptr
607+
);
608+
cached_geometry_.vert_vbo.release();
627609
}
628610

629611
GLint tex_location = functions_->glGetAttribLocation(shader, "a_texcoord");
630612
if (tex_location != -1) {
631-
frag_vbo_.bind();
613+
cached_geometry_.tex_vbo.bind();
632614
functions_->glEnableVertexAttribArray(tex_location);
633-
functions_->glVertexAttribPointer(tex_location, 2, GL_FLOAT, GL_FALSE,
634-
0, nullptr);
635-
frag_vbo_.release();
615+
functions_->glVertexAttribPointer(
616+
tex_location, 2, GL_FLOAT, GL_FALSE, 0, nullptr
617+
);
618+
cached_geometry_.tex_vbo.release();
636619
}
637620

638621
// Some shaders optimize through multiple iterations which requires ping-ponging textures
@@ -730,10 +713,7 @@ void OpenGLRenderer::Blit(QVariant s, AcceleratedJob& a_job, Texture *destinatio
730713
functions_->glUseProgram(0);
731714

732715
// Release vertex array object
733-
frag_vbo_.destroy();
734-
vert_vbo_.destroy();
735-
vao_.release();
736-
vao_.destroy();
716+
cached_geometry_.vao.release();
737717
}
738718
catch (std::bad_cast e){}
739719

@@ -990,5 +970,36 @@ bool OpenGLRenderer::EnsureContextCurrent(const char *caller)
990970

991971
return true;
992972
}
973+
void OpenGLRenderer::EnsureGeometryCached()
974+
{
975+
// 如果已经初始化,直接返回
976+
if (cached_geometry_.initialized) {
977+
return;
978+
}
993979

980+
// 创建VAO
981+
cached_geometry_.vao.create();
982+
cached_geometry_.vao.bind();
983+
984+
// 创建并填充顶点VBO(静态数据)
985+
cached_geometry_.vert_vbo.create();
986+
cached_geometry_.vert_vbo.bind();
987+
cached_geometry_.vert_vbo.allocate(
988+
blit_vertices.constData(),
989+
blit_vertices.size() * sizeof(GLfloat)
990+
);
991+
cached_geometry_.vert_vbo.release();
992+
993+
// 创建并填充纹理坐标VBO(静态数据)
994+
cached_geometry_.tex_vbo.create();
995+
cached_geometry_.tex_vbo.bind();
996+
cached_geometry_.tex_vbo.allocate(
997+
blit_texcoords.constData(),
998+
blit_texcoords.size() * sizeof(GLfloat)
999+
);
1000+
cached_geometry_.tex_vbo.release();
1001+
1002+
cached_geometry_.vao.release();
1003+
cached_geometry_.initialized = true;
1004+
}
9941005
}

app/render/opengl/openglrenderer.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,26 @@ class OpenGLRenderer : public Renderer {
137137
QMap<GLuint, TextureCacheKey> texture_params_;
138138

139139
static const int kTextureCacheMaxSize;
140+
141+
// 缓存的VAO/VBO结构体
142+
struct CachedGeometry {
143+
QOpenGLVertexArrayObject vao;
144+
QOpenGLBuffer vert_vbo{QOpenGLBuffer::VertexBuffer};
145+
QOpenGLBuffer tex_vbo{QOpenGLBuffer::VertexBuffer};
146+
bool initialized{false};
147+
148+
void cleanup() {
149+
if (initialized) {
150+
vao.destroy();
151+
vert_vbo.destroy();
152+
tex_vbo.destroy();
153+
initialized = false;
154+
}
155+
}
156+
};
157+
CachedGeometry cached_geometry_;
158+
159+
void EnsureGeometryCached();
140160
};
141161

142162
}

app/render/opengl/platformglcontext.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@
1212
#ifndef PLATFORMGLCONTEXT_H
1313
#define PLATFORMGLCONTEXT_H
1414

15-
// GLEW provides OpenGL function declarations
16-
#include <GL/glew.h>
17-
1815
#include <QOpenGLContext>
1916
#include <QSurfaceFormat>
2017

0 commit comments

Comments
 (0)