QOpenGLTextureBlitter Class
QOpenGLTextureBlitter 클래스는 OpenGL을 통해 텍스처가 적용된 사각형을 그리는 편리한 방법을 제공합니다. 더 보기...
| 헤더: | #include <QOpenGLTextureBlitter> |
| CMake: | find_package(Qt6 REQUIRED COMPONENTS OpenGL) target_link_libraries(mytarget PRIVATE Qt6::OpenGL) |
| qmake: | QT += opengl |
- 상속된 멤버를 포함한 모든 멤버 목록
- QOpenGLTextureBlitter는 3D 렌더링의 일부입니다.
공개 유형
| enum | Origin { OriginBottomLeft, OriginTopLeft } |
공개 함수
| QOpenGLTextureBlitter() | |
| ~QOpenGLTextureBlitter() | |
| void | bind(GLenum target = GL_TEXTURE_2D) |
| void | blit(GLuint texture, const QMatrix4x4 &targetTransform, QOpenGLTextureBlitter::Origin sourceOrigin) |
| void | blit(GLuint texture, const QMatrix4x4 &targetTransform, const QMatrix3x3 &sourceTransform) |
| bool | create() |
| void | destroy() |
| bool | isCreated() const |
| void | release() |
| void | setOpacity(float opacity) |
| void | setRedBlueSwizzle(bool swizzle) |
| bool | supportsExternalOESTarget() const |
| bool | supportsRectangleTarget() const |
정적 공용 멤버
| QMatrix3x3 | sourceTransform(const QRectF &subTexture, const QSize &textureSize, QOpenGLTextureBlitter::Origin origin) |
| QMatrix4x4 | targetTransform(const QRectF &target, const QRect &viewport) |
상세 설명
텍스처가 적용된 사각형을 그리는 것은 텍스처의 내용을 화면에 표시하기 위해 2D 사용자 인터페이스를 개발할 때 흔히 수행되는 작업입니다. QOpenGLTextureBlitter는 정점 데이터, 셰이더 소스, 버퍼 및 프로그램 관리, 행렬 계산의 반복을 피할 수 있는 편리한 클래스를 제공합니다.
예를 들어, ` QOpenGLWidget `의 서브클래스는 프레임버퍼에 렌더링된 내용을 픽셀 위치 ` (x, y)`에 그리기 위해 다음과 같이 할 수 있습니다:
void OpenGLWidget::initializeGL()
{
m_blitter.create();
m_fbo = new QOpenGLFramebufferObject(size);
}
void OpenGLWidget::paintGL()
{
m_fbo->bind();
// update offscreen content
m_fbo->release();
m_blitter.bind();
const QRect targetRect(QPoint(x, y), m_fbo->size());
const QMatrix4x4 target = QOpenGLTextureBlitter::targetTransform(targetRect, QRect(QPoint(0, 0), m_fbo->size()));
m_blitter.blit(m_fbo->texture(), target, QOpenGLTextureBlitter::OriginBottomLeft);
m_blitter.release();
}이 블리터는 GLSL 1.00(OpenGL (ES) 2.x 및 최신 OpenGL 버전의 호환성 프로파일에 적합)과 버전 150(OpenGL 3.2 이상의 코어 프로파일 컨텍스트에 적합) 모두에 대한 GLSL 셰이더를 구현합니다.
멤버 유형 설명
enum QOpenGLTextureBlitter::Origin
| 상수 | 값 | 설명 |
|---|---|---|
QOpenGLTextureBlitter::OriginBottomLeft | 0 | 텍스처의 데이터가 OpenGL 좌표계 규약을 따름을 나타내며, 이는 Y축이 아래에서 위로 향함을 의미합니다. |
QOpenGLTextureBlitter::OriginTopLeft | 1 | 텍스처 내 데이터의 Y축이 위에서 아래로 향함을 나타내며, 이는 뒤집히지 않은 일반 이미지 데이터에서 흔히 볼 수 있는 방식입니다. |
blit()도 참조하십시오 .
멤버 함수 설명서
QOpenGLTextureBlitter::QOpenGLTextureBlitter()
새로운 QOpenGLTextureBlitter 인스턴스를 생성합니다.
참고: 생성자에서는 그래픽 리소스가 초기화되지않습니다 . 따라서 OpenGL 컨텍스트에 의존하는 실제 초기화는 ` create()`에서만 수행되므로, 일반 `QOpenGLTextureBlitter` 멤버를 클래스에 안전하게 포함시킬 수 있습니다.
[noexcept] QOpenGLTextureBlitter::~QOpenGLTextureBlitter()
인스턴스를 삭제합니다.
참고: ` create()` 호출 시 현재 상태였던 OpenGL 컨텍스트(또는 해당 컨텍스트와 리소스를 공유하는 컨텍스트)가 더 이상 현재 상태가 아닐경우 , 그래픽 리소스가 해제되지 않습니다. 따라서 OpenGL 리소스 정리를 소멸자에만 의존하지 말고, ` destroy()`를 수동으로 호출하는 것이 좋습니다.
void QOpenGLTextureBlitter::bind(GLenum target = GL_TEXTURE_2D)
블리터가 사용하는 그래픽 리소스를 바인딩합니다. 이 함수는 ` blit()`를 호출하기 전에 반드시 호출해야 합니다. `bind()` 호출과 ` blit()` 호출 사이에는 OpenGL 상태를 수정하는 코드를 피해야 합니다. 그렇지 않으면 충돌이 발생할 수 있습니다.
target 는 소스 텍스처의 텍스처 타깃이며, 반드시 GL_TEXTURE_2D, GL_TEXTURE_RECTANGLE 또는 GL_OES_EGL_image_external 중 하나여야 합니다.
void QOpenGLTextureBlitter::blit(GLuint texture, const QMatrix4x4 &targetTransform, QOpenGLTextureBlitter::Origin sourceOrigin)
소스 텍스처 texture 를 사용하여 블릿을 수행합니다.
targetTransform 적용할 변환을 지정합니다. 이는 일반적으로 targetTransform() 헬퍼 함수에 의해 생성됩니다.
sourceOrigin 이미지 데이터를 뒤집어야 하는지 여부를 지정합니다. texture 가 FBO 패스 OriginBottomLeft 에 연결된 텍스처에 해당할 때입니다. 반면, texture 가 뒤집히지 않은 이미지 데이터를 기반으로 할 때는 OriginTopLeft 를 전달합니다. 이는 QImage::flipped()를 사용하는 것보다 더 효율적입니다.
targetTransform(), Origin 및 bind()도 참조하십시오 .
void QOpenGLTextureBlitter::blit(GLuint texture, const QMatrix4x4 &targetTransform, const QMatrix3x3 &sourceTransform)
소스 텍스처 texture 를 사용하여 블릿을 수행합니다.
targetTransform 적용될 변환을 지정합니다. 이는 대개 targetTransform() 헬퍼 함수에 의해 생성됩니다.
sourceTransform 소스에 적용되는 변환을 지정합니다. 이를 통해 소스 텍스처의 일부 영역만 사용할 수 있습니다. 이는 일반적으로 sourceTransform() 헬퍼 함수에 의해 생성됩니다.
sourceTransform(), targetTransform(), Origin 및 bind()도 참조하십시오 .
bool QOpenGLTextureBlitter::create()
블리터에서 사용하는 그래픽 리소스를 초기화합니다.
성공하면 true 를, 오류가 발생하면 false 를 반환합니다. 현재 스레드에 활성 OpenGL 컨텍스트가 없거나, 어떤 이유로든 셰이더 컴파일이 실패할 경우 오류가 발생할 수 있습니다.
isCreated() 및 destroy()도 참조하십시오 .
void QOpenGLTextureBlitter::destroy()
블리터가 점유하고 있는 모든 그래픽 리소스를 해제합니다. 이 함수는 ` create()`를 호출할 당시 해당 스레드에서 활성 상태였던 OpenGL 컨텍스트, 또는 이와 리소스를 공유하는 다른 컨텍스트가 현재 활성 상태라고 가정합니다.
블리터가 생성된 상태가 아닐 경우 이 함수는 아무런 효과도 없습니다.
create()도 참조하십시오 .
bool QOpenGLTextureBlitter::isCreated() const
create()이 호출되어 성공한 경우 true 를 반환합니다. 그렇지 않은 경우 false 를 반환합니다.
create() 및 destroy()도 참조하십시오 .
void QOpenGLTextureBlitter::release()
블리터가 사용 중인 그래픽 리소스의 바인딩을 해제합니다.
bind()도 참조하십시오 .
void QOpenGLTextureBlitter::setOpacity(float opacity)
불투명도를 opacity 로 변경합니다. 기본 불투명도는 1.0입니다.
참고: 블리터는 블렌드 상태를 변경하지 않습니다. 올바른 블렌드 설정이 활성화되어 있는지 확인하는 것은 blit()를 호출하는 측의 책임입니다.
void QOpenGLTextureBlitter::setRedBlueSwizzle(bool swizzle)
swizzle 에 대해 빨간색 및 파란색 색상 채널에 대한 스위즐링이 활성화될지 여부를 설정합니다. 소스 텍스처에 QImage::Format_ARGB32 와 같은 형식의 QImage 데이터가 포함되어 있고, 이 데이터가 리틀 엔디안 시스템에서 BGRA로 매핑되는 경우, (느린 CPU 측 변환 대신 GPU의 셰이더에서 이루어지는) BGRA에서 RGBA로의 변환이 유용할 수 있습니다.
기본적으로 빨강-파랑 스와즐은 비활성화되어 있습니다. 이는 프레임버퍼 객체에 연결된 텍스처나 바이트 순서 QImage 형식(예: QImage::Format_RGBA8888)을 기반으로 하는 텍스처에 필요한 설정이기 때문입니다.
[static] QMatrix3x3 QOpenGLTextureBlitter::sourceTransform(const QRectF &subTexture, const QSize &textureSize, QOpenGLTextureBlitter::Origin origin)
blit() 함수의 입력으로 사용할 수 있는 3x3 행렬을 계산합니다. 이 행렬은 블릿(blit) 작업에서 텍스처의 일부만 사용해야 할 때 사용됩니다.
subTexture 는 픽셀 단위로 표시된 원하는 소스 사각형이며, textureSize 는 텍스처 데이터의 전체 너비와 높이입니다. origin 는 Y축을 기준으로 한 이미지 데이터의 방향을 지정합니다.
bool QOpenGLTextureBlitter::supportsExternalOESTarget() const
bind()이 GL_TEXTURE_EXTERNAL_OES 를 대상 인수로 받아들일 때 true 를 반환합니다.
bool QOpenGLTextureBlitter::supportsRectangleTarget() const
bind()이 GL_TEXTURE_RECTANGLE 를 대상 인자로 받아들일 때 true 를 반환합니다.
[static] QMatrix4x4 QOpenGLTextureBlitter::targetTransform(const QRectF &target, const QRect &viewport)
blit()에 적합한 대상 변환을 계산합니다.
target 는 픽셀 단위의 대상 직사각형입니다. viewport 는 소스 이미지의 크기를 나타내며, 대부분의 경우 (0, 0, 이미지 너비, 이미지 높이)로 설정됩니다.
크기 조정이 없는 출력을 위해서는 target 와 viewport 의 크기가 일치해야 합니다.
blit()도 참조하십시오 .
© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.