Compare commits
54 Commits
devel050
...
dev-0.7-re
| Author | SHA1 | Date | |
|---|---|---|---|
|
afe30a5dbd
|
|||
|
e6cd8b7d24
|
|||
|
66602a79e0
|
|||
|
a28b7318d2
|
|||
|
71563e8979
|
|||
|
7d89ab1c47
|
|||
|
186fce803e
|
|||
|
66412ca8e0
|
|||
|
e04046720b
|
|||
|
d4c59e5b61
|
|||
|
fe9194b907
|
|||
|
4924d86bc0
|
|||
|
41b612ec0a
|
|||
|
ff1b574276
|
|||
|
1b47ed843f
|
|||
|
02d2200edd
|
|||
|
97efca5173
|
|||
|
68cc809555
|
|||
|
ca490df915
|
|||
|
da0f7320c8
|
|||
|
8ee7006d2c
|
|||
|
683c226ce0
|
|||
|
1ec06a26cc
|
|||
|
21b45f5855
|
|||
|
090656b30c
|
|||
|
e8072a064c
|
|||
|
892f8ce0c4
|
|||
|
c373b15bab
|
|||
|
fb46f4d36a
|
|||
|
337c016824
|
|||
|
d2806b2061
|
|||
|
da79db223f
|
|||
|
b2c7c1fdbf
|
|||
|
4a73e8c8da
|
|||
|
641fc27e55
|
|||
|
b8c25d6901
|
|||
|
931e02aefb
|
|||
|
0db4953125
|
|||
|
2b7d25cf06
|
|||
|
0ef6d34435
|
|||
|
eb5d5f9974
|
|||
|
3575a6787d
|
|||
|
7fc7a2ecb9
|
|||
|
03f65e069f
|
|||
|
c618c616fe
|
|||
|
ac281dc7a9
|
|||
|
0cb5de882f
|
|||
|
b3d621a847
|
|||
|
4ad00cd2be
|
|||
|
1e35dbd743
|
|||
|
803fa5cdb5
|
|||
|
66d3825481
|
|||
|
6c38aa6f21
|
|||
|
f19c947fc3
|
334
.clang-format
Normal file
334
.clang-format
Normal file
@@ -0,0 +1,334 @@
|
|||||||
|
---
|
||||||
|
Language: Cpp
|
||||||
|
AccessModifierOffset: -1
|
||||||
|
AlignAfterOpenBracket: Align
|
||||||
|
AlignArrayOfStructures: None
|
||||||
|
AlignConsecutiveAssignments:
|
||||||
|
Enabled: false
|
||||||
|
AcrossEmptyLines: false
|
||||||
|
AcrossComments: false
|
||||||
|
AlignCompound: false
|
||||||
|
AlignFunctionDeclarations: false
|
||||||
|
AlignFunctionPointers: false
|
||||||
|
PadOperators: true
|
||||||
|
AlignConsecutiveBitFields:
|
||||||
|
Enabled: false
|
||||||
|
AcrossEmptyLines: false
|
||||||
|
AcrossComments: false
|
||||||
|
AlignCompound: false
|
||||||
|
AlignFunctionDeclarations: false
|
||||||
|
AlignFunctionPointers: false
|
||||||
|
PadOperators: false
|
||||||
|
AlignConsecutiveDeclarations:
|
||||||
|
Enabled: false
|
||||||
|
AcrossEmptyLines: false
|
||||||
|
AcrossComments: false
|
||||||
|
AlignCompound: false
|
||||||
|
AlignFunctionDeclarations: true
|
||||||
|
AlignFunctionPointers: false
|
||||||
|
PadOperators: false
|
||||||
|
AlignConsecutiveMacros:
|
||||||
|
Enabled: false
|
||||||
|
AcrossEmptyLines: false
|
||||||
|
AcrossComments: false
|
||||||
|
AlignCompound: false
|
||||||
|
AlignFunctionDeclarations: false
|
||||||
|
AlignFunctionPointers: false
|
||||||
|
PadOperators: false
|
||||||
|
AlignConsecutiveShortCaseStatements:
|
||||||
|
Enabled: false
|
||||||
|
AcrossEmptyLines: false
|
||||||
|
AcrossComments: false
|
||||||
|
AlignCaseArrows: false
|
||||||
|
AlignCaseColons: false
|
||||||
|
AlignConsecutiveTableGenBreakingDAGArgColons:
|
||||||
|
Enabled: false
|
||||||
|
AcrossEmptyLines: false
|
||||||
|
AcrossComments: false
|
||||||
|
AlignCompound: false
|
||||||
|
AlignFunctionDeclarations: false
|
||||||
|
AlignFunctionPointers: false
|
||||||
|
PadOperators: false
|
||||||
|
AlignConsecutiveTableGenCondOperatorColons:
|
||||||
|
Enabled: false
|
||||||
|
AcrossEmptyLines: false
|
||||||
|
AcrossComments: false
|
||||||
|
AlignCompound: false
|
||||||
|
AlignFunctionDeclarations: false
|
||||||
|
AlignFunctionPointers: false
|
||||||
|
PadOperators: false
|
||||||
|
AlignConsecutiveTableGenDefinitionColons:
|
||||||
|
Enabled: false
|
||||||
|
AcrossEmptyLines: false
|
||||||
|
AcrossComments: false
|
||||||
|
AlignCompound: false
|
||||||
|
AlignFunctionDeclarations: false
|
||||||
|
AlignFunctionPointers: false
|
||||||
|
PadOperators: false
|
||||||
|
AlignEscapedNewlines: Left
|
||||||
|
AlignOperands: Align
|
||||||
|
AlignTrailingComments:
|
||||||
|
Kind: Always
|
||||||
|
OverEmptyLines: 0
|
||||||
|
AllowAllArgumentsOnNextLine: true
|
||||||
|
AllowAllParametersOfDeclarationOnNextLine: true
|
||||||
|
AllowBreakBeforeNoexceptSpecifier: Never
|
||||||
|
AllowShortBlocksOnASingleLine: Never
|
||||||
|
AllowShortCaseExpressionOnASingleLine: true
|
||||||
|
AllowShortCaseLabelsOnASingleLine: false
|
||||||
|
AllowShortCompoundRequirementOnASingleLine: true
|
||||||
|
AllowShortEnumsOnASingleLine: true
|
||||||
|
AllowShortFunctionsOnASingleLine: All
|
||||||
|
AllowShortIfStatementsOnASingleLine: WithoutElse
|
||||||
|
AllowShortLambdasOnASingleLine: All
|
||||||
|
AllowShortLoopsOnASingleLine: true
|
||||||
|
AllowShortNamespacesOnASingleLine: false
|
||||||
|
AlwaysBreakAfterDefinitionReturnType: None
|
||||||
|
AlwaysBreakBeforeMultilineStrings: true
|
||||||
|
AttributeMacros:
|
||||||
|
- __capability
|
||||||
|
- absl_nonnull
|
||||||
|
- absl_nullable
|
||||||
|
- absl_nullability_unknown
|
||||||
|
BinPackArguments: true
|
||||||
|
BinPackLongBracedList: true
|
||||||
|
BinPackParameters: BinPack
|
||||||
|
BitFieldColonSpacing: Both
|
||||||
|
BracedInitializerIndentWidth: -1
|
||||||
|
BraceWrapping:
|
||||||
|
AfterCaseLabel: false
|
||||||
|
AfterClass: false
|
||||||
|
AfterControlStatement: Never
|
||||||
|
AfterEnum: false
|
||||||
|
AfterExternBlock: false
|
||||||
|
AfterFunction: false
|
||||||
|
AfterNamespace: false
|
||||||
|
AfterObjCDeclaration: false
|
||||||
|
AfterStruct: false
|
||||||
|
AfterUnion: false
|
||||||
|
BeforeCatch: false
|
||||||
|
BeforeElse: false
|
||||||
|
BeforeLambdaBody: false
|
||||||
|
BeforeWhile: false
|
||||||
|
IndentBraces: false
|
||||||
|
SplitEmptyFunction: true
|
||||||
|
SplitEmptyRecord: true
|
||||||
|
SplitEmptyNamespace: true
|
||||||
|
BreakAdjacentStringLiterals: true
|
||||||
|
BreakAfterAttributes: Leave
|
||||||
|
BreakAfterJavaFieldAnnotations: false
|
||||||
|
BreakAfterReturnType: None
|
||||||
|
BreakArrays: true
|
||||||
|
BreakBeforeBinaryOperators: None
|
||||||
|
BreakBeforeConceptDeclarations: Always
|
||||||
|
BreakBeforeBraces: Attach
|
||||||
|
BreakBeforeInlineASMColon: OnlyMultiline
|
||||||
|
BreakBeforeTemplateCloser: false
|
||||||
|
BreakBeforeTernaryOperators: true
|
||||||
|
BreakBinaryOperations: Never
|
||||||
|
BreakConstructorInitializers: BeforeColon
|
||||||
|
BreakFunctionDefinitionParameters: false
|
||||||
|
BreakInheritanceList: BeforeColon
|
||||||
|
BreakStringLiterals: true
|
||||||
|
BreakTemplateDeclarations: Yes
|
||||||
|
ColumnLimit: 80
|
||||||
|
CommentPragmas: '^ IWYU pragma:'
|
||||||
|
CompactNamespaces: false
|
||||||
|
ConstructorInitializerIndentWidth: 4
|
||||||
|
ContinuationIndentWidth: 4
|
||||||
|
Cpp11BracedListStyle: true
|
||||||
|
DerivePointerAlignment: false
|
||||||
|
DisableFormat: false
|
||||||
|
EmptyLineAfterAccessModifier: Never
|
||||||
|
EmptyLineBeforeAccessModifier: LogicalBlock
|
||||||
|
EnumTrailingComma: Leave
|
||||||
|
ExperimentalAutoDetectBinPacking: false
|
||||||
|
FixNamespaceComments: true
|
||||||
|
ForEachMacros:
|
||||||
|
- foreach
|
||||||
|
- Q_FOREACH
|
||||||
|
- BOOST_FOREACH
|
||||||
|
IfMacros:
|
||||||
|
- KJ_IF_MAYBE
|
||||||
|
IncludeBlocks: Regroup
|
||||||
|
IncludeCategories:
|
||||||
|
- Regex: '^<ext/.*\.h>'
|
||||||
|
Priority: 2
|
||||||
|
SortPriority: 0
|
||||||
|
CaseSensitive: false
|
||||||
|
- Regex: '^<.*\.h>'
|
||||||
|
Priority: 1
|
||||||
|
SortPriority: 0
|
||||||
|
CaseSensitive: false
|
||||||
|
- Regex: '^<.*'
|
||||||
|
Priority: 2
|
||||||
|
SortPriority: 0
|
||||||
|
CaseSensitive: false
|
||||||
|
- Regex: '.*'
|
||||||
|
Priority: 3
|
||||||
|
SortPriority: 0
|
||||||
|
CaseSensitive: false
|
||||||
|
IncludeIsMainRegex: '([-_](test|unittest))?$'
|
||||||
|
IncludeIsMainSourceRegex: ''
|
||||||
|
IndentAccessModifiers: false
|
||||||
|
IndentCaseBlocks: false
|
||||||
|
IndentCaseLabels: true
|
||||||
|
IndentExportBlock: true
|
||||||
|
IndentExternBlock: AfterExternBlock
|
||||||
|
IndentGotoLabels: true
|
||||||
|
IndentPPDirectives: None
|
||||||
|
IndentRequiresClause: true
|
||||||
|
IndentWidth: 2
|
||||||
|
IndentWrappedFunctionNames: false
|
||||||
|
InsertBraces: false
|
||||||
|
InsertNewlineAtEOF: false
|
||||||
|
InsertTrailingCommas: None
|
||||||
|
IntegerLiteralSeparator:
|
||||||
|
Binary: 0
|
||||||
|
BinaryMinDigits: 0
|
||||||
|
Decimal: 0
|
||||||
|
DecimalMinDigits: 0
|
||||||
|
Hex: 0
|
||||||
|
HexMinDigits: 0
|
||||||
|
JavaScriptQuotes: Leave
|
||||||
|
JavaScriptWrapImports: true
|
||||||
|
KeepEmptyLines:
|
||||||
|
AtEndOfFile: false
|
||||||
|
AtStartOfBlock: false
|
||||||
|
AtStartOfFile: true
|
||||||
|
KeepFormFeed: false
|
||||||
|
LambdaBodyIndentation: Signature
|
||||||
|
LineEnding: DeriveLF
|
||||||
|
MacroBlockBegin: ''
|
||||||
|
MacroBlockEnd: ''
|
||||||
|
MainIncludeChar: Quote
|
||||||
|
MaxEmptyLinesToKeep: 1
|
||||||
|
NamespaceIndentation: None
|
||||||
|
ObjCBinPackProtocolList: Never
|
||||||
|
ObjCBlockIndentWidth: 2
|
||||||
|
ObjCBreakBeforeNestedBlockParam: true
|
||||||
|
ObjCSpaceAfterProperty: false
|
||||||
|
ObjCSpaceBeforeProtocolList: true
|
||||||
|
OneLineFormatOffRegex: ''
|
||||||
|
PackConstructorInitializers: NextLine
|
||||||
|
PenaltyBreakAssignment: 2
|
||||||
|
PenaltyBreakBeforeFirstCallParameter: 1
|
||||||
|
PenaltyBreakBeforeMemberAccess: 150
|
||||||
|
PenaltyBreakComment: 300
|
||||||
|
PenaltyBreakFirstLessLess: 120
|
||||||
|
PenaltyBreakOpenParenthesis: 0
|
||||||
|
PenaltyBreakScopeResolution: 500
|
||||||
|
PenaltyBreakString: 1000
|
||||||
|
PenaltyBreakTemplateDeclaration: 10
|
||||||
|
PenaltyExcessCharacter: 1000000
|
||||||
|
PenaltyIndentedWhitespace: 0
|
||||||
|
PenaltyReturnTypeOnItsOwnLine: 200
|
||||||
|
PointerAlignment: Left
|
||||||
|
PPIndentWidth: -1
|
||||||
|
QualifierAlignment: Leave
|
||||||
|
RawStringFormats:
|
||||||
|
- Language: Cpp
|
||||||
|
Delimiters:
|
||||||
|
- cc
|
||||||
|
- CC
|
||||||
|
- cpp
|
||||||
|
- Cpp
|
||||||
|
- CPP
|
||||||
|
- 'c++'
|
||||||
|
- 'C++'
|
||||||
|
CanonicalDelimiter: ''
|
||||||
|
BasedOnStyle: google
|
||||||
|
- Language: TextProto
|
||||||
|
Delimiters:
|
||||||
|
- pb
|
||||||
|
- PB
|
||||||
|
- proto
|
||||||
|
- PROTO
|
||||||
|
EnclosingFunctions:
|
||||||
|
- EqualsProto
|
||||||
|
- EquivToProto
|
||||||
|
- PARSE_PARTIAL_TEXT_PROTO
|
||||||
|
- PARSE_TEST_PROTO
|
||||||
|
- PARSE_TEXT_PROTO
|
||||||
|
- ParseTextOrDie
|
||||||
|
- ParseTextProtoOrDie
|
||||||
|
- ParseTestProto
|
||||||
|
- ParsePartialTestProto
|
||||||
|
CanonicalDelimiter: pb
|
||||||
|
BasedOnStyle: google
|
||||||
|
ReferenceAlignment: Pointer
|
||||||
|
ReflowComments: Always
|
||||||
|
RemoveBracesLLVM: false
|
||||||
|
RemoveEmptyLinesInUnwrappedLines: false
|
||||||
|
RemoveParentheses: Leave
|
||||||
|
RemoveSemicolon: false
|
||||||
|
RequiresClausePosition: OwnLine
|
||||||
|
RequiresExpressionIndentation: OuterScope
|
||||||
|
SeparateDefinitionBlocks: Leave
|
||||||
|
ShortNamespaceLines: 1
|
||||||
|
SkipMacroDefinitionBody: false
|
||||||
|
SortIncludes:
|
||||||
|
Enabled: true
|
||||||
|
IgnoreCase: false
|
||||||
|
SortJavaStaticImport: Before
|
||||||
|
SortUsingDeclarations: LexicographicNumeric
|
||||||
|
SpaceAfterCStyleCast: false
|
||||||
|
SpaceAfterLogicalNot: false
|
||||||
|
SpaceAfterOperatorKeyword: false
|
||||||
|
SpaceAfterTemplateKeyword: true
|
||||||
|
SpaceAroundPointerQualifiers: Default
|
||||||
|
SpaceBeforeAssignmentOperators: true
|
||||||
|
SpaceBeforeCaseColon: false
|
||||||
|
SpaceBeforeCpp11BracedList: false
|
||||||
|
SpaceBeforeCtorInitializerColon: true
|
||||||
|
SpaceBeforeInheritanceColon: true
|
||||||
|
SpaceBeforeJsonColon: false
|
||||||
|
SpaceBeforeParens: ControlStatements
|
||||||
|
SpaceBeforeParensOptions:
|
||||||
|
AfterControlStatements: true
|
||||||
|
AfterForeachMacros: true
|
||||||
|
AfterFunctionDefinitionName: false
|
||||||
|
AfterFunctionDeclarationName: false
|
||||||
|
AfterIfMacros: true
|
||||||
|
AfterNot: false
|
||||||
|
AfterOverloadedOperator: false
|
||||||
|
AfterPlacementOperator: true
|
||||||
|
AfterRequiresInClause: false
|
||||||
|
AfterRequiresInExpression: false
|
||||||
|
BeforeNonEmptyParentheses: false
|
||||||
|
SpaceBeforeRangeBasedForLoopColon: true
|
||||||
|
SpaceBeforeSquareBrackets: false
|
||||||
|
SpaceInEmptyBlock: false
|
||||||
|
SpacesBeforeTrailingComments: 2
|
||||||
|
SpacesInAngles: Never
|
||||||
|
SpacesInContainerLiterals: true
|
||||||
|
SpacesInLineCommentPrefix:
|
||||||
|
Minimum: 1
|
||||||
|
Maximum: -1
|
||||||
|
SpacesInParens: Never
|
||||||
|
SpacesInParensOptions:
|
||||||
|
ExceptDoubleParentheses: false
|
||||||
|
InCStyleCasts: false
|
||||||
|
InConditionalStatements: false
|
||||||
|
InEmptyParentheses: false
|
||||||
|
Other: false
|
||||||
|
SpacesInSquareBrackets: false
|
||||||
|
Standard: Auto
|
||||||
|
StatementAttributeLikeMacros:
|
||||||
|
- Q_EMIT
|
||||||
|
StatementMacros:
|
||||||
|
- Q_UNUSED
|
||||||
|
- QT_REQUIRE_VERSION
|
||||||
|
TableGenBreakInsideDAGArg: DontBreak
|
||||||
|
TabWidth: 8
|
||||||
|
UseTab: Never
|
||||||
|
VerilogBreakBetweenInstancePorts: true
|
||||||
|
WhitespaceSensitiveMacros:
|
||||||
|
- BOOST_PP_STRINGIZE
|
||||||
|
- CF_SWIFT_NAME
|
||||||
|
- NS_SWIFT_NAME
|
||||||
|
- PP_STRINGIZE
|
||||||
|
- STRINGIZE
|
||||||
|
WrapNamespaceBodyWithEmptyLines: Leave
|
||||||
|
...
|
||||||
|
|
||||||
5
.clangd
Normal file
5
.clangd
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
CompileFlags:
|
||||||
|
Add: []
|
||||||
|
|
||||||
|
Completion:
|
||||||
|
HeaderInsertion: Never
|
||||||
1
.gitattributes
vendored
Normal file
1
.gitattributes
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
vendor/* linguist-vendored
|
||||||
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1,3 +1,3 @@
|
|||||||
build/
|
build*/
|
||||||
.cache
|
.cache
|
||||||
.vscode
|
.vscode
|
||||||
15
.gitmodules
vendored
15
.gitmodules
vendored
@@ -1,3 +1,12 @@
|
|||||||
[submodule "backends/desktop/glfw"]
|
[submodule "vendor/stb"]
|
||||||
path = backends/desktop/glfw
|
path = vendor/stb
|
||||||
url = https://github.com/glfw/glfw
|
url = https://github.com/nothings/stb.git
|
||||||
|
[submodule "vendor/glfw"]
|
||||||
|
path = vendor/glfw
|
||||||
|
url = https://github.com/glfw/glfw.git
|
||||||
|
[submodule "vendor/libpicasso"]
|
||||||
|
path = vendor/libpicasso
|
||||||
|
url = https://github.com/tobid7/libpicasso
|
||||||
|
[submodule "vendor/spirv-helper"]
|
||||||
|
path = vendor/spirv-helper
|
||||||
|
url = https://github.com/tobid7/spirv-helper.git
|
||||||
|
|||||||
135
CMakeLists.txt
135
CMakeLists.txt
@@ -1,36 +1,141 @@
|
|||||||
cmake_minimum_required(VERSION 3.22)
|
cmake_minimum_required(VERSION 3.22)
|
||||||
|
|
||||||
|
include(GNUInstallDirs)
|
||||||
|
|
||||||
# Set Project
|
# Set Project
|
||||||
project(palladium LANGUAGES C CXX VERSION 0.5.1)
|
project(palladium LANGUAGES C CXX VERSION 0.7.0)
|
||||||
|
|
||||||
# Required to add this Variable
|
# Required to add this Variable
|
||||||
set(PD_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include)
|
set(PD_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include)
|
||||||
include(cmake/palladium.cmake)
|
include(cmake/palladium.cmake)
|
||||||
|
|
||||||
option(PD_BUILD_TESTS "Sets if TestApp and TestBench get build" OFF)
|
option(PD_BUILD_TESTS "Sets if TestApp and TestBench get build" OFF)
|
||||||
option(PD_BUILD_SHARED "Build Shared Libraries" OFF)
|
option(PD_BUILD_SHARED "Build Shared Library" OFF)
|
||||||
option(PD_BUILD_TOOLS "Build Palladium Tools" OFF)
|
option(PD_BUILD_TOOLS "Build Palladium Tools" OFF)
|
||||||
|
|
||||||
|
if(${CMAKE_SYSTEM_NAME} STREQUAL "Nintendo3DS")
|
||||||
|
add_compile_options(-Wno-psabi)
|
||||||
|
endif()
|
||||||
|
|
||||||
if(${PD_BUILD_TOOLS})
|
if(${PD_BUILD_TOOLS})
|
||||||
add_subdirectory(tools)
|
add_subdirectory(tools)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
## Include Library Source
|
add_subdirectory(vendor)
|
||||||
|
|
||||||
add_subdirectory(pd/drivers)
|
# # Include Library Source
|
||||||
add_subdirectory(pd/core)
|
set(PD_SOURCES
|
||||||
add_subdirectory(pd/image)
|
# Common
|
||||||
add_subdirectory(pd/external)
|
source/common.cpp
|
||||||
add_subdirectory(pd/lithium)
|
|
||||||
add_subdirectory(pd/ui7)
|
|
||||||
|
|
||||||
add_library(palladium INTERFACE)
|
# Core
|
||||||
target_link_libraries(palladium INTERFACE
|
source/core/bits.cpp
|
||||||
pd-core pd-image pd-external pd-lithium pd-ui7 #pd-net
|
source/core/color.cpp
|
||||||
|
source/core/io.cpp
|
||||||
|
source/core/mat.cpp
|
||||||
|
source/core/strings.cpp
|
||||||
|
source/core/timer.cpp
|
||||||
|
source/core/timetrace.cpp
|
||||||
|
|
||||||
|
# Drivers
|
||||||
|
source/drivers/os.cpp
|
||||||
|
source/drivers/gfx.cpp
|
||||||
|
|
||||||
|
# Lithium
|
||||||
|
source/lithium/pools.cpp
|
||||||
|
source/lithium/math.cpp
|
||||||
|
source/lithium/drawlist.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
add_dependencies(palladium
|
if(${PD_BUILD_SHARED})
|
||||||
pd-drivers pd-core pd-image pd-external pd-lithium pd-ui7 #pd-net
|
add_library(palladium SHARED ${PD_SOURCES})
|
||||||
|
target_compile_definitions(palladium PRIVATE PD_BUILD_SHARED)
|
||||||
|
else()
|
||||||
|
add_library(palladium STATIC ${PD_SOURCES})
|
||||||
|
target_compile_definitions(palladium PUBLIC PD_BUILD_STATIC)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
target_compile_definitions(palladium PUBLIC PD_DEBUG)
|
||||||
|
target_compile_options(palladium
|
||||||
|
PUBLIC $<$<CXX_COMPILER_ID:GNU,Clang>:
|
||||||
|
-fmacro-prefix-map=${CMAKE_CURRENT_SOURCE_DIR}/source=source
|
||||||
|
-fmacro-prefix-map=${CMAKE_CURRENT_SOURCE_DIR}/include=include
|
||||||
|
>
|
||||||
)
|
)
|
||||||
|
|
||||||
install(DIRECTORY include DESTINATION ".")
|
add_library(palladium::palladium ALIAS palladium)
|
||||||
|
|
||||||
|
target_include_directories(palladium
|
||||||
|
PUBLIC
|
||||||
|
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
|
||||||
|
$<INSTALL_INTERFACE:include>
|
||||||
|
)
|
||||||
|
|
||||||
|
target_compile_options(palladium
|
||||||
|
PRIVATE
|
||||||
|
$<$<AND:$<CONFIG:Debug>,$<CXX_COMPILER_ID:GNU,Clang>>:-O0 -g>
|
||||||
|
$<$<AND:$<CONFIG:Release>,$<CXX_COMPILER_ID:GNU,Clang>>:-O3>
|
||||||
|
|
||||||
|
$<$<AND:$<CONFIG:Debug>,$<CXX_COMPILER_ID:MSVC>>:/Od /Zi>
|
||||||
|
$<$<AND:$<CONFIG:Release>,$<CXX_COMPILER_ID:MSVC>>:/O2>
|
||||||
|
)
|
||||||
|
|
||||||
|
install(
|
||||||
|
TARGETS palladium
|
||||||
|
EXPORT palladiumTargets
|
||||||
|
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||||
|
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||||
|
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
||||||
|
)
|
||||||
|
install(
|
||||||
|
DIRECTORY include/
|
||||||
|
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
|
||||||
|
)
|
||||||
|
install(EXPORT palladiumTargets
|
||||||
|
FILE palladiumTargets.cmake
|
||||||
|
NAMESPACE palladium::
|
||||||
|
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/palladium
|
||||||
|
)
|
||||||
|
|
||||||
|
include(CMakePackageConfigHelpers)
|
||||||
|
configure_package_config_file(
|
||||||
|
cmake/palladiumConfig.cmake.in
|
||||||
|
${CMAKE_CURRENT_BINARY_DIR}/palladiumConfig.cmake
|
||||||
|
INSTALL_DESTINATION
|
||||||
|
${CMAKE_INSTALL_LIBDIR}/cmake/palladium
|
||||||
|
)
|
||||||
|
|
||||||
|
write_basic_package_version_file(
|
||||||
|
${CMAKE_CURRENT_BINARY_DIR}/palladiumConfigVersion.cmake
|
||||||
|
VERSION
|
||||||
|
${PROJECT_VERSION}
|
||||||
|
COMPATIBILITY
|
||||||
|
SameMajorVersion
|
||||||
|
)
|
||||||
|
|
||||||
|
install(
|
||||||
|
FILES
|
||||||
|
${CMAKE_CURRENT_BINARY_DIR}/palladiumConfig.cmake
|
||||||
|
${CMAKE_CURRENT_BINARY_DIR}/palladiumConfigVersion.cmake
|
||||||
|
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/palladium
|
||||||
|
)
|
||||||
|
|
||||||
|
find_program(CLANG_FORMAT clang-format)
|
||||||
|
|
||||||
|
file(GLOB_RECURSE PD_FMTFILES
|
||||||
|
CONFIGURE_DEPENDS
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/source/*.cpp
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/include/*.hpp
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/backends/source/*.cpp
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/backends/include/*.hpp
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/tests/core/source/*.cpp
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/tests/gfx/source/*.cpp
|
||||||
|
)
|
||||||
|
|
||||||
|
add_custom_target(pd-clang-format
|
||||||
|
COMMAND ${CLANG_FORMAT} --style=file -i ${PD_FMTFILES}
|
||||||
|
COMMENT "Formatting Project Sources"
|
||||||
|
)
|
||||||
|
|
||||||
|
add_subdirectory(backends)
|
||||||
|
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/tests)
|
||||||
|
|||||||
2
LICENSE
2
LICENSE
@@ -1,6 +1,6 @@
|
|||||||
MIT License
|
MIT License
|
||||||
|
|
||||||
Copyright (c) 2024 - 2025 tobid7
|
Copyright (c) 2024 - 2026 René Amthor (tobid7)
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|||||||
@@ -1,13 +0,0 @@
|
|||||||
cmake_minimum_required(VERSION 3.22)
|
|
||||||
|
|
||||||
project(pd-3ds LANGUAGES CXX VERSION 0.5.0)
|
|
||||||
|
|
||||||
set(SRC
|
|
||||||
source/bknd-gfx.cpp
|
|
||||||
source/bknd-hid.cpp
|
|
||||||
source/pd-3ds.cpp
|
|
||||||
)
|
|
||||||
|
|
||||||
pd_add_lib(pd-3ds SRC_FILES ${SRC})
|
|
||||||
target_include_directories(pd-3ds PUBLIC include)
|
|
||||||
target_link_libraries(pd-3ds PUBLIC m palladium ctru citro3d)
|
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
/*
|
|
||||||
MIT License
|
|
||||||
|
|
||||||
Copyright (c) 2024 - 2025 tobid7
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <pd-3ds/bknd-gfx.hpp>
|
|
||||||
#include <pd-3ds/bknd-hid.hpp>
|
|
||||||
|
|
||||||
namespace PD {
|
|
||||||
void Init(void* data = nullptr);
|
|
||||||
}
|
|
||||||
@@ -1,69 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
/*
|
|
||||||
MIT License
|
|
||||||
|
|
||||||
Copyright (c) 2024 - 2025 tobid7
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <3ds.h>
|
|
||||||
#include <citro3d.h>
|
|
||||||
|
|
||||||
#include <pd/lithium/lithium.hpp>
|
|
||||||
|
|
||||||
namespace PD {
|
|
||||||
template <typename T>
|
|
||||||
class LinearAlloc : public Allocator<T> {
|
|
||||||
public:
|
|
||||||
LinearAlloc() = default;
|
|
||||||
~LinearAlloc() = default;
|
|
||||||
|
|
||||||
/** Never forget the sizeof(T) again (most painful bug i created) */
|
|
||||||
T* Allocate(size_t n) override { return (T*)linearAlloc(n * sizeof(T)); }
|
|
||||||
void Deallocate(T* ptr) { linearFree(ptr); }
|
|
||||||
};
|
|
||||||
class GfxC3D : public GfxDriver {
|
|
||||||
public:
|
|
||||||
GfxC3D() : GfxDriver("Citro3D") {}
|
|
||||||
~GfxC3D() = default;
|
|
||||||
|
|
||||||
PD_SHARED(GfxC3D);
|
|
||||||
|
|
||||||
void Init() override;
|
|
||||||
void Deinit() override;
|
|
||||||
void NewFrame() override;
|
|
||||||
void BindTex(PD::Li::TexAddress addr) override;
|
|
||||||
void RenderDrawData(
|
|
||||||
const std::vector<PD::Li::Command::Ref>& Commands) override;
|
|
||||||
PD::Li::Texture::Ref LoadTex(
|
|
||||||
const std::vector<PD::u8>& pixels, int w, int h,
|
|
||||||
PD::Li::Texture::Type type = PD::Li::Texture::Type::RGBA32,
|
|
||||||
PD::Li::Texture::Filter filter =
|
|
||||||
PD::Li::Texture::Filter::LINEAR) override;
|
|
||||||
|
|
||||||
Vec<Li::Vertex, LinearAlloc<Li::Vertex>> VertexBuffer;
|
|
||||||
Vec<u16, LinearAlloc<u16>> IndexBuffer;
|
|
||||||
int pLocProjection = 0;
|
|
||||||
DVLB_s* ShaderCode;
|
|
||||||
shaderProgram_s Shader;
|
|
||||||
C3D_AttrInfo ShaderInfo;
|
|
||||||
};
|
|
||||||
} // namespace PD
|
|
||||||
@@ -1,39 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
/*
|
|
||||||
MIT License
|
|
||||||
|
|
||||||
Copyright (c) 2024 - 2025 tobid7
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <pd/drivers/drivers.hpp>
|
|
||||||
|
|
||||||
namespace PD {
|
|
||||||
class Hid3DS : public HidDriver {
|
|
||||||
public:
|
|
||||||
Hid3DS();
|
|
||||||
~Hid3DS() = default;
|
|
||||||
|
|
||||||
PD_SHARED(Hid3DS);
|
|
||||||
|
|
||||||
void Update() override;
|
|
||||||
};
|
|
||||||
} // namespace PD
|
|
||||||
@@ -1,251 +0,0 @@
|
|||||||
/*
|
|
||||||
MIT License
|
|
||||||
|
|
||||||
Copyright (c) 2024 - 2025 tobid7
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <pd-3ds/bknd-gfx.hpp>
|
|
||||||
|
|
||||||
/// @brief Shader Code (Unused as i dont want to use libpicasso here (yet))
|
|
||||||
/// Update: Picasso breaks the linearRam or ram for somereason
|
|
||||||
/// as far as i found out loading anything into linear ram after
|
|
||||||
/// using libpicasso to compile a shader leads into a system freeze
|
|
||||||
const char* LIShaderCTR = R"(
|
|
||||||
; LI7 Shader
|
|
||||||
; Constants
|
|
||||||
.constf myconst(0.0, 1.0, 0.00392156862745, 0.0)
|
|
||||||
.alias ones myconst.yyyy ; Vector full of ones
|
|
||||||
|
|
||||||
; Uniforms
|
|
||||||
.fvec projection[4]
|
|
||||||
|
|
||||||
; Outputs
|
|
||||||
.out out_position position
|
|
||||||
.out out_color color
|
|
||||||
.out out_uv texcoord0
|
|
||||||
|
|
||||||
; Inputs
|
|
||||||
.alias in_xy v0
|
|
||||||
.alias in_uvc v1
|
|
||||||
.alias in_col v2
|
|
||||||
|
|
||||||
.entry vmain
|
|
||||||
.proc vmain
|
|
||||||
mov r0.xy, in_xy.xy
|
|
||||||
mov r0.w, ones
|
|
||||||
|
|
||||||
dp4 out_position.x, projection[0], r0
|
|
||||||
dp4 out_position.y, projection[1], r0
|
|
||||||
dp4 out_position.z, projection[2], r0
|
|
||||||
dp4 out_position.w, projection[3], r0
|
|
||||||
|
|
||||||
mov out_uv, in_uvc.xy
|
|
||||||
|
|
||||||
mul r1, myconst.zzzz, in_col
|
|
||||||
mov out_color, r1
|
|
||||||
end
|
|
||||||
.end
|
|
||||||
)";
|
|
||||||
|
|
||||||
// clang-format off
|
|
||||||
unsigned char li_shader[] = {
|
|
||||||
0x44, 0x56, 0x4c, 0x42, 0x1, 0x0, 0x0, 0x0, 0xa4, 0x0, 0x0, 0x0, 0x44, 0x56, 0x4c, 0x50, 0x0, 0x0, 0x0, 0x0, 0x28, 0x0, 0x0, 0x0, 0xa, 0x0, 0x0, 0x0, 0x50, 0x0, 0x0, 0x0, 0x9, 0x0, 0x0, 0x0, 0x98, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x4e, 0x1, 0xf0, 0x7, 0x4e, 0x2, 0x8, 0x2, 0x8, 0x3, 0x18, 0x2, 0x8, 0x4, 0x28, 0x2, 0x8, 0x5, 0x38, 0x2, 0x8, 0x6, 0x10, 0x40, 0x4c, 0x7, 0xf1, 0x27, 0x22, 0x8, 0x10, 0x21, 0x4c, 0x0, 0x0, 0x0, 0x88, 0xac, 0x2, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xa1, 0xa, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x68, 0xc3, 0x6, 0x0, 0x0, 0x0, 0x0, 0x0, 0x64, 0xc3, 0x6, 0x0, 0x0, 0x0, 0x0, 0x0, 0x62, 0xc3, 0x6, 0x0, 0x0, 0x0, 0x0, 0x0, 0x61, 0xc3, 0x6, 0x0, 0x0, 0x0, 0x0, 0x0, 0xaf, 0x2, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x4f, 0xd5, 0x6, 0x0, 0x0, 0x0, 0x0, 0x0, 0x6f, 0x3, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x44, 0x56, 0x4c, 0x45, 0x2, 0x10, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xa, 0x0, 0x0, 0x0, 0x0, 0x0, 0x7, 0x0, 0x0, 0x0, 0x0, 0x0, 0x40, 0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0, 0x54, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x54, 0x0, 0x0, 0x0, 0x3, 0x0, 0x0, 0x0, 0x6c, 0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0, 0x74, 0x0, 0x0, 0x0, 0xb, 0x0, 0x0, 0x0, 0x2, 0x0, 0x5f, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x3f, 0x0, 0x1, 0x1, 0x37, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xf, 0x0, 0x0, 0x0, 0x2, 0x0, 0x1, 0x0, 0xf, 0x0, 0x0, 0x0, 0x3, 0x0, 0x2, 0x0, 0xf, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x10, 0x0, 0x13, 0x0, 0x70, 0x72, 0x6f, 0x6a, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x0, 0x0,
|
|
||||||
};
|
|
||||||
// clang-format on
|
|
||||||
size_t li_shader_size = 0x124;
|
|
||||||
|
|
||||||
namespace PD {
|
|
||||||
GPU_TEXCOLOR GetTexFmt(Li::Texture::Type type) {
|
|
||||||
if (type == Li::Texture::RGBA32)
|
|
||||||
return GPU_RGBA8;
|
|
||||||
else if (type == Li::Texture::RGB24)
|
|
||||||
return GPU_RGB8;
|
|
||||||
else if (type == Li::Texture::A8)
|
|
||||||
return GPU_A8;
|
|
||||||
return GPU_RGBA8; // Default
|
|
||||||
}
|
|
||||||
int GetBPP(Li::Texture::Type type) {
|
|
||||||
if (type == Li::Texture::RGBA32)
|
|
||||||
return 4;
|
|
||||||
else if (type == Li::Texture::RGB24)
|
|
||||||
return 3;
|
|
||||||
else if (type == Li::Texture::A8)
|
|
||||||
return 1;
|
|
||||||
return 0; // Error
|
|
||||||
}
|
|
||||||
|
|
||||||
void GfxC3D::Init() {
|
|
||||||
VertexBuffer.Resize(4 * 8192);
|
|
||||||
IndexBuffer.Resize(6 * 8192);
|
|
||||||
|
|
||||||
Flags |= LiBackendFlags_FlipUV_Y;
|
|
||||||
|
|
||||||
ShaderCode = DVLB_ParseFile((uint32_t*)li_shader, li_shader_size);
|
|
||||||
shaderProgramInit(&Shader);
|
|
||||||
shaderProgramSetVsh(&Shader, &ShaderCode->DVLE[0]);
|
|
||||||
pLocProjection =
|
|
||||||
shaderInstanceGetUniformLocation(Shader.vertexShader, "projection");
|
|
||||||
|
|
||||||
AttrInfo_Init(&ShaderInfo);
|
|
||||||
AttrInfo_AddLoader(&ShaderInfo, 0, GPU_FLOAT, 2);
|
|
||||||
AttrInfo_AddLoader(&ShaderInfo, 1, GPU_FLOAT, 2);
|
|
||||||
AttrInfo_AddLoader(&ShaderInfo, 2, GPU_UNSIGNED_BYTE, 4);
|
|
||||||
}
|
|
||||||
|
|
||||||
void GfxC3D::Deinit() {
|
|
||||||
shaderProgramFree(&Shader);
|
|
||||||
DVLB_Free(ShaderCode);
|
|
||||||
}
|
|
||||||
|
|
||||||
void GfxC3D::NewFrame() {
|
|
||||||
C3D_BindProgram(&Shader);
|
|
||||||
C3D_SetAttrInfo(&ShaderInfo);
|
|
||||||
CurrentIndex = 0;
|
|
||||||
CurrentVertex = 0;
|
|
||||||
FrameCounter++;
|
|
||||||
/** Probably completly incorrect but just do it like that */
|
|
||||||
VertexCounter = CurrentVertex;
|
|
||||||
IndexCounter = CurrentIndex;
|
|
||||||
}
|
|
||||||
|
|
||||||
void GfxC3D::BindTex(PD::Li::TexAddress addr) {
|
|
||||||
C3D_TexBind(0, reinterpret_cast<C3D_Tex*>(addr));
|
|
||||||
}
|
|
||||||
|
|
||||||
void GfxC3D::RenderDrawData(const std::vector<PD::Li::Command::Ref>& Commands) {
|
|
||||||
// C3D_BindProgram(&Shader);
|
|
||||||
shaderProgramUse(&Shader);
|
|
||||||
C3D_SetAttrInfo(&ShaderInfo);
|
|
||||||
C3D_Mtx proj;
|
|
||||||
Mtx_OrthoTilt(&proj, 0.f, ViewPort.x, ViewPort.y, 0.f, 1.f, -1.f, false);
|
|
||||||
C3D_FVUnifMtx4x4(GPU_VERTEX_SHADER, pLocProjection, &proj);
|
|
||||||
// Mat4 proj = Mat4::Ortho(0.f, ViewPort.x, ViewPort.y, 0.f, 1.f, -1.f);
|
|
||||||
// C3D_FVUnifMtx4x4(GPU_VERTEX_SHADER, pLocProjection, (C3D_Mtx*)&proj);
|
|
||||||
C3D_DepthTest(false, GPU_GREATER, GPU_WRITE_ALL);
|
|
||||||
C3D_TexEnv* env = C3D_GetTexEnv(0);
|
|
||||||
C3D_TexEnvInit(env);
|
|
||||||
C3D_TexEnvSrc(env, C3D_Both, GPU_TEXTURE0);
|
|
||||||
C3D_TexEnvFunc(env, C3D_Both, GPU_MODULATE);
|
|
||||||
size_t index = 0;
|
|
||||||
while (index < Commands.size()) {
|
|
||||||
PD::Li::Texture::Ref Tex = Commands[index]->Tex;
|
|
||||||
if (!Tex) {
|
|
||||||
index++;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
bool ScissorEnabled = Commands[index]->ScissorOn;
|
|
||||||
ivec4 ScissorRect = Commands[index]->ScissorRect;
|
|
||||||
size_t StartIndex = CurrentIndex;
|
|
||||||
|
|
||||||
while (index < Commands.size() && Commands[index]->Tex == Tex &&
|
|
||||||
Commands[index]->ScissorOn == ScissorEnabled &&
|
|
||||||
Commands[index]->ScissorRect == ScissorRect) {
|
|
||||||
auto c = Commands[index].get();
|
|
||||||
for (size_t i = 0; i < c->IndexBuffer.Size(); i++) {
|
|
||||||
IndexBuffer[CurrentIndex++] = CurrentVertex + c->IndexBuffer.At(i);
|
|
||||||
}
|
|
||||||
for (size_t i = 0; i < c->VertexBuffer.Size(); i++) {
|
|
||||||
VertexBuffer[CurrentVertex++] = c->VertexBuffer.At(i);
|
|
||||||
}
|
|
||||||
index++;
|
|
||||||
}
|
|
||||||
if (ScissorEnabled) {
|
|
||||||
// Figure out this setup was pain
|
|
||||||
C3D_SetScissor(GPU_SCISSOR_NORMAL,
|
|
||||||
ViewPort.y - (ScissorRect.y + ScissorRect.w),
|
|
||||||
ViewPort.x - (ScissorRect.x + ScissorRect.z),
|
|
||||||
ViewPort.y - ScissorRect.y, ViewPort.x - ScissorRect.x);
|
|
||||||
} else {
|
|
||||||
C3D_SetScissor(GPU_SCISSOR_DISABLE, 0, 0, 0, 0);
|
|
||||||
}
|
|
||||||
BindTex(Tex->Address);
|
|
||||||
auto bufInfo = C3D_GetBufInfo();
|
|
||||||
BufInfo_Init(bufInfo);
|
|
||||||
BufInfo_Add(bufInfo, VertexBuffer.Data(), sizeof(Li::Vertex), 3, 0x210);
|
|
||||||
|
|
||||||
C3D_DrawElements(GPU_TRIANGLES, CurrentIndex - StartIndex,
|
|
||||||
C3D_UNSIGNED_SHORT, IndexBuffer.Data() + StartIndex);
|
|
||||||
}
|
|
||||||
C3D_DepthTest(true, GPU_GREATER, GPU_WRITE_ALL);
|
|
||||||
}
|
|
||||||
|
|
||||||
PD::Li::Texture::Ref GfxC3D::LoadTex(const std::vector<PD::u8>& pixels, int w,
|
|
||||||
int h, PD::Li::Texture::Type type,
|
|
||||||
PD::Li::Texture::Filter filter) {
|
|
||||||
if (w > 1024 || h > 1024) {
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
// Don't check here as check done before
|
|
||||||
PD::Li::Texture::Ref res = PD::Li::Texture::New();
|
|
||||||
int bpp = GetBPP(type);
|
|
||||||
ivec2 tex_size(w, h);
|
|
||||||
// Pow2
|
|
||||||
if (!PD::BitUtil::IsSingleBit(w)) {
|
|
||||||
tex_size.x = PD::BitUtil::GetPow2((unsigned int)w);
|
|
||||||
}
|
|
||||||
if (!PD::BitUtil::IsSingleBit(h)) {
|
|
||||||
tex_size.y = PD::BitUtil::GetPow2((unsigned int)h);
|
|
||||||
}
|
|
||||||
res->Size.x = w;
|
|
||||||
res->Size.y = h;
|
|
||||||
res->UV = fvec4(0.f, 1.f, ((float)w / (float)tex_size.x),
|
|
||||||
1.0 - ((float)h / (float)tex_size.y));
|
|
||||||
|
|
||||||
// Texture Setup
|
|
||||||
auto fltr = (filter == Li::Texture::NEAREST ? GPU_NEAREST : GPU_LINEAR);
|
|
||||||
auto tex_fmt = GetTexFmt(type);
|
|
||||||
auto tex = new C3D_Tex;
|
|
||||||
C3D_TexInit(tex, (u16)tex_size.x, (u16)tex_size.y, tex_fmt);
|
|
||||||
C3D_TexSetFilter(tex, fltr, fltr);
|
|
||||||
|
|
||||||
// Using std::fill_n instead cause i hate this error lines
|
|
||||||
// under the memset func in my editor
|
|
||||||
std::fill_n((PD::u8*)tex->data, tex->size, 0);
|
|
||||||
// memset(tex->data, 0, tex->size);s
|
|
||||||
|
|
||||||
/// Probably Remove this if statement in future
|
|
||||||
/// This are the things confirmed as working
|
|
||||||
if (bpp == 3 || bpp == 4 || bpp == 1) {
|
|
||||||
for (int x = 0; x < w; x++) {
|
|
||||||
for (int y = 0; y < h; y++) {
|
|
||||||
int dst_pos = ((((y >> 3) * ((int)tex_size.x >> 3) + (x >> 3)) << 6) +
|
|
||||||
((x & 1) | ((y & 1) << 1) | ((x & 2) << 1) |
|
|
||||||
((y & 2) << 2) | ((x & 4) << 2) | ((y & 4) << 3))) *
|
|
||||||
bpp;
|
|
||||||
int src_pos = (y * w + x) * bpp;
|
|
||||||
/// Best idea i had
|
|
||||||
for (int i = 0; i < bpp; i++) {
|
|
||||||
((u8*)tex->data)[dst_pos + bpp - 1 - i] = pixels[src_pos + i];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
C3D_TexFlush(tex);
|
|
||||||
}
|
|
||||||
|
|
||||||
tex->border = 0x00000000;
|
|
||||||
C3D_TexSetWrap(tex, GPU_REPEAT, GPU_REPEAT);
|
|
||||||
res->Address = (Li::TexAddress)tex;
|
|
||||||
std::cout << std::format("Tex {:#08x} Addr {:#08X}",
|
|
||||||
(Li::TexAddress)res.get(), res->Address)
|
|
||||||
<< std::endl;
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
} // namespace PD
|
|
||||||
@@ -1,87 +0,0 @@
|
|||||||
/*
|
|
||||||
MIT License
|
|
||||||
|
|
||||||
Copyright (c) 2024 - 2025 tobid7
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <3ds.h>
|
|
||||||
|
|
||||||
#include <pd-3ds/bknd-hid.hpp>
|
|
||||||
|
|
||||||
namespace PD {
|
|
||||||
Hid3DS::Hid3DS() : HidDriver("Hid3DS") {
|
|
||||||
this->Flags |= Flags_HasTouch;
|
|
||||||
this->Flags |= FLags_HasGamepad;
|
|
||||||
pBinds[KEY_A] = A;
|
|
||||||
pBinds[KEY_B] = B;
|
|
||||||
pBinds[KEY_X] = X;
|
|
||||||
pBinds[KEY_Y] = Y;
|
|
||||||
pBinds[KEY_START] = Start;
|
|
||||||
pBinds[KEY_SELECT] = Select;
|
|
||||||
pBinds[KEY_L] = L;
|
|
||||||
pBinds[KEY_R] = R;
|
|
||||||
pBinds[KEY_DUP] = DUp;
|
|
||||||
pBinds[KEY_DDOWN] = DDown;
|
|
||||||
pBinds[KEY_DLEFT] = DLeft;
|
|
||||||
pBinds[KEY_DRIGHT] = DRight;
|
|
||||||
pBinds[KEY_CPAD_UP] = CPUp;
|
|
||||||
pBinds[KEY_CPAD_DOWN] = CPDown;
|
|
||||||
pBinds[KEY_CPAD_LEFT] = CPLeft;
|
|
||||||
pBinds[KEY_CPAD_RIGHT] = CPRight;
|
|
||||||
pBinds[KEY_CSTICK_UP] = CSUp;
|
|
||||||
pBinds[KEY_CSTICK_DOWN] = CSDown;
|
|
||||||
pBinds[KEY_CSTICK_LEFT] = CSLeft;
|
|
||||||
pBinds[KEY_CSTICK_RIGHT] = CSRight;
|
|
||||||
pBinds[KEY_ZL] = ZL;
|
|
||||||
pBinds[KEY_ZR] = ZR;
|
|
||||||
pBinds[KEY_TOUCH] = Touch;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Hid3DS::Update() {
|
|
||||||
hidScanInput();
|
|
||||||
for (int i = 0; i < 2; i++) {
|
|
||||||
KeyEvents[i][Event_Down] = 0;
|
|
||||||
KeyEvents[i][Event_Held] = 0;
|
|
||||||
KeyEvents[i][Event_Up] = 0;
|
|
||||||
}
|
|
||||||
u32 kd = hidKeysDown();
|
|
||||||
u32 kh = hidKeysHeld();
|
|
||||||
u32 ku = hidKeysUp();
|
|
||||||
for (auto &b : pBinds) {
|
|
||||||
if (b.first & kd) {
|
|
||||||
KeyEvents[0][Event_Down] |= b.second;
|
|
||||||
}
|
|
||||||
if (b.first & kh) {
|
|
||||||
KeyEvents[0][Event_Held] |= b.second;
|
|
||||||
}
|
|
||||||
if (b.first & ku) {
|
|
||||||
KeyEvents[0][Event_Up] |= b.second;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (pLocked) {
|
|
||||||
SwapTab();
|
|
||||||
}
|
|
||||||
touchPosition t;
|
|
||||||
hidTouchRead(&t);
|
|
||||||
pMouse[1] = pMouse[0]; // Cycle pMouse pos
|
|
||||||
pMouse[0] = fvec2(t.px, t.py);
|
|
||||||
}
|
|
||||||
} // namespace PD
|
|
||||||
@@ -1,36 +0,0 @@
|
|||||||
/*
|
|
||||||
MIT License
|
|
||||||
|
|
||||||
Copyright (c) 2024 - 2025 tobid7
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <palladium>
|
|
||||||
#include <pd-3ds.hpp>
|
|
||||||
|
|
||||||
namespace PD {
|
|
||||||
void Init(void* data) {
|
|
||||||
// Dekstop Init Stage
|
|
||||||
// First use default OS Driver
|
|
||||||
PD::OS::Init();
|
|
||||||
PD::Gfx::Init(PD::GfxC3D::New());
|
|
||||||
PD::Hid::Init(PD::Hid3DS::New());
|
|
||||||
}
|
|
||||||
} // namespace PD
|
|
||||||
83
backends/CMakeLists.txt
Normal file
83
backends/CMakeLists.txt
Normal file
@@ -0,0 +1,83 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.22)
|
||||||
|
|
||||||
|
project(pd-system)
|
||||||
|
|
||||||
|
option(PD_ENABLE_OPENGL2 "Enable OpenGL 2.1 (On Supported Hardware)" ON)
|
||||||
|
option(PD_ENABLE_OPENGL3 "Enable OpenGL 3.3 (On Supported Hardware)" ON)
|
||||||
|
option(PD_ENABLE_DIRECTX9 "Enable DirectX9 Support" ON)
|
||||||
|
option(PD_ENABLE_CITRO3D "Enable Citro3D Support (3DS)" OFF)
|
||||||
|
option(PD_ENABLE_VULKAN "Not implemented yet" OFF)
|
||||||
|
|
||||||
|
if(NOT WIN32) # cause we are not on windows...
|
||||||
|
set(PD_ENABLE_DIRECTX9 OFF)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(${CMAKE_SYSTEM_NAME} STREQUAL "Nintendo3DS")
|
||||||
|
set(PD_ENABLE_OPENGL2 OFF)
|
||||||
|
set(PD_ENABLE_OPENGL3 OFF)
|
||||||
|
set(PD_ENABLE_VULKAN OFF)
|
||||||
|
set(PD_ENABLE_CITRO3D ON)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
add_library(pd-system STATIC
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/source/gl-helper.cpp
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/source/gfx_opengl2.cpp
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/source/gfx_opengl3.cpp
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/source/gfx_directx9.cpp
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/source/gfx_citro3d.cpp
|
||||||
|
)
|
||||||
|
|
||||||
|
target_include_directories(pd-system
|
||||||
|
PUBLIC
|
||||||
|
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
|
||||||
|
$<INSTALL_INTERFACE:include>
|
||||||
|
)
|
||||||
|
|
||||||
|
target_compile_options(palladium
|
||||||
|
PUBLIC $<$<CXX_COMPILER_ID:GNU,Clang>:
|
||||||
|
-fmacro-prefix-map=${CMAKE_CURRENT_SOURCE_DIR}/source=source
|
||||||
|
-fmacro-prefix-map=${CMAKE_CURRENT_SOURCE_DIR}/include=include
|
||||||
|
>
|
||||||
|
)
|
||||||
|
|
||||||
|
target_compile_definitions(pd-system
|
||||||
|
PUBLIC
|
||||||
|
$<$<BOOL:${PD_ENABLE_OPENGL2}>:PD_ENABLE_OPENGL2>
|
||||||
|
$<$<BOOL:${PD_ENABLE_OPENGL3}>:PD_ENABLE_OPENGL3>
|
||||||
|
$<$<BOOL:${PD_ENABLE_VULKAN}>:PD_ENABLE_VULKAN>
|
||||||
|
$<$<BOOL:${PD_ENABLE_DIRECTX9}>:PD_ENABLE_DIRECTX9>
|
||||||
|
$<$<BOOL:${PD_ENABLE_CITRO3D}>:PD_ENABLE_CITRO3D>
|
||||||
|
)
|
||||||
|
|
||||||
|
# Palladium
|
||||||
|
target_link_libraries(pd-system PUBLIC palladium::palladium)
|
||||||
|
|
||||||
|
# glad (if we have any OpenGL version included)
|
||||||
|
if(PD_ENABLE_OPENGL2 OR PD_ENABLE_OPENGL3)
|
||||||
|
target_link_libraries(pd-system
|
||||||
|
PUBLIC glad
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# DirectX9
|
||||||
|
if(PD_ENABLE_DIRECTX9)
|
||||||
|
target_link_libraries(pd-system
|
||||||
|
PUBLIC
|
||||||
|
d3d9
|
||||||
|
d3dcompiler
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(${CMAKE_SYSTEM_NAME} STREQUAL "Nintendo3DS")
|
||||||
|
target_link_libraries(pd-system
|
||||||
|
PUBLIC
|
||||||
|
pica::pica
|
||||||
|
citro3d
|
||||||
|
ctru
|
||||||
|
)
|
||||||
|
else()
|
||||||
|
target_link_libraries(pd-system
|
||||||
|
PUBLIC
|
||||||
|
spirv-helper
|
||||||
|
)
|
||||||
|
endif()
|
||||||
24
backends/README.md
Normal file
24
backends/README.md
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
# Backends
|
||||||
|
|
||||||
|
- [Graphics](#graphics)
|
||||||
|
- [OpenGL2](#opengl2-legacy)
|
||||||
|
- [OpenGL3](#opengl3-modern-opengl)
|
||||||
|
- [DirectX9](#directx9-could-potentially-cover-more-then-opengl2)
|
||||||
|
- [Citro3D](#citro3d-3ds)
|
||||||
|
|
||||||
|
## Graphics
|
||||||
|
|
||||||
|
### OpenGL2 (Legacy)
|
||||||
|
|
||||||
|
> [!NOTE]
|
||||||
|
> As SPIRV to GLSL 120 translation doesn't work, your'e forced to write separate shaders for this backend
|
||||||
|
|
||||||
|
### OpenGL3+ (Modern OpenGL)
|
||||||
|
|
||||||
|
### DirectX9 (Could potentially cover more than OpenGL2)
|
||||||
|
|
||||||
|
### Citro3D (3DS)
|
||||||
|
|
||||||
|
> [!NOTE]
|
||||||
|
> This backend requires shaders as binary file, directly in the code or as string for libpicasso
|
||||||
|
> The Fragment Stage is special and is still wip
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
cmake_minimum_required(VERSION 3.22)
|
|
||||||
|
|
||||||
project(pd-desktop LANGUAGES CXX VERSION 0.5.0)
|
|
||||||
|
|
||||||
add_subdirectory(glad)
|
|
||||||
add_subdirectory(glfw)
|
|
||||||
|
|
||||||
set(SRC
|
|
||||||
source/bknd-gfx.cpp
|
|
||||||
source/bknd-hid.cpp
|
|
||||||
source/pd-desktop.cpp
|
|
||||||
)
|
|
||||||
|
|
||||||
pd_add_lib(pd-desktop SRC_FILES ${SRC})
|
|
||||||
target_include_directories(pd-desktop PUBLIC include)
|
|
||||||
target_link_libraries(pd-desktop PUBLIC palladium glad glfw)
|
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
cmake_minimum_required(VERSION 3.22)
|
|
||||||
|
|
||||||
add_library(glad source/glad.c)
|
|
||||||
target_include_directories(glad PUBLIC include)
|
|
||||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Submodule backends/desktop/glfw deleted from e7ea71be03
@@ -1,32 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
/*
|
|
||||||
MIT License
|
|
||||||
|
|
||||||
Copyright (c) 2024 - 2025 tobid7
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <pd-desktop/bknd-gfx.hpp>
|
|
||||||
#include <pd-desktop/bknd-hid.hpp>
|
|
||||||
|
|
||||||
namespace PD {
|
|
||||||
void Init(void* data = nullptr);
|
|
||||||
}
|
|
||||||
@@ -1,62 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
/*
|
|
||||||
MIT License
|
|
||||||
|
|
||||||
Copyright (c) 2024 - 2025 tobid7
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <glad/glad.h>
|
|
||||||
|
|
||||||
/** SEPARATOR */
|
|
||||||
#include <GLFW/glfw3.h>
|
|
||||||
/** SEPARATOR */
|
|
||||||
|
|
||||||
#include <pd/lithium/lithium.hpp>
|
|
||||||
|
|
||||||
namespace PD {
|
|
||||||
class GfxGL2 : public GfxDriver {
|
|
||||||
public:
|
|
||||||
GfxGL2() : GfxDriver("OpenGL2") {}
|
|
||||||
~GfxGL2() = default;
|
|
||||||
|
|
||||||
PD_SHARED(GfxGL2);
|
|
||||||
|
|
||||||
void Init() override;
|
|
||||||
void Deinit() override;
|
|
||||||
void NewFrame() override;
|
|
||||||
void BindTex(PD::Li::TexAddress addr) override;
|
|
||||||
void RenderDrawData(
|
|
||||||
const std::vector<PD::Li::Command::Ref>& Commands) override;
|
|
||||||
PD::Li::Texture::Ref LoadTex(
|
|
||||||
const std::vector<PD::u8>& pixels, int w, int h,
|
|
||||||
PD::Li::Texture::Type type = PD::Li::Texture::Type::RGBA32,
|
|
||||||
PD::Li::Texture::Filter filter =
|
|
||||||
PD::Li::Texture::Filter::LINEAR) override;
|
|
||||||
|
|
||||||
PD::Vec<Li::Vertex> VertexBuffer;
|
|
||||||
PD::Vec<PD::u16> IndexBuffer;
|
|
||||||
GLuint Shader;
|
|
||||||
GLuint pLocProjection;
|
|
||||||
GLuint pLocTex;
|
|
||||||
GLuint VBO, IBO;
|
|
||||||
};
|
|
||||||
} // namespace PD
|
|
||||||
@@ -1,72 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
/*
|
|
||||||
MIT License
|
|
||||||
|
|
||||||
Copyright (c) 2024 - 2025 tobid7
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <GLFW/glfw3.h>
|
|
||||||
|
|
||||||
#include <pd/drivers/drivers.hpp>
|
|
||||||
|
|
||||||
namespace PD {
|
|
||||||
class HidGLFW : public HidDriver {
|
|
||||||
public:
|
|
||||||
HidGLFW(GLFWwindow* win);
|
|
||||||
~HidGLFW() = default;
|
|
||||||
|
|
||||||
PD_SHARED(HidGLFW);
|
|
||||||
|
|
||||||
void Update() override;
|
|
||||||
void GetInputStr(std::string& str) override;
|
|
||||||
void HandleTextOps();
|
|
||||||
bool pTimedHeld(KbKey k) {
|
|
||||||
if (pTimings.count(k)) {
|
|
||||||
if (IsEvent(Event_Up, k)) {
|
|
||||||
pTimings.erase(k);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return (PD::OS::GetTime() - pTimings[k]) > 50;
|
|
||||||
}
|
|
||||||
if (!IsEvent(Event_Held, k)) {
|
|
||||||
if (pTimings.count(k)) {
|
|
||||||
pTimings.erase(k);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (IsEvent(Event_Held, k)) {
|
|
||||||
pTimings[k] = PD::OS::GetTime();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Data section */
|
|
||||||
GLFWwindow* Window;
|
|
||||||
int PrevState;
|
|
||||||
std::unordered_map<int, int> PrevStates;
|
|
||||||
static std::string* pText;
|
|
||||||
bool pInTextMode = false;
|
|
||||||
PD::u64 pLastUpdate = 0;
|
|
||||||
std::unordered_map<KbKey, u64> pTimings;
|
|
||||||
};
|
|
||||||
} // namespace PD
|
|
||||||
@@ -1,256 +0,0 @@
|
|||||||
/*
|
|
||||||
MIT License
|
|
||||||
|
|
||||||
Copyright (c) 2024 - 2025 tobid7
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <pd-desktop/bknd-gfx.hpp>
|
|
||||||
|
|
||||||
namespace PD {
|
|
||||||
const char* vertex_shader = R"(
|
|
||||||
#version 120
|
|
||||||
|
|
||||||
attribute vec2 pos;
|
|
||||||
attribute vec2 uv;
|
|
||||||
attribute vec4 color;
|
|
||||||
|
|
||||||
varying vec2 oUV;
|
|
||||||
varying vec4 oColor;
|
|
||||||
|
|
||||||
// Probably forgot about this matrix and
|
|
||||||
// searched hours for why the rendering isn't working :/
|
|
||||||
uniform mat4 projection;
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
gl_Position = projection*vec4(pos, 0.0, 1.0);
|
|
||||||
oUV = uv;
|
|
||||||
oColor = color;
|
|
||||||
}
|
|
||||||
)";
|
|
||||||
|
|
||||||
const char* frag_shader = R"(
|
|
||||||
#version 120
|
|
||||||
|
|
||||||
varying vec2 oUV;
|
|
||||||
varying vec4 oColor;
|
|
||||||
|
|
||||||
uniform sampler2D tex;
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
vec4 tc = texture2D(tex, oUV);
|
|
||||||
gl_FragColor = tc*oColor;
|
|
||||||
}
|
|
||||||
)";
|
|
||||||
|
|
||||||
GLuint compileShader(const std::string& source, GLenum type) {
|
|
||||||
GLuint shader = glCreateShader(type);
|
|
||||||
const char* src = source.c_str();
|
|
||||||
glShaderSource(shader, 1, &src, nullptr);
|
|
||||||
glCompileShader(shader);
|
|
||||||
|
|
||||||
GLint success;
|
|
||||||
glGetShaderiv(shader, GL_COMPILE_STATUS, &success);
|
|
||||||
if (!success) {
|
|
||||||
char infoLog[512];
|
|
||||||
glGetShaderInfoLog(shader, 512, nullptr, infoLog);
|
|
||||||
std::cerr << "Shader Compilation Error: " << infoLog << std::endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
return shader;
|
|
||||||
}
|
|
||||||
|
|
||||||
GLuint createShaderProgram(const std::string& vertexShaderSource,
|
|
||||||
const std::string& fragmentShaderSource) {
|
|
||||||
GLuint vertexShader = compileShader(vertexShaderSource, GL_VERTEX_SHADER);
|
|
||||||
GLuint fragmentShader =
|
|
||||||
compileShader(fragmentShaderSource, GL_FRAGMENT_SHADER);
|
|
||||||
|
|
||||||
GLuint shaderProgram = glCreateProgram();
|
|
||||||
glAttachShader(shaderProgram, vertexShader);
|
|
||||||
glAttachShader(shaderProgram, fragmentShader);
|
|
||||||
glLinkProgram(shaderProgram);
|
|
||||||
|
|
||||||
GLint success;
|
|
||||||
glGetProgramiv(shaderProgram, GL_LINK_STATUS, &success);
|
|
||||||
if (!success) {
|
|
||||||
char infoLog[512];
|
|
||||||
glGetProgramInfoLog(shaderProgram, 512, nullptr, infoLog);
|
|
||||||
std::cerr << "Shader Program Linking Error: " << infoLog << std::endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
glDeleteShader(vertexShader);
|
|
||||||
glDeleteShader(fragmentShader);
|
|
||||||
|
|
||||||
return shaderProgram;
|
|
||||||
}
|
|
||||||
|
|
||||||
void SetupShaderAttribs(GLuint Shader) {
|
|
||||||
GLint _pos = glGetAttribLocation(Shader, "pos");
|
|
||||||
GLint _uv = glGetAttribLocation(Shader, "uv");
|
|
||||||
GLint _color = glGetAttribLocation(Shader, "color");
|
|
||||||
glVertexAttribPointer(_pos, 2, GL_FLOAT, GL_FALSE, sizeof(PD::Li::Vertex),
|
|
||||||
(void*)offsetof(PD::Li::Vertex, Pos));
|
|
||||||
glEnableVertexAttribArray(_pos);
|
|
||||||
|
|
||||||
glVertexAttribPointer(_uv, 2, GL_FLOAT, GL_FALSE, sizeof(PD::Li::Vertex),
|
|
||||||
(void*)offsetof(PD::Li::Vertex, UV));
|
|
||||||
glEnableVertexAttribArray(_uv);
|
|
||||||
|
|
||||||
glVertexAttribPointer(_color, 4, GL_UNSIGNED_BYTE, GL_TRUE,
|
|
||||||
sizeof(PD::Li::Vertex),
|
|
||||||
(void*)offsetof(PD::Li::Vertex, Color));
|
|
||||||
glEnableVertexAttribArray(_color);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Actual Backend */
|
|
||||||
|
|
||||||
void GfxGL2::Init() {
|
|
||||||
VertexBuffer.Resize(4 * 8192);
|
|
||||||
IndexBuffer.Resize(6 * 8192);
|
|
||||||
Shader = createShaderProgram(vertex_shader, frag_shader);
|
|
||||||
glUseProgram(Shader);
|
|
||||||
|
|
||||||
glGenBuffers(1, &VBO);
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, VBO);
|
|
||||||
|
|
||||||
// Attribs Setup
|
|
||||||
SetupShaderAttribs(Shader);
|
|
||||||
|
|
||||||
glGenBuffers(1, &IBO);
|
|
||||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, IBO);
|
|
||||||
|
|
||||||
pLocTex = glGetUniformLocation(Shader, "tex");
|
|
||||||
pLocProjection = glGetUniformLocation(Shader, "projection");
|
|
||||||
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
|
||||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
void GfxGL2::Deinit() {
|
|
||||||
glDeleteBuffers(1, &VBO);
|
|
||||||
glDeleteBuffers(1, &IBO);
|
|
||||||
}
|
|
||||||
|
|
||||||
void GfxGL2::NewFrame() {
|
|
||||||
/*
|
|
||||||
glViewport(0, 0, ViewPort.x, ViewPort.y);
|
|
||||||
glClearColor(ClearColor.x, ClearColor.y, ClearColor.z, ClearColor.w);
|
|
||||||
glClear(GL_COLOR_BUFFER_BIT);
|
|
||||||
*/
|
|
||||||
Projection = Mat4::Ortho(0.f, ViewPort.x, ViewPort.y, 0.f, -1.f, 1.f);
|
|
||||||
glUseProgram(Shader);
|
|
||||||
glUniformMatrix4fv(pLocProjection, 1, GL_FALSE, Projection.m.data());
|
|
||||||
glEnable(GL_BLEND);
|
|
||||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
|
||||||
FrameCounter++;
|
|
||||||
VertexCounter = CurrentVertex;
|
|
||||||
IndexCounter = CurrentIndex;
|
|
||||||
CurrentVertex = 0;
|
|
||||||
CurrentIndex = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void GfxGL2::BindTex(PD::Li::TexAddress addr) {
|
|
||||||
// Actually not using the Address as Address
|
|
||||||
glActiveTexture(GL_TEXTURE0);
|
|
||||||
glBindTexture(GL_TEXTURE_2D, (GLuint)addr);
|
|
||||||
glUniform1i(pLocTex, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
void GfxGL2::RenderDrawData(const std::vector<PD::Li::Command::Ref>& Commands) {
|
|
||||||
size_t index = 0;
|
|
||||||
while (index < Commands.size()) {
|
|
||||||
PD::Li::Texture::Ref Tex = Commands[index]->Tex;
|
|
||||||
if (!Tex) {
|
|
||||||
index++;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
size_t StartIndex = CurrentIndex;
|
|
||||||
bool ScissorOn = Commands[index]->ScissorOn;
|
|
||||||
ivec4 ScissorRect = Commands[index]->ScissorRect;
|
|
||||||
|
|
||||||
while (index < Commands.size() && Commands[index]->Tex == Tex &&
|
|
||||||
Commands[index]->ScissorOn == ScissorOn &&
|
|
||||||
Commands[index]->ScissorRect == ScissorRect) {
|
|
||||||
auto c = Commands[index].get();
|
|
||||||
for (size_t i = 0; i < c->IndexBuffer.Size(); i++) {
|
|
||||||
IndexBuffer[CurrentIndex++] = CurrentVertex + c->IndexBuffer.At(i);
|
|
||||||
}
|
|
||||||
for (size_t i = 0; i < c->VertexBuffer.Size(); i++) {
|
|
||||||
VertexBuffer[CurrentVertex++] = c->VertexBuffer.At(i);
|
|
||||||
}
|
|
||||||
index++;
|
|
||||||
}
|
|
||||||
if (ScissorOn) {
|
|
||||||
glScissor(ScissorRect.x, ViewPort.y - (ScissorRect.y + ScissorRect.w),
|
|
||||||
ScissorRect.z, ScissorRect.w);
|
|
||||||
glEnable(GL_SCISSOR_TEST);
|
|
||||||
} else {
|
|
||||||
glDisable(GL_SCISSOR_TEST);
|
|
||||||
}
|
|
||||||
BindTex(Tex->Address);
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, VBO);
|
|
||||||
glBufferData(GL_ARRAY_BUFFER, CurrentVertex * sizeof(PD::Li::Vertex),
|
|
||||||
&VertexBuffer[0], GL_DYNAMIC_DRAW);
|
|
||||||
// For some reason we need to set these every frame for every buffer
|
|
||||||
// Found that out when creating My 3d Engine
|
|
||||||
SetupShaderAttribs(Shader);
|
|
||||||
|
|
||||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, IBO);
|
|
||||||
glBufferData(GL_ELEMENT_ARRAY_BUFFER, CurrentIndex * sizeof(PD::u16),
|
|
||||||
&IndexBuffer[0], GL_DYNAMIC_DRAW);
|
|
||||||
|
|
||||||
glDrawElements(GL_TRIANGLES, CurrentIndex - StartIndex, GL_UNSIGNED_SHORT,
|
|
||||||
(void*)(StartIndex * sizeof(PD::u16)));
|
|
||||||
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
|
||||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
|
||||||
BindTex(0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
PD::Li::Texture::Ref GfxGL2::LoadTex(const std::vector<PD::u8>& pixels, int w,
|
|
||||||
int h, PD::Li::Texture::Type type,
|
|
||||||
PD::Li::Texture::Filter filter) {
|
|
||||||
GLuint texID;
|
|
||||||
glGenTextures(1, &texID);
|
|
||||||
glBindTexture(GL_TEXTURE_2D, texID);
|
|
||||||
|
|
||||||
// Set base format (Always using RGBA as base)
|
|
||||||
GLenum fmt = GL_RGBA;
|
|
||||||
if (type == PD::Li::Texture::Type::RGB24) {
|
|
||||||
fmt = GL_RGB;
|
|
||||||
} else if (type == PD::Li::Texture::Type::A8) {
|
|
||||||
fmt = GL_ALPHA;
|
|
||||||
}
|
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, fmt, w, h, 0, fmt, GL_UNSIGNED_BYTE,
|
|
||||||
pixels.data());
|
|
||||||
if (filter == PD::Li::Texture::Filter::LINEAR) {
|
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
|
||||||
} else if (filter == PD::Li::Texture::Filter::NEAREST) {
|
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
|
||||||
}
|
|
||||||
glBindTexture(GL_TEXTURE_2D, 0);
|
|
||||||
auto res = PD::Li::Texture::New(texID, PD::ivec2(w, h));
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
} // namespace PD
|
|
||||||
@@ -1,166 +0,0 @@
|
|||||||
/*
|
|
||||||
MIT License
|
|
||||||
|
|
||||||
Copyright (c) 2024 - 2025 tobid7
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <pd-desktop/bknd-hid.hpp>
|
|
||||||
namespace PD {
|
|
||||||
std::string* HidGLFW::pText;
|
|
||||||
// Default Call back (If no Text input is requsted)
|
|
||||||
void NullTextCB(GLFWwindow* win, unsigned int c) {}
|
|
||||||
// Text callback if requested
|
|
||||||
void TextCB(GLFWwindow* win, unsigned int c) {
|
|
||||||
if (!HidGLFW::pText) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
*HidGLFW::pText += (char)c;
|
|
||||||
}
|
|
||||||
HidGLFW::HidGLFW(GLFWwindow* win) : HidDriver("HidGLFW") {
|
|
||||||
Window = win;
|
|
||||||
glfwSetCharCallback(Window, NullTextCB);
|
|
||||||
Flags |= Flags_HasKeyboard;
|
|
||||||
Flags |= Flags_HasMouse;
|
|
||||||
pBinds[GLFW_MOUSE_BUTTON_LEFT] = Touch;
|
|
||||||
/*pBinds[GLFW_KEY_F3] = Kb_3;
|
|
||||||
pBinds[GLFW_KEY_ESCAPE] = Kb_Escape;
|
|
||||||
pBinds[GLFW_KEY_F11] = Kb_F11;
|
|
||||||
pBinds[GLFW_KEY_ESCAPE] = Kb_Escape;
|
|
||||||
pBinds[GLFW_KEY_Q] = Kb_Q;
|
|
||||||
pBinds[GLFW_KEY_W] = Kb_W;
|
|
||||||
pBinds[GLFW_KEY_E] = Kb_E;
|
|
||||||
pBinds[GLFW_KEY_R] = Kb_R;
|
|
||||||
pBinds[GLFW_KEY_T] = Kb_T;
|
|
||||||
pBinds[GLFW_KEY_Z] = Kb_Z;
|
|
||||||
pBinds[GLFW_KEY_U] = Kb_U;
|
|
||||||
pBinds[GLFW_KEY_I] = Kb_I;
|
|
||||||
pBinds[GLFW_KEY_O] = Kb_O;
|
|
||||||
pBinds[GLFW_KEY_P] = Kb_P;
|
|
||||||
pBinds[GLFW_KEY_A] = Kb_A;
|
|
||||||
pBinds[GLFW_KEY_S] = Kb_S;
|
|
||||||
pBinds[GLFW_KEY_D] = Kb_D;
|
|
||||||
pBinds[GLFW_KEY_F] = Kb_F;
|
|
||||||
pBinds[GLFW_KEY_G] = Kb_G;
|
|
||||||
pBinds[GLFW_KEY_H] = Kb_H;
|
|
||||||
pBinds[GLFW_KEY_J] = Kb_J;
|
|
||||||
pBinds[GLFW_KEY_K] = Kb_K;
|
|
||||||
pBinds[GLFW_KEY_L] = Kb_L;
|
|
||||||
pBinds[GLFW_KEY_Y] = Kb_Y;
|
|
||||||
pBinds[GLFW_KEY_X] = Kb_X;
|
|
||||||
pBinds[GLFW_KEY_C] = Kb_C;
|
|
||||||
pBinds[GLFW_KEY_V] = Kb_V;
|
|
||||||
pBinds[GLFW_KEY_B] = Kb_B;
|
|
||||||
pBinds[GLFW_KEY_N] = Kb_N;
|
|
||||||
pBinds[GLFW_KEY_M] = Kb_M;
|
|
||||||
pBinds[GLFW_KEY_LEFT_SHIFT] = Kb_LShift;
|
|
||||||
pBinds[GLFW_KEY_F1] = Kb_F1;
|
|
||||||
pBinds[GLFW_KEY_F2] = Kb_F2;
|
|
||||||
pBinds[GLFW_KEY_F3] = Kb_F3;
|
|
||||||
pBinds[GLFW_KEY_F4] = Kb_F4;
|
|
||||||
pBinds[GLFW_KEY_F5] = Kb_F5;
|
|
||||||
pBinds[GLFW_KEY_F6] = Kb_F6;
|
|
||||||
pBinds[GLFW_KEY_F7] = Kb_F7;
|
|
||||||
pBinds[GLFW_KEY_F8] = Kb_F8;
|
|
||||||
pBinds[GLFW_KEY_F9] = Kb_F9;
|
|
||||||
pBinds[GLFW_KEY_F10] = Kb_F10;
|
|
||||||
pBinds[GLFW_KEY_F11] = Kb_F11;
|
|
||||||
pBinds[GLFW_KEY_F12] = Kb_F12;
|
|
||||||
pBinds[GLFW_KEY_1] = Kb_1;
|
|
||||||
pBinds[GLFW_KEY_2] = Kb_2;
|
|
||||||
pBinds[GLFW_KEY_3] = Kb_3;
|
|
||||||
pBinds[GLFW_KEY_4] = Kb_4;
|
|
||||||
pBinds[GLFW_KEY_5] = Kb_5;
|
|
||||||
pBinds[GLFW_KEY_6] = Kb_6;
|
|
||||||
pBinds[GLFW_KEY_7] = Kb_7;
|
|
||||||
pBinds[GLFW_KEY_8] = Kb_8;
|
|
||||||
pBinds[GLFW_KEY_9] = Kb_9;
|
|
||||||
pBinds[GLFW_KEY_0] = Kb_0;
|
|
||||||
pBinds[GLFW_KEY_BACKSPACE] = Kb_Backspace;
|
|
||||||
pBinds[GLFW_KEY_ENTER] = Kb_Enter;*/
|
|
||||||
}
|
|
||||||
|
|
||||||
void HidGLFW::Update() {
|
|
||||||
// Clear States
|
|
||||||
for (int i = 0; i < 2; i++) {
|
|
||||||
KeyEvents[i][Event_Down] = 0;
|
|
||||||
KeyEvents[i][Event_Held] = 0;
|
|
||||||
KeyEvents[i][Event_Up] = 0;
|
|
||||||
for (auto& it : KbKeyEvents[i]) {
|
|
||||||
it.second = Event_Null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Keyboard Logic
|
|
||||||
/*for (auto& it : pBinds) {
|
|
||||||
int kbstate = glfwGetKey(Window, it.first);
|
|
||||||
if (kbstate == GLFW_PRESS) {
|
|
||||||
if (PrevStates[it.first] == GLFW_RELEASE) {
|
|
||||||
KbKeyEvents[0][it.second] = Event_Down;
|
|
||||||
}
|
|
||||||
KbKeyEvents[0][it.second] = Event_Held;
|
|
||||||
} else if (kbstate == GLFW_RELEASE && PrevStates[it.first] == GLFW_PRESS) {
|
|
||||||
KbKeyEvents[0][it.second] = Event_Up;
|
|
||||||
}
|
|
||||||
PrevStates[it.first] = kbstate;
|
|
||||||
}*/
|
|
||||||
// Mouse Logic (Todo: Support all mouse buttons)
|
|
||||||
int state = glfwGetMouseButton(Window, GLFW_MOUSE_BUTTON_LEFT);
|
|
||||||
if (state == GLFW_PRESS) {
|
|
||||||
if (PrevState == GLFW_RELEASE) {
|
|
||||||
KeyEvents[0][Event_Down] |= Touch;
|
|
||||||
}
|
|
||||||
KeyEvents[0][Event_Held] |= Touch;
|
|
||||||
} else if (state == GLFW_RELEASE && PrevState == GLFW_PRESS) {
|
|
||||||
KeyEvents[0][Event_Up] |= Touch;
|
|
||||||
}
|
|
||||||
|
|
||||||
PrevState = state;
|
|
||||||
if (pLocked) {
|
|
||||||
SwapTab();
|
|
||||||
}
|
|
||||||
double x, y;
|
|
||||||
glfwGetCursorPos(Window, &x, &y);
|
|
||||||
pMouse[1] = pMouse[0]; // Cycle pMouse pos
|
|
||||||
pMouse[0] = fvec2(x, y);
|
|
||||||
if (pInTextMode && (PD::OS::GetTime() - pLastUpdate) > 50) {
|
|
||||||
pLastUpdate = PD::OS::GetTime();
|
|
||||||
HandleTextOps();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void HidGLFW::GetInputStr(std::string& str) {
|
|
||||||
pText = &str;
|
|
||||||
glfwSetCharCallback(Window, TextCB);
|
|
||||||
pInTextMode = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void HidGLFW::HandleTextOps() {
|
|
||||||
if (!pText) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
/*if (pTimedHeld(Kb_Backspace)) {
|
|
||||||
if (!pText->empty()) {
|
|
||||||
pText->pop_back();
|
|
||||||
}
|
|
||||||
} else if (pTimedHeld(Kb_Enter)) {
|
|
||||||
*pText += '\n';
|
|
||||||
}*/
|
|
||||||
}
|
|
||||||
} // namespace PD
|
|
||||||
@@ -1,43 +0,0 @@
|
|||||||
/*
|
|
||||||
MIT License
|
|
||||||
|
|
||||||
Copyright (c) 2024 - 2025 tobid7
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <palladium>
|
|
||||||
#include <pd-desktop.hpp>
|
|
||||||
|
|
||||||
namespace PD {
|
|
||||||
void Init(void* data) {
|
|
||||||
if (!data) {
|
|
||||||
std::cout << "[PD-DRIVERS] Error: pd-desktop requires GLFWwindow* "
|
|
||||||
"reference as data "
|
|
||||||
"input!"
|
|
||||||
<< std::endl;
|
|
||||||
abort();
|
|
||||||
}
|
|
||||||
// Dekstop Init Stage
|
|
||||||
// First use default OS Driver
|
|
||||||
PD::OS::Init();
|
|
||||||
PD::Gfx::Init(PD::GfxGL2::New());
|
|
||||||
PD::Hid::Init(PD::HidGLFW::New(reinterpret_cast<GLFWwindow*>(data)));
|
|
||||||
}
|
|
||||||
} // namespace PD
|
|
||||||
67
backends/include/pd_system/ctr-linear-allocator.hpp
Normal file
67
backends/include/pd_system/ctr-linear-allocator.hpp
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#ifdef __3DS__
|
||||||
|
#include <3ds.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <limits>
|
||||||
|
#include <memory>
|
||||||
|
#include <stdexcept>
|
||||||
|
|
||||||
|
// Custom C++ Allocator class to interface with libctru linear heap memory
|
||||||
|
// based on this guide:
|
||||||
|
// https://johnfarrier.com/custom-allocators-in-c-high-performance-memory-management/
|
||||||
|
|
||||||
|
namespace PD {
|
||||||
|
template <typename T>
|
||||||
|
class LinearAllocator {
|
||||||
|
public:
|
||||||
|
using value_type = T;
|
||||||
|
LinearAllocator() noexcept = default;
|
||||||
|
template <typename U>
|
||||||
|
constexpr LinearAllocator(const LinearAllocator<U>&) noexcept {}
|
||||||
|
|
||||||
|
T* allocate(std::size_t n) {
|
||||||
|
if (n > max_size()) {
|
||||||
|
throw std::runtime_error("[PD] LinearAllocator: Bad alloc!");
|
||||||
|
}
|
||||||
|
#ifdef __3DS__
|
||||||
|
return static_cast<T*>(linearAlloc(n * sizeof(T)));
|
||||||
|
#else
|
||||||
|
return static_cast<T*>(malloc(n * sizeof(T)));
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
#ifdef __3DS__
|
||||||
|
void deallocate(T* p, std::size_t) noexcept { linearFree(p); }
|
||||||
|
#else
|
||||||
|
void deallocate(T* p, std::size_t) noexcept { free(p); }
|
||||||
|
#endif
|
||||||
|
|
||||||
|
template <class U, class... Args>
|
||||||
|
void construct(U* p, Args&&... args) {
|
||||||
|
::new ((void*)p) U(std::forward<Args>(args)...);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class U>
|
||||||
|
void destroy(U* p) {
|
||||||
|
p->~U();
|
||||||
|
}
|
||||||
|
|
||||||
|
friend bool operator==(const LinearAllocator, const LinearAllocator) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
friend bool operator!=(const LinearAllocator, const LinearAllocator) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef __3DS__
|
||||||
|
// Use linearSpace free as max_size to not allocate out of bounds
|
||||||
|
// or to b eable to see a crash report screen.
|
||||||
|
size_t max_size() const noexcept { return linearSpaceFree(); }
|
||||||
|
#else
|
||||||
|
size_t max_size() const noexcept {
|
||||||
|
return std::numeric_limits<size_t>::max();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
};
|
||||||
|
} // namespace PD
|
||||||
39
backends/include/pd_system/gfx_citro3d.hpp
Normal file
39
backends/include/pd_system/gfx_citro3d.hpp
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <pd/drivers/gfx.hpp>
|
||||||
|
#include <pd_system/ctr-linear-allocator.hpp>
|
||||||
|
|
||||||
|
namespace PD {
|
||||||
|
struct GfxCitro3DConfig {
|
||||||
|
// Vertex Allocator
|
||||||
|
template <typename T>
|
||||||
|
using VertexAlloc = LinearAllocator<T>;
|
||||||
|
// Index Allocator
|
||||||
|
template <typename T>
|
||||||
|
using IndexAlloc = LinearAllocator<T>;
|
||||||
|
|
||||||
|
static constexpr size_t NumVertices = 32768; // 8192*4
|
||||||
|
static constexpr size_t NumIndices = 49152; // 8192*6
|
||||||
|
};
|
||||||
|
|
||||||
|
class GfxCitro3D : public GfxDriverBase<GfxCitro3DConfig> {
|
||||||
|
public:
|
||||||
|
GfxCitro3D() : GfxDriverBase("Citro3D") {}
|
||||||
|
~GfxCitro3D() {}
|
||||||
|
|
||||||
|
void SysInit() override;
|
||||||
|
void SysDeinit() override;
|
||||||
|
void Submit(size_t count, size_t start) override;
|
||||||
|
void BindTexture(TextureID id) override;
|
||||||
|
void SysReset() override;
|
||||||
|
Li::Texture LoadTexture(
|
||||||
|
const std::vector<PD::u8>& pixels, int w, int h,
|
||||||
|
TextureFormat type = TextureFormat::RGBA32,
|
||||||
|
TextureFilter filter = TextureFilter::Linear) override;
|
||||||
|
void DeleteTexture(const Li::Texture& tex) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
struct Impl;
|
||||||
|
Impl* impl = nullptr;
|
||||||
|
};
|
||||||
|
} // namespace PD
|
||||||
40
backends/include/pd_system/gfx_directx9.hpp
Normal file
40
backends/include/pd_system/gfx_directx9.hpp
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <pd/drivers/gfx.hpp>
|
||||||
|
|
||||||
|
namespace PD {
|
||||||
|
struct GfxDirectX9Config {
|
||||||
|
// Vertex Allocator
|
||||||
|
template <typename T>
|
||||||
|
using VertexAlloc = std::allocator<T>;
|
||||||
|
// Index Allocator
|
||||||
|
template <typename T>
|
||||||
|
using IndexAlloc = std::allocator<T>;
|
||||||
|
|
||||||
|
static constexpr size_t NumVertices = 32768; // 8192*4
|
||||||
|
static constexpr size_t NumIndices = 49152; // 8192*6
|
||||||
|
};
|
||||||
|
|
||||||
|
class GfxDirectX9 : public GfxDriverBase<GfxDirectX9Config> {
|
||||||
|
public:
|
||||||
|
GfxDirectX9(void* device = nullptr)
|
||||||
|
: GfxDriverBase("DirectX9"), pDevice(device) {}
|
||||||
|
~GfxDirectX9() {}
|
||||||
|
|
||||||
|
void SysInit() override;
|
||||||
|
void SysDeinit() override;
|
||||||
|
void Submit(size_t count, size_t start) override;
|
||||||
|
void BindTexture(TextureID id) override;
|
||||||
|
void SysReset() override;
|
||||||
|
Li::Texture LoadTexture(
|
||||||
|
const std::vector<PD::u8>& pixels, int w, int h,
|
||||||
|
TextureFormat type = TextureFormat::RGBA32,
|
||||||
|
TextureFilter filter = TextureFilter::Linear) override;
|
||||||
|
void DeleteTexture(const Li::Texture& tex) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
struct Impl;
|
||||||
|
Impl* impl = nullptr;
|
||||||
|
void* pDevice = nullptr;
|
||||||
|
};
|
||||||
|
} // namespace PD
|
||||||
45
backends/include/pd_system/gfx_opengl2.hpp
Normal file
45
backends/include/pd_system/gfx_opengl2.hpp
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <pd/drivers/gfx.hpp>
|
||||||
|
|
||||||
|
namespace PD {
|
||||||
|
struct GfxOpenGL2Config {
|
||||||
|
// Vertex Allocator
|
||||||
|
template <typename T>
|
||||||
|
using VertexAlloc = std::allocator<T>;
|
||||||
|
// Index Allocator
|
||||||
|
template <typename T>
|
||||||
|
using IndexAlloc = std::allocator<T>;
|
||||||
|
|
||||||
|
static constexpr size_t NumVertices = 32768; // 8192*4
|
||||||
|
static constexpr size_t NumIndices = 49152; // 8192*6
|
||||||
|
};
|
||||||
|
|
||||||
|
class GfxOpenGL2 : public GfxDriverBase<GfxOpenGL2Config> {
|
||||||
|
public:
|
||||||
|
GfxOpenGL2() : GfxDriverBase("OpenGL2") {}
|
||||||
|
~GfxOpenGL2() {}
|
||||||
|
|
||||||
|
void SysInit() override;
|
||||||
|
void SysDeinit() override;
|
||||||
|
void Submit(size_t count, size_t start) override;
|
||||||
|
void BindTexture(TextureID id) override;
|
||||||
|
void SysReset() override;
|
||||||
|
Li::Texture LoadTexture(
|
||||||
|
const std::vector<PD::u8>& pixels, int w, int h,
|
||||||
|
TextureFormat type = TextureFormat::RGBA32,
|
||||||
|
TextureFilter filter = TextureFilter::Linear) override;
|
||||||
|
void DeleteTexture(const Li::Texture& tex) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
void pSetupShaderAttribs(u32 shader);
|
||||||
|
u32 pShader = 0;
|
||||||
|
u32 VBO = 0;
|
||||||
|
u32 IBO = 0;
|
||||||
|
int pLocTex = 0;
|
||||||
|
int pLocAlfa = 0;
|
||||||
|
int pLocProjection = 0;
|
||||||
|
static const char* pVertCode;
|
||||||
|
static const char* pFragCode;
|
||||||
|
};
|
||||||
|
} // namespace PD
|
||||||
43
backends/include/pd_system/gfx_opengl3.hpp
Normal file
43
backends/include/pd_system/gfx_opengl3.hpp
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <pd/drivers/gfx.hpp>
|
||||||
|
|
||||||
|
namespace PD {
|
||||||
|
struct GfxOpenGL3Config {
|
||||||
|
// Vertex Allocator
|
||||||
|
template <typename T>
|
||||||
|
using VertexAlloc = std::allocator<T>;
|
||||||
|
// Index Allocator
|
||||||
|
template <typename T>
|
||||||
|
using IndexAlloc = std::allocator<T>;
|
||||||
|
|
||||||
|
static constexpr size_t NumVertices = 32768; // 8192*4
|
||||||
|
static constexpr size_t NumIndices = 49152; // 8192*6
|
||||||
|
};
|
||||||
|
|
||||||
|
class GfxOpenGL3 : public GfxDriverBase<GfxOpenGL3Config> {
|
||||||
|
public:
|
||||||
|
GfxOpenGL3() : GfxDriverBase("OpenGL3") {}
|
||||||
|
~GfxOpenGL3() {}
|
||||||
|
|
||||||
|
void SysInit() override;
|
||||||
|
void SysDeinit() override;
|
||||||
|
void Submit(size_t count, size_t start) override;
|
||||||
|
void BindTexture(TextureID id) override;
|
||||||
|
void SysReset() override;
|
||||||
|
Li::Texture LoadTexture(
|
||||||
|
const std::vector<PD::u8>& pixels, int w, int h,
|
||||||
|
TextureFormat type = TextureFormat::RGBA32,
|
||||||
|
TextureFilter filter = TextureFilter::Linear) override;
|
||||||
|
void DeleteTexture(const Li::Texture& tex) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
u32 pShader = 0;
|
||||||
|
u32 VBO = 0;
|
||||||
|
u32 IBO = 0;
|
||||||
|
u32 VAO = 0;
|
||||||
|
int pLocTex = 0;
|
||||||
|
int pLocAlfa = 0;
|
||||||
|
int pLocProjection = 0;
|
||||||
|
};
|
||||||
|
} // namespace PD
|
||||||
7
backends/include/pd_system/gl-helper.hpp
Normal file
7
backends/include/pd_system/gl-helper.hpp
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <pd/common.hpp>
|
||||||
|
|
||||||
|
namespace PD {
|
||||||
|
u32 CreateShaderProgram(const char* vert, const char* frag);
|
||||||
|
}
|
||||||
17
backends/include/pd_system/shaders.hpp
Normal file
17
backends/include/pd_system/shaders.hpp
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
namespace PD {
|
||||||
|
/**
|
||||||
|
* Shader blobs
|
||||||
|
* Required for OpenGL3, and maybe later for vulkan
|
||||||
|
* Shaders can be found in /tools/pdsg/shaders
|
||||||
|
*/
|
||||||
|
namespace Shaders {
|
||||||
|
// clang-format off
|
||||||
|
const unsigned int VertexShader[] = { 0x7230203, 0x10000, 0x8000B, 0x2B, 0x0, 0x20011, 0x1, 0x6000B, 0x1, 0x4C534C47, 0x6474732E, 0x3035342E, 0x0, 0x3000E, 0x0, 0x1, 0xB000F, 0x0, 0x4, 0x6E69616D, 0x0, 0xD, 0x19, 0x24, 0x25, 0x27, 0x29, 0x30003, 0x2, 0x1CC, 0x40005, 0x4, 0x6E69616D, 0x0, 0x60005, 0xB, 0x505F6C67, 0x65567265, 0x78657472, 0x0, 0x60006, 0xB, 0x0, 0x505F6C67, 0x7469736F, 0x6E6F69, 0x70006, 0xB, 0x1, 0x505F6C67, 0x746E696F, 0x657A6953, 0x0, 0x70006, 0xB, 0x2, 0x435F6C67, 0x4470696C, 0x61747369, 0x65636E, 0x70006, 0xB, 0x3, 0x435F6C67, 0x446C6C75, 0x61747369, 0x65636E, 0x30005, 0xD, 0x0, 0x30005, 0x11, 0x4F4255, 0x60006, 0x11, 0x0, 0x6A6F7270, 0x69746365, 0x6E6F, 0x30005, 0x13, 0x6F6275, 0x30005, 0x19, 0x736F70, 0x30005, 0x24, 0x56556F, 0x30005, 0x25, 0x7675, 0x40005, 0x27, 0x6C6F436F, 0x726F, 0x40005, 0x29, 0x6F6C6F63, 0x72, 0x30047, 0xB, 0x2, 0x50048, 0xB, 0x0, 0xB, 0x0, 0x50048, 0xB, 0x1, 0xB, 0x1, 0x50048, 0xB, 0x2, 0xB, 0x3, 0x50048, 0xB, 0x3, 0xB, 0x4, 0x30047, 0x11, 0x2, 0x40048, 0x11, 0x0, 0x5, 0x50048, 0x11, 0x0, 0x7, 0x10, 0x50048, 0x11, 0x0, 0x23, 0x0, 0x40047, 0x13, 0x21, 0x0, 0x40047, 0x13, 0x22, 0x0, 0x40047, 0x19, 0x1E, 0x0, 0x40047, 0x24, 0x1E, 0x0, 0x40047, 0x25, 0x1E, 0x1, 0x40047, 0x27, 0x1E, 0x1, 0x40047, 0x29, 0x1E, 0x2, 0x20013, 0x2, 0x30021, 0x3, 0x2, 0x30016, 0x6, 0x20, 0x40017, 0x7, 0x6, 0x4, 0x40015, 0x8, 0x20, 0x0, 0x4002B, 0x8, 0x9, 0x1, 0x4001C, 0xA, 0x6, 0x9, 0x6001E, 0xB, 0x7, 0x6, 0xA, 0xA, 0x40020, 0xC, 0x3, 0xB, 0x4003B, 0xC, 0xD, 0x3, 0x40015, 0xE, 0x20, 0x1, 0x4002B, 0xE, 0xF, 0x0, 0x40018, 0x10, 0x7, 0x4, 0x3001E, 0x11, 0x10, 0x40020, 0x12, 0x2, 0x11, 0x4003B, 0x12, 0x13, 0x2, 0x40020, 0x14, 0x2, 0x10, 0x40017, 0x17, 0x6, 0x2, 0x40020, 0x18, 0x1, 0x17, 0x4003B, 0x18, 0x19, 0x1, 0x4002B, 0x6, 0x1B, 0x0, 0x4002B, 0x6, 0x1C, 0x3F800000, 0x40020, 0x21, 0x3, 0x7, 0x40020, 0x23, 0x3, 0x17, 0x4003B, 0x23, 0x24, 0x3, 0x4003B, 0x18, 0x25, 0x1, 0x4003B, 0x21, 0x27, 0x3, 0x40020, 0x28, 0x1, 0x7, 0x4003B, 0x28, 0x29, 0x1, 0x50036, 0x2, 0x4, 0x0, 0x3, 0x200F8, 0x5, 0x50041, 0x14, 0x15, 0x13, 0xF, 0x4003D, 0x10, 0x16, 0x15, 0x4003D, 0x17, 0x1A, 0x19, 0x50051, 0x6, 0x1D, 0x1A, 0x0, 0x50051, 0x6, 0x1E, 0x1A, 0x1, 0x70050, 0x7, 0x1F, 0x1D, 0x1E, 0x1B, 0x1C, 0x50091, 0x7, 0x20, 0x16, 0x1F, 0x50041, 0x21, 0x22, 0xD, 0xF, 0x3003E, 0x22, 0x20, 0x4003D, 0x17, 0x26, 0x25, 0x3003E, 0x24, 0x26, 0x4003D, 0x7, 0x2A, 0x29, 0x3003E, 0x27, 0x2A, 0x100FD, 0x10038, };
|
||||||
|
// clang-format on
|
||||||
|
// clang-format off
|
||||||
|
const unsigned int FragmentShader[] = { 0x7230203, 0x10000, 0x8000B, 0x39, 0x0, 0x20011, 0x1, 0x6000B, 0x1, 0x4C534C47, 0x6474732E, 0x3035342E, 0x0, 0x3000E, 0x0, 0x1, 0x8000F, 0x0, 0x4, 0x6E69616D, 0x0, 0x11, 0x22, 0x24, 0x30003, 0x2, 0x1CC, 0x40005, 0x4, 0x6E69616D, 0x0, 0x30005, 0x9, 0x6374, 0x30005, 0xD, 0x786574, 0x30005, 0x11, 0x56556F, 0x50005, 0x16, 0x68737550, 0x61746144, 0x0, 0x50006, 0x16, 0x0, 0x61666C61, 0x0, 0x40005, 0x18, 0x68737570, 0x0, 0x50005, 0x22, 0x67617246, 0x6F6C6F43, 0x72, 0x40005, 0x24, 0x6C6F436F, 0x726F, 0x40047, 0xD, 0x21, 0x0, 0x40047, 0xD, 0x22, 0x0, 0x40047, 0x11, 0x1E, 0x0, 0x30047, 0x16, 0x2, 0x50048, 0x16, 0x0, 0x23, 0x0, 0x40047, 0x24, 0x1E, 0x1, 0x20013, 0x2, 0x30021, 0x3, 0x2, 0x30016, 0x6, 0x20, 0x40017, 0x7, 0x6, 0x4, 0x40020, 0x8, 0x7, 0x7, 0x90019, 0xA, 0x6, 0x1, 0x0, 0x0, 0x0, 0x1, 0x0, 0x3001B, 0xB, 0xA, 0x40020, 0xC, 0x0, 0xB, 0x4003B, 0xC, 0xD, 0x0, 0x40017, 0xF, 0x6, 0x2, 0x40020, 0x10, 0x1, 0xF, 0x4003B, 0x10, 0x11, 0x1, 0x4002B, 0x6, 0x13, 0x0, 0x40015, 0x15, 0x20, 0x1, 0x3001E, 0x16, 0x15, 0x40020, 0x17, 0x9, 0x16, 0x4003B, 0x17, 0x18, 0x9, 0x4002B, 0x15, 0x19, 0x0, 0x40020, 0x1A, 0x9, 0x15, 0x20014, 0x1D, 0x40020, 0x21, 0x3, 0x7, 0x4003B, 0x21, 0x22, 0x3, 0x40020, 0x23, 0x1, 0x7, 0x4003B, 0x23, 0x24, 0x1, 0x40017, 0x25, 0x6, 0x3, 0x40015, 0x28, 0x20, 0x0, 0x4002B, 0x28, 0x29, 0x3, 0x40020, 0x2A, 0x7, 0x6, 0x40020, 0x2D, 0x1, 0x6, 0x50036, 0x2, 0x4, 0x0, 0x3, 0x200F8, 0x5, 0x4003B, 0x8, 0x9, 0x7, 0x4003D, 0xB, 0xE, 0xD, 0x4003D, 0xF, 0x12, 0x11, 0x70058, 0x7, 0x14, 0xE, 0x12, 0x2, 0x13, 0x3003E, 0x9, 0x14, 0x50041, 0x1A, 0x1B, 0x18, 0x19, 0x4003D, 0x15, 0x1C, 0x1B, 0x500AB, 0x1D, 0x1E, 0x1C, 0x19, 0x300F7, 0x20, 0x0, 0x400FA, 0x1E, 0x1F, 0x35, 0x200F8, 0x1F, 0x4003D, 0x7, 0x26, 0x24, 0x8004F, 0x25, 0x27, 0x26, 0x26, 0x0, 0x1, 0x2, 0x50041, 0x2A, 0x2B, 0x9, 0x29, 0x4003D, 0x6, 0x2C, 0x2B, 0x50041, 0x2D, 0x2E, 0x24, 0x29, 0x4003D, 0x6, 0x2F, 0x2E, 0x50085, 0x6, 0x30, 0x2C, 0x2F, 0x50051, 0x6, 0x31, 0x27, 0x0, 0x50051, 0x6, 0x32, 0x27, 0x1, 0x50051, 0x6, 0x33, 0x27, 0x2, 0x70050, 0x7, 0x34, 0x31, 0x32, 0x33, 0x30, 0x3003E, 0x22, 0x34, 0x200F9, 0x20, 0x200F8, 0x35, 0x4003D, 0x7, 0x36, 0x9, 0x4003D, 0x7, 0x37, 0x24, 0x50085, 0x7, 0x38, 0x36, 0x37, 0x3003E, 0x22, 0x38, 0x200F9, 0x20, 0x200F8, 0x20, 0x100FD, 0x10038, };
|
||||||
|
// clang-format on
|
||||||
|
} // namespace Shaders
|
||||||
|
} // namespace PD
|
||||||
6
backends/include/pdsystem
Normal file
6
backends/include/pdsystem
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <pd_system/gfx_citro3d.hpp>
|
||||||
|
#include <pd_system/gfx_directx9.hpp>
|
||||||
|
#include <pd_system/gfx_opengl2.hpp>
|
||||||
|
#include <pd_system/gfx_opengl3.hpp>
|
||||||
254
backends/source/gfx_citro3d.cpp
Normal file
254
backends/source/gfx_citro3d.cpp
Normal file
@@ -0,0 +1,254 @@
|
|||||||
|
// Well yes, i finally try it
|
||||||
|
|
||||||
|
#include <pd/core/core.hpp>
|
||||||
|
#include <pd/lithium/formatters.hpp>
|
||||||
|
#include <pd_system/gfx_citro3d.hpp>
|
||||||
|
|
||||||
|
#if defined(PD_ENABLE_CITRO3D) && defined(__3DS__)
|
||||||
|
|
||||||
|
#include <3ds.h>
|
||||||
|
#include <citro3d.h>
|
||||||
|
|
||||||
|
#include <pd/drivers/drivers.hpp>
|
||||||
|
#include <pica.hpp>
|
||||||
|
|
||||||
|
namespace PD {
|
||||||
|
const char* LIShaderCTR = R"(
|
||||||
|
; LI7 Shader
|
||||||
|
; Constants
|
||||||
|
.constf myconst(0.0, 1.0, 0.00392156862745, 0.0)
|
||||||
|
.alias ones myconst.yyyy ; Vector full of ones
|
||||||
|
|
||||||
|
; Uniforms
|
||||||
|
.fvec projection[4]
|
||||||
|
|
||||||
|
; Outputs
|
||||||
|
.out out_position position
|
||||||
|
.out out_color color
|
||||||
|
.out out_uv texcoord0
|
||||||
|
|
||||||
|
; Inputs
|
||||||
|
.alias in_xy v0
|
||||||
|
.alias in_uvc v1
|
||||||
|
.alias in_col v2
|
||||||
|
|
||||||
|
.entry vmain
|
||||||
|
.proc vmain
|
||||||
|
mov r0.xy, in_xy.xy
|
||||||
|
mov r0.w, ones
|
||||||
|
|
||||||
|
dp4 out_position.x, projection[0], r0
|
||||||
|
dp4 out_position.y, projection[1], r0
|
||||||
|
dp4 out_position.z, projection[2], r0
|
||||||
|
dp4 out_position.w, projection[3], r0
|
||||||
|
|
||||||
|
mov out_uv, in_uvc.xy
|
||||||
|
|
||||||
|
mul r1, myconst.zzzz, in_col
|
||||||
|
mov out_color, r1
|
||||||
|
end
|
||||||
|
.end
|
||||||
|
)";
|
||||||
|
|
||||||
|
struct GfxCitro3D::Impl {
|
||||||
|
C3D_AttrInfo pAttr;
|
||||||
|
shaderProgram_s pShader;
|
||||||
|
DVLB_s* pCode;
|
||||||
|
int uLocProjection = 0;
|
||||||
|
C3D_Tex* CurrentTex = nullptr;
|
||||||
|
std::vector<u8> pShaderRaw;
|
||||||
|
|
||||||
|
GPU_TEXCOLOR TextureTranslateFormat(TextureFormat fmt) {
|
||||||
|
switch (fmt) {
|
||||||
|
case PD::TextureFormat::A8:
|
||||||
|
return GPU_A8;
|
||||||
|
case PD::TextureFormat::RGB24:
|
||||||
|
return GPU_RGB8;
|
||||||
|
case PD::TextureFormat::RGBA32:
|
||||||
|
return GPU_RGBA8;
|
||||||
|
default:
|
||||||
|
return GPU_RGBA8;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int TextureFormat2Bpp(TextureFormat fmt) {
|
||||||
|
switch (fmt) {
|
||||||
|
case PD::TextureFormat::A8:
|
||||||
|
return 1;
|
||||||
|
case PD::TextureFormat::RGB24:
|
||||||
|
return 3;
|
||||||
|
case PD::TextureFormat::RGBA32:
|
||||||
|
return 4;
|
||||||
|
default:
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void SetupPixelStage() {
|
||||||
|
shaderProgramUse(&pShader);
|
||||||
|
C3D_BindProgram(&pShader);
|
||||||
|
C3D_SetAttrInfo(&pAttr);
|
||||||
|
C3D_DepthTest(false, GPU_GREATER, GPU_WRITE_ALL);
|
||||||
|
if (!CurrentTex) return;
|
||||||
|
C3D_TexEnv* env = C3D_GetTexEnv(0);
|
||||||
|
C3D_TexEnvInit(env);
|
||||||
|
switch (CurrentTex->fmt) {
|
||||||
|
case GPU_A4:
|
||||||
|
case GPU_A8:
|
||||||
|
case GPU_L4:
|
||||||
|
case GPU_L8:
|
||||||
|
C3D_TexEnvSrc(env, C3D_Alpha, GPU_TEXTURE0);
|
||||||
|
C3D_TexEnvFunc(env, C3D_RGB, GPU_REPLACE);
|
||||||
|
C3D_TexEnvFunc(env, C3D_Alpha, GPU_MODULATE);
|
||||||
|
break;
|
||||||
|
case GPU_RGB565:
|
||||||
|
C3D_TexEnvSrc(env, C3D_Alpha, GPU_TEXTURE0);
|
||||||
|
C3D_TexEnvFunc(env, C3D_RGB, GPU_MODULATE);
|
||||||
|
C3D_TexEnvFunc(env, C3D_Alpha, GPU_REPLACE);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
C3D_TexEnvSrc(env, C3D_Both, GPU_TEXTURE0);
|
||||||
|
C3D_TexEnvFunc(env, C3D_Both, GPU_MODULATE);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
void GfxCitro3D::SysInit() {
|
||||||
|
if (impl) return;
|
||||||
|
PDLOG("GfxCitro3D::SysInit();");
|
||||||
|
impl = new Impl();
|
||||||
|
impl->pShaderRaw = Pica::AssembleCode(LIShaderCTR);
|
||||||
|
impl->pCode = DVLB_ParseFile((uint32_t*)impl->pShaderRaw.data(),
|
||||||
|
impl->pShaderRaw.size());
|
||||||
|
shaderProgramInit(&impl->pShader);
|
||||||
|
shaderProgramSetVsh(&impl->pShader, &impl->pCode->DVLE[0]);
|
||||||
|
impl->uLocProjection = shaderInstanceGetUniformLocation(
|
||||||
|
impl->pShader.vertexShader, "projection");
|
||||||
|
|
||||||
|
AttrInfo_Init(&impl->pAttr);
|
||||||
|
AttrInfo_AddLoader(&impl->pAttr, 0, GPU_FLOAT, 2);
|
||||||
|
AttrInfo_AddLoader(&impl->pAttr, 1, GPU_FLOAT, 2);
|
||||||
|
AttrInfo_AddLoader(&impl->pAttr, 2, GPU_UNSIGNED_BYTE, 4);
|
||||||
|
}
|
||||||
|
|
||||||
|
void GfxCitro3D::SysDeinit() {
|
||||||
|
if (!impl) return;
|
||||||
|
shaderProgramFree(&impl->pShader);
|
||||||
|
DVLB_Free(impl->pCode);
|
||||||
|
delete impl;
|
||||||
|
impl = nullptr;
|
||||||
|
PDLOG("GfxCitro3D::SysDeinit()");
|
||||||
|
}
|
||||||
|
|
||||||
|
void GfxCitro3D::Submit(size_t count, size_t start) {
|
||||||
|
if (!impl) return;
|
||||||
|
BindTexture(CurrentTex);
|
||||||
|
impl->SetupPixelStage(); // needs to be called after
|
||||||
|
C3D_Mtx proj;
|
||||||
|
Mtx_OrthoTilt(&proj, 0.f, ViewPort.x, ViewPort.y, 0.f, 1.f, -1.f, false);
|
||||||
|
C3D_FVUnifMtx4x4(GPU_VERTEX_SHADER, impl->uLocProjection, &proj);
|
||||||
|
// C3D_FVUnifMtx4x4(GPU_VERTEX_SHADER, impl->uLocProjection,
|
||||||
|
// (C3D_Mtx*)&Projection);
|
||||||
|
auto buf = C3D_GetBufInfo();
|
||||||
|
BufInfo_Init(buf);
|
||||||
|
BufInfo_Add(buf, GetVertexBufPtr(0), sizeof(Li::Vertex), 3, 0x210);
|
||||||
|
C3D_DrawElements(GPU_TRIANGLES, count, C3D_UNSIGNED_SHORT,
|
||||||
|
GetIndexBufPtr(start));
|
||||||
|
impl->CurrentTex = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
void GfxCitro3D::BindTexture(TextureID id) {
|
||||||
|
if (!impl || !id) return;
|
||||||
|
impl->CurrentTex = (C3D_Tex*)id;
|
||||||
|
C3D_TexBind(0, (C3D_Tex*)id);
|
||||||
|
}
|
||||||
|
|
||||||
|
void GfxCitro3D::SysReset() {
|
||||||
|
if (!impl) return;
|
||||||
|
C3D_CullFace(GPU_CULL_NONE);
|
||||||
|
}
|
||||||
|
|
||||||
|
Li::Texture GfxCitro3D::LoadTexture(const std::vector<PD::u8>& pixels, int w,
|
||||||
|
int h, TextureFormat type,
|
||||||
|
TextureFilter filter) {
|
||||||
|
if (!impl || w > 1024 || h > 1024) return Li::Texture();
|
||||||
|
// Don't check here as check done before
|
||||||
|
PD::Li::Texture res;
|
||||||
|
int bpp = impl->TextureFormat2Bpp(type);
|
||||||
|
ivec2 tex_size(w, h);
|
||||||
|
// Pow2
|
||||||
|
if (!PD::Bits::IsSingleBit(w)) {
|
||||||
|
tex_size.x = PD::Bits::GetPow2((unsigned int)w);
|
||||||
|
}
|
||||||
|
if (!PD::Bits::IsSingleBit(h)) {
|
||||||
|
tex_size.y = PD::Bits::GetPow2((unsigned int)h);
|
||||||
|
}
|
||||||
|
res.SetSize(w, h);
|
||||||
|
res.SetUV(0.f, 1.f, ((float)w / (float)tex_size.x),
|
||||||
|
1.0 - ((float)h / (float)tex_size.y));
|
||||||
|
|
||||||
|
// Texture Setup
|
||||||
|
auto fltr = (filter == TextureFilter::Linear ? GPU_NEAREST : GPU_LINEAR);
|
||||||
|
auto tex_fmt = impl->TextureTranslateFormat(type);
|
||||||
|
auto tex = new C3D_Tex;
|
||||||
|
C3D_TexInit(tex, (u16)tex_size.x, (u16)tex_size.y, tex_fmt);
|
||||||
|
C3D_TexSetFilter(tex, fltr, fltr);
|
||||||
|
|
||||||
|
std::memset((PD::u8*)tex->data, 0x0, tex->size);
|
||||||
|
|
||||||
|
/// Probably Remove this if statement in future
|
||||||
|
/// This are the things confirmed as working
|
||||||
|
if (bpp == 3 || bpp == 4 || bpp == 1) {
|
||||||
|
for (int x = 0; x < w; x++) {
|
||||||
|
for (int y = 0; y < h; y++) {
|
||||||
|
int dst_pos = ((((y >> 3) * ((int)tex_size.x >> 3) + (x >> 3)) << 6) +
|
||||||
|
((x & 1) | ((y & 1) << 1) | ((x & 2) << 1) |
|
||||||
|
((y & 2) << 2) | ((x & 4) << 2) | ((y & 4) << 3))) *
|
||||||
|
bpp;
|
||||||
|
int src_pos = (y * w + x) * bpp;
|
||||||
|
/// Best idea i had
|
||||||
|
for (int i = 0; i < bpp; i++) {
|
||||||
|
((u8*)tex->data)[dst_pos + bpp - 1 - i] = pixels[src_pos + i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
C3D_TexFlush(tex);
|
||||||
|
}
|
||||||
|
|
||||||
|
tex->border = 0x00000000;
|
||||||
|
C3D_TexSetWrap(tex, GPU_REPEAT, GPU_REPEAT);
|
||||||
|
res.SetID((TextureID)tex);
|
||||||
|
RegisterTexture(res);
|
||||||
|
PDLOG("GfxCitro3D::LoadTexture -> {{ {} }}, [{}, {}]", res, type, filter);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
void GfxCitro3D::DeleteTexture(const Li::Texture& tex) {
|
||||||
|
if (!tex.GetID()) return;
|
||||||
|
UnregisterTexture(tex);
|
||||||
|
C3D_Tex* t = reinterpret_cast<C3D_Tex*>(tex.GetID());
|
||||||
|
C3D_TexDelete(t);
|
||||||
|
delete t;
|
||||||
|
}
|
||||||
|
} // namespace PD
|
||||||
|
#else
|
||||||
|
namespace PD {
|
||||||
|
void GfxCitro3D::SysInit() {
|
||||||
|
PDLOG(
|
||||||
|
"GfxCitro3D::SysInit: Citro3D Driver is not included in "
|
||||||
|
"palladium-system");
|
||||||
|
}
|
||||||
|
void GfxCitro3D::SysDeinit() {}
|
||||||
|
void GfxCitro3D::Submit(size_t count, size_t start) {}
|
||||||
|
void GfxCitro3D::BindTexture(TextureID id) {}
|
||||||
|
void GfxCitro3D::SysReset() {}
|
||||||
|
Li::Texture GfxCitro3D::LoadTexture(const std::vector<PD::u8>& pixels, int w,
|
||||||
|
int h, TextureFormat type,
|
||||||
|
TextureFilter filter) {
|
||||||
|
return Li::Texture();
|
||||||
|
}
|
||||||
|
void GfxCitro3D::DeleteTexture(const Li::Texture& tex) {}
|
||||||
|
} // namespace PD
|
||||||
|
#endif
|
||||||
273
backends/source/gfx_directx9.cpp
Normal file
273
backends/source/gfx_directx9.cpp
Normal file
@@ -0,0 +1,273 @@
|
|||||||
|
// Well yes, i finally try it
|
||||||
|
|
||||||
|
#include <pd/lithium/formatters.hpp>
|
||||||
|
#include <pd_system/gfx_directx9.hpp>
|
||||||
|
|
||||||
|
// Sicher ist sicher
|
||||||
|
#if defined(PD_ENABLE_DIRECTX9) && defined(_WIN32)
|
||||||
|
#include <d3d9.h>
|
||||||
|
#include <d3dcompiler.h>
|
||||||
|
|
||||||
|
#include <pd/drivers/drivers.hpp>
|
||||||
|
|
||||||
|
namespace PD {
|
||||||
|
static const char* g_vsCode = R"(
|
||||||
|
float4x4 projection;
|
||||||
|
|
||||||
|
struct VS_IN {
|
||||||
|
float2 pos : POSITION0;
|
||||||
|
float2 uv : TEXCOORD0;
|
||||||
|
float4 col : COLOR0;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct VS_OUT {
|
||||||
|
float4 pos : POSITION0;
|
||||||
|
float2 uv : TEXCOORD0;
|
||||||
|
float4 col : COLOR0;
|
||||||
|
};
|
||||||
|
|
||||||
|
VS_OUT main(VS_IN input) {
|
||||||
|
VS_OUT o;
|
||||||
|
o.pos = mul(projection, float4(input.pos, 0.0, 1.0));
|
||||||
|
o.uv = input.uv;
|
||||||
|
o.col = input.col;
|
||||||
|
return o;
|
||||||
|
}
|
||||||
|
)";
|
||||||
|
|
||||||
|
static const char* g_psCode = R"(
|
||||||
|
sampler2D tex : register(s0);
|
||||||
|
float alfa;
|
||||||
|
|
||||||
|
struct PS_IN {
|
||||||
|
float2 uv : TEXCOORD0;
|
||||||
|
float4 col : COLOR0;
|
||||||
|
};
|
||||||
|
|
||||||
|
float4 main(PS_IN input) : COLOR0 {
|
||||||
|
float4 tc = tex2D(tex, input.uv);
|
||||||
|
if (alfa > 0.5)
|
||||||
|
return float4(input.col.rgb, tc.a * input.col.a);
|
||||||
|
else
|
||||||
|
return tc * input.col;
|
||||||
|
}
|
||||||
|
)";
|
||||||
|
|
||||||
|
struct GfxDirectX9::Impl {
|
||||||
|
IDirect3DDevice9* Device = nullptr;
|
||||||
|
IDirect3DVertexBuffer9* VBO = nullptr;
|
||||||
|
IDirect3DIndexBuffer9* IBO = nullptr;
|
||||||
|
IDirect3DVertexDeclaration9* Decl = nullptr;
|
||||||
|
IDirect3DVertexShader9* VS = nullptr;
|
||||||
|
IDirect3DPixelShader9* FS = nullptr;
|
||||||
|
IDirect3DTexture9* CurrentTex = nullptr;
|
||||||
|
};
|
||||||
|
|
||||||
|
void GfxDirectX9::SysInit() {
|
||||||
|
if (impl) return;
|
||||||
|
PDLOG("GfxDirectX9::SysInit();");
|
||||||
|
impl = new Impl();
|
||||||
|
impl->Device = (IDirect3DDevice9*)pDevice;
|
||||||
|
if (impl->Device) {
|
||||||
|
D3DVERTEXELEMENT9 elements[]{
|
||||||
|
{0, 0, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION,
|
||||||
|
0},
|
||||||
|
{0, 8, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD,
|
||||||
|
0},
|
||||||
|
{0, 16, D3DDECLTYPE_D3DCOLOR, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_COLOR,
|
||||||
|
0},
|
||||||
|
D3DDECL_END()};
|
||||||
|
impl->Device->CreateVertexDeclaration(elements, &impl->Decl);
|
||||||
|
impl->Device->CreateVertexBuffer(
|
||||||
|
GfxDirectX9Config::NumVertices * sizeof(PD::Li::Vertex),
|
||||||
|
D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY, 0, D3DPOOL_DEFAULT, &impl->VBO,
|
||||||
|
nullptr);
|
||||||
|
impl->Device->CreateIndexBuffer(GfxDirectX9Config::NumIndices * sizeof(u16),
|
||||||
|
D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY,
|
||||||
|
D3DFMT_INDEX16, D3DPOOL_DEFAULT, &impl->IBO,
|
||||||
|
nullptr);
|
||||||
|
ID3DBlob* vsBlob = nullptr;
|
||||||
|
ID3DBlob* errBlob = nullptr;
|
||||||
|
HRESULT hr = D3DCompile(g_vsCode, strlen(g_vsCode), nullptr, nullptr,
|
||||||
|
nullptr, "main", "vs_2_0", 0, 0, &vsBlob, &errBlob);
|
||||||
|
if (FAILED(hr)) {
|
||||||
|
PDLOG("Vertex Shader compile error: {}",
|
||||||
|
errBlob ? (char*)errBlob->GetBufferPointer() : "");
|
||||||
|
} else {
|
||||||
|
impl->Device->CreateVertexShader((DWORD*)vsBlob->GetBufferPointer(),
|
||||||
|
&impl->VS);
|
||||||
|
}
|
||||||
|
if (vsBlob) vsBlob->Release();
|
||||||
|
if (errBlob) errBlob->Release();
|
||||||
|
|
||||||
|
ID3DBlob* psBlob = nullptr;
|
||||||
|
errBlob = nullptr;
|
||||||
|
hr = D3DCompile(g_psCode, strlen(g_psCode), nullptr, nullptr, nullptr,
|
||||||
|
"main", "ps_2_0", 0, 0, &psBlob, &errBlob);
|
||||||
|
if (FAILED(hr)) {
|
||||||
|
PDLOG("Pixel Shader compile error: {}",
|
||||||
|
errBlob ? (char*)errBlob->GetBufferPointer() : "");
|
||||||
|
} else {
|
||||||
|
impl->Device->CreatePixelShader((DWORD*)psBlob->GetBufferPointer(),
|
||||||
|
&impl->FS);
|
||||||
|
}
|
||||||
|
if (psBlob) psBlob->Release();
|
||||||
|
if (errBlob) errBlob->Release();
|
||||||
|
} else {
|
||||||
|
PDLOG(
|
||||||
|
"GfxDirectX9::SysInit Error: pDevice is not set!\nYOu need to include "
|
||||||
|
"your D3D9 Device as "
|
||||||
|
"folowing:\nPD::Gfx::UseDriver<PD::GfxDirectX9>(D3D9Device);");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void GfxDirectX9::SysDeinit() {
|
||||||
|
if (!impl || !impl->Device) return;
|
||||||
|
if (impl->VBO) impl->VBO->Release();
|
||||||
|
if (impl->IBO) impl->IBO->Release();
|
||||||
|
if (impl->Decl) impl->Decl->Release();
|
||||||
|
if (impl->VS) impl->VS->Release();
|
||||||
|
if (impl->FS) impl->FS->Release();
|
||||||
|
delete impl;
|
||||||
|
impl = nullptr;
|
||||||
|
PDLOG("GfxDirectX9::SysDeinit()");
|
||||||
|
}
|
||||||
|
|
||||||
|
void GfxDirectX9::Submit(size_t count, size_t start) {
|
||||||
|
if (!impl || !impl->Device || !impl->VBO || !impl->IBO) return;
|
||||||
|
|
||||||
|
BindTexture(CurrentTex);
|
||||||
|
impl->Device->SetVertexShaderConstantF(
|
||||||
|
0, reinterpret_cast<const float*>(&Projection), 4);
|
||||||
|
|
||||||
|
void* vptr;
|
||||||
|
impl->VBO->Lock(0, 0, &vptr, D3DLOCK_DISCARD);
|
||||||
|
memcpy(vptr, GetVertexBufPtr(0), CurrentVertex * sizeof(PD::Li::Vertex));
|
||||||
|
impl->VBO->Unlock();
|
||||||
|
|
||||||
|
void* iptr;
|
||||||
|
impl->IBO->Lock(0, 0, &iptr, D3DLOCK_DISCARD);
|
||||||
|
memcpy(iptr, GetIndexBufPtr(0), CurrentIndex * sizeof(u16));
|
||||||
|
impl->IBO->Unlock();
|
||||||
|
|
||||||
|
impl->Device->SetStreamSource(0, impl->VBO, 0, sizeof(PD::Li::Vertex));
|
||||||
|
impl->Device->SetIndices(impl->IBO);
|
||||||
|
impl->Device->SetVertexDeclaration(impl->Decl);
|
||||||
|
impl->Device->SetVertexShader(impl->VS);
|
||||||
|
impl->Device->SetPixelShader(impl->FS);
|
||||||
|
|
||||||
|
impl->Device->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, CurrentVertex,
|
||||||
|
start, count / 3);
|
||||||
|
}
|
||||||
|
|
||||||
|
void GfxDirectX9::BindTexture(TextureID id) {
|
||||||
|
if (!impl || !impl->Device) return;
|
||||||
|
impl->CurrentTex = (IDirect3DTexture9*)id;
|
||||||
|
impl->Device->SetTexture(0, impl->CurrentTex);
|
||||||
|
|
||||||
|
bool a8 = false;
|
||||||
|
if (impl->CurrentTex) {
|
||||||
|
D3DSURFACE_DESC desc;
|
||||||
|
impl->CurrentTex->GetLevelDesc(0, &desc);
|
||||||
|
a8 = (desc.Format == D3DFMT_A8);
|
||||||
|
}
|
||||||
|
|
||||||
|
float v = a8 ? 1.0f : 0.0f;
|
||||||
|
impl->Device->SetPixelShaderConstantF(0, &v, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
void GfxDirectX9::SysReset() {
|
||||||
|
if (!impl || !impl->Device) return;
|
||||||
|
|
||||||
|
impl->Device->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
|
||||||
|
impl->Device->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
|
||||||
|
impl->Device->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
|
||||||
|
}
|
||||||
|
|
||||||
|
Li::Texture GfxDirectX9::LoadTexture(const std::vector<PD::u8>& pixels, int w,
|
||||||
|
int h, TextureFormat type,
|
||||||
|
TextureFilter filter) {
|
||||||
|
if (!impl || !impl->Device) return Li::Texture();
|
||||||
|
IDirect3DTexture9* tex = nullptr;
|
||||||
|
D3DFORMAT fmt = D3DFMT_A8R8G8B8;
|
||||||
|
if (type == TextureFormat::RGB24)
|
||||||
|
fmt = D3DFMT_X8R8G8B8;
|
||||||
|
else if (type == TextureFormat::A8)
|
||||||
|
fmt = D3DFMT_A8;
|
||||||
|
|
||||||
|
HRESULT hr = impl->Device->CreateTexture(w, h, 1, 0, fmt, D3DPOOL_MANAGED,
|
||||||
|
&tex, nullptr);
|
||||||
|
if (FAILED(hr) || !tex) return Li::Texture();
|
||||||
|
|
||||||
|
D3DLOCKED_RECT rect;
|
||||||
|
tex->LockRect(0, &rect, nullptr, 0);
|
||||||
|
|
||||||
|
if (type == TextureFormat::RGB24) {
|
||||||
|
u8* dstRow = reinterpret_cast<u8*>(rect.pBits);
|
||||||
|
for (int y = 0; y < h; ++y) {
|
||||||
|
u32* dst = reinterpret_cast<u32*>(dstRow);
|
||||||
|
for (int x = 0; x < w; ++x) {
|
||||||
|
u8 r = pixels[(y * w + x) * 3 + 0];
|
||||||
|
u8 g = pixels[(y * w + x) * 3 + 1];
|
||||||
|
u8 b = pixels[(y * w + x) * 3 + 2];
|
||||||
|
dst[x] = (0xFF << 24) | (r << 16) | (g << 8) | b;
|
||||||
|
}
|
||||||
|
dstRow += rect.Pitch;
|
||||||
|
}
|
||||||
|
} else if (type == TextureFormat::RGBA32) {
|
||||||
|
u8* dstRow = reinterpret_cast<u8*>(rect.pBits);
|
||||||
|
for (int y = 0; y < h; ++y) {
|
||||||
|
u32* dst = reinterpret_cast<u32*>(dstRow);
|
||||||
|
for (int x = 0; x < w; ++x) {
|
||||||
|
u8 r = pixels[(y * w + x) * 4 + 0];
|
||||||
|
u8 g = pixels[(y * w + x) * 4 + 1];
|
||||||
|
u8 b = pixels[(y * w + x) * 4 + 2];
|
||||||
|
u8 a = pixels[(y * w + x) * 4 + 3];
|
||||||
|
dst[x] = (a << 24) | (r << 16) | (g << 8) | b;
|
||||||
|
}
|
||||||
|
dstRow += rect.Pitch;
|
||||||
|
}
|
||||||
|
} else if (type == TextureFormat::A8) {
|
||||||
|
u8* dstRow = reinterpret_cast<u8*>(rect.pBits);
|
||||||
|
for (int y = 0; y < h; ++y) {
|
||||||
|
memcpy(dstRow, &pixels[y * w], w);
|
||||||
|
dstRow += rect.Pitch;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
tex->UnlockRect(0);
|
||||||
|
Li::Texture res;
|
||||||
|
res.SetID((TextureID)tex);
|
||||||
|
res.SetSize(w, h);
|
||||||
|
res.SetUV(0.f, 0.f, 1.f, 1.f);
|
||||||
|
RegisterTexture(res);
|
||||||
|
PDLOG("GfxDirectX9::LoadTexture -> {{ {} }}, [{}, {}]", res, type, filter);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
void GfxDirectX9::DeleteTexture(const Li::Texture& tex) {
|
||||||
|
if (!tex.GetID()) return;
|
||||||
|
UnregisterTexture(tex);
|
||||||
|
IDirect3DTexture9* t = (IDirect3DTexture9*)tex.GetID();
|
||||||
|
t->Release();
|
||||||
|
}
|
||||||
|
} // namespace PD
|
||||||
|
#else
|
||||||
|
namespace PD {
|
||||||
|
void GfxDirectX9::SysInit() {
|
||||||
|
PDLOG(
|
||||||
|
"GfxDirectX9::SysInit: DirectX9 Driver is not included in "
|
||||||
|
"palladium-system");
|
||||||
|
}
|
||||||
|
void GfxDirectX9::SysDeinit() {}
|
||||||
|
void GfxDirectX9::Submit(size_t count, size_t start) {}
|
||||||
|
void GfxDirectX9::BindTexture(TextureID id) {}
|
||||||
|
void GfxDirectX9::SysReset() {}
|
||||||
|
Li::Texture GfxDirectX9::LoadTexture(const std::vector<PD::u8>& pixels, int w,
|
||||||
|
int h, TextureFormat type,
|
||||||
|
TextureFilter filter) {
|
||||||
|
return Li::Texture();
|
||||||
|
}
|
||||||
|
void GfxDirectX9::DeleteTexture(const Li::Texture& tex) {}
|
||||||
|
} // namespace PD
|
||||||
|
#endif
|
||||||
191
backends/source/gfx_opengl2.cpp
Normal file
191
backends/source/gfx_opengl2.cpp
Normal file
@@ -0,0 +1,191 @@
|
|||||||
|
#include <pd/lithium/formatters.hpp>
|
||||||
|
#include <pd_system/gfx_opengl2.hpp>
|
||||||
|
|
||||||
|
#if defined(PD_ENABLE_OPENGL2)
|
||||||
|
#include <glad/glad.h>
|
||||||
|
|
||||||
|
#include <pd/drivers/drivers.hpp>
|
||||||
|
#include <pd_system/gl-helper.hpp>
|
||||||
|
|
||||||
|
namespace PD {
|
||||||
|
|
||||||
|
const char* GfxOpenGL2::pVertCode = R"(
|
||||||
|
#version 120
|
||||||
|
|
||||||
|
attribute vec2 pos;
|
||||||
|
attribute vec2 uv;
|
||||||
|
attribute vec4 color;
|
||||||
|
|
||||||
|
varying vec2 oUV;
|
||||||
|
varying vec4 oColor;
|
||||||
|
|
||||||
|
// Probably forgot about this matrix and
|
||||||
|
// searched hours for why the rendering isn't working :/
|
||||||
|
uniform mat4 projection;
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
gl_Position = projection*vec4(pos, 0.0, 1.0);
|
||||||
|
oUV = uv;
|
||||||
|
oColor = color;
|
||||||
|
}
|
||||||
|
)";
|
||||||
|
|
||||||
|
const char* GfxOpenGL2::pFragCode = R"(
|
||||||
|
#version 120
|
||||||
|
|
||||||
|
varying vec2 oUV;
|
||||||
|
varying vec4 oColor;
|
||||||
|
|
||||||
|
uniform sampler2D tex;
|
||||||
|
uniform bool alfa;
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
vec4 tc = texture2D(tex, oUV);
|
||||||
|
if (alfa) {
|
||||||
|
gl_FragColor = vec4(oColor.rgb, tc.a * oColor.a);
|
||||||
|
} else {
|
||||||
|
gl_FragColor = tc * oColor;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)";
|
||||||
|
|
||||||
|
void GfxOpenGL2::pSetupShaderAttribs(u32 shader) {
|
||||||
|
GLint _pos = glGetAttribLocation(shader, "pos");
|
||||||
|
GLint _uv = glGetAttribLocation(shader, "uv");
|
||||||
|
GLint _color = glGetAttribLocation(shader, "color");
|
||||||
|
glVertexAttribPointer(_pos, 2, GL_FLOAT, GL_FALSE, sizeof(PD::Li::Vertex),
|
||||||
|
(void*)offsetof(PD::Li::Vertex, pos));
|
||||||
|
glEnableVertexAttribArray(_pos);
|
||||||
|
|
||||||
|
glVertexAttribPointer(_uv, 2, GL_FLOAT, GL_FALSE, sizeof(PD::Li::Vertex),
|
||||||
|
(void*)offsetof(PD::Li::Vertex, uv));
|
||||||
|
glEnableVertexAttribArray(_uv);
|
||||||
|
|
||||||
|
glVertexAttribPointer(_color, 4, GL_UNSIGNED_BYTE, GL_TRUE,
|
||||||
|
sizeof(PD::Li::Vertex),
|
||||||
|
(void*)offsetof(PD::Li::Vertex, color));
|
||||||
|
glEnableVertexAttribArray(_color);
|
||||||
|
}
|
||||||
|
|
||||||
|
void GfxOpenGL2::SysInit() {
|
||||||
|
pShader = CreateShaderProgram(pVertCode, pFragCode);
|
||||||
|
glUseProgram(pShader);
|
||||||
|
glGenBuffers(1, &VBO);
|
||||||
|
glBindBuffer(GL_ARRAY_BUFFER, VBO);
|
||||||
|
glGenBuffers(1, &IBO);
|
||||||
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, IBO);
|
||||||
|
|
||||||
|
pSetupShaderAttribs(pShader);
|
||||||
|
pLocTex = glGetUniformLocation(pShader, "tex");
|
||||||
|
pLocAlfa = glGetUniformLocation(pShader, "alfa");
|
||||||
|
pLocProjection = glGetUniformLocation(pShader, "projection");
|
||||||
|
|
||||||
|
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||||
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
||||||
|
PDLOG(
|
||||||
|
"GfxOpenGL2::SysInit():\n pShader = {}\n pLocTex = {}\n pLocAlfa = "
|
||||||
|
"{}\n pLocProjection = {}\n VBO = {}\n IBO = {}",
|
||||||
|
pShader, pLocTex, pLocAlfa, pLocProjection, VBO, IBO);
|
||||||
|
}
|
||||||
|
|
||||||
|
void GfxOpenGL2::SysDeinit() {
|
||||||
|
glDeleteBuffers(1, &VBO);
|
||||||
|
glDeleteBuffers(1, &IBO);
|
||||||
|
PDLOG("GfxOpenGL2::SysDeinit()");
|
||||||
|
}
|
||||||
|
|
||||||
|
void GfxOpenGL2::Submit(size_t count, size_t start) {
|
||||||
|
BindTexture(CurrentTex);
|
||||||
|
glUseProgram(pShader);
|
||||||
|
glUniformMatrix4fv(pLocProjection, 1, GL_FALSE, Projection.m.data());
|
||||||
|
glBindBuffer(GL_ARRAY_BUFFER, VBO);
|
||||||
|
glBufferData(GL_ARRAY_BUFFER, CurrentVertex * sizeof(PD::Li::Vertex),
|
||||||
|
GetVertexBufPtr(0), GL_DYNAMIC_DRAW);
|
||||||
|
|
||||||
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, IBO);
|
||||||
|
glBufferData(GL_ELEMENT_ARRAY_BUFFER, CurrentIndex * sizeof(PD::u16),
|
||||||
|
GetIndexBufPtr(0), GL_DYNAMIC_DRAW);
|
||||||
|
|
||||||
|
pSetupShaderAttribs(pShader);
|
||||||
|
GLint ibo = 0;
|
||||||
|
glGetIntegerv(GL_ELEMENT_ARRAY_BUFFER_BINDING, &ibo);
|
||||||
|
glDrawElements(GL_TRIANGLES, count, GL_UNSIGNED_SHORT,
|
||||||
|
reinterpret_cast<void*>(start * sizeof(u16)));
|
||||||
|
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||||
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
||||||
|
BindTexture(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void GfxOpenGL2::BindTexture(TextureID id) {
|
||||||
|
glActiveTexture(GL_TEXTURE0);
|
||||||
|
glBindTexture(GL_TEXTURE_2D, (GLuint)id);
|
||||||
|
glUniform1i(pLocTex, 0);
|
||||||
|
GLint fmt = 0;
|
||||||
|
glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_INTERNAL_FORMAT, &fmt);
|
||||||
|
glUniform1i(pLocAlfa, fmt == GL_ALPHA);
|
||||||
|
}
|
||||||
|
|
||||||
|
void GfxOpenGL2::SysReset() {
|
||||||
|
glEnable(GL_BLEND);
|
||||||
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||||
|
}
|
||||||
|
|
||||||
|
Li::Texture GfxOpenGL2::LoadTexture(const std::vector<PD::u8>& pixels, int w,
|
||||||
|
int h, TextureFormat type,
|
||||||
|
TextureFilter filter) {
|
||||||
|
GLuint texID;
|
||||||
|
glGenTextures(1, &texID);
|
||||||
|
glBindTexture(GL_TEXTURE_2D, texID);
|
||||||
|
|
||||||
|
// Set base format (Always using RGBA as base)
|
||||||
|
GLenum fmt = GL_RGBA;
|
||||||
|
if (type == TextureFormat::RGB24) {
|
||||||
|
fmt = GL_RGB;
|
||||||
|
} else if (type == TextureFormat::A8) {
|
||||||
|
fmt = GL_ALPHA;
|
||||||
|
}
|
||||||
|
glTexImage2D(GL_TEXTURE_2D, 0, fmt, w, h, 0, fmt, GL_UNSIGNED_BYTE,
|
||||||
|
pixels.data());
|
||||||
|
if (filter == TextureFilter::Linear) {
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||||
|
} else if (filter == TextureFilter::Nearest) {
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||||
|
}
|
||||||
|
glBindTexture(GL_TEXTURE_2D, 0);
|
||||||
|
Li::Texture res;
|
||||||
|
res.SetID(texID);
|
||||||
|
res.SetSize(w, h);
|
||||||
|
res.SetUV(0.f, 0.f, 1.f, 1.f);
|
||||||
|
RegisterTexture(res);
|
||||||
|
PDLOG("GfxOpenGL2::LoadTexture -> {{ {} }}, [{}, {}]", res, type, filter);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
void GfxOpenGL2::DeleteTexture(const Li::Texture& tex) {
|
||||||
|
UnregisterTexture(tex);
|
||||||
|
GLuint tex_ = tex.GetID();
|
||||||
|
glDeleteTextures(1, &tex_);
|
||||||
|
}
|
||||||
|
} // namespace PD
|
||||||
|
#else
|
||||||
|
namespace PD {
|
||||||
|
void GfxOpenGL2::SysInit() {
|
||||||
|
PDLOG(
|
||||||
|
"GfxOpenGL2::SysInit: OpenGL2 Driver is not included in "
|
||||||
|
"palladium-system");
|
||||||
|
}
|
||||||
|
void GfxOpenGL2::SysDeinit() {}
|
||||||
|
void GfxOpenGL2::Submit(size_t count, size_t start) {}
|
||||||
|
void GfxOpenGL2::BindTexture(TextureID id) {}
|
||||||
|
void GfxOpenGL2::SysReset() {}
|
||||||
|
Li::Texture GfxOpenGL2::LoadTexture(const std::vector<PD::u8>& pixels, int w,
|
||||||
|
int h, TextureFormat type,
|
||||||
|
TextureFilter filter) {
|
||||||
|
return Li::Texture();
|
||||||
|
}
|
||||||
|
void GfxOpenGL2::DeleteTexture(const Li::Texture& tex) {}
|
||||||
|
void GfxOpenGL2::pSetupShaderAttribs(u32 shader) {}
|
||||||
|
} // namespace PD
|
||||||
|
#endif
|
||||||
160
backends/source/gfx_opengl3.cpp
Normal file
160
backends/source/gfx_opengl3.cpp
Normal file
@@ -0,0 +1,160 @@
|
|||||||
|
#include <pd/lithium/formatters.hpp>
|
||||||
|
#include <pd_system/gfx_opengl3.hpp>
|
||||||
|
|
||||||
|
#if defined(PD_ENABLE_OPENGL3)
|
||||||
|
#include <glad/glad.h>
|
||||||
|
|
||||||
|
#include <pd/drivers/drivers.hpp>
|
||||||
|
#include <pd_system/gl-helper.hpp>
|
||||||
|
#include <pd_system/shaders.hpp>
|
||||||
|
#include <spirv-helper.hpp>
|
||||||
|
|
||||||
|
namespace PD {
|
||||||
|
void GfxOpenGL3::SysInit() {
|
||||||
|
std::string vcode = SpirvHelper::SPV2GLSL(
|
||||||
|
std::vector<unsigned int>(
|
||||||
|
Shaders::VertexShader,
|
||||||
|
Shaders::VertexShader +
|
||||||
|
(sizeof(Shaders::VertexShader) / sizeof(unsigned int))),
|
||||||
|
330, false);
|
||||||
|
std::string fcode = SpirvHelper::SPV2GLSL(
|
||||||
|
std::vector<unsigned int>(
|
||||||
|
Shaders::FragmentShader,
|
||||||
|
Shaders::FragmentShader +
|
||||||
|
(sizeof(Shaders::FragmentShader) / sizeof(unsigned int))),
|
||||||
|
330, false);
|
||||||
|
PDLOG("Vertex: \n{}", vcode);
|
||||||
|
PDLOG("Fragment: \n{}", fcode);
|
||||||
|
pShader = CreateShaderProgram(vcode.c_str(), fcode.c_str());
|
||||||
|
glUseProgram(pShader);
|
||||||
|
glGenVertexArrays(1, &VAO);
|
||||||
|
glBindVertexArray(VAO);
|
||||||
|
glGenBuffers(1, &VBO);
|
||||||
|
glBindBuffer(GL_ARRAY_BUFFER, VBO);
|
||||||
|
|
||||||
|
glEnableVertexAttribArray(0);
|
||||||
|
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, sizeof(PD::Li::Vertex),
|
||||||
|
(void*)offsetof(PD::Li::Vertex, pos));
|
||||||
|
glEnableVertexAttribArray(1);
|
||||||
|
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(PD::Li::Vertex),
|
||||||
|
(void*)offsetof(PD::Li::Vertex, uv));
|
||||||
|
glEnableVertexAttribArray(2);
|
||||||
|
glVertexAttribPointer(2, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(PD::Li::Vertex),
|
||||||
|
(void*)offsetof(PD::Li::Vertex, color));
|
||||||
|
|
||||||
|
glGenBuffers(1, &IBO);
|
||||||
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, IBO);
|
||||||
|
|
||||||
|
pLocTex = glGetUniformLocation(pShader, "tex");
|
||||||
|
pLocAlfa = glGetUniformLocation(pShader, "push.alfa");
|
||||||
|
pLocProjection = glGetUniformLocation(pShader, "ubo.projection");
|
||||||
|
|
||||||
|
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||||
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
||||||
|
glBindVertexArray(0);
|
||||||
|
PDLOG(
|
||||||
|
"GfxOpenGL3::SysInit():\n pShader = {}\n pLocTex = {}\n pLocAlfa = "
|
||||||
|
"{}\n pLocProjection = {}\n VBO = {}\n IBO = {}, VAO = {}",
|
||||||
|
pShader, pLocTex, pLocAlfa, pLocProjection, VBO, IBO, VAO);
|
||||||
|
}
|
||||||
|
|
||||||
|
void GfxOpenGL3::SysDeinit() {
|
||||||
|
glDeleteBuffers(1, &VBO);
|
||||||
|
glDeleteBuffers(1, &IBO);
|
||||||
|
glDeleteVertexArrays(1, &VAO);
|
||||||
|
PDLOG("GfxOpenGL3::SysDeinit()");
|
||||||
|
}
|
||||||
|
|
||||||
|
void GfxOpenGL3::Submit(size_t count, size_t start) {
|
||||||
|
BindTexture(CurrentTex);
|
||||||
|
glUseProgram(pShader);
|
||||||
|
glUniformMatrix4fv(pLocProjection, 1, GL_FALSE, Projection.m.data());
|
||||||
|
glBindVertexArray(VAO);
|
||||||
|
glBindBuffer(GL_ARRAY_BUFFER, VBO);
|
||||||
|
glBufferData(GL_ARRAY_BUFFER, CurrentVertex * sizeof(PD::Li::Vertex),
|
||||||
|
GetVertexBufPtr(0), GL_DYNAMIC_DRAW);
|
||||||
|
|
||||||
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, IBO);
|
||||||
|
glBufferData(GL_ELEMENT_ARRAY_BUFFER, CurrentIndex * sizeof(u16),
|
||||||
|
GetIndexBufPtr(0), GL_DYNAMIC_DRAW);
|
||||||
|
|
||||||
|
glDrawElements(GL_TRIANGLES, count, GL_UNSIGNED_SHORT,
|
||||||
|
reinterpret_cast<void*>(start * sizeof(u16)));
|
||||||
|
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||||
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
||||||
|
glBindVertexArray(0);
|
||||||
|
BindTexture(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void GfxOpenGL3::BindTexture(TextureID id) {
|
||||||
|
glActiveTexture(GL_TEXTURE0);
|
||||||
|
glBindTexture(GL_TEXTURE_2D, (GLuint)id);
|
||||||
|
glUniform1i(pLocTex, 0);
|
||||||
|
GLint fmt = 0;
|
||||||
|
glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_INTERNAL_FORMAT, &fmt);
|
||||||
|
glUniform1i(pLocAlfa, fmt == GL_ALPHA);
|
||||||
|
}
|
||||||
|
|
||||||
|
void GfxOpenGL3::SysReset() {
|
||||||
|
glEnable(GL_BLEND);
|
||||||
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||||
|
}
|
||||||
|
|
||||||
|
Li::Texture GfxOpenGL3::LoadTexture(const std::vector<PD::u8>& pixels, int w,
|
||||||
|
int h, TextureFormat type,
|
||||||
|
TextureFilter filter) {
|
||||||
|
GLuint texID;
|
||||||
|
glGenTextures(1, &texID);
|
||||||
|
glBindTexture(GL_TEXTURE_2D, texID);
|
||||||
|
|
||||||
|
// Set base format (Always using RGBA as base)
|
||||||
|
GLenum fmt = GL_RGBA;
|
||||||
|
if (type == TextureFormat::RGB24) {
|
||||||
|
fmt = GL_RGB;
|
||||||
|
} else if (type == TextureFormat::A8) {
|
||||||
|
fmt = GL_ALPHA;
|
||||||
|
}
|
||||||
|
glTexImage2D(GL_TEXTURE_2D, 0, fmt, w, h, 0, fmt, GL_UNSIGNED_BYTE,
|
||||||
|
pixels.data());
|
||||||
|
if (filter == TextureFilter::Linear) {
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||||
|
} else if (filter == TextureFilter::Nearest) {
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||||
|
}
|
||||||
|
glBindTexture(GL_TEXTURE_2D, 0);
|
||||||
|
Li::Texture res;
|
||||||
|
res.SetID(texID);
|
||||||
|
res.SetSize(w, h);
|
||||||
|
res.SetUV(0.f, 0.f, 1.f, 1.f);
|
||||||
|
RegisterTexture(res);
|
||||||
|
PDLOG("GfxOpenGL3::LoadTexture -> {{ {} }}, [{}, {}]", res, type, filter);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
void GfxOpenGL3::DeleteTexture(const Li::Texture& tex) {
|
||||||
|
UnregisterTexture(tex);
|
||||||
|
GLuint tex_ = tex.GetID();
|
||||||
|
glDeleteTextures(1, &tex_);
|
||||||
|
}
|
||||||
|
} // namespace PD
|
||||||
|
#else
|
||||||
|
namespace PD {
|
||||||
|
void GfxOpenGL3::SysInit() {
|
||||||
|
PDLOG(
|
||||||
|
"GfxOpenGL3::SysInit: OpenGL3 Driver is not included in "
|
||||||
|
"palladium-system");
|
||||||
|
}
|
||||||
|
void GfxOpenGL3::SysDeinit() {}
|
||||||
|
void GfxOpenGL3::Submit(size_t count, size_t start) {}
|
||||||
|
void GfxOpenGL3::BindTexture(TextureID id) {}
|
||||||
|
void GfxOpenGL3::SysReset() {}
|
||||||
|
Li::Texture GfxOpenGL3::LoadTexture(const std::vector<PD::u8>& pixels, int w,
|
||||||
|
int h, TextureFormat type,
|
||||||
|
TextureFilter filter) {
|
||||||
|
return Li::Texture();
|
||||||
|
}
|
||||||
|
void GfxOpenGL3::DeleteTexture(const Li::Texture& tex) {}
|
||||||
|
} // namespace PD
|
||||||
|
#endif
|
||||||
48
backends/source/gl-helper.cpp
Normal file
48
backends/source/gl-helper.cpp
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
#if defined(PD_ENABLE_OPENGL2) || defined(PD_ENABLE_OPENGL3)
|
||||||
|
#include <glad/glad.h>
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <pd_system/gl-helper.hpp>
|
||||||
|
|
||||||
|
namespace PD {
|
||||||
|
GLuint compileShader(const char* src, GLenum type) {
|
||||||
|
GLuint shader = glCreateShader(type);
|
||||||
|
glShaderSource(shader, 1, &src, nullptr);
|
||||||
|
glCompileShader(shader);
|
||||||
|
|
||||||
|
GLint success;
|
||||||
|
glGetShaderiv(shader, GL_COMPILE_STATUS, &success);
|
||||||
|
if (!success) {
|
||||||
|
char infoLog[512];
|
||||||
|
glGetShaderInfoLog(shader, 512, nullptr, infoLog);
|
||||||
|
std::cerr << "Shader Compilation Error: " << infoLog << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
return shader;
|
||||||
|
}
|
||||||
|
u32 CreateShaderProgram(const char* vert, const char* frag) {
|
||||||
|
GLuint vertexShader = compileShader(vert, GL_VERTEX_SHADER);
|
||||||
|
GLuint fragmentShader = compileShader(frag, GL_FRAGMENT_SHADER);
|
||||||
|
|
||||||
|
GLuint shaderProgram = glCreateProgram();
|
||||||
|
glAttachShader(shaderProgram, vertexShader);
|
||||||
|
glAttachShader(shaderProgram, fragmentShader);
|
||||||
|
glLinkProgram(shaderProgram);
|
||||||
|
|
||||||
|
GLint success;
|
||||||
|
glGetProgramiv(shaderProgram, GL_LINK_STATUS, &success);
|
||||||
|
if (!success) {
|
||||||
|
char infoLog[512];
|
||||||
|
glGetProgramInfoLog(shaderProgram, 512, nullptr, infoLog);
|
||||||
|
std::cerr << "Shader Program Linking Error: " << infoLog << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
glDeleteShader(vertexShader);
|
||||||
|
glDeleteShader(fragmentShader);
|
||||||
|
|
||||||
|
if (success) PDLOG("Shader [{}] compiled sucessfully", shaderProgram);
|
||||||
|
|
||||||
|
return shaderProgram;
|
||||||
|
}
|
||||||
|
} // namespace PD
|
||||||
|
#endif
|
||||||
@@ -11,51 +11,6 @@ set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
|
|||||||
# Enable Compile Command Export
|
# Enable Compile Command Export
|
||||||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||||
|
|
||||||
option(PD_INCLUDE_DIR "")
|
|
||||||
|
|
||||||
### Helper Function to Build Librarys without have always
|
|
||||||
### These includes and definition defines
|
|
||||||
function(pd_add_lib TARGET_NAME)
|
|
||||||
set(opts "BUILD_SHARED")
|
|
||||||
set(one_val_args "")
|
|
||||||
set(multi_val_args SRC_FILES DEPENDS)
|
|
||||||
cmake_parse_arguments(ARG "${opts}" "${one_val_args}" "${multi_val_args}" ${ARGN})
|
|
||||||
|
|
||||||
string(REPLACE "-" "_" FLAG_NAME_T ${TARGET_NAME})
|
|
||||||
string(TOUPPER ${FLAG_NAME_T} FLAG_NAME_F)
|
|
||||||
|
|
||||||
if(ARG_BUILD_SHARED)
|
|
||||||
add_library(${TARGET_NAME} SHARED ${ARG_SRC_FILES})
|
|
||||||
target_compile_definitions(${TARGET_NAME} PUBLIC -D${FLAG_NAME_F}_BUILD_SHARED=1)
|
|
||||||
message("Building SHARED library: ${FLAG_NAME_F}_BUILD_SHARED=1")
|
|
||||||
else()
|
|
||||||
add_library(${TARGET_NAME} STATIC ${ARG_SRC_FILES})
|
|
||||||
target_compile_definitions(${TARGET_NAME} PUBLIC -D${FLAG_NAME_F}_BUILD_SHARED=0)
|
|
||||||
message("Building STATIC library: ${FLAG_NAME_F}_BUILD_SHARED=0")
|
|
||||||
endif()
|
|
||||||
target_include_directories(${TARGET_NAME} PUBLIC
|
|
||||||
${PD_INCLUDE_DIR}
|
|
||||||
${DEVKITPRO}/portlibs/3ds/include
|
|
||||||
)
|
|
||||||
target_compile_definitions(${TARGET_NAME} PRIVATE
|
|
||||||
-D_GNU_SOURCE=1
|
|
||||||
-DPALLADIUM_VERSION="${PROJECT_VERSION}"
|
|
||||||
-DPALLADIUM_GIT_COMMIT="${GIT_SHORT_HASH}"
|
|
||||||
-DPALLADIUM_GIT_BRANCH="${GIT_BRANCH}"
|
|
||||||
-DBUILD_CTR=1
|
|
||||||
)
|
|
||||||
if(${CMAKE_SYSTEM_NAME} STREQUAL "Nintendo3DS")
|
|
||||||
target_compile_options(${TARGET_NAME} PRIVATE
|
|
||||||
-Wno-abi
|
|
||||||
)
|
|
||||||
endif()
|
|
||||||
### For the libs that depend on another
|
|
||||||
if(ARG_DEPENDS)
|
|
||||||
target_link_libraries(${TARGET_NAME} PUBLIC ${ARG_DEPENDS})
|
|
||||||
endif()
|
|
||||||
install(TARGETS ${TARGET_NAME})
|
|
||||||
endfunction()
|
|
||||||
|
|
||||||
### GIT HELPER ###
|
### GIT HELPER ###
|
||||||
|
|
||||||
function(pd_git_get_hash ret)
|
function(pd_git_get_hash ret)
|
||||||
|
|||||||
6
cmake/palladiumConfig.cmake.in
Normal file
6
cmake/palladiumConfig.cmake.in
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
@PACKAGE_INIT@
|
||||||
|
|
||||||
|
include("${CMAKE_CURRENT_LIST_DIR}/palladiumTargets.cmake")
|
||||||
|
if(NOT TARGET palladium::pd-desktop AND PALLADIUM_FIND_DESKTOP)
|
||||||
|
find_dependency(palladium::pd-desktop OPTIONAL)
|
||||||
|
endif()
|
||||||
@@ -1,8 +1,28 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
/*
|
||||||
|
MIT License
|
||||||
|
Copyright (c) 2024 - 2026 René Amthor (tobid7)
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
#include <pd/core/core.hpp>
|
#include <pd/core/core.hpp>
|
||||||
#include <pd/drivers/drivers.hpp>
|
#include <pd/drivers/drivers.hpp>
|
||||||
#include <pd/external/json.hpp>
|
|
||||||
#include <pd/image/image.hpp>
|
|
||||||
#include <pd/lithium/lithium.hpp>
|
#include <pd/lithium/lithium.hpp>
|
||||||
#include <pd/ui7/ui7.hpp>
|
|
||||||
@@ -1,6 +1,8 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
/*
|
/*
|
||||||
MIT License
|
MIT License
|
||||||
Copyright (c) 2024 - 2025 René Amthor (tobid7)
|
Copyright (c) 2024 - 2026 René Amthor (tobid7)
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
@@ -21,28 +23,41 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|||||||
SOFTWARE.
|
SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifdef PD_LI_INCLUDE_FONTS
|
#include <array>
|
||||||
#include <pd/lithium/fonts.hpp>
|
#include <chrono>
|
||||||
|
#include <cmath>
|
||||||
|
#include <cstddef>
|
||||||
|
#include <cstdint>
|
||||||
|
#include <cstring>
|
||||||
|
#include <exception>
|
||||||
|
#include <format>
|
||||||
|
#include <fstream>
|
||||||
|
#include <numbers>
|
||||||
|
#include <pd/pd_p_api.hpp>
|
||||||
|
#include <string>
|
||||||
|
#include <unordered_map>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
/** Generated with pdfm */
|
|
||||||
namespace PD {
|
namespace PD {
|
||||||
FontFileData pFontData[] = {
|
[[noreturn]] inline void Throw(const std::string& msg) {
|
||||||
{
|
throw std::runtime_error(msg);
|
||||||
"ComicNeue-Bold.ttf",
|
}
|
||||||
0,
|
using u8 = unsigned char;
|
||||||
1,
|
using u16 = unsigned short;
|
||||||
},
|
using u32 = unsigned int;
|
||||||
{
|
using u64 = unsigned long long;
|
||||||
"Roboto-Regular.ttf",
|
using ptr = uintptr_t;
|
||||||
0,
|
PD_API void Log(const std::string& txt);
|
||||||
1,
|
template <typename... Args>
|
||||||
},
|
void Log(std::format_string<Args...> fmt, Args&&... args) {
|
||||||
};
|
std::string msg = std::format(fmt, std::forward<Args>(args)...);
|
||||||
size_t pNumFonts = 2;
|
Log(msg);
|
||||||
// clang-format off
|
}
|
||||||
PD::u8 pFontsDataRaw[] = {
|
|
||||||
0x0
|
|
||||||
};
|
|
||||||
// clang-format on
|
|
||||||
} // namespace PD
|
} // namespace PD
|
||||||
|
|
||||||
|
#ifdef PD_DEBUG
|
||||||
|
#define PDLOG(fmt, ...) \
|
||||||
|
PD::Log("[{}:{}]: " fmt, __FILE__, __LINE__, ##__VA_ARGS__)
|
||||||
|
#else
|
||||||
|
#define PDLOG(fmt, ...)
|
||||||
#endif
|
#endif
|
||||||
16
include/pd/core/bit_util.hpp → include/pd/core/bits.hpp
Executable file → Normal file
16
include/pd/core/bit_util.hpp → include/pd/core/bits.hpp
Executable file → Normal file
@@ -2,8 +2,7 @@
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
MIT License
|
MIT License
|
||||||
|
Copyright (c) 2024 - 2026 René Amthor (tobid7)
|
||||||
Copyright (c) 2024 - 2025 tobid7
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
@@ -24,24 +23,21 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|||||||
SOFTWARE.
|
SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <pd/core/common.hpp>
|
#include <pd/common.hpp>
|
||||||
|
|
||||||
namespace PD {
|
namespace PD {
|
||||||
/**
|
namespace Bits {
|
||||||
* Binary Utillity Functions
|
|
||||||
*/
|
|
||||||
namespace BitUtil {
|
|
||||||
/**
|
/**
|
||||||
* Check if a 32 Bit number only set a sigle bit to 1
|
* Check if a 32 Bit number only set a sigle bit to 1
|
||||||
* @param v 32 bit unsigned int
|
* @param v 32 bit unsigned int
|
||||||
* @return true if its a single bit number
|
* @return true if its a single bit number
|
||||||
*/
|
*/
|
||||||
PD_CORE_API bool IsSingleBit(u32 v);
|
PD_API bool IsSingleBit(u32 v);
|
||||||
/**
|
/**
|
||||||
* Get the Next Power of two Number
|
* Get the Next Power of two Number
|
||||||
* @param v Current Number
|
* @param v Current Number
|
||||||
* @return Next Number thats a Pow of 2
|
* @return Next Number thats a Pow of 2
|
||||||
*/
|
*/
|
||||||
PD_CORE_API u32 GetPow2(u32 v);
|
PD_API u32 GetPow2(u32 v);
|
||||||
} // namespace BitUtil
|
} // namespace Bits
|
||||||
} // namespace PD
|
} // namespace PD
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
MIT License
|
MIT License
|
||||||
Copyright (c) 2024 - 2025 René Amthor (tobid7)
|
Copyright (c) 2024 - 2026 René Amthor (tobid7)
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
@@ -23,10 +23,11 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|||||||
SOFTWARE.
|
SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <pd/core/common.hpp>
|
#include <pd/common.hpp>
|
||||||
|
#include <pd/core/strings.hpp>
|
||||||
|
|
||||||
namespace PD {
|
namespace PD {
|
||||||
class PD_CORE_API Color {
|
class PD_API Color {
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* Default Constructor (all variables are set to 0)
|
* Default Constructor (all variables are set to 0)
|
||||||
@@ -65,17 +66,34 @@ class PD_CORE_API Color {
|
|||||||
b(static_cast<u8>(255.f * b)),
|
b(static_cast<u8>(255.f * b)),
|
||||||
a(static_cast<u8>(255.f * a)) {}
|
a(static_cast<u8>(255.f * a)) {}
|
||||||
/**
|
/**
|
||||||
* Constructor for Hex Input
|
* Constructor for Hex Input (is abel to run at compile time xD)
|
||||||
* @param hex Hex String in `#ffffff` or `#ffffffff` format
|
* @param hex Hex String in `#ffffff` or `#ffffffff` format
|
||||||
*/
|
*/
|
||||||
Color(const std::string& hex) { Hex(hex); }
|
constexpr Color(const std::string_view& hex) { Hex(hex); }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create Color Object by Hex String
|
* Create Color Object by Hex String (at compile time btw)
|
||||||
* @param hex Hex String in `#ffffff` or `#ffffffff` format
|
* @param hex Hex String in `#ffffff` or `#ffffffff` format
|
||||||
* @return Color class itself
|
* @return Color class itself
|
||||||
*/
|
*/
|
||||||
Color& Hex(const std::string& hex);
|
constexpr Color& Hex(const std::string_view& hex) {
|
||||||
|
if (!(hex.length() == 7 || hex.length() == 9)) {
|
||||||
|
PD::Throw("[PD] Color: hex string is not rgb or rgba!");
|
||||||
|
}
|
||||||
|
r = PD::Strings::HexChar2Int(hex[1]) * 16 +
|
||||||
|
PD::Strings::HexChar2Int(hex[2]);
|
||||||
|
g = PD::Strings::HexChar2Int(hex[3]) * 16 +
|
||||||
|
PD::Strings::HexChar2Int(hex[4]);
|
||||||
|
b = PD::Strings::HexChar2Int(hex[5]) * 16 +
|
||||||
|
PD::Strings::HexChar2Int(hex[6]);
|
||||||
|
if (hex.length() == 9) {
|
||||||
|
a = PD::Strings::HexChar2Int(hex[7]) * 16 +
|
||||||
|
PD::Strings::HexChar2Int(hex[8]);
|
||||||
|
} else {
|
||||||
|
a = 255;
|
||||||
|
}
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* Convert this Color Object to Hex string
|
* Convert this Color Object to Hex string
|
||||||
* @param rgba [default false] sets if 8 or 6 digit color should be returned
|
* @param rgba [default false] sets if 8 or 6 digit color should be returned
|
||||||
@@ -89,7 +107,7 @@ class PD_CORE_API Color {
|
|||||||
* @param p Amount (supports -1.0 to 1.0 for use of sine)
|
* @param p Amount (supports -1.0 to 1.0 for use of sine)
|
||||||
* @return Class Reference
|
* @return Class Reference
|
||||||
*/
|
*/
|
||||||
Color& Fade(const Color& color, float p) {
|
constexpr Color& Fade(const Color& color, float p) {
|
||||||
a = static_cast<u8>((color.a - a) * ((p + 1.f) / 2));
|
a = static_cast<u8>((color.a - a) * ((p + 1.f) / 2));
|
||||||
b = static_cast<u8>((color.b - b) * ((p + 1.f) / 2));
|
b = static_cast<u8>((color.b - b) * ((p + 1.f) / 2));
|
||||||
g = static_cast<u8>((color.g - g) * ((p + 1.f) / 2));
|
g = static_cast<u8>((color.g - g) * ((p + 1.f) / 2));
|
||||||
@@ -101,12 +119,12 @@ class PD_CORE_API Color {
|
|||||||
* Get 32Bit Color Value
|
* Get 32Bit Color Value
|
||||||
* @return 32Bit Color Value (ABGR iirc)
|
* @return 32Bit Color Value (ABGR iirc)
|
||||||
*/
|
*/
|
||||||
u32 Get() const { return (a << 24) | (b << 16) | (g << 8) | r; }
|
constexpr u32 Get() const { return (a << 24) | (b << 16) | (g << 8) | r; }
|
||||||
/**
|
/**
|
||||||
* Get The Luminance of the Color
|
* Get The Luminance of the Color
|
||||||
* @return luminance (from 0.0 to 1.0)
|
* @return luminance (from 0.0 to 1.0)
|
||||||
*/
|
*/
|
||||||
float Luminance() const {
|
constexpr float Luminance() const {
|
||||||
// For Reference https://en.wikipedia.org/wiki/HSL_and_HSV#Lightness
|
// For Reference https://en.wikipedia.org/wiki/HSL_and_HSV#Lightness
|
||||||
return (0.3 * (r / 255.f) + 0.59 * (g / 255.f) + 0.11 * (b / 255.f));
|
return (0.3 * (r / 255.f) + 0.59 * (g / 255.f) + 0.11 * (b / 255.f));
|
||||||
}
|
}
|
||||||
@@ -114,13 +132,18 @@ class PD_CORE_API Color {
|
|||||||
* Check if the Color is Light or Dark
|
* Check if the Color is Light or Dark
|
||||||
* @return true if light
|
* @return true if light
|
||||||
*/
|
*/
|
||||||
bool IsLight() const { return (Luminance() >= 0.5); }
|
constexpr bool IsLight() const { return (Luminance() >= 0.5); }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Operator to cast Color to 32Bit Value
|
* Operator to cast Color to 32Bit Value
|
||||||
* @return 32Bit Color Value
|
* @return 32Bit Color Value
|
||||||
*/
|
*/
|
||||||
operator u32() const { return Get(); }
|
constexpr operator u32() const { return Get(); }
|
||||||
|
|
||||||
|
const float rf() const { return static_cast<float>(r) / 255.f; }
|
||||||
|
const float gf() const { return static_cast<float>(g) / 255.f; }
|
||||||
|
const float bf() const { return static_cast<float>(b) / 255.f; }
|
||||||
|
const float af() const { return static_cast<float>(a) / 255.f; }
|
||||||
|
|
||||||
/** Public Access Data section */
|
/** Public Access Data section */
|
||||||
u8 r;
|
u8 r;
|
||||||
|
|||||||
@@ -1,70 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
/*
|
|
||||||
MIT License
|
|
||||||
Copyright (c) 2024 - 2025 René Amthor (tobid7)
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <array>
|
|
||||||
#include <chrono>
|
|
||||||
#include <cinttypes>
|
|
||||||
#include <cmath>
|
|
||||||
#include <filesystem> // Requires C++ 17 or later
|
|
||||||
#include <format> // Requires C++ 20 or later
|
|
||||||
#include <fstream>
|
|
||||||
#include <functional>
|
|
||||||
#include <iostream>
|
|
||||||
#include <map>
|
|
||||||
#include <memory>
|
|
||||||
#include <numbers>
|
|
||||||
#include <sstream>
|
|
||||||
#include <stack>
|
|
||||||
#include <string>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
/** Dynamic Lib loading */
|
|
||||||
#include <pd/core/pd_p_api.hpp>
|
|
||||||
|
|
||||||
/** Memory Management */
|
|
||||||
|
|
||||||
#define PD_SHARED(x) \
|
|
||||||
using Ref = std::shared_ptr<x>; \
|
|
||||||
template <typename... Args> \
|
|
||||||
static Ref New(Args&&... args) { \
|
|
||||||
return std::make_shared<x>(std::forward<Args>(args)...); \
|
|
||||||
}
|
|
||||||
|
|
||||||
#define PD_UNIQUE(x) \
|
|
||||||
using Ref = std::unique_ptr<x>; \
|
|
||||||
template <typename... Args> \
|
|
||||||
static Ref New(Args&&... args) { \
|
|
||||||
return std::make_unique<x>(std::forward<Args>(args)...); \
|
|
||||||
}
|
|
||||||
|
|
||||||
#define PD_BIT(x) (1 << x)
|
|
||||||
|
|
||||||
namespace PD {
|
|
||||||
/** Types */
|
|
||||||
using u8 = unsigned char;
|
|
||||||
using u16 = unsigned short;
|
|
||||||
using u32 = unsigned int;
|
|
||||||
using u64 = unsigned long long;
|
|
||||||
} // namespace PD
|
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
MIT License
|
MIT License
|
||||||
Copyright (c) 2024 - 2025 René Amthor (tobid7)
|
Copyright (c) 2024 - 2026 René Amthor (tobid7)
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
@@ -23,13 +23,18 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|||||||
SOFTWARE.
|
SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <pd/core/bit_util.hpp>
|
#include <pd/core/bits.hpp>
|
||||||
#include <pd/core/color.hpp>
|
#include <pd/core/color.hpp>
|
||||||
|
#include <pd/core/fnv.hpp>
|
||||||
|
#include <pd/core/formatters.hpp>
|
||||||
|
#include <pd/core/fquat.hpp>
|
||||||
|
#include <pd/core/hashid.hpp>
|
||||||
#include <pd/core/io.hpp>
|
#include <pd/core/io.hpp>
|
||||||
#include <pd/core/mat.hpp>
|
#include <pd/core/mat.hpp>
|
||||||
#include <pd/core/sl/sl.hpp>
|
#include <pd/core/pool.hpp>
|
||||||
#include <pd/core/strings.hpp>
|
#include <pd/core/strings.hpp>
|
||||||
#include <pd/core/timer.hpp>
|
#include <pd/core/timer.hpp>
|
||||||
#include <pd/core/timetrace.hpp>
|
#include <pd/core/timetrace.hpp>
|
||||||
#include <pd/core/tween.hpp>
|
#include <pd/core/tween.hpp>
|
||||||
|
#include <pd/core/u128.hpp>
|
||||||
#include <pd/core/vec.hpp>
|
#include <pd/core/vec.hpp>
|
||||||
61
include/pd/core/sl/allocator.hpp → include/pd/core/fnv.hpp
Executable file → Normal file
61
include/pd/core/sl/allocator.hpp → include/pd/core/fnv.hpp
Executable file → Normal file
@@ -2,8 +2,7 @@
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
MIT License
|
MIT License
|
||||||
|
Copyright (c) 2024 - 2026 René Amthor (tobid7)
|
||||||
Copyright (c) 2024 - 2025 tobid7
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
@@ -22,30 +21,50 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
SOFTWARE.
|
SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <pd/core/common.hpp>
|
#include <pd/common.hpp>
|
||||||
|
|
||||||
namespace PD {
|
namespace PD {
|
||||||
/**
|
/**
|
||||||
* Custom Allocator for Custom Vec and probably other stuff in future
|
* FNV-1a 32Bit hasing function
|
||||||
|
* https://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function
|
||||||
*/
|
*/
|
||||||
template <typename T>
|
constexpr u32 FNV1A32(std::string_view str) {
|
||||||
class Allocator {
|
u32 ret = 0x811c9dc5; // Offset basis
|
||||||
public:
|
for (auto& it : str) {
|
||||||
Allocator() = default;
|
ret ^= it;
|
||||||
~Allocator() = default;
|
ret *= 0x01000193; // Prime
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* FNV-1a 64Bit hasing function
|
||||||
|
* https://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function
|
||||||
|
*/
|
||||||
|
constexpr u64 FNV1A64(std::string_view str) {
|
||||||
|
u64 ret = 0xcbf29ce484222325; // Offset basis
|
||||||
|
for (auto& it : str) {
|
||||||
|
ret ^= it;
|
||||||
|
ret *= 0x00000100000001b3; // Prime
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
virtual T* Allocate(size_t n) { return new T[n]; }
|
namespace Detail {
|
||||||
virtual T* AllocateRaw(size_t n) {
|
template <typename T>
|
||||||
return reinterpret_cast<T*>(::operator new(sizeof(T) * n));
|
struct FNV1A {};
|
||||||
}
|
|
||||||
virtual void DeallocateRaw(T* ptr) { operator delete(ptr); }
|
template <>
|
||||||
virtual void Deallocate(T* ptr) { delete[] ptr; }
|
struct FNV1A<u32> {
|
||||||
template <typename... Args>
|
static constexpr u32 Hash(std::string_view str) { return FNV1A32(str); }
|
||||||
void Construct(T* ptr, Args&&... args) {
|
static constexpr u32 Hash(const std::string& str) { return FNV1A32(str); }
|
||||||
new (ptr) T(std::forward<Args>(args)...);
|
|
||||||
}
|
|
||||||
void Destroy(T* ptr) { ptr->~T(); }
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template <>
|
||||||
|
struct FNV1A<u64> {
|
||||||
|
static constexpr u64 Hash(std::string_view str) { return FNV1A64(str); }
|
||||||
|
static constexpr u64 Hash(const std::string& str) { return FNV1A64(str); }
|
||||||
|
};
|
||||||
|
} // namespace Detail
|
||||||
} // namespace PD
|
} // namespace PD
|
||||||
98
include/pd/core/formatters.hpp
Normal file
98
include/pd/core/formatters.hpp
Normal file
@@ -0,0 +1,98 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
/*
|
||||||
|
MIT License
|
||||||
|
Copyright (c) 2024 - 2026 René Amthor (tobid7)
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <pd/core/color.hpp>
|
||||||
|
|
||||||
|
template <>
|
||||||
|
struct std::formatter<PD::Color> : std::formatter<std::string> {
|
||||||
|
enum class ColorFmt {
|
||||||
|
Hex,
|
||||||
|
Rgbf,
|
||||||
|
Rgb,
|
||||||
|
Rgba,
|
||||||
|
Rgbaf,
|
||||||
|
};
|
||||||
|
ColorFmt mode = ColorFmt::Hex;
|
||||||
|
constexpr auto parse(std::format_parse_context& ctx) {
|
||||||
|
auto it = ctx.begin();
|
||||||
|
auto end = ctx.end();
|
||||||
|
|
||||||
|
if (it == end || *it == '}') return it;
|
||||||
|
|
||||||
|
if (check(it, end, 5, "rgbaf")) {
|
||||||
|
mode = ColorFmt::Rgbaf;
|
||||||
|
it += 5;
|
||||||
|
} else if (check(it, end, 4, "rgba")) {
|
||||||
|
mode = ColorFmt::Rgba;
|
||||||
|
it += 4;
|
||||||
|
} else if (check(it, end, 4, "rgbf")) {
|
||||||
|
mode = ColorFmt::Rgbf;
|
||||||
|
it += 4;
|
||||||
|
} else if (check(it, end, 3, "rgb")) {
|
||||||
|
mode = ColorFmt::Rgb;
|
||||||
|
it += 3;
|
||||||
|
} else if (check(it, end, 3, "hex")) {
|
||||||
|
mode = ColorFmt::Hex;
|
||||||
|
it += 3;
|
||||||
|
} else {
|
||||||
|
throw std::format_error("invalid format for PD::Color");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (it == end || *it != '}')
|
||||||
|
throw std::format_error("invalid format for PD::Color");
|
||||||
|
|
||||||
|
return it;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename FormatContext>
|
||||||
|
auto format(const PD::Color& value, FormatContext& ctx) const {
|
||||||
|
switch (mode) {
|
||||||
|
case ColorFmt::Hex:
|
||||||
|
return std::format_to(ctx.out(), "#{:02X}{:02X}{:02X}{:02X}", value.r,
|
||||||
|
value.g, value.b, value.a);
|
||||||
|
case ColorFmt::Rgb:
|
||||||
|
return std::format_to(ctx.out(), "{}, {}, {}", value.r, value.g,
|
||||||
|
value.b);
|
||||||
|
case ColorFmt::Rgba:
|
||||||
|
return std::format_to(ctx.out(), "{}, {}, {}, {}", value.r, value.g,
|
||||||
|
value.b, value.a);
|
||||||
|
case ColorFmt::Rgbf:
|
||||||
|
return std::format_to(ctx.out(), "{}, {}, {}", value.rf(), value.gf(),
|
||||||
|
value.bf());
|
||||||
|
case ColorFmt::Rgbaf:
|
||||||
|
return std::format_to(ctx.out(), "{}, {}, {}, {}", value.rf(),
|
||||||
|
value.gf(), value.bf(), value.af());
|
||||||
|
default:
|
||||||
|
return ctx.out();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr bool check(std::format_parse_context::const_iterator it,
|
||||||
|
std::format_parse_context::const_iterator end,
|
||||||
|
size_t len, const char* what) {
|
||||||
|
return (end - it >= static_cast<std::ptrdiff_t>(len) &&
|
||||||
|
std::string_view(&*it, len) == what); // msvc things...
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
MIT License
|
MIT License
|
||||||
Copyright (c) 2024 - 2025 René Amthor (tobid7)
|
Copyright (c) 2024 - 2026 René Amthor (tobid7)
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
@@ -25,7 +25,7 @@ SOFTWARE.
|
|||||||
|
|
||||||
// This file is based on fvec4
|
// This file is based on fvec4
|
||||||
|
|
||||||
#include <pd/core/common.hpp>
|
#include <pd/common.hpp>
|
||||||
#include <pd/core/vec4.hpp>
|
#include <pd/core/vec4.hpp>
|
||||||
|
|
||||||
namespace PD {
|
namespace PD {
|
||||||
|
|||||||
50
include/pd/core/hashid.hpp
Normal file
50
include/pd/core/hashid.hpp
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <pd/core/fnv.hpp>
|
||||||
|
#include <pd/core/strings.hpp>
|
||||||
|
|
||||||
|
namespace PD {
|
||||||
|
template <typename T>
|
||||||
|
class HashID {
|
||||||
|
public:
|
||||||
|
using __Type = T;
|
||||||
|
|
||||||
|
constexpr HashID() {};
|
||||||
|
constexpr HashID(T id) { pID = id; }
|
||||||
|
HashID(const std::string& name) {
|
||||||
|
pID = Detail::FNV1A<T>::Hash(name);
|
||||||
|
#ifdef PD_HASHID_KEEP_STR
|
||||||
|
pName = name;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
constexpr HashID(const char* name) {
|
||||||
|
pID = Detail::FNV1A<T>::Hash(std::string_view(name));
|
||||||
|
#ifdef PD_HASHID_KEEP_STR
|
||||||
|
pName = name;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
~HashID() {}
|
||||||
|
|
||||||
|
constexpr T Get() { return pID; }
|
||||||
|
|
||||||
|
std::string GetName() const {
|
||||||
|
#ifdef PD_HASHID_KEEP_STR
|
||||||
|
return pName;
|
||||||
|
#else
|
||||||
|
return std::format("hash({:#08x})", pID);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
operator T() const { return pID; }
|
||||||
|
// operator std::string() const { return GetName(); }
|
||||||
|
|
||||||
|
private:
|
||||||
|
T pID;
|
||||||
|
#ifdef PD_HASHID_KEEP_STR
|
||||||
|
str pName;
|
||||||
|
#endif
|
||||||
|
};
|
||||||
|
|
||||||
|
using HashID32 = HashID<u32>;
|
||||||
|
using HashID64 = HashID<u64>;
|
||||||
|
} // namespace PD
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
MIT License
|
MIT License
|
||||||
Copyright (c) 2024 - 2025 René Amthor (tobid7)
|
Copyright (c) 2024 - 2026 René Amthor (tobid7)
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
@@ -23,7 +23,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|||||||
SOFTWARE.
|
SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <pd/core/common.hpp>
|
#include <pd/common.hpp>
|
||||||
|
|
||||||
namespace PD {
|
namespace PD {
|
||||||
/**
|
/**
|
||||||
@@ -35,28 +35,28 @@ namespace IO {
|
|||||||
* @param path Path to the File
|
* @param path Path to the File
|
||||||
* @return 8Bit FileBuffer
|
* @return 8Bit FileBuffer
|
||||||
*/
|
*/
|
||||||
PD_CORE_API std::vector<u8> LoadFile2Mem(const std::string& path);
|
PD_API std::vector<u8> LoadFile2Mem(const std::string& path);
|
||||||
/**
|
/**
|
||||||
* Load a File into a std::string
|
* Load a File into a std::string
|
||||||
* @param path Path to the File
|
* @param path Path to the File
|
||||||
* @return std::string file content
|
* @return std::string file content
|
||||||
*/
|
*/
|
||||||
PD_CORE_API std::string LoadFile2Str(const std::string& path);
|
PD_API std::string LoadFile2Str(const std::string& path);
|
||||||
/**
|
/**
|
||||||
* Hash a 8Bit Memory Buffer
|
* Hash a 8Bit Memory Buffer
|
||||||
* @param data 8Bit input Buffer
|
* @param data 8Bit input Buffer
|
||||||
* @return 32Bit Hash
|
* @return 32Bit Hash
|
||||||
*/
|
*/
|
||||||
PD_CORE_API u32 HashMemory(const std::vector<u8>& data);
|
PD_API u32 HashMemory(const std::vector<u8>& data);
|
||||||
/**
|
/**
|
||||||
* Function to decrompress RLE buffer
|
* Function to decrompress RLE buffer
|
||||||
* @param data Data buffer to decompress
|
* @param data Data buffer to decompress
|
||||||
*/
|
*/
|
||||||
PD_CORE_API void DecompressRLE(std::vector<u8>& data);
|
PD_API void DecompressRLE(std::vector<u8>& data);
|
||||||
/**
|
/**
|
||||||
* Function to compress data with RLE Algorithm
|
* Function to compress data with RLE Algorithm
|
||||||
* @param data Data buf
|
* @param data Data buf
|
||||||
*/
|
*/
|
||||||
PD_CORE_API void CompressRLE(std::vector<u8>& data);
|
PD_API void CompressRLE(std::vector<u8>& data);
|
||||||
} // namespace IO
|
} // namespace IO
|
||||||
} // namespace PD
|
} // namespace PD
|
||||||
@@ -2,8 +2,7 @@
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
MIT License
|
MIT License
|
||||||
|
Copyright (c) 2024 - 2026 René Amthor (tobid7)
|
||||||
Copyright (c) 2024 - 2025 tobid7
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
@@ -24,7 +23,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|||||||
SOFTWARE.
|
SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <pd/core/common.hpp>
|
#include <pd/common.hpp>
|
||||||
#include <pd/core/vec3.hpp>
|
#include <pd/core/vec3.hpp>
|
||||||
|
|
||||||
namespace PD {
|
namespace PD {
|
||||||
@@ -41,7 +40,7 @@ constexpr float Radians(float v) { return v * (Numbers::Tau / 360.0f); }
|
|||||||
* @note That this is not a full Matrix Library
|
* @note That this is not a full Matrix Library
|
||||||
*/
|
*/
|
||||||
|
|
||||||
struct PD_CORE_API Mat4 {
|
struct PD_API Mat4 {
|
||||||
std::array<float, 16> m;
|
std::array<float, 16> m;
|
||||||
constexpr Mat4() : m{} {}
|
constexpr Mat4() : m{} {}
|
||||||
constexpr static Mat4 Diagonal(float x, float y, float z, float w) {
|
constexpr static Mat4 Diagonal(float x, float y, float z, float w) {
|
||||||
@@ -110,6 +109,16 @@ struct PD_CORE_API Mat4 {
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
constexpr Mat4 Transpose() const {
|
||||||
|
Mat4 ret;
|
||||||
|
for (int i = 0; i < 4; ++i) {
|
||||||
|
for (int j = 0; j < 4; ++j) {
|
||||||
|
ret(i, j) = (*this)(j, i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
constexpr static Mat4 Ortho(float l, float r, float b, float t, float n,
|
constexpr static Mat4 Ortho(float l, float r, float b, float t, float n,
|
||||||
float f) {
|
float f) {
|
||||||
Mat4 ret;
|
Mat4 ret;
|
||||||
|
|||||||
@@ -1,51 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
/*
|
|
||||||
MIT License
|
|
||||||
Copyright (c) 2024 - 2025 René Amthor (tobid7)
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/** Generated with ppam */
|
|
||||||
|
|
||||||
#ifdef _WIN32 // Windows (MSVC Tested)
|
|
||||||
#ifdef PD_CORE_BUILD_SHARED
|
|
||||||
#define PD_CORE_API __declspec(dllexport)
|
|
||||||
#else
|
|
||||||
#define PD_CORE_API __declspec(dllimport)
|
|
||||||
#endif
|
|
||||||
#elif defined(__APPLE__) // macOS (untested yet)
|
|
||||||
#ifdef PD_CORE_BUILD_SHARED
|
|
||||||
#define PD_CORE_API __attribute__((visibility("default")))
|
|
||||||
#else
|
|
||||||
#define PD_CORE_API
|
|
||||||
#endif
|
|
||||||
#elif defined(__linux__) // Linux (untested yet)
|
|
||||||
#ifdef PD_CORE_BUILD_SHARED
|
|
||||||
#define PD_CORE_API __attribute__((visibility("default")))
|
|
||||||
#else
|
|
||||||
#define PD_CORE_API
|
|
||||||
#endif
|
|
||||||
#elif defined(__3DS__) // 3ds Specific
|
|
||||||
// Only Static supported
|
|
||||||
#define PD_CORE_API
|
|
||||||
#else
|
|
||||||
#define PD_CORE_API
|
|
||||||
#endif
|
|
||||||
98
include/pd/core/pool.hpp
Normal file
98
include/pd/core/pool.hpp
Normal file
@@ -0,0 +1,98 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
#include <pd/common.hpp>
|
||||||
|
namespace PD {
|
||||||
|
template <typename T, typename Alloc = std::allocator<T>>
|
||||||
|
class Pool {
|
||||||
|
public:
|
||||||
|
using value_type = T;
|
||||||
|
using iterator = T*;
|
||||||
|
using const_iterator = const T*;
|
||||||
|
|
||||||
|
Pool() = default;
|
||||||
|
~Pool() {
|
||||||
|
if (pData) {
|
||||||
|
pAlloc.deallocate(pData, pCap);
|
||||||
|
pData = nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static Pool* Create(size_t size) { return new Pool(size); }
|
||||||
|
|
||||||
|
void Init(size_t size) {
|
||||||
|
pPos = 0;
|
||||||
|
pCap = size;
|
||||||
|
pData = pAlloc.allocate(size);
|
||||||
|
for (size_t i = 0; i < pCap; i++) {
|
||||||
|
std::allocator_traits<Alloc>::construct(pAlloc, &pData[i]);
|
||||||
|
}
|
||||||
|
PDLOG("Pool::Init({})", size);
|
||||||
|
}
|
||||||
|
|
||||||
|
Pool(const Pool&) = delete;
|
||||||
|
Pool(Pool&&) = delete;
|
||||||
|
Pool& operator=(const Pool&) = delete;
|
||||||
|
Pool& operator=(Pool&&) = delete;
|
||||||
|
|
||||||
|
T* Allocate(size_t num = 1) {
|
||||||
|
ExpandIf(num);
|
||||||
|
T* ret = &pData[pPos];
|
||||||
|
pPos += num;
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Push(const T& elem) {
|
||||||
|
T* e = Allocate(1);
|
||||||
|
*e = elem;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ExpandIf(size_t req) {
|
||||||
|
if ((pPos + req) <= pCap) return;
|
||||||
|
size_t ncap = std::max(pCap * 2, pPos + req);
|
||||||
|
T* nu = pAlloc.allocate(ncap);
|
||||||
|
if (pData) {
|
||||||
|
for (size_t i = 0; i < pPos; i++) {
|
||||||
|
std::allocator_traits<Alloc>::construct(
|
||||||
|
pAlloc, &nu[i], std::move_if_noexcept(pData[i]));
|
||||||
|
}
|
||||||
|
pAlloc.deallocate(pData, pCap);
|
||||||
|
}
|
||||||
|
for (size_t i = pPos; i < ncap; i++) {
|
||||||
|
std::allocator_traits<Alloc>::construct(pAlloc, &nu[i]);
|
||||||
|
}
|
||||||
|
PDLOG("Pool::ExpandIf({}): {} -> {}", req, pCap, ncap);
|
||||||
|
pData = nu;
|
||||||
|
pCap = ncap;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Reset() {
|
||||||
|
for (size_t i = 0; i < pCap; i++) {
|
||||||
|
std::allocator_traits<Alloc>::destroy(pAlloc, &pData[i]);
|
||||||
|
}
|
||||||
|
pPos = 0;
|
||||||
|
for (size_t i = 0; i < pCap; i++) {
|
||||||
|
std::allocator_traits<Alloc>::construct(pAlloc, &pData[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t size() const { return pPos; }
|
||||||
|
size_t capacity() const { return pCap; }
|
||||||
|
T& at(size_t idx) { return pData[idx]; }
|
||||||
|
const T& at(size_t idx) const { return pData[idx]; }
|
||||||
|
iterator begin() { return pData; }
|
||||||
|
iterator end() { return pData + pPos; }
|
||||||
|
const_iterator begin() const { return pData; }
|
||||||
|
const_iterator end() const { return pData + pPos; }
|
||||||
|
|
||||||
|
T& operator[](size_t idx) { return at(idx); }
|
||||||
|
const T& operator[](size_t idx) const { return at(idx); }
|
||||||
|
|
||||||
|
private:
|
||||||
|
Pool(size_t size) : pCap(size), pPos(0) { pData = pAlloc.allocate(size); }
|
||||||
|
size_t pCap = 0;
|
||||||
|
size_t pPos = 0;
|
||||||
|
Alloc pAlloc;
|
||||||
|
T* pData = nullptr;
|
||||||
|
};
|
||||||
|
} // namespace PD
|
||||||
@@ -1,71 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
/*
|
|
||||||
MIT License
|
|
||||||
|
|
||||||
Copyright (c) 2024 - 2025 tobid7
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <pd/core/common.hpp>
|
|
||||||
#include <pd/core/sl/list.hpp>
|
|
||||||
#include <pd/core/sl/pair.hpp>
|
|
||||||
|
|
||||||
namespace PD {
|
|
||||||
template <typename K, typename V, size_t bucket_count = 10>
|
|
||||||
class HashMap {
|
|
||||||
public:
|
|
||||||
HashMap() {}
|
|
||||||
~HashMap() {}
|
|
||||||
|
|
||||||
void Insert(const K& k, const V& v) {
|
|
||||||
size_t idx = Hash(k);
|
|
||||||
auto& bukket = pBuckets[idx];
|
|
||||||
for (auto& it : bukket) {
|
|
||||||
if (it.First == k) {
|
|
||||||
it.Second = v;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
bukket.PushBack(Pair(k, v));
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Contains(const K& k) const {
|
|
||||||
size_t idx = Hash(k);
|
|
||||||
auto& bukket = pBuckets[idx];
|
|
||||||
|
|
||||||
for (auto& it : bukket) {
|
|
||||||
if (it.First == k) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Clear() {
|
|
||||||
for (size_t i = 0; i < bucket_count; i++) {
|
|
||||||
pBuckets[i].Clear();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t Hash(const K& k) const { return std::hash<K>{}(k) % bucket_count; }
|
|
||||||
PD::List<PD::Pair<K, V>> pBuckets[bucket_count];
|
|
||||||
};
|
|
||||||
} // namespace PD
|
|
||||||
@@ -1,210 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
/*
|
|
||||||
MIT License
|
|
||||||
|
|
||||||
Copyright (c) 2024 - 2025 tobid7
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <pd/core/common.hpp>
|
|
||||||
|
|
||||||
namespace PD {
|
|
||||||
template <typename T>
|
|
||||||
class List {
|
|
||||||
public:
|
|
||||||
List() {}
|
|
||||||
~List() {}
|
|
||||||
|
|
||||||
struct Node {
|
|
||||||
Node(const T& v) : Data(v) {}
|
|
||||||
T Data;
|
|
||||||
Node* Prev = nullptr;
|
|
||||||
Node* Next = nullptr;
|
|
||||||
};
|
|
||||||
|
|
||||||
class Iterator {
|
|
||||||
public:
|
|
||||||
Iterator(Node* n) : pNode(n) {}
|
|
||||||
T& operator*() { return pNode->Data; }
|
|
||||||
Iterator& operator++() {
|
|
||||||
pNode = pNode->Next;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
bool operator!=(const Iterator& o) const { return pNode != o.pNode; }
|
|
||||||
|
|
||||||
Node* pNode = nullptr;
|
|
||||||
};
|
|
||||||
|
|
||||||
void PushFront(const T& val) {
|
|
||||||
Node* node = new Node(val);
|
|
||||||
// node->Data = val;
|
|
||||||
node->Prev = nullptr;
|
|
||||||
node->Next = pHead;
|
|
||||||
if (pHead) {
|
|
||||||
pHead->Prev = node;
|
|
||||||
}
|
|
||||||
pHead = node;
|
|
||||||
if (!pTail) {
|
|
||||||
pTail = node;
|
|
||||||
}
|
|
||||||
pSize++;
|
|
||||||
}
|
|
||||||
|
|
||||||
void PushBack(const T& val) {
|
|
||||||
Node* node = new Node(val);
|
|
||||||
// node->Data = val;
|
|
||||||
node->Prev = pTail;
|
|
||||||
node->Next = nullptr;
|
|
||||||
if (pTail) {
|
|
||||||
pTail->Next = node;
|
|
||||||
}
|
|
||||||
pTail = node;
|
|
||||||
if (!pHead) {
|
|
||||||
pHead = node;
|
|
||||||
}
|
|
||||||
pSize++;
|
|
||||||
}
|
|
||||||
|
|
||||||
void PopFront() {
|
|
||||||
if (!pHead) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Node* t = pHead;
|
|
||||||
pHead = pHead->Next;
|
|
||||||
if (pHead) {
|
|
||||||
pHead->Prev = nullptr;
|
|
||||||
} else {
|
|
||||||
pTail = nullptr;
|
|
||||||
}
|
|
||||||
delete t;
|
|
||||||
pSize--;
|
|
||||||
}
|
|
||||||
|
|
||||||
void PopBack() {
|
|
||||||
if (!pTail) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Node* t = pTail;
|
|
||||||
pTail = pTail->Prev;
|
|
||||||
if (pTail) {
|
|
||||||
pTail->Next = nullptr;
|
|
||||||
} else {
|
|
||||||
pHead = nullptr;
|
|
||||||
}
|
|
||||||
delete t;
|
|
||||||
pSize--;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Clear() {
|
|
||||||
while (pHead) {
|
|
||||||
PopFront();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Remove(const T& v) {
|
|
||||||
Node* s = pHead;
|
|
||||||
while (s) {
|
|
||||||
if (s->Data == v) {
|
|
||||||
if (s->Prev) {
|
|
||||||
s->Prev->Next = s->Next;
|
|
||||||
} else {
|
|
||||||
pHead = s->Next;
|
|
||||||
}
|
|
||||||
if (s->Next) {
|
|
||||||
s->Next->Prev = s->Prev;
|
|
||||||
} else {
|
|
||||||
pTail = s->Prev;
|
|
||||||
}
|
|
||||||
delete s;
|
|
||||||
pSize--;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
s = s->Next;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Reverse() {
|
|
||||||
Node* cur = pHead;
|
|
||||||
while (cur) {
|
|
||||||
Node* temp = cur->Prev;
|
|
||||||
cur->Prev = cur->Next;
|
|
||||||
cur->Next = temp;
|
|
||||||
cur = cur->Prev;
|
|
||||||
}
|
|
||||||
Node* temp = pHead;
|
|
||||||
pHead = pTail;
|
|
||||||
pTail = temp;
|
|
||||||
}
|
|
||||||
|
|
||||||
T& Front() {
|
|
||||||
if (pHead) {
|
|
||||||
return pHead->Data;
|
|
||||||
}
|
|
||||||
// Need a List Empty Error Here (exceptions are disabled on 3ds)
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
const T& Front() const {
|
|
||||||
if (pHead) {
|
|
||||||
return pHead->Data;
|
|
||||||
}
|
|
||||||
// Need a List Empty Error Here (exceptions are disabled on 3ds)
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
T& Back() {
|
|
||||||
if (pTail) {
|
|
||||||
return pTail->Data;
|
|
||||||
}
|
|
||||||
// Need a List Empty Error Here (exceptions are disabled on 3ds)
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
const T& Back() const {
|
|
||||||
if (pTail) {
|
|
||||||
return pTail->Data;
|
|
||||||
}
|
|
||||||
// Need a List Empty Error Here (exceptions are disabled on 3ds)
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t Size() const { return pSize; }
|
|
||||||
|
|
||||||
Iterator begin() { return Iterator(pHead); }
|
|
||||||
Iterator end() { return Iterator(nullptr); }
|
|
||||||
|
|
||||||
private:
|
|
||||||
Node* Find(const T& v) const {
|
|
||||||
Node* t = pHead;
|
|
||||||
while (t) {
|
|
||||||
if (t->Data == v) {
|
|
||||||
return t;
|
|
||||||
}
|
|
||||||
t = t->Next;
|
|
||||||
}
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
Node* pHead = nullptr;
|
|
||||||
Node* pTail = nullptr;
|
|
||||||
size_t pSize = 0;
|
|
||||||
};
|
|
||||||
} // namespace PD
|
|
||||||
@@ -1,41 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
/*
|
|
||||||
MIT License
|
|
||||||
|
|
||||||
Copyright (c) 2024 - 2025 tobid7
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <pd/core/common.hpp>
|
|
||||||
|
|
||||||
namespace PD {
|
|
||||||
template <typename T1, typename T2>
|
|
||||||
class Pair {
|
|
||||||
public:
|
|
||||||
Pair() = default;
|
|
||||||
Pair(const T1& f, const T2& s) : First(f), Second(s) {}
|
|
||||||
Pair(T1&& f, T2&& s) : First(std::move(f)), Second(std::move(s)) {}
|
|
||||||
~Pair() = default;
|
|
||||||
|
|
||||||
T1 First;
|
|
||||||
T2 Second;
|
|
||||||
};
|
|
||||||
} // namespace PD
|
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
/*
|
|
||||||
MIT License
|
|
||||||
|
|
||||||
Copyright (c) 2024 - 2025 tobid7
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <pd/core/sl/allocator.hpp>
|
|
||||||
#include <pd/core/sl/hashmap.hpp>
|
|
||||||
#include <pd/core/sl/list.hpp>
|
|
||||||
#include <pd/core/sl/pair.hpp>
|
|
||||||
#include <pd/core/sl/stack.hpp>
|
|
||||||
#include <pd/core/sl/tools.hpp>
|
|
||||||
#include <pd/core/sl/u128.hpp>
|
|
||||||
#include <pd/core/sl/vector.hpp>
|
|
||||||
@@ -1,70 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
/*
|
|
||||||
MIT License
|
|
||||||
|
|
||||||
Copyright (c) 2024 - 2025 tobid7
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <pd/core/common.hpp>
|
|
||||||
#include <pd/core/sl/vector.hpp>
|
|
||||||
|
|
||||||
namespace PD {
|
|
||||||
/**
|
|
||||||
* Custom Stack class (caus std::stack ofsten lead to memory coruption)
|
|
||||||
*/
|
|
||||||
template <typename T, typename Alloc = Allocator<T>>
|
|
||||||
class Stack {
|
|
||||||
public:
|
|
||||||
Stack() = default;
|
|
||||||
explicit Stack(size_t cap) : pVec(cap) {}
|
|
||||||
|
|
||||||
void Push(const T& val) { pVec.Add(val); }
|
|
||||||
|
|
||||||
void Pop() {
|
|
||||||
if (pVec.Size() == 0) {
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
pVec.PopBack();
|
|
||||||
}
|
|
||||||
|
|
||||||
T& Top() {
|
|
||||||
if (pVec.Size() == 0) {
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
return pVec[pVec.Size() - 1];
|
|
||||||
}
|
|
||||||
|
|
||||||
const T& Top() const {
|
|
||||||
if (pVec.Size() == 0) {
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
return pVec[pVec.Size() - 1];
|
|
||||||
}
|
|
||||||
|
|
||||||
bool IsEmpty() const { return pVec.Size() == 0; }
|
|
||||||
size_t Size() const { return pVec.Size(); }
|
|
||||||
void Clear() { pVec.Clear(); }
|
|
||||||
|
|
||||||
private:
|
|
||||||
Vec<T, Alloc> pVec;
|
|
||||||
};
|
|
||||||
} // namespace PD
|
|
||||||
@@ -1,43 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
/*
|
|
||||||
MIT License
|
|
||||||
|
|
||||||
Copyright (c) 2024 - 2025 tobid7
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <pd/core/common.hpp>
|
|
||||||
|
|
||||||
namespace PD {
|
|
||||||
/**
|
|
||||||
* Function to get Arraysize for any type using modern c++ to
|
|
||||||
* get the size at compiletime instead of runtime
|
|
||||||
* @note this function only works for Arrays declared as
|
|
||||||
* type arr[size] and not for pointer references.
|
|
||||||
* This function will precalculate the size at compile time
|
|
||||||
* while keeping the code clean to not hardcode arraysizes
|
|
||||||
* into functions like std::fill_n
|
|
||||||
*/
|
|
||||||
template <typename T, size_t N>
|
|
||||||
constexpr size_t ArraySize(T (&)[N]) noexcept {
|
|
||||||
return N;
|
|
||||||
}
|
|
||||||
} // namespace PD
|
|
||||||
@@ -1,165 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
/*
|
|
||||||
MIT License
|
|
||||||
Copyright (c) 2024 - 2025 René Amthor (tobid7)
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <pd/core/common.hpp>
|
|
||||||
#include <pd/core/sl/allocator.hpp>
|
|
||||||
|
|
||||||
namespace PD {
|
|
||||||
/**
|
|
||||||
* Open Access Vector class (Alternative to std::vector)
|
|
||||||
*/
|
|
||||||
template <typename T, typename Alloc = Allocator<T>>
|
|
||||||
class Vec {
|
|
||||||
public:
|
|
||||||
Vec() {
|
|
||||||
pData = pAllocator.Allocate(2);
|
|
||||||
pCap = 2;
|
|
||||||
Clear();
|
|
||||||
pPos = 0;
|
|
||||||
};
|
|
||||||
Vec(const size_t& Size) {
|
|
||||||
pData = pAllocator.Allocate(Size + 2);
|
|
||||||
pCap = Size + 2;
|
|
||||||
Clear();
|
|
||||||
pPos = Size;
|
|
||||||
}
|
|
||||||
Vec(const size_t& Size, const T& v) {
|
|
||||||
pData = pAllocator.Allocate(Size + 2);
|
|
||||||
pCap = Size + 2;
|
|
||||||
Clear();
|
|
||||||
pPos = Size;
|
|
||||||
std::fill_n(pData, Size, v);
|
|
||||||
}
|
|
||||||
Vec(const T* s, const T* e) {
|
|
||||||
pData = pAllocator.Allocate(2);
|
|
||||||
pCap = 2;
|
|
||||||
Clear();
|
|
||||||
pPos = 0;
|
|
||||||
Resize(e - s);
|
|
||||||
std::copy_n(s, e - s, pData);
|
|
||||||
}
|
|
||||||
Vec(const Vec& v) {
|
|
||||||
pCap = v.pCap;
|
|
||||||
pPos = v.pPos;
|
|
||||||
pData = pAllocator.Allocate(pCap);
|
|
||||||
for (size_t i = 0; i < pPos; i++) {
|
|
||||||
pData[i] = v.pData[i];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
~Vec() { pAllocator.Deallocate(pData); }
|
|
||||||
|
|
||||||
void Add(const T& v) {
|
|
||||||
if (pPos >= pCap) {
|
|
||||||
Reserve(pCap * 2);
|
|
||||||
}
|
|
||||||
pData[pPos++] = v;
|
|
||||||
}
|
|
||||||
|
|
||||||
void PopBack() {
|
|
||||||
if (pPos == 0) return;
|
|
||||||
pPos--;
|
|
||||||
}
|
|
||||||
|
|
||||||
T Pop() {
|
|
||||||
if (pPos == 0) {
|
|
||||||
// Todo: LOG
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
return pData[pPos--];
|
|
||||||
}
|
|
||||||
|
|
||||||
T& At(const size_t& Idx) {
|
|
||||||
if (Idx >= pPos) {
|
|
||||||
// Log
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
return pData[Idx];
|
|
||||||
}
|
|
||||||
|
|
||||||
const T& At(const size_t& Idx) const {
|
|
||||||
if (Idx >= pPos) {
|
|
||||||
// Log
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
return pData[Idx];
|
|
||||||
}
|
|
||||||
|
|
||||||
T& operator[](const size_t& Idx) { return At(Idx); }
|
|
||||||
const T& operator[](const size_t& Idx) const { return At(Idx); }
|
|
||||||
void operator+=(T v) { Add(v); }
|
|
||||||
|
|
||||||
T* Begin() { return pData; }
|
|
||||||
const T* Begin() const { return pData; }
|
|
||||||
T* End() { return pData + pPos; }
|
|
||||||
const T* End() const { return pData + pPos; }
|
|
||||||
|
|
||||||
// Support: `for(auto& it : Vec)` //
|
|
||||||
T* begin() { return pData; }
|
|
||||||
const T* begin() const { return pData; }
|
|
||||||
T* end() { return pData + pPos; }
|
|
||||||
const T* end() const { return pData + pPos; }
|
|
||||||
|
|
||||||
T* Data() { return pData; }
|
|
||||||
T* Data() const { return pData; }
|
|
||||||
size_t Size() const { return pPos; }
|
|
||||||
size_t Capacity() const { return pCap; }
|
|
||||||
void Clear() {
|
|
||||||
// Avoid memset to support std::string for now
|
|
||||||
// probably revert this decision based if it lacks performance
|
|
||||||
// or make it a setting
|
|
||||||
std::fill(pData, pData + pCap, T());
|
|
||||||
pPos = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Reserve(const size_t& Size) {
|
|
||||||
if (Size <= pCap) return;
|
|
||||||
T* tmp = pAllocator.Allocate(Size);
|
|
||||||
std::fill(tmp, tmp + Size, T());
|
|
||||||
std::copy(pData, pData + pCap, tmp);
|
|
||||||
pAllocator.Deallocate(pData);
|
|
||||||
pData = tmp;
|
|
||||||
pCap = Size;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Resize(size_t Size) {
|
|
||||||
if (Size < pPos) {
|
|
||||||
pPos = Size;
|
|
||||||
} else if (Size > pCap) {
|
|
||||||
Reserve(Size);
|
|
||||||
}
|
|
||||||
std::fill(pData + pPos, pData + Size, T());
|
|
||||||
pPos = Size;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Allocator
|
|
||||||
Alloc pAllocator;
|
|
||||||
// Data Reference Pointer
|
|
||||||
T* pData;
|
|
||||||
// Capacity
|
|
||||||
size_t pCap;
|
|
||||||
// Current Position (Size)
|
|
||||||
size_t pPos;
|
|
||||||
};
|
|
||||||
} // namespace PD
|
|
||||||
103
include/pd/core/strings.hpp
Executable file → Normal file
103
include/pd/core/strings.hpp
Executable file → Normal file
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
MIT License
|
MIT License
|
||||||
Copyright (c) 2024 - 2025 René Amthor (tobid7)
|
Copyright (c) 2024 - 2026 René Amthor (tobid7)
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
@@ -23,60 +23,67 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|||||||
SOFTWARE.
|
SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <pd/core/common.hpp>
|
#include <pd/common.hpp>
|
||||||
|
|
||||||
namespace PD {
|
namespace PD {
|
||||||
/**
|
/**
|
||||||
* Set of String Utillity Functions
|
* Set of String Utillity Functions
|
||||||
*/
|
*/
|
||||||
namespace Strings {
|
namespace Strings {
|
||||||
|
constexpr int HexChar2Int(char c) {
|
||||||
|
/** Imagine man hat ne lookup table dafür verwendet :/ */
|
||||||
|
if (c >= '0' && c <= '9') return c - '0';
|
||||||
|
if (c >= 'a' && c <= 'f') return 10 + (c - 'a');
|
||||||
|
if (c >= 'A' && c <= 'F') return 10 + (c - 'A');
|
||||||
|
return -1; // Error
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* Check if a String ends with a specific extension
|
* Check if a String ends with a specific extension
|
||||||
* @param str Input string
|
* @param str Input string
|
||||||
* @param exts List of Extensions to check for
|
* @param exts List of Extensions to check for
|
||||||
* @return true if one of the extensions is found in the String
|
* @return true if one of the extensions is found in the String
|
||||||
*/
|
*/
|
||||||
PD_CORE_API bool StringEndsWith(const std::string& str,
|
PD_API bool StringEndsWith(const std::string& str,
|
||||||
const std::vector<std::string>& exts);
|
const std::vector<std::string>& exts);
|
||||||
/**
|
/**
|
||||||
* Function to Create a wstring of a string
|
* Function to Create a wstring of a string
|
||||||
* @param s Input String to Convert
|
* @param s Input String to Convert
|
||||||
* @return Result wstring
|
* @return Result wstring
|
||||||
* @note Returns Empty if it has an error
|
* @note Returns Empty if it has an error
|
||||||
*/
|
*/
|
||||||
PD_CORE_API std::wstring MakeWstring(const std::string& s);
|
PD_API std::wstring MakeWstring(const std::string& s);
|
||||||
/**
|
/**
|
||||||
* Generate a Formatted String by an Nanoseconds Input
|
* Generate a Formatted String by an Nanoseconds Input
|
||||||
* @param nanos Nanoseconds Input
|
* @param nanos Nanoseconds Input
|
||||||
* @return Result String
|
* @return Result String
|
||||||
*/
|
*/
|
||||||
PD_CORE_API const std::string FormatNanos(unsigned long long nanos);
|
PD_API const std::string FormatNanos(unsigned long long nanos);
|
||||||
/**
|
/**
|
||||||
* Generate a Formatted String by an Milliseconds Input
|
* Generate a Formatted String by an Milliseconds Input
|
||||||
* @param millis Milliseconds Input
|
* @param millis Milliseconds Input
|
||||||
* @return Result String
|
* @return Result String
|
||||||
*/
|
*/
|
||||||
PD_CORE_API const std::string FormatMillis(unsigned long long millis);
|
PD_API const std::string FormatMillis(unsigned long long millis);
|
||||||
/**
|
/**
|
||||||
* Create a formatted String by an input bytes value
|
* Create a formatted String by an input bytes value
|
||||||
* @param bytes value in bytes
|
* @param bytes value in bytes
|
||||||
* @result Formatted String for example `2.5MB`
|
* @result Formatted String for example `2.5MB`
|
||||||
*/
|
*/
|
||||||
PD_CORE_API const std::string FormatBytes(unsigned long long bytes);
|
PD_API const std::string FormatBytes(unsigned long long bytes);
|
||||||
/**
|
/**
|
||||||
* Extract the Filename out of a Path
|
* Extract the Filename out of a Path
|
||||||
* @param path Path to extract from
|
* @param path Path to extract from
|
||||||
* @param saperators Path Split Chars
|
* @param saperators Path Split Chars
|
||||||
* @return extracted filename
|
* @return extracted filename
|
||||||
*/
|
*/
|
||||||
PD_CORE_API const std::string GetFileName(
|
PD_API const std::string GetFileName(const std::string& path,
|
||||||
const std::string& path, const std::string& saperators = "/\\");
|
const std::string& saperators = "/\\");
|
||||||
/**
|
/**
|
||||||
* Remove Extension from a Path / Filename
|
* Remove Extension from a Path / Filename
|
||||||
* @param path Input Path
|
* @param path Input Path
|
||||||
* @return Path without Extension
|
* @return Path without Extension
|
||||||
*/
|
*/
|
||||||
PD_CORE_API const std::string PathRemoveExtension(const std::string& path);
|
PD_API const std::string PathRemoveExtension(const std::string& path);
|
||||||
/**
|
/**
|
||||||
* Function to Convert a Type to a hex value
|
* Function to Convert a Type to a hex value
|
||||||
* @tparam T Type
|
* @tparam T Type
|
||||||
@@ -85,39 +92,79 @@ PD_CORE_API const std::string PathRemoveExtension(const std::string& path);
|
|||||||
*/
|
*/
|
||||||
template <typename T>
|
template <typename T>
|
||||||
inline const std::string ToHex(const T& v) {
|
inline const std::string ToHex(const T& v) {
|
||||||
std::stringstream s;
|
return std::format("{0:0{1}X}", v, sizeof(v) * 2);
|
||||||
s << "0x" << std::setfill('0') << std::setw(sizeof(v) * 2) << std::hex << v;
|
|
||||||
return s.str();
|
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Generate a Hash out of a string
|
* Generate a Hash out of a string
|
||||||
* @param s String to hash
|
* @param s String to hash
|
||||||
* @return 32Bit Hash
|
* @return 32Bit Hash
|
||||||
*/
|
*/
|
||||||
PD_CORE_API u32 FastHash(const std::string& s);
|
PD_API u32 FastHash(const std::string& s);
|
||||||
/**
|
/**
|
||||||
* Function to Generate a Compiler Name and Version String
|
* Function to Generate a Compiler Name and Version String
|
||||||
* Based on their Macros
|
* Based on their Macros
|
||||||
* @return CompilerName: Version
|
* @return CompilerName: Version
|
||||||
*/
|
*/
|
||||||
inline const std::string GetCompilerVersion() {
|
inline const char* GetCompilerVersion() {
|
||||||
/// As the function looks like this Project is meant to
|
/// As the function looks like this Project is meant to
|
||||||
/// Be ported to other systems as well
|
/// Be ported to other systems as well
|
||||||
std::stringstream res;
|
#define __mks(x) #x
|
||||||
|
#define mkstring(x) __mks(x)
|
||||||
#ifdef __clang__ // Check clang first
|
#ifdef __clang__ // Check clang first
|
||||||
res << "Clang: " << __clang_major__ << ".";
|
return "Clang: " mkstring(__clang_major__) "." mkstring(
|
||||||
res << __clang_minor__ << ".";
|
__clang_minor__) "." mkstring(__clang_patchlevel__);
|
||||||
res << __clang_patchlevel__;
|
|
||||||
#elif __GNUC__
|
#elif __GNUC__
|
||||||
res << "GCC: " << __GNUC__;
|
return "GCC: " mkstring(__GNUC__) "." mkstring(__GNUC_MINOR__) "." mkstring(
|
||||||
res << "." << __GNUC_MINOR__ << ".";
|
__GNUC_PATCHLEVEL__);
|
||||||
res << __GNUC_PATCHLEVEL__;
|
|
||||||
#elif _MSC_VER
|
#elif _MSC_VER
|
||||||
res << "MSVC: " << _MSC_VER;
|
return "MSVC; " mkstring(_MSC_VER);
|
||||||
#else
|
#else
|
||||||
res << "Unknown Compiler";
|
return "Unknown Compiler";
|
||||||
#endif
|
#endif
|
||||||
return res.str();
|
|
||||||
}
|
}
|
||||||
} // namespace Strings
|
} // namespace Strings
|
||||||
|
class U8Iterator {
|
||||||
|
public:
|
||||||
|
explicit U8Iterator(const char* s) : ptr(reinterpret_cast<const u8*>(s)) {}
|
||||||
|
~U8Iterator() = default;
|
||||||
|
|
||||||
|
bool Decode32(u32& ret) {
|
||||||
|
if (ptr == nullptr || *ptr == 0) return false;
|
||||||
|
u8 c = *ptr;
|
||||||
|
if (c < 0x80) {
|
||||||
|
ret = c;
|
||||||
|
ptr += 1;
|
||||||
|
} else if ((c >> 5) == 0x6) {
|
||||||
|
ret = ((c & 0x1F) << 6) | (ptr[1] & 0x3F);
|
||||||
|
ptr += 2;
|
||||||
|
} else if ((c >> 4) == 0xE) {
|
||||||
|
ret = ((c & 0x0F) << 12) | ((ptr[1] & 0x3F) << 6) | (ptr[2] & 0x3F);
|
||||||
|
ptr += 3;
|
||||||
|
} else {
|
||||||
|
ret = ((c & 0x07) << 18) | ((ptr[1] & 0x3F) << 12) |
|
||||||
|
((ptr[2] & 0x3F) << 6) | (ptr[3] & 0x3F);
|
||||||
|
ptr += 4;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool PeekNext32(u32& ret) {
|
||||||
|
// if ((ptr + 1) == 0 || *(ptr + 1) == 0) return false;
|
||||||
|
u8 c = *ptr;
|
||||||
|
if (c < 0x80) {
|
||||||
|
ret = c;
|
||||||
|
} else if ((c >> 5) == 0x6) {
|
||||||
|
ret = ((c & 0x1F) << 6) | (ptr[1] & 0x3F);
|
||||||
|
} else if ((c >> 4) == 0xE) {
|
||||||
|
ret = ((c & 0x0F) << 12) | ((ptr[1] & 0x3F) << 6) | (ptr[2] & 0x3F);
|
||||||
|
} else {
|
||||||
|
ret = ((c & 0x07) << 18) | ((ptr[1] & 0x3F) << 12) |
|
||||||
|
((ptr[2] & 0x3F) << 6) | (ptr[3] & 0x3F);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
const u8* ptr = nullptr;
|
||||||
|
};
|
||||||
} // namespace PD
|
} // namespace PD
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
MIT License
|
MIT License
|
||||||
Copyright (c) 2024 - 2025 René Amthor (tobid7)
|
Copyright (c) 2024 - 2026 René Amthor (tobid7)
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
@@ -23,13 +23,13 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|||||||
SOFTWARE.
|
SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <pd/core/common.hpp>
|
#include <pd/common.hpp>
|
||||||
|
|
||||||
namespace PD {
|
namespace PD {
|
||||||
/**
|
/**
|
||||||
* Timer class
|
* Timer class
|
||||||
*/
|
*/
|
||||||
class PD_CORE_API Timer {
|
class PD_API Timer {
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
@@ -41,8 +41,6 @@ class PD_CORE_API Timer {
|
|||||||
*/
|
*/
|
||||||
~Timer() {}
|
~Timer() {}
|
||||||
|
|
||||||
PD_SHARED(Timer);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resume Timer if Paused
|
* Resume Timer if Paused
|
||||||
*/
|
*/
|
||||||
|
|||||||
33
include/pd/core/timetrace.hpp
Executable file → Normal file
33
include/pd/core/timetrace.hpp
Executable file → Normal file
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
MIT License
|
MIT License
|
||||||
Copyright (c) 2024 - 2025 René Amthor (tobid7)
|
Copyright (c) 2024 - 2026 René Amthor (tobid7)
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
@@ -23,7 +23,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|||||||
SOFTWARE.
|
SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <pd/core/common.hpp>
|
#include <pd/common.hpp>
|
||||||
|
|
||||||
namespace PD {
|
namespace PD {
|
||||||
/**
|
/**
|
||||||
@@ -38,8 +38,6 @@ class TimeStats {
|
|||||||
TimeStats(int l) : len(l), val(l, 0) {}
|
TimeStats(int l) : len(l), val(l, 0) {}
|
||||||
~TimeStats() = default;
|
~TimeStats() = default;
|
||||||
|
|
||||||
PD_SHARED(TimeStats);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a New Value to the list
|
* Add a New Value to the list
|
||||||
* @param v value to add
|
* @param v value to add
|
||||||
@@ -102,12 +100,12 @@ class TimeStats {
|
|||||||
* Get Data Buffer
|
* Get Data Buffer
|
||||||
* @return data bufer (not edidable)
|
* @return data bufer (not edidable)
|
||||||
*/
|
*/
|
||||||
const std::vector<u64> &GetData() { return val; }
|
const std::vector<u64>& GetData() { return val; }
|
||||||
/**
|
/**
|
||||||
* Access an element in the list [not edidable]
|
* Access an element in the list [not edidable]
|
||||||
* @return value to access
|
* @return value to access
|
||||||
*/
|
*/
|
||||||
const u64 &operator[](int i) { return val[smart_idx(i)]; }
|
const u64& operator[](int i) { return val[smart_idx(i)]; }
|
||||||
/**
|
/**
|
||||||
* Get List Lengh
|
* Get List Lengh
|
||||||
* @return Lengh
|
* @return Lengh
|
||||||
@@ -151,16 +149,14 @@ namespace TT {
|
|||||||
class Res {
|
class Res {
|
||||||
public:
|
public:
|
||||||
/** Constructore that Inits a protocol at size of 60 frames */
|
/** Constructore that Inits a protocol at size of 60 frames */
|
||||||
Res(): start(0), end(0) { protocol = TimeStats::New(60); }
|
Res() : start(0), end(0), protocol(60) {}
|
||||||
~Res() = default;
|
~Res() = default;
|
||||||
|
|
||||||
PD_SHARED(Res);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Setter for the ID (Name)
|
* Setter for the ID (Name)
|
||||||
* @param v ID of the Trace
|
* @param v ID of the Trace
|
||||||
*/
|
*/
|
||||||
void SetID(const std::string &v) { id = v; }
|
void SetID(const std::string& v) { id = v; }
|
||||||
/**
|
/**
|
||||||
* Getter for the traces ID
|
* Getter for the traces ID
|
||||||
* @return Trace ID
|
* @return Trace ID
|
||||||
@@ -182,7 +178,8 @@ class Res {
|
|||||||
*/
|
*/
|
||||||
void SetEnd(u64 v) {
|
void SetEnd(u64 v) {
|
||||||
end = v;
|
end = v;
|
||||||
protocol->Add(GetLastDiff());
|
diff = end - start;
|
||||||
|
protocol.Add(GetLastDiff());
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Getter for the End Time
|
* Getter for the End Time
|
||||||
@@ -194,12 +191,12 @@ class Res {
|
|||||||
* Get Last Diffrence between end and start
|
* Get Last Diffrence between end and start
|
||||||
* @return end - start
|
* @return end - start
|
||||||
*/
|
*/
|
||||||
u64 GetLastDiff() { return end - start; }
|
u64 GetLastDiff() { return diff; }
|
||||||
/**
|
/**
|
||||||
* Get Protcol Reference
|
* Get Protcol Reference
|
||||||
* @return Protocol Ref
|
* @return Protocol Ref
|
||||||
*/
|
*/
|
||||||
TimeStats::Ref GetProtocol() { return protocol; }
|
TimeStats& GetProtocol() { return protocol; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/** Trace ID */
|
/** Trace ID */
|
||||||
@@ -208,19 +205,21 @@ class Res {
|
|||||||
u64 start;
|
u64 start;
|
||||||
/** End Time */
|
/** End Time */
|
||||||
u64 end;
|
u64 end;
|
||||||
|
/** Last Diff */
|
||||||
|
u64 diff;
|
||||||
/** Protocol */
|
/** Protocol */
|
||||||
TimeStats::Ref protocol;
|
TimeStats protocol;
|
||||||
};
|
};
|
||||||
/**
|
/**
|
||||||
* Begin a Trace
|
* Begin a Trace
|
||||||
* @param id Name of the Trace
|
* @param id Name of the Trace
|
||||||
*/
|
*/
|
||||||
PD_CORE_API void Beg(const std::string &id);
|
PD_API void Beg(const std::string& id);
|
||||||
/**
|
/**
|
||||||
* End a Trace
|
* End a Trace
|
||||||
* @param id Name of the Trace
|
* @param id Name of the Trace
|
||||||
*/
|
*/
|
||||||
PD_CORE_API void End(const std::string &id);
|
PD_API void End(const std::string& id);
|
||||||
/**
|
/**
|
||||||
* Collect Start end end of the trace by tracking
|
* Collect Start end end of the trace by tracking
|
||||||
* when the Scope object goes out of scope
|
* when the Scope object goes out of scope
|
||||||
@@ -242,7 +241,7 @@ class Scope {
|
|||||||
* Constructor requiring a Name for the Trace
|
* Constructor requiring a Name for the Trace
|
||||||
* @param id Name of the Trace
|
* @param id Name of the Trace
|
||||||
*/
|
*/
|
||||||
Scope(const std::string &id) {
|
Scope(const std::string& id) {
|
||||||
this->ID = id;
|
this->ID = id;
|
||||||
Beg(id);
|
Beg(id);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
MIT License
|
MIT License
|
||||||
Copyright (c) 2024 - 2025 René Amthor (tobid7)
|
Copyright (c) 2024 - 2026 René Amthor (tobid7)
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
@@ -23,7 +23,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|||||||
SOFTWARE.
|
SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <pd/core/common.hpp>
|
#include <pd/common.hpp>
|
||||||
|
|
||||||
#ifndef M_PI
|
#ifndef M_PI
|
||||||
#define M_PI 3.14159265358979323846
|
#define M_PI 3.14159265358979323846
|
||||||
@@ -60,7 +60,7 @@ class Tween {
|
|||||||
* @param delta deltatime
|
* @param delta deltatime
|
||||||
*/
|
*/
|
||||||
void Update(float delta) {
|
void Update(float delta) {
|
||||||
time += delta / 1000.f;
|
time += delta * 0.001f;
|
||||||
if (time > tend) {
|
if (time > tend) {
|
||||||
finished = true;
|
finished = true;
|
||||||
time = tend;
|
time = tend;
|
||||||
@@ -162,10 +162,10 @@ class Tween {
|
|||||||
return -(end - start) * t * (t - 2) + start;
|
return -(end - start) * t * (t - 2) + start;
|
||||||
break;
|
break;
|
||||||
case EaseInOutQuad:
|
case EaseInOutQuad:
|
||||||
t = time / (tend / 2);
|
t = time / (tend * 0.5f);
|
||||||
if (t < 1) return (end - start) / 2 * t * t + start;
|
if (t < 1) return (end - start) * 0.5f * t * t + start;
|
||||||
t--;
|
t--;
|
||||||
return -(end - start) / 2 * (t * (t - 2) - 1) + start;
|
return -(end - start) * 0.5f * (t * (t - 2) - 1) + start;
|
||||||
break;
|
break;
|
||||||
case EaseInCubic:
|
case EaseInCubic:
|
||||||
t = time / tend;
|
t = time / tend;
|
||||||
@@ -177,20 +177,20 @@ class Tween {
|
|||||||
return (end - start) * (t * t * t + 1) + start;
|
return (end - start) * (t * t * t + 1) + start;
|
||||||
break;
|
break;
|
||||||
// case EaseInOutCubic:
|
// case EaseInOutCubic:
|
||||||
// t = time / (tend / 2);
|
// t = time / (tend *0.5f);
|
||||||
// if (t < 1) return (end - start) / 2 * t * t * t + start;
|
// if (t < 1) return (end - start) *0.5f * t * t * t + start;
|
||||||
// t--;
|
// t--;
|
||||||
// return (end - start) / 2 * (t * t * t * 2) + start;
|
// return (end - start) *0.5f * (t * t * t * 2) + start;
|
||||||
// break;
|
// break;
|
||||||
case EaseInSine:
|
case EaseInSine:
|
||||||
return -(end - start) * cos(time / tend * (M_PI / 2)) + (end - start) +
|
return -(end - start) * cos(time / tend * (M_PI * 0.5f)) +
|
||||||
start;
|
(end - start) + start;
|
||||||
break;
|
break;
|
||||||
case EaseOutSine:
|
case EaseOutSine:
|
||||||
return (end - start) * sin(time / tend * (M_PI / 2)) + start;
|
return (end - start) * sin(time / tend * (M_PI * 0.5f)) + start;
|
||||||
break;
|
break;
|
||||||
case EaseInOutSine:
|
case EaseInOutSine:
|
||||||
return -(end - start) / 2 * (cos(M_PI * time / tend) - 1) + start;
|
return -(end - start) * 0.5f * (cos(M_PI * time / tend) - 1) + start;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default: // Linear
|
default: // Linear
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <pd/core/common.hpp>
|
#include <pd/common.hpp>
|
||||||
|
|
||||||
namespace PD {
|
namespace PD {
|
||||||
/**
|
/**
|
||||||
@@ -28,18 +28,18 @@ class u128 {
|
|||||||
return u128();
|
return u128();
|
||||||
}
|
}
|
||||||
|
|
||||||
u128 operator+(const u128& v) const {
|
constexpr u128 operator+(const u128& v) const {
|
||||||
u128 ret;
|
u128 ret;
|
||||||
ret.pLow = pLow + v.pLow;
|
ret.pLow = pLow + v.pLow;
|
||||||
ret.pHigh = pHigh + v.pHigh + (ret.pLow < pLow);
|
ret.pHigh = pHigh + v.pHigh + (ret.pLow < pLow);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
u128 operator&(const u128& v) const {
|
constexpr u128 operator&(const u128& v) const {
|
||||||
return u128(pLow & v.pLow, pHigh & v.pHigh);
|
return u128(pLow & v.pLow, pHigh & v.pHigh);
|
||||||
}
|
}
|
||||||
|
|
||||||
u128 operator<<(u32 s) const {
|
constexpr u128 operator<<(u32 s) const {
|
||||||
if (s == 0) {
|
if (s == 0) {
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
@@ -52,7 +52,7 @@ class u128 {
|
|||||||
return u128(pLow << s, (pHigh << s) | (pLow >> (64 - s)));
|
return u128(pLow << s, (pHigh << s) | (pLow >> (64 - s)));
|
||||||
}
|
}
|
||||||
|
|
||||||
u128 operator>>(u32 s) const {
|
constexpr u128 operator>>(u32 s) const {
|
||||||
if (s == 0) {
|
if (s == 0) {
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
@@ -65,23 +65,23 @@ class u128 {
|
|||||||
return u128((pLow >> s) | (pHigh << (64 - s)), pHigh >> s);
|
return u128((pLow >> s) | (pHigh << (64 - s)), pHigh >> s);
|
||||||
}
|
}
|
||||||
|
|
||||||
u128& operator|=(const u128& v) {
|
constexpr u128& operator|=(const u128& v) {
|
||||||
pLow |= v.pLow;
|
pLow |= v.pLow;
|
||||||
pHigh |= v.pHigh;
|
pHigh |= v.pHigh;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
u128 operator|(const u128& v) const {
|
constexpr u128 operator|(const u128& v) const {
|
||||||
return u128(pLow | v.pLow, pHigh | v.pHigh);
|
return u128(pLow | v.pLow, pHigh | v.pHigh);
|
||||||
}
|
}
|
||||||
|
|
||||||
u128& operator&=(const u128& v) {
|
constexpr u128& operator&=(const u128& v) {
|
||||||
pLow &= v.pLow;
|
pLow &= v.pLow;
|
||||||
pHigh &= v.pHigh;
|
pHigh &= v.pHigh;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
u128 operator~() const { return u128(~pLow, ~pHigh); }
|
constexpr u128 operator~() const { return u128(~pLow, ~pHigh); }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Old why to make if checks possible
|
* Old why to make if checks possible
|
||||||
@@ -92,7 +92,7 @@ class u128 {
|
|||||||
// return pLow & v.pLow || pHigh & v.pHigh;
|
// return pLow & v.pLow || pHigh & v.pHigh;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
bool operator==(const u128& v) const {
|
constexpr bool operator==(const u128& v) const {
|
||||||
return pLow == v.pLow && pHigh == v.pHigh;
|
return pLow == v.pLow && pHigh == v.pHigh;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -100,12 +100,14 @@ class u128 {
|
|||||||
* Use explicit here to make sure it is only for checking and not for
|
* Use explicit here to make sure it is only for checking and not for
|
||||||
* some error leading implicit bool assignments...
|
* some error leading implicit bool assignments...
|
||||||
*/
|
*/
|
||||||
explicit operator bool() const { return pLow != 0 || pHigh != 0; }
|
constexpr explicit operator bool() const { return pLow != 0 || pHigh != 0; }
|
||||||
|
|
||||||
/** Deprecated way to handle `flag & SomeFlag` */
|
/** Deprecated way to handle `flag & SomeFlag` */
|
||||||
bool Has(const u128& v) const { return pLow & v.pLow || pHigh & v.pHigh; }
|
constexpr bool Has(const u128& v) const {
|
||||||
|
return pLow & v.pLow || pHigh & v.pHigh;
|
||||||
|
}
|
||||||
|
|
||||||
bool operator!=(const u128& v) const { return !(*this == v); }
|
constexpr bool operator!=(const u128& v) const { return !(*this == v); }
|
||||||
};
|
};
|
||||||
} // namespace PD
|
} // namespace PD
|
||||||
|
|
||||||
@@ -2,8 +2,7 @@
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
MIT License
|
MIT License
|
||||||
|
Copyright (c) 2024 - 2026 René Amthor (tobid7)
|
||||||
Copyright (c) 2024 - 2025 tobid7
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
@@ -24,7 +23,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|||||||
SOFTWARE.
|
SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <pd/core/common.hpp>
|
#include <pd/common.hpp>
|
||||||
#include <pd/core/vec2.hpp>
|
#include <pd/core/vec2.hpp>
|
||||||
#include <pd/core/vec3.hpp>
|
#include <pd/core/vec3.hpp>
|
||||||
#include <pd/core/vec4.hpp>
|
#include <pd/core/vec4.hpp>
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
MIT License
|
MIT License
|
||||||
Copyright (c) 2024 - 2025 René Amthor (tobid7)
|
Copyright (c) 2024 - 2026 René Amthor (tobid7)
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
@@ -25,7 +25,7 @@ SOFTWARE.
|
|||||||
|
|
||||||
// This file is generated by lazyvec 2.0.0
|
// This file is generated by lazyvec 2.0.0
|
||||||
|
|
||||||
#include <pd/core/common.hpp>
|
#include <pd/common.hpp>
|
||||||
|
|
||||||
namespace PD {
|
namespace PD {
|
||||||
template <typename T>
|
template <typename T>
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
MIT License
|
MIT License
|
||||||
Copyright (c) 2024 - 2025 René Amthor (tobid7)
|
Copyright (c) 2024 - 2026 René Amthor (tobid7)
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
@@ -25,7 +25,7 @@ SOFTWARE.
|
|||||||
|
|
||||||
// This file is generated by lazyvec 2.0.0
|
// This file is generated by lazyvec 2.0.0
|
||||||
|
|
||||||
#include <pd/core/common.hpp>
|
#include <pd/common.hpp>
|
||||||
// Extended includes (rename if you use other filenames/paths)
|
// Extended includes (rename if you use other filenames/paths)
|
||||||
#include <pd/core/vec2.hpp>
|
#include <pd/core/vec2.hpp>
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
MIT License
|
MIT License
|
||||||
Copyright (c) 2024 - 2025 René Amthor (tobid7)
|
Copyright (c) 2024 - 2026 René Amthor (tobid7)
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
@@ -25,7 +25,7 @@ SOFTWARE.
|
|||||||
|
|
||||||
// This file is generated by lazyvec 2.0.0
|
// This file is generated by lazyvec 2.0.0
|
||||||
|
|
||||||
#include <pd/core/common.hpp>
|
#include <pd/common.hpp>
|
||||||
// Extended includes (rename if you use other filenames/paths)
|
// Extended includes (rename if you use other filenames/paths)
|
||||||
#include <pd/core/vec2.hpp>
|
#include <pd/core/vec2.hpp>
|
||||||
#include <pd/core/vec3.hpp>
|
#include <pd/core/vec3.hpp>
|
||||||
|
|||||||
@@ -1,28 +1,4 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
/*
|
|
||||||
MIT License
|
|
||||||
Copyright (c) 2024 - 2025 René Amthor (tobid7)
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <pd/drivers/gfx.hpp>
|
#include <pd/drivers/gfx.hpp>
|
||||||
#include <pd/drivers/hid.hpp>
|
|
||||||
#include <pd/drivers/os.hpp>
|
#include <pd/drivers/os.hpp>
|
||||||
|
|||||||
@@ -1,114 +1,172 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
/*
|
#include <pd/core/mat.hpp>
|
||||||
MIT License
|
#include <pd/drivers/interface.hpp>
|
||||||
Copyright (c) 2024 - 2025 René Amthor (tobid7)
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <pd/core/core.hpp>
|
|
||||||
#include <pd/lithium/command.hpp>
|
#include <pd/lithium/command.hpp>
|
||||||
#include <pd/lithium/texture.hpp>
|
#include <pd/lithium/texture.hpp>
|
||||||
|
|
||||||
using LiBackendFlags = PD::u32;
|
using LiBackendFlags = PD::u32;
|
||||||
enum LiBackendFlags_ {
|
enum LiBackendFlags_ {
|
||||||
LiBackendFlags_None = 0,
|
LiBackendFlags_None = 0,
|
||||||
LiBackendFlags_FlipUV_Y = PD_BIT(0), // Essential for font loading
|
LiBackendFlags_FlipUV_Y = 1 << 0, // Essential for font loading
|
||||||
};
|
};
|
||||||
|
|
||||||
namespace PD {
|
namespace PD {
|
||||||
class GfxDriver {
|
|
||||||
|
// Pre interface class
|
||||||
|
class PD_API GfxDriver : public DriverInterface {
|
||||||
public:
|
public:
|
||||||
GfxDriver(const std::string& name = "NullGfx") : pName(name) {};
|
GfxDriver(std::string_view name);
|
||||||
~GfxDriver() = default;
|
virtual ~GfxDriver();
|
||||||
|
|
||||||
PD_SHARED(GfxDriver);
|
|
||||||
|
|
||||||
void PostInit();
|
|
||||||
|
|
||||||
virtual void Init() {}
|
virtual void Init() {}
|
||||||
virtual void Deinit() {}
|
virtual void Deinit() { SysDeinit(); }
|
||||||
virtual void NewFrame() {}
|
|
||||||
|
|
||||||
virtual void BindTex(Li::TexAddress addr) {}
|
void SetViewPort(const ivec2& size);
|
||||||
|
void SetViewPort(int x, int y);
|
||||||
virtual void RenderDrawData(const std::vector<Li::Command::Ref>& Commands) {}
|
virtual void BindTexture(TextureID id) {}
|
||||||
|
void Reset();
|
||||||
void SetViewPort(const ivec2& vp) { ViewPort = vp; }
|
virtual Li::Texture LoadTexture(
|
||||||
|
const std::vector<PD::u8>& pixels, int w, int h,
|
||||||
virtual Li::Texture::Ref LoadTex(
|
TextureFormat type = TextureFormat::RGBA32,
|
||||||
const std::vector<u8>& pixels, int w, int h,
|
TextureFilter filter = TextureFilter::Linear) {
|
||||||
Li::Texture::Type type = Li::Texture::Type::RGBA32,
|
return Li::Texture();
|
||||||
Li::Texture::Filter filter = Li::Texture::Filter::LINEAR) {
|
|
||||||
// Texture loading not supported (when this func not get override)
|
|
||||||
return nullptr;
|
|
||||||
}
|
}
|
||||||
|
virtual void DeleteTexture(const Li::Texture& tex) {}
|
||||||
|
virtual void Draw(const Pool<Li::Command>& commands) {}
|
||||||
|
Li::Texture::Ptr GetWhiteTexture() { return &pWhite; }
|
||||||
|
|
||||||
Li::Texture::Ref GetSolidTex() { return pSolid; }
|
protected:
|
||||||
|
virtual void SysDeinit() {}
|
||||||
|
virtual void SysInit() {}
|
||||||
|
virtual void SysReset() {}
|
||||||
|
virtual void Submit(size_t count, size_t start) {}
|
||||||
|
virtual void ResetPools() = 0;
|
||||||
|
void RegisterTexture(const Li::Texture& tex);
|
||||||
|
void UnregisterTexture(const Li::Texture& tex);
|
||||||
|
|
||||||
const std::string pName = "NullGfx";
|
// Counters
|
||||||
LiBackendFlags Flags = 0;
|
size_t CountDrawcalls = 0;
|
||||||
ivec2 ViewPort;
|
size_t CountCommands = 0;
|
||||||
Mat4 Projection;
|
size_t CountVertices = 0;
|
||||||
Li::Texture::Ref pSolid;
|
size_t CountIndices = 0;
|
||||||
size_t CurrentVertex = 0;
|
|
||||||
size_t CurrentIndex = 0;
|
size_t CurrentIndex = 0;
|
||||||
|
size_t CurrentVertex = 0;
|
||||||
/** Debug Variables */
|
TextureID CurrentTex = 0;
|
||||||
|
Mat4 Projection;
|
||||||
// Optional Index counter
|
ivec2 ViewPort;
|
||||||
u32 IndexCounter;
|
std::unordered_map<TextureID, Li::Texture> pTextureRegestry;
|
||||||
// Optional Vertex counter
|
Li::Texture pWhite;
|
||||||
u32 VertexCounter;
|
|
||||||
// Optional Frame Counter
|
|
||||||
u64 FrameCounter;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Static Gfx Controller */
|
struct DefaultGfxConfig {
|
||||||
class Gfx {
|
// Vertex Allocator
|
||||||
|
template <typename T>
|
||||||
|
using VertexAlloc = std::allocator<T>;
|
||||||
|
// Index Allocator
|
||||||
|
template <typename T>
|
||||||
|
using IndexAlloc = std::allocator<T>;
|
||||||
|
|
||||||
|
static constexpr size_t NumVertices = 32768; // 8192*4
|
||||||
|
static constexpr size_t NumIndices = 49152; // 8192*6
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename Config = DefaultGfxConfig>
|
||||||
|
class GfxDriverBase : public GfxDriver {
|
||||||
|
public:
|
||||||
|
using VtxPool =
|
||||||
|
Pool<Li::Vertex, typename Config::template VertexAlloc<Li::Vertex>>;
|
||||||
|
using IdxPool = Pool<u16, typename Config::template VertexAlloc<u16>>;
|
||||||
|
GfxDriverBase(std::string_view name = "Default") : GfxDriver(name) {}
|
||||||
|
virtual ~GfxDriverBase() {}
|
||||||
|
|
||||||
|
void Init() override {
|
||||||
|
// pVtxPool.Init(Config::NumVertices);
|
||||||
|
// pIdxPool.Init(Config::NumIndices);
|
||||||
|
SysInit();
|
||||||
|
std::vector<u8> img(16 * 16 * 4, 0xff);
|
||||||
|
pWhite = LoadTexture(img, 16, 16);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Draw(const Pool<Li::Command>& commands) override {
|
||||||
|
CountCommands += commands.size();
|
||||||
|
size_t index = 0;
|
||||||
|
while (index < commands.size()) {
|
||||||
|
CurrentTex = commands[index].Tex;
|
||||||
|
if (!CurrentTex) {
|
||||||
|
CurrentTex = pWhite.GetID();
|
||||||
|
}
|
||||||
|
size_t startidx = CurrentIndex;
|
||||||
|
while (index < commands.size() &&
|
||||||
|
(CurrentTex == commands[index].Tex ||
|
||||||
|
(CurrentTex == pWhite.GetID() && commands[index].Tex == 0))) {
|
||||||
|
const auto& c = commands[index];
|
||||||
|
CountVertices += c.VertexCount;
|
||||||
|
CountIndices += c.IndexCount;
|
||||||
|
auto pIdx = pIdxPool.Allocate(c.IndexCount);
|
||||||
|
auto pVtx = pVtxPool.Allocate(c.VertexCount);
|
||||||
|
for (size_t i = 0; i < c.IndexCount; i++) {
|
||||||
|
pIdx[i] = CurrentVertex + c.FirstIndex[i];
|
||||||
|
}
|
||||||
|
CurrentIndex += c.IndexCount;
|
||||||
|
CurrentVertex += c.VertexCount;
|
||||||
|
for (size_t i = 0; i < c.VertexCount; i++) {
|
||||||
|
pVtx[i] = c.FirstVertex[i];
|
||||||
|
}
|
||||||
|
index++;
|
||||||
|
}
|
||||||
|
Submit(CurrentIndex - startidx, startidx);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
u16* GetIndexBufPtr(size_t start) { return &pIdxPool[start]; }
|
||||||
|
Li::Vertex* GetVertexBufPtr(size_t start) { return &pVtxPool[start]; }
|
||||||
|
void ResetPools() override {
|
||||||
|
pVtxPool.Reset();
|
||||||
|
pIdxPool.Reset();
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
VtxPool pVtxPool;
|
||||||
|
IdxPool pIdxPool;
|
||||||
|
};
|
||||||
|
|
||||||
|
class PD_API Gfx {
|
||||||
public:
|
public:
|
||||||
Gfx() = default;
|
Gfx() = default;
|
||||||
~Gfx() = default;
|
~Gfx() = default;
|
||||||
|
|
||||||
static void Init(GfxDriver::Ref d);
|
template <typename T, typename... Args>
|
||||||
|
static void UseDriver(Args&&... args) {
|
||||||
static void Deinit() { pGfx->Deinit(); }
|
// assert(driver == nullptr && "OS Driver already set");
|
||||||
static void NewFrame() { pGfx->NewFrame(); }
|
driver = std::make_unique<T>(std::forward<Args>(args)...);
|
||||||
|
|
||||||
static void BindTex(Li::TexAddress addr) { pGfx->BindTex(addr); }
|
|
||||||
static void SetViewPort(const ivec2& vp) { pGfx->SetViewPort(vp); }
|
|
||||||
|
|
||||||
static void RenderDrawData(const std::vector<Li::Command::Ref>& Commands) {
|
|
||||||
pGfx->RenderDrawData(Commands);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static LiBackendFlags Flags() { return pGfx->Flags; }
|
static void Init() { driver->Init(); }
|
||||||
static Li::Texture::Ref LoadTex(
|
static void Deinit() { driver->Deinit(); }
|
||||||
const std::vector<u8>& pixels, int w, int h,
|
static void SetViewPort(const ivec2& vp) { driver->SetViewPort(vp); }
|
||||||
Li::Texture::Type type = Li::Texture::Type::RGBA32,
|
static void SetViewPort(int w, int h) { driver->SetViewPort(w, h); }
|
||||||
Li::Texture::Filter filter = Li::Texture::Filter::LINEAR) {
|
static void Reset() { driver->Reset(); }
|
||||||
return pGfx->LoadTex(pixels, w, h, type, filter);
|
static void Draw(const Pool<Li::Command>& commands) {
|
||||||
|
driver->Draw(commands);
|
||||||
|
}
|
||||||
|
static Li::Texture LoadTexture(const std::vector<PD::u8>& pixels, int w,
|
||||||
|
int h,
|
||||||
|
TextureFormat type = TextureFormat::RGBA32,
|
||||||
|
TextureFilter filter = TextureFilter::Linear) {
|
||||||
|
return driver->LoadTexture(pixels, w, h, type, filter);
|
||||||
|
}
|
||||||
|
static void DeleteTexture(const Li::Texture& tex) {
|
||||||
|
driver->DeleteTexture(tex);
|
||||||
|
}
|
||||||
|
static Li::Texture::Ptr GetWhiteTexture() {
|
||||||
|
return driver->GetWhiteTexture();
|
||||||
}
|
}
|
||||||
|
|
||||||
static Li::Texture::Ref GetSolidTex() { return pGfx->GetSolidTex(); }
|
static const char* GetDriverName() { return driver->GetName(); }
|
||||||
|
|
||||||
static GfxDriver::Ref pGfx;
|
private:
|
||||||
|
static std::unique_ptr<GfxDriver> driver;
|
||||||
};
|
};
|
||||||
} // namespace PD
|
} // namespace PD
|
||||||
@@ -1,296 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
/*
|
|
||||||
MIT License
|
|
||||||
Copyright (c) 2024 - 2025 René Amthor (tobid7)
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPHidE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <pd/core/core.hpp>
|
|
||||||
|
|
||||||
namespace PD {
|
|
||||||
/** Did not found a better solution yet sadly */
|
|
||||||
namespace HidKb {
|
|
||||||
// Lets use u128 here
|
|
||||||
using KbKey = u128;
|
|
||||||
constexpr static KbKey Kb_No = 0;
|
|
||||||
constexpr static KbKey Kb_Escape = KbKey::Flag(0);
|
|
||||||
constexpr static KbKey Kb_Q = KbKey::Flag(1);
|
|
||||||
constexpr static KbKey Kb_W = KbKey::Flag(2);
|
|
||||||
constexpr static KbKey Kb_E = KbKey::Flag(3);
|
|
||||||
constexpr static KbKey Kb_R = KbKey::Flag(4);
|
|
||||||
constexpr static KbKey Kb_T = KbKey::Flag(5);
|
|
||||||
constexpr static KbKey Kb_Z = KbKey::Flag(6);
|
|
||||||
constexpr static KbKey Kb_U = KbKey::Flag(7);
|
|
||||||
constexpr static KbKey Kb_I = KbKey::Flag(8);
|
|
||||||
constexpr static KbKey Kb_O = KbKey::Flag(9);
|
|
||||||
constexpr static KbKey Kb_P = KbKey::Flag(10);
|
|
||||||
constexpr static KbKey Kb_A = KbKey::Flag(11);
|
|
||||||
constexpr static KbKey Kb_S = KbKey::Flag(12);
|
|
||||||
constexpr static KbKey Kb_D = KbKey::Flag(13);
|
|
||||||
constexpr static KbKey Kb_F = KbKey::Flag(14);
|
|
||||||
constexpr static KbKey Kb_G = KbKey::Flag(15);
|
|
||||||
constexpr static KbKey Kb_H = KbKey::Flag(16);
|
|
||||||
constexpr static KbKey Kb_J = KbKey::Flag(17);
|
|
||||||
constexpr static KbKey Kb_K = KbKey::Flag(18);
|
|
||||||
constexpr static KbKey Kb_L = KbKey::Flag(19);
|
|
||||||
constexpr static KbKey Kb_Y = KbKey::Flag(20);
|
|
||||||
constexpr static KbKey Kb_X = KbKey::Flag(21);
|
|
||||||
constexpr static KbKey Kb_C = KbKey::Flag(22);
|
|
||||||
constexpr static KbKey Kb_V = KbKey::Flag(23);
|
|
||||||
constexpr static KbKey Kb_B = KbKey::Flag(24);
|
|
||||||
constexpr static KbKey Kb_N = KbKey::Flag(25);
|
|
||||||
constexpr static KbKey Kb_M = KbKey::Flag(26);
|
|
||||||
constexpr static KbKey Kb_1 = KbKey::Flag(27);
|
|
||||||
constexpr static KbKey Kb_2 = KbKey::Flag(28);
|
|
||||||
constexpr static KbKey Kb_3 = KbKey::Flag(29);
|
|
||||||
constexpr static KbKey Kb_4 = KbKey::Flag(30);
|
|
||||||
constexpr static KbKey Kb_5 = KbKey::Flag(31);
|
|
||||||
constexpr static KbKey Kb_6 = KbKey::Flag(32);
|
|
||||||
constexpr static KbKey Kb_7 = KbKey::Flag(33);
|
|
||||||
constexpr static KbKey Kb_8 = KbKey::Flag(34);
|
|
||||||
constexpr static KbKey Kb_9 = KbKey::Flag(35);
|
|
||||||
constexpr static KbKey Kb_0 = KbKey::Flag(36);
|
|
||||||
constexpr static KbKey Kb_F1 = KbKey::Flag(37);
|
|
||||||
constexpr static KbKey Kb_F2 = KbKey::Flag(38);
|
|
||||||
constexpr static KbKey Kb_F3 = KbKey::Flag(39);
|
|
||||||
constexpr static KbKey Kb_F4 = KbKey::Flag(40);
|
|
||||||
constexpr static KbKey Kb_F5 = KbKey::Flag(41);
|
|
||||||
constexpr static KbKey Kb_F6 = KbKey::Flag(42);
|
|
||||||
constexpr static KbKey Kb_F7 = KbKey::Flag(43);
|
|
||||||
constexpr static KbKey Kb_F8 = KbKey::Flag(44);
|
|
||||||
constexpr static KbKey Kb_F9 = KbKey::Flag(45);
|
|
||||||
constexpr static KbKey Kb_F10 = KbKey::Flag(46);
|
|
||||||
constexpr static KbKey Kb_F11 = KbKey::Flag(47);
|
|
||||||
constexpr static KbKey Kb_F12 = KbKey::Flag(48);
|
|
||||||
constexpr static KbKey Kb_MouseLeft = KbKey::Flag(120);
|
|
||||||
} // namespace HidKb
|
|
||||||
class HidDriver {
|
|
||||||
public:
|
|
||||||
enum Flags : u32 {
|
|
||||||
Flags_None = 0,
|
|
||||||
FLags_HasGamepad = 1 << 0,
|
|
||||||
Flags_HasKeyboard = 1 << 1,
|
|
||||||
Flags_HasTouch = 1 << 2,
|
|
||||||
Flags_HasMouse = 1 << 3,
|
|
||||||
};
|
|
||||||
// Todo: Name to GpKey (GamepadKey)
|
|
||||||
/** Key [Controller] */
|
|
||||||
enum Key : u32 {
|
|
||||||
No = 0, ///< No Key
|
|
||||||
A = 1 << 0, ///< A
|
|
||||||
B = 1 << 1, ///< B
|
|
||||||
X = 1 << 2, ///< X
|
|
||||||
Y = 1 << 3, ///< Y
|
|
||||||
Start = 1 << 4, ///< Start
|
|
||||||
Select = 1 << 5, ///< Select
|
|
||||||
L = 1 << 6, ///< L
|
|
||||||
R = 1 << 7, ///< R
|
|
||||||
DUp = 1 << 8, ///< Dpad Up
|
|
||||||
DDown = 1 << 9, ///< Dpad down
|
|
||||||
DLeft = 1 << 10, ///< Dpad left
|
|
||||||
DRight = 1 << 11, ///< Dpad right
|
|
||||||
CPUp = 1 << 12, ///< Cpad up
|
|
||||||
CPDown = 1 << 13, ///< cpad down
|
|
||||||
CPLeft = 1 << 14, ///< cpad left
|
|
||||||
CPRight = 1 << 15, ///< Cpad right
|
|
||||||
CSUp = 1 << 16, ///< Cstick up
|
|
||||||
CSDown = 1 << 17, ///< cstick down
|
|
||||||
CSLeft = 1 << 18, ///< cstick left
|
|
||||||
CSRight = 1 << 19, ///< cstick right
|
|
||||||
ZL = 1 << 20, ///< ZL
|
|
||||||
ZR = 1 << 21, ///< ZR
|
|
||||||
Touch = 1 << 22, ///< Touch
|
|
||||||
Up = DUp | CPUp, ///< DPad or CPad Up
|
|
||||||
Down = DDown | CPDown, ///< DPad or CPad Down
|
|
||||||
Left = DLeft | CPLeft, ///< DPad or CPad Left
|
|
||||||
Right = DRight | CPRight, ///< DPad or CPad Right
|
|
||||||
};
|
|
||||||
|
|
||||||
using KbKey = HidKb::KbKey;
|
|
||||||
|
|
||||||
/** Event */
|
|
||||||
enum Event {
|
|
||||||
Event_Null,
|
|
||||||
Event_Down, ///< Key Pressed
|
|
||||||
Event_Held, ///< Key Held
|
|
||||||
Event_Up, ///< Key released
|
|
||||||
};
|
|
||||||
|
|
||||||
HidDriver(const std::string& name = "NullHid") : pName(name) {};
|
|
||||||
virtual ~HidDriver() = default;
|
|
||||||
PD_SHARED(HidDriver);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get Mouse Position
|
|
||||||
* @return Mouse pos
|
|
||||||
*/
|
|
||||||
fvec2 MousePos() const {
|
|
||||||
return pMouse[0];
|
|
||||||
} /**
|
|
||||||
* Get Last Mouse Position (from last frame)
|
|
||||||
* @return Mouse pos
|
|
||||||
*/
|
|
||||||
fvec2 MousePosLast() const { return pMouse[1]; }
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Check for a Button Event
|
|
||||||
* @param e Event Type
|
|
||||||
* @param keys Keys to check for
|
|
||||||
* @return if key(s) doing the requiested event
|
|
||||||
*/
|
|
||||||
bool IsEvent(Event e, Key keys);
|
|
||||||
bool IsEvent(Event e, KbKey key);
|
|
||||||
/**
|
|
||||||
* Check for Key Press Event
|
|
||||||
* @param keys set of keys
|
|
||||||
* @return true if key is pressed
|
|
||||||
*/
|
|
||||||
bool IsDown(Key keys) const { return KeyEvents[0].at(Event_Down) & keys; }
|
|
||||||
/**
|
|
||||||
* Check for Key Held Event
|
|
||||||
* @param keys set of keys
|
|
||||||
* @return true if key is held
|
|
||||||
*/
|
|
||||||
bool IsHeld(Key keys) const { return KeyEvents[0].at(Event_Held) & keys; }
|
|
||||||
/**
|
|
||||||
* Check for Key Release Event
|
|
||||||
* @param keys set of keys
|
|
||||||
* @return true if key is released
|
|
||||||
*/
|
|
||||||
bool IsUp(Key keys) const { return KeyEvents[0].at(Event_Up) & keys; }
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sett all keyevents to 0
|
|
||||||
*/
|
|
||||||
void Clear() {
|
|
||||||
for (int i = 0; i < 2; i++) {
|
|
||||||
KeyEvents[i][Event_Down] = 0;
|
|
||||||
KeyEvents[i][Event_Up] = 0;
|
|
||||||
KeyEvents[i][Event_Held] = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Lock input driver
|
|
||||||
* @param v lock or not lock
|
|
||||||
*/
|
|
||||||
void Lock(bool v) {
|
|
||||||
if (v != pLocked) {
|
|
||||||
SwapTab();
|
|
||||||
}
|
|
||||||
pLocked = v;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Check if Driver is locked
|
|
||||||
* @return true if locked
|
|
||||||
*/
|
|
||||||
bool Locked() const { return pLocked; }
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Lock Input Driver
|
|
||||||
*/
|
|
||||||
void Lock() {
|
|
||||||
if (!pLocked) {
|
|
||||||
SwapTab();
|
|
||||||
}
|
|
||||||
pLocked = true;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* Unlock Input Driver
|
|
||||||
*/
|
|
||||||
void Unlock() {
|
|
||||||
if (pLocked) {
|
|
||||||
SwapTab();
|
|
||||||
}
|
|
||||||
pLocked = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Template Update Function for a device specific driver
|
|
||||||
*/
|
|
||||||
virtual void Update();
|
|
||||||
/**
|
|
||||||
* Get Text from Keyboard
|
|
||||||
*/
|
|
||||||
virtual void GetInputStr(std::string& str) {}
|
|
||||||
|
|
||||||
/** Data Section */
|
|
||||||
|
|
||||||
/** Backend Identification Name */
|
|
||||||
const std::string pName;
|
|
||||||
|
|
||||||
/** Flags */
|
|
||||||
u32 Flags = 0;
|
|
||||||
|
|
||||||
/** Key Binds Map */
|
|
||||||
std::unordered_map<u32, u32> pBinds;
|
|
||||||
std::unordered_map<u128, u128> pKbBinds;
|
|
||||||
/** Swap Tabe Function */
|
|
||||||
void SwapTab();
|
|
||||||
/** Using 2 Positions for Current and Last */
|
|
||||||
fvec2 pMouse[2];
|
|
||||||
/** Lock State */
|
|
||||||
bool pLocked = false;
|
|
||||||
/** Key Event Table Setup */
|
|
||||||
std::unordered_map<Event, u32> KeyEvents[2];
|
|
||||||
/** Keyboard Key Event Table Setup */
|
|
||||||
std::unordered_map<Event, u128> KbKeyEvents[2];
|
|
||||||
};
|
|
||||||
|
|
||||||
/** Static Hid Controller */
|
|
||||||
class Hid {
|
|
||||||
public:
|
|
||||||
Hid() = default;
|
|
||||||
~Hid() = default;
|
|
||||||
|
|
||||||
/** Referenec to Drivers enums */
|
|
||||||
using Key = HidDriver::Key;
|
|
||||||
using KbKey = HidKb::KbKey;
|
|
||||||
using Event = HidDriver::Event;
|
|
||||||
|
|
||||||
static void Init(HidDriver::Ref v = nullptr) {
|
|
||||||
if (v) {
|
|
||||||
pHid = v;
|
|
||||||
} else {
|
|
||||||
pHid = HidDriver::New();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool IsEvent(Event e, Key keys) { return pHid->IsEvent(e, keys); }
|
|
||||||
static bool IsEvent(Event e, KbKey key) { return pHid->IsEvent(e, key); }
|
|
||||||
static bool IsDown(Key keys) { return pHid->IsDown(keys); }
|
|
||||||
static bool IsUp(Key keys) { return pHid->IsUp(keys); }
|
|
||||||
static bool IsHeld(Key keys) { return pHid->IsHeld(keys); }
|
|
||||||
static fvec2 MousePos() { return pHid->MousePos(); }
|
|
||||||
static fvec2 MousePosLast() { return pHid->MousePosLast(); }
|
|
||||||
static void Clear() { pHid->Clear(); }
|
|
||||||
static void Lock() { pHid->Lock(); }
|
|
||||||
static void Lock(bool v) { pHid->Lock(v); }
|
|
||||||
static void Unlock() { pHid->Unlock(); }
|
|
||||||
static bool Locked() { return pHid->Locked(); }
|
|
||||||
static void Update() { pHid->Update(); }
|
|
||||||
static u32 GetFlags() { return pHid->Flags; }
|
|
||||||
static void GetStrInput(std::string& str) { pHid->GetInputStr(str); }
|
|
||||||
|
|
||||||
static HidDriver::Ref pHid;
|
|
||||||
};
|
|
||||||
} // namespace PD
|
|
||||||
16
include/pd/drivers/interface.hpp
Normal file
16
include/pd/drivers/interface.hpp
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <pd/common.hpp>
|
||||||
|
|
||||||
|
namespace PD {
|
||||||
|
class DriverInterface {
|
||||||
|
public:
|
||||||
|
DriverInterface(const std::string_view& name) : pName(name) {}
|
||||||
|
virtual ~DriverInterface() {}
|
||||||
|
|
||||||
|
const char* GetName() const { return pName.data(); }
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::string_view pName;
|
||||||
|
};
|
||||||
|
} // namespace PD
|
||||||
@@ -1,71 +1,32 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
/*
|
#include <pd/drivers/interface.hpp>
|
||||||
MIT License
|
|
||||||
Copyright (c) 2024 - 2025 René Amthor (tobid7)
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <pd/core/common.hpp>
|
|
||||||
#include <pd/core/timetrace.hpp>
|
|
||||||
|
|
||||||
namespace PD {
|
namespace PD {
|
||||||
using TraceMap = std::map<std::string, TT::Res::Ref>;
|
class PD_API OsDriver : public DriverInterface {
|
||||||
|
|
||||||
class OsDriver {
|
|
||||||
public:
|
public:
|
||||||
OsDriver() = default;
|
OsDriver(std::string_view name = "Default") : DriverInterface(name) {}
|
||||||
virtual ~OsDriver() = default;
|
virtual ~OsDriver() {}
|
||||||
PD_SHARED(OsDriver);
|
|
||||||
|
|
||||||
virtual u64 GetTime();
|
virtual u64 GetTime() const;
|
||||||
virtual u64 GetNanoTime();
|
virtual u64 GetTimeNano() const;
|
||||||
TraceMap& GetTraceMap();
|
|
||||||
TT::Res::Ref& GetTraceRef(const std::string& id);
|
|
||||||
bool TraceExist(const std::string& id);
|
|
||||||
|
|
||||||
TraceMap pTraces;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Static Os Controller */
|
class PD_API Os {
|
||||||
class OS {
|
|
||||||
public:
|
public:
|
||||||
OS() = default;
|
Os() = default;
|
||||||
~OS() = default;
|
~Os() = default;
|
||||||
|
|
||||||
static void Init(OsDriver::Ref v = nullptr) {
|
template <typename T, typename... Args>
|
||||||
if (v) {
|
static void UseDriver(Args&&... args) {
|
||||||
pOs = v;
|
// assert(driver == nullptr && "OS Driver already set");
|
||||||
} else {
|
driver = std::make_unique<T>(std::forward<Args>(args)...);
|
||||||
pOs = OsDriver::New();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static u64 GetTime() { return pOs->GetTime(); }
|
static u64 GetTime() { return driver->GetTime(); }
|
||||||
static u64 GetNanoTime() { return pOs->GetNanoTime(); }
|
static u64 GetTimeNano() { return driver->GetTimeNano(); }
|
||||||
static TraceMap& GetTraceMap() { return pOs->GetTraceMap(); }
|
|
||||||
static TT::Res::Ref& GetTraceRef(const std::string& id) {
|
|
||||||
return pOs->GetTraceRef(id);
|
|
||||||
}
|
|
||||||
static bool TraceExist(const std::string& id) { return pOs->TraceExist(id); }
|
|
||||||
|
|
||||||
static OsDriver::Ref pOs;
|
private:
|
||||||
|
static std::unique_ptr<OsDriver> driver;
|
||||||
};
|
};
|
||||||
} // namespace PD
|
} // namespace PD
|
||||||
@@ -1,26 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
/*
|
|
||||||
MIT License
|
|
||||||
Copyright (c) 2024 - 2025 René Amthor (tobid7)
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#define PD_DEF_EXP(x, y) x y = nullptr
|
|
||||||
24962
include/pd/external/json.hpp
vendored
24962
include/pd/external/json.hpp
vendored
File diff suppressed because it is too large
Load Diff
7988
include/pd/external/stb_image.h
vendored
7988
include/pd/external/stb_image.h
vendored
File diff suppressed because it is too large
Load Diff
5079
include/pd/external/stb_truetype.h
vendored
5079
include/pd/external/stb_truetype.h
vendored
File diff suppressed because it is too large
Load Diff
@@ -1,88 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
/*
|
|
||||||
MIT License
|
|
||||||
|
|
||||||
Copyright (c) 2024 - 2025 tobid7
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <pd/core/core.hpp>
|
|
||||||
#include <pd/image/pd_p_api.hpp>
|
|
||||||
|
|
||||||
namespace PD {
|
|
||||||
class PD_IMAGE_API Image {
|
|
||||||
public:
|
|
||||||
enum Format {
|
|
||||||
RGBA, // bpp == 4
|
|
||||||
RGB, // bpp == 3
|
|
||||||
RGB565, // bpp == 2 (not supported in laoding)
|
|
||||||
BGR, // bpp == 3
|
|
||||||
ABGR, // bpp == 4
|
|
||||||
BGRA, // bpp == 4
|
|
||||||
};
|
|
||||||
Image() = default;
|
|
||||||
Image(const std::string& path) { this->Load(path); }
|
|
||||||
Image(const std::vector<u8>& buf) { this->Load(buf); }
|
|
||||||
Image(const std::vector<u8>& buf, int w, int h, int bpp = 4) {
|
|
||||||
this->Copy(buf, w, h, bpp);
|
|
||||||
}
|
|
||||||
~Image() = default;
|
|
||||||
|
|
||||||
PD_SHARED(Image)
|
|
||||||
|
|
||||||
void Load(const std::string& path);
|
|
||||||
void Load(const std::vector<u8>& buf);
|
|
||||||
void Copy(const std::vector<u8>& buf, int w, int h, int bpp = 4);
|
|
||||||
|
|
||||||
std::vector<PD::u8>& GetBuffer() { return pBuffer; }
|
|
||||||
std::vector<PD::u8> GetBuffer() const { return pBuffer; }
|
|
||||||
|
|
||||||
int Width() const { return pWidth; }
|
|
||||||
int Height() const { return pHeight; }
|
|
||||||
Format Fmt() const { return pFmt; }
|
|
||||||
|
|
||||||
void FlipVertical();
|
|
||||||
void FlipHorizontal();
|
|
||||||
|
|
||||||
u8& operator[](int idx) { return pBuffer[idx]; }
|
|
||||||
u8 operator[](int idx) const { return pBuffer[idx]; }
|
|
||||||
|
|
||||||
// Probably these make th eabove ones useless
|
|
||||||
|
|
||||||
operator std::vector<PD::u8>&() { return pBuffer; }
|
|
||||||
operator std::vector<PD::u8>() const { return pBuffer; }
|
|
||||||
|
|
||||||
static void Convert(Image::Ref img, Image::Format dst);
|
|
||||||
static void ReTile(Image::Ref img,
|
|
||||||
std::function<u32(int x, int y, int w)> src,
|
|
||||||
std::function<u32(int x, int y, int w)> dst);
|
|
||||||
static int Fmt2Bpp(Format fmt);
|
|
||||||
|
|
||||||
std::vector<PD::u8> pBuffer;
|
|
||||||
int pWidth;
|
|
||||||
int pHeight;
|
|
||||||
Format pFmt = Format::RGBA;
|
|
||||||
|
|
||||||
private:
|
|
||||||
/** Leftover variable used for stbi_load */
|
|
||||||
int fmt = 0;
|
|
||||||
};
|
|
||||||
} // namespace PD
|
|
||||||
@@ -1,72 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
/*
|
|
||||||
MIT License
|
|
||||||
|
|
||||||
Copyright (c) 2024 - 2025 tobid7
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <pd/core/core.hpp>
|
|
||||||
#include <pd/image/pd_p_api.hpp>
|
|
||||||
|
|
||||||
namespace PD {
|
|
||||||
/**
|
|
||||||
* Namepace containing functions to blur images
|
|
||||||
*/
|
|
||||||
namespace ImgBlur {
|
|
||||||
/**
|
|
||||||
* Function to create Gaussian Kernel List
|
|
||||||
* @param radius Rasius to use
|
|
||||||
* @param si sigma value to use
|
|
||||||
* @return list of kernel values
|
|
||||||
*/
|
|
||||||
PD_IMAGE_API std::vector<float> GaussianKernel(int radius, float si);
|
|
||||||
/**
|
|
||||||
* Gaussian Blur for basic Image Buffer
|
|
||||||
* @param buf Image Buffer (unsigned char)
|
|
||||||
* @param w width of the image
|
|
||||||
* @param h width of the image
|
|
||||||
* @param radius Blur radius
|
|
||||||
* @param si Blur sigma
|
|
||||||
* @param idxfn Indexing function
|
|
||||||
*/
|
|
||||||
PD_IMAGE_API void GaussianBlur(
|
|
||||||
std::vector<u8> &buf, int w, int h, float radius, float si,
|
|
||||||
std::function<int(int, int, int)> idxfn = [](int x, int y, int w) -> int {
|
|
||||||
return y * w + x;
|
|
||||||
});
|
|
||||||
/**
|
|
||||||
* Advanced func to access memory directly
|
|
||||||
* @param buf Referenvce to the buffer
|
|
||||||
* @param w width of the image
|
|
||||||
* @param h width of the image
|
|
||||||
* @param bpp Bytes per Pixels (RGB[A], RGB565, etc)
|
|
||||||
* @param radius Blur radius
|
|
||||||
* @param si Blur sigma
|
|
||||||
* @param idxfn Indexing function
|
|
||||||
*/
|
|
||||||
PD_IMAGE_API void GaussianBlur(
|
|
||||||
void *buf, int w, int h, int bpp, float radius, float si,
|
|
||||||
std::function<int(int, int, int)> idxfn = [](int x, int y, int w) -> int {
|
|
||||||
return y * w + x;
|
|
||||||
});
|
|
||||||
} // namespace ImgBlur
|
|
||||||
} // namespace PD
|
|
||||||
@@ -1,82 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
/*
|
|
||||||
MIT License
|
|
||||||
|
|
||||||
Copyright (c) 2024 - 2025 tobid7
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <pd/core/core.hpp>
|
|
||||||
#include <pd/image/image.hpp>
|
|
||||||
#include <pd/image/pd_p_api.hpp>
|
|
||||||
|
|
||||||
namespace PD {
|
|
||||||
/**
|
|
||||||
* Namespace containing function to convert images
|
|
||||||
*/
|
|
||||||
namespace ImgConvert {
|
|
||||||
/**
|
|
||||||
* Convert RGB24 to RGBA32 by adding a 4th alpha value set to 255
|
|
||||||
* to every pixel
|
|
||||||
* @param out Result List
|
|
||||||
* @param in Input Buffer List (rgb24)
|
|
||||||
* @param w width of the image
|
|
||||||
* @param h height of the image
|
|
||||||
*/
|
|
||||||
PD_IMAGE_API
|
|
||||||
void RGB24toRGBA32(std::vector<PD::u8> &out, const std::vector<u8> &in,
|
|
||||||
const int &w, const int &h);
|
|
||||||
PD_IMAGE_API
|
|
||||||
void RGB32toRGBA24(std::vector<u8> &out, const std::vector<u8> &in,
|
|
||||||
const int &w, const int &h);
|
|
||||||
/**
|
|
||||||
* Reverse 32 (RGBA -> ABGR || ABGR -> RGBA)
|
|
||||||
* @param buf Buffer to convert
|
|
||||||
* @param w width
|
|
||||||
* @param h height
|
|
||||||
*/
|
|
||||||
PD_IMAGE_API void Reverse32(std::vector<u8> &buf, const int &w, const int &h);
|
|
||||||
PD_IMAGE_API void ReverseBuf(std::vector<u8> &buf, size_t bpp, int w, int h);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Convert RGB24 to RGBA32 by adding a 4th alpha value set to 255
|
|
||||||
* to every pixel
|
|
||||||
* @param out Result List
|
|
||||||
* @param in Input Buffer List (rgb24)
|
|
||||||
* @param w width of the image
|
|
||||||
* @param h height of the image
|
|
||||||
*/
|
|
||||||
PD_IMAGE_API
|
|
||||||
void RGB24toRGBA32(PD::Vec<u8> &out, const PD::Vec<u8> &in, const int &w,
|
|
||||||
const int &h);
|
|
||||||
PD_IMAGE_API
|
|
||||||
void RGB32toRGBA24(PD::Vec<u8> &out, const PD::Vec<u8> &in, const int &w,
|
|
||||||
const int &h);
|
|
||||||
/**
|
|
||||||
* Reverse 32 (RGBA -> ABGR || ABGR -> RGBA)
|
|
||||||
* @param buf Buffer to convert
|
|
||||||
* @param w width
|
|
||||||
* @param h height
|
|
||||||
*/
|
|
||||||
PD_IMAGE_API void Reverse32(PD::Vec<u8> &buf, const int &w, const int &h);
|
|
||||||
PD_IMAGE_API void ReverseBuf(PD::Vec<u8> &buf, size_t bpp, int w, int h);
|
|
||||||
} // namespace ImgConvert
|
|
||||||
} // namespace PD
|
|
||||||
@@ -1,51 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
/*
|
|
||||||
MIT License
|
|
||||||
Copyright (c) 2024 - 2025 René Amthor (tobid7)
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/** Generated with ppam */
|
|
||||||
|
|
||||||
#ifdef _WIN32 // Windows (MSVC Tested)
|
|
||||||
#ifdef PD_IMAGE_BUILD_SHARED
|
|
||||||
#define PD_IMAGE_API __declspec(dllexport)
|
|
||||||
#else
|
|
||||||
#define PD_IMAGE_API __declspec(dllimport)
|
|
||||||
#endif
|
|
||||||
#elif defined(__APPLE__) // macOS (untested yet)
|
|
||||||
#ifdef PD_IMAGE_BUILD_SHARED
|
|
||||||
#define PD_IMAGE_API __attribute__((visibility("default")))
|
|
||||||
#else
|
|
||||||
#define PD_IMAGE_API
|
|
||||||
#endif
|
|
||||||
#elif defined(__linux__) // Linux (untested yet)
|
|
||||||
#ifdef PD_IMAGE_BUILD_SHARED
|
|
||||||
#define PD_IMAGE_API __attribute__((visibility("default")))
|
|
||||||
#else
|
|
||||||
#define PD_IMAGE_API
|
|
||||||
#endif
|
|
||||||
#elif defined(__3DS__) // 3ds Specific
|
|
||||||
// Only Static supported
|
|
||||||
#define PD_IMAGE_API
|
|
||||||
#else
|
|
||||||
#define PD_IMAGE_API
|
|
||||||
#endif
|
|
||||||
25
include/pd/lithium/atlas.hpp
Normal file
25
include/pd/lithium/atlas.hpp
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <pd/core/core.hpp>
|
||||||
|
#include <pd/lithium/texture.hpp>
|
||||||
|
|
||||||
|
namespace PD {
|
||||||
|
namespace Li {
|
||||||
|
enum class AtlasState {
|
||||||
|
Invalid,
|
||||||
|
ReqCreate,
|
||||||
|
ReqUpdate,
|
||||||
|
ReqDestroy,
|
||||||
|
};
|
||||||
|
|
||||||
|
class Atlas {
|
||||||
|
public:
|
||||||
|
Atlas() {}
|
||||||
|
~Atlas() {}
|
||||||
|
|
||||||
|
private:
|
||||||
|
AtlasState pState = AtlasState::Invalid;
|
||||||
|
TextureID pID;
|
||||||
|
};
|
||||||
|
} // namespace Li
|
||||||
|
} // namespace PD
|
||||||
87
include/pd/lithium/command.hpp
Executable file → Normal file
87
include/pd/lithium/command.hpp
Executable file → Normal file
@@ -1,58 +1,61 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
/*
|
#include <cstddef>
|
||||||
MIT License
|
#include <pd/core/pool.hpp>
|
||||||
Copyright (c) 2024 - 2025 René Amthor (tobid7)
|
#include <pd/lithium/pools.hpp>
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <pd/core/core.hpp>
|
|
||||||
#include <pd/lithium/texture.hpp>
|
|
||||||
#include <pd/lithium/vertex.hpp>
|
#include <pd/lithium/vertex.hpp>
|
||||||
|
|
||||||
namespace PD {
|
namespace PD {
|
||||||
namespace Li {
|
namespace Li {
|
||||||
class Command {
|
class Command {
|
||||||
public:
|
public:
|
||||||
Command() = default;
|
Command() { Reset(); }
|
||||||
~Command() = default;
|
~Command() {}
|
||||||
|
|
||||||
PD_UNIQUE(Command);
|
void Reserve(size_t vtx, size_t idx) {
|
||||||
|
if (!FirstVertex)
|
||||||
|
FirstVertex = AllocateVertices(vtx);
|
||||||
|
else
|
||||||
|
AllocateVertices(vtx);
|
||||||
|
if (!FirstIndex)
|
||||||
|
FirstIndex = AllocateIndices(idx);
|
||||||
|
else
|
||||||
|
AllocateIndices(idx);
|
||||||
|
}
|
||||||
|
|
||||||
Command& AddIdx(const u16& idx) {
|
void Reset() {
|
||||||
IndexBuffer.Add(VertexBuffer.Size() + idx);
|
Layer = 0;
|
||||||
|
Tex = 0;
|
||||||
|
FirstIndex = nullptr;
|
||||||
|
FirstVertex = nullptr;
|
||||||
|
IndexCount = 0;
|
||||||
|
VertexCount = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
Command& Add(const Vertex& vtx) {
|
||||||
|
FirstVertex[VertexCount++] = vtx;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
Command& Add(u16 idx) {
|
||||||
|
FirstIndex[IndexCount++] = VertexCount + idx;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
Command& Add(u16 a, u16 b, u16 c) {
|
||||||
|
FirstIndex[IndexCount++] = VertexCount + a;
|
||||||
|
FirstIndex[IndexCount++] = VertexCount + b;
|
||||||
|
FirstIndex[IndexCount++] = VertexCount + c;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
Command& AddVtx(const Vertex& v) {
|
int Layer = 0;
|
||||||
VertexBuffer.Add(std::move(v));
|
ptr Tex = 0;
|
||||||
return *this;
|
Vertex* FirstVertex = nullptr;
|
||||||
}
|
u16* FirstIndex = nullptr;
|
||||||
|
size_t VertexCount = 0;
|
||||||
PD::Vec<Vertex> VertexBuffer;
|
size_t IndexCount = 0;
|
||||||
PD::Vec<u16> IndexBuffer;
|
// Todo: implement
|
||||||
ivec4 ScissorRect;
|
size_t VertexCountMax = 0;
|
||||||
bool ScissorOn = false;
|
size_t IndexCountMax = 0;
|
||||||
int Layer;
|
|
||||||
int Index;
|
|
||||||
Texture::Ref Tex;
|
|
||||||
};
|
};
|
||||||
} // namespace Li
|
} // namespace Li
|
||||||
} // namespace PD
|
} // namespace PD
|
||||||
251
include/pd/lithium/drawlist.hpp
Executable file → Normal file
251
include/pd/lithium/drawlist.hpp
Executable file → Normal file
@@ -1,201 +1,116 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
/*
|
|
||||||
MIT License
|
|
||||||
|
|
||||||
Copyright (c) 2024 - 2025 tobid7
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <pd/lithium/command.hpp>
|
#include <pd/lithium/command.hpp>
|
||||||
#include <pd/lithium/font.hpp>
|
#include <pd/lithium/texture.hpp>
|
||||||
#include <pd/lithium/pd_p_api.hpp>
|
|
||||||
|
|
||||||
/** Path Rect Flags */
|
|
||||||
using LiPathRectFlags = PD::u32;
|
using LiPathRectFlags = PD::u32;
|
||||||
|
|
||||||
/** Setup for everything (oder so) */
|
|
||||||
enum LiPathRectFlags_ : PD::u32 {
|
enum LiPathRectFlags_ : PD::u32 {
|
||||||
LiPathRectFlags_None = 0,
|
LiPathRectFlags_None = 0,
|
||||||
LiPathRectFlags_KeepTopLeft = PD_BIT(0),
|
LiPathRectFlags_KeepTopLeft = 1 << 0,
|
||||||
LiPathRectFlags_KeepTopRight = PD_BIT(1),
|
LiPathRectFlags_KeepTopRight = 1 << 1,
|
||||||
LiPathRectFlags_KeepBotRight = PD_BIT(2),
|
LiPathRectFlags_KeepBotRight = 1 << 2,
|
||||||
LiPathRectFlags_KeepBotLeft = PD_BIT(3),
|
LiPathRectFlags_KeepBotLeft = 1 << 3,
|
||||||
LiPathRectFlags_KeepTop = PD_BIT(0) | PD_BIT(1),
|
LiPathRectFlags_KeepTop =
|
||||||
LiPathRectFlags_KeepBot = PD_BIT(2) | PD_BIT(3),
|
LiPathRectFlags_KeepTopLeft | LiPathRectFlags_KeepTopRight,
|
||||||
LiPathRectFlags_KeepLeft = PD_BIT(0) | PD_BIT(3),
|
LiPathRectFlags_KeepBot =
|
||||||
LiPathRectFlags_KeepRight = PD_BIT(1) | PD_BIT(2),
|
LiPathRectFlags_KeepBotLeft | LiPathRectFlags_KeepBotRight,
|
||||||
|
LiPathRectFlags_KeepLeft =
|
||||||
|
LiPathRectFlags_KeepTopLeft | LiPathRectFlags_KeepBotLeft,
|
||||||
|
LiPathRectFlags_KeepRight =
|
||||||
|
LiPathRectFlags_KeepTopRight | LiPathRectFlags_KeepBotRight,
|
||||||
|
};
|
||||||
|
|
||||||
|
using LiDrawFlags = PD::u32;
|
||||||
|
enum LiDrawFlags_ : PD::u32 {
|
||||||
|
LiDrawFlags_None = 0,
|
||||||
|
LiDrawFlags_Close = 1 << 0,
|
||||||
|
};
|
||||||
|
|
||||||
|
using LiTextFlags = PD::u32;
|
||||||
|
enum LiTextFlags_ : PD::u32 {
|
||||||
|
LiTextFlags_None = 0, ///< Do nothing
|
||||||
|
LiTextFlags_AlignRight = 1 << 0, ///< Align Right of position
|
||||||
|
LiTextFlags_AlignMid = 1 << 1, ///< Align in the middle of pos and box
|
||||||
|
LiTextFlags_Shaddow = 1 << 2, ///< Draws the text twice to create shaddow
|
||||||
|
LiTextFlags_Wrap = 1 << 3, ///< Wrap Text: May be runs better with TMS
|
||||||
|
LiTextFlags_Short = 1 << 4, ///< Short Text: May be runs better with TMS
|
||||||
|
LiTextFlags_Scroll = 1 << 5, ///< Not implemented [scoll text if to long]
|
||||||
|
LiTextFlags_NoOOS = 1 << 6, ///< No Out of Screen Rendering
|
||||||
};
|
};
|
||||||
|
|
||||||
namespace PD {
|
namespace PD {
|
||||||
namespace Li {
|
namespace Li {
|
||||||
class PD_LITHIUM_API DrawList {
|
class PD_API Drawlist {
|
||||||
public:
|
public:
|
||||||
DrawList() { DrawSolid(); }
|
Drawlist();
|
||||||
~DrawList() { pDrawList.clear(); }
|
~Drawlist();
|
||||||
|
|
||||||
/** Require Copy and Move Constructors */
|
/** Baisc */
|
||||||
|
|
||||||
DrawList(const DrawList&) = delete;
|
void Merge(Drawlist& other);
|
||||||
DrawList& operator=(const DrawList&) = delete;
|
void Copy(Drawlist& other);
|
||||||
|
void Optimize();
|
||||||
DrawList(DrawList&&) noexcept = default;
|
|
||||||
DrawList& operator=(DrawList&&) noexcept = default;
|
|
||||||
|
|
||||||
PD_SHARED(DrawList);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Append an input drawlist on top of this one
|
|
||||||
* This Function will clear the Input list to make sure
|
|
||||||
* THat the moved memory blocks don't get used
|
|
||||||
* @param list DrawList to move into current
|
|
||||||
*/
|
|
||||||
void Merge(DrawList::Ref list);
|
|
||||||
|
|
||||||
Command::Ref PreGenerateCmd();
|
|
||||||
void AddCommand(Command::Ref v);
|
|
||||||
void Clear();
|
void Clear();
|
||||||
|
|
||||||
void SetFont(Font::Ref font) { pCurrentFont = font; }
|
/** Command Allocation */
|
||||||
void SetFontScale(float scale) { pFontScale = scale; }
|
Command& NewCommand();
|
||||||
|
|
||||||
void DrawSolid();
|
/** Path API */
|
||||||
void DrawTexture(Texture::Ref tex) { CurrentTex = tex; }
|
void PathAdd(const fvec2& point) { pPath.Push(point); }
|
||||||
|
void PathAdd(float x, float y) { pPath.Push(fvec2(x, y)); }
|
||||||
|
void PathClear() { pPath.Reset(); }
|
||||||
|
/**
|
||||||
|
* @brief Reserve memory for the next PathAdd uses
|
||||||
|
* @note As path will autoexpant and keep the size this func is
|
||||||
|
* only for special use cases
|
||||||
|
*/
|
||||||
|
void PathReserve(size_t num) { pPath.ExpandIf(num); }
|
||||||
|
void PathStroke(u32 color, int t = 1, LiDrawFlags flags = LiDrawFlags_None);
|
||||||
|
void PathFill(u32 color);
|
||||||
|
void PathArcToN(const fvec2& c, float r, float amin, float amax, int s);
|
||||||
|
void PathFastArcToN(const fvec2& c, float r, float amin, float amax, int s);
|
||||||
|
void PathRect(const fvec2& tl, const fvec2& br, float r = 0.f);
|
||||||
|
void PathRectEx(const fvec2& tl, const fvec2& br, float r = 0.f,
|
||||||
|
LiPathRectFlags flags = LiPathRectFlags_None);
|
||||||
|
|
||||||
// SECTION: Draw API //
|
/** Texture Handling */
|
||||||
|
void BindTexture(const Texture& tex);
|
||||||
|
void UnbindTexture() { pCurrentTexture = Texture(); }
|
||||||
|
|
||||||
void DrawRect(const fvec2& pos, const fvec2& size, u32 color,
|
/** Data geters */
|
||||||
int thickness = 1);
|
const Pool<Command>& Data() const { return pCommands; }
|
||||||
|
operator const Pool<Command>&() const { return pCommands; }
|
||||||
|
|
||||||
|
/** Drawing functions */
|
||||||
|
void DrawRect(const fvec2& pos, const fvec2& size, u32 color, int t = 1);
|
||||||
void DrawRectFilled(const fvec2& pos, const fvec2& size, u32 color);
|
void DrawRectFilled(const fvec2& pos, const fvec2& size, u32 color);
|
||||||
void DrawTriangle(const fvec2& a, const fvec2& b, const fvec2& c, u32 color,
|
void DrawTriangle(const fvec2& a, const fvec2& b, const fvec2& c, u32 color,
|
||||||
int thickness = 1);
|
int t = 1);
|
||||||
void DrawTriangleFilled(const fvec2& a, const fvec2& b, const fvec2& c,
|
void DrawTriangleFilled(const fvec2& a, const fvec2& b, const fvec2& c,
|
||||||
u32 color);
|
u32 color);
|
||||||
void DrawCircle(const fvec2& center, float rad, u32 color, int num_segments,
|
void DrawCircle(const fvec2& center, float rad, u32 color, int num_segments,
|
||||||
int thickness = 1);
|
int t = 1);
|
||||||
void DrawCircleFilled(const fvec2& center, float rad, u32 color,
|
void DrawCircleFilled(const fvec2& center, float rad, u32 color,
|
||||||
int num_segments);
|
int num_segments);
|
||||||
void DrawText(const fvec2& p, const std::string& text, u32 color);
|
void DrawText(const fvec2& p, const char* text, u32 color);
|
||||||
/**
|
void DrawTextEx(const fvec2& p, const char* text, u32 color,
|
||||||
* Extended Draw Text Function
|
LiTextFlags flags, const fvec2& box = fvec2(0.f));
|
||||||
*/
|
|
||||||
void DrawTextEx(const fvec2& p, const std::string& text, u32 color,
|
|
||||||
LiTextFlags flags, fvec2 box = fvec2(0.f));
|
|
||||||
void DrawLine(const fvec2& a, const fvec2& b, u32 color, int t = 1);
|
|
||||||
/**
|
|
||||||
* Take list of points and display it as a line on screen
|
|
||||||
* @param points List of Positions
|
|
||||||
* @param clr Color of the Line
|
|
||||||
* @param flags Additional Flags (Close for go back to starting point)
|
|
||||||
* @param thickness Thickness of the Line
|
|
||||||
*/
|
|
||||||
void DrawPolyLine(const Vec<fvec2>& points, u32 clr, u32 flags = 0,
|
|
||||||
int thickness = 1);
|
|
||||||
/**
|
|
||||||
* Take a List ofpoints and display it as Filled Shape
|
|
||||||
* @note Keep in mind to setup the list of points clockwise
|
|
||||||
* @param points List of Points
|
|
||||||
* @param clr Color of the shape
|
|
||||||
*/
|
|
||||||
void DrawConvexPolyFilled(const Vec<fvec2>& points, u32 clr);
|
|
||||||
|
|
||||||
// SECTION: PATH API //
|
void DrawPolyLine(const Pool<fvec2>& points, u32 color,
|
||||||
|
LiDrawFlags flags = LiDrawFlags_None, int t = 1);
|
||||||
|
void DrawConvexPolyFilled(const Pool<fvec2>& points, u32 color);
|
||||||
|
|
||||||
/**
|
void PrimQuad(Command& cmd, const Rect& quad, const Rect& uv, u32 color);
|
||||||
* Function to reserve Memory to prevent overhead on
|
void PrimTriangle(Command& cmd, const fvec2& a, const fvec2& b,
|
||||||
* pusing a lot of points with PathNext
|
const fvec2& c, u32 color);
|
||||||
* @param num_points Number of Positions you want to add
|
|
||||||
*/
|
|
||||||
void PathReserve(size_t num_points) {
|
|
||||||
pPath.Reserve(pPath.Size() + num_points);
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* Clear current Path
|
|
||||||
* @note PathStroke and PathFill will automatically clear
|
|
||||||
*/
|
|
||||||
void PathClear() { pPath.Clear(); }
|
|
||||||
/**
|
|
||||||
* Add a Point to the Path
|
|
||||||
* @note Keep in mind that this function is used for
|
|
||||||
* setting the starting point
|
|
||||||
* @param v Position to add
|
|
||||||
*/
|
|
||||||
void PathAdd(const fvec2& v) { pPath.Add(v); }
|
|
||||||
/**
|
|
||||||
* Path Stroke Create Line from point to point
|
|
||||||
* @note For Primitives like Rect or Triangle mak sure to use
|
|
||||||
* UI7DrawFlags_Close to add a line back to the starting point
|
|
||||||
* @param clr Color od the line
|
|
||||||
* @param thickness Thickness of the line
|
|
||||||
* @param flags Additional Drawflags
|
|
||||||
*/
|
|
||||||
void PathStroke(u32 clr, int thickness = 1, u32 flags = 0) {
|
|
||||||
DrawPolyLine(pPath, clr, flags, thickness);
|
|
||||||
pPath.Clear();
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* Fill a Path with a Color
|
|
||||||
* @note **IMPORTANT: ** Paths need to be setup clockwise
|
|
||||||
* to be rendered correctly
|
|
||||||
* @param clr Fill Color
|
|
||||||
*/
|
|
||||||
void PathFill(u32 clr) {
|
|
||||||
DrawConvexPolyFilled(pPath, clr);
|
|
||||||
pPath.Clear();
|
|
||||||
}
|
|
||||||
void PathArcToN(const fvec2& c, float radius, float a_min, float a_max,
|
|
||||||
int segments);
|
|
||||||
void PathFastArcToN(const fvec2& c, float r, float amin, float amax, int s);
|
|
||||||
/// @brief Create a Path Rect (uses to Positions instead of Pos/Size)
|
|
||||||
/// @param a Top Left Position
|
|
||||||
/// @param b Bottom Right Position
|
|
||||||
/// @param rounding rounding
|
|
||||||
void PathRect(fvec2 a, fvec2 b, float rounding = 0.f);
|
|
||||||
/// @brief Create a Path Rect (uses to Positions instead of Pos/Size)
|
|
||||||
/// @param a Top Left Position
|
|
||||||
/// @param b Bottom Right Position
|
|
||||||
/// @param rounding rounding
|
|
||||||
/// @param flags DrawFlags (for special rounding rules)
|
|
||||||
void PathRectEx(fvec2 a, fvec2 b, float rounding = 0.f, u32 flags = 0);
|
|
||||||
|
|
||||||
void PushClipRect(const fvec4& cr) { pClipRects.Push(cr); }
|
private:
|
||||||
void PopClipRect() {
|
Texture pCurrentTexture;
|
||||||
if (pClipRects.IsEmpty()) {
|
Pool<Command> pCommands;
|
||||||
return;
|
Pool<fvec2> pPath;
|
||||||
}
|
Pool<Vertex> pVertices;
|
||||||
pClipRects.Pop();
|
Pool<u16> pIndices;
|
||||||
}
|
|
||||||
/** One linear Clip rect Setup */
|
|
||||||
void pClipCmd(Command* cmd);
|
|
||||||
|
|
||||||
/** Data Section */
|
|
||||||
|
|
||||||
Stack<fvec4> pClipRects;
|
|
||||||
int Layer;
|
|
||||||
float pFontScale = 0.7f;
|
|
||||||
Font::Ref pCurrentFont;
|
|
||||||
Texture::Ref CurrentTex;
|
|
||||||
std::vector<Command::Ref> pDrawList;
|
|
||||||
PD::Vec<fvec2> pPath;
|
|
||||||
u32 pNumIndices = 0;
|
|
||||||
u32 pNumVertices = 0;
|
|
||||||
};
|
};
|
||||||
} // namespace Li
|
} // namespace Li
|
||||||
} // namespace PD
|
} // namespace PD
|
||||||
@@ -1,116 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
/*
|
|
||||||
MIT License
|
|
||||||
|
|
||||||
Copyright (c) 2024 - 2025 tobid7
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <pd/core/core.hpp>
|
|
||||||
#include <pd/lithium/command.hpp>
|
|
||||||
#include <pd/lithium/pd_p_api.hpp>
|
|
||||||
#include <pd/lithium/rect.hpp>
|
|
||||||
#include <pd/lithium/texture.hpp>
|
|
||||||
|
|
||||||
using LiTextFlags = PD::u32;
|
|
||||||
enum LiTextFlags_ {
|
|
||||||
LiTextFlags_None = 0, ///< Do nothing
|
|
||||||
LiTextFlags_AlignRight = 1 << 0, ///< Align Right of position
|
|
||||||
LiTextFlags_AlignMid = 1 << 1, ///< Align in the middle of pos and box
|
|
||||||
LiTextFlags_Shaddow = 1 << 2, ///< Draws the text twice to create shaddow
|
|
||||||
LiTextFlags_Wrap = 1 << 3, ///< Wrap Text: May be runs better with TMS
|
|
||||||
LiTextFlags_Short = 1 << 4, ///< Short Text: May be runs better with TMS
|
|
||||||
LiTextFlags_Scroll = 1 << 5, ///< Not implemented [scoll text if to long]
|
|
||||||
};
|
|
||||||
|
|
||||||
namespace PD {
|
|
||||||
namespace Li {
|
|
||||||
class PD_LITHIUM_API Font {
|
|
||||||
public:
|
|
||||||
/** Codepoint Data holder */
|
|
||||||
struct Codepoint {
|
|
||||||
u32 pCodepoint = 0;
|
|
||||||
fvec4 SimpleUV;
|
|
||||||
Texture::Ref Tex;
|
|
||||||
fvec2 Size;
|
|
||||||
float Offset = 0.f;
|
|
||||||
bool pInvalid = false;
|
|
||||||
};
|
|
||||||
|
|
||||||
/** Constructore doesnt need Backand anymore */
|
|
||||||
Font() = default;
|
|
||||||
~Font() = default;
|
|
||||||
|
|
||||||
PD_SHARED(Font);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Load a TTF File
|
|
||||||
* @param path Path to the TTF file
|
|
||||||
* @param px_height Pixelheight of the codepoints (limit by 64)
|
|
||||||
*/
|
|
||||||
void LoadTTF(const std::string& path, int px_height = 32);
|
|
||||||
/**
|
|
||||||
* Load a TTF File from Memory
|
|
||||||
* @param data File data
|
|
||||||
* @param px_height Pixelheight of the codepoints (limit by 64)
|
|
||||||
*/
|
|
||||||
void LoadTTF(const std::vector<u8>& data, int px_height = 32);
|
|
||||||
/**
|
|
||||||
* Function that loads a default integrated font...
|
|
||||||
* This will only work if PD_LI_INCLUDE_FONTS was set
|
|
||||||
* on lithium build cause otherwise the font data is not included
|
|
||||||
*/
|
|
||||||
void LoadDefaultFont(int id = 0, int pixel_height = 32);
|
|
||||||
/**
|
|
||||||
* Getter for Codepoint reference
|
|
||||||
* @return codepoint dataholder reference
|
|
||||||
*/
|
|
||||||
Codepoint& GetCodepoint(u32 c);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get Text Bounding Box
|
|
||||||
*/
|
|
||||||
fvec2 GetTextBounds(const std::string& text, float scale);
|
|
||||||
/**
|
|
||||||
* Extended Draw Text Function that vreates a Command List
|
|
||||||
*/
|
|
||||||
void CmdTextEx(std::vector<Command::Ref>& cmds, const fvec2& pos, u32 color,
|
|
||||||
float scale, const std::string& text, LiTextFlags flags = 0,
|
|
||||||
const fvec2& box = 0);
|
|
||||||
/**
|
|
||||||
* Utility function to create a font atlas
|
|
||||||
* During TTF loading (Internal and should not be called)
|
|
||||||
*/
|
|
||||||
void pMakeAtlas(bool final, std::vector<u8>& font_tex, int texszs,
|
|
||||||
PD::Li::Texture::Ref tex);
|
|
||||||
|
|
||||||
/** Data Section */
|
|
||||||
int PixelHeight;
|
|
||||||
int DefaultPixelHeight = 24;
|
|
||||||
std::vector<Texture::Ref> Textures;
|
|
||||||
/**
|
|
||||||
* 32Bit Codepoint Dataholder reference map
|
|
||||||
* **Now using unordered map**
|
|
||||||
*/
|
|
||||||
std::unordered_map<u32, Codepoint> CodeMap;
|
|
||||||
};
|
|
||||||
} // namespace Li
|
|
||||||
} // namespace PD
|
|
||||||
@@ -1,41 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
/*
|
|
||||||
MIT License
|
|
||||||
Copyright (c) 2024 - 2025 René Amthor (tobid7)
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifdef PD_LI_INCLUDE_FONTS
|
|
||||||
|
|
||||||
#include <pd/core/common.hpp>
|
|
||||||
|
|
||||||
/** Generated with pdfm */
|
|
||||||
namespace PD {
|
|
||||||
struct FontFileData {
|
|
||||||
std::string Name;
|
|
||||||
u32 StartOff;
|
|
||||||
u32 Size;
|
|
||||||
};
|
|
||||||
extern FontFileData pFontData[];
|
|
||||||
extern size_t pNumFonts;
|
|
||||||
extern PD::u8 pFontsDataRaw[];
|
|
||||||
} // namespace PD
|
|
||||||
#endif
|
|
||||||
109
include/pd/lithium/formatters.hpp
Normal file
109
include/pd/lithium/formatters.hpp
Normal file
@@ -0,0 +1,109 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <pd/lithium/atlas.hpp>
|
||||||
|
#include <pd/lithium/rect.hpp>
|
||||||
|
#include <pd/lithium/texture.hpp>
|
||||||
|
#include <pd/lithium/vertex.hpp>
|
||||||
|
|
||||||
|
template <>
|
||||||
|
struct std::formatter<PD::TextureFilter> {
|
||||||
|
constexpr auto parse(std::format_parse_context& ctx) { return ctx.begin(); }
|
||||||
|
|
||||||
|
template <typename FormatContext>
|
||||||
|
auto format(const PD::TextureFilter& value, FormatContext& ctx) const {
|
||||||
|
std::string_view ret = "Unknown";
|
||||||
|
switch (value) {
|
||||||
|
case PD::TextureFilter::Linear:
|
||||||
|
ret = "Linear";
|
||||||
|
break;
|
||||||
|
case PD::TextureFilter::Nearest:
|
||||||
|
ret = "Nearest";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return std::format_to(ctx.out(), "{}", ret);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <>
|
||||||
|
struct std::formatter<PD::TextureFormat> {
|
||||||
|
constexpr auto parse(std::format_parse_context& ctx) { return ctx.begin(); }
|
||||||
|
|
||||||
|
template <typename FormatContext>
|
||||||
|
auto format(const PD::TextureFormat& value, FormatContext& ctx) const {
|
||||||
|
std::string_view ret = "Unknown";
|
||||||
|
switch (value) {
|
||||||
|
case PD::TextureFormat::RGBA32:
|
||||||
|
ret = "RGBA32";
|
||||||
|
break;
|
||||||
|
case PD::TextureFormat::RGB24:
|
||||||
|
ret = "RGB24";
|
||||||
|
break;
|
||||||
|
case PD::TextureFormat::A8:
|
||||||
|
ret = "A8";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return std::format_to(ctx.out(), "{}", ret);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <>
|
||||||
|
struct std::formatter<PD::Li::Rect> : std::formatter<std::string> {
|
||||||
|
constexpr auto parse(std::format_parse_context& ctx) { return ctx.begin(); }
|
||||||
|
|
||||||
|
template <typename FormatContext>
|
||||||
|
auto format(const PD::Li::Rect& value, FormatContext& ctx) const {
|
||||||
|
// {l, t, r, t, l, b, r, b}
|
||||||
|
return std::format_to(ctx.out(), "{}, {}, {}, {}, {}, {}, {}, {}",
|
||||||
|
value.Top.x, value.Top.y, value.Top.z, value.Top.w,
|
||||||
|
value.Bot.x, value.Bot.y, value.Bot.z, value.Bot.w);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <>
|
||||||
|
struct std::formatter<PD::Li::Texture> : std::formatter<std::string> {
|
||||||
|
constexpr auto parse(std::format_parse_context& ctx) { return ctx.begin(); }
|
||||||
|
|
||||||
|
template <typename FormatContext>
|
||||||
|
auto format(const PD::Li::Texture& value, FormatContext& ctx) const {
|
||||||
|
// {ID, [w, h], [l, t, r, t, l, b, r, b]}
|
||||||
|
return std::format_to(ctx.out(), "{}, [{}], [{}]", value.GetID(),
|
||||||
|
value.GetSize(), value.GetUV());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <>
|
||||||
|
struct std::formatter<PD::Li::Vertex> : std::formatter<std::string> {
|
||||||
|
constexpr auto parse(std::format_parse_context& ctx) { return ctx.begin(); }
|
||||||
|
|
||||||
|
template <typename FormatContext>
|
||||||
|
auto format(const PD::Li::Vertex& value, FormatContext& ctx) const {
|
||||||
|
// { [x, y], [u, v], colorhex }
|
||||||
|
return std::format_to(ctx.out(), "[{}], [{}], #{:08X}", value.pos, value.uv,
|
||||||
|
value.color);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <>
|
||||||
|
struct std::formatter<PD::Li::AtlasState> : std::formatter<std::string> {
|
||||||
|
constexpr auto parse(std::format_parse_context& ctx) { return ctx.begin(); }
|
||||||
|
|
||||||
|
template <typename FormatContext>
|
||||||
|
auto format(const PD::Li::AtlasState& value, FormatContext& ctx) const {
|
||||||
|
std::string_view ret = "Unknown";
|
||||||
|
switch (value) {
|
||||||
|
case PD::Li::AtlasState::Invalid:
|
||||||
|
ret = "Invalid";
|
||||||
|
break;
|
||||||
|
case PD::Li::AtlasState::ReqCreate:
|
||||||
|
ret = "RequestCreate";
|
||||||
|
break;
|
||||||
|
case PD::Li::AtlasState::ReqUpdate:
|
||||||
|
ret = "RequestUpdate";
|
||||||
|
break;
|
||||||
|
case PD::Li::AtlasState::ReqDestroy:
|
||||||
|
ret = "RequestDestroy";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return std::format_to(ctx.out(), "{}", ret);
|
||||||
|
}
|
||||||
|
};
|
||||||
31
include/pd/lithium/lithium.hpp
Executable file → Normal file
31
include/pd/lithium/lithium.hpp
Executable file → Normal file
@@ -1,32 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
/*
|
|
||||||
MIT License
|
|
||||||
|
|
||||||
Copyright (c) 2024 - 2025 tobid7
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <pd/lithium/command.hpp>
|
#include <pd/lithium/command.hpp>
|
||||||
#include <pd/lithium/drawlist.hpp>
|
#include <pd/lithium/drawlist.hpp>
|
||||||
#include <pd/lithium/font.hpp>
|
#include <pd/lithium/math.hpp>
|
||||||
#include <pd/lithium/rect.hpp>
|
#include <pd/lithium/pools.hpp>
|
||||||
#include <pd/lithium/renderer.hpp>
|
#include <pd/lithium/vertex.hpp>
|
||||||
#include <pd/lithium/texture.hpp>
|
|
||||||
|
|||||||
18
include/pd/lithium/math.hpp
Normal file
18
include/pd/lithium/math.hpp
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <pd/core/core.hpp>
|
||||||
|
#include <pd/lithium/rect.hpp>
|
||||||
|
|
||||||
|
namespace PD {
|
||||||
|
namespace Li {
|
||||||
|
namespace Math {
|
||||||
|
PD_API bool InBounds(const fvec2& pos, const fvec2& size, const fvec4& rect);
|
||||||
|
PD_API bool InBounds(const fvec2& pos, const fvec4& rect);
|
||||||
|
PD_API bool InBounds(const fvec2& a, const fvec2& b, const fvec2& c,
|
||||||
|
const fvec4& rect);
|
||||||
|
PD_API void RotateCorner(fvec2& pos, float sinus, float cosinus);
|
||||||
|
PD_API Rect PrimRect(const fvec2& pos, const fvec2& size, float angle = 0.f);
|
||||||
|
PD_API Rect PrimLine(const fvec2& a, const fvec2& b, int t = 1);
|
||||||
|
} // namespace Math
|
||||||
|
} // namespace Li
|
||||||
|
} // namespace PD
|
||||||
@@ -1,51 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
/*
|
|
||||||
MIT License
|
|
||||||
Copyright (c) 2024 - 2025 René Amthor (tobid7)
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/** Generated with ppam */
|
|
||||||
|
|
||||||
#ifdef _WIN32 // Windows (MSVC Tested)
|
|
||||||
#ifdef PD_LITHIUM_BUILD_SHARED
|
|
||||||
#define PD_LITHIUM_API __declspec(dllexport)
|
|
||||||
#else
|
|
||||||
#define PD_LITHIUM_API __declspec(dllimport)
|
|
||||||
#endif
|
|
||||||
#elif defined(__APPLE__) // macOS (untested yet)
|
|
||||||
#ifdef PD_LITHIUM_BUILD_SHARED
|
|
||||||
#define PD_LITHIUM_API __attribute__((visibility("default")))
|
|
||||||
#else
|
|
||||||
#define PD_LITHIUM_API
|
|
||||||
#endif
|
|
||||||
#elif defined(__linux__) // Linux (untested yet)
|
|
||||||
#ifdef PD_LITHIUM_BUILD_SHARED
|
|
||||||
#define PD_LITHIUM_API __attribute__((visibility("default")))
|
|
||||||
#else
|
|
||||||
#define PD_LITHIUM_API
|
|
||||||
#endif
|
|
||||||
#elif defined(__3DS__) // 3ds Specific
|
|
||||||
// Only Static supported
|
|
||||||
#define PD_LITHIUM_API
|
|
||||||
#else
|
|
||||||
#define PD_LITHIUM_API
|
|
||||||
#endif
|
|
||||||
12
include/pd/lithium/pools.hpp
Normal file
12
include/pd/lithium/pools.hpp
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <cstddef>
|
||||||
|
#include <pd/lithium/vertex.hpp>
|
||||||
|
|
||||||
|
namespace PD {
|
||||||
|
namespace Li {
|
||||||
|
PD_API Vertex* AllocateVertices(size_t count);
|
||||||
|
PD_API u16* AllocateIndices(size_t count);
|
||||||
|
PD_API void ResetPools();
|
||||||
|
} // namespace Li
|
||||||
|
} // namespace PD
|
||||||
4
include/pd/lithium/rect.hpp
Executable file → Normal file
4
include/pd/lithium/rect.hpp
Executable file → Normal file
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
MIT License
|
MIT License
|
||||||
Copyright (c) 2024 - 2025 René Amthor (tobid7)
|
Copyright (c) 2024 - 2026 René Amthor (tobid7)
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
@@ -131,6 +131,8 @@ class Rect {
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool operator==(const Rect& r) const { return Top == r.Top && Bot == r.Bot; }
|
||||||
|
|
||||||
void SwapVec2XY() {
|
void SwapVec2XY() {
|
||||||
Top.SwapXY();
|
Top.SwapXY();
|
||||||
Top.SwapZW();
|
Top.SwapZW();
|
||||||
|
|||||||
@@ -1,62 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
/*
|
|
||||||
MIT License
|
|
||||||
|
|
||||||
Copyright (c) 2024 - 2025 tobid7
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <pd/drivers/drivers.hpp>
|
|
||||||
#include <pd/lithium/pd_p_api.hpp>
|
|
||||||
#include <pd/lithium/rect.hpp>
|
|
||||||
|
|
||||||
namespace PD {
|
|
||||||
namespace Li {
|
|
||||||
/**
|
|
||||||
* Static Class Render Setup Functions
|
|
||||||
*/
|
|
||||||
class PD_LITHIUM_API Renderer {
|
|
||||||
public:
|
|
||||||
Renderer() = default;
|
|
||||||
~Renderer() = default;
|
|
||||||
|
|
||||||
// SECTION: Open Command and Object creation API
|
|
||||||
static void RotateCorner(fvec2& pos, float s, float c);
|
|
||||||
static Rect PrimRect(const fvec2& pos, const fvec2& size, float angle = 0.f);
|
|
||||||
static Rect PrimLine(const fvec2& a, const fvec2& b, int thickness = 1);
|
|
||||||
static void CmdQuad(Command* cmd, const Rect& quad, const Rect& uv,
|
|
||||||
u32 color);
|
|
||||||
static void CmdTriangle(Command* cmd, const fvec2 a, const fvec2 b,
|
|
||||||
const fvec2 c, u32 clr);
|
|
||||||
static void CmdPolyLine(const Vec<fvec2>& points, u32 clr, u32 flags = 0,
|
|
||||||
int thickness = 1);
|
|
||||||
static void CmdConvexPolyFilled(Command* cmd, const Vec<fvec2>& points,
|
|
||||||
u32 clr, Texture::Ref tex);
|
|
||||||
|
|
||||||
// SECTION: InBounds Checks
|
|
||||||
|
|
||||||
static bool InBox(const fvec2& pos, const fvec2& size, const fvec4& area);
|
|
||||||
static bool InBox(const fvec2& pos, const fvec4& area);
|
|
||||||
static bool InBox(const fvec2& a, const fvec2& b, const fvec2& c,
|
|
||||||
const fvec4& area);
|
|
||||||
};
|
|
||||||
} // namespace Li
|
|
||||||
} // namespace PD
|
|
||||||
94
include/pd/lithium/texture.hpp
Executable file → Normal file
94
include/pd/lithium/texture.hpp
Executable file → Normal file
@@ -1,75 +1,47 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
/*
|
|
||||||
MIT License
|
|
||||||
Copyright (c) 2024 - 2025 René Amthor (tobid7)
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <pd/core/core.hpp>
|
#include <pd/core/core.hpp>
|
||||||
#include <pd/lithium/rect.hpp>
|
#include <pd/lithium/rect.hpp>
|
||||||
|
|
||||||
namespace PD {
|
namespace PD {
|
||||||
|
using TextureID = ptr;
|
||||||
|
enum class TextureFilter {
|
||||||
|
Linear,
|
||||||
|
Nearest,
|
||||||
|
};
|
||||||
|
|
||||||
|
enum class TextureFormat {
|
||||||
|
RGBA32,
|
||||||
|
RGB24,
|
||||||
|
A8,
|
||||||
|
};
|
||||||
namespace Li {
|
namespace Li {
|
||||||
/** Use so address type for TexAddress */
|
|
||||||
using TexAddress = uintptr_t;
|
|
||||||
class Texture {
|
class Texture {
|
||||||
public:
|
public:
|
||||||
/** Texture Types */
|
using Ptr = Texture*;
|
||||||
enum Type {
|
Texture() : pID(0), pSize(0, 0), pUV(fvec4(0, 0, 1, 1)) {}
|
||||||
RGBA32, ///< Rgba 32Bit
|
Texture(TextureID id, ivec2 size)
|
||||||
RGB24, ///< Rgb 24 Bit
|
: pID(id), pSize(size), pUV(fvec4(0, 0, 1, 1)) {}
|
||||||
A8, ///< A8 8Bit alpha
|
|
||||||
};
|
const ivec2& GetSize() const { return pSize; }
|
||||||
/** Texture Filters */
|
TextureID GetID() { return pID; }
|
||||||
enum Filter {
|
const TextureID& GetID() const { return pID; }
|
||||||
NEAREST, ///< Nearest
|
const Rect& GetUV() const { return pUV; }
|
||||||
LINEAR, ///< Linear
|
|
||||||
};
|
void SetSize(int x, int y) {
|
||||||
/** Constructor */
|
pSize.x = x;
|
||||||
Texture() : Address(0), Size(0), UV(fvec4(0.f, 0.f, 1.f, 1.f)) {}
|
pSize.y = y;
|
||||||
Texture(TexAddress addr, ivec2 size,
|
|
||||||
Li::Rect uv = fvec4(0.f, 0.f, 1.f, 1.f)) {
|
|
||||||
Address = addr;
|
|
||||||
Size = size;
|
|
||||||
UV = uv;
|
|
||||||
}
|
}
|
||||||
|
void SetSize(const ivec2& size) { pSize = size; }
|
||||||
|
void SetID(TextureID id) { pID = id; }
|
||||||
|
void SetUV(const Rect& uv) { pUV = uv; }
|
||||||
|
void SetUV(const fvec4& uv) { pUV = uv; }
|
||||||
|
void SetUV(float t, float l, float b, float r) { SetUV(fvec4(t, l, b, r)); }
|
||||||
|
|
||||||
PD_SHARED(Texture);
|
private:
|
||||||
|
TextureID pID;
|
||||||
void CopyFrom(Texture::Ref tex) {
|
ivec2 pSize;
|
||||||
Address = tex->Address;
|
Rect pUV;
|
||||||
Size = tex->Size;
|
|
||||||
UV = tex->UV;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Left in Code getter (should be remoevd) */
|
|
||||||
ivec2 GetSize() const { return Size; }
|
|
||||||
Li::Rect GetUV() const { return UV; }
|
|
||||||
|
|
||||||
operator ivec2() const { return Size; }
|
|
||||||
operator Li::Rect() const { return UV; }
|
|
||||||
|
|
||||||
TexAddress Address;
|
|
||||||
ivec2 Size;
|
|
||||||
Li::Rect UV;
|
|
||||||
};
|
};
|
||||||
} // namespace Li
|
} // namespace Li
|
||||||
} // namespace PD
|
} // namespace PD
|
||||||
@@ -1,50 +1,19 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
/*
|
#include <pd/core/vec.hpp>
|
||||||
MIT License
|
|
||||||
Copyright (c) 2024 - 2025 René Amthor (tobid7)
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <pd/core/core.hpp>
|
|
||||||
|
|
||||||
namespace PD {
|
namespace PD {
|
||||||
namespace Li {
|
namespace Li {
|
||||||
class Vertex {
|
class Vertex {
|
||||||
public:
|
public:
|
||||||
Vertex() {}
|
Vertex() {}
|
||||||
Vertex(const fvec2& p, const fvec2& u, u32 c) {
|
Vertex(const fvec2& pos, const fvec2& uv, u32 color)
|
||||||
Pos.x = p.x;
|
: pos(pos), uv(uv), color(color) {}
|
||||||
Pos.y = p.y;
|
|
||||||
UV = u;
|
|
||||||
Color = c;
|
|
||||||
}
|
|
||||||
~Vertex() {}
|
~Vertex() {}
|
||||||
|
|
||||||
// private:
|
fvec2 pos;
|
||||||
|
fvec2 uv;
|
||||||
/** Open Access Data Section */
|
u32 color = 0x00000000;
|
||||||
|
|
||||||
fvec2 Pos;
|
|
||||||
fvec2 UV;
|
|
||||||
u32 Color;
|
|
||||||
};
|
};
|
||||||
} // namespace Li
|
} // namespace Li
|
||||||
} // namespace PD
|
} // namespace PD
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
MIT License
|
MIT License
|
||||||
Copyright (c) 2024 - 2025 René Amthor (tobid7)
|
Copyright (c) 2024 - 2026 René Amthor (tobid7)
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
@@ -24,28 +24,31 @@ SOFTWARE.
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/** Generated with ppam */
|
/** Generated with ppam */
|
||||||
|
#ifndef PD_BUILD_STATIC
|
||||||
#ifdef _WIN32 // Windows (MSVC Tested)
|
#ifdef _WIN32 // Windows (MSVC Tested)
|
||||||
#ifdef PD_UI7_BUILD_SHARED
|
#ifdef PD_BUILD_SHARED
|
||||||
#define PD_UI7_API __declspec(dllexport)
|
#define PD_API __declspec(dllexport)
|
||||||
#else
|
#else
|
||||||
#define PD_UI7_API __declspec(dllimport)
|
#define PD_API __declspec(dllimport)
|
||||||
#endif
|
#endif
|
||||||
#elif defined(__APPLE__) // macOS (untested yet)
|
#elif defined(__APPLE__) // macOS (untested yet)
|
||||||
#ifdef PD_UI7_BUILD_SHARED
|
#ifdef PD_BUILD_SHARED
|
||||||
#define PD_UI7_API __attribute__((visibility("default")))
|
#define PD_API __attribute__((visibility("default")))
|
||||||
#else
|
#else
|
||||||
#define PD_UI7_API
|
#define PD_API
|
||||||
#endif
|
#endif
|
||||||
#elif defined(__linux__) // Linux (untested yet)
|
#elif defined(__linux__) // Linux (untested yet)
|
||||||
#ifdef PD_UI7_BUILD_SHARED
|
#ifdef PD_BUILD_SHARED
|
||||||
#define PD_UI7_API __attribute__((visibility("default")))
|
#define PD_API __attribute__((visibility("default")))
|
||||||
#else
|
#else
|
||||||
#define PD_UI7_API
|
#define PD_API
|
||||||
#endif
|
#endif
|
||||||
#elif defined(__3DS__) // 3ds Specific
|
#elif defined(__3DS__) // 3ds Specific
|
||||||
// Only Static supported
|
// Only Static supported
|
||||||
#define PD_UI7_API
|
#define PD_API
|
||||||
#else
|
#else
|
||||||
#define PD_UI7_API
|
#define PD_API
|
||||||
|
#endif
|
||||||
|
#else
|
||||||
|
#define PD_API
|
||||||
#endif
|
#endif
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user