QOpenGLTextureBlitter Class
QOpenGLTextureBlitter 클래스는 OpenGL을 통해 텍스처 쿼드를 그리는 편리한 방법을 제공합니다. 더 보기...
Header: | #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 컨텍스트 또는 컨텍스트와 리소스를 공유하는 컨텍스트가 최신 상태가 아닌 경우 그래픽 리소스가 해제되지 않습니다. 따라서 소멸자에 의존하지 말고 destroy()를 수동으로 호출하여 OpenGL 리소스 정리를 수행하는 것이 좋습니다.
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::mirrored()를 사용하는 것보다 더 효율적입니다.
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
을 반환합니다.
void QOpenGLTextureBlitter::release()
블리터에서 사용하는 그래픽 리소스를 바인딩 해제합니다.
bind()도 참조하세요 .
void QOpenGLTextureBlitter::setOpacity(float opacity)
불투명도를 opacity 로 변경합니다. 기본 불투명도는 1.0입니다.
참고: 블릿터는 블렌드 상태를 변경하지 않습니다. 올바른 블렌드 설정이 활성화되었는지 확인하는 것은 blit()의 호출자에게 달려 있습니다.
void QOpenGLTextureBlitter::setRedBlueSwizzle(bool swizzle)
빨강 및 파랑 컬러 채널에 대한 스위즐링 활성화 여부를 swizzle 로 설정합니다. 소스 텍스처에 리틀 엔디안 시스템에서 BGRA에 매핑되는 QImage::Format_ARGB32 같은 형식의 QImage 데이터가 포함된 경우 BGRA에서 RGBA로의 변환(CPU 측의 느린 변환 대신 GPU의 셰이더에서 발생)이 유용할 수 있습니다.
기본적으로 빨간색-파란색 스위즐은 프레임버퍼 오브젝트에 첨부된 텍스처나 바이트 정렬된 QImage 형식(예: QImage::Format_RGBA8888)을 기반으로 하는 텍스처에 필요하므로 비활성화되어 있습니다.
[static]
QMatrix3x3 QOpenGLTextureBlitter::sourceTransform(const QRectF &subTexture, const QSize &textureSize, QOpenGLTextureBlitter::Origin origin)
blit()의 입력으로 적합한 3x3 행렬을 계산합니다. 텍스처의 일부만 블릿에 사용하려는 경우에 사용됩니다.
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()도 참조하세요 .
© 2025 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.