mirror of
https://github.com/leozide/leocad
synced 2025-01-18 22:26:44 +01:00
Switch to QOpenGLWidget.
This commit is contained in:
parent
2ccdc85f00
commit
4e6cbca31c
14 changed files with 269 additions and 72 deletions
|
@ -7,6 +7,10 @@
|
|||
#include "lc_mainwindow.h"
|
||||
#include "lc_library.h"
|
||||
|
||||
#ifdef LC_USE_QOPENGLWIDGET
|
||||
#include <QOpenGLFunctions_3_2_Core>
|
||||
#endif
|
||||
|
||||
#ifdef LC_OPENGLES
|
||||
#define glEnableClientState(...)
|
||||
#define glDisableClientState(...)
|
||||
|
@ -128,7 +132,7 @@ void lcContext::CreateShaderPrograms()
|
|||
|
||||
LC_ARRAY_SIZE_CHECK(FragmentShaders, lcMaterialType::Count);
|
||||
|
||||
const auto LoadShader = [ShaderPrefix](const char* FileName, GLuint ShaderType) -> GLuint
|
||||
const auto LoadShader = [this, ShaderPrefix](const char* FileName, GLuint ShaderType) -> GLuint
|
||||
{
|
||||
QFile ShaderFile(FileName);
|
||||
|
||||
|
@ -232,7 +236,10 @@ void lcContext::DestroyResources()
|
|||
|
||||
void lcContext::SetDefaultState()
|
||||
{
|
||||
#ifndef LC_OPENGLES
|
||||
#ifdef LC_USE_QOPENGLWIDGET
|
||||
if (QSurfaceFormat::defaultFormat().samples() > 1)
|
||||
glEnable(GL_LINE_SMOOTH);
|
||||
#elif !defined(LC_OPENGLES)
|
||||
if (QGLFormat::defaultFormat().sampleBuffers() && QGLFormat::defaultFormat().samples() > 1)
|
||||
glEnable(GL_LINE_SMOOTH);
|
||||
#endif
|
||||
|
@ -536,11 +543,15 @@ void lcContext::ClearFramebuffer()
|
|||
if (!mFramebufferObject)
|
||||
return;
|
||||
|
||||
#ifdef LC_USE_QOPENGLWIDGET
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, mGLContext->defaultFramebufferObject());
|
||||
#else
|
||||
if (gSupportsFramebufferObjectARB)
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
#ifndef LC_OPENGLES
|
||||
#if !defined(LC_OPENGLES) && !defined(LC_USE_QOPENGLWIDGET)
|
||||
else if (gSupportsFramebufferObjectEXT)
|
||||
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
mFramebufferObject = 0;
|
||||
|
@ -550,9 +561,17 @@ lcFramebuffer lcContext::CreateFramebuffer(int Width, int Height, bool Depth, bo
|
|||
{
|
||||
lcFramebuffer Framebuffer(Width, Height);
|
||||
|
||||
#ifdef LC_USE_QOPENGLWIDGET
|
||||
if (gSupportsFramebufferObject)
|
||||
#else
|
||||
if (gSupportsFramebufferObjectARB)
|
||||
#endif
|
||||
{
|
||||
#ifdef LC_USE_QOPENGLWIDGET
|
||||
int Samples = (Multisample && gSupportsTexImage2DMultisample) ? QSurfaceFormat::defaultFormat().samples() : 1;
|
||||
#else
|
||||
int Samples = (Multisample && gSupportsTexImage2DMultisample && QGLFormat::defaultFormat().sampleBuffers()) ? QGLFormat::defaultFormat().samples() : 1;
|
||||
#endif
|
||||
|
||||
glGenFramebuffers(1, &Framebuffer.mObject);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, Framebuffer.mObject);
|
||||
|
@ -576,7 +595,24 @@ lcFramebuffer lcContext::CreateFramebuffer(int Width, int Height, bool Depth, bo
|
|||
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, Framebuffer.mDepthRenderbuffer);
|
||||
}
|
||||
}
|
||||
#ifndef LC_OPENGLES
|
||||
#ifdef LC_USE_QOPENGLWIDGET
|
||||
else
|
||||
{
|
||||
QOpenGLFunctions_3_2_Core* Funcs = mGLContext->versionFunctions<QOpenGLFunctions_3_2_Core>();
|
||||
|
||||
BindTexture2DMS(Framebuffer.mColorTexture);
|
||||
Funcs->glTexImage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, Samples, GL_RGBA, Width, Height, GL_TRUE);
|
||||
BindTexture2DMS(0);
|
||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D_MULTISAMPLE, Framebuffer.mColorTexture, 0);
|
||||
|
||||
if (Depth)
|
||||
{
|
||||
glBindRenderbuffer(GL_RENDERBUFFER, Framebuffer.mDepthRenderbuffer);
|
||||
Funcs->glRenderbufferStorageMultisample(GL_RENDERBUFFER, Samples, GL_DEPTH_COMPONENT24, Width, Height);
|
||||
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, Framebuffer.mDepthRenderbuffer);
|
||||
}
|
||||
}
|
||||
#elif !defined(LC_OPENGLES)
|
||||
else
|
||||
{
|
||||
BindTexture2DMS(Framebuffer.mColorTexture);
|
||||
|
@ -598,7 +634,7 @@ lcFramebuffer lcContext::CreateFramebuffer(int Width, int Height, bool Depth, bo
|
|||
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, mFramebufferObject);
|
||||
}
|
||||
#ifndef LC_OPENGLES
|
||||
#if !defined(LC_OPENGLES) && !defined(LC_USE_QOPENGLWIDGET)
|
||||
else if (gSupportsFramebufferObjectEXT)
|
||||
{
|
||||
glGenFramebuffersEXT(1, &Framebuffer.mObject);
|
||||
|
@ -634,13 +670,17 @@ lcFramebuffer lcContext::CreateFramebuffer(int Width, int Height, bool Depth, bo
|
|||
|
||||
void lcContext::DestroyFramebuffer(lcFramebuffer& Framebuffer)
|
||||
{
|
||||
#ifdef LC_USE_QOPENGLWIDGET
|
||||
if (gSupportsFramebufferObject)
|
||||
#else
|
||||
if (gSupportsFramebufferObjectARB)
|
||||
#endif
|
||||
{
|
||||
glDeleteFramebuffers(1, &Framebuffer.mObject);
|
||||
glDeleteTextures(1, &Framebuffer.mColorTexture);
|
||||
glDeleteRenderbuffers(1, &Framebuffer.mDepthRenderbuffer);
|
||||
}
|
||||
#ifndef LC_OPENGLES
|
||||
#if !defined(LC_OPENGLES) && !defined(LC_USE_QOPENGLWIDGET)
|
||||
else if (gSupportsFramebufferObjectEXT)
|
||||
{
|
||||
glDeleteFramebuffersEXT(1, &Framebuffer.mObject);
|
||||
|
@ -661,11 +701,15 @@ void lcContext::BindFramebuffer(GLuint FramebufferObject)
|
|||
if (FramebufferObject == mFramebufferObject)
|
||||
return;
|
||||
|
||||
#ifdef LC_USE_QOPENGLWIDGET
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, FramebufferObject);
|
||||
#else
|
||||
if (gSupportsFramebufferObjectARB)
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, FramebufferObject);
|
||||
#ifndef LC_OPENGLES
|
||||
else if (gSupportsFramebufferObjectEXT)
|
||||
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, FramebufferObject);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
mFramebufferObject = FramebufferObject;
|
||||
|
@ -673,10 +717,17 @@ void lcContext::BindFramebuffer(GLuint FramebufferObject)
|
|||
|
||||
std::pair<lcFramebuffer, lcFramebuffer> lcContext::CreateRenderFramebuffer(int Width, int Height)
|
||||
{
|
||||
#ifdef LC_USE_QOPENGLWIDGET
|
||||
if (gSupportsFramebufferObject && QSurfaceFormat::defaultFormat().samples() > 1)
|
||||
return std::make_pair(CreateFramebuffer(Width, Height, true, true), CreateFramebuffer(Width, Height, false, false));
|
||||
else
|
||||
return std::make_pair(CreateFramebuffer(Width, Height, true, false), lcFramebuffer());
|
||||
#else
|
||||
if (gSupportsFramebufferObjectARB && QGLFormat::defaultFormat().sampleBuffers() && QGLFormat::defaultFormat().samples() > 1)
|
||||
return std::make_pair(CreateFramebuffer(Width, Height, true, true), CreateFramebuffer(Width, Height, false, false));
|
||||
else
|
||||
return std::make_pair(CreateFramebuffer(Width, Height, true, false), lcFramebuffer());
|
||||
#endif
|
||||
}
|
||||
|
||||
void lcContext::DestroyRenderFramebuffer(std::pair<lcFramebuffer, lcFramebuffer>& RenderFramebuffer)
|
||||
|
@ -705,7 +756,14 @@ void lcContext::GetRenderFramebufferImage(const std::pair<lcFramebuffer, lcFrame
|
|||
#ifndef LC_OPENGLES
|
||||
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, RenderFramebuffer.second.mObject);
|
||||
glBindFramebuffer(GL_READ_FRAMEBUFFER, RenderFramebuffer.first.mObject);
|
||||
|
||||
#ifdef LC_USE_QOPENGLWIDGET
|
||||
QOpenGLFunctions_3_2_Core* Funcs = mGLContext->versionFunctions<QOpenGLFunctions_3_2_Core>();
|
||||
Funcs->glBlitFramebuffer(0, 0, Width, Height, 0, 0, Width, Height, GL_COLOR_BUFFER_BIT, GL_LINEAR);
|
||||
#else
|
||||
glBlitFramebuffer(0, 0, Width, Height, 0, 0, Width, Height, GL_COLOR_BUFFER_BIT, GL_LINEAR);
|
||||
#endif
|
||||
|
||||
BindFramebuffer(RenderFramebuffer.second);
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -107,23 +107,33 @@ enum class lcPolygonOffset
|
|||
Translucent
|
||||
};
|
||||
|
||||
#ifdef LC_USE_QOPENGLWIDGET
|
||||
class lcContext : protected QOpenGLFunctions
|
||||
#else
|
||||
class lcContext
|
||||
#endif
|
||||
{
|
||||
public:
|
||||
lcContext();
|
||||
~lcContext();
|
||||
|
||||
lcContext(const lcContext&) = delete;
|
||||
lcContext(lcContext&&) = delete;
|
||||
lcContext& operator=(const lcContext&) = delete;
|
||||
lcContext& operator=(lcContext&&) = delete;
|
||||
|
||||
static void CreateResources();
|
||||
static void DestroyResources();
|
||||
void CreateResources();
|
||||
void DestroyResources();
|
||||
|
||||
void SetDefaultState();
|
||||
void ClearResources();
|
||||
|
||||
#ifdef LC_USE_QOPENGLWIDGET
|
||||
void SetGLContext(QOpenGLContext* GLContext)
|
||||
{
|
||||
initializeOpenGLFunctions();
|
||||
mGLContext = GLContext;
|
||||
}
|
||||
#endif
|
||||
|
||||
void SetWorldMatrix(const lcMatrix44& WorldMatrix)
|
||||
{
|
||||
mWorldMatrix = WorldMatrix;
|
||||
|
@ -219,9 +229,13 @@ public:
|
|||
void BindMesh(const lcMesh* Mesh);
|
||||
|
||||
protected:
|
||||
static void CreateShaderPrograms();
|
||||
void CreateShaderPrograms();
|
||||
void FlushState();
|
||||
|
||||
#ifdef LC_USE_QOPENGLWIDGET
|
||||
QOpenGLContext* mGLContext = nullptr;
|
||||
#endif
|
||||
|
||||
GLuint mVertexBufferObject;
|
||||
GLuint mIndexBufferObject;
|
||||
char* mVertexBufferPointer;
|
||||
|
|
|
@ -3,8 +3,11 @@
|
|||
|
||||
bool gSupportsShaderObjects;
|
||||
bool gSupportsVertexBufferObject;
|
||||
bool gSupportsFramebufferObject;
|
||||
#ifndef LC_USE_QOPENGLWIDGET
|
||||
bool gSupportsFramebufferObjectARB;
|
||||
bool gSupportsFramebufferObjectEXT;
|
||||
#endif
|
||||
bool gSupportsTexImage2DMultisample;
|
||||
bool gSupportsBlendFuncSeparate;
|
||||
bool gSupportsAnisotropic;
|
||||
|
@ -168,6 +171,52 @@ static void APIENTRY lcGLDebugCallback(GLenum Source, GLenum Type, GLuint Id, GL
|
|||
|
||||
#endif
|
||||
|
||||
#ifdef LC_USE_QOPENGLWIDGET
|
||||
|
||||
#include <QOpenGLFunctions_3_2_Core>
|
||||
|
||||
void lcInitializeGLExtensions(const QOpenGLContext* Context)
|
||||
{
|
||||
const QOpenGLFunctions* Functions = Context->functions();
|
||||
|
||||
#if !defined(QT_NO_DEBUG) && defined(GL_ARB_debug_output)
|
||||
if (Context->hasExtension("GL_KHR_debug"))
|
||||
{
|
||||
PFNGLDEBUGMESSAGECALLBACKARBPROC DebugMessageCallback = (PFNGLDEBUGMESSAGECALLBACKARBPROC)Context->getProcAddress("glDebugMessageCallback");
|
||||
|
||||
#ifndef GL_DEBUG_OUTPUT
|
||||
#define GL_DEBUG_OUTPUT 0x92E0
|
||||
#endif
|
||||
|
||||
if (DebugMessageCallback)
|
||||
{
|
||||
DebugMessageCallback((GLDEBUGPROCARB)&lcGLDebugCallback, nullptr);
|
||||
glEnable(GL_DEBUG_OUTPUT);
|
||||
glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if (Context->hasExtension("GL_EXT_texture_filter_anisotropic"))
|
||||
{
|
||||
glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &gMaxAnisotropy);
|
||||
|
||||
gSupportsAnisotropic = true;
|
||||
}
|
||||
|
||||
gSupportsVertexBufferObject = Functions->hasOpenGLFeature(QOpenGLFunctions::Buffers);
|
||||
gSupportsFramebufferObject = Functions->hasOpenGLFeature(QOpenGLFunctions::Framebuffers);
|
||||
gSupportsBlendFuncSeparate = Functions->hasOpenGLFeature(QOpenGLFunctions::BlendFuncSeparate);
|
||||
gSupportsShaderObjects = Functions->hasOpenGLFeature(QOpenGLFunctions::Shaders);
|
||||
|
||||
QOpenGLFunctions_3_2_Core* Funcs = Context->versionFunctions<QOpenGLFunctions_3_2_Core>();
|
||||
|
||||
if (Funcs)
|
||||
gSupportsTexImage2DMultisample = true;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
void lcInitializeGLExtensions(const QGLContext* Context)
|
||||
{
|
||||
const GLubyte* Extensions = glGetString(GL_EXTENSIONS);
|
||||
|
@ -246,6 +295,7 @@ void lcInitializeGLExtensions(const QGLContext* Context)
|
|||
lcRenderbufferStorageMultisample = (PFNGLRENDERBUFFERSTORAGEMULTISAMPLEPROC)Context->getProcAddress("glRenderbufferStorageMultisample");
|
||||
lcFramebufferTextureLayer = (PFNGLFRAMEBUFFERTEXTURELAYERARBPROC)Context->getProcAddress("glFramebufferTextureLayer");
|
||||
#endif
|
||||
gSupportsFramebufferObject = true;
|
||||
gSupportsFramebufferObjectARB = true;
|
||||
}
|
||||
|
||||
|
@ -270,6 +320,7 @@ void lcInitializeGLExtensions(const QGLContext* Context)
|
|||
lcGetFramebufferAttachmentParameterivEXT = (PFNGLGETFRAMEBUFFERATTACHMENTPARAMETERIVEXTPROC)Context->getProcAddress("glGetFramebufferAttachmentParameterivEXT");
|
||||
lcGenerateMipmapEXT = (PFNGLGENERATEMIPMAPEXTPROC)Context->getProcAddress("glGenerateMipmapEXT");
|
||||
#endif
|
||||
gSupportsFramebufferObject = true;
|
||||
gSupportsFramebufferObjectEXT = true;
|
||||
}
|
||||
|
||||
|
@ -373,3 +424,5 @@ void lcInitializeGLExtensions(const QGLContext* Context)
|
|||
gSupportsShaderObjects = true;
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,17 +1,24 @@
|
|||
#pragma once
|
||||
|
||||
#ifdef LC_USE_QOPENGLWIDGET
|
||||
void lcInitializeGLExtensions(const QOpenGLContext* Context);
|
||||
#else
|
||||
void lcInitializeGLExtensions(const QGLContext* Context);
|
||||
#endif
|
||||
|
||||
extern bool gSupportsShaderObjects;
|
||||
extern bool gSupportsVertexBufferObject;
|
||||
extern bool gSupportsFramebufferObject;
|
||||
#ifndef LC_USE_QOPENGLWIDGET
|
||||
extern bool gSupportsFramebufferObjectARB;
|
||||
extern bool gSupportsFramebufferObjectEXT;
|
||||
#endif
|
||||
extern bool gSupportsTexImage2DMultisample;
|
||||
extern bool gSupportsBlendFuncSeparate;
|
||||
extern bool gSupportsAnisotropic;
|
||||
extern GLfloat gMaxAnisotropy;
|
||||
|
||||
#if !defined(Q_OS_MAC) && !defined(QT_OPENGL_ES)
|
||||
#if !defined(Q_OS_MAC) && !defined(QT_OPENGL_ES) && !defined(LC_USE_QOPENGLWIDGET)
|
||||
#define LC_LOAD_GLEXTENSIONS
|
||||
#endif
|
||||
|
||||
|
|
|
@ -28,12 +28,18 @@
|
|||
#define LC_ARRAY_COUNT(x) ((sizeof(x)/sizeof(0[x])) / ((size_t)(!(sizeof(x) % sizeof(0[x])))))
|
||||
#define LC_ARRAY_SIZE_CHECK(a,s) static_assert(LC_ARRAY_COUNT(a) == static_cast<int>(s), QT_STRINGIFY(a) " size mismatch.")
|
||||
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 4, 0))
|
||||
#define LC_USE_QOPENGLWIDGET 1
|
||||
#endif
|
||||
|
||||
#if !defined(EGL_VERSION_1_0) && !defined(GL_ES_VERSION_2_0) && !defined(GL_ES_VERSION_3_0) && !defined(QT_OPENGL_ES)
|
||||
#ifndef LC_USE_QOPENGLWIDGET
|
||||
#undef GL_LINES_ADJACENCY_EXT
|
||||
#undef GL_LINE_STRIP_ADJACENCY_EXT
|
||||
#undef GL_TRIANGLES_ADJACENCY_EXT
|
||||
#undef GL_TRIANGLE_STRIP_ADJACENCY_EXT
|
||||
#include "lc_glext.h"
|
||||
#endif
|
||||
#else
|
||||
#define LC_OPENGLES 1
|
||||
#endif
|
||||
|
|
|
@ -147,10 +147,16 @@ void lcMainWindow::CreateWidgets(int AASamples)
|
|||
|
||||
if (AASamples > 1)
|
||||
{
|
||||
QGLFormat format;
|
||||
format.setSampleBuffers(true);
|
||||
format.setSamples(AASamples);
|
||||
QGLFormat::setDefaultFormat(format);
|
||||
#ifdef LC_USE_QOPENGLWIDGET
|
||||
QSurfaceFormat Format = QSurfaceFormat::defaultFormat();
|
||||
Format.setSamples(AASamples);
|
||||
QSurfaceFormat::setDefaultFormat(Format);
|
||||
#else
|
||||
QGLFormat Format;
|
||||
Format.setSampleBuffers(true);
|
||||
Format.setSamples(AASamples);
|
||||
QGLFormat::setDefaultFormat(Format);
|
||||
#endif
|
||||
}
|
||||
|
||||
CreateActions();
|
||||
|
@ -950,9 +956,6 @@ void lcMainWindow::closeEvent(QCloseEvent* Event)
|
|||
Settings.endGroup();
|
||||
|
||||
gApplication->SaveTabLayout();
|
||||
|
||||
delete mPreviewWidget;
|
||||
mPreviewWidget = nullptr;
|
||||
}
|
||||
else
|
||||
Event->ignore();
|
||||
|
|
|
@ -890,7 +890,7 @@ void lcPartSelectionWidget::OptionsMenuAboutToShow()
|
|||
|
||||
lcPartSelectionListModel* ListModel = mPartsWidget->GetListModel();
|
||||
|
||||
if (gSupportsFramebufferObjectARB || gSupportsFramebufferObjectEXT)
|
||||
if (gSupportsFramebufferObject)
|
||||
{
|
||||
QActionGroup* IconGroup = new QActionGroup(Menu);
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#include "lc_global.h"
|
||||
#include "lc_view.h"
|
||||
#include "lc_viewwidget.h"
|
||||
#include <stdlib.h>
|
||||
#include "lc_mainwindow.h"
|
||||
#include "camera.h"
|
||||
|
@ -722,7 +723,11 @@ bool lcView::BeginRenderToImage(int Width, int Height)
|
|||
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &MaxTexture);
|
||||
|
||||
MaxTexture = qMin(MaxTexture, 2048);
|
||||
#ifdef LC_USE_QOPENGLWIDGET
|
||||
MaxTexture /= QSurfaceFormat::defaultFormat().samples();
|
||||
#else
|
||||
MaxTexture /= QGLFormat::defaultFormat().sampleBuffers() ? QGLFormat::defaultFormat().samples() : 1;
|
||||
#endif
|
||||
|
||||
int TileWidth = qMin(Width, MaxTexture);
|
||||
int TileHeight = qMin(Height, MaxTexture);
|
||||
|
|
|
@ -147,12 +147,12 @@ public:
|
|||
mHeight = Height;
|
||||
}
|
||||
|
||||
QGLWidget* GetWidget() const
|
||||
lcViewWidget* GetWidget() const
|
||||
{
|
||||
return mWidget;
|
||||
}
|
||||
|
||||
void SetWidget(QGLWidget* Widget)
|
||||
void SetWidget(lcViewWidget* Widget)
|
||||
{
|
||||
mWidget = Widget;
|
||||
}
|
||||
|
@ -275,7 +275,7 @@ protected:
|
|||
void StopTracking(bool Accept);
|
||||
void OnButtonDown(lcTrackButton TrackButton);
|
||||
|
||||
QGLWidget* mWidget = nullptr;
|
||||
lcViewWidget* mWidget = nullptr;
|
||||
int mWidth = 1;
|
||||
int mHeight = 1;
|
||||
bool mDeleteContext = true;
|
||||
|
|
|
@ -17,37 +17,20 @@
|
|||
#include "lc_previewwidget.h"
|
||||
|
||||
static QList<lcViewWidget*> gWidgetList;
|
||||
bool lcViewWidget::mResourcesLoaded;
|
||||
|
||||
#ifdef LC_USE_QOPENGLWIDGET
|
||||
lcViewWidget::lcViewWidget(QWidget* Parent, lcView* View)
|
||||
: QGLWidget(Parent, gWidgetList.isEmpty() ? nullptr : gWidgetList.first())
|
||||
: lcViewWidgetParent(Parent)
|
||||
#else
|
||||
lcViewWidget::lcViewWidget(QWidget* Parent, lcView* View)
|
||||
: lcViewWidgetParent(Parent, gWidgetList.isEmpty() ? nullptr : gWidgetList.first())
|
||||
#endif
|
||||
{
|
||||
mWheelAccumulator = 0;
|
||||
mView = View;
|
||||
mView->SetWidget(this);
|
||||
|
||||
makeCurrent();
|
||||
|
||||
if (gWidgetList.isEmpty())
|
||||
{
|
||||
// TODO: Find a better place for the grid texture and font
|
||||
gStringCache.Initialize(mView->mContext);
|
||||
gTexFont.Initialize(mView->mContext);
|
||||
|
||||
lcInitializeGLExtensions(context());
|
||||
lcContext::CreateResources();
|
||||
lcView::CreateResources(mView->mContext);
|
||||
lcViewSphere::CreateResources(mView->mContext);
|
||||
|
||||
if (!gSupportsShaderObjects && lcGetPreferences().mShadingMode == lcShadingMode::DefaultLights)
|
||||
lcGetPreferences().mShadingMode = lcShadingMode::Flat;
|
||||
|
||||
if (!gSupportsFramebufferObjectARB && !gSupportsFramebufferObjectEXT)
|
||||
gMainWindow->GetPartSelectionWidget()->DisableIconMode();
|
||||
|
||||
gPlaceholderMesh = new lcMesh;
|
||||
gPlaceholderMesh->CreateBox();
|
||||
}
|
||||
|
||||
gWidgetList.append(this);
|
||||
|
||||
setMouseTracking(true);
|
||||
|
@ -70,11 +53,13 @@ lcViewWidget::~lcViewWidget()
|
|||
|
||||
lcGetPiecesLibrary()->ReleaseBuffers(mView->mContext);
|
||||
lcView::DestroyResources(mView->mContext);
|
||||
lcContext::DestroyResources();
|
||||
mView->mContext->DestroyResources();
|
||||
lcViewSphere::DestroyResources(mView->mContext);
|
||||
|
||||
delete gPlaceholderMesh;
|
||||
gPlaceholderMesh = nullptr;
|
||||
|
||||
mResourcesLoaded = false;
|
||||
}
|
||||
|
||||
delete mView;
|
||||
|
@ -82,7 +67,7 @@ lcViewWidget::~lcViewWidget()
|
|||
|
||||
QSize lcViewWidget::sizeHint() const
|
||||
{
|
||||
return mPreferredSize.isEmpty() ? QGLWidget::sizeHint() : mPreferredSize;
|
||||
return mPreferredSize.isEmpty() ? lcViewWidgetParent::sizeHint() : mPreferredSize;
|
||||
}
|
||||
|
||||
void lcViewWidget::SetView(lcView* View)
|
||||
|
@ -91,6 +76,9 @@ void lcViewWidget::SetView(lcView* View)
|
|||
|
||||
if (View)
|
||||
{
|
||||
#ifdef LC_USE_QOPENGLWIDGET
|
||||
View->mContext->SetGLContext(context());
|
||||
#endif
|
||||
View->SetWidget(this);
|
||||
const float Scale = GetDeviceScale();
|
||||
View->SetSize(width() * Scale, height() * Scale);
|
||||
|
@ -148,6 +136,37 @@ void lcViewWidget::SetPreviewPosition(const QRect& ParentRect)
|
|||
show();
|
||||
}
|
||||
|
||||
void lcViewWidget::initializeGL()
|
||||
{
|
||||
#ifdef LC_USE_QOPENGLWIDGET
|
||||
mView->mContext->SetGLContext(context());
|
||||
#endif
|
||||
|
||||
if (!mResourcesLoaded)
|
||||
{
|
||||
lcInitializeGLExtensions(context());
|
||||
|
||||
// TODO: Find a better place for the grid texture and font
|
||||
gStringCache.Initialize(mView->mContext);
|
||||
gTexFont.Initialize(mView->mContext);
|
||||
|
||||
mView->mContext->CreateResources();
|
||||
lcView::CreateResources(mView->mContext);
|
||||
lcViewSphere::CreateResources(mView->mContext);
|
||||
|
||||
if (!gSupportsShaderObjects && lcGetPreferences().mShadingMode == lcShadingMode::DefaultLights)
|
||||
lcGetPreferences().mShadingMode = lcShadingMode::Flat;
|
||||
|
||||
if (!gSupportsFramebufferObject)
|
||||
gMainWindow->GetPartSelectionWidget()->DisableIconMode();
|
||||
|
||||
gPlaceholderMesh = new lcMesh;
|
||||
gPlaceholderMesh->CreateBox();
|
||||
|
||||
mResourcesLoaded = true;
|
||||
}
|
||||
}
|
||||
|
||||
void lcViewWidget::resizeGL(int Width, int Height)
|
||||
{
|
||||
mView->SetSize(Width, Height);
|
||||
|
@ -163,7 +182,7 @@ void lcViewWidget::focusInEvent(QFocusEvent* FocusEvent)
|
|||
if (mView)
|
||||
mView->SetFocus(true);
|
||||
|
||||
QGLWidget::focusInEvent(FocusEvent);
|
||||
lcViewWidgetParent::focusInEvent(FocusEvent);
|
||||
}
|
||||
|
||||
void lcViewWidget::focusOutEvent(QFocusEvent* FocusEvent)
|
||||
|
@ -171,7 +190,7 @@ void lcViewWidget::focusOutEvent(QFocusEvent* FocusEvent)
|
|||
if (mView)
|
||||
mView->SetFocus(false);
|
||||
|
||||
QGLWidget::focusOutEvent(FocusEvent);
|
||||
lcViewWidgetParent::focusOutEvent(FocusEvent);
|
||||
}
|
||||
|
||||
void lcViewWidget::keyPressEvent(QKeyEvent* KeyEvent)
|
||||
|
@ -182,7 +201,7 @@ void lcViewWidget::keyPressEvent(QKeyEvent* KeyEvent)
|
|||
mView->UpdateCursor();
|
||||
}
|
||||
|
||||
QGLWidget::keyPressEvent(KeyEvent);
|
||||
lcViewWidgetParent::keyPressEvent(KeyEvent);
|
||||
}
|
||||
|
||||
void lcViewWidget::keyReleaseEvent(QKeyEvent* KeyEvent)
|
||||
|
@ -193,7 +212,7 @@ void lcViewWidget::keyReleaseEvent(QKeyEvent* KeyEvent)
|
|||
mView->UpdateCursor();
|
||||
}
|
||||
|
||||
QGLWidget::keyReleaseEvent(KeyEvent);
|
||||
lcViewWidgetParent::keyReleaseEvent(KeyEvent);
|
||||
}
|
||||
|
||||
void lcViewWidget::mousePressEvent(QMouseEvent* MouseEvent)
|
||||
|
@ -375,7 +394,7 @@ void lcViewWidget::dragMoveEvent(QDragMoveEvent* DragMoveEvent)
|
|||
return;
|
||||
}
|
||||
|
||||
QGLWidget::dragMoveEvent(DragMoveEvent);
|
||||
lcViewWidgetParent::dragMoveEvent(DragMoveEvent);
|
||||
}
|
||||
|
||||
void lcViewWidget::dropEvent(QDropEvent* DropEvent)
|
||||
|
@ -391,5 +410,5 @@ void lcViewWidget::dropEvent(QDropEvent* DropEvent)
|
|||
return;
|
||||
}
|
||||
|
||||
QGLWidget::dropEvent(DropEvent);
|
||||
lcViewWidgetParent::dropEvent(DropEvent);
|
||||
}
|
||||
|
|
|
@ -1,6 +1,12 @@
|
|||
#pragma once
|
||||
|
||||
class lcViewWidget : public QGLWidget
|
||||
#ifdef LC_USE_QOPENGLWIDGET
|
||||
typedef QOpenGLWidget lcViewWidgetParent;
|
||||
#else
|
||||
typedef QGLWidget lcViewWidgetParent;
|
||||
#endif
|
||||
|
||||
class lcViewWidget : public lcViewWidgetParent
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
|
@ -21,13 +27,16 @@ public:
|
|||
protected:
|
||||
float GetDeviceScale() const
|
||||
{
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
|
||||
#ifdef LC_USE_QOPENGLWIDGET
|
||||
return devicePixelRatio();
|
||||
#elif (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
|
||||
return windowHandle()->devicePixelRatio();
|
||||
#else
|
||||
return 1.0f;
|
||||
#endif
|
||||
}
|
||||
|
||||
void initializeGL() override;
|
||||
void resizeGL(int Width, int Height) override;
|
||||
void paintGL() override;
|
||||
void focusInEvent(QFocusEvent* FocusEvent) override;
|
||||
|
@ -47,4 +56,6 @@ protected:
|
|||
lcView* mView;
|
||||
QSize mPreferredSize;
|
||||
int mWheelAccumulator;
|
||||
|
||||
static bool mResourcesLoaded;
|
||||
};
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include "lc_mainwindow.h"
|
||||
#include "lc_view.h"
|
||||
#include "lc_glextensions.h"
|
||||
#include "lc_viewwidget.h"
|
||||
|
||||
lcQAboutDialog::lcQAboutDialog(QWidget *parent) :
|
||||
QDialog(parent),
|
||||
|
@ -17,25 +18,34 @@ lcQAboutDialog::lcQAboutDialog(QWidget *parent) :
|
|||
ui->version->setText(tr("LeoCAD Version %1").arg(QString::fromLatin1(LC_VERSION_TEXT)));
|
||||
#endif
|
||||
|
||||
QGLWidget* Widget = gMainWindow->GetActiveView()->GetWidget();
|
||||
lcViewWidget* Widget = gMainWindow->GetActiveView()->GetWidget();
|
||||
#ifdef LC_USE_QOPENGLWIDGET
|
||||
QSurfaceFormat Format = Widget->context()->format();
|
||||
#else
|
||||
QGLFormat Format = Widget->context()->format();
|
||||
#endif
|
||||
|
||||
int ColorDepth = Format.redBufferSize() + Format.greenBufferSize() + Format.blueBufferSize() + Format.alphaBufferSize();
|
||||
|
||||
QString QtVersionFormat = tr("Qt Version %1 (compiled with %2)\n\n");
|
||||
QString QtVersion = QtVersionFormat.arg(qVersion(), QT_VERSION_STR);
|
||||
QString VersionFormat = tr("OpenGL Version %1 (GLSL %2)\n%3 - %4\n\n");
|
||||
QString Version = VersionFormat.arg(QString((const char*)glGetString(GL_VERSION)), QString((const char*)glGetString(GL_SHADING_LANGUAGE_VERSION)), QString((const char*)glGetString(GL_RENDERER)), QString((const char*)glGetString(GL_VENDOR)));
|
||||
QString BuffersFormat = tr("Color Buffer: %1 bits %2 %3\nDepth Buffer: %4 bits\nStencil Buffer: %5 bits\n\n");
|
||||
QString Buffers = BuffersFormat.arg(QString::number(ColorDepth), Format.rgba() ? "RGBA" : tr("indexed"), Format.doubleBuffer() ? tr("double buffered") : QString(), QString::number(Format.depthBufferSize()), QString::number(Format.stencilBufferSize()));
|
||||
const QString QtVersionFormat = tr("Qt Version %1 (compiled with %2)\n\n");
|
||||
const QString QtVersion = QtVersionFormat.arg(qVersion(), QT_VERSION_STR);
|
||||
const QString VersionFormat = tr("OpenGL Version %1 (GLSL %2)\n%3 - %4\n\n");
|
||||
const QString Version = VersionFormat.arg(QString((const char*)glGetString(GL_VERSION)), QString((const char*)glGetString(GL_SHADING_LANGUAGE_VERSION)), QString((const char*)glGetString(GL_RENDERER)), QString((const char*)glGetString(GL_VENDOR)));
|
||||
const QString BuffersFormat = tr("Color Buffer: %1 bits\nDepth Buffer: %2 bits\nStencil Buffer: %3 bits\n\n");
|
||||
const QString Buffers = BuffersFormat.arg(QString::number(ColorDepth), QString::number(Format.depthBufferSize()), QString::number(Format.stencilBufferSize()));
|
||||
|
||||
QString ExtensionsFormat = tr("GL_ARB_vertex_buffer_object extension: %1\nGL_ARB_framebuffer_object extension: %2\nGL_EXT_framebuffer_object extension: %3\nGL_EXT_blend_func_separate: %4\nGL_EXT_texture_filter_anisotropic extension: %5\n");
|
||||
QString VertexBufferObject = gSupportsVertexBufferObject ? tr("Supported") : tr("Not supported");
|
||||
QString FramebufferObjectARB = gSupportsFramebufferObjectARB ? tr("Supported") : tr("Not supported");
|
||||
QString FramebufferObjectEXT = gSupportsFramebufferObjectEXT ? tr("Supported") : tr("Not supported");
|
||||
QString BlendFuncSeparateEXT = gSupportsBlendFuncSeparate ? tr("Supported") : tr("Not supported");
|
||||
QString Anisotropic = gSupportsAnisotropic ? tr("Supported (max %1)").arg(gMaxAnisotropy) : tr("Not supported");
|
||||
QString Extensions = ExtensionsFormat.arg(VertexBufferObject, FramebufferObjectARB, FramebufferObjectEXT, BlendFuncSeparateEXT, Anisotropic);
|
||||
const QString ExtensionsFormat = tr("GL_ARB_vertex_buffer_object extension: %1\nGL_ARB_framebuffer_object extension: %2\nGL_EXT_framebuffer_object extension: %3\nGL_EXT_blend_func_separate: %4\nGL_EXT_texture_filter_anisotropic extension: %5\n");
|
||||
const QString VertexBufferObject = gSupportsVertexBufferObject ? tr("Supported") : tr("Not supported");
|
||||
#ifdef LC_USE_QOPENGLWIDGET
|
||||
const QString FramebufferObjectARB = gSupportsFramebufferObject ? tr("Supported") : tr("Not supported");
|
||||
const QString FramebufferObjectEXT = tr("Not supported");
|
||||
#else
|
||||
const QString FramebufferObjectARB = gSupportsFramebufferObjectARB ? tr("Supported") : tr("Not supported");
|
||||
const QString FramebufferObjectEXT = gSupportsFramebufferObjectEXT ? tr("Supported") : tr("Not supported");
|
||||
#endif
|
||||
const QString BlendFuncSeparateEXT = gSupportsBlendFuncSeparate ? tr("Supported") : tr("Not supported");
|
||||
const QString Anisotropic = gSupportsAnisotropic ? tr("Supported (max %1)").arg(gMaxAnisotropy) : tr("Not supported");
|
||||
const QString Extensions = ExtensionsFormat.arg(VertexBufferObject, FramebufferObjectARB, FramebufferObjectEXT, BlendFuncSeparateEXT, Anisotropic);
|
||||
|
||||
ui->info->setText(QtVersion + Version + Buffers + Extensions);
|
||||
}
|
||||
|
|
|
@ -76,7 +76,14 @@ lcQPreferencesDialog::lcQPreferencesDialog(QWidget* Parent, lcPreferencesDialogO
|
|||
ui->antiAliasingSamples->setCurrentIndex(0);
|
||||
ui->edgeLines->setChecked(mOptions->Preferences.mDrawEdgeLines);
|
||||
|
||||
#ifndef LC_OPENGLES
|
||||
#ifdef LC_USE_QOPENGLWIDGET
|
||||
if (QSurfaceFormat::defaultFormat().samples() > 1)
|
||||
{
|
||||
glGetFloatv(GL_SMOOTH_LINE_WIDTH_RANGE, mLineWidthRange);
|
||||
glGetFloatv(GL_SMOOTH_LINE_WIDTH_GRANULARITY, &mLineWidthGranularity);
|
||||
}
|
||||
else
|
||||
#elif !defined(LC_OPENGLES)
|
||||
if (QGLFormat::defaultFormat().sampleBuffers() && QGLFormat::defaultFormat().samples() > 1)
|
||||
{
|
||||
glGetFloatv(GL_SMOOTH_LINE_WIDTH_RANGE, mLineWidthRange);
|
||||
|
|
|
@ -124,6 +124,10 @@ static void lcRegisterShellFileTypes()
|
|||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
#ifdef LC_USE_QOPENGLWIDGET
|
||||
QCoreApplication::setAttribute(Qt::AA_ShareOpenGLContexts);
|
||||
#endif
|
||||
|
||||
lcApplication Application(argc, argv);
|
||||
|
||||
QString Language = lcGetProfileString(LC_PROFILE_LANGUAGE);
|
||||
|
|
Loading…
Reference in a new issue