From c435eae17b2d61d72bae1a2b0070d9f360f3f508 Mon Sep 17 00:00:00 2001 From: leo Date: Mon, 14 Apr 2014 03:20:16 +0000 Subject: [PATCH] Added graphics context class. --- common/camera.cpp | 30 +++---- common/camera.h | 2 +- common/lc_context.cpp | 156 ++++++++++++++++++++++++++++++++++ common/lc_context.h | 31 +++++++ common/lc_global.h | 2 + common/lc_glwidget.h | 2 + common/light.cpp | 27 ++++-- common/light.h | 3 +- common/project.cpp | 189 +++++------------------------------------- leocad.pro | 68 +++++++-------- qt/lc_qglwidget.cpp | 2 + qt/lc_qmainwindow.cpp | 1 + 12 files changed, 281 insertions(+), 232 deletions(-) create mode 100644 common/lc_context.cpp create mode 100644 common/lc_context.h diff --git a/common/camera.cpp b/common/camera.cpp index 61a06eee..b1a26be5 100644 --- a/common/camera.cpp +++ b/common/camera.cpp @@ -10,6 +10,8 @@ #include "camera.h" #include "view.h" #include "tr.h" +#include "lc_application.h" +#include "lc_context.h" #define LC_CAMERA_SAVE_VERSION 6 // LeoCAD 0.73 @@ -460,11 +462,13 @@ void Camera::CopyPosition(const Camera* camera) mUpVector = camera->mUpVector; } -void Camera::Render(const lcMatrix44& ViewMatrix, float LineWidth) +void Camera::Render(View* View) { - lcMatrix44 ViewWorld = lcMatrix44AffineInverse(mWorldView); + float LineWidth = lcGetPreferences().mLineWidth; + const lcMatrix44& ViewMatrix = View->mCamera->mWorldView; + lcContext* Context = View->mContext; - // Draw camera. + lcMatrix44 ViewWorld = lcMatrix44AffineInverse(mWorldView); glLoadMatrixf(lcMul(ViewWorld, ViewMatrix)); float verts[34][3] = @@ -490,7 +494,7 @@ void Camera::Render(const lcMatrix44& ViewMatrix, float LineWidth) if (IsEyeSelected()) { - glLineWidth(2.0f); + Context->SetLineWidth(2.0f * LineWidth); if (m_nState & LC_CAMERA_FOCUSED) lcSetColorFocused(); else @@ -498,7 +502,7 @@ void Camera::Render(const lcMatrix44& ViewMatrix, float LineWidth) } else { - glLineWidth(1.0f); + Context->SetLineWidth(LineWidth); lcSetColorCamera(); } @@ -522,24 +526,14 @@ void Camera::Render(const lcMatrix44& ViewMatrix, float LineWidth) { -0.2f, -0.2f, 0.2f }, { -0.2f, -0.2f, -0.2f }, { 0.2f, -0.2f, 0.2f }, { 0.2f, -0.2f, -0.2f } }; -/* - // Draw ortho target. - TargetMat.SetTranslation(mOrthoTarget); - glMultMatrixf(TargetMat); - glLineWidth(1.0f); - glColor4f(1.0f, 0.0f, 0.0f, 1.0f); - - glVertexPointer(3, GL_FLOAT, 0, box); - glDrawArrays(GL_LINES, 0, 24); -*/ // Draw target. TargetMat.SetTranslation(mTargetPosition); glLoadMatrixf(lcMul(TargetMat, ViewMatrix)); if (IsTargetSelected()) { - glLineWidth(2.0f); + Context->SetLineWidth(2.0f * LineWidth); if (m_nState & LC_CAMERA_TARGET_FOCUSED) lcSetColorFocused(); else @@ -547,7 +541,7 @@ void Camera::Render(const lcMatrix44& ViewMatrix, float LineWidth) } else { - glLineWidth(1.0f); + Context->SetLineWidth(LineWidth); lcSetColorCamera(); } @@ -564,7 +558,7 @@ void Camera::Render(const lcMatrix44& ViewMatrix, float LineWidth) glVertexPointer(3, GL_FLOAT, 0, Line); glColor4f(0.5f, 0.8f, 0.5f, 1.0f); - glLineWidth(1.0f); + Context->SetLineWidth(LineWidth); glDrawArrays(GL_LINES, 0, 2); if (IsSelected()) diff --git a/common/camera.h b/common/camera.h index 2ebd4428..42f11c6b 100644 --- a/common/camera.h +++ b/common/camera.h @@ -143,7 +143,7 @@ public: void UpdatePosition(unsigned short nTime); void CopyPosition(const Camera* camera); - void Render(const lcMatrix44& ViewMatrix, float LineWidth); + void Render(View* View); void LoadProjection(const lcProjection& projection); void ZoomExtents(View* view, const lcVector3& Center, const lcVector3* Points, int NumPoints, unsigned short nTime, bool bAddKey); diff --git a/common/lc_context.cpp b/common/lc_context.cpp new file mode 100644 index 00000000..be6df0bc --- /dev/null +++ b/common/lc_context.cpp @@ -0,0 +1,156 @@ +#include "lc_global.h" +#include "lc_context.h" +#include "lc_mesh.h" +#include "lc_texture.h" + +lcContext::lcContext() +{ + mVertexBufferObject = 0; + mIndexBufferObject = 0; + mVertexBufferPointer = NULL; + mIndexBufferPointer = NULL; + mVertexBufferOffset = (char*)~0; + + mTexture = NULL; + mLineWidth = 1.0f; + mMatrixMode = GL_MODELVIEW; +} + +lcContext::~lcContext() +{ +} + +void lcContext::SetWorldViewMatrix(const lcMatrix44& WorldViewMatrix) +{ + if (mMatrixMode != GL_MODELVIEW) + { + glMatrixMode(GL_MODELVIEW); + mMatrixMode = GL_MODELVIEW; + } + + glLoadMatrixf(WorldViewMatrix); +} + +void lcContext::SetProjectionMatrix(const lcMatrix44& ProjectionMatrix) +{ + if (mMatrixMode != GL_PROJECTION) + { + glMatrixMode(GL_PROJECTION); + mMatrixMode = GL_PROJECTION; + } + + glLoadMatrixf(ProjectionMatrix); +} + +void lcContext::SetLineWidth(float LineWidth) +{ + if (LineWidth == mLineWidth) + return; + + glLineWidth(LineWidth); + mLineWidth = LineWidth; +} + +void lcContext::BindMesh(lcMesh* Mesh) +{ + if (GL_HasVertexBufferObject()) + { + GLuint VertexBufferObject = Mesh->mVertexBuffer.mBuffer; + mVertexBufferPointer = NULL; + GLuint IndexBufferObject = Mesh->mIndexBuffer.mBuffer; + mIndexBufferPointer = NULL; + + if (VertexBufferObject != mVertexBufferObject) + { + glBindBuffer(GL_ARRAY_BUFFER_ARB, VertexBufferObject); + mVertexBufferObject = VertexBufferObject; + mVertexBufferOffset = (char*)~0; + } + + if (IndexBufferObject != mIndexBufferObject) + { + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER_ARB, IndexBufferObject); + mIndexBufferObject = IndexBufferObject; + } + } + else + { + mVertexBufferPointer = (char*)Mesh->mVertexBuffer.mData; + mIndexBufferPointer = (char*)Mesh->mIndexBuffer.mData; + mVertexBufferOffset = (char*)~0; + } +} + +void lcContext::UnbindMesh() +{ + if (mTexture) + { + glDisableClientState(GL_TEXTURE_COORD_ARRAY); + glDisable(GL_TEXTURE_2D); + mTexture = NULL; + } + + if (GL_HasVertexBufferObject()) + { + glBindBuffer(GL_ARRAY_BUFFER_ARB, 0); + mVertexBufferObject = 0; + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER_ARB, 0); + mIndexBufferObject = 0; + } + + mVertexBufferPointer = NULL; + mIndexBufferPointer = NULL; + + glVertexPointer(3, GL_FLOAT, 0, NULL); + glTexCoordPointer(2, GL_FLOAT, 0, NULL); +} + +void lcContext::DrawMeshSection(lcMesh* Mesh, lcMeshSection* Section) +{ + char* BufferOffset = mVertexBufferPointer; + lcTexture* Texture = Section->Texture; + + if (!Texture) + { + if (mTexture) + { + glDisableClientState(GL_TEXTURE_COORD_ARRAY); + glDisable(GL_TEXTURE_2D); + + mTexture = NULL; + } + } + else + { + BufferOffset += Mesh->mNumVertices * sizeof(lcVertex); + + if (Texture != mTexture) + { + glBindTexture(GL_TEXTURE_2D, Texture->mTexture); + + if (!mTexture) + { + glEnableClientState(GL_TEXTURE_COORD_ARRAY); + glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); + glEnable(GL_TEXTURE_2D); + } + + mTexture = Texture; + } + } + + if (mVertexBufferOffset != BufferOffset) + { + if (!Texture) + glVertexPointer(3, GL_FLOAT, 0, BufferOffset); + else + { + glVertexPointer(3, GL_FLOAT, sizeof(lcVertexTextured), BufferOffset); + glTexCoordPointer(2, GL_FLOAT, sizeof(lcVertexTextured), BufferOffset + sizeof(lcVector3)); + } + + mVertexBufferOffset = BufferOffset; + } + + glDrawElements(Section->PrimitiveType, Section->NumIndices, Mesh->mIndexType, mIndexBufferPointer + Section->IndexOffset); +} diff --git a/common/lc_context.h b/common/lc_context.h new file mode 100644 index 00000000..295ccedc --- /dev/null +++ b/common/lc_context.h @@ -0,0 +1,31 @@ +#ifndef _LC_CONTEXT_H_ +#define _LC_CONTEXT_H_ + +class lcContext +{ +public: + lcContext(); + ~lcContext(); + + void SetWorldViewMatrix(const lcMatrix44& WorldViewMatrix); + void SetProjectionMatrix(const lcMatrix44& ProjectionMatrix); +// void SetColor(const lcVector4& Color); + void SetLineWidth(float LineWidth); + + void BindMesh(lcMesh* Mesh); + void UnbindMesh(); + void DrawMeshSection(lcMesh* Mesh, lcMeshSection* Section); + +protected: + GLuint mVertexBufferObject; + GLuint mIndexBufferObject; + char* mVertexBufferPointer; + char* mIndexBufferPointer; + char* mVertexBufferOffset; + + lcTexture* mTexture; + float mLineWidth; + int mMatrixMode; +}; + +#endif // _LC_CONTEXT_H_ diff --git a/common/lc_global.h b/common/lc_global.h index a9494084..8a1b0904 100644 --- a/common/lc_global.h +++ b/common/lc_global.h @@ -15,7 +15,9 @@ class lcVector3; class lcVector4; class lcMatrix44; +class lcContext; class lcMesh; +struct lcMeshSection; class lcTexture; class lcFile; diff --git a/common/lc_glwidget.h b/common/lc_glwidget.h index e2ab398a..83fa3e35 100644 --- a/common/lc_glwidget.h +++ b/common/lc_glwidget.h @@ -45,6 +45,7 @@ public: mInputState.Control = false; mInputState.Shift = false; mInputState.Alt = false; + mContext = NULL; } virtual ~lcGLWidget() @@ -78,6 +79,7 @@ public: int mHeight; int mCursorType; void* mWidget; + lcContext* mContext; }; #endif // _LC_GLWIDGET_H_ diff --git a/common/light.cpp b/common/light.cpp index 8149c932..108fd4ce 100644 --- a/common/light.cpp +++ b/common/light.cpp @@ -6,6 +6,10 @@ #include #include #include "light.h" +#include "camera.h" +#include "view.h" +#include "lc_application.h" +#include "lc_context.h" static LC_OBJECT_KEY_INFO light_key_info[LC_LK_COUNT] = { @@ -292,44 +296,49 @@ void Light::UpdatePosition(unsigned short nTime) } } -void Light::Render(const lcMatrix44& ViewMatrix, float LineWidth) +void Light::Render(View* View) { + float LineWidth = lcGetPreferences().mLineWidth; + const lcMatrix44& ViewMatrix = View->mCamera->mWorldView; + lcContext* Context = View->mContext; + if (m_pTarget != NULL) { if (IsEyeSelected()) { - glLineWidth(LineWidth*2); + Context->SetLineWidth(2.0f * LineWidth); if (m_nState & LC_LIGHT_FOCUSED) lcSetColorFocused(); else lcSetColorSelected(); - RenderCone(ViewMatrix); - glLineWidth(LineWidth); } else { + Context->SetLineWidth(LineWidth); lcSetColorLight(); - RenderCone(ViewMatrix); } + RenderCone(ViewMatrix); + if (IsTargetSelected()) { - glLineWidth(LineWidth*2); + Context->SetLineWidth(2.0f * LineWidth); if (m_nState & LC_LIGHT_TARGET_FOCUSED) lcSetColorFocused(); else lcSetColorSelected(); - RenderTarget(); - glLineWidth(LineWidth); } else { + Context->SetLineWidth(LineWidth); lcSetColorLight(); - RenderTarget(); } + RenderTarget(); + glLoadMatrixf(ViewMatrix); + Context->SetLineWidth(LineWidth); lcSetColorLight(); lcVector3 Line[2] = { mPosition, mTargetPosition }; diff --git a/common/light.h b/common/light.h index fbacd8a8..d7a6973e 100644 --- a/common/light.h +++ b/common/light.h @@ -13,6 +13,7 @@ class Light; class LightTarget; +class View; enum LC_LK_TYPES { @@ -96,7 +97,7 @@ public: const char* GetName() const { return m_strName; } - void Render(const lcMatrix44& ViewMatrix, float LineWidth); + void Render(View* View); void RenderCone(const lcMatrix44& ViewMatrix); void RenderTarget(); void RenderSphere(); diff --git a/common/project.cpp b/common/project.cpp index c1ca8e38..5179124d 100644 --- a/common/project.cpp +++ b/common/project.cpp @@ -26,6 +26,8 @@ #include "debug.h" #include "lc_application.h" #include "lc_profile.h" +#include "lc_context.h" +#include "preview.h" void lcModelProperties::LoadDefaults() { @@ -1731,53 +1733,16 @@ void Project::RenderScenePieces(View* view) } } - lcMesh* PreviousMesh = NULL; - bool PreviousSelected = false; - lcTexture* PreviousTexture = NULL; - char* ElementsOffset = NULL; - char* BaseBufferOffset = NULL; - char* PreviousOffset = (char*)(~0); + lcContext* Context = view->mContext; for (int PieceIdx = 0; PieceIdx < OpaquePieces.GetSize(); PieceIdx++) { Piece* piece = OpaquePieces[PieceIdx]; lcMesh* Mesh = piece->mPieceInfo->mMesh; - glLoadMatrixf(lcMul(piece->mModelWorld, ViewMatrix)); - - if (PreviousMesh != Mesh) - { - if (GL_HasVertexBufferObject()) - { - glBindBuffer(GL_ARRAY_BUFFER_ARB, Mesh->mVertexBuffer.mBuffer); - BaseBufferOffset = NULL; - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER_ARB, Mesh->mIndexBuffer.mBuffer); - ElementsOffset = NULL; - } - else - { - BaseBufferOffset = (char*)Mesh->mVertexBuffer.mData; - ElementsOffset = (char*)Mesh->mIndexBuffer.mData; - } - - PreviousMesh = Mesh; - PreviousOffset = (char*)(~0); - } - - if (piece->IsSelected()) - { - if (!PreviousSelected) - glLineWidth(2.0f * Preferences.mLineWidth); - - PreviousSelected = true; - } - else - { - if (PreviousSelected) - glLineWidth(Preferences.mLineWidth); - - PreviousSelected = false; - } + Context->BindMesh(Mesh); + Context->SetWorldViewMatrix(lcMul(piece->mModelWorld, ViewMatrix)); + Context->SetLineWidth(piece->IsSelected() ? 2.0f * Preferences.mLineWidth : Preferences.mLineWidth); for (int SectionIdx = 0; SectionIdx < Mesh->mNumSections; SectionIdx++) { @@ -1806,56 +1771,10 @@ void Project::RenderScenePieces(View* view) lcSetColor(ColorIdx); } - char* BufferOffset = BaseBufferOffset; - lcTexture* Texture = Section->Texture; - - if (!Texture) - { - if (PreviousTexture) - { - glDisableClientState(GL_TEXTURE_COORD_ARRAY); - glDisable(GL_TEXTURE_2D); - } - } - else - { - BufferOffset += Mesh->mNumVertices * sizeof(lcVertex); - - if (Texture != PreviousTexture) - { - glBindTexture(GL_TEXTURE_2D, Section->Texture->mTexture); - - if (!PreviousTexture) - { - glEnableClientState(GL_TEXTURE_COORD_ARRAY); - glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); - glEnable(GL_TEXTURE_2D); - } - } - } - - PreviousTexture = Texture; - - if (PreviousOffset != BufferOffset) - { - if (!Texture) - glVertexPointer(3, GL_FLOAT, 0, BufferOffset); - else - { - glVertexPointer(3, GL_FLOAT, sizeof(lcVertexTextured), BufferOffset); - glTexCoordPointer(2, GL_FLOAT, sizeof(lcVertexTextured), BufferOffset + sizeof(lcVector3)); - } - - PreviousOffset = BufferOffset; - } - - glDrawElements(Section->PrimitiveType, Section->NumIndices, Mesh->mIndexType, ElementsOffset + Section->IndexOffset); + Context->DrawMeshSection(Mesh, Section); } } - if (PreviousSelected) - glLineWidth(Preferences.mLineWidth); - if (TranslucentSections.GetSize()) { glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); @@ -1867,26 +1786,8 @@ void Project::RenderScenePieces(View* view) Piece* piece = TranslucentSections[PieceIdx].piece; lcMesh* Mesh = piece->mPieceInfo->mMesh; - glLoadMatrixf(lcMul(piece->mModelWorld, ViewMatrix)); - - if (PreviousMesh != Mesh) - { - if (GL_HasVertexBufferObject()) - { - glBindBuffer(GL_ARRAY_BUFFER_ARB, Mesh->mVertexBuffer.mBuffer); - BaseBufferOffset = NULL; - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER_ARB, Mesh->mIndexBuffer.mBuffer); - ElementsOffset = NULL; - } - else - { - BaseBufferOffset = (char*)Mesh->mVertexBuffer.mData; - ElementsOffset = (char*)Mesh->mIndexBuffer.mData; - } - - PreviousMesh = Mesh; - PreviousOffset = (char*)(~0); - } + Context->BindMesh(Mesh); + Context->SetWorldViewMatrix(lcMul(piece->mModelWorld, ViewMatrix)); for (int SectionIdx = 0; SectionIdx < Mesh->mNumSections; SectionIdx++) { @@ -1904,50 +1805,7 @@ void Project::RenderScenePieces(View* view) lcSetColor(ColorIdx); - char* BufferOffset = BaseBufferOffset; - lcTexture* Texture = Section->Texture; - - if (!Texture) - { - if (PreviousTexture) - { - glDisableClientState(GL_TEXTURE_COORD_ARRAY); - glDisable(GL_TEXTURE_2D); - } - } - else - { - BufferOffset += Mesh->mNumVertices * sizeof(lcVertex); - - if (Texture != PreviousTexture) - { - glBindTexture(GL_TEXTURE_2D, Section->Texture->mTexture); - - if (!PreviousTexture) - { - glEnableClientState(GL_TEXTURE_COORD_ARRAY); - glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); - glEnable(GL_TEXTURE_2D); - } - } - } - - PreviousTexture = Texture; - - if (PreviousOffset != BufferOffset) - { - if (!Texture) - glVertexPointer(3, GL_FLOAT, 0, BufferOffset); - else - { - glVertexPointer(3, GL_FLOAT, sizeof(lcVertexTextured), BufferOffset); - glTexCoordPointer(2, GL_FLOAT, sizeof(lcVertexTextured), BufferOffset + sizeof(lcVector3)); - } - - PreviousOffset = BufferOffset; - } - - glDrawElements(Section->PrimitiveType, Section->NumIndices, Mesh->mIndexType, ElementsOffset + Section->IndexOffset); + Context->DrawMeshSection(Mesh, Section); } } @@ -1965,26 +1823,15 @@ void Project::RenderScenePieces(View* view) if (mProperties.mFogEnabled) glDisable(GL_FOG); - if (PreviousTexture) - { - glDisableClientState(GL_TEXTURE_COORD_ARRAY); - glDisable(GL_TEXTURE_2D); - } - - if (GL_HasVertexBufferObject()) - { - glBindBuffer(GL_ARRAY_BUFFER_ARB, 0); - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER_ARB, 0); - } - - glVertexPointer(3, GL_FLOAT, 0, NULL); - glTexCoordPointer(2, GL_FLOAT, 0, NULL); + Context->SetLineWidth(Preferences.mLineWidth); // context remove + Context->UnbindMesh(); // context remove } void Project::RenderSceneObjects(View* view) { const lcPreferences& Preferences = lcGetPreferences(); const lcMatrix44& ViewMatrix = view->mCamera->mWorldView; + lcContext* Context = view->mContext; #ifdef LC_DEBUG RenderDebugPrimitives(); @@ -2003,9 +1850,8 @@ void Project::RenderSceneObjects(View* view) glLoadMatrixf(lcMul(WorldMatrix, ViewMatrix)); - glLineWidth(2 * Preferences.mLineWidth); + Context->SetLineWidth(2.0f * Preferences.mLineWidth); PreviewPiece->RenderPiece(gMainWindow->mColorIndex); - glLineWidth(Preferences.mLineWidth); } if (Preferences.mLightingMode != LC_LIGHTING_FLAT) @@ -2018,12 +1864,14 @@ void Project::RenderSceneObjects(View* view) if ((pCamera == view->mCamera) || !pCamera->IsVisible()) continue; - pCamera->Render(ViewMatrix, Preferences.mLineWidth); + pCamera->Render(view); } for (int LightIdx = 0; LightIdx < mLights.GetSize(); LightIdx++) if (mLights[LightIdx]->IsVisible()) - mLights[LightIdx]->Render(ViewMatrix, Preferences.mLineWidth); + mLights[LightIdx]->Render(view); + + Context->SetLineWidth(Preferences.mLineWidth); // context remove if (Preferences.mDrawGridStuds || Preferences.mDrawGridLines) { @@ -3492,6 +3340,7 @@ void Project::CreateImages(Image* images, int width, int height, unsigned short view.SetCamera(m_ActiveView->mCamera, false); view.mWidth = width; view.mHeight = height; + view.mContext = gMainWindow->mPreviewWidget->mContext; if (!hilite) SelectAndFocusNone(false); diff --git a/leocad.pro b/leocad.pro index 621618e5..a74b5d0a 100644 --- a/leocad.pro +++ b/leocad.pro @@ -18,8 +18,8 @@ win32 { RC_FILE = qt/leocad.rc LIBS += -ladvapi32 -lshell32 } else { - LIBS += -lz - QMAKE_CXXFLAGS_WARN_ON += -Wno-unused-parameter + LIBS += -lz + QMAKE_CXXFLAGS_WARN_ON += -Wno-unused-parameter } unix:!macx { @@ -93,20 +93,24 @@ SOURCES += common/view.cpp \ common/object.cpp \ common/minifig.cpp \ common/light.cpp \ - common/lc_zipfile.cpp \ - common/lc_texture.cpp \ - common/lc_mesh.cpp \ - common/lc_library.cpp \ - common/lc_file.cpp \ - common/lc_colors.cpp \ common/lc_application.cpp \ + common/lc_category.cpp \ + common/lc_colors.cpp \ + common/lc_commands.cpp \ + common/lc_context.cpp \ + common/lc_file.cpp \ + common/lc_library.cpp \ + common/lc_mainwindow.cpp \ + common/lc_mesh.cpp \ + common/lc_profile.cpp \ + common/lc_projection.cpp \ + common/lc_shortcuts.cpp \ + common/lc_texture.cpp \ + common/lc_zipfile.cpp \ common/image.cpp \ common/group.cpp \ common/debug.cpp \ common/camera.cpp \ - common/lc_profile.cpp \ - common/lc_category.cpp \ - common/lc_projection.cpp \ qt/lc_qmainwindow.cpp \ qt/system.cpp \ qt/qtmain.cpp \ @@ -129,13 +133,10 @@ SOURCES += common/view.cpp \ qt/lc_qutils.cpp \ qt/lc_qpropertiestree.cpp \ qt/lc_qcolorpicker.cpp \ - common/lc_commands.cpp \ - common/lc_shortcuts.cpp \ qt/lc_qimage.cpp \ qt/lc_qglwidget.cpp \ qt/lc_qcolorlist.cpp \ - qt/lc_qfinddialog.cpp \ - common/lc_mainwindow.cpp + qt/lc_qfinddialog.cpp HEADERS += \ common/view.h \ common/tr.h \ @@ -151,22 +152,29 @@ HEADERS += \ common/object.h \ common/minifig.h \ common/light.h \ - common/lc_zipfile.h \ - common/lc_texture.h \ - common/lc_mesh.h \ - common/lc_math.h \ - common/lc_library.h \ - common/lc_global.h \ - common/lc_file.h \ - common/lc_colors.h \ common/lc_application.h \ + common/lc_array.h \ + common/lc_basewindow.h \ + common/lc_category.h \ + common/lc_colors.h \ + common/lc_commands.h \ + common/lc_context.h \ + common/lc_file.h \ + common/lc_global.h \ + common/lc_glwidget.h \ + common/lc_library.h \ + common/lc_mainwindow.h \ + common/lc_math.h \ + common/lc_mesh.h \ + common/lc_profile.h \ + common/lc_projection.h \ + common/lc_shortcuts.h \ + common/lc_texture.h \ + common/lc_zipfile.h \ common/image.h \ common/group.h \ common/debug.h \ common/camera.h \ - common/lc_profile.h \ - common/lc_category.h \ - common/lc_projection.h \ qt/lc_qmainwindow.h \ qt/lc_config.h \ qt/lc_qpovraydialog.h \ @@ -186,15 +194,9 @@ HEADERS += \ qt/lc_qutils.h \ qt/lc_qpropertiestree.h \ qt/lc_qcolorpicker.h \ - common/lc_commands.h \ - common/lc_shortcuts.h \ qt/lc_qglwidget.h \ qt/lc_qcolorlist.h \ - common/lc_glwidget.h \ - qt/lc_qfinddialog.h \ - common/lc_array.h \ - common/lc_basewindow.h \ - common/lc_mainwindow.h + qt/lc_qfinddialog.h FORMS += \ qt/lc_qpovraydialog.ui \ qt/lc_qarraydialog.ui \ diff --git a/qt/lc_qglwidget.cpp b/qt/lc_qglwidget.cpp index d94268c8..fae9ffd2 100644 --- a/qt/lc_qglwidget.cpp +++ b/qt/lc_qglwidget.cpp @@ -6,6 +6,7 @@ #include "lc_application.h" #include "lc_qmainwindow.h" #include "lc_mainwindow.h" +#include "lc_context.h" void lcGLWidget::MakeCurrent() { @@ -128,6 +129,7 @@ lcQGLWidget::lcQGLWidget(QWidget *parent, lcQGLWidget *share, lcGLWidget *owner, { widget = owner; widget->mWidget = this; + owner->mContext = new lcContext(); widget->MakeCurrent(); GL_InitializeSharedExtensions(widget); diff --git a/qt/lc_qmainwindow.cpp b/qt/lc_qmainwindow.cpp index fdd74168..7b6483da 100644 --- a/qt/lc_qmainwindow.cpp +++ b/qt/lc_qmainwindow.cpp @@ -808,6 +808,7 @@ void lcQMainWindow::print(QPrinter *printer) view.SetCamera(project->GetActiveView()->mCamera, false); view.mWidth = tileWidth; view.mHeight = tileHeight; + view.mContext = piecePreview->widget->mContext; GL_BeginRenderToTexture(tileWidth, tileHeight); glPixelStorei(GL_PACK_ALIGNMENT, 1);