Compare commits
75 Commits
80e5f76ee4
...
3d53c8a69f
| Author | SHA1 | Date | |
|---|---|---|---|
| 3d53c8a69f | |||
| d269f30107 | |||
| 5a7158531f | |||
| 7dfaf924e5 | |||
| c642ec603f | |||
| 553e24b896 | |||
| 9d119f5c97 | |||
| 5de0f6234d | |||
| 2156e1d3e9 | |||
| 0baee2f54c | |||
| d2d0a3fb62 | |||
| 1ed6f12498 | |||
| 56a50715e2 | |||
| 849063e846 | |||
| ef764d947d | |||
| c3bb81f72d | |||
| 9c78ba5281 | |||
| dfc4c718e8 | |||
| 85bc739987 | |||
| fcc1e98a6e | |||
| 893910c431 | |||
| 292f68a574 | |||
| 484a7f972f | |||
| c275d006d5 | |||
| 011c3eeb71 | |||
| 0151e34477 | |||
| c179bc95cf | |||
| bddb288586 | |||
| 9e7afb5fb5 | |||
| 34976b8865 | |||
|
3ee778cb92
|
|||
| 64eee9e607 | |||
| adf8c4d7f0 | |||
| 0fab015e25 | |||
| 51562dec9d | |||
| 52e9b19f37 | |||
| 7455a7341c | |||
| 91bc31e7db | |||
| eb5f50fc9d | |||
| 3c9386de63 | |||
| 69caa98d04 | |||
| 12695983d2 | |||
| 36540468dc | |||
| c8dcd5e9c0 | |||
| e3389bcc20 | |||
| 728c4a85ed | |||
| 6ddb3488e5 | |||
| 175cbe7064 | |||
| 50c5e5ae18 | |||
| c3f91d78f0 | |||
| 3cf466e5d3 | |||
| 65dd078f07 | |||
| 3ed7976257 | |||
| 4a1d58ef4c | |||
| 4e62165c80 | |||
|
9cc870c996
|
|||
|
a2695ae481
|
|||
|
2b0a5f82b5
|
|||
| 98ccefd057 | |||
| 71d391c91b | |||
| 4e02e154c6 | |||
| 7c6ca07323 | |||
| 7d30802cbd | |||
| b20068165f | |||
| cb944b62e4 | |||
| 1dfca0aeab | |||
| 953cece292 | |||
|
|
0f993e6c1c | ||
|
|
1afa4ea368 | ||
|
|
6150882794 | ||
| ce3df7d051 | |||
|
|
3b0d1ea0e2 | ||
| c865f9fc94 | |||
| f6f0dd151c | |||
| 52056a44bb |
224
.clang-format
Normal file
@@ -0,0 +1,224 @@
|
||||
---
|
||||
Language: Cpp
|
||||
AccessModifierOffset: -4
|
||||
AlignAfterOpenBracket: Align
|
||||
AlignArrayOfStructures: Left
|
||||
AlignConsecutiveAssignments:
|
||||
Enabled: true
|
||||
AcrossEmptyLines: true
|
||||
AcrossComments: true
|
||||
AlignCompound: false
|
||||
PadOperators: true
|
||||
AlignConsecutiveBitFields:
|
||||
Enabled: true
|
||||
AcrossEmptyLines: false
|
||||
AcrossComments: true
|
||||
AlignCompound: false
|
||||
PadOperators: true
|
||||
AlignConsecutiveDeclarations:
|
||||
Enabled: false
|
||||
AcrossEmptyLines: false
|
||||
AcrossComments: false
|
||||
AlignCompound: false
|
||||
PadOperators: false
|
||||
AlignConsecutiveMacros:
|
||||
Enabled: true
|
||||
AcrossEmptyLines: true
|
||||
AcrossComments: true
|
||||
AlignCompound: false
|
||||
PadOperators: true
|
||||
AlignEscapedNewlines: Left
|
||||
AlignOperands: Align
|
||||
AlignTrailingComments: true
|
||||
AllowAllArgumentsOnNextLine: false
|
||||
AllowAllParametersOfDeclarationOnNextLine: false
|
||||
AllowShortEnumsOnASingleLine: false
|
||||
AllowShortBlocksOnASingleLine: Empty
|
||||
AllowShortCaseLabelsOnASingleLine: true
|
||||
AllowShortFunctionsOnASingleLine: Inline
|
||||
AllowShortLambdasOnASingleLine: All
|
||||
AllowShortIfStatementsOnASingleLine: WithoutElse
|
||||
AllowShortLoopsOnASingleLine: false
|
||||
AlwaysBreakAfterDefinitionReturnType: None
|
||||
AlwaysBreakAfterReturnType: None
|
||||
AlwaysBreakBeforeMultilineStrings: false
|
||||
AlwaysBreakTemplateDeclarations: Yes
|
||||
AttributeMacros:
|
||||
- __capability
|
||||
BinPackArguments: false
|
||||
BinPackParameters: false
|
||||
BraceWrapping:
|
||||
AfterCaseLabel: false
|
||||
AfterClass: false
|
||||
AfterControlStatement: Never
|
||||
AfterEnum: false
|
||||
AfterFunction: false
|
||||
AfterNamespace: false
|
||||
AfterObjCDeclaration: false
|
||||
AfterStruct: false
|
||||
AfterUnion: false
|
||||
AfterExternBlock: false
|
||||
BeforeCatch: false
|
||||
BeforeElse: false
|
||||
BeforeLambdaBody: false
|
||||
BeforeWhile: false
|
||||
IndentBraces: false
|
||||
SplitEmptyFunction: false
|
||||
SplitEmptyRecord: false
|
||||
SplitEmptyNamespace: true
|
||||
BreakBeforeBinaryOperators: None
|
||||
BreakBeforeConceptDeclarations: Always
|
||||
BreakBeforeBraces: Attach
|
||||
BreakInheritanceList: BeforeComma
|
||||
BreakBeforeTernaryOperators: true
|
||||
BreakConstructorInitializers: BeforeComma
|
||||
BreakAfterJavaFieldAnnotations: false
|
||||
BreakStringLiterals: true
|
||||
ColumnLimit: 140
|
||||
CommentPragmas: '^ IWYU pragma:'
|
||||
QualifierAlignment: Leave
|
||||
CompactNamespaces: false
|
||||
ConstructorInitializerIndentWidth: 4
|
||||
ContinuationIndentWidth: 4
|
||||
Cpp11BracedListStyle: true
|
||||
DeriveLineEnding: false
|
||||
DerivePointerAlignment: false
|
||||
DisableFormat: false
|
||||
EmptyLineAfterAccessModifier: Never
|
||||
EmptyLineBeforeAccessModifier: Always
|
||||
ExperimentalAutoDetectBinPacking: false
|
||||
PackConstructorInitializers: CurrentLine
|
||||
BasedOnStyle: ''
|
||||
ConstructorInitializerAllOnOneLineOrOnePerLine: true
|
||||
AllowAllConstructorInitializersOnNextLine: true
|
||||
FixNamespaceComments: true
|
||||
ForEachMacros:
|
||||
- foreach
|
||||
- Q_FOREACH
|
||||
- BOOST_FOREACH
|
||||
- piForeach
|
||||
- piForeachC
|
||||
- piForeachR
|
||||
- piForeachRC
|
||||
- piForeachCR
|
||||
IfMacros:
|
||||
- KJ_IF_MAYBE
|
||||
IncludeBlocks: Regroup
|
||||
IncludeCategories:
|
||||
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
|
||||
Priority: 2
|
||||
SortPriority: 0
|
||||
CaseSensitive: false
|
||||
- Regex: '^(<|"(gtest|gmock|isl|json)/)'
|
||||
Priority: 3
|
||||
SortPriority: 0
|
||||
CaseSensitive: false
|
||||
- Regex: '.*'
|
||||
Priority: 1
|
||||
SortPriority: 0
|
||||
CaseSensitive: false
|
||||
IncludeIsMainRegex: '(Test)?$'
|
||||
IncludeIsMainSourceRegex: ''
|
||||
IndentAccessModifiers: false
|
||||
IndentCaseLabels: false
|
||||
IndentCaseBlocks: false
|
||||
IndentGotoLabels: false
|
||||
IndentPPDirectives: AfterHash
|
||||
IndentExternBlock: NoIndent
|
||||
IndentRequiresClause: true
|
||||
IndentWidth: 4
|
||||
IndentWrappedFunctionNames: false
|
||||
InsertBraces: false
|
||||
InsertTrailingCommas: Wrapped
|
||||
JavaScriptQuotes: Leave
|
||||
JavaScriptWrapImports: true
|
||||
KeepEmptyLinesAtTheStartOfBlocks: false
|
||||
LambdaBodyIndentation: Signature
|
||||
MacroBlockBegin: "PRIVATE_DEFINITION_START|STATIC_INITIALIZER_BEGIN"
|
||||
MacroBlockEnd: "PRIVATE_DEFINITION_END|PRIVATE_DEFINITION_END_NO_INITIALIZE|STATIC_INITIALIZER_END"
|
||||
MaxEmptyLinesToKeep: 2
|
||||
NamespaceIndentation: None
|
||||
ObjCBinPackProtocolList: Auto
|
||||
ObjCBlockIndentWidth: 2
|
||||
ObjCBreakBeforeNestedBlockParam: true
|
||||
ObjCSpaceAfterProperty: false
|
||||
ObjCSpaceBeforeProtocolList: true
|
||||
PenaltyBreakAssignment: 2
|
||||
PenaltyBreakBeforeFirstCallParameter: 19
|
||||
PenaltyBreakComment: 300
|
||||
PenaltyBreakFirstLessLess: 120
|
||||
PenaltyBreakOpenParenthesis: 0
|
||||
PenaltyBreakString: 1000
|
||||
PenaltyBreakTemplateDeclaration: 10
|
||||
PenaltyExcessCharacter: 1000000
|
||||
PenaltyReturnTypeOnItsOwnLine: 60
|
||||
PenaltyIndentedWhitespace: 0
|
||||
PointerAlignment: Middle
|
||||
PPIndentWidth: 2
|
||||
ReferenceAlignment: Middle
|
||||
ReflowComments: true
|
||||
RemoveBracesLLVM: false
|
||||
RequiresClausePosition: OwnLine
|
||||
SeparateDefinitionBlocks: Leave
|
||||
ShortNamespaceLines: 1
|
||||
SortIncludes: CaseSensitive
|
||||
SortJavaStaticImport: Before
|
||||
SortUsingDeclarations: true
|
||||
SpaceAfterCStyleCast: false
|
||||
SpaceAfterLogicalNot: false
|
||||
SpaceAfterTemplateKeyword: false
|
||||
SpaceBeforeAssignmentOperators: true
|
||||
SpaceBeforeCaseColon: false
|
||||
SpaceBeforeCpp11BracedList: false
|
||||
SpaceBeforeCtorInitializerColon: false
|
||||
SpaceBeforeInheritanceColon: false
|
||||
SpaceBeforeParens: ControlStatementsExceptControlMacros
|
||||
SpaceBeforeParensOptions:
|
||||
AfterControlStatements: true
|
||||
AfterForeachMacros: false
|
||||
AfterFunctionDefinitionName: false
|
||||
AfterFunctionDeclarationName: false
|
||||
AfterIfMacros: false
|
||||
AfterOverloadedOperator: false
|
||||
AfterRequiresInClause: false
|
||||
AfterRequiresInExpression: false
|
||||
BeforeNonEmptyParentheses: false
|
||||
SpaceAroundPointerQualifiers: Both
|
||||
SpaceBeforeRangeBasedForLoopColon: false
|
||||
SpaceInEmptyBlock: false
|
||||
SpaceInEmptyParentheses: false
|
||||
SpacesBeforeTrailingComments: 1
|
||||
SpacesInAngles: Never
|
||||
SpacesInConditionalStatement: false
|
||||
SpacesInContainerLiterals: false
|
||||
SpacesInCStyleCastParentheses: false
|
||||
SpacesInLineCommentPrefix:
|
||||
Minimum: 1
|
||||
Maximum: -1
|
||||
SpacesInParentheses: false
|
||||
SpacesInSquareBrackets: false
|
||||
SpaceBeforeSquareBrackets: false
|
||||
BitFieldColonSpacing: After
|
||||
Standard: c++11
|
||||
StatementAttributeLikeMacros:
|
||||
- Q_EMIT
|
||||
- PIMETA
|
||||
StatementMacros:
|
||||
- Q_UNUSED
|
||||
- QT_REQUIRE_VERSION
|
||||
- PRIVATE_DECLARATION
|
||||
- NO_COPY_CLASS
|
||||
- FOREVER_WAIT
|
||||
- WAIT_FOREVER
|
||||
TabWidth: 4
|
||||
UseCRLF: false
|
||||
UseTab: AlignWithSpaces
|
||||
WhitespaceSensitiveMacros:
|
||||
- STRINGIZE
|
||||
- PP_STRINGIZE
|
||||
- BOOST_PP_STRINGIZE
|
||||
- NS_SWIFT_NAME
|
||||
- CF_SWIFT_NAME
|
||||
- PIMETA
|
||||
...
|
||||
|
||||
6
.editorconfig
Normal file
@@ -0,0 +1,6 @@
|
||||
root = true
|
||||
|
||||
[*.{h,c,cpp}]
|
||||
charset = utf-8
|
||||
indent_style = tab
|
||||
tab_width = 4
|
||||
@@ -1,4 +1,4 @@
|
||||
cmake_minimum_required(VERSION 3.0)
|
||||
cmake_minimum_required(VERSION 3.13)
|
||||
cmake_policy(SET CMP0072 NEW) # FindOpenGL prefers GLVND by default
|
||||
if (POLICY CMP0057)
|
||||
cmake_policy(SET CMP0057 NEW)
|
||||
@@ -6,7 +6,11 @@ endif()
|
||||
if (POLICY CMP0054)
|
||||
cmake_policy(SET CMP0054 NEW)
|
||||
endif()
|
||||
project(qglengine)
|
||||
project(QGLEngine)
|
||||
if (NOT DEFINED SHSTKPROJECT)
|
||||
include(SHSTKQtMacros)
|
||||
endif()
|
||||
find_package(PIP REQUIRED)
|
||||
find_package(QAD REQUIRED)
|
||||
shstk_qt_founded(QtVersions)
|
||||
set(_qgl_ok 0)
|
||||
@@ -19,61 +23,26 @@ endif()
|
||||
if (NOT _qgl_ok)
|
||||
message(WARNING "Building ${PROJECT_NAME} available only on Qt5/6!")
|
||||
else()
|
||||
qad_find_qt(Core Gui OpenGL OpenGLWidgets Xml)
|
||||
find_package(OpenGL REQUIRED)
|
||||
include(SHSTKQtMacros)
|
||||
|
||||
set(qglengine_MAJOR 1)
|
||||
set(qglengine_MINOR 0)
|
||||
set(qglengine_REVISION 0)
|
||||
set(qglengine_SUFFIX "rc")
|
||||
set(qglengine_COMPANY SHS)
|
||||
set(qglengine_DOMAIN org.SHS)
|
||||
set(QGLEngine_MAJOR 1)
|
||||
set(QGLEngine_MINOR 4)
|
||||
set(QGLEngine_REVISION 0)
|
||||
set(QGLEngine_SUFFIX "rc")
|
||||
set(QGLEngine_COMPANY SHS)
|
||||
set(QGLEngine_DOMAIN org.SHS)
|
||||
|
||||
if ("x${CMAKE_MODULE_PATH}" STREQUAL "x")
|
||||
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
|
||||
endif()
|
||||
|
||||
shstk_begin_project(qglengine QGLENGINE)
|
||||
shstk_begin_project(QGLEngine)
|
||||
set(_qglengine_root_build "${CMAKE_CURRENT_BINARY_DIR}")
|
||||
|
||||
qad_sources(SRC)
|
||||
qad_sources(FSRC DIR "formats")
|
||||
list(APPEND SRC ${FSRC})
|
||||
qad_sources(FSRC DIR "core")
|
||||
list(APPEND SRC ${FSRC})
|
||||
qad_wrap(${SRC} HDRS out_HDR CPPS out_CPP QMS out_QM)
|
||||
file(GLOB PHS "*_p.h" "formats/*_p.h" "core/*_p.h")
|
||||
list(REMOVE_ITEM out_HDR "${PHS}")
|
||||
import_version(qglengine_core qglengine)
|
||||
set_deploy_property(qglengine_core ${qglengine_LIB_TYPE}
|
||||
LABEL "QGLEngine core library"
|
||||
FULLNAME "${qglengine_DOMAIN}.qglengine_core"
|
||||
COMPANY "${qglengine_COMPANY}"
|
||||
INFO "QGLEngine core library")
|
||||
make_rc(qglengine_core _RC)
|
||||
qad_add_library(qglengine_core ${qglengine_LIB_TYPE} out_CPP ${_RC})
|
||||
qad_generate_export_header(qglengine_core)
|
||||
list(APPEND out_HDR "${CMAKE_CURRENT_BINARY_DIR}/qglengine_core_export.h")
|
||||
list(APPEND out_HDR "${qglengine_VERSION_FILE}")
|
||||
qad_target_include_directories(qglengine_core PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}/core")
|
||||
qad_target_link_libraries(qglengine_core QAD::Widgets assimp ${OPENGL_LIBRARIES})
|
||||
message(STATUS "Building QGLEngine version ${qglengine_VERSION} (${qglengine_LIB_TYPE_MSG}) for ${QtVersions}")
|
||||
list(APPEND QT_MULTILIB_LIST qglengine_core)
|
||||
add_subdirectory(widgets)
|
||||
add_subdirectory(src)
|
||||
shstk_copy_to_parent()
|
||||
shstk_qad_install("qglengine" FALSE "qglengine_core" "${out_HDR}" "out_QM")
|
||||
if (NOT DEFINED ANDROID_PLATFORM)
|
||||
if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/plugin")
|
||||
#add_subdirectory(plugin)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
qad_sources(test_SRC DIR "qglview_test")
|
||||
qad_wrap(${test_SRC} CPPS test_CPP)
|
||||
qad_add_executable(qglengine_test test_CPP)
|
||||
qad_target_link_libraries(qglengine_test qglengine_core qglengine_widgets)
|
||||
qad_target_include_directories(qglengine_test PRIVATE ${QAD_INCLUDES} "${CMAKE_CURRENT_SOURCE_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}/core" "${CMAKE_CURRENT_SOURCE_DIR}/widgets")
|
||||
|
||||
shstk_install(qglengine FALSE "" "${QGLEngine_VERSION_FILE}")
|
||||
file(GLOB CMAKES "cmake/*.cmake" "cmake/*.in")
|
||||
install(FILES ${CMAKES} DESTINATION ${CMAKE_ROOT}/Modules)
|
||||
|
||||
|
||||
@@ -11,22 +11,21 @@ These targets include directories and dependencies
|
||||
cmake_policy(SET CMP0011 NEW) # don`t affect includer policies
|
||||
cmake_policy(SET CMP0020 NEW) # Automatically link Qt executables to qtmain target on Windows
|
||||
|
||||
find_package(PIP REQUIRED)
|
||||
find_package(QAD REQUIRED)
|
||||
include(QtWraps)
|
||||
include(SHSTKMacros)
|
||||
|
||||
shstk_is_parent_exists(hasParent PARENT_DIRECTORY)
|
||||
|
||||
shstk_set_find_dirs(qglengine QGLEngine)
|
||||
set(_SEARCH_DIR ${qglengine_LIBDIR})
|
||||
shstk_set_find_dirs(QGLEngine)
|
||||
|
||||
if (NOT BUILDING_qglengine)
|
||||
list(APPEND _SEARCH_DIR $ENV{SMSDK_DIR}/lib)
|
||||
shstk_find_header(qglengine QGLENGINE "qglengine_version.h" "")
|
||||
if (NOT BUILDING_QGLEngine)
|
||||
shstk_find_header(QGLEngine "qglengine_version.h" ${QGLEngine_INCDIR})
|
||||
endif()
|
||||
|
||||
if(QGLENGINE_FIND_VERSION VERSION_GREATER QGLENGINE_VERSION)
|
||||
message(FATAL_ERROR "QGLENGINE version ${QGLENGINE_VERSION} is available, but ${QGLENGINE_FIND_VERSION} requested!")
|
||||
if(QGLEngine_FIND_VERSION VERSION_GREATER QGLEngine_VERSION)
|
||||
message(FATAL_ERROR "QGLEngine version ${QGLEngine_VERSION} is available, but ${QGLEngine_FIND_VERSION} requested!")
|
||||
endif()
|
||||
|
||||
set(__libs "core;widgets")
|
||||
@@ -40,15 +39,15 @@ foreach (_l ${__libs})
|
||||
set(__libs_${_l} "")
|
||||
endforeach()
|
||||
|
||||
set(__deps_core "QAD::Widgets")
|
||||
set(__deps_core "QAD::Widgets;QAD::PIQtUtils")
|
||||
set(__deps_widgets "QGLEngine::Core")
|
||||
|
||||
#message("find QGLEngine ${BUILDING_qglengine}")
|
||||
#message("find QGLEngine ${BUILDING_QGLEngine}")
|
||||
|
||||
if (BUILDING_qglengine)
|
||||
if (BUILDING_QGLEngine)
|
||||
|
||||
if (NOT SET_TARGETS_qglengine)
|
||||
set(SET_TARGETS_qglengine ON CACHE BOOL "")
|
||||
if (NOT SET_TARGETS_QGLEngine)
|
||||
set(SET_TARGETS_QGLEngine ON CACHE BOOL "")
|
||||
#message("create aliases")
|
||||
foreach(_l ${__libs})
|
||||
foreach(_v ${_QT_VERSIONS_})
|
||||
@@ -71,7 +70,7 @@ else()
|
||||
foreach(_l ${__libs})
|
||||
foreach(_v ${_QT_VERSIONS_})
|
||||
set(_m ${__module_${_l}})
|
||||
find_library(QGLENGINE_LIBRARY_${_l}${_v} qglengine_${_l}${_v} HINTS ${_SEARCH_DIR})
|
||||
find_library(QGLENGINE_LIBRARY_${_l}${_v} qglengine_${_l}${_v} HINTS ${QGLEngine_LIBDIR})
|
||||
#message("found ${_l}${_v} = ${QGLENGINE_LIBRARY_${_l}${_v}} (${qglengine_INCLUDES})")
|
||||
if((NOT TARGET QGLEngine::${_m}${_v}) AND QGLENGINE_LIBRARY_${_l}${_v})
|
||||
#message("imported QGLEngine::${_m}${_v} = ${QGLENGINE_LIBRARY_${_l}${_v}}")
|
||||
@@ -87,7 +86,7 @@ else()
|
||||
endforeach()
|
||||
set_target_properties(QGLEngine::${_m}${_v} PROPERTIES
|
||||
IMPORTED_LOCATION "${QGLENGINE_LIBRARY_${_l}${_v}}"
|
||||
INTERFACE_INCLUDE_DIRECTORIES "${qglengine_INCLUDES}"
|
||||
INTERFACE_INCLUDE_DIRECTORIES "${QGLEngine_INCLUDES}"
|
||||
INTERFACE_LINK_LIBRARIES "${_deps}")
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
@@ -1,58 +0,0 @@
|
||||
/*
|
||||
QGL Buffer
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef GLBUFFER_H
|
||||
#define GLBUFFER_H
|
||||
|
||||
#include "gltypes.h"
|
||||
|
||||
|
||||
class Buffer
|
||||
{
|
||||
friend class ObjectBase;
|
||||
public:
|
||||
Buffer(GLenum target, GLenum usage = GL_DYNAMIC_DRAW);
|
||||
~Buffer();
|
||||
|
||||
void init (QOpenGLExtraFunctions * f);
|
||||
void destroy (QOpenGLExtraFunctions * f);
|
||||
|
||||
void bind (QOpenGLExtraFunctions * f);
|
||||
void release (QOpenGLExtraFunctions * f);
|
||||
void * map (QOpenGLExtraFunctions * f, GLbitfield mode, int size = -1);
|
||||
void unmap (QOpenGLExtraFunctions * f);
|
||||
|
||||
// returns true if size changed
|
||||
bool resize (QOpenGLExtraFunctions * f, int new_size);
|
||||
void load (QOpenGLExtraFunctions * f, const void * data, int size, int offset = 0);
|
||||
|
||||
GLuint ID() const {return buffer_;}
|
||||
GLenum usage() const {return usage_;}
|
||||
GLenum target() const {return target_;}
|
||||
void setTarget(GLenum t) {target_ = t;}
|
||||
bool isInit() const {return buffer_ != 0;}
|
||||
|
||||
private:
|
||||
GLenum target_, usage_;
|
||||
GLuint buffer_;
|
||||
int prev_size;
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif // GLBUFFER_H
|
||||
@@ -1,54 +0,0 @@
|
||||
/*
|
||||
QGL CubeTexture
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef GLCUBEMAP_H
|
||||
#define GLCUBEMAP_H
|
||||
|
||||
#include "glshaders_types.h"
|
||||
#include "chunkstream.h"
|
||||
|
||||
QVector<QVector3D> loadFileHDR(const QString & path, QSize * size = 0);
|
||||
|
||||
class CubeTexture {
|
||||
public:
|
||||
CubeTexture(QOpenGLExtraFunctions * f_, int _size, const GLenum & _format = GL_RGB16F);
|
||||
bool init();
|
||||
void destroy();
|
||||
void bind(int channel = 0);
|
||||
void release();
|
||||
void resize(int _size) {size = _size; changed_ = true;}
|
||||
void loadHDR(const QVector<QVector3D> & data, QSize sz);
|
||||
void setFileHDR(const QString & path);
|
||||
QString fileHDR() const {return hdr_path;}
|
||||
GLenum format() const {return format_;}
|
||||
void setFormat(GLenum f) {format_ = f; changed_ = true;}
|
||||
GLuint id() const {return id_;}
|
||||
bool isInit() const {return id_ != 0;}
|
||||
void load();
|
||||
private:
|
||||
|
||||
QOpenGLExtraFunctions * f;
|
||||
bool changed_;
|
||||
int size;
|
||||
GLenum format_;
|
||||
GLuint id_;
|
||||
QString hdr_path;
|
||||
};
|
||||
|
||||
|
||||
#endif // GLCUBEMAP_H
|
||||
@@ -1,86 +0,0 @@
|
||||
/*
|
||||
QGL Framebuffer
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef GLFRAMEBUFFER_H
|
||||
#define GLFRAMEBUFFER_H
|
||||
|
||||
#include "glbuffer.h"
|
||||
|
||||
|
||||
class Framebuffer
|
||||
{
|
||||
friend class FramebufferMipmap;
|
||||
public:
|
||||
Framebuffer(QOpenGLExtraFunctions * f_, int colorAttachments = 1, bool withDepth = true, GLenum colorFormat = GL_RGBA8, GLenum _target = GL_TEXTURE_2D);
|
||||
Framebuffer(QOpenGLExtraFunctions * f_, QVector<GLenum> colors_, bool withDepth = true, GLenum _target = GL_TEXTURE_2D);
|
||||
virtual ~Framebuffer();
|
||||
|
||||
GLuint id() const {return fbo;}
|
||||
GLuint colorTexture(int index = 0) const {return colors[index];}
|
||||
GLuint depthTexture() const {return tex_d;}
|
||||
GLenum target() const {return target_;}
|
||||
bool isInit() const {return fbo != 0;}
|
||||
int width() const {return wid;}
|
||||
int height() const {return hei;}
|
||||
QSize size() const {return QSize(wid, hei);}
|
||||
QRect rect() const {return QRect(0, 0, wid, hei);}
|
||||
QImage grab() const;
|
||||
QVector<float> grabF(int index) const;
|
||||
void queryPoint(int index, QPoint p);
|
||||
void queryPoints(int index, QRect rect, GLenum pixel_format = GL_UNSIGNED_BYTE);
|
||||
void queryImage(int index);
|
||||
uint getPoint() const;
|
||||
QVector<uint> getPointsByte() const;
|
||||
QVector<QVector4D> getPointsFloat() const;
|
||||
QImage getImage() const;
|
||||
int queriedPoints() const {return pbo_queried;}
|
||||
void blit(int index_from, GLuint fb_to, int index_to, QRect from, QRect to, GLbitfield mask = GL_COLOR_BUFFER_BIT, GLenum filter = GL_NEAREST) const;
|
||||
|
||||
void resize(int width, int height, bool force = false);
|
||||
void bind();
|
||||
void release();
|
||||
void setReadBuffer(int index) {glReadBuffer(GL_COLOR_ATTACHMENT0 + index);}
|
||||
void setWriteBuffer(int index);
|
||||
void setWriteBuffers(const int * indeces, int count);
|
||||
void setWriteBuffers(const QVector<int> & indeces) {setWriteBuffers(indeces.constData(), indeces.size());}
|
||||
void setWriteBuffers();
|
||||
void unsetWriteBuffers();
|
||||
void enablePixelBuffer();
|
||||
void setColorTextureFiltering(int index, GLenum filter);
|
||||
|
||||
void copyDepthFrom(GLuint tex) {;}
|
||||
void bindColorTexture(int index, int channel = 0);
|
||||
void bindColorTextures();
|
||||
void bindDepthTexture(int channel);
|
||||
|
||||
private:
|
||||
void deleteGLRenderbuffer(GLuint & drbo);
|
||||
void deleteGLFramebuffer(GLuint & fbo);
|
||||
|
||||
bool is_depth, is_changed;
|
||||
int pbo_queried;
|
||||
QOpenGLExtraFunctions * f;
|
||||
mutable Buffer pbo;
|
||||
QVector<GLuint> colors;
|
||||
QVector<GLenum> color_formats;
|
||||
GLenum target_;
|
||||
GLuint fbo, drbo, tex_d;
|
||||
GLint prev_view[4], wid, hei;
|
||||
};
|
||||
|
||||
#endif // GLFRAMEBUFFER_H
|
||||
@@ -1,50 +0,0 @@
|
||||
/*
|
||||
QGL FramebufferMipmap
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <QOpenGLExtraFunctions>
|
||||
#include "glframebuffer_mipmap.h"
|
||||
#include <QTime>
|
||||
|
||||
|
||||
FramebufferMipmap::FramebufferMipmap(const Framebuffer & fb, int index_from_, int levels): src_fb(fb) {
|
||||
index_from = index_from_;
|
||||
for (int i = 0; i < levels; ++i)
|
||||
fbo << new Framebuffer(fb.f, 1, false, fb.color_formats[index_from]);
|
||||
}
|
||||
|
||||
|
||||
FramebufferMipmap::~FramebufferMipmap() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
void FramebufferMipmap::resize() {
|
||||
QSize sz = src_fb.size();
|
||||
for (int i = 0; i < fbo.size(); ++i) {
|
||||
sz /= 2;
|
||||
fbo[i]->resize(sz.width(), sz.height());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void FramebufferMipmap::create() {
|
||||
if (fbo.isEmpty()) return;
|
||||
src_fb.blit(index_from, fbo[0]->id(), 0, src_fb.rect(), fbo[0]->rect(), GL_COLOR_BUFFER_BIT, GL_LINEAR);
|
||||
for (int i = 0; i < fbo.size() - 1; ++i)
|
||||
fbo[i]->blit(0, fbo[i + 1]->id(), 0, fbo[i]->rect(), fbo[i + 1]->rect(), GL_COLOR_BUFFER_BIT, GL_LINEAR);
|
||||
}
|
||||
@@ -1,50 +0,0 @@
|
||||
/*
|
||||
QGL FramebufferMipmap
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef GLFRAMEBUFFER_MIPMAP_H
|
||||
#define GLFRAMEBUFFER_MIPMAP_H
|
||||
|
||||
#include "glframebuffer.h"
|
||||
|
||||
|
||||
class FramebufferMipmap
|
||||
{
|
||||
public:
|
||||
FramebufferMipmap(const Framebuffer & fb, int index_from_, int levels = 2);
|
||||
virtual ~FramebufferMipmap();
|
||||
|
||||
int levelsCount() const {return fbo.size();}
|
||||
int lastLevel() const {return fbo.size() - 1;}
|
||||
Framebuffer & plane(int level) {return *fbo[level];}
|
||||
Framebuffer & lastPlane() {return *fbo[lastLevel()];}
|
||||
int width (int level) const {return fbo[level]->wid;}
|
||||
int height(int level) const {return fbo[level]->hei;}
|
||||
QSize size(int level) const {return fbo[level]->size();}
|
||||
QRect rect(int level) const {return fbo[level]->rect();}
|
||||
|
||||
void resize();
|
||||
void create();
|
||||
|
||||
private:
|
||||
int index_from;
|
||||
const Framebuffer & src_fb;
|
||||
QVector<Framebuffer*> fbo;
|
||||
|
||||
};
|
||||
|
||||
#endif // GLFRAMEBUFFER_MIPMAP_H
|
||||
@@ -1,151 +0,0 @@
|
||||
/*
|
||||
QGL Material
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "gltypes.h"
|
||||
#include "gltexture_manager.h"
|
||||
#include "qglview.h"
|
||||
|
||||
using namespace QGLEngineShaders;
|
||||
|
||||
|
||||
Map::Map() {
|
||||
bitmap_id = 0;
|
||||
color_amount = 1.f;
|
||||
color_offset = 0.f;
|
||||
bitmap_scale = QPointF(1., 1.);
|
||||
use_bitmap = false;
|
||||
_changed = true;
|
||||
_layer = 0;
|
||||
}
|
||||
|
||||
|
||||
void Map::setBitmapPath(const QString & p) {
|
||||
bitmap_path = p;
|
||||
_changed = true;
|
||||
}
|
||||
|
||||
|
||||
void Map::load(TextureManager * tm) {
|
||||
if (bitmap_id == 0)
|
||||
bitmap_id = tm->loadTexture(bitmap_path, true, _type == mtNormal);
|
||||
}
|
||||
|
||||
|
||||
void Map::copyToQGLMap(QGLMap & m) const {
|
||||
m.amount = color_amount;
|
||||
m.offset = color_offset;
|
||||
m.scale = QVector2D(bitmap_scale);
|
||||
if (hasBitmap() && use_bitmap) {
|
||||
m.array_index = tarMaps;
|
||||
m.map_index = _layer;
|
||||
} else {
|
||||
m.array_index = tarEmpty;
|
||||
m.map_index = (_type == mtNormal ? emrBlue : emrWhite);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Material::Material(const QString _name) {
|
||||
setTypes();
|
||||
name = _name;
|
||||
color_diffuse = Qt::white;
|
||||
color_emission = Qt::black;
|
||||
glass = false;
|
||||
transparency = reflectivity = 0.f;
|
||||
map_roughness.color_amount = 0.75f;
|
||||
map_metalness.color_amount = 0.25f;
|
||||
iof = 1.f;
|
||||
dispersion = 0.05f;
|
||||
_changed = true;
|
||||
_index = 0;
|
||||
}
|
||||
|
||||
|
||||
uint Material::hash() {
|
||||
return qHash(name);
|
||||
}
|
||||
|
||||
|
||||
bool Material::hasTransparency() const {
|
||||
return float(color_diffuse.alphaF()) * (1.f - transparency) < 1.f;
|
||||
}
|
||||
|
||||
|
||||
bool Material::isMapsChanged() const {
|
||||
return map_diffuse ._changed ||
|
||||
map_normal ._changed ||
|
||||
map_metalness._changed ||
|
||||
map_roughness._changed ||
|
||||
map_emission ._changed ||
|
||||
map_relief ._changed;
|
||||
}
|
||||
|
||||
|
||||
bool Material::isMapChanged(int type) const {
|
||||
switch (type) {
|
||||
case mtDiffuse : return map_diffuse ._changed;
|
||||
case mtNormal : return map_normal ._changed;
|
||||
case mtMetalness: return map_metalness._changed;
|
||||
case mtRoughness: return map_roughness._changed;
|
||||
case mtEmission : return map_emission ._changed;
|
||||
case mtRelief : return map_relief ._changed;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void Material::load(TextureManager * tm) {
|
||||
map_diffuse .load(tm);
|
||||
map_normal .load(tm);
|
||||
map_metalness.load(tm);
|
||||
map_roughness.load(tm);
|
||||
map_emission .load(tm);
|
||||
map_relief .load(tm);
|
||||
}
|
||||
|
||||
|
||||
void Material::setMapsChanged() {
|
||||
map_diffuse ._changed = true;
|
||||
map_normal ._changed = true;
|
||||
map_metalness._changed = true;
|
||||
map_roughness._changed = true;
|
||||
map_emission ._changed = true;
|
||||
map_relief ._changed = true;
|
||||
}
|
||||
|
||||
|
||||
void Material::setTypes() {
|
||||
map_diffuse ._type = mtDiffuse ;
|
||||
map_normal ._type = mtNormal ;
|
||||
map_metalness._type = mtMetalness;
|
||||
map_roughness._type = mtRoughness;
|
||||
map_emission ._type = mtEmission ;
|
||||
map_relief ._type = mtRelief ;
|
||||
}
|
||||
|
||||
|
||||
void Material::detectMaps() {
|
||||
map_diffuse .use_bitmap = !map_diffuse .bitmap_path.isEmpty();
|
||||
map_normal .use_bitmap = !map_normal .bitmap_path.isEmpty();
|
||||
map_metalness.use_bitmap = !map_metalness.bitmap_path.isEmpty();
|
||||
map_roughness.use_bitmap = !map_roughness.bitmap_path.isEmpty();
|
||||
map_emission .use_bitmap = !map_emission .bitmap_path.isEmpty();
|
||||
map_relief .use_bitmap = !map_relief .bitmap_path.isEmpty();
|
||||
}
|
||||
@@ -1,120 +0,0 @@
|
||||
/*
|
||||
QGL Material
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef GLMATERIAL_H
|
||||
#define GLMATERIAL_H
|
||||
|
||||
#include "glshaders_types.h"
|
||||
#include "chunkstream.h"
|
||||
|
||||
|
||||
class Map {
|
||||
public:
|
||||
Map();
|
||||
void setBitmapPath(const QString & p);
|
||||
void clearBitmap() {setBitmapPath(QString());}
|
||||
bool hasBitmap() const {return !bitmap_path.isEmpty();}
|
||||
void load(TextureManager * tm);
|
||||
void copyToQGLMap(QGLEngineShaders::QGLMap & m) const;
|
||||
QString bitmap_path;
|
||||
GLuint bitmap_id;
|
||||
QPointF bitmap_offset;
|
||||
QPointF bitmap_scale;
|
||||
float color_amount;
|
||||
float color_offset;
|
||||
bool use_bitmap;
|
||||
|
||||
bool _changed;
|
||||
int _type, _layer;
|
||||
};
|
||||
|
||||
class Material {
|
||||
public:
|
||||
Material(const QString _name = QString());
|
||||
uint hash();
|
||||
bool hasTransparency() const;
|
||||
bool isMapsChanged() const;
|
||||
bool isMapChanged(int type) const;
|
||||
void load(TextureManager * tm);
|
||||
void setMapsChanged();
|
||||
void setTypes();
|
||||
void detectMaps();
|
||||
QString name;
|
||||
QColor color_diffuse;
|
||||
QColor color_emission;
|
||||
bool glass;
|
||||
float transparency;
|
||||
float reflectivity;
|
||||
float iof;
|
||||
float dispersion;
|
||||
Map map_diffuse ;
|
||||
Map map_normal ;
|
||||
Map map_metalness;
|
||||
Map map_roughness;
|
||||
Map map_emission ;
|
||||
Map map_relief ;
|
||||
bool _changed;
|
||||
int _index;
|
||||
};
|
||||
|
||||
|
||||
inline QDataStream & operator <<(QDataStream & s, const Map & m) {
|
||||
ChunkStream cs;
|
||||
cs.add(1, m.bitmap_path).add(2, m.color_amount).add(3, m.color_offset).add(6, m.bitmap_scale)
|
||||
.add(7, m.use_bitmap);
|
||||
s << cs.data(); return s;
|
||||
}
|
||||
inline QDataStream & operator >>(QDataStream & s, Map & m) {
|
||||
ChunkStream cs(s);
|
||||
cs.readAll();
|
||||
cs.get(1, m.bitmap_path).get(2, m.color_amount).get(3, m.color_offset).get(6, m.bitmap_scale)
|
||||
.get(7, m.use_bitmap);
|
||||
return s;
|
||||
}
|
||||
|
||||
inline QDataStream & operator <<(QDataStream & s, const Material * m) {
|
||||
ChunkStream cs;
|
||||
cs.add(1, m->name).add(2, m->color_diffuse).add(4, m->color_emission)
|
||||
.add(5, m->transparency).add(6, m->reflectivity).add(7, m->glass).add(8, m->map_diffuse).add(9, m->map_normal)
|
||||
.add(10, m->map_relief).add(11, m->map_metalness).add(12, m->map_roughness).add(13, m->map_emission);
|
||||
s << (cs.data()); return s;
|
||||
}
|
||||
inline QDataStream & operator >>(QDataStream & s, Material *& m) {
|
||||
m = new Material();
|
||||
ChunkStream cs(s);
|
||||
while (!cs.atEnd()) {
|
||||
switch (cs.read()) {
|
||||
case 1: cs.get(m->name); break;
|
||||
case 2: cs.get(m->color_diffuse); break;
|
||||
case 4: cs.get(m->color_emission); break;
|
||||
case 5: cs.get(m->transparency); break;
|
||||
case 6: cs.get(m->reflectivity); break;
|
||||
case 7: cs.get(m->glass); break;
|
||||
case 8: cs.get(m->map_diffuse); break;
|
||||
case 9: cs.get(m->map_normal); break;
|
||||
case 10: cs.get(m->map_relief); break;
|
||||
case 11: cs.get(m->map_metalness); break;
|
||||
case 12: cs.get(m->map_roughness); break;
|
||||
case 13: cs.get(m->map_emission); break;
|
||||
}
|
||||
}
|
||||
m->setTypes();
|
||||
return s;
|
||||
}
|
||||
|
||||
#endif // GLMATERIAL_H
|
||||
104
core/glmesh.h
@@ -1,104 +0,0 @@
|
||||
/*
|
||||
QGL Mesh
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef GLMESH_H
|
||||
#define GLMESH_H
|
||||
|
||||
#include <chunkstream.h>
|
||||
#include "glvertexobject.h"
|
||||
|
||||
|
||||
class Mesh
|
||||
{
|
||||
friend QDataStream & operator <<(QDataStream & s, const Mesh * m);
|
||||
friend QDataStream & operator >>(QDataStream & s, Mesh *& m);
|
||||
public:
|
||||
Mesh(GLenum geom_type_ = GL_TRIANGLES);
|
||||
~Mesh();
|
||||
|
||||
Mesh * clone();
|
||||
|
||||
void init (QOpenGLExtraFunctions * f);
|
||||
void destroy (QOpenGLExtraFunctions * f);
|
||||
bool rebuffer(QOpenGLExtraFunctions * f);
|
||||
void draw (QOpenGLExtraFunctions * f, int count, int type = 0);
|
||||
void clear();
|
||||
void loadObject (QOpenGLExtraFunctions * f, const QGLEngineShaders::Object & object, int type = 0);
|
||||
void loadObjects (QOpenGLExtraFunctions * f, const QVector<QGLEngineShaders::Object> & objects, int type = 0);
|
||||
void loadSelections(QOpenGLExtraFunctions * f, const QVector<uchar> & sels, int type = 0);
|
||||
|
||||
int verticesCount() const {return vertices_.size();}
|
||||
int trianglesCount() const {return triangles_.size();}
|
||||
int linesCount() const {return lines_.size();}
|
||||
bool isInit() const {return buffer_geom.isInit();}
|
||||
bool isEmpty() const {return vertices_.isEmpty();}
|
||||
uint hash() const;
|
||||
|
||||
bool isObjectsChanged (int type = 0) const;
|
||||
bool isSelectionChanged (int type = 0) const;
|
||||
void setObjectsChanged (int type = 0, bool yes = true);
|
||||
void setSelectionChanged(int type = 0, bool yes = true);
|
||||
void setAllObjectsChanged (bool yes = true);
|
||||
void setAllSelectionChanged(bool yes = true);
|
||||
|
||||
QVector<QVector3D> & vertices () {changed = hash_changed = true; return vertices_;}
|
||||
QVector<QVector3D> & normals () {changed = hash_changed = true; return normals_;}
|
||||
QVector<QVector2D> & texcoords() {changed = hash_changed = true; return texcoords_;}
|
||||
QVector< Vector3i> & indicesTriangles() {changed = hash_changed = true; return triangles_;}
|
||||
QVector< Vector2i> & indicesLines () {changed = hash_changed = true; return lines_;}
|
||||
|
||||
void translatePoints(const QVector3D & dp);
|
||||
void translatePoints(const double & x, const double & y, const double & z) {translatePoints(QVector3D(x, y, z));}
|
||||
void scalePoints (const QVector3D & dp);
|
||||
void scalePoints (const double & s) {scalePoints(QVector3D(s, s, s));}
|
||||
void rotatePoints (const double & angle, const QVector3D & a);
|
||||
void rotatePoints (const double & angle, const double & x, const double & y, const double & z) {rotatePoints(angle, QVector3D(x, y, z));}
|
||||
void transformPoints(const QMatrix4x4 & mat);
|
||||
void flipNormals();
|
||||
void append(const Mesh * m);
|
||||
|
||||
bool saveToFile(const QString & filename);
|
||||
bool loadFromFile(const QString & filename);
|
||||
|
||||
Box3D boundingBox() const;
|
||||
|
||||
private:
|
||||
void calculateNormals();
|
||||
void calculateTangents();
|
||||
VertexObject * vaoByType(int type);
|
||||
|
||||
QVector<QVector3D> vertices_, normals_, tangents_, bitangents_;
|
||||
QVector<QVector2D> texcoords_;
|
||||
QVector< Vector3i> triangles_;
|
||||
QVector< Vector2i> lines_;
|
||||
|
||||
QVector<QGLEngineShaders::Vertex> data_;
|
||||
GLenum geom_type;
|
||||
Buffer buffer_geom, buffer_ind;
|
||||
QMap<int, VertexObject * > vao_map;
|
||||
mutable uint hash_;
|
||||
mutable bool hash_changed;
|
||||
int vert_count;
|
||||
bool changed;
|
||||
};
|
||||
|
||||
|
||||
QDataStream & operator <<(QDataStream & s, const Mesh * m);
|
||||
QDataStream & operator >>(QDataStream & s, Mesh *& m);
|
||||
|
||||
#endif // GLMESH_H
|
||||
@@ -1,55 +0,0 @@
|
||||
/*
|
||||
QGL Primitives
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef GLPRIMITIVE_CUBE_H
|
||||
#define GLPRIMITIVE_CUBE_H
|
||||
|
||||
#include "gltypes.h"
|
||||
|
||||
|
||||
namespace Primitive {
|
||||
|
||||
|
||||
Mesh * plane(float width = 1., float length = 1.);
|
||||
|
||||
Mesh * cube(float width = 1., float length = 1., float height = 1.);
|
||||
|
||||
Mesh * ellipsoid(int segments_wl, int segments_h, float radius = 1., float end_angle = 360.);
|
||||
|
||||
Mesh * disc(int segments, float radius = 1., float end_angle = 360.);
|
||||
|
||||
Mesh * cone(int segments, float radius = 1., float height = 1.);
|
||||
|
||||
Mesh * cylinder(int segments, float radius = 1., float height = 1., float end_angle = 360.);
|
||||
|
||||
Mesh * arrow(int segments = 16, float thick = 0.04, float angle = 30.); // length = 1
|
||||
|
||||
Mesh * torus(int segments_main = 30, int segments_second = 16, float radius_main = 2.5, float radius_second = 0.5, float end_angle = 360.);
|
||||
|
||||
|
||||
Mesh * lineFrame(QVector3D p0, QVector3D p1);
|
||||
|
||||
Mesh * cubeFrame(float width = 1., float length = 1., float height = 1.);
|
||||
|
||||
Mesh * ellipsoidFrame(int segments_wl, int segments_h, float radius = 1.);
|
||||
|
||||
Mesh * coneFrame(int segments, float radius = 1., float height = 1.);
|
||||
|
||||
}
|
||||
|
||||
#endif // GLPRIMITIVE_CUBE_H
|
||||
@@ -1,31 +0,0 @@
|
||||
/*
|
||||
QGLEngineShaders
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef GLSHADERS_H
|
||||
#define GLSHADERS_H
|
||||
|
||||
#include "gltypes.h"
|
||||
|
||||
namespace QGLEngineShaders {
|
||||
|
||||
bool loadShadersMulti(QOpenGLShaderProgram *& prog, const QString & file, bool add_qgl = true, const QStringList & defines = QStringList());
|
||||
bool loadShaders(QOpenGLShaderProgram *& prog, const QStringList & files, bool add_qgl = true, const QStringList & defines = QStringList());
|
||||
|
||||
}
|
||||
|
||||
#endif // GLSHADERS_H
|
||||
@@ -1,121 +0,0 @@
|
||||
/*
|
||||
QGLEngineShaders
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef GLSHADERS_HEADERS_H
|
||||
#define GLSHADERS_HEADERS_H
|
||||
|
||||
namespace QGLEngineShaders {
|
||||
|
||||
const int max_materials = 128;
|
||||
const int max_lights = 256 ;
|
||||
|
||||
const char qgl_common_head[] =
|
||||
"#version 400 core\n"
|
||||
"";
|
||||
|
||||
const char qgl_vertex_head[] =
|
||||
"layout(location = 1 ) in vec3 qgl_Vertex ;\n"
|
||||
"layout(location = 2 ) in vec3 qgl_Normal ;\n"
|
||||
"layout(location = 3 ) in vec3 qgl_Tangent ;\n"
|
||||
"layout(location = 4 ) in vec3 qgl_Bitangent ;\n"
|
||||
"layout(location = 5 ) in vec2 qgl_Texture ;\n"
|
||||
"layout(location = 6 ) in uint qgl_Material ;\n"
|
||||
"layout(location = 7 ) in uint qgl_ObjectSelected;\n"
|
||||
"layout(location = 8 ) in uint qgl_ObjectID ;\n"
|
||||
"layout(location = 9 ) in vec4 qgl_ObjectColor ;\n"
|
||||
"layout(location = 10) in mat4 qgl_ModelMatrix ;\n"
|
||||
"out vec2 qgl_FragTexture;\n"
|
||||
"flat out uint qgl_MaterialIndex;\n"
|
||||
"uniform mat4 qgl_ViewMatrix;\n"
|
||||
"uniform mat4 qgl_ViewProjMatrix;\n"
|
||||
"mat3 qgl_getNormalMatrix() {return inverse(mat3(qgl_ViewMatrix * qgl_ModelMatrix));}\n"
|
||||
"mat3 qgl_getTangentMatrix() {return mat3(qgl_ViewMatrix * qgl_ModelMatrix);}\n"
|
||||
"vec4 qgl_ftransform() {return qgl_ViewProjMatrix * (qgl_ModelMatrix * vec4(qgl_Vertex, 1));}\n"
|
||||
"";
|
||||
|
||||
const char qgl_fragment_head[] =
|
||||
"in vec2 qgl_FragTexture;\n"
|
||||
"flat in uint qgl_MaterialIndex;\n"
|
||||
"out vec4 qgl_FragData[gl_MaxDrawBuffers];\n"
|
||||
"vec4 qgl_materialTexture(uint type, vec2 coord, vec4 tex_shift) {\n"
|
||||
" coord *= qgl_material[qgl_MaterialIndex].map[type].scale;\n"
|
||||
" vec4 t = texture(qgl_texture_array[qgl_material[qgl_MaterialIndex].map[type].array_index],\n"
|
||||
" vec3(coord, qgl_material[qgl_MaterialIndex].map[type].map_index));\n"
|
||||
" t += tex_shift;\n"
|
||||
" t.rgb = t.rgb * qgl_material[qgl_MaterialIndex].map[type].amount + qgl_material[qgl_MaterialIndex].map[type].offset;\n"
|
||||
" return t;\n"
|
||||
"}\n"
|
||||
"#define qgl_FragColor qgl_FragData[0]\n"
|
||||
"";
|
||||
|
||||
const char qgl_geometry_head[] =
|
||||
"";
|
||||
|
||||
const char qgl_structs[] =
|
||||
"#define QGL_MAPS_COUNT 6\n"
|
||||
"#define QGL_MAP_DIFFUSE 0\n"
|
||||
"#define QGL_MAP_NORMAL 1\n"
|
||||
"#define QGL_MAP_METALNESS 2\n"
|
||||
"#define QGL_MAP_ROUGHNESS 3\n"
|
||||
"#define QGL_MAP_EMISSION 4\n"
|
||||
"#define QGL_MAP_RELIEF 5\n"
|
||||
"#define QGL_TEXTURE_ARRAY_EMPTY 0\n"
|
||||
"#define QGL_TEXTURE_ARRAY_MAPS 1\n"
|
||||
"struct QGLMap {\n"
|
||||
" float offset;\n"
|
||||
" float amount;\n"
|
||||
" vec2 scale;\n"
|
||||
" uint array_index;\n"
|
||||
" uint map_index;\n"
|
||||
"};\n"
|
||||
"struct QGLMaterial {\n"
|
||||
" vec4 color_diffuse;\n"
|
||||
" vec4 color_emission;\n"
|
||||
" float transparency;\n"
|
||||
" float reflectivity;\n"
|
||||
" float iof;\n"
|
||||
" float dispersion;\n"
|
||||
" QGLMap map[QGL_MAPS_COUNT];\n"
|
||||
"};\n"
|
||||
"struct QGLLightParameter {\n"
|
||||
" vec4 color;\n"
|
||||
" vec4 decay_intensity;\n"
|
||||
" vec4 angles;\n"
|
||||
"};\n"
|
||||
"struct QGLLightPosition {\n"
|
||||
" vec4 position;\n"
|
||||
" vec4 direction;\n"
|
||||
"};\n"
|
||||
"";
|
||||
|
||||
const char qgl_uniform[] =
|
||||
"layout (std140) uniform QGLMaterialData {\n"
|
||||
" QGLMaterial qgl_material[128];\n"
|
||||
"};\n"
|
||||
"layout (std140) uniform QGLLightParameterData {\n"
|
||||
" QGLLightParameter qgl_light_parameter[256];\n"
|
||||
"};\n"
|
||||
"layout (std140) uniform QGLLightPositionData {\n"
|
||||
" QGLLightPosition qgl_light_position[256];\n"
|
||||
"};\n"
|
||||
"uniform sampler2DArray qgl_texture_array[2];\n"
|
||||
"";
|
||||
|
||||
}
|
||||
|
||||
#endif // GLSHADERS_HEADERS_H
|
||||
@@ -1,97 +0,0 @@
|
||||
/*
|
||||
QGLEngineShaders
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "glshaders_types.h"
|
||||
|
||||
|
||||
QGLEngineShaders::QGLMap::QGLMap() {
|
||||
offset = 0.;
|
||||
amount = 1.;
|
||||
scale = QVector2D(1., 1.);
|
||||
array_index = map_index = 0;
|
||||
}
|
||||
|
||||
|
||||
QGLEngineShaders::QGLMaterial::QGLMaterial() {
|
||||
color_diffuse = QVector4D(1., 1., 1., 0.);
|
||||
color_emission = QVector4D(0., 0., 0., 0.);
|
||||
transparency = 0.;
|
||||
reflectivity = 0.;
|
||||
iof = 0.;
|
||||
dispersion = 0.;
|
||||
map[mtNormal].map_index = emrBlue;
|
||||
map[mtRoughness].amount = 0.75;
|
||||
map[mtMetalness].amount = 0.25;
|
||||
}
|
||||
|
||||
|
||||
void QGLEngineShaders::prepareDrawGeom(QOpenGLExtraFunctions * f) {
|
||||
//qDebug() << "prepareDrawGeom";
|
||||
|
||||
f->glEnableVertexAttribArray(pos_loc );
|
||||
f->glEnableVertexAttribArray(normal_loc );
|
||||
f->glEnableVertexAttribArray(tangent_loc );
|
||||
f->glEnableVertexAttribArray(bitangent_loc);
|
||||
f->glEnableVertexAttribArray(tex_loc );
|
||||
|
||||
int size = sizeof(Vertex);
|
||||
f->glVertexAttribPointer(pos_loc , 3, GL_FLOAT, GL_FALSE, size, (const void *)pos_offset );
|
||||
f->glVertexAttribPointer(normal_loc , 3, GL_FLOAT, GL_FALSE, size, (const void *)normal_offset );
|
||||
f->glVertexAttribPointer(tangent_loc , 3, GL_FLOAT, GL_FALSE, size, (const void *)tangent_offset );
|
||||
f->glVertexAttribPointer(bitangent_loc, 3, GL_FLOAT, GL_FALSE, size, (const void *)bitangent_offset);
|
||||
f->glVertexAttribPointer(tex_loc , 2, GL_FLOAT, GL_FALSE, size, (const void *)tex_offset );
|
||||
}
|
||||
|
||||
|
||||
void QGLEngineShaders::prepareDrawObj(QOpenGLExtraFunctions * f) {
|
||||
//qDebug() << "prepareDrawObj";
|
||||
|
||||
f->glEnableVertexAttribArray(material_loc );
|
||||
f->glEnableVertexAttribArray(object_id_loc);
|
||||
f->glEnableVertexAttribArray(color_loc );
|
||||
for (int i = 0; i < 4; ++i) {
|
||||
f->glEnableVertexAttribArray(modelmatrix_loc + i);
|
||||
}
|
||||
|
||||
GLsizei size = sizeof(Object);
|
||||
f->glVertexAttribIPointer(material_loc , 1, GL_UNSIGNED_INT , size, (const void *)material_offset );
|
||||
f->glVertexAttribIPointer(object_id_loc, 1, GL_UNSIGNED_INT , size, (const void *)object_id_offset);
|
||||
f->glVertexAttribPointer (color_loc , 4, GL_FLOAT, GL_FALSE, size, (const void *)color_offset );
|
||||
for (int i = 0; i < 4; ++i) {
|
||||
f->glVertexAttribPointer(modelmatrix_loc + i, 4, GL_FLOAT, GL_FALSE, size, (const void *)(modelmatrix_offset + sizeof(QVector4D)*i));
|
||||
}
|
||||
|
||||
f->glVertexAttribDivisor(material_loc , 1);
|
||||
f->glVertexAttribDivisor(object_id_loc, 1);
|
||||
f->glVertexAttribDivisor(color_loc , 1);
|
||||
for (int i = 0; i < 4; ++i) {
|
||||
f->glVertexAttribDivisor(modelmatrix_loc + i, 1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void QGLEngineShaders::prepareDrawSel(QOpenGLExtraFunctions * f) {
|
||||
//qDebug() << "prepareDrawObj";
|
||||
|
||||
f->glEnableVertexAttribArray(is_selected_loc);
|
||||
GLsizei size = 1;
|
||||
f->glVertexAttribIPointer(is_selected_loc, 1, GL_UNSIGNED_BYTE, size, (const void *)is_selected_offset);
|
||||
f->glVertexAttribDivisor(is_selected_loc, 1);
|
||||
|
||||
}
|
||||
@@ -1,142 +0,0 @@
|
||||
/*
|
||||
QGLEngineShaders
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef GLSHADERS_TYPES_H
|
||||
#define GLSHADERS_TYPES_H
|
||||
|
||||
#include "gltypes.h"
|
||||
|
||||
namespace QGLEngineShaders {
|
||||
|
||||
|
||||
/// VBO
|
||||
|
||||
// geometry
|
||||
const GLsizei pos_offset = 0;
|
||||
const GLsizei normal_offset = sizeof(QVector3D) + pos_offset ;
|
||||
const GLsizei tangent_offset = sizeof(QVector3D) + normal_offset ;
|
||||
const GLsizei bitangent_offset = sizeof(QVector3D) + tangent_offset ;
|
||||
const GLsizei tex_offset = sizeof(QVector3D) + bitangent_offset;
|
||||
|
||||
// object
|
||||
const GLsizei material_offset = 0;
|
||||
const GLsizei object_id_offset = sizeof(GLuint ) + material_offset ;
|
||||
const GLsizei color_offset = sizeof(GLuint ) + object_id_offset ;
|
||||
const GLsizei modelmatrix_offset = sizeof(QVector4D) + color_offset;
|
||||
|
||||
const GLsizei is_selected_offset = 0;
|
||||
|
||||
const GLuint pos_loc = 1 ; // qgl_Vertex
|
||||
const GLuint normal_loc = 2 ; // qgl_Normal
|
||||
const GLuint tangent_loc = 3 ; // qgl_Tangent
|
||||
const GLuint bitangent_loc = 4 ; // qgl_Bitangent
|
||||
const GLuint tex_loc = 5 ; // qgl_Texture
|
||||
|
||||
const GLuint material_loc = 6 ; // qgl_Material
|
||||
const GLuint object_id_loc = 8 ; // qgl_ObjectID
|
||||
const GLuint color_loc = 9 ; // qgl_ObjectColor
|
||||
const GLuint modelmatrix_loc = 10; // qgl_ModelViewProjectionMatrix
|
||||
|
||||
const GLuint is_selected_loc = 7 ; // qgl_ObjectSelected
|
||||
|
||||
#pragma pack(push, 1)
|
||||
struct Vertex {
|
||||
QVector3D pos;
|
||||
QVector3D normal;
|
||||
QVector3D tangent;
|
||||
QVector3D bitangent;
|
||||
QVector2D tex;
|
||||
};
|
||||
struct Object {
|
||||
Object() {
|
||||
material = object_id = 0;
|
||||
color = QVector4D(1,1,1,1);
|
||||
QMatrix4x4().copyDataTo(modelmatrix);
|
||||
}
|
||||
GLuint material;
|
||||
GLuint object_id;
|
||||
QVector4D color;
|
||||
GLfloat modelmatrix[16];
|
||||
};
|
||||
#pragma pack(pop)
|
||||
|
||||
|
||||
/// UBO
|
||||
|
||||
enum BindingPoints {
|
||||
bpMaterials,
|
||||
bpLightParameters,
|
||||
bpLightPositions,
|
||||
};
|
||||
|
||||
enum MapType {
|
||||
mtDiffuse = 0,
|
||||
mtNormal = 1,
|
||||
mtMetalness = 2,
|
||||
mtRoughness = 3,
|
||||
mtEmission = 4,
|
||||
mtRelief = 5,
|
||||
};
|
||||
enum TextureArrayRole {
|
||||
tarEmpty = 0,
|
||||
tarMaps = 1,
|
||||
};
|
||||
enum EmptyMapRole {
|
||||
emrWhite = 0,
|
||||
emrBlue = 1,
|
||||
};
|
||||
#define QGL_MAPS_COUNT 6
|
||||
#pragma pack(push, 1)
|
||||
struct QGLMap {
|
||||
QGLMap();
|
||||
GLfloat offset;
|
||||
GLfloat amount;
|
||||
QVector2D scale;
|
||||
GLuint array_index;
|
||||
GLuint map_index;
|
||||
GLfloat __res_2[2];
|
||||
};
|
||||
struct QGLMaterial {
|
||||
QGLMaterial();
|
||||
QVector4D color_diffuse;
|
||||
QVector4D color_emission;
|
||||
GLfloat transparency;
|
||||
GLfloat reflectivity;
|
||||
GLfloat iof;
|
||||
GLfloat dispersion;
|
||||
QGLMap map[QGL_MAPS_COUNT];
|
||||
};
|
||||
struct QGLLightParameter {
|
||||
QVector4D color;
|
||||
QVector4D decay_intensity; // [^0, ^1, ^2, intensity]
|
||||
QVector4D angles; // [start, cos(start), end, cos(end)]
|
||||
};
|
||||
struct QGLLightPosition {
|
||||
QVector4D position;
|
||||
QVector4D direction;
|
||||
};
|
||||
#pragma pack(pop)
|
||||
|
||||
void prepareDrawGeom(QOpenGLExtraFunctions * f);
|
||||
void prepareDrawObj (QOpenGLExtraFunctions * f);
|
||||
void prepareDrawSel (QOpenGLExtraFunctions * f);
|
||||
|
||||
|
||||
}
|
||||
|
||||
#endif // GLSHADERS_TYPES_H
|
||||
@@ -1,54 +0,0 @@
|
||||
/*
|
||||
QGL Texture2DArray
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef GLTEXTUREARRAY_H
|
||||
#define GLTEXTUREARRAY_H
|
||||
|
||||
#include "gltypes.h"
|
||||
|
||||
|
||||
class Texture2DArray
|
||||
{
|
||||
public:
|
||||
Texture2DArray(bool filter);
|
||||
~Texture2DArray();
|
||||
|
||||
void init (QOpenGLExtraFunctions * f);
|
||||
void destroy (QOpenGLExtraFunctions * f);
|
||||
|
||||
void bind (QOpenGLExtraFunctions * f, int channel = 0);
|
||||
void release (QOpenGLExtraFunctions * f);
|
||||
|
||||
// returns true if size changed
|
||||
bool resize (QOpenGLExtraFunctions * f, QSize new_size, int layers_count);
|
||||
void load (QOpenGLExtraFunctions * f, const QImage & image, int layer);
|
||||
void mipmaps (QOpenGLExtraFunctions * f);
|
||||
|
||||
GLuint ID() const {return texture_;}
|
||||
bool isInit() const {return texture_ != 0;}
|
||||
|
||||
private:
|
||||
GLenum target_;
|
||||
GLuint texture_;
|
||||
QSize size_;
|
||||
int layers_;
|
||||
bool filtering_;
|
||||
};
|
||||
|
||||
|
||||
#endif // GLTEXTUREARRAY_H
|
||||
304
core/gltypes.h
@@ -1,304 +0,0 @@
|
||||
/*
|
||||
QGLView Types
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef GLTYPES_H
|
||||
#define GLTYPES_H
|
||||
|
||||
#if WIN32 || WIN64 || _WIN32 || _WIN64 || __WIN32__ || __WIN64__
|
||||
# define WINDOWS
|
||||
#endif
|
||||
#if __QNX__ || __QNXNTO__
|
||||
# define QNX
|
||||
#endif
|
||||
#ifdef __APPLE__
|
||||
# define MAC
|
||||
#endif
|
||||
#ifndef WINDOWS
|
||||
# ifndef QNX
|
||||
# ifndef MAC
|
||||
# define LINUX
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
#if __GNUC__
|
||||
# define CC_GCC
|
||||
#elif _MSC_VER
|
||||
# define CC_VC
|
||||
#endif
|
||||
|
||||
|
||||
#include <QObject>
|
||||
//#ifndef WINDOWS
|
||||
//# ifdef MAC
|
||||
//# include <OpenGL/gl.h>
|
||||
//# include <OpenGL/glu.h>
|
||||
//# include <GLUT/glut.h>
|
||||
//# else
|
||||
//# include <GL/gl.h>
|
||||
//# include <GL/glext.h>
|
||||
//# include <GL/glu.h>
|
||||
//# endif
|
||||
//#endif
|
||||
#include <QOpenGLExtraFunctions>
|
||||
#include <QOpenGLShader>
|
||||
#include <QOpenGLShaderProgram>
|
||||
#include <qopenglext.h>
|
||||
#include <cmath>
|
||||
#include <float.h>
|
||||
#include <QMatrix4x4>
|
||||
#include <QDebug>
|
||||
#include <QDataStream>
|
||||
#include <QColor>
|
||||
#include <QVector2D>
|
||||
#include <QVector3D>
|
||||
#include <QImage>
|
||||
#include <QMutex>
|
||||
#include <QFile>
|
||||
#include <QDir>
|
||||
#ifndef QNX
|
||||
# include <cmath>
|
||||
# include <complex>
|
||||
#else
|
||||
# include <math.h>
|
||||
# include <complex.h>
|
||||
#endif
|
||||
#include <iostream>
|
||||
#include "qglengine_version.h"
|
||||
#include "qglengine_core_export.h"
|
||||
|
||||
|
||||
//#ifdef WINDOWS
|
||||
//# define GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT 0x84FF
|
||||
//# define GL_TEXTURE_MAX_ANISOTROPY_EXT 0x84FE
|
||||
//#endif
|
||||
|
||||
#ifndef M_PI
|
||||
# define M_PI 3.14159265358979323846
|
||||
#endif
|
||||
#ifndef M_2PI
|
||||
# define M_2PI 6.28318530717958647692
|
||||
#endif
|
||||
#ifndef M_PI_3
|
||||
# define M_PI_3 1.04719755119659774615
|
||||
#endif
|
||||
|
||||
#ifndef GL_RGBA16F
|
||||
# define GL_RGBA16F GL_RGBA16F_ARB
|
||||
#endif
|
||||
|
||||
using std::complex;
|
||||
|
||||
#ifndef PIP_VERSION
|
||||
typedef long long llong;
|
||||
typedef unsigned char uchar;
|
||||
typedef unsigned short int ushort;
|
||||
typedef unsigned int uint;
|
||||
typedef unsigned long ulong;
|
||||
typedef unsigned long long ullong;
|
||||
typedef long double ldouble;
|
||||
|
||||
const float deg2rad = atanf(1.f) / 45.f;
|
||||
const float rad2deg = 45.f / atanf(1.f);
|
||||
|
||||
# ifdef WINDOWS
|
||||
inline int random() {return rand();}
|
||||
# endif
|
||||
#else
|
||||
#define random randomi
|
||||
#endif
|
||||
|
||||
#ifdef CC_VC
|
||||
inline float round(const float & v) {return floor(v + 0.5);}
|
||||
#endif
|
||||
inline float randomu() {return float(random()) / RAND_MAX;}
|
||||
|
||||
inline const QSizeF operator *(const QSizeF & f, const QSizeF & s) {return QSizeF(f.width() * s.width(), f.height() * s.height());}
|
||||
#ifndef PIP_VERSION
|
||||
template<typename T> inline void piSwap(T & f, T & s) {T t(f); f = s; s = t;}
|
||||
template<typename Type> inline Type piMin(const Type & f, const Type & s) {return (f > s) ? s : f;}
|
||||
template<typename Type> inline Type piMin(const Type & f, const Type & s, const Type & t) {return (f < s && f < t) ? f : ((s < t) ? s : t);}
|
||||
template<typename Type> inline Type piMax(const Type & f, const Type & s) {return (f < s) ? s : f;}
|
||||
template<typename Type> inline Type piMax(const Type & f, const Type & s, const Type & t) {return (f > s && f > t) ? f : ((s > t) ? s : t);}
|
||||
template<typename Type> inline Type piClamp(const Type & v, const Type & min, const Type & max) {return (v > max ? max : (v < min ? min : v));}
|
||||
inline ushort letobe_s(ushort v) {return (v << 8) | (v >> 8);}
|
||||
inline uint letobe_i(const uint & v) {return (v >> 24) | ((v >> 8) & 0xFF00) | ((v << 8) & 0xFF0000) | ((v << 24) & 0xFF000000);}
|
||||
#endif
|
||||
// return [-1, 1]
|
||||
inline float urand(const float & scale = 1.) {return ((float)rand() / RAND_MAX - .5f) * (scale + scale);}
|
||||
// return [0, 1]
|
||||
inline float uprand(const float & scale = 1.) {return ((float)rand() / RAND_MAX) * scale;}
|
||||
QString readCharsUntilNull(QDataStream & s);
|
||||
QString findFile(const QString & file, const QStringList & pathes);
|
||||
inline QColor operator *(const QColor & c, float v) {return QColor(piClamp<int>(c.red() * v, 0, 255), piClamp<int>(c.green() * v, 0, 255), piClamp<int>(c.blue() * v, 0, 255), piClamp<int>(c.alpha() * v, 0, 255));}
|
||||
inline QColor operator /(const QColor & c, float v) {return QColor(piClamp<int>(c.red() / v, 0, 255), piClamp<int>(c.green() / v, 0, 255), piClamp<int>(c.blue() / v, 0, 255), piClamp<int>(c.alpha() / v, 0, 255));}
|
||||
|
||||
|
||||
inline void qglColor(const QColor & c) {glColor4f(c.redF(), c.greenF(), c.blueF(), c.alphaF());}
|
||||
inline void glClearError() {int c = 100; while (glGetError() != GL_NO_ERROR && --c > 0) glGetError();}
|
||||
inline void glSetCapEnabled(GLenum cap, bool on = true) {if (on) glEnable(cap); else glDisable(cap);}
|
||||
inline void glSetPolygonMode(GLenum mode) {glPolygonMode(GL_FRONT_AND_BACK, mode);}
|
||||
inline void deleteGLTexture(QOpenGLExtraFunctions * f, GLuint & tex) {if (tex != 0) f->glDeleteTextures(1, &tex); tex = 0;}
|
||||
void glEnableDepth();
|
||||
void glDisableDepth();
|
||||
void glClearFramebuffer(const QColor & color = Qt::black, bool depth = true);
|
||||
void glDrawQuad(QOpenGLShaderProgram * prog = nullptr, QVector4D * corner_dirs = nullptr, GLfloat x = -1.f, GLfloat y = -1.f, GLfloat w = 2.f, GLfloat h = 2.f);
|
||||
void createGLTexture(QOpenGLExtraFunctions * f, GLuint & tex, int width, int height, const GLenum & format = GL_RGBA, const GLenum & target = GL_TEXTURE_2D);
|
||||
void createGLTexture(QOpenGLExtraFunctions * f, GLuint & tex, const QImage & image, const GLenum & format = GL_RGBA, const GLenum & target = GL_TEXTURE_2D);
|
||||
QMatrix4x4 glMatrixPerspective(float angle, float aspect, float near_);
|
||||
QImage rotateQImageLeft(const QImage & im);
|
||||
QImage rotateQImageRight(const QImage & im);
|
||||
inline QImage rotateQImage180(const QImage & im) {return im.mirrored(true, true);}
|
||||
|
||||
class QGLView;
|
||||
class MouseController;
|
||||
class ObjectBase;
|
||||
class AimedObject;
|
||||
class Light;
|
||||
class Camera;
|
||||
class Texture;
|
||||
class CubeTexture;
|
||||
class Map;
|
||||
class Material;
|
||||
class TextureManager;
|
||||
class Texture2DArray;
|
||||
class Framebuffer;
|
||||
class FramebufferMipmap;
|
||||
class VertexObject;
|
||||
class Mesh;
|
||||
class Scene;
|
||||
class RendererBase;
|
||||
class Renderer;
|
||||
class RendererMaterial;
|
||||
class RendererService;
|
||||
class RendererSelection;
|
||||
|
||||
enum RenderPass {
|
||||
rpSolid,
|
||||
rpTransparent,
|
||||
};
|
||||
|
||||
typedef QList<ObjectBase*> ObjectBaseList;
|
||||
|
||||
struct Box3D {
|
||||
GLfloat x;
|
||||
GLfloat y;
|
||||
GLfloat z;
|
||||
GLfloat width;
|
||||
GLfloat length;
|
||||
GLfloat height;
|
||||
GLfloat angle_z;
|
||||
GLfloat angle_xy;
|
||||
GLfloat angle_roll;
|
||||
Box3D() {x = y = z = width = length = height = angle_z = angle_xy = angle_roll = 0.f;}
|
||||
Box3D(const QVector3D & center, GLfloat hwid, GLfloat hlen, GLfloat hhei) {x = center.x() - hwid; y = center.y() - hlen; z = center.z() - hhei; width = 2 * hwid; length = 2 * hlen; height = 2 * hhei; angle_z = angle_xy = angle_roll = 0.f;}
|
||||
Box3D(const QVector<QVector3D> & points);
|
||||
bool isEmpty() const {return (qAbs(width) < 1E-6f) && (qAbs(length) < 1E-6f) && (qAbs(height) < 1E-6f);}
|
||||
QVector3D randomPoint() const {return QVector3D(uprand(length) + x, uprand(width) + y, uprand(height) + z);}
|
||||
QVector3D pos() const {return QVector3D(x, y, z);}
|
||||
QVector3D size() const {return QVector3D(length, width, height);}
|
||||
QVector3D center() const {return QVector3D(length / 2.f + x, width / 2.f + y, height / 2.f + z);}
|
||||
QVector3D angles() const {return QVector3D(angle_xy, angle_roll, angle_z);}
|
||||
QVector<QVector3D> corners() const;
|
||||
void setPos(const QVector3D & p) {x = p.x(); y = p.y(); z = p.z();}
|
||||
void setAngles(const QVector3D & a) {angle_xy = a.x(); angle_roll = a.y(); angle_z = a.z();}
|
||||
void setSize(const QVector3D & s) {length = s.x(); width = s.y(); height = s.z();}
|
||||
Box3D & moveTo(const QVector3D & v) {x = v.x(); y = v.y(); z = v.z(); return *this;}
|
||||
Box3D & move(const QVector3D & v) {x += v.x(); y += v.y(); z += v.z(); return *this;}
|
||||
Box3D movedTo(const QVector3D & v) const {Box3D t(*this); t.x = v.x(); t.y = v.y(); t.z = v.z(); return t;}
|
||||
Box3D moved(const QVector3D & v) const {Box3D t(*this); t.x += v.x(); t.y += v.y(); t.z += v.z(); return t;}
|
||||
Box3D & operator |=(const Box3D & o);
|
||||
};
|
||||
|
||||
inline QDebug operator <<(QDebug d, const Box3D & v) {d << "Box3D {start (" << v.x << "," << v.y << "," << v.z << "), size (" << v.length << "," << v.width << "," << v.height << ")}"; return d;}
|
||||
|
||||
|
||||
#pragma pack(push, 1)
|
||||
struct Vector2i {
|
||||
Vector2i(int p0_ = 0, int p1_ = 0) {p0 = p0_; p1 = p1_;}
|
||||
Vector2i(const QString & str);
|
||||
Vector2i movedX(const int & o) {return Vector2i(p0 + o, p1);}
|
||||
Vector2i movedY(const int & o) {return Vector2i(p0, p1 + o);}
|
||||
Vector2i moved(const int & x, const int & y) {return Vector2i(p0 + x, p1 + y);}
|
||||
GLint p0;
|
||||
GLint p1;
|
||||
bool operator ==(const Vector2i & o) const {return p0 == o.p0 && p1 == o.p1;}
|
||||
bool operator !=(const Vector2i & o) const {return p0 != o.p0 || p1 != o.p1;}
|
||||
void operator +=(int v) {p0 += v; p1 += v;}
|
||||
QVector2D toQVector2D() const {return QVector2D(p0, p1);}
|
||||
};
|
||||
#pragma pack(pop)
|
||||
|
||||
inline Vector2i operator +(const Vector2i & f, const Vector2i & s) {return Vector2i(f.p0 + s.p0, f.p1 + s.p1);}
|
||||
inline Vector2i operator -(const Vector2i & f, const Vector2i & s) {return Vector2i(f.p0 - s.p0, f.p1 - s.p1);}
|
||||
inline Vector2i operator /(const Vector2i & f, const int & s) {return Vector2i(f.p0 / s, f.p1 / s);}
|
||||
inline uint qHash(const Vector2i & v) {return v.p0 ^ ((v.p1 << 8) | (v.p1 >> 24));}
|
||||
inline QDebug operator <<(QDebug d, const Vector2i & v) {d.nospace() << "{" << v.p0 << ", " << v.p1 << "}"; return d.space();}
|
||||
|
||||
inline QDataStream & operator <<(QDataStream & s, const Vector2i & v) {s << v.p0 << v.p1; return s;}
|
||||
inline QDataStream & operator >>(QDataStream & s, Vector2i & v) {s >> v.p0 >> v.p1; return s;}
|
||||
|
||||
|
||||
#pragma pack(push, 1)
|
||||
struct Vector3i {
|
||||
Vector3i(int p0_ = 0, int p1_ = 0, int p2_ = 0) {p0 = p0_; p1 = p1_; p2 = p2_;}
|
||||
Vector3i(const QString & str);
|
||||
Vector3i movedX(const int & o) {return Vector3i(p0 + o, p1, p2);}
|
||||
Vector3i movedY(const int & o) {return Vector3i(p0, p1 + o, p2);}
|
||||
Vector3i movedZ(const int & o) {return Vector3i(p0, p1, p2 + o);}
|
||||
Vector3i moved(const int & x, const int & y, const int & z) {return Vector3i(p0 + x, p1 + y, p2 + z);}
|
||||
GLint p0;
|
||||
GLint p1;
|
||||
GLint p2;
|
||||
bool operator ==(const Vector3i & o) const {return p0 == o.p0 && p1 == o.p1 && p2 == o.p2;}
|
||||
bool operator !=(const Vector3i & o) const {return p0 != o.p0 || p1 != o.p1 || p2 != o.p2;}
|
||||
void operator +=(int v) {p0 += v; p1 += v; p2 += v;}
|
||||
QVector3D toQVector3D() const {return QVector3D(p0, p1, p2);}
|
||||
};
|
||||
#pragma pack(pop)
|
||||
|
||||
inline Vector3i operator +(const Vector3i & f, const Vector3i & s) {return Vector3i(f.p0 + s.p0, f.p1 + s.p1, f.p2 + s.p2);}
|
||||
inline Vector3i operator -(const Vector3i & f, const Vector3i & s) {return Vector3i(f.p0 - s.p0, f.p1 - s.p1, f.p2 - s.p2);}
|
||||
inline Vector3i operator /(const Vector3i & f, const int & s) {return Vector3i(f.p0 / s, f.p1 / s, f.p2 / s);}
|
||||
inline uint qHash(const Vector3i & v) {return v.p0 ^ ((v.p1 << 8) | (v.p1 >> 24)) ^ ((v.p2 << 16) | (v.p2 >> 16));}
|
||||
inline QDebug operator <<(QDebug d, const Vector3i & v) {d.nospace() << "{" << v.p0 << ", " << v.p1 << ", " << v.p2 << "}"; return d.space();}
|
||||
|
||||
inline QDataStream & operator <<(QDataStream & s, const Vector3i & v) {s << v.p0 << v.p1 << v.p2; return s;}
|
||||
inline QDataStream & operator >>(QDataStream & s, Vector3i & v) {s >> v.p0 >> v.p1 >> v.p2; return s;}
|
||||
|
||||
|
||||
QVector3D vectorFromString(const QString & str);
|
||||
QColor colorFromString(const QString & str);
|
||||
inline QVector4D QColor2QVector(const QColor & c) {return QVector4D(c.redF(), c.greenF(), c.blueF(), c.alphaF());}
|
||||
inline float cosABV(const QVector3D & v0, const QVector3D & v1) {
|
||||
float l = v0.length() * v1.length();
|
||||
if (l == 0.f) return 0.;
|
||||
return (QVector3D::dotProduct(v0, v1)) / l;
|
||||
}
|
||||
inline void normalizeAngleRad(float & a) {while (a < 0.) a += M_2PI; while (a >= M_2PI) a -= M_2PI;}
|
||||
inline void normalizeAngleDeg360(float & a) {while (a < 0.) a += 360. ; while (a >= 360. ) a -= 360. ;}
|
||||
inline QVector3D projection(const QVector3D & v, const QVector3D & to) {return to.normalized() * v.length() * cosABV(v, to);}
|
||||
QVector3D orthToVector(const QVector3D & v, const float & scale = 1.);
|
||||
QVector3D rotateVector(const QVector3D & v, const QVector3D & a);
|
||||
void setVectorLength(QVector3D & v, const float & l);
|
||||
void lengthenVector(QVector3D & v, const float & l);
|
||||
inline float squareLength(const QVector3D & from, const QVector3D & to) {return (to.x() - from.x())*(to.x() - from.x()) + (to.y() - from.y())*(to.y() - from.y()) + (to.z() - from.z())*(to.z() - from.z());}
|
||||
inline QVector3D directionFromAngles(const QVector3D & a) {return rotateVector(QVector3D(1., 0., 0.), a);}
|
||||
inline float frac(const float & x, const float & b) {return x - int(x / b) * b;}
|
||||
|
||||
|
||||
#endif // GLTYPES_H
|
||||
@@ -1,62 +0,0 @@
|
||||
/*
|
||||
QGL VertexObject
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef GLVERTEXOBJECT_H
|
||||
#define GLVERTEXOBJECT_H
|
||||
|
||||
#include "glbuffer.h"
|
||||
#include "glshaders_types.h"
|
||||
|
||||
|
||||
class VertexObject
|
||||
{
|
||||
public:
|
||||
VertexObject();
|
||||
~VertexObject();
|
||||
|
||||
void init (QOpenGLExtraFunctions * f);
|
||||
void destroy (QOpenGLExtraFunctions * f);
|
||||
|
||||
void bind (QOpenGLExtraFunctions * f);
|
||||
void release (QOpenGLExtraFunctions * f);
|
||||
|
||||
void bindBuffers (QOpenGLExtraFunctions * f, Buffer & geom, Buffer & elem, bool force = false);
|
||||
void loadObject (QOpenGLExtraFunctions * f, const QGLEngineShaders::Object & object);
|
||||
void loadObjects (QOpenGLExtraFunctions * f, const QVector<QGLEngineShaders::Object> & objects);
|
||||
void loadSelections(QOpenGLExtraFunctions * f, const QVector<uchar> & sels);
|
||||
|
||||
void draw(QOpenGLExtraFunctions * f, GLenum geom_type, int vert_cout, int obj_count);
|
||||
|
||||
GLuint ID() const {return vao_;}
|
||||
bool isInit() const {return vao_ != 0;}
|
||||
|
||||
bool isObjectsChanged() const {return objects_changed;}
|
||||
bool isSelectionChanged() const {return selected_changed;}
|
||||
void setObjectsChanged(bool yes = true) {objects_changed = yes;}
|
||||
void setSelectionChanged(bool yes = true) {selected_changed = yes;}
|
||||
|
||||
private:
|
||||
void loadBuffer(QOpenGLExtraFunctions * f, Buffer & buf, const void * data, int size);
|
||||
|
||||
GLuint vao_;
|
||||
Buffer buffer_obj, buffer_sel;
|
||||
bool buffers_binded, objects_changed, selected_changed;
|
||||
};
|
||||
|
||||
|
||||
#endif // GLVERTEXOBJECT_H
|
||||
126
core/hdr.cpp
@@ -1,126 +0,0 @@
|
||||
/*
|
||||
QGL HDR
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "hdr_p.h"
|
||||
#include <qmath.h>
|
||||
#include <QByteArray>
|
||||
|
||||
#define RGBE_DATA_RED 2
|
||||
#define RGBE_DATA_GREEN 1
|
||||
#define RGBE_DATA_BLUE 0
|
||||
/* number of floats per pixel */
|
||||
#define RGBE_DATA_SIZE 3
|
||||
|
||||
|
||||
void rgbe2float(float *red, float *green, float *blue, uchar rgbe[4]) {
|
||||
float f;
|
||||
if (rgbe[3]) {
|
||||
f = static_cast<float>(ldexp(1.0,rgbe[3]-(int)(128+8)));
|
||||
*red = rgbe[0] * f;
|
||||
*green = rgbe[1] * f;
|
||||
*blue = rgbe[2] * f;
|
||||
}
|
||||
else
|
||||
*red = *green = *blue = 0.0;
|
||||
}
|
||||
|
||||
|
||||
/* simple read routine. will not correctly handle run length encoding */
|
||||
bool RGBE_ReadPixels(QDataStream * fp, float * data, int numpixels) {
|
||||
uchar rgbe[4];
|
||||
while(numpixels-- > 0) {
|
||||
if (fp->readRawData((char*)rgbe, sizeof(rgbe)) < 1)
|
||||
return false;
|
||||
rgbe2float(&data[RGBE_DATA_RED], &data[RGBE_DATA_GREEN], &data[RGBE_DATA_BLUE],rgbe);
|
||||
data += RGBE_DATA_SIZE;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool RGBE_ReadPixels_RLE(QDataStream * fp, float * data, int scanline_width, int num_scanlines) {
|
||||
uchar rgbe[4], *ptr, *ptr_end;
|
||||
int i, count;
|
||||
uchar buf[2];
|
||||
QByteArray scanline_buffer;
|
||||
|
||||
if ((scanline_width < 8)||(scanline_width > 0x7fff))
|
||||
/* run length encoding is not allowed so read flat*/
|
||||
return RGBE_ReadPixels(fp,data,scanline_width*num_scanlines);
|
||||
scanline_buffer.resize(4*scanline_width);
|
||||
/* read in each successive scanline */
|
||||
while(num_scanlines > 0) {
|
||||
if (fp->readRawData((char*)rgbe,sizeof(rgbe)) < 1) {
|
||||
return false;
|
||||
}
|
||||
if ((rgbe[0] != 2)||(rgbe[1] != 2)||(rgbe[2] & 0x80)) {
|
||||
/* this file is not run length encoded */
|
||||
rgbe2float(&data[RGBE_DATA_RED],&data[RGBE_DATA_GREEN],&data[RGBE_DATA_BLUE],rgbe);
|
||||
data += RGBE_DATA_SIZE;
|
||||
return RGBE_ReadPixels(fp,data,scanline_width*num_scanlines-1);
|
||||
}
|
||||
if ((((int)rgbe[2])<<8 | rgbe[3]) != scanline_width) {
|
||||
return false;
|
||||
}
|
||||
ptr = (uchar*)scanline_buffer.data();
|
||||
/* read each of the four channels for the scanline into the buffer */
|
||||
for(i=0;i<4;i++) {
|
||||
ptr_end = (uchar*)scanline_buffer.data() + ((i+1)*scanline_width);
|
||||
while(ptr < ptr_end) {
|
||||
if (fp->readRawData((char*)buf,sizeof(buf[0])*2) < 1) {
|
||||
return false;
|
||||
}
|
||||
if (buf[0] > 128) {
|
||||
/* a run of the same value */
|
||||
count = buf[0]-128;
|
||||
if ((count == 0)||(count > ptr_end - ptr)) {
|
||||
return false;
|
||||
}
|
||||
while(count-- > 0)
|
||||
*ptr++ = buf[1];
|
||||
}
|
||||
else {
|
||||
/* a non-run */
|
||||
count = buf[0];
|
||||
if ((count == 0)||(count > ptr_end - ptr)) {
|
||||
return false;
|
||||
}
|
||||
*ptr++ = buf[1];
|
||||
if (--count > 0) {
|
||||
if (fp->readRawData((char*)ptr,sizeof(*ptr)*count) < 1) {
|
||||
return false;
|
||||
}
|
||||
ptr += count;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/* now convert data from buffer into floats */
|
||||
for(i=0;i<scanline_width;i++) {
|
||||
rgbe[0] = scanline_buffer[i];
|
||||
rgbe[1] = scanline_buffer[i+scanline_width];
|
||||
rgbe[2] = scanline_buffer[i+2*scanline_width];
|
||||
rgbe[3] = scanline_buffer[i+3*scanline_width];
|
||||
rgbe2float(&data[RGBE_DATA_RED],&data[RGBE_DATA_GREEN],
|
||||
&data[RGBE_DATA_BLUE],rgbe);
|
||||
data += RGBE_DATA_SIZE;
|
||||
}
|
||||
num_scanlines--;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
26
core/hdr_p.h
@@ -1,26 +0,0 @@
|
||||
/*
|
||||
QGL HDR
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef HDR_P_H
|
||||
#define HDR_P_H
|
||||
|
||||
#include <QDataStream>
|
||||
|
||||
bool RGBE_ReadPixels_RLE(QDataStream * fp, float * data, int scanline_width, int num_scanlines);
|
||||
|
||||
#endif // HDR_P_H
|
||||
@@ -1,27 +0,0 @@
|
||||
/*
|
||||
QGL Loader Assimp
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef LOADER_ASSIMP_H
|
||||
#define LOADER_ASSIMP_H
|
||||
|
||||
#include "gltypes.h"
|
||||
|
||||
Scene * loadScene(const QString & filepath);
|
||||
QStringList supportedFormats();
|
||||
|
||||
#endif // LOADER_ASSIMP_H
|
||||
@@ -1,28 +0,0 @@
|
||||
/*
|
||||
QGL Loader QGL
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef LOADER_QGL_H
|
||||
#define LOADER_QGL_H
|
||||
|
||||
#include "gltypes.h"
|
||||
#include <QFileInfo>
|
||||
|
||||
Scene * loadFromQGLFile(const QString & filepath);
|
||||
bool saveToQGLFile(const QString & filepath, const Scene * scene);
|
||||
|
||||
#endif // LOADER_QGL_H
|
||||
91
glcamera.cpp
@@ -1,91 +0,0 @@
|
||||
/*
|
||||
QGL Camera
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "gltypes.h"
|
||||
#include "qglview.h"
|
||||
|
||||
|
||||
Camera::Camera() {
|
||||
type_ = glCamera;
|
||||
fov_ = 60.;
|
||||
roll_ = 0.;
|
||||
depth_start = 0.1f;
|
||||
mirror_x = mirror_y = false;
|
||||
}
|
||||
|
||||
|
||||
QMatrix4x4 Camera::offsetMatrix() const {
|
||||
QMatrix4x4 ret;
|
||||
ret.translate(parent_ ? -offset_ : -aim());
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
void Camera::assign(const Camera & c) {
|
||||
trans = c.trans;
|
||||
aim_dist = c.aim_dist;
|
||||
fov_ = c.fov_;
|
||||
mirror_x = c.mirror_x;
|
||||
mirror_y = c.mirror_y;
|
||||
depth_start = c.depth_start;
|
||||
buildTransform();
|
||||
}
|
||||
|
||||
|
||||
ObjectBase * Camera::clone(bool withChildren) {
|
||||
Camera * o = new Camera(*this);
|
||||
o->is_init = false;
|
||||
o->name_ = name_;
|
||||
o->scene_ = nullptr;
|
||||
o->children_.clear();
|
||||
if (withChildren) {
|
||||
for (int i = 0; i < children_.size(); ++i)
|
||||
o->addChild(children_[i]->clone(withChildren));
|
||||
}
|
||||
o->trans = trans;
|
||||
o->aim_dist = aim_dist;
|
||||
o->fov_ = fov_;
|
||||
o->roll_ = roll_;
|
||||
o->mirror_x = mirror_x;
|
||||
o->mirror_y = mirror_y;
|
||||
o->depth_start = depth_start;
|
||||
o->meta = meta;
|
||||
return o;
|
||||
}
|
||||
|
||||
|
||||
QMatrix4x4 Camera::viewMatrix() const {
|
||||
QMatrix4x4 ret;
|
||||
//qDebug() << pos() << aim();
|
||||
ret.translate(0., 0., -distance());
|
||||
ret.rotate(-roll_, 0., 0., 1.);
|
||||
ret *= trans.matrixRotateScale().inverted();
|
||||
if (parent_) {
|
||||
QMatrix4x4 pmat = parent_->worldTransform();
|
||||
offset_ = pmat.column(3).toVector3D();
|
||||
pmat(0, 3) = pmat(1, 3) = pmat(2, 3) = 0.;
|
||||
pmat.translate(aim());
|
||||
ret *= pmat.inverted();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
QMatrix4x4 Camera::projectionMatrix(double aspect) const {
|
||||
return glMatrixPerspective(fov_, aspect, depth_start);
|
||||
}
|
||||
65
glcamera.h
@@ -1,65 +0,0 @@
|
||||
/*
|
||||
QGL Camera
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef GLCAMERA_H
|
||||
#define GLCAMERA_H
|
||||
|
||||
#include "globject.h"
|
||||
|
||||
|
||||
class Camera: public AimedObject
|
||||
{
|
||||
friend QDataStream & operator <<(QDataStream & s, const ObjectBase * p);
|
||||
friend QDataStream & operator >>(QDataStream & s, ObjectBase *& p);
|
||||
public:
|
||||
Camera();
|
||||
|
||||
void setFOV(const float & f) {fov_ = f;}
|
||||
void setAngles(const QVector3D & a) {setRotation(a);}
|
||||
void setAngleZ(const float & a) {setRotationZ(a);}
|
||||
void setAngleXY(const float & a) {setRotationX(a);}
|
||||
void setAngleRoll(const float & a) {roll_ = a;}
|
||||
void setDepthStart(const float & d) {depth_start = d;}
|
||||
void setMirrorX(bool yes) {mirror_x = yes;}
|
||||
void setMirrorY(bool yes) {mirror_y = yes;}
|
||||
|
||||
float FOV() const {return fov_;}
|
||||
float angleZ() const {return rotationZ();}
|
||||
float angleXY() const {return rotationX();}
|
||||
float angleRoll() const {return roll_;}
|
||||
float depthStart() const {return depth_start;}
|
||||
bool isMirrorX() const {return mirror_x;}
|
||||
bool isMirrorY() const {return mirror_y;}
|
||||
void assign(const Camera & c);
|
||||
|
||||
virtual ObjectBase * clone(bool withChildren = true);
|
||||
QMatrix4x4 viewMatrix() const;
|
||||
QMatrix4x4 projectionMatrix(double aspect) const;
|
||||
QMatrix4x4 offsetMatrix() const;
|
||||
|
||||
QMatrix4x4 fullViewMatrix() const {return viewMatrix() * offsetMatrix();}
|
||||
|
||||
private:
|
||||
mutable QVector3D offset_;
|
||||
GLfloat fov_, roll_;
|
||||
GLfloat depth_start;
|
||||
bool mirror_x;
|
||||
bool mirror_y;
|
||||
};
|
||||
|
||||
#endif // GLCAMERA_H
|
||||
717
globject.cpp
@@ -1,717 +0,0 @@
|
||||
/*
|
||||
QGL ObjectBase & Light
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "globject.h"
|
||||
#include "glcamera.h"
|
||||
#include "glscene.h"
|
||||
#include "glmesh.h"
|
||||
#include <chunkstream.h>
|
||||
//static int _count = 0;
|
||||
|
||||
ObjectBase::ObjectBase(Mesh * geom, Material * mat) {
|
||||
type_ = glMesh;
|
||||
render_mode = View;
|
||||
prev_pass = rpSolid;
|
||||
parent_ = nullptr;
|
||||
color_ = Qt::white;
|
||||
is_root = is_init = selected_ = false;
|
||||
visible_ = accept_fog = accept_light = cast_shadow = rec_shadow = select_ = true;
|
||||
line_width = -1.;
|
||||
id_ = 0;
|
||||
blend_src = GL_SRC_ALPHA;
|
||||
blend_dest = GL_ONE_MINUS_SRC_ALPHA;
|
||||
type_ = glMesh;
|
||||
raw_matrix = selected_aim = false;
|
||||
mat_.setToIdentity();
|
||||
scene_ = nullptr;
|
||||
mesh_ = geom;
|
||||
material_ = mat;
|
||||
//qDebug() << "ObjectBase, now" << ++_count;
|
||||
}
|
||||
|
||||
|
||||
ObjectBase::~ObjectBase() {
|
||||
//qDebug() << "~ObjectBase, now" << --_count;
|
||||
if (parent_) parent_->children_.removeAll(this);
|
||||
if (scene_) {
|
||||
scene_->__objectDeleted(this);
|
||||
scene_->setTreeChanged();
|
||||
scene_->setTreeStructChanged();
|
||||
}
|
||||
foreach (ObjectBase * c, children_) {
|
||||
c->parent_ = nullptr;
|
||||
delete c;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
ObjectBase * ObjectBase::clone(bool withChildren) {
|
||||
ObjectBase * o = new ObjectBase();
|
||||
o->prev_pass = prev_pass;
|
||||
o->is_init = false;
|
||||
o->accept_light = accept_light;
|
||||
o->accept_fog = accept_fog;
|
||||
o->visible_ = visible_;
|
||||
o->color_ = color_;
|
||||
o->type_ = type_;
|
||||
o->raw_matrix = raw_matrix;
|
||||
o->mat_ = mat_;
|
||||
o->trans = trans;
|
||||
o->itransform_ = itransform_;
|
||||
o->bound = bound;
|
||||
o->name_ = name_;// + "_copy";
|
||||
o->blend_src = blend_src;
|
||||
o->blend_dest = blend_dest;
|
||||
o->pos_h = pos_h;
|
||||
o->material_ = material_;
|
||||
o->mesh_ = mesh_;
|
||||
o->meta = meta;
|
||||
o->scene_ = nullptr;
|
||||
if (withChildren) {
|
||||
for (int i = 0; i < children_.size(); ++i)
|
||||
o->addChild(children_[i]->clone(withChildren));
|
||||
}
|
||||
return o;
|
||||
}
|
||||
|
||||
|
||||
void ObjectBase::destroy() {
|
||||
if (mesh_) delete mesh_;
|
||||
}
|
||||
|
||||
|
||||
void ObjectBase::init() {
|
||||
calculateBoundingBox();
|
||||
//material_.reflection.create();
|
||||
//qDebug() << "init" << vbo.buffer_;
|
||||
is_init = true;
|
||||
}
|
||||
|
||||
|
||||
RenderPass ObjectBase::pass() const {
|
||||
RenderPass ret = rpSolid;
|
||||
if (material_)
|
||||
if (material_->hasTransparency())
|
||||
ret = rpTransparent;
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
void ObjectBase::setScene(Scene * v) {
|
||||
scene_ = v;
|
||||
foreach (ObjectBase * c, children_)
|
||||
c->setScene(v);
|
||||
}
|
||||
|
||||
|
||||
void ObjectBase::addChild(ObjectBase * o) {
|
||||
if (o == this) return;
|
||||
if (o->parent_)
|
||||
o->parent_->children_.removeAll(o);
|
||||
children_ << o;
|
||||
o->parent_ = this;
|
||||
o->setScene(scene_);
|
||||
o->buildTransform();
|
||||
/*if (scene_) {
|
||||
ObjectBaseList cl = o->children(true);
|
||||
cl << o;
|
||||
//foreach (ObjectBase * i, cl) {
|
||||
// emit view_->objectAdded(i);
|
||||
//}
|
||||
}*/
|
||||
setSceneTreeChanged();
|
||||
}
|
||||
|
||||
|
||||
void ObjectBase::removeChild(ObjectBase * o) {
|
||||
if (o == this) return;
|
||||
children_.removeAll(o);
|
||||
o->parent_ = nullptr;
|
||||
o->buildTransform();
|
||||
setSceneTreeChanged();
|
||||
}
|
||||
|
||||
|
||||
void ObjectBase::removeChild(int index) {
|
||||
children_[index]->parent_ = nullptr;
|
||||
children_[index]->buildTransform();
|
||||
children_.removeAt(index);
|
||||
setSceneTreeChanged();
|
||||
}
|
||||
|
||||
|
||||
void ObjectBase::clearChildren(bool deleteAll) {
|
||||
foreach (ObjectBase * i, children_) {
|
||||
i->scene_ = nullptr;
|
||||
i->parent_ = nullptr;
|
||||
i->clearChildren(deleteAll);
|
||||
if (deleteAll) {
|
||||
delete i;
|
||||
} else {
|
||||
i->buildTransform();
|
||||
}
|
||||
}
|
||||
children_.clear();
|
||||
setSceneTreeChanged();
|
||||
}
|
||||
|
||||
|
||||
ObjectBase * ObjectBase::child(int index) {
|
||||
if (index < 0 || index >= children_.size()) return nullptr;
|
||||
return children_[index];
|
||||
}
|
||||
|
||||
|
||||
ObjectBase * ObjectBase::child(const QString & name) {
|
||||
foreach (ObjectBase * i, children_)
|
||||
if (i->name_ == name) return i;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
const ObjectBase * ObjectBase::child(int index) const {
|
||||
if (index < 0 || index >= children_.size()) return nullptr;
|
||||
return children_[index];
|
||||
}
|
||||
|
||||
|
||||
const ObjectBase * ObjectBase::child(const QString & name) const {
|
||||
foreach (ObjectBase * i, children_)
|
||||
if (i->name_ == name) return i;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
ObjectBaseList ObjectBase::children(bool all_) {
|
||||
if (!all_) return children_;
|
||||
ObjectBaseList cl;
|
||||
addChildren(cl, this);
|
||||
return cl;
|
||||
}
|
||||
|
||||
|
||||
bool ObjectBase::isVisible(bool check_parents) const {
|
||||
if (!check_parents) return visible_;
|
||||
if (!visible_) return false;
|
||||
ObjectBase * p = parent_;
|
||||
while (p) {
|
||||
if (!p->visible_) return false;
|
||||
p = p->parent_;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void ObjectBase::setVisible(bool v) {
|
||||
visible_ = v;
|
||||
setSceneTreeChanged();
|
||||
}
|
||||
|
||||
|
||||
void ObjectBase::rotateZ(GLfloat a) {
|
||||
raw_matrix = false;
|
||||
trans.setRotationZ(trans.rotationZ() + a);
|
||||
//angles_.setZ(angles_.z() + a);
|
||||
//while (angles_.z() < -360.f) angles_.setZ(angles_.z() + 360.f);
|
||||
//while (angles_.z() > 360.f) angles_.setZ(angles_.z() - 360.f);
|
||||
buildTransform();
|
||||
}
|
||||
|
||||
|
||||
void ObjectBase::setRotationZ(GLfloat a) {
|
||||
raw_matrix = false;
|
||||
trans.setRotationZ(a);
|
||||
//angles_.setZ(a);
|
||||
//while (angles_.z() < -360.f) angles_.setZ(angles_.z() + 360.f);
|
||||
//while (angles_.z() > 360.f) angles_.setZ(angles_.z() - 360.f);
|
||||
buildTransform();
|
||||
}
|
||||
|
||||
|
||||
void ObjectBase::setTransform(const Transform & t) {
|
||||
trans = t;
|
||||
buildTransform();
|
||||
}
|
||||
|
||||
|
||||
void ObjectBase::addChildren(ObjectBaseList & list, ObjectBase * where) {
|
||||
foreach (ObjectBase * i, where->children_) {
|
||||
list << i;
|
||||
addChildren(list, i);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ObjectBase::calculateBoundingBox() {
|
||||
bound = Box3D();
|
||||
if (mesh_) {
|
||||
bound = mesh_->boundingBox();
|
||||
QVector<QVector3D> c = bound.corners(), tc;
|
||||
foreach (QVector3D p, c)
|
||||
tc << (itransform_ * QVector4D(p, 1)).toVector3D();
|
||||
bound = Box3D(tc);
|
||||
}
|
||||
foreach (ObjectBase * i, children_) {
|
||||
i->calculateBoundingBox();
|
||||
bound |= i->boundingBox();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ObjectBase::updateTransform() {
|
||||
buildTransform(true);
|
||||
}
|
||||
|
||||
|
||||
void ObjectBase::setProperty(const QString & pn, const QVariant & v) {
|
||||
meta[pn] = v;
|
||||
}
|
||||
|
||||
|
||||
QVariant ObjectBase::property(const QString & pn, bool * exists) const {
|
||||
if (exists) *exists = meta.contains(pn);
|
||||
return meta.value(pn);
|
||||
}
|
||||
|
||||
|
||||
bool ObjectBase::hasProperty(const QString & pn) const {
|
||||
return meta.contains(pn);
|
||||
}
|
||||
|
||||
|
||||
void ObjectBase::removeProperty(const QString & pn) {
|
||||
meta.remove(pn);
|
||||
}
|
||||
|
||||
|
||||
void ObjectBase::setMatrix(const QMatrix4x4 & t) {
|
||||
//raw_matrix = true;
|
||||
//mat_ = t;
|
||||
//pos_ = mat_.column(3).toVector3D();
|
||||
//mat_.setColumn(3, QVector4D(0., 0., 0., 1.));
|
||||
raw_matrix = false;
|
||||
trans.setMatrix(t);
|
||||
buildTransform();
|
||||
}
|
||||
|
||||
|
||||
QMatrix4x4 ObjectBase::matrix() const {
|
||||
return trans.matrix();
|
||||
}
|
||||
|
||||
|
||||
QVector3D ObjectBase::inParentSpace(const QVector3D & v) const {
|
||||
if (!parent_) return v;
|
||||
return (parent_->matrix() * QVector4D(v, 1)).toVector3D();
|
||||
}
|
||||
|
||||
|
||||
void ObjectBase::transferTransformToChildren(bool only_scale) {
|
||||
QMatrix4x4 m = trans.matrix();
|
||||
if (only_scale) m = trans.matrixScale();
|
||||
foreach (ObjectBase * i, children_)
|
||||
i->trans.setMatrix(m * i->trans.matrix());
|
||||
if (only_scale) resetScale();
|
||||
else setMatrix(QMatrix4x4());
|
||||
}
|
||||
|
||||
|
||||
void ObjectBase::cleanTree() {
|
||||
for (int i = 0; i < children_.size(); ++i) {
|
||||
ObjectBase * o = children_[i];
|
||||
if (!o->hasChildren() && !o->mesh() && (o->type() == glMesh)) {
|
||||
delete o;
|
||||
--i;
|
||||
}
|
||||
o->cleanTree();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool ObjectBase::isSelected(bool check_parents) const {
|
||||
if (!check_parents) return selected_;
|
||||
if (selected_) return true;
|
||||
ObjectBase * p = parent_;
|
||||
while (p) {
|
||||
if (p->selected_) return true;
|
||||
p = p->parent_;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void ObjectBase::setSelected(bool yes) {
|
||||
//qDebug() << "select" << name() << view_;
|
||||
if (select_)
|
||||
selected_ = yes;
|
||||
if (!selected_)
|
||||
selected_aim = false;
|
||||
}
|
||||
|
||||
|
||||
ObjectBase * ObjectBase::selectedParent() const {
|
||||
ObjectBase * p = parent_;
|
||||
while (p) {
|
||||
if (p->selected_) return p;
|
||||
p = p->parent_;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void ObjectBase::setMaterial(Material * m, bool with_children) {
|
||||
material_ = m;
|
||||
if (with_children)
|
||||
foreach (ObjectBase * i, children_) i->setMaterial(m, true);
|
||||
setObjectsChanged();
|
||||
if (scene_) scene_->mat_changed = scene_->tree_changed = true;
|
||||
}
|
||||
|
||||
|
||||
void ObjectBase::setColor(QColor c, bool with_children) {
|
||||
color_ = c;
|
||||
if (with_children)
|
||||
foreach (ObjectBase * i, children_) i->setColor(c, true);
|
||||
setObjectsChanged();
|
||||
}
|
||||
|
||||
|
||||
void ObjectBase::setMesh(Mesh * v) {
|
||||
if (scene_)
|
||||
v = scene_->attachMesh(v);
|
||||
mesh_ = v;
|
||||
setSceneTreeChanged();
|
||||
setObjectsChanged();
|
||||
}
|
||||
|
||||
|
||||
void ObjectBase::buildTransform(bool force) {
|
||||
if (force) trans.setDirty();
|
||||
itransform_.setToIdentity();
|
||||
ObjectBase * p = parent_;
|
||||
if (p)
|
||||
itransform_ = p->itransform_;
|
||||
//if (raw_matrix) {
|
||||
// itransform_.translate(pos_);
|
||||
// itransform_ *= mat_;
|
||||
// //qDebug() << "raw_matrix" << itransform_;
|
||||
//} else
|
||||
localTransform(itransform_);
|
||||
//qDebug() << name_ << itransform_;
|
||||
foreach (ObjectBase * i, children_)
|
||||
i->buildTransform(force);
|
||||
setObjectsChanged();
|
||||
}
|
||||
|
||||
|
||||
void ObjectBase::initInternal() {
|
||||
init();
|
||||
foreach (ObjectBase * i, children_) i->initInternal();
|
||||
}
|
||||
|
||||
|
||||
void ObjectBase::localTransform(QMatrix4x4 & m) {
|
||||
m *= trans.matrix();
|
||||
}
|
||||
|
||||
|
||||
void ObjectBase::setSceneTreeChanged() {
|
||||
if (scene_) {
|
||||
scene_->setTreeChanged();
|
||||
scene_->setTreeStructChanged();
|
||||
}
|
||||
setObjectsChanged();
|
||||
}
|
||||
|
||||
|
||||
void ObjectBase::setObjectsChanged() {
|
||||
int p = pass();
|
||||
if (mesh_) {
|
||||
mesh_->setObjectsChanged (p, true);
|
||||
mesh_->setSelectionChanged(p, true);
|
||||
if (prev_pass != p) {
|
||||
mesh_->setObjectsChanged (prev_pass, true);
|
||||
mesh_->setSelectionChanged(prev_pass, true);
|
||||
}
|
||||
}
|
||||
prev_pass = p;
|
||||
}
|
||||
|
||||
|
||||
QMatrix4x4 ObjectBase::worldMatrix(QMatrix4x4 parent) const {
|
||||
QMatrix4x4 mat;
|
||||
//mat.translate(pos_);
|
||||
//if (raw_matrix) {
|
||||
// mat *= mat_;
|
||||
//} else {
|
||||
// if (angles_.z() != 0.f) mat.rotate(angles_.z(), 0., 0., 1.);
|
||||
// if (angles_.y() != 0.f) mat.rotate(angles_.y(), 0., 1., 0.);
|
||||
// if (angles_.x() != 0.f) mat.rotate(angles_.x(), 1., 0., 0.);
|
||||
// mat.scale(scale_);
|
||||
//}
|
||||
mat = trans.matrix();
|
||||
return parent * mat;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
AimedObject::AimedObject() {
|
||||
aim_dist = 1.;
|
||||
}
|
||||
|
||||
|
||||
QVector3D AimedObject::worldAim() const {
|
||||
QVector3D ret = worldPos() + worldDirection() * aim_dist;
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
void AimedObject::setAim(const QVector3D & p) {
|
||||
QVector3D dir = p - pos();
|
||||
trans.setRotation(Transform::fromDirection(dir, trans.rotationY()));
|
||||
aim_dist = dir.length();
|
||||
buildTransform();
|
||||
//if (!p.isNull())
|
||||
//qDebug() << "setAim" << p << aim() << worldAim();
|
||||
}
|
||||
|
||||
|
||||
QVector3D AimedObject::direction() const {
|
||||
return trans.direction();
|
||||
}
|
||||
|
||||
|
||||
void AimedObject::setDirection(const QVector3D & d) {
|
||||
//double len = qMax(aim_.length(), 0.001f);
|
||||
//aim_ = d.normalized() * len;
|
||||
buildTransform();
|
||||
}
|
||||
|
||||
|
||||
void AimedObject::flyCloser(double s) {
|
||||
double tl = 1. / (1. + s);
|
||||
move(direction() * aim_dist * (1. - tl));
|
||||
aim_dist *= tl;
|
||||
}
|
||||
|
||||
|
||||
void AimedObject::flyFarer(double s) {
|
||||
double tl = 1. * (1. + s);
|
||||
move(direction() * aim_dist * (1. - tl));
|
||||
aim_dist *= tl;
|
||||
}
|
||||
|
||||
|
||||
void AimedObject::flyToDistance(double d) {
|
||||
move(direction() * (aim_dist - d));
|
||||
aim_dist = d;
|
||||
//qDebug() << d << (aim() - pos()).length() << aim();
|
||||
}
|
||||
|
||||
|
||||
void AimedObject::moveForward(const float & x, bool withZ) {
|
||||
QVector3D dv = itransform_.mapVector(QVector3D(0, 0, -x));
|
||||
if (!withZ) dv[2] = 0.;
|
||||
move(dv);
|
||||
}
|
||||
|
||||
|
||||
void AimedObject::moveLeft(const float & x, bool withZ) {
|
||||
QVector3D dv = itransform_.mapVector(QVector3D(-x, 0, 0));
|
||||
if (!withZ) dv[2] = 0.;
|
||||
move(dv);
|
||||
}
|
||||
|
||||
|
||||
void AimedObject::moveUp(const float & x, bool onlyZ) {
|
||||
QVector3D dv = itransform_.mapVector(QVector3D(0, x, 0));
|
||||
if (onlyZ) dv[0] = dv[1] = 0.;
|
||||
move(dv);
|
||||
}
|
||||
|
||||
|
||||
void AimedObject::orbitZ(const float & a) {
|
||||
QVector3D pa = aim();
|
||||
rotateZ(-a);
|
||||
move(pa - aim());
|
||||
}
|
||||
|
||||
|
||||
void AimedObject::orbitXY(const float & a) {
|
||||
QVector3D pa = aim();
|
||||
rotateX(-a);
|
||||
move(pa - aim());
|
||||
}
|
||||
|
||||
|
||||
void AimedObject::transformChanged() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Light::Light(): AimedObject(), shadow_map(0, true, GL_R16F) {
|
||||
type_ = glLight;
|
||||
light_type = Omni;
|
||||
intensity = 1.;
|
||||
angle_start = angle_end = 180.;
|
||||
decay_linear = decay_quadratic = decay_start = 0.;
|
||||
decay_const = decay_end = 1.;
|
||||
setDirection(0, 0, -1.);
|
||||
}
|
||||
|
||||
|
||||
Light::Light(const QVector3D & p, const QColor & c, float i): AimedObject(), shadow_map(0, true, GL_R16F) {
|
||||
type_ = glLight;
|
||||
light_type = Omni;
|
||||
intensity = i;
|
||||
color_ = c;
|
||||
angle_start = angle_end = 180.;
|
||||
decay_linear = decay_quadratic = decay_start = 0.;
|
||||
decay_const = decay_end = 1.;
|
||||
setPos(p);
|
||||
setDirection(0, 0, -1.);
|
||||
}
|
||||
|
||||
|
||||
ObjectBase * Light::clone(bool withChildren) {
|
||||
Light * o = new Light(*this);
|
||||
//GLObjectBase::clone(withChildren);
|
||||
o->is_init = false;
|
||||
o->name_ = name_;// + "_copy";
|
||||
o->scene_ = nullptr;
|
||||
o->children_.clear();
|
||||
if (withChildren) {
|
||||
for (int i = 0; i < children_.size(); ++i)
|
||||
o->addChild(children_[i]->clone(withChildren));
|
||||
}
|
||||
o->color_ = color_;
|
||||
o->light_type = light_type;
|
||||
o->trans = trans;
|
||||
o->aim_dist = aim_dist;
|
||||
o->angle_start = angle_start;
|
||||
o->angle_end = angle_end;
|
||||
o->intensity = intensity;
|
||||
o->decay_const = decay_const;
|
||||
o->decay_linear = decay_linear;
|
||||
o->decay_quadratic = decay_quadratic;
|
||||
o->meta = meta;
|
||||
return o;
|
||||
}
|
||||
|
||||
|
||||
void Light::apply() {
|
||||
if (scene_) scene_->setLightsChanged();
|
||||
}
|
||||
|
||||
|
||||
QDataStream & operator <<(QDataStream & s, const ObjectBase * p) {
|
||||
ChunkStream cs;
|
||||
//qDebug() << "place" << p->name() << "...";
|
||||
cs.add(1, int(p->type_)).add(2, p->accept_light).add(3, p->accept_fog).add(4, p->visible_)
|
||||
.add(5, p->cast_shadow).add(6, p->rec_shadow).add(7, p->raw_matrix).add(8, p->line_width)
|
||||
.add(9, int(p->render_mode)).add(14, p->mat_).add(16, p->children_.size())
|
||||
.add(17, p->name_).add(18, p->meta).add(19, p->color_).add(20, p->trans);
|
||||
//qDebug() << "place self done";
|
||||
if (p->type_ == ObjectBase::glLight) {
|
||||
//qDebug() << "place light ...";
|
||||
const Light * l = (const Light*)p;
|
||||
cs.add(101, l->angle_start).add(102, l->angle_end).add(103, l->intensity)
|
||||
.add(104, l->decay_const).add(105, l->decay_linear).add(106, l->decay_quadratic)
|
||||
.add(107, l->decay_start).add(108, l->decay_end).add(109, int(l->light_type))
|
||||
.add(111, l->distance());
|
||||
}
|
||||
if (p->type_ == ObjectBase::glCamera) {
|
||||
//qDebug() << "place camera ...";
|
||||
const Camera * c = (const Camera*)p;
|
||||
cs.add(200, c->aim()).add(201, c->fov_).add(202, c->depth_start)
|
||||
.add(206, c->mirror_x).add(207, c->mirror_y).add(208, c->distance())
|
||||
.add(209, c->roll_);
|
||||
}
|
||||
//qDebug() << "place" << p->name() << cs.data().size() << s.device()->size();
|
||||
s << cs.data();
|
||||
foreach (const ObjectBase * c, p->children_)
|
||||
s << c;
|
||||
return s;
|
||||
}
|
||||
QDataStream & operator >>(QDataStream & s, ObjectBase *& p) {
|
||||
ChunkStream cs(s);
|
||||
p = nullptr;
|
||||
int ccnt = 0;
|
||||
Light * l = nullptr;
|
||||
Camera * c = nullptr;
|
||||
//qDebug() << "read obj ...";
|
||||
while (!cs.atEnd()) {
|
||||
switch (cs.read()) {
|
||||
case 1: {
|
||||
ObjectBase::Type type = (ObjectBase::Type)cs.getData<int>();
|
||||
switch (type) {
|
||||
case ObjectBase::glMesh: p = new ObjectBase(); break;
|
||||
case ObjectBase::glLight: p = new Light(); l = (Light*)p; break;
|
||||
case ObjectBase::glCamera: p = new Camera(); c = (Camera*)p; break;
|
||||
default : break;
|
||||
}
|
||||
if (p) p->type_ = type;
|
||||
} break;
|
||||
case 2: if (p) p->accept_light = cs.getData<bool>(); break;
|
||||
case 3: if (p) p->accept_fog = cs.getData<bool>(); break;
|
||||
case 4: if (p) p->visible_ = cs.getData<bool>(); break;
|
||||
case 5: if (p) p->cast_shadow = cs.getData<bool>(); break;
|
||||
case 6: if (p) p->rec_shadow = cs.getData<bool>(); break;
|
||||
case 7: if (p) p->raw_matrix = cs.getData<bool>(); break;
|
||||
case 8: if (p) p->line_width = cs.getData<float>(); break;
|
||||
case 9: if (p) p->render_mode = (ObjectBase::RenderMode)cs.getData<int>(); break;
|
||||
case 14: if (p) p->mat_ = cs.getData<QMatrix4x4>(); break;
|
||||
case 16: if (p) ccnt = cs.getData<int>(); break;
|
||||
case 17: if (p) p->name_ = cs.getData<QString>(); break;
|
||||
case 18: if (p) p->meta = cs.getData<QVariantMap>(); break;
|
||||
case 19: if (p) p->color_ = cs.getData<QColor>(); break;
|
||||
case 20: if (p) p->trans = cs.getData<Transform>(); break;
|
||||
case 100: if (l) l->setAim(cs.getData<QVector3D>()); break;
|
||||
case 101: if (l) l->angle_start = cs.getData<GLfloat>(); break;
|
||||
case 102: if (l) l->angle_end = cs.getData<GLfloat>(); break;
|
||||
case 103: if (l) l->intensity = cs.getData<GLfloat>(); break;
|
||||
case 104: if (l) l->decay_const = cs.getData<GLfloat>(); break;
|
||||
case 105: if (l) l->decay_linear = cs.getData<GLfloat>(); break;
|
||||
case 106: if (l) l->decay_quadratic = cs.getData<GLfloat>(); break;
|
||||
case 107: if (l) l->decay_start = cs.getData<GLfloat>(); break;
|
||||
case 108: if (l) l->decay_end = cs.getData<GLfloat>(); break;
|
||||
case 109: if (l) l->light_type = (Light::Type)cs.getData<int>(); break;
|
||||
case 111: if (l) l->setDistance(cs.getData<double>()); break;
|
||||
case 200: if (c) c->setAim(cs.getData<QVector3D>()); break;
|
||||
case 201: if (c) c->setFOV(cs.getData<GLfloat>()); break;
|
||||
case 202: if (c) c->setDepthStart(cs.getData<GLfloat>()); break;
|
||||
case 206: if (c) c->mirror_x = cs.getData<bool>(); break;
|
||||
case 207: if (c) c->mirror_y = cs.getData<bool>(); break;
|
||||
case 208: if (c) c->setDistance(cs.getData<double>()); break;
|
||||
case 209: if (c) c->roll_ = cs.getData<GLfloat>(); break;
|
||||
}
|
||||
}
|
||||
//qDebug() << p->name() << ccnt;
|
||||
for (int i = 0; i < ccnt; ++i) {
|
||||
ObjectBase * c = nullptr;
|
||||
s >> c;
|
||||
if (!c) continue;
|
||||
c->parent_ = p;
|
||||
p->children_ << c;
|
||||
}
|
||||
p->buildTransform();
|
||||
return s;
|
||||
}
|
||||
303
globject.h
@@ -1,303 +0,0 @@
|
||||
/*
|
||||
QGL ObjectBase & Light
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef GLOBJECT_H
|
||||
#define GLOBJECT_H
|
||||
|
||||
#include "glframebuffer.h"
|
||||
#include "glmaterial.h"
|
||||
#include "gltypes.h"
|
||||
#include "gltransform.h"
|
||||
|
||||
|
||||
class ObjectBase
|
||||
{
|
||||
friend class Scene;
|
||||
friend class RendererSelection;
|
||||
friend QDataStream & operator <<(QDataStream & s, const ObjectBase * p);
|
||||
friend QDataStream & operator >>(QDataStream & s, ObjectBase *& p);
|
||||
friend QDataStream & operator >>(QDataStream & s, Scene *& p);
|
||||
public:
|
||||
enum Type {glMesh, glLight, glCamera, glParticlesSystem};
|
||||
enum RenderMode {View = 0, Point = GL_POINT, Line = GL_LINE, Fill = GL_FILL};
|
||||
|
||||
explicit ObjectBase(Mesh * geom = 0, Material * mat = 0);
|
||||
virtual ~ObjectBase();
|
||||
|
||||
virtual ObjectBase * clone(bool withChildren = true);
|
||||
void destroy();
|
||||
|
||||
QString name() const {return name_;}
|
||||
void setName(const QString & name) {name_ = name;}
|
||||
virtual void init();
|
||||
virtual void update() {}
|
||||
bool isInit() const {return is_init;}
|
||||
Type type() const {return type_;}
|
||||
RenderPass pass() const;
|
||||
uint id() const {return id_;}
|
||||
|
||||
RenderMode renderMode() const {return render_mode;}
|
||||
void setRenderMode(RenderMode mode) {render_mode = mode;}
|
||||
|
||||
float lineWidth() const {return line_width;}
|
||||
void setLineWidth(const float & width) {line_width = width;}
|
||||
|
||||
ObjectBase * parent() {return parent_;}
|
||||
void setParent(ObjectBase * o) {parent_ = o;}
|
||||
bool hasParent() const {return parent_ != nullptr;}
|
||||
bool hasChildren() const {return !children_.isEmpty();}
|
||||
void setScene(Scene * v);
|
||||
|
||||
void addChild(ObjectBase * o);
|
||||
void removeChild(ObjectBase * o);
|
||||
void removeChild(int index);
|
||||
void clearChildren(bool deleteAll = false);
|
||||
int childCount() const {return children_.size();}
|
||||
ObjectBase * child(int index);
|
||||
ObjectBase * child(const QString & name);
|
||||
const ObjectBase * child(int index) const;
|
||||
const ObjectBase * child(const QString & name) const;
|
||||
ObjectBaseList children(bool all_ = false);
|
||||
|
||||
bool isVisible(bool check_parents = false) const;
|
||||
bool isHidden(bool check_parents = false) const {return !isVisible(check_parents);}
|
||||
void setVisible(bool v);
|
||||
void setHidden(bool v) {setVisible(!v);}
|
||||
void show() {setVisible(true);}
|
||||
void hide() {setVisible(false);}
|
||||
|
||||
bool isReceiveShadows() const {return rec_shadow;}
|
||||
bool isCastShadows() const {return cast_shadow;}
|
||||
void setReceiveShadows(bool on) {rec_shadow = on;}
|
||||
void setCastShadows(bool on) {cast_shadow = on;}
|
||||
|
||||
void move(const QVector3D & dv) {trans.setTranslation(pos() + dv); buildTransform();}
|
||||
void moveTo(const QVector3D & dv) {trans.setTranslation(dv); buildTransform();}
|
||||
void move(GLfloat dx, GLfloat dy, GLfloat dz = 0.) {move(QVector3D(dx, dy, dz)); buildTransform();}
|
||||
void moveTo(GLfloat dx, GLfloat dy, GLfloat dz = 0.) {moveTo(QVector3D(dx, dy, dz)); buildTransform();}
|
||||
void moveX(GLfloat o) {trans.setTranslationX(posX() + o); buildTransform();}
|
||||
void moveY(GLfloat o) {trans.setTranslationY(posY() + o); buildTransform();}
|
||||
void moveZ(GLfloat o) {trans.setTranslationZ(posZ() + o); buildTransform();}
|
||||
void setPosX(GLfloat o) {trans.setTranslationX(o); buildTransform();}
|
||||
void setPosY(GLfloat o) {trans.setTranslationY(o); buildTransform();}
|
||||
void setPosZ(GLfloat o) {trans.setTranslationZ(o); buildTransform();}
|
||||
void setPos(GLfloat x, GLfloat y, GLfloat z) {trans.setTranslation(QVector3D(x, y, z)); buildTransform();}
|
||||
void setPos(const QVector3D & p) {trans.setTranslation(p); buildTransform();}
|
||||
void resetPos() {trans.setTranslation(QVector3D()); buildTransform();}
|
||||
|
||||
QVector3D pos() const {return trans.translation();}
|
||||
float posX() const {return trans.translation().x();}
|
||||
float posY() const {return trans.translation().y();}
|
||||
float posZ() const {return trans.translation().z();}
|
||||
QVector3D worldPos() const {return (itransform_ * QVector4D(0, 0, 0, 1.)).toVector3D();}
|
||||
QMatrix4x4 worldTransform() const {return itransform_;}
|
||||
|
||||
QVector3D rotation() const {return trans.rotation();}
|
||||
float rotationX() const {return rotation().x();}
|
||||
float rotationY() const {return rotation().y();}
|
||||
float rotationZ() const {return rotation().z();}
|
||||
void rotateX(GLfloat a) {raw_matrix = false; trans.setRotationX(trans.rotationX() + a); buildTransform();}
|
||||
void rotateY(GLfloat a) {raw_matrix = false; trans.setRotationY(trans.rotationY() + a); buildTransform();}
|
||||
void rotateZ(GLfloat a);
|
||||
void setRotationX(GLfloat a) {raw_matrix = false; trans.setRotationX(a); buildTransform();}
|
||||
void setRotationY(GLfloat a) {raw_matrix = false; trans.setRotationY(a); buildTransform();}
|
||||
void setRotationZ(GLfloat a);
|
||||
void setRotation(const QVector3D & a) {raw_matrix = false; trans.setRotation(a); buildTransform();}
|
||||
void resetRotation() {raw_matrix = false; trans.setRotation(QVector3D()); buildTransform();}
|
||||
|
||||
QVector3D scale() {return trans.scale3D();}
|
||||
float scaleX() {return trans.scale3D().x();}
|
||||
float scaleY() {return trans.scale3D().y();}
|
||||
float scaleZ() {return trans.scale3D().z();}
|
||||
void scale(const QVector3D & sv) {raw_matrix = false; trans.setScale(trans.scale3D() * sv); buildTransform();}
|
||||
void scale(GLfloat sx, GLfloat sy, GLfloat sz) {raw_matrix = false; scale(QVector3D(sx, sy, sz)); buildTransform();}
|
||||
void scale(GLfloat sx, GLfloat sy) {raw_matrix = false; scale(QVector3D(sx, sy, sy)); buildTransform();}
|
||||
void scale(GLfloat sx) {raw_matrix = false; scale(QVector3D(sx, sx, sx)); buildTransform();}
|
||||
void scaleX(GLfloat a) {raw_matrix = false; trans.setScaleX(trans.scale3D().x() + a); buildTransform();}
|
||||
void scaleY(GLfloat a) {raw_matrix = false; trans.setScaleY(trans.scale3D().y() + a); buildTransform();}
|
||||
void scaleZ(GLfloat a) {raw_matrix = false; trans.setScaleZ(trans.scale3D().z() + a); buildTransform();}
|
||||
void setScale(const QVector3D & a) {raw_matrix = false; trans.setScale(a); buildTransform();}
|
||||
void setScale(GLfloat a) {raw_matrix = false; trans.setScale(a); buildTransform();}
|
||||
void setScaleX(GLfloat a) {raw_matrix = false; trans.setScaleX(a); buildTransform();}
|
||||
void setScaleY(GLfloat a) {raw_matrix = false; trans.setScaleY(a); buildTransform();}
|
||||
void setScaleZ(GLfloat a) {raw_matrix = false; trans.setScaleZ(a); buildTransform();}
|
||||
void resetScale() {raw_matrix = false; trans.setScale(1.f); buildTransform();}
|
||||
|
||||
Transform transform() {return trans;}
|
||||
void setTransform(const Transform & t);
|
||||
void setMatrix(const QMatrix4x4 & t);
|
||||
QMatrix4x4 matrix() const;
|
||||
bool isRawMatrix() {return raw_matrix;}
|
||||
QVector3D inParentSpace(const QVector3D & v) const;
|
||||
void transferTransformToChildren(bool only_scale = false);
|
||||
void cleanTree();
|
||||
|
||||
bool isAcceptLight() const {return accept_light;}
|
||||
void setAcceptLight(bool yes) {accept_light = yes;}
|
||||
|
||||
bool isAcceptFog() const {return accept_fog;}
|
||||
void setAcceptFog(bool yes) {accept_fog = yes;}
|
||||
|
||||
bool isSelected(bool check_parents = false) const;
|
||||
void setSelected(bool yes);
|
||||
void select() {setSelected(true);}
|
||||
void deselect() {setSelected(false);}
|
||||
ObjectBase * selectedParent() const;
|
||||
void setAimSelected(bool yes) {selected_aim = yes;}
|
||||
bool isAimSelected() const {return selected_aim;}
|
||||
|
||||
bool isSelectable() const {return select_;}
|
||||
void setSelectable(bool yes) {select_ = yes;}
|
||||
|
||||
GLenum srcAlpha() const {return blend_src;}
|
||||
GLenum destAlpha() const {return blend_dest;}
|
||||
void setSrcAlpha(GLenum mode) {blend_src = mode;}
|
||||
void setDestAlpha(GLenum mode) {blend_dest = mode;}
|
||||
|
||||
void setMaterial(Material * m, bool with_children = false);
|
||||
Material * material() {return material_;}
|
||||
|
||||
void setColor(QColor c, bool with_children = false);
|
||||
QColor color() {return color_;}
|
||||
|
||||
const Box3D & boundingBox() const {return bound;}
|
||||
void setMesh(Mesh * v);
|
||||
Mesh * mesh() {return mesh_;}
|
||||
|
||||
void calculateBoundingBox();
|
||||
void updateTransform();
|
||||
|
||||
void setProperty(const QString & pn, const QVariant & v);
|
||||
QVariant property(const QString & pn, bool * exists = 0) const;
|
||||
bool hasProperty(const QString & pn) const;
|
||||
void removeProperty(const QString & pn);
|
||||
|
||||
QVector3D pos_h;
|
||||
|
||||
protected:
|
||||
virtual void transformChanged() {}
|
||||
void addChildren(ObjectBaseList & list, ObjectBase * where);
|
||||
void buildTransform(bool force = false);
|
||||
void initInternal();
|
||||
void setSceneTreeChanged();
|
||||
void setObjectsChanged();
|
||||
void localTransform(QMatrix4x4 & m);
|
||||
QMatrix4x4 worldMatrix(QMatrix4x4 parent) const;
|
||||
|
||||
int prev_pass; // Pass
|
||||
bool is_init, accept_light, accept_fog, visible_, cast_shadow, rec_shadow, select_, selected_, raw_matrix;
|
||||
bool is_root, selected_aim;
|
||||
float line_width;
|
||||
QColor color_;
|
||||
uint id_;
|
||||
Type type_;
|
||||
RenderMode render_mode;
|
||||
Box3D bound;
|
||||
Transform trans;
|
||||
ObjectBaseList children_;
|
||||
QMatrix4x4 itransform_, mat_;
|
||||
QString name_;
|
||||
GLenum blend_src, blend_dest;
|
||||
ObjectBase * parent_;
|
||||
Scene * scene_;
|
||||
Material * material_;
|
||||
Mesh * mesh_;
|
||||
QVariantMap meta;
|
||||
};
|
||||
|
||||
inline bool operator <(const ObjectBase & f, const ObjectBase & s) {return f.pos_h.z() < s.pos_h.z();}
|
||||
|
||||
|
||||
class AimedObject: public ObjectBase {
|
||||
friend class QGLView;
|
||||
friend class GLRendererBase;
|
||||
friend class Light;
|
||||
friend class Camera;
|
||||
public:
|
||||
AimedObject();
|
||||
~AimedObject() {}
|
||||
QVector3D aim() const {return pos() + (direction() * aim_dist);}
|
||||
QVector3D worldAim() const;
|
||||
void setAim(const QVector3D & p);
|
||||
QVector3D direction() const;
|
||||
QVector3D worldDirection() const {return (itransform_ * QVector4D(QVector3D(0,0,-1), 0.)).toVector3D().normalized();}
|
||||
void setDirection(const QVector3D & d);
|
||||
void setDirection(double x, double y, double z) {setDirection(QVector3D(x, y, z));}
|
||||
|
||||
double distance() const {return aim_dist;}
|
||||
void setDistance(double d) {aim_dist = d;}
|
||||
void flyCloser(double s);
|
||||
void flyFarer(double s);
|
||||
void flyToDistance(double d);
|
||||
|
||||
void moveForward(const float & x, bool withZ = true);
|
||||
void moveBackward(const float & x, bool withZ = true) {moveForward(-x, withZ);}
|
||||
void moveLeft(const float & x, bool withZ = true);
|
||||
void moveRight(const float & x, bool withZ = true) {moveLeft(-x, withZ);}
|
||||
void moveUp(const float & x, bool onlyZ = false);
|
||||
void moveDown(const float & x, bool onlyZ = false) {moveUp(-x, onlyZ);}
|
||||
|
||||
void rotateRoll(const float & a) {rotateY(a);}
|
||||
void orbitZ(const float & a);
|
||||
void orbitXY(const float & a);
|
||||
|
||||
protected:
|
||||
void transformChanged() override;
|
||||
double aim_dist;
|
||||
};
|
||||
|
||||
|
||||
class Light: public AimedObject {
|
||||
friend class QGLView;
|
||||
friend class RendererBase;
|
||||
public:
|
||||
enum Type {Omni, Cone, Directional};
|
||||
|
||||
Light();
|
||||
Light(const QVector3D & p, const QColor & c = Qt::white, float i = 1.);
|
||||
virtual ObjectBase * clone(bool withChildren = true);
|
||||
virtual void init() {shadow_map.resize(512, 512); is_init = true;}
|
||||
void apply();
|
||||
|
||||
float angle_start;
|
||||
float angle_end;
|
||||
float intensity;
|
||||
float decay_const;
|
||||
float decay_linear;
|
||||
float decay_quadratic;
|
||||
float decay_start;
|
||||
float decay_end;
|
||||
Type light_type;
|
||||
Framebuffer shadow_map;
|
||||
QMatrix4x4 shadow_matrix;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
inline T globject_cast(ObjectBase * object) {return reinterpret_cast<T>(object);}
|
||||
|
||||
template <class T>
|
||||
inline T globject_cast(const ObjectBase * object) {return reinterpret_cast<T>(object);}
|
||||
|
||||
|
||||
QDataStream & operator <<(QDataStream & s, const ObjectBase * p);
|
||||
QDataStream & operator >>(QDataStream & s, ObjectBase *& p);
|
||||
|
||||
inline ObjectBaseList lights2objectList(const QList<Light*> & v) {ObjectBaseList ret; foreach (Light*i, v) ret << (ObjectBase*)i; return ret;}
|
||||
inline ObjectBaseList cameras2objectList(const QList<Camera*> & v) {ObjectBaseList ret; foreach (Camera*i, v) ret << (ObjectBase*)i; return ret;}
|
||||
|
||||
#endif // GLOBJECT_H
|
||||
@@ -1,201 +0,0 @@
|
||||
/*
|
||||
QGL TextureManager
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "gltexture_manager.h"
|
||||
#include "gltypes.h"
|
||||
|
||||
QStringList TextureManager::search_pathes(".");
|
||||
|
||||
|
||||
QVector3D colorVector(QRgb c) {
|
||||
return QVector3D(((uchar*)(&c))[0] / 255.f, ((uchar*)(&c))[1] / 255.f, ((uchar*)(&c))[2] / 255.f);
|
||||
}
|
||||
|
||||
|
||||
QString TextureManager::findFile(const QString & path) {
|
||||
return ::findFile(path, search_pathes);
|
||||
}
|
||||
|
||||
|
||||
GLuint TextureManager::loadTexture(const QString & path, bool ownership, bool bump) {
|
||||
QString p = findFile(path);
|
||||
if (p.isEmpty()) return 0;
|
||||
int tid = textureID(p, bump);
|
||||
if (tid > 0) {
|
||||
//qDebug() << "[TextureManager] Found" << path << "as" << tid;
|
||||
return tid;
|
||||
}
|
||||
QImage image(p);
|
||||
if (bump) convertToNormal(image);
|
||||
//qDebug() << p << image.width() << image.height() << image.format() << bump;
|
||||
GLuint tid_ = tid;
|
||||
createGLTexture(f, tid_, image);
|
||||
tid = tid_;
|
||||
if (tid == 0) {
|
||||
qDebug() << "[TextureManager] Can`t load" << p;
|
||||
return tid;
|
||||
}
|
||||
qDebug() << "[TextureManager] Loaded" << p << "as" << tid;
|
||||
if (ownership) {
|
||||
tex_ids[bump ? 1 : 0].insert(p, tid);
|
||||
tex_im [bump ? 1 : 0].insert(p, image);
|
||||
}
|
||||
return tid;
|
||||
}
|
||||
|
||||
|
||||
GLuint TextureManager::loadTexture(const QImage & im, bool ownership, bool bump) {
|
||||
if (im.isNull()) return 0;
|
||||
QImage image(im);
|
||||
if (bump) convertToNormal(image);
|
||||
GLuint tid = 0;
|
||||
createGLTexture(f, tid, im);
|
||||
if (tid == 0) {
|
||||
qDebug() << "[TextureManager] Can`t load image";
|
||||
return tid;
|
||||
}
|
||||
//qDebug() << "[TextureManager] Loaded image as" << tid;
|
||||
return tid;
|
||||
}
|
||||
|
||||
|
||||
QImage TextureManager::loadTextureImage(const QString & path, bool bump) {
|
||||
QString p = findFile(path);
|
||||
if (p.isEmpty()) return QImage();
|
||||
QImage ret = tex_im[bump ? 1 : 0].value(p);
|
||||
if (!ret.isNull()) return ret;
|
||||
ret = QImage(p);
|
||||
if (bump) convertToNormal(ret);
|
||||
tex_im[bump ? 1 : 0].insert(p, ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
void TextureManager::reloadTexture(GLuint tid, const QString & path) {
|
||||
QString p = findFile(path);
|
||||
if (p.isEmpty() || (tid == 0)) return;
|
||||
QImage image(p);
|
||||
createGLTexture(f, tid, image);
|
||||
if (tid == 0) {
|
||||
qDebug() << "[TextureManager] Can`t load" << p;
|
||||
return;
|
||||
}
|
||||
qDebug() << "[TextureManager] Reloaded" << p << "as" << tid;
|
||||
}
|
||||
|
||||
|
||||
void TextureManager::reloadTexture(GLuint tid, const QImage & im) {
|
||||
if (im.isNull() || (tid == 0)) return;
|
||||
QImage image(im);
|
||||
createGLTexture(f, tid, image);
|
||||
qDebug() << "[TextureManager] Reloaded" << tid;
|
||||
}
|
||||
|
||||
|
||||
void TextureManager::convertToNormal(QImage & im) {
|
||||
if (im.isNull()) return;
|
||||
QImage sim = im.convertToFormat(QImage::Format_ARGB32);
|
||||
float sum[3] = {0., 0., 0.};
|
||||
llong a = 0;
|
||||
const uchar * sd = sim.constBits();
|
||||
for (int i = 0; i < sim.height(); i++) {
|
||||
for (int j = 0; j < sim.width(); j++) {
|
||||
sum[2] += sd[a] / 255.f - 0.5f; ++a;
|
||||
sum[1] += sd[a] / 255.f - 0.5f; ++a;
|
||||
sum[0] += sd[a] / 255.f - 0.5f; ++a;
|
||||
++a;
|
||||
}
|
||||
}
|
||||
float wh = sim.width() * sim.height();
|
||||
sum[0] /= wh;
|
||||
sum[1] /= wh;
|
||||
sum[2] /= wh;
|
||||
//qDebug() << sum[0] << sum[1] << sum[2];
|
||||
if ((qAbs(sum[0]) <= 0.05f) && (qAbs(sum[1]) <= 0.05f) && (sum[2] >= 0.25f)) /// already normal
|
||||
return;
|
||||
//qDebug() << "convert to normal";
|
||||
QImage dim = QImage(sim.width(), sim.height(), QImage::Format_ARGB32);
|
||||
int tx, ty, w = sim.width(), h = sim.height();
|
||||
a = 0;
|
||||
uchar * dd = dim.bits();
|
||||
for (int i = 0; i < sim.height(); i++) {
|
||||
for (int j = 0; j < sim.width(); j++) {
|
||||
tx = j - 1;
|
||||
tx = tx < 0 ? w + tx : tx % w;
|
||||
ty = i - 1;
|
||||
ty = ty < 0 ? h + ty : ty % h;
|
||||
QVector3D p[3], res;
|
||||
p[0] = colorVector(sim.pixel(j, i));
|
||||
p[1] = colorVector(sim.pixel(j, ty));
|
||||
p[2] = colorVector(sim.pixel(tx, i));
|
||||
res.setY(piClamp(0.5f + (p[0].length() - p[1].length()) / 2.f, 0.f, 1.f));
|
||||
res.setX(piClamp(0.5f - (p[0].length() - p[2].length()) / 2.f, 0.f, 1.f));
|
||||
tx = (j + 1) % w;
|
||||
ty = (i + 1) % h;
|
||||
p[1] = colorVector(sim.pixel(j, ty));
|
||||
p[2] = colorVector(sim.pixel(tx, i));
|
||||
res.setY(piClamp(0.5f + (p[0].length() - p[1].length()) / 2.f, 0.f, 1.f));
|
||||
res.setX(piClamp(0.5f - (p[0].length() - p[2].length()) / 2.f, 0.f, 1.f));
|
||||
res.setZ(1.f);
|
||||
dd[a] = res.z() * 255; ++a;
|
||||
dd[a] = res.y() * 255; ++a;
|
||||
dd[a] = res.x() * 255; ++a;
|
||||
dd[a] = 255; ++a;
|
||||
}
|
||||
}
|
||||
im = dim;
|
||||
//im.save("_normal.png");
|
||||
}
|
||||
|
||||
|
||||
bool TextureManager::loadTextures() {
|
||||
QFileInfoList fil;
|
||||
foreach (const QString & i, tex_pathes)
|
||||
loadTexture(i, true);
|
||||
tex_pathes.clear();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void TextureManager::deleteTextures() {
|
||||
for (int i = 0; i < 2; ++i) {
|
||||
QList<GLuint> texs = tex_ids[i].values();
|
||||
qDebug() << "[TextureManager] Delete" << texs.size() << "textures";
|
||||
if (!texs.isEmpty()) f->glDeleteTextures(texs.size(), &texs[0]);
|
||||
tex_ids[i].clear();
|
||||
tex_im [i].clear();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void TextureManager::deleteTexture(const QString & name) {
|
||||
for (int i = 0; i < 2; ++i) {
|
||||
if (tex_ids[i].contains(name)) {
|
||||
GLuint id = tex_ids[i][name];
|
||||
f->glDeleteTextures(1, &id);
|
||||
tex_ids[i].remove(name);
|
||||
tex_im [i].remove(name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void TextureManager::clearImageCache() {
|
||||
tex_im[0].clear();
|
||||
tex_im[1].clear();
|
||||
}
|
||||
@@ -1,63 +0,0 @@
|
||||
/*
|
||||
QGL TextureManager
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef GLTEXTUREMANAGER_H
|
||||
#define GLTEXTUREMANAGER_H
|
||||
|
||||
#include <QOpenGLExtraFunctions>
|
||||
#include <QDir>
|
||||
#include <QMap>
|
||||
#include <QFileInfo>
|
||||
#include <QImage>
|
||||
|
||||
|
||||
class TextureManager {
|
||||
public:
|
||||
TextureManager(QOpenGLExtraFunctions * f_): f(f_) {}
|
||||
virtual ~TextureManager() {}
|
||||
|
||||
static void addSearchPath(const QString & path) {if (!search_pathes.contains(path)) search_pathes << path;}
|
||||
static void clearSearchPathes() {search_pathes.clear();}
|
||||
static QStringList searchPathes() {return search_pathes;}
|
||||
static QString findFile(const QString & path);
|
||||
GLuint loadTexture(const QString & path, bool ownership = true, bool bump = false);
|
||||
GLuint loadTexture(const QImage & image, bool ownership = true, bool bump = false);
|
||||
QImage loadTextureImage(const QString & path, bool bump = false);
|
||||
void reloadTexture(GLuint tid, const QString & path);
|
||||
void reloadTexture(GLuint tid, const QImage & image);
|
||||
int textureID (const QString & path, bool bump = false) {return tex_ids[bump ? 1 : 0][path];}
|
||||
QImage textureImage(const QString & path, bool bump = false) {return tex_im [bump ? 1 : 0][path];}
|
||||
void addTexture(const QString & path) {tex_pathes << path;}
|
||||
bool loadTextures();
|
||||
void deleteTextures();
|
||||
void deleteTexture(const QString & name);
|
||||
void clearImageCache();
|
||||
|
||||
protected:
|
||||
static void convertToNormal(QImage & im);
|
||||
|
||||
static QStringList search_pathes;
|
||||
|
||||
QMap<QString, GLuint> tex_ids[2];
|
||||
QMap<QString, QImage> tex_im [2];
|
||||
QStringList tex_pathes;
|
||||
QOpenGLExtraFunctions * f;
|
||||
};
|
||||
|
||||
|
||||
#endif // GLTEXTUREMANAGER_H
|
||||
102
glwidget.h
@@ -1,102 +0,0 @@
|
||||
/*
|
||||
QGL GLWidget
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef GLWIDGET_H
|
||||
#define GLWIDGET_H
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
|
||||
class QGLView;
|
||||
class ObjectBase;
|
||||
class Scene;
|
||||
|
||||
class GLWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY (QColor backColor READ backColor WRITE setBackColor)
|
||||
Q_PROPERTY (qreal lineWidth READ lineWidth WRITE setLineWidth)
|
||||
Q_PROPERTY (qreal FOV READ FOV WRITE setFOV)
|
||||
Q_PROPERTY (qreal depthStart READ depthStart WRITE setDepthStart)
|
||||
Q_PROPERTY (QColor ambientColor READ ambientColor WRITE setAmbientColor)
|
||||
Q_PROPERTY (bool grabMouse READ isGrabMouseEnabled WRITE setGrabMouseEnabled)
|
||||
Q_PROPERTY (bool mouseRotate READ isMouseRotateEnabled WRITE setMouseRotateEnabled)
|
||||
Q_PROPERTY (bool mouseSelection READ isMouseSelectionEnabled WRITE setMouseSelectionEnabled)
|
||||
Q_PROPERTY (bool cameraOrbit READ isCameraOrbit WRITE setCameraOrbit)
|
||||
Q_PROPERTY (bool hoverHalo READ isHoverHaloEnabled WRITE setHoverHaloEnabled)
|
||||
Q_PROPERTY (QColor hoverHaloColor READ hoverHaloColor WRITE setHoverHaloColor)
|
||||
Q_PROPERTY (qreal hoverHaloFillAlpha READ hoverHaloFillAlpha WRITE setHoverHaloFillAlpha)
|
||||
Q_PROPERTY (bool selectionHalo READ isSelectionHaloEnabled WRITE setSelectionHaloEnabled)
|
||||
Q_PROPERTY (QColor selectionHaloColor READ selectionHaloColor WRITE setSelectionHaloColor)
|
||||
Q_PROPERTY (qreal selectionHaloFillAlpha READ selectionHaloFillAlpha WRITE setSelectionHaloFillAlpha)
|
||||
public:
|
||||
explicit GLWidget(QWidget *parent = nullptr);
|
||||
QGLView * view() {return view_;}
|
||||
|
||||
QColor backColor() const;
|
||||
qreal lineWidth() const;
|
||||
qreal FOV() const;
|
||||
qreal depthStart() const;
|
||||
QColor ambientColor() const;
|
||||
bool isLightEnabled() const;
|
||||
bool isGrabMouseEnabled() const;
|
||||
bool isMouseRotateEnabled() const;
|
||||
bool isMouseSelectionEnabled() const;
|
||||
bool isCameraOrbit() const;
|
||||
bool isHoverHaloEnabled() const;
|
||||
QColor hoverHaloColor() const;
|
||||
qreal hoverHaloFillAlpha() const;
|
||||
bool isSelectionHaloEnabled() const;
|
||||
QColor selectionHaloColor() const;
|
||||
qreal selectionHaloFillAlpha() const;
|
||||
Scene * scene();
|
||||
|
||||
void addObject(ObjectBase * o);
|
||||
QByteArray saveCamera();
|
||||
void restoreCamera(const QByteArray & ba);
|
||||
|
||||
public slots:
|
||||
void stop();
|
||||
void start(float freq = 60.0);
|
||||
void setBackColor(const QColor & c);
|
||||
void setLineWidth(const qreal & arg);
|
||||
void setFOV(const qreal & arg);
|
||||
void setDepthStart(const qreal & arg);
|
||||
void setAmbientColor(const QColor & arg);
|
||||
void setLightEnabled(const bool & arg);
|
||||
void setGrabMouseEnabled(const bool & arg);
|
||||
void setMouseRotateEnabled(const bool & arg);
|
||||
void setMouseSelectionEnabled(const bool & arg);
|
||||
void setCameraOrbit(const bool & arg);
|
||||
void setHoverHaloEnabled(const bool & arg);
|
||||
void setHoverHaloColor(const QColor & arg);
|
||||
void setHoverHaloFillAlpha(const qreal & arg);
|
||||
void setSelectionHaloEnabled(const bool & arg);
|
||||
void setSelectionHaloColor(const QColor & arg);
|
||||
void setSelectionHaloFillAlpha(const qreal & arg);
|
||||
|
||||
private slots:
|
||||
void viewDoubleClicked();
|
||||
|
||||
private:
|
||||
QWidget * container;
|
||||
QGLView * view_;
|
||||
QLayout * lay;
|
||||
};
|
||||
|
||||
#endif // GLWIDGET_H
|
||||
|
Before Width: | Height: | Size: 32 KiB |
|
Before Width: | Height: | Size: 32 KiB |
|
Before Width: | Height: | Size: 44 KiB |
|
Before Width: | Height: | Size: 38 KiB |
|
Before Width: | Height: | Size: 29 KiB |
|
Before Width: | Height: | Size: 24 KiB |
|
Before Width: | Height: | Size: 8.4 KiB |
|
Before Width: | Height: | Size: 26 KiB |
|
Before Width: | Height: | Size: 22 KiB |
|
Before Width: | Height: | Size: 20 KiB |
|
Before Width: | Height: | Size: 54 KiB |
|
Before Width: | Height: | Size: 14 KiB |
|
Before Width: | Height: | Size: 22 KiB |
|
Before Width: | Height: | Size: 42 KiB |
|
Before Width: | Height: | Size: 14 KiB |
|
Before Width: | Height: | Size: 4.7 KiB |
|
Before Width: | Height: | Size: 43 KiB |
|
Before Width: | Height: | Size: 7.0 KiB |
BIN
icons/go-top.png
|
Before Width: | Height: | Size: 31 KiB |
|
Before Width: | Height: | Size: 52 KiB |
|
Before Width: | Height: | Size: 49 KiB |
|
Before Width: | Height: | Size: 34 KiB |
|
Before Width: | Height: | Size: 25 KiB |
|
Before Width: | Height: | Size: 22 KiB |
|
Before Width: | Height: | Size: 24 KiB |
|
Before Width: | Height: | Size: 20 KiB |
|
Before Width: | Height: | Size: 7.9 KiB |
|
Before Width: | Height: | Size: 40 KiB |
@@ -1,84 +0,0 @@
|
||||
/*
|
||||
QGL MouseController
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef MOUSE_CONTROLLER_H
|
||||
#define MOUSE_CONTROLLER_H
|
||||
|
||||
#include "glprimitives.h"
|
||||
#include "glcamera.h"
|
||||
#include "renderer_service.h"
|
||||
#include <QMouseEvent>
|
||||
#include <QTime>
|
||||
|
||||
|
||||
class MouseController: public QObject
|
||||
{
|
||||
friend class QGLView;
|
||||
friend class RendererSelection;
|
||||
Q_OBJECT
|
||||
public:
|
||||
MouseController(QGLView * view_);
|
||||
virtual ~MouseController();
|
||||
|
||||
bool isGrabMouseEnabled() const {return grabMouse_;}
|
||||
bool isMouseRotateEnabled() const {return mouseRotate_;}
|
||||
bool isMouseSelectionEnabled() const {return mouseSelect_;}
|
||||
bool isCameraOrbit() const {return cameraOrbit_;}
|
||||
|
||||
Qt::MouseButton selectionButton() const {return sel_button;}
|
||||
Qt::KeyboardModifier selectionModifier() const {return sel_mod;}
|
||||
|
||||
void setSelectionButton(Qt::MouseButton v) {sel_button = v;}
|
||||
void setSelectionModifier(Qt::KeyboardModifier v) {sel_mod = v;}
|
||||
|
||||
protected:
|
||||
void resize();
|
||||
void mousePressEvent(QMouseEvent * e);
|
||||
void mouseMoveEvent(QMouseEvent * e);
|
||||
void mouseReleaseEvent(QMouseEvent * e);
|
||||
void wheelEvent(QWheelEvent * e);
|
||||
void leaveEvent(QEvent * );
|
||||
void mouseDoubleClickEvent(QMouseEvent * e);
|
||||
|
||||
private:
|
||||
QGLView * view;
|
||||
QPoint lastPos, downPos;
|
||||
QSet<int> keys_;
|
||||
QVector<ObjectBase * > hov_objects, hov_aims;
|
||||
Qt::MouseButton sel_button;
|
||||
Qt::KeyboardModifier sel_mod;
|
||||
RendererService::HandleAction cur_action;
|
||||
QFlags<RendererService::HandleMesh> cur_handle;
|
||||
float app_scale;
|
||||
bool grabMouse_, mouse_first, mouseRotate_, mouseSelect_, customMouseMove_, canSelect_;
|
||||
bool cameraOrbit_, selecting_, mouse_sec;
|
||||
|
||||
private slots:
|
||||
|
||||
public slots:
|
||||
void setGrabMouseEnabled(const bool & arg) {grabMouse_ = arg; mouse_first = true;}
|
||||
void setMouseRotateEnabled(const bool & arg) {mouseRotate_ = arg;}
|
||||
void setMouseSelectionEnabled(const bool & arg) {mouseSelect_ = arg;}
|
||||
void setCustomMouseMove(const bool & arg) {customMouseMove_ = arg;}
|
||||
void setCameraOrbit(const bool & arg) {cameraOrbit_ = arg;}
|
||||
|
||||
signals:
|
||||
|
||||
};
|
||||
|
||||
#endif // QGLVIEW_H
|
||||
112
openglwindow.cpp
@@ -1,112 +0,0 @@
|
||||
/*
|
||||
QGL OpenGLWindow
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "openglwindow.h"
|
||||
#include <QCoreApplication>
|
||||
#include <QOpenGLContext>
|
||||
#include <QOpenGLPaintDevice>
|
||||
#include <QPainter>
|
||||
|
||||
|
||||
OpenGLWindow::OpenGLWindow(QWindow *parent)
|
||||
: QWindow(parent)
|
||||
, m_context(nullptr)
|
||||
, m_device(nullptr)
|
||||
{
|
||||
setFlags(flags() | Qt::FramelessWindowHint);
|
||||
setSurfaceType(QWindow::OpenGLSurface);
|
||||
QSurfaceFormat format = QSurfaceFormat::defaultFormat();
|
||||
// qDebug() << format;
|
||||
#ifdef QT_OPENGL_ES_2
|
||||
format.setRenderableType(QSurfaceFormat::OpenGLES);
|
||||
#else
|
||||
if (QOpenGLContext::openGLModuleType() == QOpenGLContext::LibGL) {
|
||||
format.setVersion(4, 0);
|
||||
format.setProfile(QSurfaceFormat::CoreProfile);
|
||||
}
|
||||
#endif
|
||||
format.setDepthBufferSize(24);
|
||||
format.setSamples(8);
|
||||
setFormat(format);
|
||||
QSurfaceFormat::setDefaultFormat(format);
|
||||
}
|
||||
|
||||
|
||||
OpenGLWindow::~OpenGLWindow() {
|
||||
delete m_device;
|
||||
}
|
||||
|
||||
|
||||
void OpenGLWindow::render(QPainter *painter) {
|
||||
}
|
||||
|
||||
|
||||
void OpenGLWindow::initialize() {
|
||||
}
|
||||
|
||||
|
||||
void OpenGLWindow::render() {
|
||||
// if (!m_device) m_device = new QOpenGLPaintDevice;
|
||||
// glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
|
||||
// m_device->setSize(size() * devicePixelRatio());
|
||||
// m_device->setDevicePixelRatio(devicePixelRatio());
|
||||
// QPainter painter(m_device);
|
||||
// render(&painter);
|
||||
}
|
||||
|
||||
|
||||
void OpenGLWindow::renderLater() {
|
||||
requestUpdate();
|
||||
}
|
||||
|
||||
|
||||
bool OpenGLWindow::event(QEvent *event) {
|
||||
switch (event->type()) {
|
||||
case QEvent::UpdateRequest:
|
||||
renderNow();
|
||||
return true;
|
||||
default:
|
||||
return QWindow::event(event);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void OpenGLWindow::exposeEvent(QExposeEvent *event) {
|
||||
if (isExposed()) renderNow();
|
||||
}
|
||||
|
||||
|
||||
void OpenGLWindow::renderNow() {
|
||||
if (!isExposed())
|
||||
return;
|
||||
bool needsInitialize = false;
|
||||
if (!m_context) {
|
||||
m_context = new QOpenGLContext(this);
|
||||
m_context->setFormat(requestedFormat());
|
||||
m_context->create();
|
||||
needsInitialize = true;
|
||||
}
|
||||
m_context->makeCurrent(this);
|
||||
if (needsInitialize) {
|
||||
initializeOpenGLFunctions();
|
||||
initialize();
|
||||
}
|
||||
render();
|
||||
m_context->swapBuffers(this);
|
||||
}
|
||||
|
||||
@@ -1,51 +0,0 @@
|
||||
/*
|
||||
QGL OpenGLWindow
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <QWindow>
|
||||
#include <QOpenGLExtraFunctions>
|
||||
|
||||
class QPainter;
|
||||
class QOpenGLContext;
|
||||
class QOpenGLPaintDevice;
|
||||
|
||||
|
||||
class OpenGLWindow: public QWindow, public QOpenGLExtraFunctions
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit OpenGLWindow(QWindow *parent = nullptr);
|
||||
~OpenGLWindow();
|
||||
|
||||
virtual void render(QPainter *painter);
|
||||
virtual void render();
|
||||
virtual void initialize();
|
||||
QOpenGLContext * context() {return m_context;}
|
||||
|
||||
public slots:
|
||||
void renderLater();
|
||||
void renderNow();
|
||||
|
||||
protected:
|
||||
bool event(QEvent *event) override;
|
||||
void exposeEvent(QExposeEvent *event) override;
|
||||
|
||||
private:
|
||||
QOpenGLContext *m_context;
|
||||
QOpenGLPaintDevice *m_device;
|
||||
};
|
||||
|
||||
288
qglview.cpp
@@ -1,288 +0,0 @@
|
||||
/*
|
||||
QGLView
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "qglview.h"
|
||||
#include "glmesh.h"
|
||||
#include "gltexture_manager.h"
|
||||
#include <chunkstream.h>
|
||||
#include <qad_types.h>
|
||||
#include <QApplication>
|
||||
#include <QOpenGLTexture>
|
||||
#include <QKeyEvent>
|
||||
|
||||
using namespace QGLEngineShaders;
|
||||
|
||||
|
||||
QGLView::QGLView(): OpenGLWindow(), renderer_(this), mouse(this) {
|
||||
setIcon(QIcon(":/icons/qglview.png"));
|
||||
deleting_ = false;
|
||||
timer = 0;
|
||||
need_init_ = is_first_draw = true;
|
||||
backColor_ = Qt::darkGray;
|
||||
hoverHaloColor_ = QColor(195, 140, 255);
|
||||
selectionHaloColor_ = QColor(175, 255, 140);
|
||||
ambientColor_ = QColor(10, 10, 10);
|
||||
lineWidth_ = 1.;
|
||||
max_anisotropic = 1;
|
||||
max_texture_chanels = 8;
|
||||
lightEnabled_ = true;
|
||||
shaders_supported = false;
|
||||
fps_cnt = 0;
|
||||
fps_tm = fps_ = 0.;
|
||||
fogColor_ = Qt::darkGray;
|
||||
fogDensity_ = 0.;
|
||||
fogDecay_ = 10.;
|
||||
hoverHaloFill_ = selectionHaloFill_ = 0.15f;
|
||||
//lmode = Simple;
|
||||
setFeature(qglFXAA, false);
|
||||
setFeature(qglAnisotropicLevel, 8);
|
||||
setFeature(qglEyeAccomodationEnabled, false);
|
||||
setFeature(qglEyeAccomodationTime, 16.);
|
||||
setFeature(qglEyeAccomodationMaxSpeed, 0.2);
|
||||
setFeature(qglBloomEnabled, false);
|
||||
setFeature(qglBloomThreshold, 0.9);
|
||||
setFeature(qglBloomFactor, 1.);
|
||||
setFeature(qglBloomRadius, 8);
|
||||
setFeature(qglMotionBlurEnabled, false);
|
||||
setFeature(qglMotionBlurFactor, 1.);
|
||||
setFeature(qglMotionBlurSteps, 8);
|
||||
setFeature(qglShadowsEnabled, false);
|
||||
setFeature(qglShadowsMapSize, 512);
|
||||
setFeature(qglShadowsSoftEnabled, true);
|
||||
setFeature(qglReflectionsEnabled, false);
|
||||
setFeature(qglReflectionsBlur, true);
|
||||
setFeature(qglSSAOEnabled, false);
|
||||
setFeature(qglSSAORadius, 5);
|
||||
setFeature(qglDepthOfFieldEnabled, false);
|
||||
setFeature(qglDepthOfFieldAutoFocusEnabled, true);
|
||||
setFeature(qglDepthOfFieldAutoFocusSpeed, 0.1);
|
||||
setFeature(qglDepthOfFieldFocus, 1.);
|
||||
setFeature(qglDepthOfFieldDiaphragm, 8.);
|
||||
hoverHalo_ = selectionHalo_ = true;
|
||||
fogEnabled_ = is_init = shaders_bind = changed_ = false;
|
||||
rmode = ObjectBase::Fill;
|
||||
scene_ = new Scene();
|
||||
connect(scene_, SIGNAL(selectionChanged()), this, SIGNAL(selectionChanged()));
|
||||
connect(scene_, SIGNAL(__destroyed()), this, SLOT(__destroyed()));
|
||||
connect(scene_, SIGNAL(__objectDeleted(ObjectBase*)), this, SLOT(__objectDeleted(ObjectBase*)));
|
||||
default_camera = new Camera();
|
||||
default_camera->setPos(QVector3D(2, 2, 2));
|
||||
default_camera->setAim(QVector3D());
|
||||
camera_ = default_camera;
|
||||
// qDebug() << camera_->aim();
|
||||
default_camera->setName("Camera");
|
||||
emit cameraPosChanged(default_camera->pos());
|
||||
ktm_.restart();
|
||||
|
||||
Mesh * m = Primitive::cube(10, 10, 10);
|
||||
m->flipNormals();
|
||||
ObjectBase * o = new ObjectBase(m);
|
||||
o->setColor(Qt::cyan);
|
||||
scene()->addObject(o);
|
||||
delete m;
|
||||
}
|
||||
|
||||
|
||||
QGLView::~QGLView() {
|
||||
deleting_ = true;
|
||||
stop();
|
||||
scene_->clear();
|
||||
delete scene_;
|
||||
delete default_camera;
|
||||
}
|
||||
|
||||
|
||||
void QGLView::stop() {
|
||||
if (timer) killTimer(timer);
|
||||
}
|
||||
|
||||
|
||||
void QGLView::start(float freq) {
|
||||
timer = startTimer(freq <= 0.f ? 0 : int(1000.f / freq));
|
||||
}
|
||||
|
||||
|
||||
QList<Light * > QGLView::selectedLights() const {
|
||||
QList<Light * > ret;
|
||||
ObjectBaseList sol = scene_->selectedObjects();
|
||||
foreach (ObjectBase * o, sol)
|
||||
if (o->type() == ObjectBase::glLight)
|
||||
ret << (Light*)o;
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
QList<Camera * > QGLView::selectedCameras() const {
|
||||
QList<Camera * > ret;
|
||||
ObjectBaseList sol = scene_->selectedObjects();
|
||||
foreach (ObjectBase * o, sol)
|
||||
if (o->type() == ObjectBase::glCamera)
|
||||
ret << (Camera*)o;
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void QGLView::resizeEvent(QResizeEvent * e) {
|
||||
renderLater();
|
||||
mouse.resize();
|
||||
}
|
||||
|
||||
|
||||
void QGLView::timerEvent(QTimerEvent *) {
|
||||
renderNow();
|
||||
Qt::KeyboardModifiers km = QApplication::keyboardModifiers();
|
||||
foreach (int i, keys_)
|
||||
emit keyEvent((Qt::Key)i, km);
|
||||
}
|
||||
|
||||
|
||||
void QGLView::render() {
|
||||
resizeGL(width(), height());
|
||||
emit glBeginPaint();
|
||||
renderer_.mouse_pos = mapFromGlobal(QCursor::pos());
|
||||
renderer_.renderScene();
|
||||
emit glEndPaint();
|
||||
fps_tm += time.elapsed();
|
||||
time.restart();
|
||||
fps_cnt++;
|
||||
if (fps_tm < 1000.) return;
|
||||
fps_ = fps_cnt / fps_tm * 1000.;
|
||||
fps_tm = 0.;
|
||||
fps_cnt = 0;
|
||||
}
|
||||
|
||||
|
||||
void QGLView::initialize() {
|
||||
checkCaps();
|
||||
glPixelStorei(GL_PACK_ALIGNMENT, 1);
|
||||
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
||||
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
||||
glDisable(GL_MULTISAMPLE);
|
||||
glDisable(GL_BLEND);
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
glEnable(GL_TEXTURE_CUBE_MAP);
|
||||
glEnable(GL_TEXTURE_MAX_ANISOTROPY_EXT);
|
||||
glEnable(GL_CULL_FACE);
|
||||
glEnable(GL_TEXTURE_CUBE_MAP_SEAMLESS);
|
||||
glCullFace(GL_BACK);
|
||||
renderer_.reloadShaders();
|
||||
renderer_.init(width(), height());
|
||||
is_init = true;
|
||||
need_init_ = false;
|
||||
emit glInitializeDone();
|
||||
}
|
||||
|
||||
|
||||
void QGLView::checkCaps() {
|
||||
glGetIntegerv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &max_anisotropic);
|
||||
shaders_supported = QOpenGLShaderProgram::hasOpenGLShaderPrograms();
|
||||
}
|
||||
|
||||
|
||||
void QGLView::__destroyed() {
|
||||
renderer_.rend_mat.mat_thumbnails.clear();
|
||||
mouse.hov_objects.clear();
|
||||
}
|
||||
|
||||
|
||||
void QGLView::__objectDeleted(ObjectBase * o) {
|
||||
if (o == camera_)
|
||||
setDefaultCamera();
|
||||
}
|
||||
|
||||
|
||||
void QGLView::resizeGL(int width, int height) {
|
||||
if (!is_init) return;
|
||||
if (width <= 0 || height <= 0) return;
|
||||
if (prev_size == QSize(width, height)) return;
|
||||
prev_size = QSize(width, height);
|
||||
aspect = float(width) / float(height);
|
||||
renderer_.resize(width, height);
|
||||
//qDebug() << "resize" << width << height;
|
||||
iaspect = (aspect == 0.f) ? 0. : 1 / aspect;
|
||||
glViewport(0, 0, width, height);
|
||||
emit glResize(width, height);
|
||||
}
|
||||
|
||||
|
||||
void QGLView::keyPressEvent(QKeyEvent * e) {
|
||||
emit glKeyPressEvent(e);
|
||||
if (e->key() > 0) keys_.insert(e->key());
|
||||
if (e->key() == Qt::Key_F11) {
|
||||
emit doubleClick();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void QGLView::keyReleaseEvent(QKeyEvent * e) {
|
||||
emit glKeyReleaseEvent(e);
|
||||
keys_.remove(e->key());
|
||||
}
|
||||
|
||||
|
||||
void QGLView::focusOutEvent(QFocusEvent *) {
|
||||
keys_.clear();
|
||||
}
|
||||
|
||||
|
||||
void QGLView::focusOn(const Box3D & bb) {
|
||||
if (bb.isEmpty() || !camera()) return;
|
||||
double size = qMax(qMax(bb.width, bb.length), bb.height);
|
||||
camera()->setAim(bb.center());
|
||||
camera()->flyToDistance(size * 1.25);
|
||||
}
|
||||
|
||||
|
||||
QByteArray QGLView::saveCamera() {
|
||||
ChunkStream cs;
|
||||
const Camera * c = camera();
|
||||
cs.add(1, c->pos()).add(2, c->aim()).add(3, c->rotation()).add(4, c->FOV());
|
||||
return cs.data();
|
||||
}
|
||||
|
||||
|
||||
void QGLView::restoreCamera(const QByteArray & ba) {
|
||||
if (ba.isEmpty()) return;
|
||||
Camera * c = camera();
|
||||
QVector3D pos(c->pos()), aim(c->aim()), ang(c->rotation());
|
||||
float fov(c->FOV());
|
||||
ChunkStream cs(ba);
|
||||
cs.readAll();
|
||||
cs.get(1, pos).get(2, aim).get(3, ang).get(4, fov);
|
||||
camera()->setPos(pos);
|
||||
camera()->setAim(aim);
|
||||
camera()->setAngles(ang);
|
||||
camera()->setFOV(fov);
|
||||
}
|
||||
|
||||
|
||||
QByteArray QGLView::saveFeatures() {
|
||||
QByteArray ba;
|
||||
QDataStream ds(&ba, QIODevice::WriteOnly);
|
||||
ds << features_;
|
||||
return ba;
|
||||
}
|
||||
|
||||
|
||||
void QGLView::restoreFeatures(const QByteArray & ba) {
|
||||
QHash<int, QVariant> f;
|
||||
QDataStream ds(ba);
|
||||
ds >> f;
|
||||
features_ = f;
|
||||
}
|
||||
281
qglview.h
@@ -1,281 +0,0 @@
|
||||
/*
|
||||
QGLView
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef QGLVIEW_H
|
||||
#define QGLVIEW_H
|
||||
|
||||
#include "openglwindow.h"
|
||||
#include "glframebuffer.h"
|
||||
#include "glprimitives.h"
|
||||
#include "glcamera.h"
|
||||
#include "glscene.h"
|
||||
#include "renderer.h"
|
||||
#include "mouse_controller.h"
|
||||
#include <QElapsedTimer>
|
||||
#include <QMenu>
|
||||
|
||||
|
||||
class QGLView: public OpenGLWindow
|
||||
{
|
||||
friend class RendererSelection;
|
||||
Q_OBJECT
|
||||
Q_PROPERTY (QColor backColor READ backColor WRITE setBackColor)
|
||||
Q_PROPERTY (float lineWidth READ lineWidth WRITE setLineWidth)
|
||||
Q_PROPERTY (float FOV READ FOV WRITE setFOV)
|
||||
Q_PROPERTY (float depthStart READ depthStart WRITE setDepthStart)
|
||||
Q_PROPERTY (float gamma READ gamma WRITE setGamma)
|
||||
Q_PROPERTY (bool autoExposure READ autoExposure WRITE setAutoExposure)
|
||||
Q_PROPERTY (QColor ambientColor READ ambientColor WRITE setAmbientColor)
|
||||
Q_PROPERTY (QColor fogColor READ fogColor WRITE setFogColor)
|
||||
Q_PROPERTY (bool fogEnabled READ isFogEnabled WRITE setFogEnabled)
|
||||
Q_PROPERTY (float fogDensity READ fogDensity WRITE setFogDensity)
|
||||
Q_PROPERTY (float fogDecay READ fogDecay WRITE setFogDecay)
|
||||
Q_PROPERTY (int renderMode READ renderMode WRITE setRenderMode)
|
||||
Q_PROPERTY (bool grabMouse READ isGrabMouseEnabled WRITE setGrabMouseEnabled)
|
||||
Q_PROPERTY (bool mouseRotate READ isMouseRotateEnabled WRITE setMouseRotateEnabled)
|
||||
Q_PROPERTY (bool mouseSelection READ isMouseSelectionEnabled WRITE setMouseSelectionEnabled)
|
||||
Q_PROPERTY (bool cameraOrbit READ isCameraOrbit WRITE setCameraOrbit)
|
||||
Q_PROPERTY (bool hoverHalo READ isHoverHaloEnabled WRITE setHoverHaloEnabled)
|
||||
Q_PROPERTY (QColor hoverHaloColor READ hoverHaloColor WRITE setHoverHaloColor)
|
||||
Q_PROPERTY (float hoverHaloFillAlpha READ hoverHaloFillAlpha WRITE setHoverHaloFillAlpha)
|
||||
Q_PROPERTY (bool selectionHalo READ isSelectionHaloEnabled WRITE setSelectionHaloEnabled)
|
||||
Q_PROPERTY (QColor selectionHaloColor READ selectionHaloColor WRITE setSelectionHaloColor)
|
||||
Q_PROPERTY (float selectionHaloFillAlpha READ selectionHaloFillAlpha WRITE setSelectionHaloFillAlpha)
|
||||
Q_PROPERTY (Qt::MouseButton selectionButton READ selectionButton WRITE setSelectionButton)
|
||||
Q_PROPERTY (Qt::KeyboardModifier selectionModifier READ selectionModifier WRITE setSelectionModifier)
|
||||
Q_PROPERTY (Scene::SelectionMode selectionMode READ selectionMode WRITE setSelectionMode)
|
||||
|
||||
public:
|
||||
QGLView();
|
||||
virtual ~QGLView();
|
||||
|
||||
enum CameraLightMode {
|
||||
clmOff,
|
||||
clmAuto,
|
||||
clmOn,
|
||||
};
|
||||
|
||||
enum Feature {
|
||||
qglFXAA,
|
||||
qglAnisotropicLevel,
|
||||
qglEyeAccomodationEnabled,
|
||||
qglEyeAccomodationTime,
|
||||
qglEyeAccomodationMaxSpeed,
|
||||
qglBloomEnabled,
|
||||
qglBloomThreshold,
|
||||
qglBloomFactor,
|
||||
qglBloomRadius,
|
||||
qglMotionBlurEnabled,
|
||||
qglMotionBlurFactor,
|
||||
qglMotionBlurSteps,
|
||||
qglShadowsEnabled,
|
||||
qglShadowsMapSize,
|
||||
qglShadowsSoftEnabled,
|
||||
qglReflectionsEnabled,
|
||||
qglReflectionsBlur,
|
||||
qglSSAOEnabled,
|
||||
qglSSAORadius,
|
||||
qglDepthOfFieldEnabled,
|
||||
qglDepthOfFieldAutoFocusEnabled,
|
||||
qglDepthOfFieldAutoFocusSpeed,
|
||||
qglDepthOfFieldFocus,
|
||||
qglDepthOfFieldDiaphragm
|
||||
};
|
||||
|
||||
Q_ENUM(CameraLightMode)
|
||||
|
||||
void stop();
|
||||
void start(float freq = 60.);
|
||||
|
||||
QColor backColor() const {return backColor_;}
|
||||
float lineWidth() const {return lineWidth_;}
|
||||
float FOV() const {return camera()->FOV();}
|
||||
float depthStart() const {return camera()->depthStart();}
|
||||
float currentFPS() const {return fps_;}
|
||||
float gamma() const {return renderer_.gamma_;}
|
||||
bool autoExposure() const {return renderer_.tone_proc.enabled;}
|
||||
int maxAnisotropicLevel() const {return max_anisotropic;}
|
||||
QString environmentMapFile() const {return renderer_.tex_env.fileHDR();}
|
||||
|
||||
QColor ambientColor() const {return ambientColor_;}
|
||||
QColor fogColor() const {return fogColor_;}
|
||||
float fogDensity() const {return fogDensity_;}
|
||||
float fogDecay() const {return fogDecay_;}
|
||||
bool isFogEnabled() const {return fogEnabled_;}
|
||||
bool isLightEnabled() const {return lightEnabled_;}
|
||||
bool isGrabMouseEnabled() const {return mouse.isGrabMouseEnabled();}
|
||||
bool isMouseRotateEnabled() const {return mouse.isMouseRotateEnabled();}
|
||||
bool isMouseSelectionEnabled() const {return mouse.isMouseSelectionEnabled();}
|
||||
bool isCameraOrbit() const {return mouse.isCameraOrbit();}
|
||||
bool isHoverHaloEnabled() const {return hoverHalo_;}
|
||||
QColor hoverHaloColor() const {return hoverHaloColor_;}
|
||||
float hoverHaloFillAlpha() const {return hoverHaloFill_;}
|
||||
bool isSelectionHaloEnabled() const {return selectionHalo_;}
|
||||
QColor selectionHaloColor() const {return selectionHaloColor_;}
|
||||
float selectionHaloFillAlpha() const {return selectionHaloFill_;}
|
||||
|
||||
QVariant feature(Feature f) const {return features_.value(int(f));}
|
||||
QVariant setFeature(Feature f, const QVariant & value) {QVariant ret = features_.value(int(f)); features_[int(f)] = value; return ret;}
|
||||
bool isFeatureEnabled(Feature f) const {return features_[int(f)].toBool();}
|
||||
|
||||
int renderMode() const {return (int)rmode;}
|
||||
void setRenderMode(int mode) {rmode = (ObjectBase::RenderMode)mode;}
|
||||
|
||||
bool isServiceMode() const {return renderer_.edit_mode;}
|
||||
void setServiceMode(bool yes) {renderer_.edit_mode = yes;}
|
||||
|
||||
|
||||
Scene::SelectionMode selectionMode() const {return scene_->selectionMode();}
|
||||
Qt::MouseButton selectionButton() const {return mouse.selectionButton();}
|
||||
Qt::KeyboardModifier selectionModifier() const {return mouse.selectionModifier();}
|
||||
|
||||
void setSelectionMode(Scene::SelectionMode m) {scene_->setSelectionMode(m);}
|
||||
void setSelectionButton(Qt::MouseButton v) {mouse.setSelectionButton(v);}
|
||||
void setSelectionModifier(Qt::KeyboardModifier v) {mouse.setSelectionModifier(v);}
|
||||
|
||||
void selectObject(ObjectBase * o, bool add_to_selection = false) {scene_->selectObject(o, add_to_selection);}
|
||||
void clearSelection() {scene_->clearSelection();}
|
||||
ObjectBaseList selectedObjects(bool top_only = false) const {return scene_->selectedObjects(top_only);}
|
||||
QList<Light * > selectedLights() const;
|
||||
QList<Camera * > selectedCameras() const;
|
||||
ObjectBase * selectedObject() const {return scene_->selectedObject();}
|
||||
|
||||
TextureManager * textureManager() {return renderer_.textures_manager;}
|
||||
void reloadTextures() {renderer_.markReloadTextures();}
|
||||
|
||||
Scene * scene() {return scene_;}
|
||||
void focusOn(const Box3D & bb);
|
||||
void setCameraLightMode(CameraLightMode m) {renderer_.setCameraLightMode(m);}
|
||||
CameraLightMode cameraLightMode() const {return (CameraLightMode)renderer_.cameraLightMode();}
|
||||
|
||||
Camera * camera() {return camera_;}
|
||||
const Camera * camera() const {return camera_;}
|
||||
void setCamera(Camera * camera) {camera_ = camera;}
|
||||
void setDefaultCamera() {camera_ = default_camera;}
|
||||
QByteArray saveCamera();
|
||||
void restoreCamera(const QByteArray & ba);
|
||||
QByteArray saveFeatures();
|
||||
void restoreFeatures(const QByteArray & ba);
|
||||
|
||||
QImage materialThumbnail(Material * m) {return renderer_.materialThumbnail(m);}
|
||||
void setCurrentAction(RendererService::HandleAction ha) {renderer_.rend_service.setCurrentAction(ha);}
|
||||
void setContextActions(QList<QAction*> al) {context_menu.clear(); context_menu.addActions(al);}
|
||||
void popupMenu(const QPoint &pos, QAction *at = nullptr) {context_menu.popup(pos, at);}
|
||||
|
||||
GLfloat aspect, iaspect;
|
||||
Renderer renderer_;
|
||||
|
||||
protected:
|
||||
void render();
|
||||
void resizeEvent(QResizeEvent * e);
|
||||
|
||||
void timerEvent(QTimerEvent * );
|
||||
void initialize();
|
||||
void resizeGL(int width, int height);
|
||||
void mousePressEvent(QMouseEvent * e) {mouse.mousePressEvent(e);}
|
||||
void mouseMoveEvent(QMouseEvent * e) {mouse.mouseMoveEvent(e);}
|
||||
void mouseReleaseEvent(QMouseEvent * e) {mouse.mouseReleaseEvent(e);}
|
||||
void wheelEvent(QWheelEvent * e) {mouse.wheelEvent(e);}
|
||||
void mouseDoubleClickEvent(QMouseEvent * e) {mouse.mouseDoubleClickEvent(e);}
|
||||
void leaveEvent(QEvent * );
|
||||
|
||||
void keyPressEvent(QKeyEvent * e);
|
||||
void keyReleaseEvent(QKeyEvent * e);
|
||||
void focusOutEvent(QFocusEvent *);
|
||||
|
||||
void checkCaps();
|
||||
|
||||
private:
|
||||
void processKeys();
|
||||
bool setupViewport();
|
||||
|
||||
Scene * scene_;
|
||||
Camera * camera_, * default_camera;
|
||||
MouseController mouse;
|
||||
QMenu context_menu;
|
||||
QSet<int> keys_;
|
||||
QColor backColor_, fogColor_, ambientColor_, hoverHaloColor_, selectionHaloColor_;
|
||||
QElapsedTimer time, ktm_;
|
||||
GLint max_anisotropic, max_texture_chanels;
|
||||
ObjectBase::RenderMode rmode;
|
||||
QHash<int, QVariant> features_;
|
||||
QSize prev_size;
|
||||
float lineWidth_;
|
||||
float fps_, fps_tm, fogDensity_, fogDecay_;
|
||||
float hoverHaloFill_, selectionHaloFill_, m_motionBlurFactor;
|
||||
int timer, fps_cnt, sh_id_loc, deleting_;
|
||||
bool is_first_draw, is_init, fogEnabled_, lightEnabled_;
|
||||
bool shaders_supported, changed_, need_init_;
|
||||
bool hoverHalo_, selectionHalo_, shaders_bind;
|
||||
|
||||
private slots:
|
||||
void __destroyed();
|
||||
void __objectDeleted(ObjectBase * o);
|
||||
|
||||
public slots:
|
||||
void setBackColor(const QColor & arg) {backColor_ = arg;}
|
||||
void setLineWidth(const float & arg) {lineWidth_ = arg;}
|
||||
void setFOV(const float & arg) {camera()->setFOV(arg);}
|
||||
void setDepthStart(const float & arg) {camera()->setDepthStart(arg);}
|
||||
void setGamma(const float & arg) {renderer_.gamma_ = arg;}
|
||||
void setAutoExposure(bool arg) {renderer_.tone_proc.enabled = arg;}
|
||||
void setAmbientColor(const QColor & arg) {ambientColor_ = arg;}
|
||||
void setEnvironmentMapFile(QString file) {renderer_.tex_env.setFileHDR(file); renderer_.recreateMaterialThumbnails(true);}
|
||||
void setFogColor(const QColor & arg) {fogColor_ = arg;}
|
||||
void setFogDensity(const float & arg) {fogDensity_ = arg;}
|
||||
void setFogDecay(const float & arg) {fogDecay_ = arg;}
|
||||
void setFogEnabled(const bool & arg) {fogEnabled_ = arg;}
|
||||
void setLightEnabled(const bool & arg) {lightEnabled_ = arg;}
|
||||
void setGrabMouseEnabled(const bool & arg) {mouse.setGrabMouseEnabled(arg);}
|
||||
void setMouseRotateEnabled(const bool & arg) {mouse.setMouseRotateEnabled(arg);}
|
||||
void setMouseSelectionEnabled(const bool & arg) {mouse.setMouseSelectionEnabled(arg);}
|
||||
void setCustomMouseMove(const bool & arg) {mouse.setCustomMouseMove(arg);}
|
||||
void setCameraOrbit(const bool & arg) {mouse.setCameraOrbit(arg);}
|
||||
void setHoverHaloEnabled(const bool & arg) {hoverHalo_ = arg;}
|
||||
void setHoverHaloColor(const QColor & arg) {hoverHaloColor_ = arg;}
|
||||
void setHoverHaloFillAlpha(const float & arg) {hoverHaloFill_ = arg;}
|
||||
void setSelectionHaloEnabled(const bool & arg) {selectionHalo_ = arg;}
|
||||
void setSelectionHaloColor(const QColor & arg) {selectionHaloColor_ = arg;}
|
||||
void setSelectionHaloFillAlpha(const float & arg) {selectionHaloFill_ = arg;}
|
||||
|
||||
void reloadShaders() {renderer_.reloadShaders();}
|
||||
|
||||
signals:
|
||||
void glBeginPaint();
|
||||
void glEndPaint();
|
||||
void glKeyPressEvent(QKeyEvent * e);
|
||||
void glKeyReleaseEvent(QKeyEvent * e);
|
||||
void glMousePressEvent(QMouseEvent * e);
|
||||
void glMouseMoveEvent(QMouseEvent * e);
|
||||
void glMouseReleaseEvent(QMouseEvent * e);
|
||||
void glWheelEvent(QWheelEvent * e);
|
||||
void glResize(int, int);
|
||||
void glInitializeDone();
|
||||
void cameraPosChanged(QVector3D pos);
|
||||
void keyEvent(Qt::Key key, Qt::KeyboardModifiers mod);
|
||||
void customMouseMoveEvent(QPoint curpos, QPoint lastpos, Qt::MouseButtons buttons);
|
||||
|
||||
void hoverChanged(ObjectBase * cur, ObjectBase * prev);
|
||||
void selectionChanged();
|
||||
void objectsPositionChanged();
|
||||
void materialsChanged();
|
||||
void materialThumbnailCreated(Material*);
|
||||
void doubleClick();
|
||||
};
|
||||
|
||||
#endif // QGLVIEW_H
|
||||
46
qglview.qrc
@@ -1,46 +0,0 @@
|
||||
<RCC>
|
||||
<qresource prefix="/">
|
||||
<file>coeffs_brdf.png</file>
|
||||
<file>icons/add-type-camera.png</file>
|
||||
<file>icons/add-type-geo.png</file>
|
||||
<file>icons/add-type-light.png</file>
|
||||
<file>icons/add-type-empty.png</file>
|
||||
<file>icons/collapse.png</file>
|
||||
<file>icons/expand.png</file>
|
||||
<file>icons/edit-rename.png</file>
|
||||
<file>icons/alpha.png</file>
|
||||
<file>icons/application-exit.png</file>
|
||||
<file>icons/configure.png</file>
|
||||
<file>icons/dialog-close.png</file>
|
||||
<file>icons/document-edit.png</file>
|
||||
<file>icons/document-import.png</file>
|
||||
<file>icons/document-new.png</file>
|
||||
<file>icons/document-open.png</file>
|
||||
<file>icons/document-save.png</file>
|
||||
<file>icons/document-save-all.png</file>
|
||||
<file>icons/edit-clear.png</file>
|
||||
<file>icons/edit-clear-locationbar-rtl.png</file>
|
||||
<file>icons/edit-copy.png</file>
|
||||
<file>icons/edit-delete.png</file>
|
||||
<file>icons/edit-find.png</file>
|
||||
<file>icons/edit-paste.png</file>
|
||||
<file>icons/go-jump.png</file>
|
||||
<file>icons/go-top.png</file>
|
||||
<file>icons/layer-visible-on.png</file>
|
||||
<file>icons/layer-visible-off.png</file>
|
||||
<file>icons/light-+.png</file>
|
||||
<file>icons/list-add.png</file>
|
||||
<file>icons/object-flip-horizontal.png</file>
|
||||
<file>icons/object-flip-vertical.png</file>
|
||||
<file>icons/picker.png</file>
|
||||
<file>icons/qglview.png</file>
|
||||
<file>icons/transform-move.png</file>
|
||||
<file>icons/transform-rotate.png</file>
|
||||
<file>icons/transform-scale.png</file>
|
||||
<file>icons/type-camera.png</file>
|
||||
<file>icons/type-geo.png</file>
|
||||
<file>icons/type-light.png</file>
|
||||
<file>icons/type-empty.png</file>
|
||||
<file>icons/view-refresh.png</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
@@ -1,34 +0,0 @@
|
||||
/*
|
||||
QGLViewWindow
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <QApplication>
|
||||
#include <QDebug>
|
||||
#include <QDir>
|
||||
#include "qglview_window.h"
|
||||
|
||||
int main(int argc, char ** argv) {
|
||||
QApplication a(argc, argv);
|
||||
a.setAttribute(Qt::AA_UseHighDpiPixmaps, true);
|
||||
QGLViewWindow w;
|
||||
w.show();
|
||||
QStringList al(a.arguments());
|
||||
al.pop_front();
|
||||
foreach (QString s, al)
|
||||
w.loadFile(s);
|
||||
return a.exec();
|
||||
}
|
||||
@@ -1,251 +0,0 @@
|
||||
/*
|
||||
QGLViewWindow
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "qglview_window.h"
|
||||
#include "renderer.h"
|
||||
#include "glwidget.h"
|
||||
#include "gltexture_manager.h"
|
||||
#include <QGraphicsRectItem>
|
||||
#include <QImageReader>
|
||||
#include <QMessageBox>
|
||||
#include "qad_types.h"
|
||||
|
||||
|
||||
QGLViewWindow::QGLViewWindow(QWidget * parent): QMainWindow(parent), Ui::QGLViewWindow() {
|
||||
setupUi(this);
|
||||
session.setFile("session_qglview_test.conf");
|
||||
session.addEntry(this);
|
||||
|
||||
extensions = "All(" + supportedFormats().join(" ") + " *.qgl)";
|
||||
extensions += ";;QGLEngine(*.qgl)";
|
||||
|
||||
//view->view()->camera()->setPos(QVector3D(2, 2, 2));
|
||||
//view->view()->camera()->setAim(QVector3D());
|
||||
//view->view()->camera()->flyToDistance(2.);
|
||||
// view->setFrameShape(QFrame::NoFrame);
|
||||
view->view()->setMouseRotateEnabled(true);
|
||||
view->view()->setMouseSelectionEnabled(true);
|
||||
view->view()->setSelectionHaloEnabled(true);
|
||||
view->view()->setHoverHaloEnabled(true);
|
||||
view->view()->setBackColor(Qt::lightGray);
|
||||
view->view()->setDepthStart(0.1);
|
||||
view->view()->setSelectionMode(Scene::smMultiSelection);
|
||||
|
||||
|
||||
groupShadows->setChecked(view->view()->isFeatureEnabled(QGLView::qglShadowsEnabled));
|
||||
groupEyeAccomodation->setChecked(view->view()->isFeatureEnabled(QGLView::qglEyeAccomodationEnabled));
|
||||
groupBloom->setChecked(view->view()->isFeatureEnabled(QGLView::qglBloomEnabled));
|
||||
groupMotionBlur->setChecked(view->view()->isFeatureEnabled(QGLView::qglMotionBlurEnabled));
|
||||
groupReflections->setChecked(view->view()->isFeatureEnabled(QGLView::qglReflectionsEnabled));
|
||||
checkSoftShadows->setChecked(view->view()->isFeatureEnabled(QGLView::qglShadowsSoftEnabled));
|
||||
groupSSAO->setChecked(view->view()->isFeatureEnabled(QGLView::qglSSAOEnabled));
|
||||
spinAccom->setValue(view->view()->feature(QGLView::qglEyeAccomodationTime).toDouble());
|
||||
spinAccomMS->setValue(view->view()->feature(QGLView::qglEyeAccomodationMaxSpeed).toDouble());
|
||||
checkReflectionsBlur->setChecked(view->view()->isFeatureEnabled(QGLView::qglReflectionsBlur));
|
||||
spinShadowmapSize->setValue(view->view()->feature(QGLView::qglShadowsMapSize).toInt());
|
||||
spinMotionBlurFactor->setValue(view->view()->feature(QGLView::qglMotionBlurFactor).toDouble());
|
||||
spinMotionBlurSteps->setValue(view->view()->feature(QGLView::qglMotionBlurSteps).toInt());
|
||||
spinBloomFactor->setValue(view->view()->feature(QGLView::qglBloomFactor).toDouble());
|
||||
spinBloomRadius->setValue(view->view()->feature(QGLView::qglBloomRadius).toInt());
|
||||
spinBloomThreshold->setValue(view->view()->feature(QGLView::qglBloomThreshold).toDouble());
|
||||
spinSSAORadius->setValue(view->view()->feature(QGLView::qglSSAORadius).toInt());
|
||||
groupDOF->setChecked(view->view()->isFeatureEnabled(QGLView::qglDepthOfFieldEnabled));
|
||||
checkDOFAutoFocus->setChecked(view->view()->isFeatureEnabled(QGLView::qglDepthOfFieldAutoFocusEnabled));
|
||||
spinDOFFocus->setValue(view->view()->feature(QGLView::qglDepthOfFieldFocus).toDouble());
|
||||
spinDOFDiaphragm->setValue(view->view()->feature(QGLView::qglDepthOfFieldDiaphragm).toDouble());
|
||||
spinDOFSpeed->setValue(view->view()->feature(QGLView::qglDepthOfFieldAutoFocusSpeed).toDouble());
|
||||
|
||||
view->view()->start(-1);
|
||||
startTimer(1000/60);
|
||||
|
||||
connect(view->view(), SIGNAL(keyEvent(Qt::Key, Qt::KeyboardModifiers)), this, SLOT(view_keyEvent(Qt::Key, Qt::KeyboardModifiers)));
|
||||
//connect(matEditor, SIGNAL(changed()), this, SLOT(materialChanged()));
|
||||
sceneTree->assignQGLView(view->view());
|
||||
matEditor->assignQGLView(view->view());
|
||||
objectEditor->assignQGLView(view->view());
|
||||
primitiveEditor->assignQGLView(view->view());
|
||||
viewEditor->assignQGLView(view->view());
|
||||
|
||||
session.load();
|
||||
|
||||
//loadFile("axis.DAE.qgl");
|
||||
//matEditor->setMaterial(const_cast<ObjectBase*>(view->view()->scene()->rootObject()->child(0))->material());
|
||||
/*Scene * sc = loadScene("truck.obj");
|
||||
//view->view()->scene()->addScene(sc);
|
||||
sc->rootObject()->moveY(-8);
|
||||
for (int i = 0; i < 7; ++i) {
|
||||
sc->rootObject()->moveY(2);
|
||||
view->view()->scene()->addScene(sc);
|
||||
}
|
||||
//view->view()->scene()->dump();
|
||||
delete sc;*/
|
||||
}
|
||||
|
||||
|
||||
QGLViewWindow::~QGLViewWindow() {
|
||||
session.save();
|
||||
//delete ps;
|
||||
}
|
||||
|
||||
|
||||
void QGLViewWindow::changeEvent(QEvent * e) {
|
||||
QMainWindow::changeEvent(e);
|
||||
if (e->type() == QEvent::LanguageChange) {
|
||||
retranslateUi(this);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void QGLViewWindow::timerEvent(QTimerEvent * ) {
|
||||
//static double t = 0.;
|
||||
//((RendererSimple*)(view->view()->renderer()))->mpos = view->view()->mapFromGlobal(QCursor::pos());
|
||||
statusBar()->showMessage(QString("FPS: %1").arg(QString::number(view->view()->currentFPS(), 'f', 2)));
|
||||
}
|
||||
|
||||
|
||||
void QGLViewWindow::loadFile(const QString & path, bool import) {
|
||||
prev_path = path;
|
||||
QApplication::setOverrideCursor(Qt::WaitCursor);
|
||||
QFileInfo fi(path);
|
||||
Scene * s = nullptr;
|
||||
if (fi.suffix().toLower() == "qgl") s = loadFromQGLFile(path);
|
||||
else s = loadScene(path);
|
||||
QApplication::restoreOverrideCursor();
|
||||
if (!s) {
|
||||
QMessageBox::critical(this, "Import", "Can`t load " + path + "!");
|
||||
return;
|
||||
}
|
||||
s->setName(fi.baseName());
|
||||
if (import) view->scene()->addScene(s);
|
||||
else {
|
||||
TextureManager::clearSearchPathes();
|
||||
view->scene()->assignFrom(s);
|
||||
view->view()->focusOn(view->scene()->boundingBox());
|
||||
}
|
||||
TextureManager::addSearchPath(fi.absoluteDir().path());
|
||||
delete s;
|
||||
}
|
||||
|
||||
|
||||
void QGLViewWindow::on_actionReset_triggered() {
|
||||
///view->view()->removeObject(axis, false);
|
||||
view->view()->scene()->clear();
|
||||
///view->view()->addObject(axis);
|
||||
}
|
||||
|
||||
|
||||
void QGLViewWindow::on_actionImport_triggered() {
|
||||
QStringList fl = QFileDialog::getOpenFileNames(this, "Select files", prev_path, extensions);
|
||||
if (fl.isEmpty()) return;
|
||||
prev_path = fl.back();
|
||||
foreach (QString f, fl)
|
||||
loadFile(f, true);
|
||||
}
|
||||
|
||||
|
||||
void QGLViewWindow::on_actionSave_triggered() {
|
||||
QString f = QFileDialog::getSaveFileName(this, "Select file", prev_path, "QGLView(*.qgl)");
|
||||
if (f.isEmpty()) return;
|
||||
if (f.right(4).toLower() != ".qgl")
|
||||
f += ".qgl";
|
||||
prev_path = f;
|
||||
QApplication::setOverrideCursor(Qt::WaitCursor);
|
||||
saveToQGLFile(f, view->scene());
|
||||
QApplication::restoreOverrideCursor();
|
||||
}
|
||||
|
||||
|
||||
void QGLViewWindow::on_actionSaveSelected_triggered() {
|
||||
ObjectBase * sel_obj = view->view()->selectedObject();
|
||||
if (!sel_obj) return;
|
||||
QString f = QFileDialog::getSaveFileName(this, "Select file", prev_path, "QGLView(*.qgl)");
|
||||
if (f.isEmpty()) return;
|
||||
if (f.right(4).toLower() != ".qgl")
|
||||
f += ".qgl";
|
||||
prev_path = f;
|
||||
QApplication::setOverrideCursor(Qt::WaitCursor);
|
||||
///saveToQGLFile(f, sel_obj);
|
||||
QApplication::restoreOverrideCursor();
|
||||
}
|
||||
|
||||
|
||||
void QGLViewWindow::on_actionOpen_triggered() {
|
||||
QString f = QFileDialog::getOpenFileName(this, "Select file", prev_path, extensions);
|
||||
if (f.isEmpty()) return;
|
||||
prev_path = f;
|
||||
loadFile(f);
|
||||
}
|
||||
|
||||
|
||||
void QGLViewWindow::view_keyEvent(Qt::Key k, Qt::KeyboardModifiers m) {
|
||||
//qDebug() << k;
|
||||
double spd = 0.2;
|
||||
if (m.testFlag(Qt::ShiftModifier))
|
||||
spd = 0.5;
|
||||
switch (k) {
|
||||
case Qt::Key_W: view->view()->camera()->moveForward(spd); break;
|
||||
case Qt::Key_S: view->view()->camera()->moveBackward(spd); break;
|
||||
case Qt::Key_A: view->view()->camera()->moveLeft(spd); break;
|
||||
case Qt::Key_D: view->view()->camera()->moveRight(spd); break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void QGLViewWindow::on_actionArrow_triggered(bool on) {
|
||||
actionArrow ->setChecked(true);
|
||||
actionMove ->setChecked(false);
|
||||
actionRotate->setChecked(false);
|
||||
actionScale ->setChecked(false);
|
||||
view->view()->setCurrentAction(RendererService::haNoAction);
|
||||
}
|
||||
|
||||
|
||||
void QGLViewWindow::on_actionMove_triggered(bool on) {
|
||||
actionArrow ->setChecked(false);
|
||||
actionMove ->setChecked(true);
|
||||
actionRotate->setChecked(false);
|
||||
actionScale ->setChecked(false);
|
||||
view->view()->setCurrentAction(RendererService::haMove);
|
||||
}
|
||||
|
||||
|
||||
void QGLViewWindow::on_actionRotate_triggered(bool on) {
|
||||
actionArrow ->setChecked(false);
|
||||
actionMove ->setChecked(false);
|
||||
actionRotate->setChecked(true);
|
||||
actionScale ->setChecked(false);
|
||||
view->view()->setCurrentAction(RendererService::haRotate);
|
||||
}
|
||||
|
||||
|
||||
void QGLViewWindow::on_actionScale_triggered(bool on) {
|
||||
actionArrow ->setChecked(false);
|
||||
actionMove ->setChecked(false);
|
||||
actionRotate->setChecked(false);
|
||||
actionScale ->setChecked(true);
|
||||
view->view()->setCurrentAction(RendererService::haScale);
|
||||
}
|
||||
|
||||
|
||||
#include "glcubemap.h"
|
||||
void QGLViewWindow::on_pushButton_3_clicked() {
|
||||
QString f = QFileDialog::getOpenFileName(this, "Select file", "", "*");
|
||||
if (f.isEmpty()) return;
|
||||
}
|
||||
@@ -1,119 +0,0 @@
|
||||
/*
|
||||
QGLViewWindow
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef QGLVIEWWINDOW_H
|
||||
#define QGLVIEWWINDOW_H
|
||||
|
||||
#include <QTranslator>
|
||||
#include <QInputDialog>
|
||||
#include <QFileDialog>
|
||||
#include <QColorDialog>
|
||||
#include <QCloseEvent>
|
||||
#include <QClipboard>
|
||||
#include <QRadioButton>
|
||||
#include <QUrl>
|
||||
#include <QThread>
|
||||
#include <QTime>
|
||||
#include <QSplitter>
|
||||
#include "ui_qglview_window.h"
|
||||
#include "formats/loader_qgl.h"
|
||||
#include "formats/loader_assimp.h"
|
||||
#include "session_manager.h"
|
||||
//#include "renderer_rt.h"
|
||||
#include "qglview.h"
|
||||
#include "ui_qglview_window.h"
|
||||
|
||||
|
||||
class QGLViewWindow: public QMainWindow, public Ui::QGLViewWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
QGLViewWindow(QWidget * parent = 0);
|
||||
~QGLViewWindow();
|
||||
|
||||
void loadFile(const QString & path, bool import = false);
|
||||
|
||||
private:
|
||||
// Qt`s overloaded
|
||||
void changeEvent(QEvent * e);
|
||||
void timerEvent(QTimerEvent * );
|
||||
|
||||
QString extensions;
|
||||
QTranslator translator;
|
||||
QString prev_path;
|
||||
//GLPrimitiveCube * box;
|
||||
Material m;
|
||||
SessionManager session;
|
||||
bool isChanged;
|
||||
|
||||
private slots:
|
||||
void on_groupShadows_clicked(bool val) {view->view()->setFeature(QGLView::qglShadowsEnabled, val);}
|
||||
void on_groupEyeAccomodation_clicked(bool val) {view->view()->setFeature(QGLView::qglEyeAccomodationEnabled, val);}
|
||||
void on_groupBloom_clicked(bool val) {view->view()->setFeature(QGLView::qglBloomEnabled, val);}
|
||||
void on_groupMotionBlur_clicked(bool val) {view->view()->setFeature(QGLView::qglMotionBlurEnabled, val);}
|
||||
void on_groupReflections_clicked(bool val) {view->view()->setFeature(QGLView::qglReflectionsEnabled, val);}
|
||||
void on_checkSoftShadows_clicked(bool val) {view->view()->setFeature(QGLView::qglShadowsSoftEnabled, val);}
|
||||
void on_groupSSAO_clicked(bool val) {view->view()->setFeature(QGLView::qglSSAOEnabled, val);}
|
||||
void on_groupDOF_clicked(bool val) {view->view()->setFeature(QGLView::qglDepthOfFieldEnabled, val);}
|
||||
void on_checkDOFAutoFocus_clicked(bool val) {view->view()->setFeature(QGLView::qglDepthOfFieldAutoFocusEnabled, val);}
|
||||
void on_spinDOFFocus_valueChanged(double val) {view->view()->setFeature(QGLView::qglDepthOfFieldFocus, val);}
|
||||
void on_spinDOFDiaphragm_valueChanged(double val) {view->view()->setFeature(QGLView::qglDepthOfFieldDiaphragm, val);}
|
||||
void on_spinDOFSpeed_valueChanged(double val) {view->view()->setFeature(QGLView::qglDepthOfFieldAutoFocusSpeed, val);}
|
||||
void on_spinAccom_valueChanged(double val) {view->view()->setFeature(QGLView::qglEyeAccomodationTime, val);}
|
||||
void on_spinAccomMS_valueChanged(double val) {view->view()->setFeature(QGLView::qglEyeAccomodationMaxSpeed, val);}
|
||||
void on_checkReflectionsBlur_clicked(bool val) {view->view()->setFeature(QGLView::qglReflectionsBlur, val);}
|
||||
void on_spinShadowmapSize_valueChanged(double val) {view->view()->setFeature(QGLView::qglShadowsMapSize, val);}
|
||||
void on_spinMotionBlurFactor_valueChanged(double val) {view->view()->setFeature(QGLView::qglMotionBlurFactor, val);}
|
||||
void on_spinMotionBlurSteps_valueChanged(int val) {view->view()->setFeature(QGLView::qglMotionBlurSteps, val);}
|
||||
void on_spinBloomFactor_valueChanged(double val) {view->view()->setFeature(QGLView::qglBloomFactor, val);}
|
||||
void on_spinBloomRadius_valueChanged(int val) {view->view()->setFeature(QGLView::qglBloomRadius, val);}
|
||||
void on_spinBloomThreshold_valueChanged(double val) {view->view()->setFeature(QGLView::qglBloomThreshold, val);}
|
||||
void on_spinSSAORadius_valueChanged(int val) {view->view()->setFeature(QGLView::qglSSAORadius, val);}
|
||||
|
||||
void on_actionExit_triggered() {close();}
|
||||
void on_actionReset_triggered();
|
||||
void on_actionImport_triggered();
|
||||
void on_actionSave_triggered();
|
||||
void on_actionSaveSelected_triggered();
|
||||
void on_actionOpen_triggered();
|
||||
|
||||
void view_keyEvent(Qt::Key k, Qt::KeyboardModifiers m);
|
||||
|
||||
void on_pushButton_2_clicked() {view->view()->reloadShaders();}
|
||||
|
||||
void on_actionArrow_triggered(bool on);
|
||||
void on_actionMove_triggered(bool on);
|
||||
void on_actionRotate_triggered(bool on);
|
||||
void on_actionScale_triggered(bool on);
|
||||
|
||||
void on_colorFogBack_colorChanged(const QColor & v) {view->view()->setFogColor(v);}
|
||||
void on_spinFogDensity_valueChanged(double v) {view->view()->setFogDensity(v);}
|
||||
void on_spinFogDecay_valueChanged(double v) {view->view()->setFogDecay(v);}
|
||||
|
||||
void on_pushButton_3_clicked();
|
||||
|
||||
public slots:
|
||||
|
||||
signals:
|
||||
|
||||
private:
|
||||
QMatrix4x4 cam_mat;
|
||||
|
||||
};
|
||||
|
||||
#endif // QGLVIEWWINDOW_H
|
||||
361
renderer.cpp
@@ -1,361 +0,0 @@
|
||||
/*
|
||||
QGL Renderer
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#define GL_GLEXT_PROTOTYPES
|
||||
#include <QOpenGLExtraFunctions>
|
||||
#include <qad_types.h>
|
||||
#include "renderer.h"
|
||||
#include "qglview.h"
|
||||
#include "glmesh.h"
|
||||
#include "gltexture_manager.h"
|
||||
#include "glshaders.h"
|
||||
|
||||
|
||||
using namespace QGLEngineShaders;
|
||||
|
||||
|
||||
Renderer::Renderer(QGLView * view_): RendererBase(view_),
|
||||
fbo_ds (view_, QVector<GLenum>() << GL_RGBA16F << GL_RGBA32F << GL_RGBA16F << GL_RGBA16F << GL_RGBA16F),
|
||||
fbo_out (view_, obrBuffersCount, false, GL_RGBA16F),
|
||||
rend_mat(this), rend_service(this), rend_selection(this), tone_proc(this), tex_env(view_, 512) {
|
||||
quad = Primitive::plane(2., 2.);
|
||||
cam_light = new Light();
|
||||
cam_light->intensity = 0.75;
|
||||
cam_light->setName("Camera_Light");
|
||||
|
||||
shader_files[srSelectionFill ] = "selection.glsl";
|
||||
shader_files[srSelectionHalo ] = "selection_halo.glsl";
|
||||
shader_files[srSelectionApply] = "selection_apply.glsl";
|
||||
shader_files[srSelectionFrame] = "selection_frame.glsl";
|
||||
|
||||
shader_files[srServiceFill ] = "service_fill.glsl";
|
||||
shader_files[srServiceFrame] = "service_frame.glsl";
|
||||
shader_files[srServiceLine ] = "service_line.glsl";
|
||||
|
||||
shader_files[srGeometryPass ] = "ds_geom.glsl";
|
||||
shader_files[srLightOmniPass] = "ds_light.glsl";
|
||||
shader_files[srLightSpotPass] = "ds_light.glsl"; shader_defines[srLightSpotPass] << "SPOT";
|
||||
shader_files[srFinalPass ] = "ds_final.glsl";
|
||||
shader_files[srTonemapPass ] = "ds_tonemap.glsl";
|
||||
|
||||
shader_fxaa = 0;
|
||||
gamma_ = 1.;
|
||||
edit_mode = need_init_shaders = true;
|
||||
camera_light_mode = QGLView::clmAuto;
|
||||
}
|
||||
|
||||
|
||||
Renderer::~Renderer() {
|
||||
delete quad;
|
||||
delete cam_light;
|
||||
qDeleteAll(shaders.values());
|
||||
if (shader_fxaa) delete shader_fxaa;
|
||||
}
|
||||
|
||||
|
||||
void Renderer::init(int width, int height) {
|
||||
resize(width, height);
|
||||
rend_mat.init(width, height);
|
||||
rend_service.init(width, height);
|
||||
rend_selection.init(width, height);
|
||||
tone_proc.init();
|
||||
initQuad(quad);
|
||||
initTextureArrays();
|
||||
initCoeffTextures();
|
||||
tex_env.init();
|
||||
need_init_shaders = true;
|
||||
}
|
||||
|
||||
|
||||
void Renderer::resize(int width, int height) {
|
||||
rend_mat.resize(width, height);
|
||||
rend_service.resize(width, height);
|
||||
rend_selection.resize(width, height);
|
||||
fbo_ds .resize(width, height);
|
||||
fbo_out .resize(width, height);
|
||||
tone_proc.resize();
|
||||
}
|
||||
|
||||
|
||||
void Renderer::reloadShaders() {
|
||||
QMapIterator<ShaderRole, QString> it(shader_files);
|
||||
QString dir = ":shaders/";
|
||||
while (it.hasNext()) {
|
||||
it.next();
|
||||
loadShadersMulti(shaders[it.key()], dir + it.value(), true, shader_defines.value(it.key()));
|
||||
}
|
||||
loadShadersMulti(tone_proc.shader_sum, dir + "sum.glsl", false);
|
||||
QStringList fxaa_defs;
|
||||
fxaa_defs << "FXAA_PC 1" << "FXAA_GLSL_130 1" << "FXAA_QUALITY__PRESET 15";
|
||||
loadShaders(shader_fxaa, QStringList() << (dir + "fxaa.vert") << (dir + "fxaa.frag"), true, fxaa_defs);
|
||||
need_init_shaders = true;
|
||||
view->scene()->setLightsChanged();
|
||||
view->scene()->setTreeStructChanged();
|
||||
view->scene()->setMaterialsChanged();
|
||||
}
|
||||
|
||||
|
||||
bool Renderer::bindShader(Renderer::ShaderRole role, QOpenGLShaderProgram ** ret) {
|
||||
QOpenGLShaderProgram * prog = shaders.value(role);
|
||||
if (ret) *ret = prog;
|
||||
if (!prog) return false;
|
||||
if (!prog->isLinked()) return false;
|
||||
prog->bind();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Renderer::bindShader(QOpenGLShaderProgram * sp) {
|
||||
if (!sp) return true;
|
||||
if (!sp->isLinked()) return true;
|
||||
if (!sp->bind()) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void Renderer::initShaders() {
|
||||
if (!need_init_shaders) return;
|
||||
need_init_shaders = false;
|
||||
initUniformBuffer(shaders.value(srGeometryPass ), &buffer_materials , bpMaterials , "QGLMaterialData" );
|
||||
initUniformBuffer(shaders.value(srLightOmniPass), &buffer_materials , bpMaterials , "QGLMaterialData" );
|
||||
initUniformBuffer(shaders.value(srLightOmniPass), &buffer_lights , bpLightParameters, "QGLLightParameterData");
|
||||
initUniformBuffer(shaders.value(srLightOmniPass), &buffer_lights_pos, bpLightPositions , "QGLLightPositionData" );
|
||||
initUniformBuffer(shaders.value(srLightSpotPass), &buffer_materials , bpMaterials , "QGLMaterialData" );
|
||||
initUniformBuffer(shaders.value(srLightSpotPass), &buffer_lights , bpLightParameters, "QGLLightParameterData");
|
||||
initUniformBuffer(shaders.value(srLightSpotPass), &buffer_lights_pos, bpLightPositions , "QGLLightPositionData" );
|
||||
ShaderRole roles[] = {srLightOmniPass, srLightSpotPass};
|
||||
QOpenGLShaderProgram * prog = 0;
|
||||
for (int p = 0; p < 2; ++p) {
|
||||
if (!bindShader(roles[p], &prog)) continue;
|
||||
for (int i = 0; i < 5; ++i)
|
||||
prog->setUniformValue(QString("tex_%1").arg(i).toLatin1().constData(), i);
|
||||
prog->setUniformValue("tex_coeffs[0]", (int)Renderer::dbrBuffersCount);
|
||||
prog->setUniformValue("tex_env", (int)Renderer::dbrBuffersCount+1);
|
||||
}
|
||||
if (bindShader(srFinalPass, &prog)) {
|
||||
prog->setUniformValue("tex_g1" , 0);
|
||||
prog->setUniformValue("tex_s_0", 1);
|
||||
prog->setUniformValue("tex_s_1", 2);
|
||||
prog->setUniformValue("tex_t_0", 3);
|
||||
prog->setUniformValue("tex_t_1", 4);
|
||||
}
|
||||
if (bindShader(srGeometryPass, &prog)) {
|
||||
setUniformMaps(prog);
|
||||
}
|
||||
if (bindShader(srTonemapPass, &prog)) {
|
||||
prog->setUniformValue("tex_0", 0);
|
||||
prog->setUniformValue("tex_sum", 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Renderer::releaseShader() {
|
||||
view->glUseProgram(0);
|
||||
}
|
||||
|
||||
|
||||
void Renderer::fillObjectsBuffer(const ObjectBaseList & ol, RenderPass pass) {
|
||||
cur_objects_.resize(ol.size());
|
||||
for (int i = 0; i < ol.size(); ++i) {
|
||||
Object & so(cur_objects_[i]);
|
||||
ObjectBase * o = ol[i];
|
||||
if (o->material()) {
|
||||
so.material = o->material()->_index;
|
||||
so.color = QVector4D(1,1,1,1);
|
||||
} else {
|
||||
so.material = 0;
|
||||
so.color = QColor2QVector(o->color());
|
||||
}
|
||||
so.object_id = o->id();
|
||||
o->worldTransform().transposed().copyDataTo(so.modelmatrix);
|
||||
//qDebug() << "load obj" << o->name() << o->worldTransform();
|
||||
}
|
||||
//qDebug() << "fillObjectsBuffer" << ol.size();
|
||||
|
||||
}
|
||||
|
||||
|
||||
void Renderer::renderObjects(Scene & scene, RenderPass pass) {
|
||||
QOpenGLExtraFunctions * f = view;
|
||||
QMapIterator<Mesh*, ObjectBaseList> it(scene.geometries_used[pass]);
|
||||
bool emit_pos_change = false;
|
||||
while (it.hasNext()) {
|
||||
it.next();
|
||||
Mesh * mesh = it.key();
|
||||
if (mesh->isObjectsChanged(pass)) {
|
||||
mesh->setObjectsChanged(pass, false);
|
||||
emit_pos_change = true;
|
||||
fillObjectsBuffer(it.value(), pass);
|
||||
//qDebug() << "loadObjects" << pass << cur_objects_.size();
|
||||
mesh->loadObjects(f, cur_objects_, pass);
|
||||
}
|
||||
if (mesh->isSelectionChanged(pass) && edit_mode) {
|
||||
mesh->setSelectionChanged(pass, false);
|
||||
fillSelectionsBuffer(rend_selection.cur_selections_, it.value());
|
||||
//qDebug() << "fillSelectionsBuffer" << pass << rend_selection.cur_selections_.size();
|
||||
mesh->loadSelections(f, rend_selection.cur_selections_, pass);
|
||||
}
|
||||
//qDebug() << "draw" << pass << it.value().size();
|
||||
mesh->draw(f, it.value().size(), pass);
|
||||
}
|
||||
if (emit_pos_change) emit view->objectsPositionChanged();
|
||||
}
|
||||
|
||||
|
||||
void Renderer::renderLight(int first_wr_buff, bool clear_only) {
|
||||
QOpenGLShaderProgram * prog = 0;
|
||||
Camera * cam = view->camera();
|
||||
for (int i = 0; i < 2; ++i) {
|
||||
view->glActiveTexture(GL_TEXTURE0 + Renderer::dbrBuffersCount + i);
|
||||
view->glBindTexture(GL_TEXTURE_2D, tex_coeff[i]);
|
||||
}
|
||||
fbo_ds.bindColorTextures();
|
||||
fbo_out.bind();
|
||||
tex_env.bind((int)Renderer::dbrBuffersCount+1);
|
||||
typedef QPair<Renderer::ShaderRole, Light::Type> PassPair;
|
||||
QVector<PassPair> passes;
|
||||
passes << PassPair(srLightOmniPass, Light::Omni) << PassPair(srLightSpotPass, Light::Cone);
|
||||
QColor back = view->fogColor();
|
||||
back.setAlpha(0);
|
||||
foreach (PassPair pass, passes) {
|
||||
if (bindShader(pass.first, &prog)) {
|
||||
fbo_out.setWriteBuffer(first_wr_buff + pass.second);
|
||||
glClearFramebuffer(back, false);
|
||||
if (clear_only) continue;
|
||||
setUniformCamera(prog, cam);
|
||||
setUniformViewCorners(prog, cam);
|
||||
prog->setUniformValue("lights_start", lights_start[pass.second]);
|
||||
prog->setUniformValue("lights_count", (int)cur_lights[pass.second].size());
|
||||
prog->setUniformValue("fog_color", view->fogColor());
|
||||
prog->setUniformValue("fog_decay", qMax(view->fogDecay(), 0.001f));
|
||||
prog->setUniformValue("fog_density", view->fogDensity());
|
||||
prog->setUniformValue("view_mat", cam->viewMatrix().inverted().toGenericMatrix<3,3>());
|
||||
renderQuad(prog, quad, cam);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Renderer::renderScene() {
|
||||
initShaders();
|
||||
tex_env.load();
|
||||
QOpenGLExtraFunctions * f = view;
|
||||
Scene & scene(*(view->scene()));
|
||||
Camera * cam = view->camera();
|
||||
QOpenGLShaderProgram * prog = 0;
|
||||
bool scene_changed = scene.prepare();
|
||||
scene.destroyUnused(f);
|
||||
|
||||
/// reload materials on change
|
||||
if (scene_changed || scene.need_reload_materials) {
|
||||
rend_selection.generateObjectsID(scene);
|
||||
reloadMaterials(scene);
|
||||
if (edit_mode)
|
||||
recreateMaterialThumbnails();
|
||||
emit view->materialsChanged();
|
||||
}
|
||||
|
||||
/// material thumbnails
|
||||
if (edit_mode && !scene_changed) {
|
||||
rend_mat.procQueue();
|
||||
}
|
||||
|
||||
/// lights
|
||||
cur_lights = scene.lights_used;
|
||||
bool use_camlight = (camera_light_mode == QGLView::clmOn);
|
||||
if ((camera_light_mode == QGLView::clmAuto) && cur_lights.isEmpty())
|
||||
use_camlight = true;
|
||||
if (use_camlight) {
|
||||
cur_lights[Light::Omni] << cam_light;
|
||||
cam_light->setPos(cam->pos());
|
||||
}
|
||||
if (scene.lights_changed) {
|
||||
scene.lights_changed = false;
|
||||
reloadLightsParameters(cur_lights);
|
||||
}
|
||||
reloadLightsPositions(cam);
|
||||
|
||||
/// selection
|
||||
if (edit_mode) {
|
||||
rend_selection.renderSelection(scene);
|
||||
}
|
||||
|
||||
/// solid geometry pass
|
||||
fbo_ds.bind();
|
||||
glEnableDepth();
|
||||
glClearFramebuffer();
|
||||
if (bindShader(srGeometryPass, &prog)) {
|
||||
setUniformCamera(prog, cam);
|
||||
textures_empty.bind(f, tarEmpty);
|
||||
textures_maps .bind(f, tarMaps );
|
||||
renderObjects(scene, rpSolid);
|
||||
}
|
||||
fbo_ds.release();
|
||||
|
||||
/// lighting passes
|
||||
renderLight(obrSolidOmni, scene.geometries_used[rpSolid].isEmpty());
|
||||
|
||||
/// transparent geometry pass
|
||||
fbo_ds.bind();
|
||||
glEnableDepth();
|
||||
glClearFramebuffer(Qt::black, false);
|
||||
if (bindShader(srGeometryPass, &prog)) {
|
||||
renderObjects(scene, rpTransparent);
|
||||
}
|
||||
fbo_ds.release();
|
||||
|
||||
/// lighting passes
|
||||
renderLight(obrTransparentOmni, scene.geometries_used[rpTransparent].isEmpty());
|
||||
|
||||
/// blending layers
|
||||
if (bindShader(srFinalPass, &prog)) {
|
||||
fbo_out.bindColorTexture(obrSolidOmni , 1);
|
||||
fbo_out.bindColorTexture(obrSolidSpot , 2);
|
||||
fbo_out.bindColorTexture(obrTransparentOmni, 3);
|
||||
fbo_out.bindColorTexture(obrTransparentSpot, 4);
|
||||
fbo_out.setWriteBuffer(obrSum);
|
||||
renderQuad(prog, quad);
|
||||
}
|
||||
|
||||
/// tonemapping
|
||||
if (tone_proc.process())
|
||||
fbo_out.bind();
|
||||
if (bindShader(srTonemapPass, &prog)) {
|
||||
prog->setUniformValue("gamma", gamma_);
|
||||
prog->setUniformValue("frame_max", tone_proc.frameMax());
|
||||
fbo_out.bindColorTexture(obrSum, 0);
|
||||
fbo_out.setWriteBuffer(obrTonemap);
|
||||
renderQuad(prog, quad);
|
||||
} else
|
||||
fbo_out.blit(obrSum, fbo_out.id(), obrTonemap, fbo_out.rect(), fbo_out.rect());
|
||||
fbo_out.release();
|
||||
|
||||
/// apply hovers and selection frame
|
||||
if (edit_mode) {
|
||||
rend_selection.drawSelection(fbo_out, obrTonemap);
|
||||
rend_service.renderService();
|
||||
} else {
|
||||
fbo_out.blit(obrTonemap, 0, 0, fbo_out.rect(), QRect(QPoint(), view->size()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Renderer::setCameraLightMode(int m) {
|
||||
camera_light_mode = m;
|
||||
view->scene()->setLightsChanged();
|
||||
}
|
||||
130
renderer.h
@@ -1,130 +0,0 @@
|
||||
/*
|
||||
QGL Renderer
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef RENDERER_H
|
||||
#define RENDERER_H
|
||||
|
||||
#include "renderer_base.h"
|
||||
#include "renderer_material.h"
|
||||
#include "renderer_service.h"
|
||||
#include "renderer_selection.h"
|
||||
#include "tonemapping_proc.h"
|
||||
#include "glcubemap.h"
|
||||
#include <QQueue>
|
||||
|
||||
|
||||
class Renderer: public RendererBase {
|
||||
friend class QGLView;
|
||||
friend class MouseController;
|
||||
friend class RendererMaterial;
|
||||
friend class RendererService;
|
||||
friend class RendererSelection;
|
||||
friend class TonemappingProc;
|
||||
enum ShaderRole {
|
||||
// Selection
|
||||
srSelectionFill,
|
||||
srSelectionHalo,
|
||||
srSelectionApply,
|
||||
srSelectionFrame,
|
||||
|
||||
// Service
|
||||
srServiceFill,
|
||||
srServiceFrame,
|
||||
srServiceLine,
|
||||
|
||||
// Deferred shading
|
||||
srGeometryPass,
|
||||
srLightOmniPass,
|
||||
srLightSpotPass,
|
||||
srFinalPass,
|
||||
srTonemapPass,
|
||||
};
|
||||
enum DeferredBufferRole {
|
||||
dbrDiffuse,
|
||||
dbrNormalZ,
|
||||
dbrSpecularReflect,
|
||||
dbrEmissionRough,
|
||||
dbrSpeedBitangXY,
|
||||
|
||||
dbrBuffersCount,
|
||||
};
|
||||
enum OutBufferRole {
|
||||
obrTonemap,
|
||||
obrSum,
|
||||
obrSolidOmni,
|
||||
obrSolidSpot,
|
||||
obrTransparentOmni,
|
||||
obrTransparentSpot,
|
||||
|
||||
obrBuffersCount,
|
||||
};
|
||||
|
||||
public:
|
||||
Renderer(QGLView * view_);
|
||||
virtual ~Renderer();
|
||||
|
||||
void init(int width, int height);
|
||||
void resize(int width, int height);
|
||||
void reloadShaders();
|
||||
void renderScene();
|
||||
void setCameraLightMode(int m);
|
||||
int cameraLightMode() const {return camera_light_mode;}
|
||||
|
||||
QImage materialThumbnail(Material * m) {return rend_mat.materialThumbnail(m);}
|
||||
void recreateMaterialThumbnails(bool force_all = false) {rend_mat.recreateMaterialThumbnails(force_all);}
|
||||
|
||||
protected:
|
||||
void fillObjectsBuffer(const ObjectBaseList & ol, RenderPass pass);
|
||||
void reloadObjects();
|
||||
void renderObjects(Scene & scene, RenderPass pass);
|
||||
void renderLight(int first_wr_buff, bool clear_only);
|
||||
|
||||
bool bindShader(ShaderRole role, QOpenGLShaderProgram ** ret = 0);
|
||||
bool bindShader(QOpenGLShaderProgram * sp);
|
||||
void initShaders();
|
||||
void releaseShader();
|
||||
|
||||
private:
|
||||
float gamma_;
|
||||
int camera_light_mode;
|
||||
bool edit_mode, need_init_shaders, need_render_sum;
|
||||
Framebuffer fbo_ds, fbo_out;
|
||||
QMap<ShaderRole, QString> shader_files;
|
||||
QMap<ShaderRole, QStringList> shader_defines;
|
||||
QMap<ShaderRole, QOpenGLShaderProgram*> shaders;
|
||||
QOpenGLShaderProgram * shader_fxaa;
|
||||
|
||||
RendererMaterial rend_mat;
|
||||
RendererService rend_service;
|
||||
RendererSelection rend_selection;
|
||||
TonemappingProc tone_proc;
|
||||
|
||||
Mesh * quad;
|
||||
Light * cam_light;
|
||||
CubeTexture tex_env;
|
||||
|
||||
QPoint mouse_pos;
|
||||
QRect mouse_rect;
|
||||
QMatrix4x4 prev_view, prev_proj;
|
||||
QMatrix3x3 nm;
|
||||
QVector4D corner_dirs[4];
|
||||
QVector<QVector3D> hcontent;
|
||||
QMap<int, QList<Light*>> cur_lights;
|
||||
};
|
||||
|
||||
#endif // RENDERER_H
|
||||
@@ -1,67 +0,0 @@
|
||||
/*
|
||||
QGL RendererBase
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef RENDERER_BASE_H
|
||||
#define RENDERER_BASE_H
|
||||
|
||||
#include "glshaders_types.h"
|
||||
#include "gltexturearray.h"
|
||||
#include "glbuffer.h"
|
||||
|
||||
|
||||
class RendererBase {
|
||||
public:
|
||||
RendererBase(QGLView * view_);
|
||||
~RendererBase();
|
||||
|
||||
protected:
|
||||
void initTextureArrays();
|
||||
void initUniformBuffer (QOpenGLShaderProgram * prog, Buffer * buffer, int bind_point, const char * blockName);
|
||||
void setUniformHalo (QOpenGLShaderProgram * prog, const char * type, QColor color, float fill);
|
||||
void setUniformMaps (QOpenGLShaderProgram * prog);
|
||||
void setUniformCamera (QOpenGLShaderProgram * prog, Camera * cam, bool matrices = true, QSize viewport = QSize());
|
||||
void setUniformViewCorners(QOpenGLShaderProgram * prog, Camera * cam, QSize viewport = QSize());
|
||||
void fillSelectionsBuffer(QVector<uchar> & buffer, const ObjectBaseList & ol);
|
||||
void fillSelectionsBuffer(QVector<uchar> & buffer, bool yes, int size);
|
||||
void reloadMaterials(Scene & scene);
|
||||
void reloadLightsParameters(const QMap<int, QList<Light*>> & lights);
|
||||
void reloadLightsPositions (Camera * cam);
|
||||
void markReloadTextures();
|
||||
void setMapsSize(QSize sz);
|
||||
void initQuad(Mesh * mesh, QMatrix4x4 mat = QMatrix4x4());
|
||||
void renderQuad(QOpenGLShaderProgram * prog, Mesh * mesh, Camera * cam = 0, bool uniforms = true);
|
||||
void initCoeffTextures();
|
||||
void createCoeffTexture(GLuint & id, const void * data, int size, int channels = 1);
|
||||
|
||||
QGLView * view;
|
||||
TextureManager * textures_manager;
|
||||
QVector<QGLEngineShaders::Object> cur_objects_;
|
||||
QVector<QGLEngineShaders::QGLMaterial> cur_materials_;
|
||||
QVector<QGLEngineShaders::QGLLightParameter> cur_lights_params_;
|
||||
QVector<QGLEngineShaders::QGLLightPosition> cur_lights_pos_;
|
||||
Buffer buffer_materials;
|
||||
Buffer buffer_lights, buffer_lights_pos;
|
||||
Texture2DArray textures_empty, textures_maps;
|
||||
QSize maps_size;
|
||||
uint maps_hash;
|
||||
GLuint tex_coeff[2];
|
||||
QMap<int, int> lights_start;
|
||||
QList<Light*> current_lights;
|
||||
};
|
||||
|
||||
#endif // RENDERER_BASE_H
|
||||
@@ -1,132 +0,0 @@
|
||||
/*
|
||||
QGL RendererMaterial
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#define GL_GLEXT_PROTOTYPES
|
||||
#include <QOpenGLExtraFunctions>
|
||||
#include "renderer_material.h"
|
||||
#include "renderer.h"
|
||||
#include "qglview.h"
|
||||
#include "glmesh.h"
|
||||
#include "gltexture_manager.h"
|
||||
#include <qad_types.h>
|
||||
|
||||
using namespace QGLEngineShaders;
|
||||
|
||||
|
||||
RendererMaterial::RendererMaterial(Renderer * r_)
|
||||
: r(r_), fbo_mat_thumb(r->view, 6, true , GL_RGBA16F) {
|
||||
mat_sphere = Primitive::ellipsoid(16, 16);
|
||||
mat_camera = new Camera();
|
||||
mat_camera->setPos(QVector3D(2, 2, 2));
|
||||
mat_camera->setAim(QVector3D());
|
||||
mat_camera->setFOV(45.);
|
||||
mat_light = new Light();
|
||||
mat_light->setPos(QVector3D(50, 100, 25));
|
||||
last_thumb_material = 0;
|
||||
}
|
||||
|
||||
|
||||
RendererMaterial::~RendererMaterial() {
|
||||
delete mat_sphere;
|
||||
delete mat_camera;
|
||||
delete mat_light;
|
||||
}
|
||||
|
||||
|
||||
void RendererMaterial::init(int width, int height) {
|
||||
resize(width, height);
|
||||
}
|
||||
|
||||
|
||||
void RendererMaterial::resize(int width, int height) {
|
||||
fbo_mat_thumb.enablePixelBuffer();
|
||||
fbo_mat_thumb.resize(256, 256);
|
||||
}
|
||||
|
||||
|
||||
void RendererMaterial::renderMaterial(Material * m) {
|
||||
//qDebug() << "renderMaterial" << m;
|
||||
last_thumb_material = m;
|
||||
QOpenGLShaderProgram * prog = 0;
|
||||
QOpenGLExtraFunctions * f = r->view;
|
||||
fbo_mat_thumb.bind();
|
||||
glEnableDepth();
|
||||
glClearFramebuffer(QColor(0,0,0,0));
|
||||
if (r->bindShader(Renderer::srGeometryPass, &prog)) {
|
||||
r->setUniformMaps(prog);
|
||||
r->setUniformCamera(prog, mat_camera, true, fbo_mat_thumb.size());
|
||||
//qDebug() << mat_camera->viewMatrix();
|
||||
r->textures_empty.bind(f, tarEmpty);
|
||||
r->textures_maps .bind(f, tarMaps );
|
||||
Object o;
|
||||
o.material = m->_index;
|
||||
mat_sphere->loadObject(f, o);
|
||||
mat_sphere->draw(f, 1);
|
||||
}
|
||||
fbo_mat_thumb.bindColorTextures();
|
||||
fbo_mat_thumb.bindDepthTexture(5);
|
||||
fbo_mat_thumb.setWriteBuffer(5);
|
||||
if (r->bindShader(Renderer::srLightOmniPass, &prog)) {
|
||||
r->setUniformCamera(prog, mat_camera, true, fbo_mat_thumb.size());
|
||||
r->setUniformViewCorners(prog, mat_camera, fbo_mat_thumb.size());
|
||||
for (int i = 0; i < 5; ++i)
|
||||
prog->setUniformValue(QString("tex_%1").arg(i).toLatin1().constData(), i);
|
||||
prog->setUniformValue("tex_d", 5);
|
||||
prog->setUniformValue("lights_start", 0);
|
||||
prog->setUniformValue("lights_count", 1);
|
||||
QMap<int, QList<Light*>> mat_l;
|
||||
mat_l[Light::Omni] << mat_light;
|
||||
r->reloadLightsParameters(mat_l);
|
||||
r->reloadLightsPositions(mat_camera);
|
||||
glClearFramebuffer(r->view->backColor(), false);
|
||||
r->renderQuad(prog, r->quad, mat_camera);
|
||||
r->view->scene()->setLightsChanged();
|
||||
}
|
||||
fbo_mat_thumb.queryImage(5);
|
||||
fbo_mat_thumb.release();
|
||||
}
|
||||
|
||||
|
||||
void RendererMaterial::procQueue() {
|
||||
if (last_thumb_material) {
|
||||
mat_thumbnails[last_thumb_material] = fbo_mat_thumb.getImage();
|
||||
emit r->view->materialThumbnailCreated(last_thumb_material);
|
||||
last_thumb_material = 0;
|
||||
}
|
||||
if (!mat_thumb_queue.isEmpty())
|
||||
renderMaterial(mat_thumb_queue.dequeue());
|
||||
}
|
||||
|
||||
|
||||
QImage RendererMaterial::materialThumbnail(Material * m) {
|
||||
return mat_thumbnails.value(m);
|
||||
}
|
||||
|
||||
|
||||
void RendererMaterial::recreateMaterialThumbnails(bool force_all) {
|
||||
if (force_all) {
|
||||
mat_thumb_queue.clear();
|
||||
//qDebug() << "recreateMaterialThumbnails" << view->scene_->materials;
|
||||
foreach (Material * m, r->view->scene()->materials)
|
||||
mat_thumb_queue.enqueue(m);
|
||||
} else {
|
||||
foreach (Material * m, r->view->scene()->changed_materials)
|
||||
if (!mat_thumb_queue.contains(m))
|
||||
mat_thumb_queue.enqueue(m);
|
||||
}
|
||||
}
|
||||
@@ -1,51 +0,0 @@
|
||||
/*
|
||||
QGL RendererMaterial
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef RENDERER_MATERIAL_H
|
||||
#define RENDERER_MATERIAL_H
|
||||
|
||||
#include "glframebuffer.h"
|
||||
#include <QQueue>
|
||||
|
||||
|
||||
class RendererMaterial {
|
||||
friend class QGLView;
|
||||
public:
|
||||
RendererMaterial(Renderer * r_);
|
||||
virtual ~RendererMaterial();
|
||||
|
||||
void init(int width, int height);
|
||||
void resize(int width, int height);
|
||||
|
||||
QImage materialThumbnail(Material * m);
|
||||
void recreateMaterialThumbnails(bool force_all = false);
|
||||
void renderMaterial(Material * m);
|
||||
void procQueue();
|
||||
|
||||
private:
|
||||
Renderer * r;
|
||||
Framebuffer fbo_mat_thumb;
|
||||
Mesh * mat_sphere;
|
||||
Camera * mat_camera;
|
||||
Light * mat_light;
|
||||
QMap<Material*, QImage> mat_thumbnails;
|
||||
Material * last_thumb_material;
|
||||
QQueue<Material*> mat_thumb_queue;
|
||||
};
|
||||
|
||||
#endif // RENDERER_MATERIAL_H
|
||||
@@ -1,65 +0,0 @@
|
||||
/*
|
||||
QGL RendererSelection
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef RENDERER_SELECTION_H
|
||||
#define RENDERER_SELECTION_H
|
||||
|
||||
#include "renderer_service.h"
|
||||
#include <QHash>
|
||||
|
||||
|
||||
class RendererSelection {
|
||||
friend class QGLView;
|
||||
friend class MouseController;
|
||||
friend class Renderer;
|
||||
friend class RendererService;
|
||||
|
||||
public:
|
||||
RendererSelection(Renderer * r_);
|
||||
virtual ~RendererSelection();
|
||||
|
||||
void init(int width, int height);
|
||||
void resize(int width, int height);
|
||||
|
||||
protected:
|
||||
enum SelectionBufferRole {
|
||||
sbrSrcHover,
|
||||
sbrSrcSelect,
|
||||
sbrHovered,
|
||||
sbrSelected,
|
||||
sbrHoveredFXAA,
|
||||
sbrSelectedFXAA,
|
||||
};
|
||||
|
||||
void generateObjectsID(Scene & scene);
|
||||
void renderSelection(Scene & scene);
|
||||
void renderSelectionFrame();
|
||||
void drawSelection(Framebuffer & fbo_out, int index_out = 0);
|
||||
|
||||
private:
|
||||
Renderer * r;
|
||||
Framebuffer fbo_selection;
|
||||
Mesh * sel_frame;
|
||||
float line_thick_, scale_;
|
||||
QVector<uchar> cur_selections_;
|
||||
QHash<uint, ObjectBase * > ids;
|
||||
QHash<uint, ObjectBase * > aim_ids;
|
||||
uint id_hover;
|
||||
};
|
||||
|
||||
#endif // RENDERER_selection_H
|
||||
19
shaders.qrc
@@ -1,19 +0,0 @@
|
||||
<RCC>
|
||||
<qresource prefix="/">
|
||||
<file>shaders/ds_final.glsl</file>
|
||||
<file>shaders/ds_geom.glsl</file>
|
||||
<file>shaders/ds_light.glsl</file>
|
||||
<file>shaders/ds_tonemap.glsl</file>
|
||||
<file>shaders/fxaa.frag</file>
|
||||
<file>shaders/fxaa.vert</file>
|
||||
<file>shaders/fxaa_v3.h</file>
|
||||
<file>shaders/selection.glsl</file>
|
||||
<file>shaders/selection_apply.glsl</file>
|
||||
<file>shaders/selection_frame.glsl</file>
|
||||
<file>shaders/selection_halo.glsl</file>
|
||||
<file>shaders/service_fill.glsl</file>
|
||||
<file>shaders/service_frame.glsl</file>
|
||||
<file>shaders/service_line.glsl</file>
|
||||
<file>shaders/sum.glsl</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
@@ -3,15 +3,21 @@
|
||||
out vec3 geom_normal;
|
||||
out mat3 TBN;
|
||||
out vec4 object_color;
|
||||
out float object_flags;
|
||||
|
||||
const vec3 luma = vec3(0.299, 0.587, 0.114);
|
||||
|
||||
void main(void) {
|
||||
qgl_MaterialIndex = qgl_Material;
|
||||
qgl_FragTexture = qgl_Texture;
|
||||
gl_Position = qgl_ftransform();
|
||||
qgl_FragTexture = qgl_getFragTexture();
|
||||
|
||||
geom_normal = normalize(qgl_Normal * qgl_getNormalMatrix());
|
||||
TBN = qgl_getTangentMatrix() * mat3(qgl_Tangent, qgl_Bitangent, qgl_Normal);
|
||||
object_color = qgl_ObjectColor;
|
||||
object_flags = qgl_ObjectFlags;
|
||||
|
||||
float height = dot(qgl_materialTexture(QGL_MAP_RELIEF, qgl_FragTexture, vec4(0.)).rgb, luma);
|
||||
gl_Position = qgl_ViewProjMatrix * (qgl_ModelMatrix * (vec4(qgl_Vertex + qgl_Normal * height, 1.)));//qgl_ftransform();
|
||||
}
|
||||
|
||||
|
||||
@@ -20,9 +26,11 @@ void main(void) {
|
||||
in vec3 geom_normal;
|
||||
in mat3 TBN;
|
||||
in vec4 object_color;
|
||||
in float object_flags;
|
||||
|
||||
uniform vec2 dt;
|
||||
uniform float z_near;
|
||||
uniform int out_index_normal = dbrNormalZ, out_index_metal = dbrMetalRoughReflectFlags;
|
||||
|
||||
const vec3 luma = vec3(0.299, 0.587, 0.114);
|
||||
const float _pe = 2.4e-7;
|
||||
@@ -30,9 +38,13 @@ const float _pe = 2.4e-7;
|
||||
void main(void) {
|
||||
vec2 tc = qgl_FragTexture.xy;
|
||||
|
||||
vec4 diffuse = qgl_materialTexture(QGL_MAP_DIFFUSE, tc, vec4(0)) * object_color;
|
||||
vec4 diffuse = qgl_materialTexture(QGL_MAP_DIFFUSE, tc, vec4(0.)) * object_color;
|
||||
diffuse.rgb *= qgl_material[qgl_MaterialIndex].color_diffuse.rgb;
|
||||
diffuse.a *= (1.f - qgl_material[qgl_MaterialIndex].transparency);
|
||||
#ifdef SOLID
|
||||
if(diffuse.a < 0.5)
|
||||
discard;
|
||||
#endif
|
||||
diffuse.a *= (1. - qgl_material[qgl_MaterialIndex].transparency);
|
||||
|
||||
vec3 normal, dn;
|
||||
dn = qgl_materialTexture(QGL_MAP_NORMAL, tc, -vec4(0.5, 0.5, 1., 0.)).xyz;
|
||||
@@ -42,28 +54,27 @@ void main(void) {
|
||||
dn *= dn_sl / (length(dn) + 1E-6);
|
||||
normal = normalize(geom_normal + dn);
|
||||
|
||||
float metalness = dot(qgl_materialTexture(QGL_MAP_METALNESS, tc, vec4(0)).rgb, luma);
|
||||
float metalness = dot(qgl_materialTexture(QGL_MAP_METALNESS, tc, vec4(0.)).rgb, luma);
|
||||
metalness = clamp(metalness, 0, 1);
|
||||
|
||||
float roughness = dot(qgl_materialTexture(QGL_MAP_ROUGHNESS, tc, vec4(0)).rgb, luma);
|
||||
float roughness = dot(qgl_materialTexture(QGL_MAP_ROUGHNESS, tc, vec4(0.)).rgb, luma);
|
||||
roughness = clamp(roughness, 0.0001, 0.9999);
|
||||
|
||||
float reflectivity = clamp(qgl_material[qgl_MaterialIndex].reflectivity, 0., 1.);
|
||||
|
||||
vec4 emission = qgl_materialTexture(QGL_MAP_EMISSION, tc, vec4(0));
|
||||
vec4 emission = qgl_materialTexture(QGL_MAP_EMISSION, tc, vec4(0.));
|
||||
emission *= qgl_material[qgl_MaterialIndex].color_emission;
|
||||
|
||||
float height = dot(qgl_materialTexture(QGL_MAP_RELIEF, tc, vec4(0)).rgb, luma);
|
||||
|
||||
float z = gl_FragCoord.z;
|
||||
z = z + z - 1;
|
||||
z = z + z - 1.;
|
||||
z = ((_pe - 2.) * z_near) / (z + _pe - 1.); // infinite depth
|
||||
|
||||
qgl_FragData[0] = vec4(diffuse .rgba);
|
||||
qgl_FragData[1] = vec4(normal .xyz, z);
|
||||
qgl_FragData[2] = vec4(metalness, roughness, reflectivity, 0);
|
||||
qgl_FragData[3] = vec4(emission.rgb, 0/*bn.x*/);
|
||||
//qgl_FragData[4] = vec4(speed.xy, bn.yz);
|
||||
|
||||
qgl_FragData[dbrDiffuse ] = vec4(diffuse .rgba);
|
||||
qgl_FragData[out_index_normal] = vec4(normal .xyz, z);
|
||||
qgl_FragData[out_index_metal ] = vec4(metalness, roughness, reflectivity, object_flags);
|
||||
qgl_FragData[dbrEmission ] = vec4(emission.rgb, 0./*bn.x*/);
|
||||
//qgl_FragData[dbrSpeedBitangXY] = vec4(speed.xy, bn.yz);
|
||||
qgl_FragData[dbrGeoNormal ] = vec4(normalize(geom_normal), 1.);
|
||||
|
||||
//ivec2 itc = ivec2(gl_FragCoord.xy);
|
||||
//qgl_FragData[0].rgb = vec3(dot(n,vec3(0,0,1)));
|
||||
|
||||
@@ -18,22 +18,139 @@ in vec3 view_dir, world_dir;
|
||||
|
||||
uniform vec2 dt;
|
||||
uniform float z_near;
|
||||
uniform sampler2D tex_coeffs[2];
|
||||
uniform sampler2D tex_0, tex_1, tex_2, tex_3, tex_4;
|
||||
uniform sampler2D tex_coeff_brdf, tex_noise;
|
||||
uniform sampler2D tex_0, tex_1, tex_2, tex_3, tex_4, tex_5, tex_sh;
|
||||
//uniform sampler2DShadow tex_shadow[16];
|
||||
uniform vec2 shadow_size;
|
||||
uniform sampler2DArrayShadow tex_shadows_cone;
|
||||
uniform sampler2DArray tex_depths_cone;
|
||||
uniform samplerCubeArrayShadow tex_shadows_omni;
|
||||
uniform samplerCubeArray tex_depths_omni;
|
||||
uniform bool soft_shadows_enabled = false, shadows_enabled = false;
|
||||
uniform float soft_shadows_quality = 1.;
|
||||
uniform int soft_shadows_samples = 16, noise_size = 64;
|
||||
uniform samplerCube tex_env;
|
||||
uniform int lights_start, lights_count;
|
||||
|
||||
uniform vec4 fog_color = vec4(0.5, 0.5, 0.5, 1);
|
||||
uniform float fog_decay = 10, fog_density = 0;
|
||||
uniform vec4 fog_color = vec4(0.5, 0.5, 0.5, 1.);
|
||||
uniform float fog_decay = 10., fog_density = 0.;
|
||||
uniform mat3 view_mat;
|
||||
const float _pe = 2.4e-7;
|
||||
|
||||
const vec3 luma = vec3(0.299, 0.587, 0.114);
|
||||
const float _min_rough = 1.e-8, max_lod = 8;
|
||||
const float _min_rough = 1.e-8, max_lod = 8.;
|
||||
const float PI = 3.1416;
|
||||
|
||||
ivec2 tc;
|
||||
vec4 pos, lpos, shp;
|
||||
vec3 li, si, ldir, halfV, bn, bn2, lwdir;
|
||||
//vec3 vds, vds2;
|
||||
float rough_diff, rough_spec, dist, NdotL, NdotH, spot, ldist, diff, spec, sdist, shadow;
|
||||
vec3 normal, geom_normal, vds, vds2;
|
||||
float rough_diff, rough_spec, dist, NdotL, NdotH, spot, ldist, diff, spec, sdist;
|
||||
uint flags;
|
||||
|
||||
|
||||
vec4 mapScreenToShadow(in int light_index, in vec3 offset) {
|
||||
vec4 shp = qgl_light_position[light_index].shadow_matrix * (pos + vec4(offset, 0));
|
||||
//shp.z += 0.5;
|
||||
return shp;
|
||||
}
|
||||
|
||||
|
||||
#ifdef SPOT
|
||||
|
||||
float getShadowCone(in vec3 uvz, in int layer) {
|
||||
/*vec2 uvpix = uvz.xy * shadow_size + vec2(0.5f);
|
||||
vec2 uvp = fract(uvpix), iuvp = vec2(1.f) - uvp;
|
||||
vec4 gt = textureGather(tex_shadows_cone, vec3(floor(uvpix.xy) / shadow_size, layer), 0);
|
||||
vec4 uvv;
|
||||
uvv[0] = iuvp.x * uvp.y;
|
||||
uvv[1] = uvp.x * uvp.y;
|
||||
uvv[2] = uvp.x * iuvp.y;
|
||||
uvv[3] = iuvp.x * iuvp.y;
|
||||
shadow_dz = max(max(uvz.z - gt[0], uvz.z - gt[1]), max(uvz.z - gt[2], uvz.z - gt[3]));
|
||||
return clamp(dot(step(vec4(uvz.z), gt), uvv), 0, 1);*/
|
||||
float z = 1. - 1. / (uvz.z - z_near + 1.);
|
||||
return texture(tex_shadows_cone, vec4(uvz.xy, layer, z));
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
float getShadowOmni(in vec4 uvwz, in int layer) {
|
||||
/*vec3 uvpix = uvwz.xyz * vec3(shadow_size.x) + vec3(0.5f);
|
||||
vec3 uvp = fract(uvpix), iuvp = vec3(1.f) - uvp;
|
||||
vec4 gt = textureGather(tex_shadows_omni, vec4(floor(uvpix.xyz) / vec3(shadow_size.x), layer), 0);
|
||||
vec4 uvv;
|
||||
uvv[0] = iuvp.y * uvp.z;
|
||||
uvv[1] = uvp.y * uvp.z;
|
||||
uvv[2] = uvp.y * iuvp.z;
|
||||
uvv[3] = iuvp.y * iuvp.z;
|
||||
return clamp(dot(step(vec4(uvwz.w), gt), uvv), 0, 1);*/
|
||||
float d = 1. - 1. / (uvwz.w - z_near + 1.);
|
||||
return texture(tex_shadows_omni, vec4(uvwz.xyz, layer), d);
|
||||
//return step(uvwz.w, gt[3]);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
uint hash(uint x) {
|
||||
x += (x << 10u);
|
||||
x ^= (x >> 6u);
|
||||
x += (x << 3u);
|
||||
x ^= (x >> 11u);
|
||||
x += (x << 15u);
|
||||
return x;
|
||||
}
|
||||
uint hash( uvec2 v ) { return hash( v.x ^ hash(v.y) ); }
|
||||
uint hash( uvec3 v ) { return hash( v.x ^ hash(v.y) ^ hash(v.z) ); }
|
||||
uint hash( uvec4 v ) { return hash( v.x ^ hash(v.y) ^ hash(v.z) ^ hash(v.w) ); }
|
||||
float floatConstruct( uint m ) {
|
||||
const uint ieeeMantissa = 0x007FFFFFu; // binary32 mantissa bitmask
|
||||
const uint ieeeOne = 0x3F800000u; // 1.0 in IEEE binary32
|
||||
|
||||
m &= ieeeMantissa; // Keep only mantissa bits (fractional part)
|
||||
m |= ieeeOne; // Add fractional part to 1.0
|
||||
|
||||
float f = uintBitsToFloat( m ); // Range [1:2]
|
||||
return f - 1.; // Range [0:1]
|
||||
}
|
||||
float random( float x ) { return floatConstruct(hash(floatBitsToUint(x))); }
|
||||
float random( vec2 v ) { return floatConstruct(hash(floatBitsToUint(v))); }
|
||||
float random( vec3 v ) { return floatConstruct(hash(floatBitsToUint(v))); }
|
||||
float random( vec4 v ) { return floatConstruct(hash(floatBitsToUint(v))); }
|
||||
float random( int x ) { return floatConstruct(hash(x)); }
|
||||
float random( ivec2 v ) { return floatConstruct(hash(v)); }
|
||||
float random( ivec3 v ) { return floatConstruct(hash(v)); }
|
||||
float random( ivec4 v ) { return floatConstruct(hash(v)); }
|
||||
|
||||
uvec2 noise_hash;
|
||||
void noise2init(vec2 v) {
|
||||
noise_hash = uvec2(hash(uint(v.x + 1)), hash(uint(v.y - 1)));
|
||||
}
|
||||
vec2 noise2() {
|
||||
noise2init(vec2(noise_hash));
|
||||
//return vec2(floatConstruct(noise_hash.x), floatConstruct(noise_hash.y)) * 2 - vec2(1.);
|
||||
float r = floatConstruct(noise_hash.x);
|
||||
float a = floatConstruct(noise_hash.y) * 2 * PI;
|
||||
return r * vec2(cos(a), sin(a));
|
||||
}
|
||||
|
||||
float rand(vec2 co) {
|
||||
float a = 12.9898;
|
||||
float b = 78.233;
|
||||
float c = 43758.5453;
|
||||
float d = dot(co.xy, vec2(a, b));
|
||||
float e = sin(mod(d, 3.14)) * c;
|
||||
return fract(e) - 0.5;
|
||||
}
|
||||
|
||||
vec4 qgl_lightTexture(int index, vec2 coord, vec4 tex_shift) {
|
||||
coord *= qgl_light_parameter[index].map.scale;
|
||||
vec4 t = texture(qgl_texture_array[qgl_light_parameter[index].map.array_index],
|
||||
vec3(coord, qgl_light_parameter[index].map.map_index));
|
||||
t += tex_shift;
|
||||
t.rgb *= qgl_light_parameter[index].map.amount + qgl_light_parameter[index].map.offset;
|
||||
return t;
|
||||
}
|
||||
|
||||
void calcLight(in int index, in vec3 n, in vec3 v) {
|
||||
lpos = qgl_light_position[index].position;
|
||||
@@ -45,42 +162,107 @@ void calcLight(in int index, in vec3 n, in vec3 v) {
|
||||
NdotL = max(dot(n, ldir), 1E-8);
|
||||
NdotH = max(dot(n, halfV), 1E-8);
|
||||
spot = step(1.001E-8, NdotL) * qgl_light_parameter[index].decay_intensity.w;
|
||||
vec3 light_color = qgl_light_parameter[index].color.rgb;
|
||||
#ifdef SPOT
|
||||
float scos = max(dot(-ldir, qgl_light_position[index].direction.xyz), 0.);
|
||||
spot *= scos * step(qgl_light_parameter[index].angles.w, scos);
|
||||
spot *= smoothstep(qgl_light_parameter[index].angles.w, qgl_light_parameter[index].angles.y, scos);
|
||||
/*//lwdir = mat3(mat_viewi) * qgl_Light[index].direction.xyz;
|
||||
//bn = normalize(cross(lwdir, vec3(1, 0, 0)));
|
||||
//bn2 = normalize(cross(lwdir, bn));
|
||||
float ds = ldist/200.;//max(abs(sdist) / 5000, 0.02);
|
||||
//spot *= clamp(1. - sdist, 0, 1);
|
||||
vds = ds * bn.xyz;
|
||||
vds2 = ds * bn2.xyz;
|
||||
float shadow = getShadow(index, pos.xyz, vec3(0)) * 3.;
|
||||
shadow += getShadow(index, pos.xyz, vds ) * 2.;
|
||||
shadow += getShadow(index, pos.xyz, - vds ) * 2.;
|
||||
shadow += getShadow(index, pos.xyz, - vds2 ) * 2.;
|
||||
shadow += getShadow(index, pos.xyz, + vds2 ) * 2.;
|
||||
//shadow += getShadow(index, pos.xyz, vds - vds2 ) * 1.5;
|
||||
//shadow += getShadow(index, pos.xyz, vds + vds2 ) * 1.5;
|
||||
//shadow += getShadow(index, pos.xyz, - vds - vds2 ) * 1.5;
|
||||
//shadow += getShadow(index, pos.xyz, - vds + vds2 ) * 1.5;
|
||||
//shadow += getShadow(index, pos.xyz, vds + vds );
|
||||
//shadow += getShadow(index, pos.xyz, - vds - vds );
|
||||
//shadow += getShadow(index, pos.xyz, - vds2 - vds2);
|
||||
//shadow += getShadow(index, pos.xyz, + vds2 + vds2);
|
||||
//shadow += getShadow(index, pos.xyz, vds + vds - vds2 );
|
||||
//shadow += getShadow(index, pos.xyz, - vds - vds - vds2 );
|
||||
//shadow += getShadow(index, pos.xyz, vds + vds + vds2 );
|
||||
//shadow += getShadow(index, pos.xyz, - vds - vds + vds2 );
|
||||
//shadow += getShadow(index, pos.xyz, vds - vds2 - vds2);
|
||||
//shadow += getShadow(index, pos.xyz, vds + vds2 + vds2);
|
||||
//shadow += getShadow(index, pos.xyz, - vds - vds2 - vds2);
|
||||
//shadow += getShadow(index, pos.xyz, - vds + vds2 + vds2);
|
||||
//shadow += shadow += getShadow(index, pos.xyz, vds+vds2)*10;
|
||||
spot *= mix(1., shadow / 11., shadow_on);*/
|
||||
vec4 shp = mapScreenToShadow(index, vec3(0));
|
||||
shp.xy /= shp.w;
|
||||
vec4 light_map_pix = qgl_lightTexture(index, shp.xy, vec4(0));
|
||||
light_color *= light_map_pix.rgb;
|
||||
spot *= light_map_pix.a;
|
||||
#endif
|
||||
vec3 dist_decay = vec3(1, ldist, ldist*ldist);
|
||||
|
||||
if (shadows_enabled && (int(round(qgl_light_parameter[index].flags)) == 1) && (bitfieldExtract(flags, 3, 1) == 1) && (spot > 1E-4)) {
|
||||
#ifndef SPOT
|
||||
vec3 odir = -(view_mat * ldir);
|
||||
#endif
|
||||
int layer = index - lights_start;
|
||||
float shadow = 0.;
|
||||
//float bias = abs(tan(PI/2.*(1 - abs(dot(normal, ldir)))) + 1) * z_near * 1;
|
||||
float bias = (1. + 1. / abs(dot(geom_normal, ldir))) * z_near * 2.;
|
||||
//bias = bias * bias + z_near;
|
||||
|
||||
if (soft_shadows_enabled) {
|
||||
|
||||
float depth = 1.;
|
||||
#ifdef SPOT
|
||||
const int gm_size = 2;
|
||||
for (int i = -gm_size; i <= gm_size; ++i) {
|
||||
for (int j = -gm_size; j <= gm_size; ++j) {
|
||||
//depth = min(depth, textureOffset(tex_depths_cone, vec3(shp.xy, layer), ivec2(i, j)).x);
|
||||
depth = min(depth, texture(tex_depths_cone, vec3(shp.xy + vec2(i, j) / vec2(shadow_size.x), layer)).x);
|
||||
}
|
||||
}
|
||||
#else
|
||||
const int gm_size = 2;
|
||||
for (int i = -gm_size; i <= gm_size; ++i) {
|
||||
for (int j = -gm_size; j <= gm_size; ++j) {
|
||||
for (int k = -gm_size; k <= gm_size; ++k) {
|
||||
depth = min(depth, texture(tex_depths_omni, vec4(odir + vec3(i, j, k) / vec3(shadow_size.x), layer)).r);
|
||||
}
|
||||
}
|
||||
}
|
||||
shp.z = ldist;
|
||||
#endif
|
||||
depth = 1. / (1. - depth) - 1. + z_near;
|
||||
float dz = max(0., shp.z - depth);
|
||||
float ds = qgl_light_parameter[index].size * dz / (ldist - dz);
|
||||
//float ds = (ldist / 2.) / qgl_light_parameter[index].size;
|
||||
float srate = abs(ds / pos.z) * 10. * soft_shadows_quality;
|
||||
//qgl_FragColor.rgb = vec3(srate);
|
||||
|
||||
int samples = clamp(int(round(srate * float(soft_shadows_samples))), 1, soft_shadows_samples);
|
||||
vds = ds * bn.xyz;
|
||||
vds2 = ds * bn2.xyz;
|
||||
vec2 so;
|
||||
ivec2 sotc = tc;
|
||||
|
||||
noise2init(vec2(hash(ivec2(tc.x * 2. + 1., tc.y)), hash(ivec2(tc.x, (tc.y * 2. + 1.)))));
|
||||
for (int i = 0; i < samples; ++i) {
|
||||
so = noise2();
|
||||
#ifdef SPOT
|
||||
//vec4 nc = texelFetch(tex_noise, sotc % noise_size, 0);
|
||||
//sotc += ivec2(nc.ba * 256) % noise_size;
|
||||
//so = (nc.rg - vec2(0.5));
|
||||
|
||||
//so = vec2(rand(vec2(shp.x + i, shp.y)), rand(vec2(shp.x + i + 1, shp.y)));
|
||||
|
||||
vec4 shp = mapScreenToShadow(index, vds * so.x + vds2 * so.y);
|
||||
shp.xy /= shp.w;
|
||||
shp.z -= bias;
|
||||
shadow += getShadowCone(shp.xyz, layer);
|
||||
#else
|
||||
//so = vec2(rand(vec2(odir.x + i, odir.y)), rand(vec2(odir.x + i + 1, odir.y)))*1.25;
|
||||
|
||||
vec3 old = lpos.xyz - ((pos.xyz + vec3(vds * so.x + vds2 * so.y)) * lpos.w);
|
||||
odir = -(view_mat * old);
|
||||
shadow += getShadowOmni(vec4(odir, length(old) - bias), layer);
|
||||
#endif
|
||||
}
|
||||
|
||||
spot *= min(1., 2. * shadow / samples);
|
||||
//spot *= shadow / soft_shadows_samples;
|
||||
//spot *= shadow / soft_shadows_samples + 1;
|
||||
|
||||
} else {
|
||||
|
||||
#ifdef SPOT
|
||||
shp.xy;
|
||||
shp.z -= bias;
|
||||
spot *= getShadowCone(shp.xyz, layer);
|
||||
#else
|
||||
spot *= getShadowOmni(vec4(odir, ldist - bias), layer);
|
||||
#endif
|
||||
|
||||
}
|
||||
//shp.z -= bias;
|
||||
//shadow += getShadowCone(shp.xyz, layer, vec2(0));
|
||||
|
||||
}
|
||||
|
||||
vec3 dist_decay = vec3(1., ldist, ldist*ldist);
|
||||
spot /= dot(qgl_light_parameter[index].decay_intensity.xyz, dist_decay);
|
||||
|
||||
float NdotLs = NdotL*NdotL;
|
||||
@@ -89,89 +271,121 @@ void calcLight(in int index, in vec3 n, in vec3 v) {
|
||||
float ndlc = (1. - NdotLs) / NdotLs;
|
||||
diff = 2. / (1. + sqrt(1. + (1. - rough_diff) * ndlc));
|
||||
//diff = texture(tex_coeffs[0], vec2(roughness, (NdotLs))).r;
|
||||
li += spot * diff * qgl_light_parameter[index].color.rgb;
|
||||
li += spot * diff * light_color;
|
||||
|
||||
ndlc = (1. - NdotHs) / NdotHs;
|
||||
float der = NdotHs * (rough_spec + ndlc);
|
||||
spec = rough_spec / (der*der) / 3.1416;
|
||||
spec = rough_spec / (der*der) / PI;
|
||||
//spec = texture(tex_coeffs[1], vec2(roughness, (NdotHs))).r;
|
||||
si += spot * spec * qgl_light_parameter[index].color.rgb;
|
||||
si += spot * spec * light_color;
|
||||
}
|
||||
|
||||
|
||||
|
||||
float GeometrySchlickGGX(float NdotV, float roughness) {
|
||||
float a = roughness;
|
||||
float k = (a * a) / 2.0;
|
||||
float nom = NdotV;
|
||||
float denom = NdotV * (1.0 - k) + k;
|
||||
return nom / denom;
|
||||
}
|
||||
// ----------------------------------------------------------------------------
|
||||
float GeometrySmith(vec3 N, vec3 V, vec3 L, float roughness) {
|
||||
float NdotV = max(dot(N, V), 0.0);
|
||||
float NdotL = max(dot(N, L), 0.0);
|
||||
float ggx2 = GeometrySchlickGGX(NdotV, roughness);
|
||||
float ggx1 = GeometrySchlickGGX(NdotL, roughness);
|
||||
return ggx1 * ggx2;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void main(void) {
|
||||
ivec2 tc = ivec2(gl_FragCoord.xy);
|
||||
tc = ivec2(gl_FragCoord.xy);
|
||||
vec4 v1 = texelFetch(tex_1, tc, 0);
|
||||
float z = v1.w;
|
||||
if (z == 1.) {
|
||||
discard;
|
||||
}
|
||||
pos.w = 1;
|
||||
pos.w = 1.;
|
||||
pos.xyz = view_dir * z;
|
||||
vec3 v = normalize(-pos.xyz);
|
||||
|
||||
vec4 v0 = texelFetch(tex_0, tc, 0),
|
||||
v2 = texelFetch(tex_2, tc, 0),
|
||||
v3 = texelFetch(tex_3, tc, 0),
|
||||
v4 = texelFetch(tex_4, tc, 0);
|
||||
v4 = texelFetch(tex_4, tc, 0),
|
||||
v5 = texelFetch(tex_5, tc, 0);
|
||||
|
||||
vec3 diffuse = v0.rgb;
|
||||
vec3 normal = v1.xyz;
|
||||
normal = v1.xyz;
|
||||
geom_normal = v5.xyz;
|
||||
#ifndef SPOT
|
||||
vec3 emission = v3.rgb;
|
||||
#endif
|
||||
float alpha = v0.a;
|
||||
float metalness = v2.r;
|
||||
float roughness = v2.g;
|
||||
float reflectivity = v2.b;
|
||||
float NdotV = dot(normal, v);
|
||||
float roughness3 = roughness*roughness*roughness;
|
||||
//bn = normalize(vec3(v3.w, v4.zw));
|
||||
//bn2 = normalize(cross(n, bn));
|
||||
bn = normalize(cross(normal, vec3(1.,0.,0.)) + cross(normal, vec3(0.,1.,0.)));
|
||||
bn2 = normalize(cross(normal, bn));
|
||||
bn = cross(normal, bn2);
|
||||
rough_diff = max(roughness, _min_rough);
|
||||
rough_spec = max(roughness3, _min_rough);
|
||||
float shlick = clamp(metalness + (1 - metalness) * pow(1 - NdotV, 5), 0, 1);
|
||||
float shlick = clamp(metalness + (1. - metalness) * pow(1. - NdotV, 5.), 0., 1.);
|
||||
flags = uint(round(v2.w));
|
||||
|
||||
//qgl_FragColor.rgba = vec4(0);
|
||||
|
||||
li = vec3(0.);//qgl_AmbientLight.color.rgb * qgl_AmbientLight.intensity;
|
||||
si = vec3(0.);
|
||||
for (int i = 0; i < lights_count; ++i)
|
||||
calcLight(lights_start + i, normal, v);
|
||||
if (bitfieldExtract(flags, 0, 1) == 1) {
|
||||
for (int i = 0; i < lights_count; ++i)
|
||||
calcLight(lights_start + i, normal, v);
|
||||
} else {
|
||||
li = vec3(1.);
|
||||
}
|
||||
si *= shlick;
|
||||
li *= (1 - shlick);
|
||||
alpha = min(1, alpha * (1 + shlick));
|
||||
li *= (1. - shlick);
|
||||
alpha = min(1., alpha * (1. + shlick));
|
||||
|
||||
vec2 brdf = texture(tex_coeffs[0], vec2(NdotV*0.99, roughness*0.995)).rg;
|
||||
vec2 brdf = texture(tex_coeff_brdf, vec2(NdotV*0.99, roughness*0.995)).rg;
|
||||
float env_spec = shlick * brdf.x + brdf.y;
|
||||
vec3 spec_col = mix(vec3(1), diffuse, metalness);
|
||||
vec3 spec_col = mix(vec3(1.), diffuse, metalness);
|
||||
vec3 env_dir = view_mat * reflect(-v, normal);
|
||||
vec3 env_col = textureLod(tex_env, env_dir, sqrt(roughness) * max_lod).rgb * spec_col;
|
||||
|
||||
vec3 res_col = max(vec3(0), li * diffuse + si * spec_col + emission);
|
||||
vec3 res_col = max(vec3(0.), li * diffuse + si * spec_col);
|
||||
#ifndef SPOT
|
||||
res_col += emission;
|
||||
#endif
|
||||
res_col = mix(res_col, env_col, env_spec * reflectivity);
|
||||
|
||||
float plen = length(pos.xyz);
|
||||
float fog = 1 - exp(-plen / fog_decay);
|
||||
fog = clamp(fog * fog_color.a * fog_density, 0, 1);
|
||||
res_col = mix(res_col, fog_color.rgb, fog);
|
||||
if (bitfieldExtract(flags, 1, 1) == 1) {
|
||||
float plen = length(pos.xyz);
|
||||
float fog = 1. - exp(-plen / fog_decay);
|
||||
fog = clamp(fog * fog_color.a * fog_density, 0., 1.);
|
||||
res_col = mix(res_col, fog_color.rgb, fog);
|
||||
}
|
||||
|
||||
qgl_FragColor = vec4(res_col, alpha);
|
||||
//qgl_FragColor = vec4(diffuse.rgb, 0.25);
|
||||
//qgl_FragColor.a = alpha;
|
||||
//qgl_FragColor.rgb = vec3(geom_normal.rgb);
|
||||
//qgl_FragColor.rgba = vec4(vec3(0), 0.5);
|
||||
|
||||
#ifdef SPOT
|
||||
//vec4 shp = mapScreenToShadow(0, vec3(0));
|
||||
//shp.xy /= shp.w;
|
||||
//float depth = texture(tex_depths_cone, vec3(shp.xy, 0)).r;
|
||||
////depth = 1 / (1 - depth) - 1 + z_near;
|
||||
//float dz = max(0, shp.z - depth);
|
||||
//shp.z -= bias;
|
||||
//for (int xi = -2; xi <= 2; ++xi) {
|
||||
// for (int yi = -2; yi <= 2; ++yi) {
|
||||
//qgl_FragColor.rgb = vec3(step(shp.z, texture(tex_shadows_cone, vec3(shp.xy, 0)).r));
|
||||
//qgl_FragColor.r = texture(tex_shadows_cone, vec3(0)).r;
|
||||
//qgl_FragColor.rgb = vec3(abs(depth) + 1);
|
||||
//float _d = texture(tex_depths_cone, vec3(shp.xy, 0)).r;
|
||||
//_d = 1 / (1 - _d) - 1 + z_near;
|
||||
//qgl_FragColor.rgb = vec3(texelFetch(tex_noise, tc % noise_size, 0).b);//vec4(res_col, alpha);
|
||||
|
||||
//shp.z += 0.095;
|
||||
//qgl_FragColor.rgb = vec3(texture(tex_sh, shp.xy).rgb);
|
||||
//qgl_FragColor.rgb = vec3(textureProj(tex_shadow[0], shp));
|
||||
//vec4 rp = qgl_ViewProjMatrix*vec4(qgl_FragTexture.xy,z,1);
|
||||
//qgl_FragColor.rgb = vec3(texture(tex_shadows_cone, vec3(gl_FragCoord.xy/1000, 0)).r);
|
||||
#else
|
||||
//vec3 odir = -(view_mat * ldir);
|
||||
//float otex = texture(tex_shadows_omni, vec4(odir, 0), 0.8);
|
||||
//qgl_FragColor.rgb = vec3(otex);
|
||||
//qgl_FragColor.rgb = vec3(ldist/50);
|
||||
//qgl_FragColor.rgb = vec3(abs(otex - ldist) * 1.);
|
||||
//qgl_FragColor.rgb = vec3(tan((1-abs(dot(view_mat*normal, odir)))));
|
||||
#endif
|
||||
|
||||
//vec3 specular = prefilteredColor * (F * envBRDF.x + envBRDF.y);
|
||||
//qgl_FragColor.rgb = vec3(shlick * brdf.x + brdf.y);
|
||||
|
||||
@@ -19,7 +19,7 @@ void main(void) {
|
||||
float l = dot(res, luma) * 0.75;
|
||||
float g = gamma / frame_max;
|
||||
res /= l;
|
||||
l = 1 - exp(-l*g);
|
||||
res *= l;
|
||||
l = 1. - exp(-l*g);
|
||||
res = max(vec3(0.), res * l);
|
||||
qgl_FragColor = vec4(res, dot(res, luma));
|
||||
}
|
||||
|
||||
15
shaders/rescale.glsl
Normal file
@@ -0,0 +1,15 @@
|
||||
// vert //
|
||||
|
||||
void main(void) {
|
||||
qgl_FragTexture = qgl_Texture;
|
||||
gl_Position = qgl_ftransform();
|
||||
}
|
||||
|
||||
|
||||
// frag //
|
||||
|
||||
uniform sampler2D tex_0;
|
||||
|
||||
void main(void) {
|
||||
qgl_FragColor = texture(tex_0, qgl_FragTexture.xy);
|
||||
}
|
||||
@@ -11,9 +11,10 @@ void main(void) {
|
||||
uniform sampler2D fb_out, fb_hover, fb_select;
|
||||
|
||||
void main(void) {
|
||||
ivec2 tc = ivec2(gl_FragCoord.xy);
|
||||
//ivec2 tc = ivec2(gl_FragCoord.xy);
|
||||
//vec4 src = texelFetch(fb_out , tc, 0);
|
||||
vec2 stc = qgl_FragTexture.xy;
|
||||
vec4 src = texelFetch(fb_out , tc, 0);
|
||||
vec4 src = texture(fb_out , stc);
|
||||
vec4 hov = texture(fb_hover , stc);
|
||||
vec4 sel = texture(fb_select, stc);
|
||||
src.rgb = clamp(src.rgb, vec3(0), vec3(1));
|
||||
|
||||
50
shaders/shadow.glsl
Normal file
@@ -0,0 +1,50 @@
|
||||
// vert //
|
||||
|
||||
flat out uint object_flags;
|
||||
out float distance;
|
||||
out vec4 pos;
|
||||
|
||||
const vec3 luma = vec3(0.299, 0.587, 0.114);
|
||||
|
||||
void main(void) {
|
||||
object_flags = qgl_ObjectFlags;
|
||||
if (bitfieldExtract(object_flags, 2, 1) == 0)
|
||||
return;
|
||||
qgl_MaterialIndex = qgl_Material;
|
||||
qgl_FragTexture = qgl_getFragTexture();
|
||||
float height = dot(qgl_materialTexture(QGL_MAP_RELIEF, qgl_FragTexture, vec4(0.)).rgb, luma);
|
||||
pos = qgl_ViewProjMatrix * (qgl_ModelMatrix * (vec4(qgl_Vertex + qgl_Normal * height, 1.)));//qgl_ftransform();
|
||||
gl_Position = pos;
|
||||
}
|
||||
|
||||
|
||||
// frag //
|
||||
|
||||
flat in uint object_flags;
|
||||
in float distance;
|
||||
in vec4 pos;
|
||||
|
||||
float z_near = 0.1f;
|
||||
const float _pe = 2.4e-7;
|
||||
|
||||
void main(void) {
|
||||
if (bitfieldExtract(object_flags, 2, 1) == 0)
|
||||
discard;
|
||||
vec4 diffuse = qgl_materialTexture(QGL_MAP_DIFFUSE, qgl_FragTexture.xy, vec4(0.f));
|
||||
if(diffuse.a < 0.5f)
|
||||
discard;
|
||||
|
||||
//float z = gl_FragCoord.z;
|
||||
//z = z + z - 1;
|
||||
//z = ((_pe - 2.) * z_near) / (z + z + _pe - 2.); // infinite depth
|
||||
|
||||
#ifdef OMNI
|
||||
float z = length(pos.xyz);
|
||||
#else
|
||||
float z = pos.z;
|
||||
#endif
|
||||
z = 1.f - 1.f / (z - z_near + 1.f);
|
||||
gl_FragDepth = z;
|
||||
qgl_FragData[0].r = z;
|
||||
//qgl_FragData[0].r = length(vec3(pos.xy, z));//1/gl_FragCoord.w;
|
||||
}
|
||||
9
src/CMakeLists.txt
Normal file
@@ -0,0 +1,9 @@
|
||||
#if (NOT DEFINED ANDROID_PLATFORM)
|
||||
# if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/plugin")
|
||||
# #add_subdirectory(plugin)
|
||||
# endif()
|
||||
#endif()
|
||||
foreach (_d "core" "widgets" "qglview_test") # "plugin")
|
||||
add_subdirectory("${_d}")
|
||||
endforeach()
|
||||
shstk_copy_to_parent()
|
||||
37
src/core/CMakeLists.txt
Normal file
@@ -0,0 +1,37 @@
|
||||
cmake_minimum_required(VERSION 3.13)
|
||||
project(qglengine_core)
|
||||
if (POLICY CMP0017)
|
||||
cmake_policy(SET CMP0017 NEW)
|
||||
endif()
|
||||
qad_find_qt(Core Gui OpenGL OpenGLWidgets Xml)
|
||||
find_package(OpenGL REQUIRED)
|
||||
qad_sources(SRC)
|
||||
set(_includes "${_qglengine_root_build}")
|
||||
foreach (_d "formats" "core" "scene" "render" "view")
|
||||
qad_sources(FSRC DIR "${_d}")
|
||||
list(APPEND SRC ${FSRC})
|
||||
list(APPEND _includes "${CMAKE_CURRENT_SOURCE_DIR}/${_d}")
|
||||
endforeach()
|
||||
qad_wrap(${SRC} HDRS out_HDR CPPS out_CPP QMS out_QM)
|
||||
file(GLOB PHS "*_p.h")
|
||||
list(REMOVE_ITEM out_HDR "${PHS}")
|
||||
import_version(${PROJECT_NAME} QGLEngine)
|
||||
set_deploy_property(${PROJECT_NAME} ${QGLEngine_LIB_TYPE}
|
||||
LABEL "QGLEngine core library"
|
||||
FULLNAME "${QGLEngine_DOMAIN}.qglengine_core"
|
||||
COMPANY "${QGLEngine_COMPANY}"
|
||||
INFO "QGLEngine core library")
|
||||
make_rc(${PROJECT_NAME} _RC)
|
||||
pip_code_model(CCM0 "render/renderer.h" OPTIONS "-DQGLENGINE_CORE_EXPORT" "-Es" NAME "ccm_renderer")
|
||||
pip_code_model(CCM1 "view/qglview_settings.h" OPTIONS "-DQGLENGINE_CORE_EXPORT" "-Ss" NAME "ccm_qglview")
|
||||
qad_add_library(${PROJECT_NAME} ${QGLEngine_LIB_TYPE} out_CPP ${_RC} ${CCM0} ${CCM1})
|
||||
qad_generate_export_header(${PROJECT_NAME})
|
||||
list(APPEND out_HDR "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}_export.h")
|
||||
qad_target_include_directories(${PROJECT_NAME} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}" ${_includes})
|
||||
qad_target_link_libraries(${PROJECT_NAME} QAD::Widgets QAD::PIQtUtils assimp ${OPENGL_LIBRARIES})
|
||||
message(STATUS "Building QGLEngine version ${QGLEngine_VERSION} (${QGLEngine_LIB_TYPE_MSG}) for ${QtVersions}")
|
||||
|
||||
list(APPEND QT_MULTILIB_LIST ${PROJECT_NAME})
|
||||
shstk_copy_to_parent()
|
||||
#message(STATUS "Building ${PROJECT_NAME}")
|
||||
shstk_qad_install("qglengine" FALSE "${PROJECT_NAME}" "${out_HDR}" "out_QM")
|
||||
|
Before Width: | Height: | Size: 32 KiB After Width: | Height: | Size: 32 KiB |
@@ -1,36 +1,36 @@
|
||||
/*
|
||||
QGL Buffer
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
QGL Buffer
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#define GL_GLEXT_PROTOTYPES
|
||||
#include <QOpenGLExtraFunctions>
|
||||
#include "glbuffer.h"
|
||||
|
||||
#include <QOpenGLExtraFunctions>
|
||||
|
||||
|
||||
Buffer::Buffer(GLenum target, GLenum _usage) {
|
||||
target_ = target;
|
||||
usage_ = _usage;
|
||||
buffer_ = 0;
|
||||
target_ = target;
|
||||
usage_ = _usage;
|
||||
buffer_ = 0;
|
||||
prev_size = 0;
|
||||
}
|
||||
|
||||
|
||||
Buffer::~Buffer() {
|
||||
}
|
||||
Buffer::~Buffer() {}
|
||||
|
||||
|
||||
void Buffer::init(QOpenGLExtraFunctions * f) {
|
||||
@@ -48,8 +48,14 @@ void Buffer::destroy(QOpenGLExtraFunctions * f) {
|
||||
}
|
||||
|
||||
|
||||
void Buffer::reinit() {
|
||||
buffer_ = 0;
|
||||
prev_size = 0;
|
||||
}
|
||||
|
||||
|
||||
void Buffer::bind(QOpenGLExtraFunctions * f) {
|
||||
//qDebug() << "bind" << target_ << buffer_;
|
||||
// qDebug() << "bind" << target_ << buffer_;
|
||||
f->glBindBuffer(target_, buffer_);
|
||||
}
|
||||
|
||||
@@ -72,10 +78,10 @@ void Buffer::unmap(QOpenGLExtraFunctions * f) {
|
||||
|
||||
bool Buffer::resize(QOpenGLExtraFunctions * f, int new_size) {
|
||||
if (new_size <= 0) return false;
|
||||
//qDebug() << "check resize buffer" << buffer_ << "bytes" << new_size << ", old =" << prev_size;
|
||||
// qDebug() << "check resize buffer" << buffer_ << "bytes" << new_size << ", old =" << prev_size;
|
||||
if (new_size <= prev_size) return false;
|
||||
prev_size = new_size;
|
||||
//qDebug() << "resize buffer " << buffer_ << target_ << "for" << new_size << "bytes";
|
||||
// qDebug() << "resize buffer " << buffer_ << target_ << "for" << new_size << "bytes";
|
||||
f->glBufferData(target_, new_size, 0, usage_);
|
||||
return true;
|
||||
}
|
||||
@@ -83,6 +89,6 @@ bool Buffer::resize(QOpenGLExtraFunctions * f, int new_size) {
|
||||
|
||||
void Buffer::load(QOpenGLExtraFunctions * f, const void * data, int size, int offset) {
|
||||
if (!data || size <= 0) return;
|
||||
//qDebug() << "load buffer" << buffer_ << "bytes" << size;
|
||||
// qDebug() << "load buffer" << buffer_ << "bytes" << size;
|
||||
f->glBufferSubData(target_, offset, size, data);
|
||||
}
|
||||
58
src/core/core/glbuffer.h
Normal file
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
QGL Buffer
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef GLBUFFER_H
|
||||
#define GLBUFFER_H
|
||||
|
||||
#include "gltypes.h"
|
||||
|
||||
|
||||
class QGLENGINE_CORE_EXPORT Buffer {
|
||||
friend class ObjectBase;
|
||||
|
||||
public:
|
||||
Buffer(GLenum target, GLenum usage = GL_DYNAMIC_DRAW);
|
||||
~Buffer();
|
||||
|
||||
void init(QOpenGLExtraFunctions * f);
|
||||
void destroy(QOpenGLExtraFunctions * f);
|
||||
void reinit();
|
||||
|
||||
void bind(QOpenGLExtraFunctions * f);
|
||||
void release(QOpenGLExtraFunctions * f);
|
||||
void * map(QOpenGLExtraFunctions * f, GLbitfield mode, int size = -1);
|
||||
void unmap(QOpenGLExtraFunctions * f);
|
||||
|
||||
// returns true if size changed
|
||||
bool resize(QOpenGLExtraFunctions * f, int new_size);
|
||||
void load(QOpenGLExtraFunctions * f, const void * data, int size, int offset = 0);
|
||||
|
||||
GLuint ID() const { return buffer_; }
|
||||
GLenum usage() const { return usage_; }
|
||||
GLenum target() const { return target_; }
|
||||
void setTarget(GLenum t) { target_ = t; }
|
||||
bool isInit() const { return buffer_ != 0; }
|
||||
|
||||
private:
|
||||
GLenum target_, usage_;
|
||||
GLuint buffer_;
|
||||
int prev_size;
|
||||
};
|
||||
|
||||
|
||||
#endif // GLBUFFER_H
|
||||
@@ -1,23 +1,24 @@
|
||||
/*
|
||||
QGL CubeTexture
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
QGL CubeTexture
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "gltypes.h"
|
||||
#include "glcubemap.h"
|
||||
|
||||
#include "gltypes.h"
|
||||
#include "hdr_p.h"
|
||||
|
||||
using namespace QGLEngineShaders;
|
||||
@@ -51,9 +52,9 @@ QVector<QVector3D> loadFileHDR(const QString & path, QSize * size) {
|
||||
qDebug() << "[QGLEngine] File" << path << "has unknown size!";
|
||||
return ret;
|
||||
}
|
||||
sz.setWidth (sl[3].toInt());
|
||||
sz.setWidth(sl[3].toInt());
|
||||
sz.setHeight(sl[1].toInt());
|
||||
//qDebug() << "found size" << sz;
|
||||
// qDebug() << "found size" << sz;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -61,26 +62,23 @@ QVector<QVector3D> loadFileHDR(const QString & path, QSize * size) {
|
||||
f.seek(ts.pos());
|
||||
QDataStream ds(&f);
|
||||
int count = sz.width() * sz.height();
|
||||
QVector<float> data(count*3);
|
||||
if (!RGBE_ReadPixels_RLE(&ds, data.data(), sz.width(), sz.height()))
|
||||
return ret;
|
||||
QVector<float> data(count * 3);
|
||||
if (!RGBE_ReadPixels_RLE(&ds, data.data(), sz.width(), sz.height())) return ret;
|
||||
|
||||
if (size) *size = sz;
|
||||
ret.resize(count);
|
||||
//QColor col;
|
||||
//QImage im(sz, QImage::Format_ARGB32);
|
||||
//QRgb * imdata = (QRgb*)im.bits();
|
||||
// QColor col;
|
||||
// QImage im(sz, QImage::Format_ARGB32);
|
||||
// QRgb * imdata = (QRgb*)im.bits();
|
||||
for (int i = 0; i < count; ++i) {
|
||||
QVector3D p(pow(data[i*3 + 2], 1. / 2.2),
|
||||
pow(data[i*3 + 1], 1. / 2.2),
|
||||
pow(data[i*3 + 0], 1. / 2.2));
|
||||
QVector3D p(pow(data[i * 3 + 2], 1. / 2.2), pow(data[i * 3 + 1], 1. / 2.2), pow(data[i * 3 + 0], 1. / 2.2));
|
||||
ret[i] = p;
|
||||
//col = QColor::fromRgbF(piClamp(p[0], 0.f, 1.f),
|
||||
// col = QColor::fromRgbF(piClamp(p[0], 0.f, 1.f),
|
||||
// piClamp(p[1], 0.f, 1.f),
|
||||
// piClamp(p[2], 0.f, 1.f));
|
||||
//imdata[i] = col.rgb();
|
||||
// imdata[i] = col.rgb();
|
||||
}
|
||||
//im.save("_hdr.png");
|
||||
// im.save("_hdr.png");
|
||||
|
||||
return ret;
|
||||
}
|
||||
@@ -90,72 +88,71 @@ QVector<QVector3D> faceHDR(const QVector<QVector3D> & data, QSize sz, QSize & fs
|
||||
QVector<QVector3D> ret;
|
||||
if (data.isEmpty() || sz.isNull()) return ret;
|
||||
QRect fr;
|
||||
int fw = sz.width () / 4;
|
||||
int fw = sz.width() / 4;
|
||||
int fh = sz.height() / 3;
|
||||
fsz = QSize(fw, fh);
|
||||
fsz = QSize(fw, fh);
|
||||
ret.reserve(fw * fh);
|
||||
switch (face) {
|
||||
case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
|
||||
fr.setRect(fw, fh, fw, fh);
|
||||
for (int x = fr.left(); x <= fr.right(); ++x) {
|
||||
for (int y = fr.top(); y <= fr.bottom(); ++y) {
|
||||
ret << data[y*sz.width() + x];
|
||||
ret << data[y * sz.width() + x];
|
||||
}
|
||||
}
|
||||
break;
|
||||
case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
|
||||
fr.setRect(fw*3, fh, fw, fh);
|
||||
fr.setRect(fw * 3, fh, fw, fh);
|
||||
for (int x = fr.right(); x >= fr.left(); --x) {
|
||||
for (int y = fr.bottom(); y >= fr.top(); --y) {
|
||||
ret << data[y*sz.width() + x];
|
||||
ret << data[y * sz.width() + x];
|
||||
}
|
||||
}
|
||||
break;
|
||||
case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
|
||||
fr.setRect( 0, fh, fw, fh);
|
||||
fr.setRect(0, fh, fw, fh);
|
||||
for (int y = fr.bottom(); y >= fr.top(); --y) {
|
||||
for (int x = fr.left(); x <= fr.right(); ++x) {
|
||||
ret << data[y*sz.width() + x];
|
||||
ret << data[y * sz.width() + x];
|
||||
}
|
||||
}
|
||||
break;
|
||||
case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
|
||||
fr.setRect(fw*2, fh, fw, fh);
|
||||
fr.setRect(fw * 2, fh, fw, fh);
|
||||
for (int y = fr.top(); y <= fr.bottom(); ++y) {
|
||||
for (int x = fr.right(); x >= fr.left(); --x) {
|
||||
ret << data[y*sz.width() + x];
|
||||
ret << data[y * sz.width() + x];
|
||||
}
|
||||
}
|
||||
break;
|
||||
case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
|
||||
fr.setRect(fw, 0, fw, fh);
|
||||
fr.setRect(fw, 0, fw, fh);
|
||||
for (int x = fr.left(); x <= fr.right(); ++x) {
|
||||
for (int y = fr.top(); y <= fr.bottom(); ++y) {
|
||||
ret << data[y*sz.width() + x];
|
||||
ret << data[y * sz.width() + x];
|
||||
}
|
||||
}
|
||||
break;
|
||||
case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
|
||||
fr.setRect(fw, fh*2, fw, fh);
|
||||
fr.setRect(fw, fh * 2, fw, fh);
|
||||
for (int x = fr.left(); x <= fr.right(); ++x) {
|
||||
for (int y = fr.top(); y <= fr.bottom(); ++y) {
|
||||
ret << data[y*sz.width() + x];
|
||||
ret << data[y * sz.width() + x];
|
||||
}
|
||||
}
|
||||
break;
|
||||
default: break;
|
||||
}
|
||||
if (fr.isEmpty()) return ret;
|
||||
//qDebug() << ret.size() << fr;
|
||||
// qDebug() << ret.size() << fr;
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
CubeTexture::CubeTexture(QOpenGLExtraFunctions * f_, int _size, const GLenum & _format): f(f_) {
|
||||
size = _size;
|
||||
format_ = _format;
|
||||
id_ = 0;
|
||||
size = _size;
|
||||
format_ = _format;
|
||||
id_ = 0;
|
||||
changed_ = false;
|
||||
}
|
||||
|
||||
@@ -199,9 +196,17 @@ void CubeTexture::loadHDR(const QVector<QVector3D> & data, QSize sz) {
|
||||
QVector<QVector3D> fd;
|
||||
for (int i = 0; i < 6; ++i) {
|
||||
fd = faceHDR(data, sz, fsz, GL_TEXTURE_CUBE_MAP_POSITIVE_X + i);
|
||||
//qDebug() << "load cube" << fd[0];
|
||||
f->glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, format_, fsz.width(), fsz.height(), 0, GL_RGB, GL_FLOAT, fd.isEmpty() ? 0 : fd.constData());
|
||||
//qDebug() << QString::number(GetLastError(), 16);
|
||||
// qDebug() << "load cube" << fd[0];
|
||||
f->glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i,
|
||||
0,
|
||||
format_,
|
||||
fsz.width(),
|
||||
fsz.height(),
|
||||
0,
|
||||
GL_RGB,
|
||||
GL_FLOAT,
|
||||
fd.isEmpty() ? 0 : fd.constData());
|
||||
// qDebug() << QString::number(GetLastError(), 16);
|
||||
}
|
||||
f->glGenerateMipmap(GL_TEXTURE_CUBE_MAP);
|
||||
}
|
||||
@@ -230,4 +235,3 @@ void CubeTexture::load() {
|
||||
}
|
||||
changed_ = false;
|
||||
}
|
||||
|
||||
60
src/core/core/glcubemap.h
Normal file
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
QGL CubeTexture
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef GLCUBEMAP_H
|
||||
#define GLCUBEMAP_H
|
||||
|
||||
#include "chunkstream.h"
|
||||
#include "glshaders_types.h"
|
||||
|
||||
QVector<QVector3D> QGLENGINE_CORE_EXPORT loadFileHDR(const QString & path, QSize * size = 0);
|
||||
|
||||
class QGLENGINE_CORE_EXPORT CubeTexture {
|
||||
public:
|
||||
CubeTexture(QOpenGLExtraFunctions * f_, int _size, const GLenum & _format = GL_RGB16F);
|
||||
bool init();
|
||||
void destroy();
|
||||
void bind(int channel = 0);
|
||||
void release();
|
||||
void resize(int _size) {
|
||||
size = _size;
|
||||
changed_ = true;
|
||||
}
|
||||
void loadHDR(const QVector<QVector3D> & data, QSize sz);
|
||||
void setFileHDR(const QString & path);
|
||||
QString fileHDR() const { return hdr_path; }
|
||||
GLenum format() const { return format_; }
|
||||
void setFormat(GLenum f) {
|
||||
format_ = f;
|
||||
changed_ = true;
|
||||
}
|
||||
GLuint id() const { return id_; }
|
||||
bool isInit() const { return id_ != 0; }
|
||||
void load();
|
||||
|
||||
private:
|
||||
QOpenGLExtraFunctions * f;
|
||||
bool changed_;
|
||||
int size;
|
||||
GLenum format_;
|
||||
GLuint id_;
|
||||
QString hdr_path;
|
||||
};
|
||||
|
||||
|
||||
#endif // GLCUBEMAP_H
|
||||
108
src/core/core/glcubemaparray.cpp
Normal file
@@ -0,0 +1,108 @@
|
||||
/*
|
||||
QGL CubeMapArray
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#define GL_GLEXT_PROTOTYPES
|
||||
#include "glcubemaparray.h"
|
||||
|
||||
#include <QOpenGLExtraFunctions>
|
||||
|
||||
|
||||
CubeMapArray::CubeMapArray(GLenum format, bool filter) {
|
||||
target_ = GL_TEXTURE_CUBE_MAP_ARRAY;
|
||||
format_ = format;
|
||||
texture_ = 0;
|
||||
layers_ = 0;
|
||||
filtering_ = filter;
|
||||
}
|
||||
|
||||
|
||||
CubeMapArray::~CubeMapArray() {}
|
||||
|
||||
|
||||
void CubeMapArray::init(QOpenGLExtraFunctions * f) {
|
||||
if (!isInit()) {
|
||||
f->glGenTextures(1, &texture_);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void CubeMapArray::destroy(QOpenGLExtraFunctions * f) {
|
||||
if (texture_ != 0) {
|
||||
f->glDeleteTextures(1, &texture_);
|
||||
}
|
||||
texture_ = 0;
|
||||
}
|
||||
|
||||
|
||||
void CubeMapArray::reinit() {
|
||||
texture_ = 0;
|
||||
layers_ = 0;
|
||||
}
|
||||
|
||||
|
||||
void CubeMapArray::bind(QOpenGLExtraFunctions * f, int channel) {
|
||||
f->glActiveTexture(GL_TEXTURE0 + channel);
|
||||
f->glBindTexture(target_, texture_);
|
||||
}
|
||||
|
||||
|
||||
void CubeMapArray::release(QOpenGLExtraFunctions * f) {
|
||||
f->glBindTexture(target_, 0);
|
||||
}
|
||||
|
||||
|
||||
bool CubeMapArray::resize(QOpenGLExtraFunctions * f, QSize new_size, int layers_count) {
|
||||
if (new_size.isNull() || layers_count <= 0) return false;
|
||||
if ((size_ == new_size) && (layers_ >= layers_count)) return false;
|
||||
size_ = new_size;
|
||||
layers_ = layers_count;
|
||||
f->glBindTexture(target_, texture_);
|
||||
f->glTexParameteri(target_, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
||||
f->glTexParameteri(target_, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
||||
if (filtering_) {
|
||||
f->glTexParameteri(target_, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
f->glTexParameteri(target_, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
|
||||
f->glTexParameteri(target_, GL_TEXTURE_MAX_ANISOTROPY_EXT, 8);
|
||||
} else {
|
||||
f->glTexParameteri(target_, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
f->glTexParameteri(target_, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
}
|
||||
GLenum bformat = format_;
|
||||
GLenum btype = GL_UNSIGNED_BYTE;
|
||||
if (format_ == GL_R16F || format_ == GL_R32F) {
|
||||
bformat = GL_RED;
|
||||
btype = GL_FLOAT;
|
||||
}
|
||||
f->glTexImage3D(target_, 0, format_, size_.width(), size_.height(), layers_ * 6, 0, bformat, btype, nullptr);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void CubeMapArray::load(QOpenGLExtraFunctions * f, const QImage & image, int layer) {
|
||||
if (image.isNull() || size_.isNull() || layer < 0 || layer >= layers_) return;
|
||||
QImage im =
|
||||
image.mirrored(false, true).scaled(size_, Qt::IgnoreAspectRatio, Qt::SmoothTransformation).convertToFormat(QImage::Format_RGBA8888);
|
||||
// qDebug() << "CubeMapArray::load image" << image.size() << "to layer" << layer;
|
||||
// f->glTexSubImage3D(target_, 0, 0, 0, layer, size_.width(), size_.height(), 1, GL_RGBA, GL_UNSIGNED_BYTE, im.constBits());
|
||||
}
|
||||
|
||||
|
||||
void CubeMapArray::mipmaps(QOpenGLExtraFunctions * f) {
|
||||
f->glBindTexture(target_, texture_);
|
||||
f->glGenerateMipmap(target_);
|
||||
}
|
||||
55
src/core/core/glcubemaparray.h
Normal file
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
QGL Texture2DArray
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef GLCUBEMAPARRAY_H
|
||||
#define GLCUBEMAPARRAY_H
|
||||
|
||||
#include "gltypes.h"
|
||||
|
||||
|
||||
class QGLENGINE_CORE_EXPORT CubeMapArray {
|
||||
public:
|
||||
CubeMapArray(GLenum format, bool filter);
|
||||
~CubeMapArray();
|
||||
|
||||
void init(QOpenGLExtraFunctions * f);
|
||||
void destroy(QOpenGLExtraFunctions * f);
|
||||
void reinit();
|
||||
|
||||
void bind(QOpenGLExtraFunctions * f, int channel = 0);
|
||||
void release(QOpenGLExtraFunctions * f);
|
||||
|
||||
// returns true if size changed
|
||||
bool resize(QOpenGLExtraFunctions * f, QSize new_size, int layers_count);
|
||||
void load(QOpenGLExtraFunctions * f, const QImage & image, int layer);
|
||||
void mipmaps(QOpenGLExtraFunctions * f);
|
||||
|
||||
GLuint ID() const { return texture_; }
|
||||
bool isInit() const { return texture_ != 0; }
|
||||
int layersCount() const { return layers_; }
|
||||
|
||||
private:
|
||||
GLenum target_, format_;
|
||||
GLuint texture_;
|
||||
QSize size_;
|
||||
int layers_;
|
||||
bool filtering_;
|
||||
};
|
||||
|
||||
|
||||
#endif // GLCUBEMAPARRAY_H
|
||||
@@ -1,56 +1,59 @@
|
||||
/*
|
||||
QGL Framebuffer
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
QGL Framebuffer
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <QOpenGLExtraFunctions>
|
||||
#include "glframebuffer.h"
|
||||
|
||||
#include <QOpenGLExtraFunctions>
|
||||
#include <QTime>
|
||||
|
||||
|
||||
Framebuffer::Framebuffer(QOpenGLExtraFunctions * f_, int colorAttachments_, bool withDepth, GLenum colorFormat_, GLenum _target)
|
||||
: f(f_), pbo(GL_PIXEL_PACK_BUFFER, GL_STREAM_DRAW) {
|
||||
: f(f_)
|
||||
, pbo(GL_PIXEL_PACK_BUFFER, GL_STREAM_DRAW) {
|
||||
is_depth = withDepth;
|
||||
target_ = _target;
|
||||
target_ = _target;
|
||||
color_formats.fill(colorFormat_, colorAttachments_);
|
||||
colors.fill(0, colorAttachments_);
|
||||
fbo = drbo = 0;
|
||||
tex_d = 0;
|
||||
wid = hei = 0;
|
||||
tex_d = 0;
|
||||
wid = hei = 0;
|
||||
pbo_queried = 0;
|
||||
is_changed = false;
|
||||
is_changed = false;
|
||||
}
|
||||
|
||||
|
||||
Framebuffer::Framebuffer(QOpenGLExtraFunctions * f_, QVector<GLenum> colors_, bool withDepth, GLenum _target)
|
||||
: f(f_), pbo(GL_PIXEL_PACK_BUFFER, GL_STREAM_DRAW) {
|
||||
is_depth = withDepth;
|
||||
target_ = _target;
|
||||
: f(f_)
|
||||
, pbo(GL_PIXEL_PACK_BUFFER, GL_STREAM_DRAW) {
|
||||
is_depth = withDepth;
|
||||
target_ = _target;
|
||||
color_formats = colors_;
|
||||
colors.fill(0, colors_.size());
|
||||
fbo = drbo = 0;
|
||||
tex_d = 0;
|
||||
wid = hei = 0;
|
||||
tex_d = 0;
|
||||
wid = hei = 0;
|
||||
pbo_queried = 0;
|
||||
is_changed = false;
|
||||
is_changed = false;
|
||||
}
|
||||
|
||||
|
||||
Framebuffer::~Framebuffer() {
|
||||
deleteGLFramebuffer(fbo);
|
||||
if (fbo > 0) deleteGLFramebuffer(fbo);
|
||||
deleteGLRenderbuffer(drbo);
|
||||
for (int i = 0; i < colors.size(); ++i)
|
||||
deleteGLTexture(f, colors[i]);
|
||||
@@ -59,12 +62,15 @@ Framebuffer::~Framebuffer() {
|
||||
|
||||
|
||||
void Framebuffer::resize(int width, int height, bool force) {
|
||||
if ((wid == width) && (hei == height) && !force) return;
|
||||
if (fbo > 0) {
|
||||
if ((wid == width) && (hei == height) && !force) return;
|
||||
}
|
||||
wid = width;
|
||||
hei = height;
|
||||
deleteGLFramebuffer(fbo);
|
||||
if (fbo > 0) deleteGLFramebuffer(fbo);
|
||||
f->glGenFramebuffers(1, &fbo);
|
||||
f->glBindFramebuffer(GL_FRAMEBUFFER, fbo);
|
||||
// qDebug() << "resize" << f << wid << hei << fbo << colors.size();
|
||||
for (int i = 0; i < colors.size(); ++i) {
|
||||
deleteGLTexture(f, colors[i]);
|
||||
createGLTexture(f, colors[i], width, height, color_formats[i], target_);
|
||||
@@ -77,7 +83,7 @@ void Framebuffer::resize(int width, int height, bool force) {
|
||||
}
|
||||
if (is_depth) {
|
||||
deleteGLTexture(f, tex_d);
|
||||
deleteGLRenderbuffer(drbo);
|
||||
if (drbo > 0) deleteGLRenderbuffer(drbo);
|
||||
f->glGenRenderbuffers(1, &drbo);
|
||||
f->glBindRenderbuffer(GL_RENDERBUFFER, drbo);
|
||||
f->glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, width, height);
|
||||
@@ -88,6 +94,7 @@ void Framebuffer::resize(int width, int height, bool force) {
|
||||
f->glTexParameteri(target_, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
f->glTexParameteri(target_, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
f->glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, target_, tex_d, 0);
|
||||
// f->glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, target_, tex_d, 0);
|
||||
}
|
||||
f->glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
if (pbo.isInit()) {
|
||||
@@ -97,6 +104,17 @@ void Framebuffer::resize(int width, int height, bool force) {
|
||||
}
|
||||
|
||||
|
||||
void Framebuffer::reinit(QOpenGLExtraFunctions * f_) {
|
||||
if (f_) f = f_;
|
||||
pbo.reinit();
|
||||
colors.fill(0);
|
||||
fbo = drbo = 0;
|
||||
tex_d = 0;
|
||||
pbo_queried = 0;
|
||||
is_changed = true;
|
||||
}
|
||||
|
||||
|
||||
QImage Framebuffer::grab() const {
|
||||
return QImage();
|
||||
}
|
||||
@@ -123,7 +141,7 @@ void Framebuffer::queryPoints(int index, QRect rect_, GLenum pixel_format) {
|
||||
f->glBindFramebuffer(GL_READ_FRAMEBUFFER, fbo);
|
||||
f->glReadBuffer(GL_COLOR_ATTACHMENT0 + index);
|
||||
pbo.bind(f);
|
||||
f->glReadPixels(rect_.x(), height() - rect_.bottom(), rect_.width(), rect_.height(), GL_RGBA, pixel_format, 0);
|
||||
f->glReadPixels(rect_.x(), height() - rect_.bottom() - 1, rect_.width(), rect_.height(), GL_RGBA, pixel_format, 0);
|
||||
pbo_queried = rect_.width() * rect_.height();
|
||||
pbo.release(f);
|
||||
}
|
||||
@@ -134,13 +152,17 @@ void Framebuffer::queryImage(int index) {
|
||||
}
|
||||
|
||||
|
||||
void Framebuffer::queryImageF(int index) {
|
||||
queryPoints(index, rect(), GL_FLOAT);
|
||||
}
|
||||
|
||||
|
||||
uint Framebuffer::getPoint() const {
|
||||
if (!pbo.isInit() || (pbo_queried == 0)) return 0;
|
||||
uint ret = 0;
|
||||
pbo.bind(f);
|
||||
void * map = pbo.map(f, GL_MAP_READ_BIT, sizeof(uint));
|
||||
if (map)
|
||||
memcpy(&ret, map, sizeof(uint));
|
||||
if (map) memcpy(&ret, map, sizeof(uint));
|
||||
pbo.unmap(f);
|
||||
pbo.release(f);
|
||||
return ret;
|
||||
@@ -153,8 +175,7 @@ QVector<uint> Framebuffer::getPointsByte() const {
|
||||
ret.resize(pbo_queried);
|
||||
pbo.bind(f);
|
||||
void * map = pbo.map(f, GL_MAP_READ_BIT, pbo_queried * sizeof(uint));
|
||||
if (map)
|
||||
memcpy(ret.data(), map, pbo_queried * sizeof(uint));
|
||||
if (map) memcpy(ret.data(), map, pbo_queried * sizeof(uint));
|
||||
pbo.unmap(f);
|
||||
pbo.release(f);
|
||||
return ret;
|
||||
@@ -167,8 +188,7 @@ QVector<QVector4D> Framebuffer::getPointsFloat() const {
|
||||
ret.resize(pbo_queried);
|
||||
pbo.bind(f);
|
||||
void * map = pbo.map(f, GL_MAP_READ_BIT, pbo_queried * sizeof(QVector4D));
|
||||
if (map)
|
||||
memcpy(ret.data(), map, pbo_queried * sizeof(QVector4D));
|
||||
if (map) memcpy(ret.data(), map, pbo_queried * sizeof(QVector4D));
|
||||
pbo.unmap(f);
|
||||
pbo.release(f);
|
||||
return ret;
|
||||
@@ -178,12 +198,11 @@ QVector<QVector4D> Framebuffer::getPointsFloat() const {
|
||||
QImage Framebuffer::getImage() const {
|
||||
QImage ret;
|
||||
if (!pbo.isInit() || (pbo_queried == 0)) return ret;
|
||||
ret = QImage(size(), QImage::Format_RGBA8888);
|
||||
ret = QImage(size(), QImage::Format_RGBA8888);
|
||||
int bytes = width() * height() * 4;
|
||||
pbo.bind(f);
|
||||
void * map = pbo.map(f, GL_MAP_READ_BIT, bytes);
|
||||
if (map)
|
||||
memcpy(ret.bits(), map, bytes);
|
||||
if (map) memcpy(ret.bits(), map, bytes);
|
||||
pbo.unmap(f);
|
||||
pbo.release(f);
|
||||
return ret;
|
||||
@@ -208,7 +227,16 @@ void Framebuffer::blit(int index_from, GLuint fb_to, int index_to, QRect from, Q
|
||||
f->glBindFramebuffer(GL_READ_FRAMEBUFFER, fbo);
|
||||
f->glReadBuffer(GL_COLOR_ATTACHMENT0 + index_from);
|
||||
f->glDrawBuffers(1, &e);
|
||||
f->glBlitFramebuffer(from.x(), from.y(), from.right(), from.bottom(), to.x(), to.y(), to.right(), to.bottom(), mask, filter);
|
||||
f->glBlitFramebuffer(from.x(),
|
||||
from.y(),
|
||||
from.right() + 1,
|
||||
from.bottom() + 1,
|
||||
to.x(),
|
||||
to.y(),
|
||||
to.right() + 1,
|
||||
to.bottom() + 1,
|
||||
mask,
|
||||
filter);
|
||||
}
|
||||
|
||||
|
||||
@@ -264,7 +292,7 @@ void Framebuffer::unsetWriteBuffers() {
|
||||
void Framebuffer::enablePixelBuffer() {
|
||||
pbo.init(f);
|
||||
pbo.bind(f);
|
||||
pbo.resize(f, width()*height()*4*4);
|
||||
pbo.resize(f, width() * height() * 4 * 4);
|
||||
pbo.release(f);
|
||||
}
|
||||
|
||||
@@ -283,6 +311,14 @@ void Framebuffer::bindColorTexture(int index, int channel) {
|
||||
}
|
||||
|
||||
|
||||
void Framebuffer::bindColorTextures(const QVector<int> & indeces) {
|
||||
for (int i = indeces.size() - 1; i >= 0; --i) {
|
||||
f->glActiveTexture(GL_TEXTURE0 + i);
|
||||
f->glBindTexture(GL_TEXTURE_2D, colors[indeces[i]]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Framebuffer::bindColorTextures() {
|
||||
for (int i = colors.size() - 1; i >= 0; --i) {
|
||||
f->glActiveTexture(GL_TEXTURE0 + i);
|
||||
@@ -298,14 +334,12 @@ void Framebuffer::bindDepthTexture(int channel) {
|
||||
|
||||
|
||||
void Framebuffer::deleteGLRenderbuffer(GLuint & drbo) {
|
||||
if (drbo != 0)
|
||||
f->glDeleteRenderbuffers(1, &drbo);
|
||||
if (drbo != 0) f->glDeleteRenderbuffers(1, &drbo);
|
||||
drbo = 0;
|
||||
}
|
||||
|
||||
|
||||
void Framebuffer::deleteGLFramebuffer(GLuint & fbo) {
|
||||
if (fbo != 0)
|
||||
f->glDeleteFramebuffers(1, &fbo);
|
||||
if (fbo != 0) f->glDeleteFramebuffers(1, &fbo);
|
||||
fbo = 0;
|
||||
}
|
||||
100
src/core/core/glframebuffer.h
Normal file
@@ -0,0 +1,100 @@
|
||||
/*
|
||||
QGL Framebuffer
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef GLFRAMEBUFFER_H
|
||||
#define GLFRAMEBUFFER_H
|
||||
|
||||
#include "glbuffer.h"
|
||||
|
||||
|
||||
class QGLENGINE_CORE_EXPORT Framebuffer {
|
||||
friend class FramebufferMipmap;
|
||||
|
||||
public:
|
||||
Framebuffer(QOpenGLExtraFunctions * f_,
|
||||
int colorAttachments = 1,
|
||||
bool withDepth = true,
|
||||
GLenum colorFormat = GL_RGBA8,
|
||||
GLenum _target = GL_TEXTURE_2D);
|
||||
Framebuffer(QOpenGLExtraFunctions * f_, QVector<GLenum> colors_, bool withDepth = true, GLenum _target = GL_TEXTURE_2D);
|
||||
virtual ~Framebuffer();
|
||||
|
||||
GLuint id() const { return fbo; }
|
||||
GLuint colorTexture(int index = 0) const { return colors[index]; }
|
||||
GLuint depthTexture() const { return tex_d; }
|
||||
GLenum target() const { return target_; }
|
||||
bool isInit() const { return fbo != 0; }
|
||||
int width() const { return wid; }
|
||||
int height() const { return hei; }
|
||||
QSize size() const { return QSize(wid, hei); }
|
||||
QRect rect() const { return QRect(0, 0, wid, hei); }
|
||||
QImage grab() const;
|
||||
QVector<float> grabF(int index) const;
|
||||
void queryPoint(int index, QPoint p);
|
||||
void queryPoints(int index, QRect rect, GLenum pixel_format = GL_UNSIGNED_BYTE);
|
||||
void queryImage(int index);
|
||||
void queryImageF(int index);
|
||||
uint getPoint() const;
|
||||
QVector<uint> getPointsByte() const;
|
||||
QVector<QVector4D> getPointsFloat() const;
|
||||
QImage getImage() const;
|
||||
int queriedPoints() const { return pbo_queried; }
|
||||
void blit(int index_from,
|
||||
GLuint fb_to,
|
||||
int index_to,
|
||||
QRect from,
|
||||
QRect to,
|
||||
GLbitfield mask = GL_COLOR_BUFFER_BIT,
|
||||
GLenum filter = GL_NEAREST) const;
|
||||
|
||||
void resize(QSize sz, bool force = false) { resize(sz.width(), sz.height(), force); }
|
||||
void resize(int width, int height, bool force = false);
|
||||
void reinit(QOpenGLExtraFunctions * f_ = nullptr);
|
||||
void bind();
|
||||
void release();
|
||||
void setReadBuffer(int index) { glReadBuffer(GL_COLOR_ATTACHMENT0 + index); }
|
||||
void setWriteBuffer(int index);
|
||||
void setWriteBuffers(const int * indeces, int count);
|
||||
void setWriteBuffers(const QVector<int> & indeces) { setWriteBuffers(indeces.constData(), indeces.size()); }
|
||||
void setWriteBuffers();
|
||||
void unsetWriteBuffers();
|
||||
void enablePixelBuffer();
|
||||
void setColorTextureFiltering(int index, GLenum filter);
|
||||
|
||||
void copyDepthFrom(GLuint tex) { ; }
|
||||
void bindColorTexture(int index, int channel = 0);
|
||||
void bindColorTextures(const QVector<int> & indeces);
|
||||
void bindColorTextures();
|
||||
void bindDepthTexture(int channel);
|
||||
|
||||
private:
|
||||
void deleteGLRenderbuffer(GLuint & drbo);
|
||||
void deleteGLFramebuffer(GLuint & fbo);
|
||||
|
||||
bool is_depth, is_changed;
|
||||
int pbo_queried;
|
||||
QOpenGLExtraFunctions * f;
|
||||
mutable Buffer pbo;
|
||||
QVector<GLuint> colors;
|
||||
QVector<GLenum> color_formats;
|
||||
GLenum target_;
|
||||
GLuint fbo, drbo, tex_d;
|
||||
GLint prev_view[4], wid, hei;
|
||||
};
|
||||
|
||||
#endif // GLFRAMEBUFFER_H
|
||||
66
src/core/core/glframebuffer_mipmap.cpp
Normal file
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
QGL FramebufferMipmap
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "glframebuffer_mipmap.h"
|
||||
|
||||
#include <QOpenGLExtraFunctions>
|
||||
#include <QTime>
|
||||
|
||||
|
||||
FramebufferMipmap::FramebufferMipmap(const Framebuffer & fb, int index_from_, int levels): src_fb(fb) {
|
||||
index_from = index_from_;
|
||||
for (int i = 0; i < levels; ++i)
|
||||
fbo << new Framebuffer(fb.f, 1, false, fb.color_formats[index_from]);
|
||||
}
|
||||
|
||||
|
||||
FramebufferMipmap::~FramebufferMipmap() {}
|
||||
|
||||
|
||||
void FramebufferMipmap::setIndexFrom(int index) {
|
||||
index_from = index;
|
||||
}
|
||||
|
||||
|
||||
void FramebufferMipmap::enablePixelBuffer() {
|
||||
for (int i = 0; i < fbo.size(); ++i)
|
||||
fbo[i]->enablePixelBuffer();
|
||||
}
|
||||
|
||||
|
||||
void FramebufferMipmap::resize() {
|
||||
QSize sz = src_fb.size();
|
||||
for (int i = 0; i < fbo.size(); ++i) {
|
||||
sz /= 2;
|
||||
fbo[i]->resize(sz.width(), sz.height());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void FramebufferMipmap::create() {
|
||||
if (fbo.isEmpty()) return;
|
||||
src_fb.blit(index_from, fbo[0]->id(), 0, src_fb.rect(), fbo[0]->rect(), GL_COLOR_BUFFER_BIT, GL_LINEAR);
|
||||
for (int i = 0; i < fbo.size() - 1; ++i)
|
||||
fbo[i]->blit(0, fbo[i + 1]->id(), 0, fbo[i]->rect(), fbo[i + 1]->rect(), GL_COLOR_BUFFER_BIT, GL_LINEAR);
|
||||
}
|
||||
|
||||
|
||||
void FramebufferMipmap::reinit() {
|
||||
for (auto * f: fbo)
|
||||
f->reinit();
|
||||
}
|
||||
51
src/core/core/glframebuffer_mipmap.h
Normal file
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
QGL FramebufferMipmap
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef GLFRAMEBUFFER_MIPMAP_H
|
||||
#define GLFRAMEBUFFER_MIPMAP_H
|
||||
|
||||
#include "glframebuffer.h"
|
||||
|
||||
|
||||
class QGLENGINE_CORE_EXPORT FramebufferMipmap {
|
||||
public:
|
||||
FramebufferMipmap(const Framebuffer & fb, int index_from_, int levels = 2);
|
||||
virtual ~FramebufferMipmap();
|
||||
|
||||
int levelsCount() const { return fbo.size(); }
|
||||
int lastLevel() const { return fbo.size() - 1; }
|
||||
Framebuffer & plane(int level) { return *fbo[level]; }
|
||||
Framebuffer & lastPlane() { return *fbo[lastLevel()]; }
|
||||
int width(int level) const { return fbo[level]->wid; }
|
||||
int height(int level) const { return fbo[level]->hei; }
|
||||
QSize size(int level) const { return fbo[level]->size(); }
|
||||
QRect rect(int level) const { return fbo[level]->rect(); }
|
||||
void setIndexFrom(int index);
|
||||
|
||||
void enablePixelBuffer();
|
||||
void resize();
|
||||
void create();
|
||||
void reinit();
|
||||
|
||||
private:
|
||||
int index_from;
|
||||
const Framebuffer & src_fb;
|
||||
QVector<Framebuffer *> fbo;
|
||||
};
|
||||
|
||||
#endif // GLFRAMEBUFFER_MIPMAP_H
|
||||
145
src/core/core/glframebuffereffectbase.cpp
Normal file
@@ -0,0 +1,145 @@
|
||||
/*
|
||||
QGL Framebuffer effect basic
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "glframebuffereffectbase.h"
|
||||
|
||||
#include "renderer.h"
|
||||
|
||||
#include <QTime>
|
||||
|
||||
|
||||
FramebufferEffectBase::FramebufferEffectBase() {}
|
||||
|
||||
|
||||
FramebufferEffectBase::~FramebufferEffectBase() {
|
||||
/*if (fbo > 0) deleteGLFramebuffer(fbo);
|
||||
deleteGLRenderbuffer(drbo);
|
||||
for (int i = 0; i < colors.size(); ++i)
|
||||
deleteGLTexture(f, colors[i]);
|
||||
deleteGLTexture(f, tex_d);*/
|
||||
}
|
||||
|
||||
|
||||
void FramebufferEffectBase::resize(int width, int height, bool force) {
|
||||
/*if (fbo > 0) {
|
||||
if ((wid == width) && (hei == height) && !force) return;
|
||||
}
|
||||
wid = width;
|
||||
hei = height;
|
||||
if (fbo > 0) deleteGLFramebuffer(fbo);
|
||||
f->glGenFramebuffers(1, &fbo);
|
||||
f->glBindFramebuffer(GL_FRAMEBUFFER, fbo);
|
||||
// qDebug() << "resize" << f << wid << hei << fbo;
|
||||
for (int i = 0; i < colors.size(); ++i) {
|
||||
deleteGLTexture(f, colors[i]);
|
||||
createGLTexture(f, colors[i], width, height, color_formats[i], target_);
|
||||
f->glTexParameteri(target_, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
f->glTexParameteri(target_, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
f->glTexParameteri(target_, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
f->glTexParameteri(target_, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
f->glTexParameteri(target_, GL_TEXTURE_MAX_LEVEL, 4);
|
||||
f->glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i, target_, colors[i], 0);
|
||||
}
|
||||
if (is_depth) {
|
||||
deleteGLTexture(f, tex_d);
|
||||
if (drbo > 0) deleteGLRenderbuffer(drbo);
|
||||
f->glGenRenderbuffers(1, &drbo);
|
||||
f->glBindRenderbuffer(GL_RENDERBUFFER, drbo);
|
||||
f->glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, width, height);
|
||||
f->glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, drbo);
|
||||
createGLTexture(f, tex_d, width, height, GL_DEPTH_COMPONENT);
|
||||
f->glTexParameteri(target_, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
f->glTexParameteri(target_, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
f->glTexParameteri(target_, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
f->glTexParameteri(target_, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
f->glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, target_, tex_d, 0);
|
||||
}
|
||||
f->glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
if (pbo.isInit()) {
|
||||
enablePixelBuffer();
|
||||
}
|
||||
is_changed = false;*/
|
||||
}
|
||||
|
||||
|
||||
void FramebufferEffectBase::reinit() {
|
||||
/*pbo.reinit();
|
||||
colors.fill(0);
|
||||
fbo = drbo = 0;
|
||||
tex_d = 0;
|
||||
pbo_queried = 0;
|
||||
is_changed = true;*/
|
||||
}
|
||||
|
||||
|
||||
void FramebufferEffectBase::bindDeferredBuffer(int role, int channel) {
|
||||
r->fbo_ds.bindColorTexture(role, channel);
|
||||
}
|
||||
|
||||
|
||||
void FramebufferEffectBase::bindDepthBuffer(int channel) {
|
||||
r->fbo_ds.bindDepthTexture(channel);
|
||||
}
|
||||
|
||||
|
||||
void FramebufferEffectBase::bindPreviousOutput(int channel) {
|
||||
r->fbo_out.bindColorTexture(r->prev_write_plane, channel);
|
||||
}
|
||||
|
||||
|
||||
void FramebufferEffectBase::setOutputPlane(int channel) {
|
||||
r->fbo_out.setWriteBuffer(channel);
|
||||
r->prev_write_plane = r->cur_write_plane;
|
||||
r->cur_write_plane = channel;
|
||||
}
|
||||
|
||||
|
||||
void FramebufferEffectBase::drawScreen(QOpenGLShaderProgram * prog) {
|
||||
r->renderQuad(prog, r->quad, nullptr);
|
||||
}
|
||||
|
||||
|
||||
void FramebufferEffectBase::drawInternal() {
|
||||
if (!r) return;
|
||||
draw();
|
||||
}
|
||||
|
||||
|
||||
void FramebufferEffectBase::reloadShadersInternal() {
|
||||
if (!r) return;
|
||||
if (is_loaded) return;
|
||||
reloadShaders();
|
||||
is_loaded = true;
|
||||
}
|
||||
|
||||
|
||||
QVector<int> FramebufferEffectBase::getFreePlanes(int count) {
|
||||
return r->getFreePlanes(count);
|
||||
}
|
||||
|
||||
|
||||
int FramebufferEffectBase::previousOutputPlane() const {
|
||||
return r->prev_write_plane;
|
||||
}
|
||||
|
||||
|
||||
void FramebufferEffectBase::deleteShader(QOpenGLShaderProgram *& s) {
|
||||
if (!s) return;
|
||||
delete s;
|
||||
s = nullptr;
|
||||
}
|
||||
68
src/core/core/glframebuffereffectbase.h
Normal file
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
QGL Framebuffer effect basic
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef glframebuffereffectbase_H
|
||||
#define glframebuffereffectbase_H
|
||||
|
||||
#include "gltypes.h"
|
||||
#include "parameteredobject.h"
|
||||
|
||||
#include <QElapsedTimer>
|
||||
|
||||
|
||||
class QGLENGINE_CORE_EXPORT FramebufferEffectBase: public ParameteredObject {
|
||||
friend class FramebufferMipmap;
|
||||
friend class Renderer;
|
||||
|
||||
public:
|
||||
FramebufferEffectBase();
|
||||
virtual ~FramebufferEffectBase();
|
||||
|
||||
virtual QString name() const = 0;
|
||||
|
||||
void setEnabled(bool on) { enabled_ = on; }
|
||||
bool isEnabled() const { return enabled_; }
|
||||
|
||||
virtual void draw() = 0;
|
||||
|
||||
protected:
|
||||
void resize(int width, int height, bool force = false);
|
||||
void reinit();
|
||||
|
||||
virtual int maxPlanesUsed() const { return 1; }
|
||||
virtual void reloadShaders() {}
|
||||
|
||||
void bindDeferredBuffer(int role, int channel);
|
||||
void bindDepthBuffer(int channel);
|
||||
void bindPreviousOutput(int channel);
|
||||
void setOutputPlane(int channel);
|
||||
void drawScreen(QOpenGLShaderProgram * prog);
|
||||
void drawInternal();
|
||||
void reloadShadersInternal();
|
||||
QVector<int> getFreePlanes(int count);
|
||||
int previousOutputPlane() const;
|
||||
static void deleteShader(QOpenGLShaderProgram *& s);
|
||||
|
||||
private:
|
||||
bool enabled_ = true;
|
||||
bool is_loaded = false;
|
||||
Renderer * r = nullptr;
|
||||
GLint wid, hei;
|
||||
};
|
||||
|
||||
#endif
|
||||
179
src/core/core/glmaterial.cpp
Normal file
@@ -0,0 +1,179 @@
|
||||
/*
|
||||
QGL Material
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "gltexture_manager.h"
|
||||
|
||||
using namespace QGLEngineShaders;
|
||||
|
||||
|
||||
Map::Map() {
|
||||
bitmap_id = 0;
|
||||
color_amount = 1.f;
|
||||
color_offset = 0.f;
|
||||
bitmap_scale = QPointF(1., 1.);
|
||||
use_bitmap = false;
|
||||
_changed = true;
|
||||
_layer = 0;
|
||||
_bitmap_hash = 0;
|
||||
}
|
||||
|
||||
|
||||
void Map::setBitmapPath(const QString & p) {
|
||||
bitmap_path = p;
|
||||
_changed = true;
|
||||
_bitmap_hash = 0;
|
||||
}
|
||||
|
||||
|
||||
void Map::load(TextureManager * tm) {
|
||||
_bitmap_hash = 0;
|
||||
if (!bitmap_path.isEmpty()) tm->loadTextureImage(bitmap_path, _type == mtNormal, bake_options, &_bitmap_hash);
|
||||
_changed = false;
|
||||
}
|
||||
|
||||
|
||||
void Map::setMapLayer(TextureManager * tm) {
|
||||
if (loadedBitmap())
|
||||
_layer = tm->textureLayer(_bitmap_hash);
|
||||
else
|
||||
_layer = 0;
|
||||
}
|
||||
|
||||
|
||||
void Map::copyToQGLMap(QGLMap & m) const {
|
||||
m.amount = color_amount;
|
||||
m.offset = color_offset;
|
||||
m.scale = QVector2D(bitmap_scale);
|
||||
if (loadedBitmap() && use_bitmap) {
|
||||
m.array_index = 1;
|
||||
m.map_index = _layer;
|
||||
} else {
|
||||
m.array_index = 0;
|
||||
m.map_index = emptyMapIndex(_type);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
GLuint Map::emptyMapIndex(int type) {
|
||||
switch (type) {
|
||||
case mtNormal: return emrBlue;
|
||||
case mtRelief: return emrBlack;
|
||||
default: return emrWhite;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Material::Material(const QString _name) {
|
||||
setTypes();
|
||||
name = _name;
|
||||
color_diffuse = Qt::white;
|
||||
color_emission = Qt::black;
|
||||
glass = false;
|
||||
transparency = reflectivity = 0.f;
|
||||
map_roughness.color_amount = 0.75f;
|
||||
map_metalness.color_amount = 0.25f;
|
||||
iof = 1.f;
|
||||
dispersion = 0.05f;
|
||||
_changed = true;
|
||||
_index = 0;
|
||||
}
|
||||
|
||||
|
||||
uint Material::hash() {
|
||||
return qHash(name);
|
||||
}
|
||||
|
||||
|
||||
bool Material::hasTransparency() const {
|
||||
return float(color_diffuse.alphaF()) * (1.f - transparency) < 1.f;
|
||||
}
|
||||
|
||||
|
||||
bool Material::isMapsChanged() const {
|
||||
return map_diffuse._changed || map_normal._changed || map_metalness._changed || map_roughness._changed || map_emission._changed ||
|
||||
map_relief._changed;
|
||||
}
|
||||
|
||||
|
||||
bool Material::isMapChanged(int type) const {
|
||||
switch (type) {
|
||||
case mtDiffuse: return map_diffuse._changed;
|
||||
case mtNormal: return map_normal._changed;
|
||||
case mtMetalness: return map_metalness._changed;
|
||||
case mtRoughness: return map_roughness._changed;
|
||||
case mtEmission: return map_emission._changed;
|
||||
case mtRelief: return map_relief._changed;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void Material::load(TextureManager * tm) {
|
||||
map_diffuse.load(tm);
|
||||
map_normal.load(tm);
|
||||
map_metalness.load(tm);
|
||||
map_roughness.load(tm);
|
||||
map_emission.load(tm);
|
||||
map_relief.load(tm);
|
||||
}
|
||||
|
||||
|
||||
void Material::setMapsLayers(TextureManager * tm) {
|
||||
map_diffuse.setMapLayer(tm);
|
||||
map_normal.setMapLayer(tm);
|
||||
map_metalness.setMapLayer(tm);
|
||||
map_roughness.setMapLayer(tm);
|
||||
map_emission.setMapLayer(tm);
|
||||
map_relief.setMapLayer(tm);
|
||||
}
|
||||
|
||||
|
||||
void Material::setMapsChanged() {
|
||||
map_diffuse._changed = true;
|
||||
map_normal._changed = true;
|
||||
map_metalness._changed = true;
|
||||
map_roughness._changed = true;
|
||||
map_emission._changed = true;
|
||||
map_relief._changed = true;
|
||||
}
|
||||
|
||||
|
||||
void Material::setTypes() {
|
||||
map_diffuse._type = mtDiffuse;
|
||||
map_normal._type = mtNormal;
|
||||
map_metalness._type = mtMetalness;
|
||||
map_roughness._type = mtRoughness;
|
||||
map_emission._type = mtEmission;
|
||||
map_relief._type = mtRelief;
|
||||
}
|
||||
|
||||
|
||||
void Material::detectMaps() {
|
||||
map_diffuse.use_bitmap = !map_diffuse.bitmap_path.isEmpty();
|
||||
map_normal.use_bitmap = !map_normal.bitmap_path.isEmpty();
|
||||
map_metalness.use_bitmap = !map_metalness.bitmap_path.isEmpty();
|
||||
map_roughness.use_bitmap = !map_roughness.bitmap_path.isEmpty();
|
||||
map_emission.use_bitmap = !map_emission.bitmap_path.isEmpty();
|
||||
map_relief.use_bitmap = !map_relief.bitmap_path.isEmpty();
|
||||
}
|
||||
|
||||
|
||||
uint MapBakeOptions::hash() const {
|
||||
return qHash((uint)invert_R + ((uint)invert_G << 1) + ((uint)invert_B << 2));
|
||||
}
|
||||
168
src/core/core/glmaterial.h
Normal file
@@ -0,0 +1,168 @@
|
||||
/*
|
||||
QGL Material
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef GLMATERIAL_H
|
||||
#define GLMATERIAL_H
|
||||
|
||||
#include "glshaders_types.h"
|
||||
|
||||
#include <chunkstream.h>
|
||||
|
||||
|
||||
struct QGLENGINE_CORE_EXPORT MapBakeOptions {
|
||||
uint hash() const;
|
||||
bool invert_R = false;
|
||||
bool invert_G = false;
|
||||
bool invert_B = false;
|
||||
};
|
||||
|
||||
|
||||
class QGLENGINE_CORE_EXPORT Map {
|
||||
public:
|
||||
Map();
|
||||
void setBitmapPath(const QString & p);
|
||||
void clearBitmap() { setBitmapPath(QString()); }
|
||||
bool hasBitmap() const { return !bitmap_path.isEmpty(); }
|
||||
bool loadedBitmap() const { return _bitmap_hash != 0; }
|
||||
void load(TextureManager * tm);
|
||||
void setMapLayer(TextureManager * tm);
|
||||
void copyToQGLMap(QGLEngineShaders::QGLMap & m) const;
|
||||
static GLuint emptyMapIndex(int type);
|
||||
QString bitmap_path;
|
||||
GLuint bitmap_id;
|
||||
QPointF bitmap_offset;
|
||||
QPointF bitmap_scale;
|
||||
float color_amount;
|
||||
float color_offset;
|
||||
bool use_bitmap;
|
||||
MapBakeOptions bake_options;
|
||||
|
||||
bool _changed;
|
||||
int _type, _layer;
|
||||
uint _bitmap_hash;
|
||||
};
|
||||
|
||||
class QGLENGINE_CORE_EXPORT Material {
|
||||
public:
|
||||
Material(const QString _name = QString());
|
||||
uint hash();
|
||||
bool hasTransparency() const;
|
||||
bool isMapsChanged() const;
|
||||
bool isMapChanged(int type) const;
|
||||
void load(TextureManager * tm);
|
||||
void setMapsLayers(TextureManager * tm);
|
||||
void setMapsChanged();
|
||||
void setTypes();
|
||||
void detectMaps();
|
||||
QString name;
|
||||
QColor color_diffuse;
|
||||
QColor color_emission;
|
||||
bool glass;
|
||||
float transparency;
|
||||
float reflectivity;
|
||||
float iof;
|
||||
float dispersion;
|
||||
Map map_diffuse;
|
||||
Map map_normal;
|
||||
Map map_metalness;
|
||||
Map map_roughness;
|
||||
Map map_emission;
|
||||
Map map_relief;
|
||||
bool _changed;
|
||||
int _index;
|
||||
};
|
||||
|
||||
|
||||
inline QDataStream & operator<<(QDataStream & s, const MapBakeOptions & m) {
|
||||
ChunkStream cs;
|
||||
cs.add(1, m.invert_R).add(2, m.invert_G).add(3, m.invert_B);
|
||||
s << cs.data();
|
||||
return s;
|
||||
}
|
||||
inline QDataStream & operator>>(QDataStream & s, MapBakeOptions & m) {
|
||||
ChunkStream cs(s);
|
||||
cs.readAll();
|
||||
cs.get(1, m.invert_R).get(2, m.invert_G).get(3, m.invert_B);
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
inline QDataStream & operator<<(QDataStream & s, const Map & m) {
|
||||
ChunkStream cs;
|
||||
cs.add(1, m.bitmap_path)
|
||||
.add(2, m.color_amount)
|
||||
.add(3, m.color_offset)
|
||||
.add(6, m.bitmap_scale)
|
||||
.add(7, m.use_bitmap)
|
||||
.add(11, m.bake_options);
|
||||
s << cs.data();
|
||||
return s;
|
||||
}
|
||||
inline QDataStream & operator>>(QDataStream & s, Map & m) {
|
||||
ChunkStream cs(s);
|
||||
cs.readAll();
|
||||
cs.get(1, m.bitmap_path)
|
||||
.get(2, m.color_amount)
|
||||
.get(3, m.color_offset)
|
||||
.get(6, m.bitmap_scale)
|
||||
.get(7, m.use_bitmap)
|
||||
.get(11, m.bake_options);
|
||||
return s;
|
||||
}
|
||||
|
||||
inline QDataStream & operator<<(QDataStream & s, const Material * m) {
|
||||
ChunkStream cs;
|
||||
cs.add(1, m->name)
|
||||
.add(2, m->color_diffuse)
|
||||
.add(4, m->color_emission)
|
||||
.add(5, m->transparency)
|
||||
.add(6, m->reflectivity)
|
||||
.add(7, m->glass)
|
||||
.add(8, m->map_diffuse)
|
||||
.add(9, m->map_normal)
|
||||
.add(10, m->map_relief)
|
||||
.add(11, m->map_metalness)
|
||||
.add(12, m->map_roughness)
|
||||
.add(13, m->map_emission);
|
||||
s << (cs.data());
|
||||
return s;
|
||||
}
|
||||
inline QDataStream & operator>>(QDataStream & s, Material *& m) {
|
||||
m = new Material();
|
||||
ChunkStream cs(s);
|
||||
while (!cs.atEnd()) {
|
||||
switch (cs.read()) {
|
||||
case 1: cs.get(m->name); break;
|
||||
case 2: cs.get(m->color_diffuse); break;
|
||||
case 4: cs.get(m->color_emission); break;
|
||||
case 5: cs.get(m->transparency); break;
|
||||
case 6: cs.get(m->reflectivity); break;
|
||||
case 7: cs.get(m->glass); break;
|
||||
case 8: cs.get(m->map_diffuse); break;
|
||||
case 9: cs.get(m->map_normal); break;
|
||||
case 10: cs.get(m->map_relief); break;
|
||||
case 11: cs.get(m->map_metalness); break;
|
||||
case 12: cs.get(m->map_roughness); break;
|
||||
case 13: cs.get(m->map_emission); break;
|
||||
}
|
||||
}
|
||||
m->setTypes();
|
||||
return s;
|
||||
}
|
||||
|
||||
#endif // GLMATERIAL_H
|
||||
@@ -1,56 +1,59 @@
|
||||
/*
|
||||
QGL Mesh
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
QGL Mesh
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#define GL_GLEXT_PROTOTYPES
|
||||
#include <QOpenGLExtraFunctions>
|
||||
#include "glmesh.h"
|
||||
|
||||
#include "globject.h"
|
||||
|
||||
#include <QOpenGLExtraFunctions>
|
||||
#include <QTime>
|
||||
|
||||
using namespace QGLEngineShaders;
|
||||
|
||||
//static int _count = 0;
|
||||
// static int _count = 0;
|
||||
|
||||
Mesh::Mesh(GLenum geom_type_): geom_type(geom_type_),
|
||||
buffer_geom(GL_ARRAY_BUFFER, GL_STATIC_DRAW),
|
||||
buffer_ind (GL_ELEMENT_ARRAY_BUFFER, GL_STATIC_DRAW) {
|
||||
hash_ = 0;
|
||||
Mesh::Mesh(GLenum geom_type_)
|
||||
: geom_type(geom_type_)
|
||||
, buffer_geom(GL_ARRAY_BUFFER, GL_STATIC_DRAW)
|
||||
, buffer_ind(GL_ELEMENT_ARRAY_BUFFER, GL_STATIC_DRAW) {
|
||||
hash_ = 0;
|
||||
changed = hash_changed = true;
|
||||
//qDebug() << "Mesh, now" << ++_count;
|
||||
// qDebug() << "Mesh, now" << ++_count;
|
||||
}
|
||||
|
||||
|
||||
Mesh::~Mesh() {
|
||||
//qDebug() << "~Mesh, now" << --_count;
|
||||
// qDebug() << "~Mesh, now" << --_count;
|
||||
}
|
||||
|
||||
|
||||
Mesh * Mesh::clone() {
|
||||
Mesh * c = new Mesh();
|
||||
c->vertices_ = vertices_ ;
|
||||
c->normals_ = normals_ ;
|
||||
c->texcoords_ = texcoords_;
|
||||
c->triangles_ = triangles_;
|
||||
c->lines_ = lines_;
|
||||
c->geom_type = geom_type;
|
||||
c->hash_ = hash_;
|
||||
Mesh * c = new Mesh();
|
||||
c->vertices_ = vertices_;
|
||||
c->normals_ = normals_;
|
||||
c->texcoords_ = texcoords_;
|
||||
c->triangles_ = triangles_;
|
||||
c->lines_ = lines_;
|
||||
c->geom_type = geom_type;
|
||||
c->hash_ = hash_;
|
||||
c->hash_changed = hash_changed;
|
||||
//qDebug() << "clone VBO";
|
||||
// qDebug() << "clone VBO";
|
||||
return c;
|
||||
}
|
||||
|
||||
@@ -58,17 +61,27 @@ Mesh * Mesh::clone() {
|
||||
void Mesh::init(QOpenGLExtraFunctions * f) {
|
||||
if (!isInit()) {
|
||||
buffer_geom.init(f);
|
||||
buffer_ind .init(f);
|
||||
buffer_ind.init(f);
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Mesh::reinit() {
|
||||
buffer_geom.reinit();
|
||||
buffer_ind.reinit();
|
||||
QMapIterator<int, VertexObject *> it(vao_map);
|
||||
while (it.hasNext())
|
||||
it.next().value()->reinit();
|
||||
changed = true;
|
||||
}
|
||||
|
||||
|
||||
void Mesh::destroy(QOpenGLExtraFunctions * f) {
|
||||
buffer_geom.destroy(f);
|
||||
buffer_ind .destroy(f);
|
||||
QList<VertexObject*> vaol = vao_map.values();
|
||||
foreach (VertexObject* vao, vaol)
|
||||
buffer_ind.destroy(f);
|
||||
QList<VertexObject *> vaol = vao_map.values();
|
||||
foreach(VertexObject * vao, vaol)
|
||||
vao->destroy(f);
|
||||
qDeleteAll(vao_map);
|
||||
vao_map.clear();
|
||||
@@ -78,12 +91,12 @@ void Mesh::destroy(QOpenGLExtraFunctions * f) {
|
||||
void Mesh::calculateNormals() {
|
||||
normals_.resize(vertices_.size());
|
||||
QVector3D dv1, dv2, n;
|
||||
foreach (const Vector3i & t, triangles_) {
|
||||
foreach(const Vector3i & t, triangles_) {
|
||||
QVector3D & v0(vertices_[t.p0]);
|
||||
QVector3D & v1(vertices_[t.p1]);
|
||||
QVector3D & v2(vertices_[t.p2]);
|
||||
dv1 = v1 - v0, dv2 = v2 - v0;
|
||||
n = QVector3D::crossProduct(dv1, dv2).normalized();
|
||||
n = QVector3D::crossProduct(dv1, dv2).normalized();
|
||||
normals_[t.p0] = n;
|
||||
normals_[t.p1] = n;
|
||||
normals_[t.p2] = n;
|
||||
@@ -94,32 +107,32 @@ void Mesh::calculateNormals() {
|
||||
void Mesh::calculateTangents() {
|
||||
if (vertices_.isEmpty() || texcoords_.isEmpty()) return;
|
||||
if (texcoords_.size() != vertices_.size()) return;
|
||||
tangents_ .resize(vertices_.size());
|
||||
tangents_.resize(vertices_.size());
|
||||
bitangents_.resize(vertices_.size());
|
||||
//qDebug() << "calculateBinormals" << vcnt << tcnt << vertices_.size() << texcoords_.size() << "...";
|
||||
// qDebug() << "calculateBinormals" << vcnt << tcnt << vertices_.size() << texcoords_.size() << "...";
|
||||
QVector3D dv1, dv2;
|
||||
QVector2D dt1, dt2;
|
||||
QVector3D tan, bitan;
|
||||
foreach (const Vector3i & t, triangles_) {
|
||||
QVector3D & v0(vertices_ [t.p0]);
|
||||
QVector3D & v1(vertices_ [t.p1]);
|
||||
QVector3D & v2(vertices_ [t.p2]);
|
||||
foreach(const Vector3i & t, triangles_) {
|
||||
QVector3D & v0(vertices_[t.p0]);
|
||||
QVector3D & v1(vertices_[t.p1]);
|
||||
QVector3D & v2(vertices_[t.p2]);
|
||||
QVector2D & t0(texcoords_[t.p0]);
|
||||
QVector2D & t1(texcoords_[t.p1]);
|
||||
QVector2D & t2(texcoords_[t.p2]);
|
||||
dv1 = v1 - v0, dv2 = v2 - v0;
|
||||
dt1 = t1 - t0, dt2 = t2 - t0;
|
||||
tan = (dv1 * dt2.y() - dv2 * dt1.y()).normalized();
|
||||
bitan = (dv2 * dt1.x() - dv1 * dt2.x()).normalized();
|
||||
tangents_ [t.p0] = tan;
|
||||
tangents_ [t.p1] = tan;
|
||||
tangents_ [t.p2] = tan;
|
||||
tan = (dv1 * dt2.y() - dv2 * dt1.y()).normalized();
|
||||
bitan = (dv2 * dt1.x() - dv1 * dt2.x()).normalized();
|
||||
tangents_[t.p0] = tan;
|
||||
tangents_[t.p1] = tan;
|
||||
tangents_[t.p2] = tan;
|
||||
bitangents_[t.p0] = bitan;
|
||||
bitangents_[t.p1] = bitan;
|
||||
bitangents_[t.p2] = bitan;
|
||||
//qDebug() << " t" << t << vi << ti << dv1.toQVector3D() << "...";
|
||||
// qDebug() << " t" << t << vi << ti << dv1.toQVector3D() << "...";
|
||||
}
|
||||
//qDebug() << "calculateBinormals" << vcnt << tcnt << tangents_.size();
|
||||
// qDebug() << "calculateBinormals" << vcnt << tcnt << tangents_.size();
|
||||
}
|
||||
|
||||
|
||||
@@ -135,8 +148,7 @@ VertexObject * Mesh::vaoByType(int type) {
|
||||
bool Mesh::rebuffer(QOpenGLExtraFunctions * f) {
|
||||
changed = false;
|
||||
if (vertices_.isEmpty()) return true;
|
||||
if (normals_.isEmpty())
|
||||
calculateNormals();
|
||||
if (normals_.isEmpty()) calculateNormals();
|
||||
calculateTangents();
|
||||
vert_count = qMin(vertices_.size(), normals_.size());
|
||||
vert_count = qMin(vert_count, tangents_.size());
|
||||
@@ -145,11 +157,11 @@ bool Mesh::rebuffer(QOpenGLExtraFunctions * f) {
|
||||
data_.resize(vert_count);
|
||||
for (int i = 0; i < vert_count; ++i) {
|
||||
Vertex & v(data_[i]);
|
||||
v.pos = vertices_ [i];
|
||||
v.normal = normals_ [i];
|
||||
v.tangent = tangents_ [i];
|
||||
v.pos = vertices_[i];
|
||||
v.normal = normals_[i];
|
||||
v.tangent = tangents_[i];
|
||||
v.bitangent = bitangents_[i];
|
||||
v.tex = texcoords_ [i];
|
||||
v.tex = texcoords_[i];
|
||||
}
|
||||
int gsize = data_.size() * sizeof(Vertex);
|
||||
int tsize = triangles_.size() * sizeof(Vector3i);
|
||||
@@ -160,12 +172,24 @@ bool Mesh::rebuffer(QOpenGLExtraFunctions * f) {
|
||||
buffer_geom.load(f, data_.constData(), gsize);
|
||||
|
||||
buffer_ind.bind(f);
|
||||
if (geom_type == GL_TRIANGLES) {
|
||||
switch (geom_type) {
|
||||
case GL_TRIANGLES:
|
||||
buffer_ind.resize(f, tsize);
|
||||
buffer_ind.load(f, triangles_.constData(), tsize);
|
||||
} else {
|
||||
break;
|
||||
case GL_LINES:
|
||||
buffer_ind.resize(f, lsize);
|
||||
buffer_ind.load(f, lines_.constData(), lsize);
|
||||
break;
|
||||
case GL_POINTS: {
|
||||
QVector<GLint> points;
|
||||
points.resize(vertices_.size());
|
||||
for (int i = 0; i < vertices_.size(); ++i)
|
||||
points[i] = i;
|
||||
int psize = points.size() * sizeof(GLint);
|
||||
buffer_ind.resize(f, psize);
|
||||
buffer_ind.load(f, points.constData(), psize);
|
||||
} break;
|
||||
}
|
||||
|
||||
return !isEmpty();
|
||||
@@ -176,26 +200,28 @@ void Mesh::draw(QOpenGLExtraFunctions * f, int count, int type) {
|
||||
if (isEmpty()) return;
|
||||
if (!isInit()) init(f);
|
||||
if (changed) rebuffer(f);
|
||||
//qDebug() << "draw" << geom_type << vert_count << count;
|
||||
// qDebug() << "draw" << geom_type << vert_count << count;
|
||||
|
||||
VertexObject * vao = vaoByType(type);
|
||||
vao->bindBuffers(f, buffer_geom, buffer_ind);
|
||||
if (geom_type == GL_TRIANGLES)
|
||||
vao->draw(f, geom_type, triangles_.size() * 3, count);
|
||||
else
|
||||
vao->draw(f, geom_type, lines_.size() * 2, count);
|
||||
switch (geom_type) {
|
||||
case GL_TRIANGLES: vao->draw(f, geom_type, triangles_.size() * 3, count); break;
|
||||
case GL_LINES: vao->draw(f, geom_type, lines_.size() * 2, count); break;
|
||||
case GL_POINTS: vao->draw(f, geom_type, vertices_.size(), count); break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Mesh::clear() {
|
||||
vertices_ .clear();
|
||||
normals_ .clear();
|
||||
tangents_ .clear();
|
||||
vertices_.clear();
|
||||
normals_.clear();
|
||||
tangents_.clear();
|
||||
bitangents_.clear();
|
||||
texcoords_ .clear();
|
||||
triangles_ .clear();
|
||||
lines_ .clear();
|
||||
data_ .clear();
|
||||
texcoords_.clear();
|
||||
triangles_.clear();
|
||||
lines_.clear();
|
||||
data_.clear();
|
||||
changed = hash_changed = true;
|
||||
}
|
||||
|
||||
@@ -221,23 +247,23 @@ void Mesh::loadSelections(QOpenGLExtraFunctions * f, const QVector<uchar> & sels
|
||||
uint Mesh::hash() const {
|
||||
if (hash_changed) {
|
||||
hash_changed = false;
|
||||
hash_ = qHashBits(vertices_ .constData(), vertices_ .size() * sizeof(QVector3D));
|
||||
hash_ ^= qHashBits(normals_ .constData(), normals_ .size() * sizeof(QVector3D));
|
||||
hash_ = qHashBits(vertices_.constData(), vertices_.size() * sizeof(QVector3D));
|
||||
hash_ ^= qHashBits(normals_.constData(), normals_.size() * sizeof(QVector3D));
|
||||
hash_ ^= qHashBits(texcoords_.constData(), texcoords_.size() * sizeof(QVector2D));
|
||||
hash_ ^= qHashBits(triangles_.constData(), triangles_.size() * sizeof( Vector3i));
|
||||
hash_ ^= qHashBits(lines_ .constData(), lines_ .size() * sizeof( Vector2i));
|
||||
hash_ ^= qHashBits(triangles_.constData(), triangles_.size() * sizeof(Vector3i));
|
||||
hash_ ^= qHashBits(lines_.constData(), lines_.size() * sizeof(Vector2i));
|
||||
}
|
||||
return hash_;
|
||||
}
|
||||
|
||||
|
||||
bool Mesh::isObjectsChanged(int type) const {
|
||||
return (const_cast<Mesh*>(this))->vaoByType(type)->isObjectsChanged();
|
||||
return (const_cast<Mesh *>(this))->vaoByType(type)->isObjectsChanged();
|
||||
}
|
||||
|
||||
|
||||
bool Mesh::isSelectionChanged(int type) const {
|
||||
return (const_cast<Mesh*>(this))->vaoByType(type)->isSelectionChanged();
|
||||
return (const_cast<Mesh *>(this))->vaoByType(type)->isSelectionChanged();
|
||||
}
|
||||
|
||||
|
||||
@@ -252,14 +278,14 @@ void Mesh::setSelectionChanged(int type, bool yes) {
|
||||
|
||||
|
||||
void Mesh::setAllObjectsChanged(bool yes) {
|
||||
QMapIterator<int, VertexObject * > it(vao_map);
|
||||
QMapIterator<int, VertexObject *> it(vao_map);
|
||||
while (it.hasNext())
|
||||
it.next().value()->setObjectsChanged(yes);
|
||||
}
|
||||
|
||||
|
||||
void Mesh::setAllSelectionChanged(bool yes) {
|
||||
QMapIterator<int, VertexObject * > it(vao_map);
|
||||
QMapIterator<int, VertexObject *> it(vao_map);
|
||||
while (it.hasNext())
|
||||
it.next().value()->setSelectionChanged(yes);
|
||||
}
|
||||
@@ -291,8 +317,7 @@ void Mesh::transformPoints(const QMatrix4x4 & mat) {
|
||||
int vcnt = vertices_.size(), ncnt = normals_.size();
|
||||
for (int i = 0; i < vcnt; ++i) {
|
||||
vertices_[i] = (mat * QVector4D(vertices_[i], 1)).toVector3D();
|
||||
if (i < ncnt)
|
||||
normals_[i] = (mat * QVector4D(normals_[i], 0)).toVector3D();
|
||||
if (i < ncnt) normals_[i] = (mat * QVector4D(normals_[i], 0)).toVector3D();
|
||||
}
|
||||
changed = hash_changed = true;
|
||||
}
|
||||
@@ -301,7 +326,7 @@ void Mesh::transformPoints(const QMatrix4x4 & mat) {
|
||||
void Mesh::flipNormals() {
|
||||
if (vertices_.isEmpty()) return;
|
||||
for (int i = 0; i < triangles_.size(); ++i)
|
||||
piSwap(triangles_[i].p1, triangles_[i].p2);
|
||||
piSwap(triangles_[i].p0, triangles_[i].p1);
|
||||
for (int i = 0; i < lines_.size(); ++i)
|
||||
piSwap(lines_[i].p0, lines_[i].p1);
|
||||
int ncnt = normals_.size();
|
||||
@@ -316,8 +341,8 @@ void Mesh::append(const Mesh * m) {
|
||||
if (m->isEmpty()) return;
|
||||
if (normals_.isEmpty()) calculateNormals();
|
||||
int vcnt = vertices_.size();
|
||||
vertices_ .append(m->vertices_ );
|
||||
normals_ .append(m->normals_ );
|
||||
vertices_.append(m->vertices_);
|
||||
normals_.append(m->normals_);
|
||||
texcoords_.append(m->texcoords_);
|
||||
QVector<Vector3i> tri = m->triangles_;
|
||||
for (int i = 0; i < tri.size(); ++i)
|
||||
@@ -368,7 +393,7 @@ bool Mesh::loadFromFile(const QString & filename) {
|
||||
Box3D Mesh::boundingBox() const {
|
||||
if (vertices_.isEmpty()) return Box3D();
|
||||
int vcnt = vertices_.size();
|
||||
//qDebug() << "calculateBinormals" << vcnt << tcnt << vertices_.size() << texcoords_.size() << "...";
|
||||
// qDebug() << "calculateBinormals" << vcnt << tcnt << vertices_.size() << texcoords_.size() << "...";
|
||||
GLfloat mix, miy, miz, max, may, maz;
|
||||
QVector3D v0(vertices_[0]);
|
||||
mix = max = v0.x();
|
||||
@@ -384,9 +409,9 @@ Box3D Mesh::boundingBox() const {
|
||||
if (miz > v.z()) miz = v.z();
|
||||
if (maz < v.z()) maz = v.z();
|
||||
}
|
||||
bound.x = mix;
|
||||
bound.y = miy;
|
||||
bound.z = miz;
|
||||
bound.x = mix;
|
||||
bound.y = miy;
|
||||
bound.z = miz;
|
||||
bound.length = max - mix;
|
||||
bound.width = may - miy;
|
||||
bound.height = maz - miz;
|
||||
@@ -394,26 +419,26 @@ Box3D Mesh::boundingBox() const {
|
||||
}
|
||||
|
||||
|
||||
QDataStream & operator <<(QDataStream & s, const Mesh * m) {
|
||||
QDataStream & operator<<(QDataStream & s, const Mesh * m) {
|
||||
ChunkStream cs;
|
||||
//qDebug() << "place VBO" << m.vertices_.size() << m.normals_.size() << m.texcoords_.size() << m.colors_.size() << "...";
|
||||
cs.add(1, m->vertices_).add(2, m->normals_).add(3, m->texcoords_)
|
||||
.add(6, m->triangles_).add(7, m->lines_).add(10, int(m->geom_type));
|
||||
//qDebug() << "place VBO done" << cs.data().size() << "...";
|
||||
s << cs.data(); return s;
|
||||
// qDebug() << "place VBO" << m.vertices_.size() << m.normals_.size() << m.texcoords_.size() << m.colors_.size() << "...";
|
||||
cs.add(1, m->vertices_).add(2, m->normals_).add(3, m->texcoords_).add(6, m->triangles_).add(7, m->lines_).add(10, int(m->geom_type));
|
||||
// qDebug() << "place VBO done" << cs.data().size() << "...";
|
||||
s << cs.data();
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
QDataStream & operator >>(QDataStream & s, Mesh *& m) {
|
||||
QDataStream & operator>>(QDataStream & s, Mesh *& m) {
|
||||
m = new Mesh();
|
||||
ChunkStream cs(s);
|
||||
while (!cs.atEnd()) {
|
||||
switch (cs.read()) {
|
||||
case 1 : cs.get(m->vertices_ ); break;
|
||||
case 2 : cs.get(m->normals_ ); break;
|
||||
case 3 : cs.get(m->texcoords_); break;
|
||||
case 6 : cs.get(m->triangles_); break;
|
||||
case 7 : cs.get(m->lines_ ); break;
|
||||
case 1: cs.get(m->vertices_); break;
|
||||
case 2: cs.get(m->normals_); break;
|
||||
case 3: cs.get(m->texcoords_); break;
|
||||
case 6: cs.get(m->triangles_); break;
|
||||
case 7: cs.get(m->lines_); break;
|
||||
case 10: m->geom_type = cs.getData<int>(); break;
|
||||
}
|
||||
}
|
||||
123
src/core/core/glmesh.h
Normal file
@@ -0,0 +1,123 @@
|
||||
/*
|
||||
QGL Mesh
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef GLMESH_H
|
||||
#define GLMESH_H
|
||||
|
||||
#include "glvertexobject.h"
|
||||
|
||||
#include <chunkstream.h>
|
||||
|
||||
|
||||
class QGLENGINE_CORE_EXPORT Mesh {
|
||||
friend QDataStream & operator<<(QDataStream & s, const Mesh * m);
|
||||
friend QDataStream & operator>>(QDataStream & s, Mesh *& m);
|
||||
|
||||
public:
|
||||
Mesh(GLenum geom_type_ = GL_TRIANGLES);
|
||||
~Mesh();
|
||||
|
||||
Mesh * clone();
|
||||
|
||||
void init(QOpenGLExtraFunctions * f);
|
||||
void destroy(QOpenGLExtraFunctions * f);
|
||||
bool rebuffer(QOpenGLExtraFunctions * f);
|
||||
void draw(QOpenGLExtraFunctions * f, int count, int type = 0);
|
||||
void reinit();
|
||||
void clear();
|
||||
void loadObject(QOpenGLExtraFunctions * f, const QGLEngineShaders::Object & object, int type = 0);
|
||||
void loadObjects(QOpenGLExtraFunctions * f, const QVector<QGLEngineShaders::Object> & objects, int type = 0);
|
||||
void loadSelections(QOpenGLExtraFunctions * f, const QVector<uchar> & sels, int type = 0);
|
||||
|
||||
int verticesCount() const { return vertices_.size(); }
|
||||
int trianglesCount() const { return triangles_.size(); }
|
||||
int linesCount() const { return lines_.size(); }
|
||||
bool isInit() const { return buffer_geom.isInit(); }
|
||||
bool isEmpty() const { return vertices_.isEmpty(); }
|
||||
uint hash() const;
|
||||
|
||||
bool isObjectsChanged(int type = 0) const;
|
||||
bool isSelectionChanged(int type = 0) const;
|
||||
void setObjectsChanged(int type = 0, bool yes = true);
|
||||
void setSelectionChanged(int type = 0, bool yes = true);
|
||||
void setAllObjectsChanged(bool yes = true);
|
||||
void setAllSelectionChanged(bool yes = true);
|
||||
|
||||
QVector<QVector3D> & vertices() {
|
||||
changed = hash_changed = true;
|
||||
return vertices_;
|
||||
}
|
||||
QVector<QVector3D> & normals() {
|
||||
changed = hash_changed = true;
|
||||
return normals_;
|
||||
}
|
||||
QVector<QVector2D> & texcoords() {
|
||||
changed = hash_changed = true;
|
||||
return texcoords_;
|
||||
}
|
||||
QVector<Vector3i> & indicesTriangles() {
|
||||
changed = hash_changed = true;
|
||||
return triangles_;
|
||||
}
|
||||
QVector<Vector2i> & indicesLines() {
|
||||
changed = hash_changed = true;
|
||||
return lines_;
|
||||
}
|
||||
|
||||
void translatePoints(const QVector3D & dp);
|
||||
void translatePoints(const double & x, const double & y, const double & z) { translatePoints(QVector3D(x, y, z)); }
|
||||
void scalePoints(const QVector3D & dp);
|
||||
void scalePoints(const double & s) { scalePoints(QVector3D(s, s, s)); }
|
||||
void rotatePoints(const double & angle, const QVector3D & a);
|
||||
void rotatePoints(const double & angle, const double & x, const double & y, const double & z) {
|
||||
rotatePoints(angle, QVector3D(x, y, z));
|
||||
}
|
||||
void transformPoints(const QMatrix4x4 & mat);
|
||||
void flipNormals();
|
||||
void append(const Mesh * m);
|
||||
|
||||
bool saveToFile(const QString & filename);
|
||||
bool loadFromFile(const QString & filename);
|
||||
|
||||
Box3D boundingBox() const;
|
||||
|
||||
private:
|
||||
void calculateNormals();
|
||||
void calculateTangents();
|
||||
VertexObject * vaoByType(int type);
|
||||
|
||||
QVector<QVector3D> vertices_, normals_, tangents_, bitangents_;
|
||||
QVector<QVector2D> texcoords_;
|
||||
QVector<Vector3i> triangles_;
|
||||
QVector<Vector2i> lines_;
|
||||
|
||||
QVector<QGLEngineShaders::Vertex> data_;
|
||||
GLenum geom_type;
|
||||
Buffer buffer_geom, buffer_ind;
|
||||
QMap<int, VertexObject *> vao_map;
|
||||
mutable uint hash_;
|
||||
mutable bool hash_changed;
|
||||
int vert_count;
|
||||
bool changed;
|
||||
};
|
||||
|
||||
|
||||
QGLENGINE_CORE_EXPORT QDataStream & operator<<(QDataStream & s, const Mesh * m);
|
||||
QGLENGINE_CORE_EXPORT QDataStream & operator>>(QDataStream & s, Mesh *& m);
|
||||
|
||||
#endif // GLMESH_H
|
||||