mirror of
https://github.com/xemu-project/nxdk_pgraph_tests.git
synced 2024-11-26 19:40:45 +00:00
This commit is contained in:
commit
1c7f719e3a
200
.clang-format
Normal file
200
.clang-format
Normal file
@ -0,0 +1,200 @@
|
||||
---
|
||||
Language: Cpp
|
||||
# BasedOnStyle: Google
|
||||
AccessModifierOffset: -1
|
||||
AlignAfterOpenBracket: Align
|
||||
AlignConsecutiveMacros: None
|
||||
AlignConsecutiveAssignments: None
|
||||
AlignConsecutiveBitFields: None
|
||||
AlignConsecutiveDeclarations: None
|
||||
AlignEscapedNewlines: Left
|
||||
AlignOperands: Align
|
||||
AlignTrailingComments: true
|
||||
AllowAllArgumentsOnNextLine: true
|
||||
AllowAllConstructorInitializersOnNextLine: true
|
||||
AllowAllParametersOfDeclarationOnNextLine: true
|
||||
AllowShortEnumsOnASingleLine: true
|
||||
AllowShortBlocksOnASingleLine: Never
|
||||
AllowShortCaseLabelsOnASingleLine: false
|
||||
AllowShortFunctionsOnASingleLine: All
|
||||
AllowShortLambdasOnASingleLine: All
|
||||
AllowShortIfStatementsOnASingleLine: WithoutElse
|
||||
AllowShortLoopsOnASingleLine: true
|
||||
AlwaysBreakAfterDefinitionReturnType: None
|
||||
AlwaysBreakAfterReturnType: None
|
||||
AlwaysBreakBeforeMultilineStrings: true
|
||||
AlwaysBreakTemplateDeclarations: Yes
|
||||
AttributeMacros:
|
||||
- __capability
|
||||
BinPackArguments: true
|
||||
BinPackParameters: true
|
||||
BraceWrapping:
|
||||
AfterCaseLabel: false
|
||||
AfterClass: false
|
||||
AfterControlStatement: Never
|
||||
AfterEnum: false
|
||||
AfterFunction: false
|
||||
AfterNamespace: false
|
||||
AfterObjCDeclaration: false
|
||||
AfterStruct: false
|
||||
AfterUnion: false
|
||||
AfterExternBlock: false
|
||||
BeforeCatch: false
|
||||
BeforeElse: false
|
||||
BeforeLambdaBody: false
|
||||
BeforeWhile: false
|
||||
IndentBraces: false
|
||||
SplitEmptyFunction: true
|
||||
SplitEmptyRecord: true
|
||||
SplitEmptyNamespace: true
|
||||
BreakBeforeBinaryOperators: None
|
||||
BreakBeforeConceptDeclarations: true
|
||||
BreakBeforeBraces: Attach
|
||||
BreakBeforeInheritanceComma: false
|
||||
BreakInheritanceList: BeforeColon
|
||||
BreakBeforeTernaryOperators: true
|
||||
BreakConstructorInitializersBeforeComma: false
|
||||
BreakConstructorInitializers: BeforeColon
|
||||
BreakAfterJavaFieldAnnotations: false
|
||||
BreakStringLiterals: true
|
||||
ColumnLimit: 80
|
||||
CommentPragmas: '^ IWYU pragma:'
|
||||
CompactNamespaces: false
|
||||
ConstructorInitializerAllOnOneLineOrOnePerLine: true
|
||||
ConstructorInitializerIndentWidth: 4
|
||||
ContinuationIndentWidth: 4
|
||||
Cpp11BracedListStyle: true
|
||||
DeriveLineEnding: true
|
||||
DerivePointerAlignment: true
|
||||
DisableFormat: false
|
||||
EmptyLineBeforeAccessModifier: LogicalBlock
|
||||
ExperimentalAutoDetectBinPacking: false
|
||||
FixNamespaceComments: true
|
||||
ForEachMacros:
|
||||
- foreach
|
||||
- Q_FOREACH
|
||||
- BOOST_FOREACH
|
||||
StatementAttributeLikeMacros:
|
||||
- Q_EMIT
|
||||
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: ''
|
||||
IndentCaseLabels: true
|
||||
IndentCaseBlocks: false
|
||||
IndentGotoLabels: true
|
||||
IndentPPDirectives: None
|
||||
IndentExternBlock: AfterExternBlock
|
||||
IndentRequires: false
|
||||
IndentWidth: 2
|
||||
IndentWrappedFunctionNames: false
|
||||
InsertTrailingCommas: None
|
||||
JavaScriptQuotes: Leave
|
||||
JavaScriptWrapImports: true
|
||||
KeepEmptyLinesAtTheStartOfBlocks: false
|
||||
MacroBlockBegin: ''
|
||||
MacroBlockEnd: ''
|
||||
MaxEmptyLinesToKeep: 1
|
||||
NamespaceIndentation: None
|
||||
ObjCBinPackProtocolList: Never
|
||||
ObjCBlockIndentWidth: 2
|
||||
ObjCBreakBeforeNestedBlockParam: true
|
||||
ObjCSpaceAfterProperty: false
|
||||
ObjCSpaceBeforeProtocolList: true
|
||||
PenaltyBreakAssignment: 2
|
||||
PenaltyBreakBeforeFirstCallParameter: 1
|
||||
PenaltyBreakComment: 300
|
||||
PenaltyBreakFirstLessLess: 120
|
||||
PenaltyBreakString: 1000
|
||||
PenaltyBreakTemplateDeclaration: 10
|
||||
PenaltyExcessCharacter: 1000000
|
||||
PenaltyReturnTypeOnItsOwnLine: 200
|
||||
PenaltyIndentedWhitespace: 0
|
||||
PointerAlignment: Left
|
||||
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: ''
|
||||
BasedOnStyle: google
|
||||
ReflowComments: true
|
||||
SortIncludes: true
|
||||
SortJavaStaticImport: Before
|
||||
SortUsingDeclarations: true
|
||||
SpaceAfterCStyleCast: false
|
||||
SpaceAfterLogicalNot: false
|
||||
SpaceAfterTemplateKeyword: true
|
||||
SpaceBeforeAssignmentOperators: true
|
||||
SpaceBeforeCaseColon: false
|
||||
SpaceBeforeCpp11BracedList: false
|
||||
SpaceBeforeCtorInitializerColon: true
|
||||
SpaceBeforeInheritanceColon: true
|
||||
SpaceBeforeParens: ControlStatements
|
||||
SpaceAroundPointerQualifiers: Default
|
||||
SpaceBeforeRangeBasedForLoopColon: true
|
||||
SpaceInEmptyBlock: false
|
||||
SpaceInEmptyParentheses: false
|
||||
SpacesBeforeTrailingComments: 2
|
||||
SpacesInAngles: false
|
||||
SpacesInConditionalStatement: false
|
||||
SpacesInContainerLiterals: true
|
||||
SpacesInCStyleCastParentheses: false
|
||||
SpacesInParentheses: false
|
||||
SpacesInSquareBrackets: false
|
||||
SpaceBeforeSquareBrackets: false
|
||||
BitFieldColonSpacing: Both
|
||||
Standard: Auto
|
||||
StatementMacros:
|
||||
- Q_UNUSED
|
||||
- QT_REQUIRE_VERSION
|
||||
TabWidth: 8
|
||||
UseCRLF: false
|
||||
UseTab: Never
|
||||
WhitespaceSensitiveMacros:
|
||||
- STRINGIZE
|
||||
- PP_STRINGIZE
|
||||
- BOOST_PP_STRINGIZE
|
||||
- NS_SWIFT_NAME
|
||||
- CF_SWIFT_NAME
|
||||
...
|
||||
|
36
.gdbinit
Normal file
36
.gdbinit
Normal file
@ -0,0 +1,36 @@
|
||||
# CLion
|
||||
# To allow this file to work you'll need to enable parsing of project-local
|
||||
# .gdbinit files. Create/edit ~/.gdbinit (on WSL make sure it's inside the
|
||||
# linux guest) and add:
|
||||
#
|
||||
# set auto-load local-gdbinit on
|
||||
# add-auto-load-safe-path /
|
||||
|
||||
|
||||
# Tell GDB that we are using 32-bit x86 architecture
|
||||
set arch i386
|
||||
|
||||
# Tell GDB to load symbols from main.exe
|
||||
#
|
||||
# Notice here that we are using the .exe file, not the .xbe file, as
|
||||
# GDB does not understand the .xbe format.
|
||||
#
|
||||
add-symbol-file main.exe
|
||||
|
||||
# Use a layout which shows source code
|
||||
# CLion: Not supported
|
||||
#layout src
|
||||
|
||||
# Prevent CLion from dying with "doesn't support qGetTIBAddr packet"
|
||||
set osabi none
|
||||
|
||||
# CLion: Handled by CLion
|
||||
# Connect to the XQEMU GDB server
|
||||
# target remote 127.0.0.1:1234
|
||||
|
||||
# Stop execution at the beginning of the `main` function
|
||||
# b main
|
||||
|
||||
# Let XQEMU run until the CPU tries to execute from the address
|
||||
# we have placed our breakpoint(s)
|
||||
# c
|
12
.gitignore
vendored
Normal file
12
.gitignore
vendored
Normal file
@ -0,0 +1,12 @@
|
||||
*.cpp.d
|
||||
*.obj
|
||||
*.iso
|
||||
*.lib
|
||||
*.exe
|
||||
*.xbe
|
||||
*.pdb
|
||||
|
||||
.DS_Store
|
||||
.vscode/
|
||||
.idea/
|
||||
bin/
|
503
LICENSE
Normal file
503
LICENSE
Normal file
@ -0,0 +1,503 @@
|
||||
GNU LESSER GENERAL PUBLIC LICENSE
|
||||
Version 2.1, February 1999
|
||||
|
||||
Copyright (C) 1991, 1999 Free Software Foundation, Inc.
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
[This is the first released version of the Lesser GPL. It also counts
|
||||
as the successor of the GNU Library Public License, version 2, hence
|
||||
the version number 2.1.]
|
||||
|
||||
Preamble
|
||||
|
||||
The licenses for most software are designed to take away your
|
||||
freedom to share and change it. By contrast, the GNU General Public
|
||||
Licenses are intended to guarantee your freedom to share and change
|
||||
free software--to make sure the software is free for all its users.
|
||||
|
||||
This license, the Lesser General Public License, applies to some
|
||||
specially designated software packages--typically libraries--of the
|
||||
Free Software Foundation and other authors who decide to use it. You
|
||||
can use it too, but we suggest you first think carefully about whether
|
||||
this license or the ordinary General Public License is the better
|
||||
strategy to use in any particular case, based on the explanations below.
|
||||
|
||||
When we speak of free software, we are referring to freedom of use,
|
||||
not price. Our General Public Licenses are designed to make sure that
|
||||
you have the freedom to distribute copies of free software (and charge
|
||||
for this service if you wish); that you receive source code or can get
|
||||
it if you want it; that you can change the software and use pieces of
|
||||
it in new free programs; and that you are informed that you can do
|
||||
these things.
|
||||
|
||||
To protect your rights, we need to make restrictions that forbid
|
||||
distributors to deny you these rights or to ask you to surrender these
|
||||
rights. These restrictions translate to certain responsibilities for
|
||||
you if you distribute copies of the library or if you modify it.
|
||||
|
||||
For example, if you distribute copies of the library, whether gratis
|
||||
or for a fee, you must give the recipients all the rights that we gave
|
||||
you. You must make sure that they, too, receive or can get the source
|
||||
code. If you link other code with the library, you must provide
|
||||
complete object files to the recipients, so that they can relink them
|
||||
with the library after making changes to the library and recompiling
|
||||
it. And you must show them these terms so they know their rights.
|
||||
|
||||
We protect your rights with a two-step method: (1) we copyright the
|
||||
library, and (2) we offer you this license, which gives you legal
|
||||
permission to copy, distribute and/or modify the library.
|
||||
|
||||
To protect each distributor, we want to make it very clear that
|
||||
there is no warranty for the free library. Also, if the library is
|
||||
modified by someone else and passed on, the recipients should know
|
||||
that what they have is not the original version, so that the original
|
||||
author's reputation will not be affected by problems that might be
|
||||
introduced by others.
|
||||
|
||||
Finally, software patents pose a constant threat to the existence of
|
||||
any free program. We wish to make sure that a company cannot
|
||||
effectively restrict the users of a free program by obtaining a
|
||||
restrictive license from a patent holder. Therefore, we insist that
|
||||
any patent license obtained for a version of the library must be
|
||||
consistent with the full freedom of use specified in this license.
|
||||
|
||||
Most GNU software, including some libraries, is covered by the
|
||||
ordinary GNU General Public License. This license, the GNU Lesser
|
||||
General Public License, applies to certain designated libraries, and
|
||||
is quite different from the ordinary General Public License. We use
|
||||
this license for certain libraries in order to permit linking those
|
||||
libraries into non-free programs.
|
||||
|
||||
When a program is linked with a library, whether statically or using
|
||||
a shared library, the combination of the two is legally speaking a
|
||||
combined work, a derivative of the original library. The ordinary
|
||||
General Public License therefore permits such linking only if the
|
||||
entire combination fits its criteria of freedom. The Lesser General
|
||||
Public License permits more lax criteria for linking other code with
|
||||
the library.
|
||||
|
||||
We call this license the "Lesser" General Public License because it
|
||||
does Less to protect the user's freedom than the ordinary General
|
||||
Public License. It also provides other free software developers Less
|
||||
of an advantage over competing non-free programs. These disadvantages
|
||||
are the reason we use the ordinary General Public License for many
|
||||
libraries. However, the Lesser license provides advantages in certain
|
||||
special circumstances.
|
||||
|
||||
For example, on rare occasions, there may be a special need to
|
||||
encourage the widest possible use of a certain library, so that it becomes
|
||||
a de-facto standard. To achieve this, non-free programs must be
|
||||
allowed to use the library. A more frequent case is that a free
|
||||
library does the same job as widely used non-free libraries. In this
|
||||
case, there is little to gain by limiting the free library to free
|
||||
software only, so we use the Lesser General Public License.
|
||||
|
||||
In other cases, permission to use a particular library in non-free
|
||||
programs enables a greater number of people to use a large body of
|
||||
free software. For example, permission to use the GNU C Library in
|
||||
non-free programs enables many more people to use the whole GNU
|
||||
operating system, as well as its variant, the GNU/Linux operating
|
||||
system.
|
||||
|
||||
Although the Lesser General Public License is Less protective of the
|
||||
users' freedom, it does ensure that the user of a program that is
|
||||
linked with the Library has the freedom and the wherewithal to run
|
||||
that program using a modified version of the Library.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow. Pay close attention to the difference between a
|
||||
"work based on the library" and a "work that uses the library". The
|
||||
former contains code derived from the library, whereas the latter must
|
||||
be combined with the library in order to run.
|
||||
|
||||
GNU LESSER GENERAL PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. This License Agreement applies to any software library or other
|
||||
program which contains a notice placed by the copyright holder or
|
||||
other authorized party saying it may be distributed under the terms of
|
||||
this Lesser General Public License (also called "this License").
|
||||
Each licensee is addressed as "you".
|
||||
|
||||
A "library" means a collection of software functions and/or data
|
||||
prepared so as to be conveniently linked with application programs
|
||||
(which use some of those functions and data) to form executables.
|
||||
|
||||
The "Library", below, refers to any such software library or work
|
||||
which has been distributed under these terms. A "work based on the
|
||||
Library" means either the Library or any derivative work under
|
||||
copyright law: that is to say, a work containing the Library or a
|
||||
portion of it, either verbatim or with modifications and/or translated
|
||||
straightforwardly into another language. (Hereinafter, translation is
|
||||
included without limitation in the term "modification".)
|
||||
|
||||
"Source code" for a work means the preferred form of the work for
|
||||
making modifications to it. For a library, complete source code means
|
||||
all the source code for all modules it contains, plus any associated
|
||||
interface definition files, plus the scripts used to control compilation
|
||||
and installation of the library.
|
||||
|
||||
Activities other than copying, distribution and modification are not
|
||||
covered by this License; they are outside its scope. The act of
|
||||
running a program using the Library is not restricted, and output from
|
||||
such a program is covered only if its contents constitute a work based
|
||||
on the Library (independent of the use of the Library in a tool for
|
||||
writing it). Whether that is true depends on what the Library does
|
||||
and what the program that uses the Library does.
|
||||
|
||||
1. You may copy and distribute verbatim copies of the Library's
|
||||
complete source code as you receive it, in any medium, provided that
|
||||
you conspicuously and appropriately publish on each copy an
|
||||
appropriate copyright notice and disclaimer of warranty; keep intact
|
||||
all the notices that refer to this License and to the absence of any
|
||||
warranty; and distribute a copy of this License along with the
|
||||
Library.
|
||||
|
||||
You may charge a fee for the physical act of transferring a copy,
|
||||
and you may at your option offer warranty protection in exchange for a
|
||||
fee.
|
||||
|
||||
2. You may modify your copy or copies of the Library or any portion
|
||||
of it, thus forming a work based on the Library, and copy and
|
||||
distribute such modifications or work under the terms of Section 1
|
||||
above, provided that you also meet all of these conditions:
|
||||
|
||||
a) The modified work must itself be a software library.
|
||||
|
||||
b) You must cause the files modified to carry prominent notices
|
||||
stating that you changed the files and the date of any change.
|
||||
|
||||
c) You must cause the whole of the work to be licensed at no
|
||||
charge to all third parties under the terms of this License.
|
||||
|
||||
d) If a facility in the modified Library refers to a function or a
|
||||
table of data to be supplied by an application program that uses
|
||||
the facility, other than as an argument passed when the facility
|
||||
is invoked, then you must make a good faith effort to ensure that,
|
||||
in the event an application does not supply such function or
|
||||
table, the facility still operates, and performs whatever part of
|
||||
its purpose remains meaningful.
|
||||
|
||||
(For example, a function in a library to compute square roots has
|
||||
a purpose that is entirely well-defined independent of the
|
||||
application. Therefore, Subsection 2d requires that any
|
||||
application-supplied function or table used by this function must
|
||||
be optional: if the application does not supply it, the square
|
||||
root function must still compute square roots.)
|
||||
|
||||
These requirements apply to the modified work as a whole. If
|
||||
identifiable sections of that work are not derived from the Library,
|
||||
and can be reasonably considered independent and separate works in
|
||||
themselves, then this License, and its terms, do not apply to those
|
||||
sections when you distribute them as separate works. But when you
|
||||
distribute the same sections as part of a whole which is a work based
|
||||
on the Library, the distribution of the whole must be on the terms of
|
||||
this License, whose permissions for other licensees extend to the
|
||||
entire whole, and thus to each and every part regardless of who wrote
|
||||
it.
|
||||
|
||||
Thus, it is not the intent of this section to claim rights or contest
|
||||
your rights to work written entirely by you; rather, the intent is to
|
||||
exercise the right to control the distribution of derivative or
|
||||
collective works based on the Library.
|
||||
|
||||
In addition, mere aggregation of another work not based on the Library
|
||||
with the Library (or with a work based on the Library) on a volume of
|
||||
a storage or distribution medium does not bring the other work under
|
||||
the scope of this License.
|
||||
|
||||
3. You may opt to apply the terms of the ordinary GNU General Public
|
||||
License instead of this License to a given copy of the Library. To do
|
||||
this, you must alter all the notices that refer to this License, so
|
||||
that they refer to the ordinary GNU General Public License, version 2,
|
||||
instead of to this License. (If a newer version than version 2 of the
|
||||
ordinary GNU General Public License has appeared, then you can specify
|
||||
that version instead if you wish.) Do not make any other change in
|
||||
these notices.
|
||||
|
||||
Once this change is made in a given copy, it is irreversible for
|
||||
that copy, so the ordinary GNU General Public License applies to all
|
||||
subsequent copies and derivative works made from that copy.
|
||||
|
||||
This option is useful when you wish to copy part of the code of
|
||||
the Library into a program that is not a library.
|
||||
|
||||
4. You may copy and distribute the Library (or a portion or
|
||||
derivative of it, under Section 2) in object code or executable form
|
||||
under the terms of Sections 1 and 2 above provided that you accompany
|
||||
it with the complete corresponding machine-readable source code, which
|
||||
must be distributed under the terms of Sections 1 and 2 above on a
|
||||
medium customarily used for software interchange.
|
||||
|
||||
If distribution of object code is made by offering access to copy
|
||||
from a designated place, then offering equivalent access to copy the
|
||||
source code from the same place satisfies the requirement to
|
||||
distribute the source code, even though third parties are not
|
||||
compelled to copy the source along with the object code.
|
||||
|
||||
5. A program that contains no derivative of any portion of the
|
||||
Library, but is designed to work with the Library by being compiled or
|
||||
linked with it, is called a "work that uses the Library". Such a
|
||||
work, in isolation, is not a derivative work of the Library, and
|
||||
therefore falls outside the scope of this License.
|
||||
|
||||
However, linking a "work that uses the Library" with the Library
|
||||
creates an executable that is a derivative of the Library (because it
|
||||
contains portions of the Library), rather than a "work that uses the
|
||||
library". The executable is therefore covered by this License.
|
||||
Section 6 states terms for distribution of such executables.
|
||||
|
||||
When a "work that uses the Library" uses material from a header file
|
||||
that is part of the Library, the object code for the work may be a
|
||||
derivative work of the Library even though the source code is not.
|
||||
Whether this is true is especially significant if the work can be
|
||||
linked without the Library, or if the work is itself a library. The
|
||||
threshold for this to be true is not precisely defined by law.
|
||||
|
||||
If such an object file uses only numerical parameters, data
|
||||
structure layouts and accessors, and small macros and small inline
|
||||
functions (ten lines or less in length), then the use of the object
|
||||
file is unrestricted, regardless of whether it is legally a derivative
|
||||
work. (Executables containing this object code plus portions of the
|
||||
Library will still fall under Section 6.)
|
||||
|
||||
Otherwise, if the work is a derivative of the Library, you may
|
||||
distribute the object code for the work under the terms of Section 6.
|
||||
Any executables containing that work also fall under Section 6,
|
||||
whether or not they are linked directly with the Library itself.
|
||||
|
||||
6. As an exception to the Sections above, you may also combine or
|
||||
link a "work that uses the Library" with the Library to produce a
|
||||
work containing portions of the Library, and distribute that work
|
||||
under terms of your choice, provided that the terms permit
|
||||
modification of the work for the customer's own use and reverse
|
||||
engineering for debugging such modifications.
|
||||
|
||||
You must give prominent notice with each copy of the work that the
|
||||
Library is used in it and that the Library and its use are covered by
|
||||
this License. You must supply a copy of this License. If the work
|
||||
during execution displays copyright notices, you must include the
|
||||
copyright notice for the Library among them, as well as a reference
|
||||
directing the user to the copy of this License. Also, you must do one
|
||||
of these things:
|
||||
|
||||
a) Accompany the work with the complete corresponding
|
||||
machine-readable source code for the Library including whatever
|
||||
changes were used in the work (which must be distributed under
|
||||
Sections 1 and 2 above); and, if the work is an executable linked
|
||||
with the Library, with the complete machine-readable "work that
|
||||
uses the Library", as object code and/or source code, so that the
|
||||
user can modify the Library and then relink to produce a modified
|
||||
executable containing the modified Library. (It is understood
|
||||
that the user who changes the contents of definitions files in the
|
||||
Library will not necessarily be able to recompile the application
|
||||
to use the modified definitions.)
|
||||
|
||||
b) Use a suitable shared library mechanism for linking with the
|
||||
Library. A suitable mechanism is one that (1) uses at run time a
|
||||
copy of the library already present on the user's computer system,
|
||||
rather than copying library functions into the executable, and (2)
|
||||
will operate properly with a modified version of the library, if
|
||||
the user installs one, as long as the modified version is
|
||||
interface-compatible with the version that the work was made with.
|
||||
|
||||
c) Accompany the work with a written offer, valid for at
|
||||
least three years, to give the same user the materials
|
||||
specified in Subsection 6a, above, for a charge no more
|
||||
than the cost of performing this distribution.
|
||||
|
||||
d) If distribution of the work is made by offering access to copy
|
||||
from a designated place, offer equivalent access to copy the above
|
||||
specified materials from the same place.
|
||||
|
||||
e) Verify that the user has already received a copy of these
|
||||
materials or that you have already sent this user a copy.
|
||||
|
||||
For an executable, the required form of the "work that uses the
|
||||
Library" must include any data and utility programs needed for
|
||||
reproducing the executable from it. However, as a special exception,
|
||||
the materials to be distributed need not include anything that is
|
||||
normally distributed (in either source or binary form) with the major
|
||||
components (compiler, kernel, and so on) of the operating system on
|
||||
which the executable runs, unless that component itself accompanies
|
||||
the executable.
|
||||
|
||||
It may happen that this requirement contradicts the license
|
||||
restrictions of other proprietary libraries that do not normally
|
||||
accompany the operating system. Such a contradiction means you cannot
|
||||
use both them and the Library together in an executable that you
|
||||
distribute.
|
||||
|
||||
7. You may place library facilities that are a work based on the
|
||||
Library side-by-side in a single library together with other library
|
||||
facilities not covered by this License, and distribute such a combined
|
||||
library, provided that the separate distribution of the work based on
|
||||
the Library and of the other library facilities is otherwise
|
||||
permitted, and provided that you do these two things:
|
||||
|
||||
a) Accompany the combined library with a copy of the same work
|
||||
based on the Library, uncombined with any other library
|
||||
facilities. This must be distributed under the terms of the
|
||||
Sections above.
|
||||
|
||||
b) Give prominent notice with the combined library of the fact
|
||||
that part of it is a work based on the Library, and explaining
|
||||
where to find the accompanying uncombined form of the same work.
|
||||
|
||||
8. You may not copy, modify, sublicense, link with, or distribute
|
||||
the Library except as expressly provided under this License. Any
|
||||
attempt otherwise to copy, modify, sublicense, link with, or
|
||||
distribute the Library is void, and will automatically terminate your
|
||||
rights under this License. However, parties who have received copies,
|
||||
or rights, from you under this License will not have their licenses
|
||||
terminated so long as such parties remain in full compliance.
|
||||
|
||||
9. You are not required to accept this License, since you have not
|
||||
signed it. However, nothing else grants you permission to modify or
|
||||
distribute the Library or its derivative works. These actions are
|
||||
prohibited by law if you do not accept this License. Therefore, by
|
||||
modifying or distributing the Library (or any work based on the
|
||||
Library), you indicate your acceptance of this License to do so, and
|
||||
all its terms and conditions for copying, distributing or modifying
|
||||
the Library or works based on it.
|
||||
|
||||
10. Each time you redistribute the Library (or any work based on the
|
||||
Library), the recipient automatically receives a license from the
|
||||
original licensor to copy, distribute, link with or modify the Library
|
||||
subject to these terms and conditions. You may not impose any further
|
||||
restrictions on the recipients' exercise of the rights granted herein.
|
||||
You are not responsible for enforcing compliance by third parties with
|
||||
this License.
|
||||
|
||||
11. If, as a consequence of a court judgment or allegation of patent
|
||||
infringement or for any other reason (not limited to patent issues),
|
||||
conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot
|
||||
distribute so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you
|
||||
may not distribute the Library at all. For example, if a patent
|
||||
license would not permit royalty-free redistribution of the Library by
|
||||
all those who receive copies directly or indirectly through you, then
|
||||
the only way you could satisfy both it and this License would be to
|
||||
refrain entirely from distribution of the Library.
|
||||
|
||||
If any portion of this section is held invalid or unenforceable under any
|
||||
particular circumstance, the balance of the section is intended to apply,
|
||||
and the section as a whole is intended to apply in other circumstances.
|
||||
|
||||
It is not the purpose of this section to induce you to infringe any
|
||||
patents or other property right claims or to contest validity of any
|
||||
such claims; this section has the sole purpose of protecting the
|
||||
integrity of the free software distribution system which is
|
||||
implemented by public license practices. Many people have made
|
||||
generous contributions to the wide range of software distributed
|
||||
through that system in reliance on consistent application of that
|
||||
system; it is up to the author/donor to decide if he or she is willing
|
||||
to distribute software through any other system and a licensee cannot
|
||||
impose that choice.
|
||||
|
||||
This section is intended to make thoroughly clear what is believed to
|
||||
be a consequence of the rest of this License.
|
||||
|
||||
12. If the distribution and/or use of the Library is restricted in
|
||||
certain countries either by patents or by copyrighted interfaces, the
|
||||
original copyright holder who places the Library under this License may add
|
||||
an explicit geographical distribution limitation excluding those countries,
|
||||
so that distribution is permitted only in or among countries not thus
|
||||
excluded. In such case, this License incorporates the limitation as if
|
||||
written in the body of this License.
|
||||
|
||||
13. The Free Software Foundation may publish revised and/or new
|
||||
versions of the Lesser General Public License from time to time.
|
||||
Such new versions will be similar in spirit to the present version,
|
||||
but may differ in detail to address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the Library
|
||||
specifies a version number of this License which applies to it and
|
||||
"any later version", you have the option of following the terms and
|
||||
conditions either of that version or of any later version published by
|
||||
the Free Software Foundation. If the Library does not specify a
|
||||
license version number, you may choose any version ever published by
|
||||
the Free Software Foundation.
|
||||
|
||||
14. If you wish to incorporate parts of the Library into other free
|
||||
programs whose distribution conditions are incompatible with these,
|
||||
write to the author to ask for permission. For software which is
|
||||
copyrighted by the Free Software Foundation, write to the Free
|
||||
Software Foundation; we sometimes make exceptions for this. Our
|
||||
decision will be guided by the two goals of preserving the free status
|
||||
of all derivatives of our free software and of promoting the sharing
|
||||
and reuse of software generally.
|
||||
|
||||
NO WARRANTY
|
||||
|
||||
15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
|
||||
WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
|
||||
EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
|
||||
OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
|
||||
KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
|
||||
LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
|
||||
THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
|
||||
WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
|
||||
AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
|
||||
FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
|
||||
CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
|
||||
LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
|
||||
RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
|
||||
FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
|
||||
SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
|
||||
DAMAGES.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Libraries
|
||||
|
||||
If you develop a new library, and you want it to be of the greatest
|
||||
possible use to the public, we recommend making it free software that
|
||||
everyone can redistribute and change. You can do so by permitting
|
||||
redistribution under these terms (or, alternatively, under the terms of the
|
||||
ordinary General Public License).
|
||||
|
||||
To apply these terms, attach the following notices to the library. It is
|
||||
safest to attach them to the start of each source file to most effectively
|
||||
convey the exclusion of warranty; and each file should have at least the
|
||||
"copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the library's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or your
|
||||
school, if any, to sign a "copyright disclaimer" for the library, if
|
||||
necessary. Here is a sample; alter the names:
|
||||
|
||||
Yoyodyne, Inc., hereby disclaims all copyright interest in the
|
||||
library `Frob' (a library for tweaking knobs) written by James Random Hacker.
|
||||
|
||||
<signature of Ty Coon>, 1 April 1990
|
||||
Ty Coon, President of Vice
|
||||
|
||||
That's all there is to it!
|
||||
|
10
Makefile
Normal file
10
Makefile
Normal file
@ -0,0 +1,10 @@
|
||||
XBE_TITLE = nxdk_texture_format_tests
|
||||
GEN_XISO = $(XBE_TITLE).iso
|
||||
SRCS = $(CURDIR)/math3d.c $(CURDIR)/main.c $(CURDIR)/swizzle.c
|
||||
SHADER_OBJS = ps.inl vs.inl
|
||||
NXDK_DIR ?= $(CURDIR)/../nxdk
|
||||
NXDK_SDL = y
|
||||
NXDK_CXX = y
|
||||
|
||||
include $(NXDK_DIR)/Makefile
|
||||
|
21
README.md
Normal file
21
README.md
Normal file
@ -0,0 +1,21 @@
|
||||
texture-formats
|
||||
====
|
||||
|
||||
Various tests for nv2a rendering.
|
||||
|
||||
Original code from https://github.com/Ernegien/nxdk/tree/test/texture-formats/samples/texture-formats
|
||||
|
||||
## Running with CLion
|
||||
|
||||
Create a build target
|
||||
|
||||
1. Create a new `Embedded GDB Server` target
|
||||
1. Set the Target to `all`
|
||||
1. Set the Executable to `main.exe`
|
||||
1. Set `Download executable` to `None`
|
||||
1. Set `'target remote' args` to `127.0.0.1:1234`
|
||||
1. Set `GDB Server` to the path to the xemu binary
|
||||
1. Set `GDB Server args` to `-s -S` (the `-S` is optional and will cause xemu to wait for the debugger to connnect)
|
||||
|
||||
To capture DbgPrint, additionally append `-device lpc47m157 -serial tcp:127.0.0.1:9091` to `GDB Server args` and use
|
||||
something like [pykdclient](https://github.com/abaire/pykdclient).
|
552
main.c
Normal file
552
main.c
Normal file
@ -0,0 +1,552 @@
|
||||
/*
|
||||
* This sample provides a very basic demonstration of 3D rendering on the Xbox,
|
||||
* using pbkit. Based on the pbkit demo sources.
|
||||
*/
|
||||
#include <hal/video.h>
|
||||
#include <hal/xbox.h>
|
||||
#define _USE_MATH_DEFINES
|
||||
#include <math.h>
|
||||
#include <pbkit/pbkit.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <strings.h>
|
||||
#include <windows.h>
|
||||
#include <xboxkrnl/xboxkrnl.h>
|
||||
#include <hal/debug.h>
|
||||
#include "math3d.h"
|
||||
#include <SDL.h>
|
||||
#include <SDL_image.h>
|
||||
#include "swizzle.h"
|
||||
|
||||
typedef struct TextureFormatInfo {
|
||||
SDL_PixelFormatEnum SdlFormat;
|
||||
uint32_t XboxFormat;
|
||||
uint16_t XboxBpp; // bytes per pixel
|
||||
bool XboxSwizzled;
|
||||
bool RequireConversion;
|
||||
char* Name;
|
||||
} TextureFormatInfo;
|
||||
|
||||
#pragma pack(1)
|
||||
typedef struct Vertex {
|
||||
float pos[3];
|
||||
float texcoord[2];
|
||||
float normal[3];
|
||||
} Vertex;
|
||||
|
||||
#pragma pack()
|
||||
|
||||
static Vertex *alloc_vertices; // texcoords 0 to width/height
|
||||
static Vertex *alloc_vertices_swizzled; // texcoords normalized 0 to 1
|
||||
static uint32_t num_vertices;
|
||||
|
||||
MATRIX m_model, m_view, m_proj;
|
||||
|
||||
VECTOR v_cam_pos = { 0, 0.05, 1.07, 1 };
|
||||
VECTOR v_cam_rot = { 0, 0, 0, 1 };
|
||||
VECTOR v_light_dir = { 0, 0, 1, 1 };
|
||||
|
||||
#include "verts.h"
|
||||
#include "texture.h"
|
||||
|
||||
#define MASK(mask, val) (((val) << (ffs(mask)-1)) & (mask))
|
||||
#define MAXRAM 0x03FFAFFF
|
||||
|
||||
// TODO: upstream missing nv2a defines
|
||||
#define NV2A_VERTEX_ATTR_POSITION 0
|
||||
#define NV2A_VERTEX_ATTR_NORMAL 2
|
||||
#define NV2A_VERTEX_ATTR_TEXTURE0 9
|
||||
#define NV097_SET_TEXTURE_FORMAT_COLOR_LU_IMAGE_G8B8 0x17
|
||||
#define NV097_SET_TEXTURE_FORMAT_COLOR_SZ_B8G8R8A8 0x3B
|
||||
#define NV097_SET_TEXTURE_FORMAT_COLOR_LC_IMAGE_CR8YB8CB8YA8 0x24
|
||||
#define NV097_SET_TEXTURE_FORMAT_COLOR_LC_IMAGE_YB8CR8YA8CB8 0x25
|
||||
#define NV097_SET_TEXTURE_FORMAT_COLOR_D16 0x2C // TODO: proper nvidia name
|
||||
#define NV097_SET_TEXTURE_FORMAT_COLOR_LIN_F16 0x31 // TODO: proper nvidia name
|
||||
#define NV097_SET_CONTROL0_COLOR_SPACE_CONVERT 0xF0000000
|
||||
#define NV097_SET_CONTROL0_COLOR_SPACE_CONVERT_CRYCB_TO_RGB 0x1
|
||||
|
||||
static void matrix_viewport(float out[4][4], float x, float y, float width, float height, float z_min, float z_max);
|
||||
static void init_shader(void);
|
||||
static void init_textures(void);
|
||||
static void set_attrib_pointer(unsigned int index, unsigned int format, unsigned int size, unsigned int stride, const void* data);
|
||||
static void draw_arrays(unsigned int mode, int start, int count);
|
||||
static int update_texture_memory(void* texMem, TextureFormatInfo format, int width, int height);
|
||||
|
||||
static const TextureFormatInfo format_map[] = {
|
||||
|
||||
// swizzled
|
||||
{ SDL_PIXELFORMAT_ABGR8888, NV097_SET_TEXTURE_FORMAT_COLOR_SZ_A8B8G8R8, 4, true, false, "A8B8G8R8" },
|
||||
{ SDL_PIXELFORMAT_RGBA8888, NV097_SET_TEXTURE_FORMAT_COLOR_SZ_R8G8B8A8, 4, true, false, "R8G8B8A8" },
|
||||
{ SDL_PIXELFORMAT_ARGB8888, NV097_SET_TEXTURE_FORMAT_COLOR_SZ_A8R8G8B8, 4, true, false, "A8R8G8B8" },
|
||||
{ SDL_PIXELFORMAT_ARGB8888, NV097_SET_TEXTURE_FORMAT_COLOR_SZ_X8R8G8B8, 4, true, false, "X8R8G8B8" },
|
||||
{ SDL_PIXELFORMAT_BGRA8888, NV097_SET_TEXTURE_FORMAT_COLOR_SZ_B8G8R8A8, 4, true, false, "B8G8R8A8" },
|
||||
{ SDL_PIXELFORMAT_RGB565, NV097_SET_TEXTURE_FORMAT_COLOR_SZ_R5G6B5, 2, true, false, "R5G6B5" },
|
||||
{ SDL_PIXELFORMAT_ARGB1555, NV097_SET_TEXTURE_FORMAT_COLOR_SZ_A1R5G5B5, 2, true, false, "A1R5G5B5" },
|
||||
{ SDL_PIXELFORMAT_ARGB1555, NV097_SET_TEXTURE_FORMAT_COLOR_SZ_X1R5G5B5, 2, true, false, "X1R5G5B5" },
|
||||
{ SDL_PIXELFORMAT_ARGB4444, NV097_SET_TEXTURE_FORMAT_COLOR_SZ_A4R4G4B4, 2, true, false, "A4R4G4B4" },
|
||||
|
||||
// linear unsigned
|
||||
{ SDL_PIXELFORMAT_ABGR8888, NV097_SET_TEXTURE_FORMAT_COLOR_LU_IMAGE_A8B8G8R8, 4, false, false, "A8B8G8R8" },
|
||||
{ SDL_PIXELFORMAT_RGBA8888, NV097_SET_TEXTURE_FORMAT_COLOR_LU_IMAGE_R8G8B8A8, 4, false, false, "R8G8B8A8" },
|
||||
{ SDL_PIXELFORMAT_ARGB8888, NV097_SET_TEXTURE_FORMAT_COLOR_LU_IMAGE_A8R8G8B8, 4, false, false, "A8R8G8B8" },
|
||||
{ SDL_PIXELFORMAT_ARGB8888, NV097_SET_TEXTURE_FORMAT_COLOR_LU_IMAGE_X8R8G8B8, 4, false, false, "X8R8G8B8" },
|
||||
{ SDL_PIXELFORMAT_BGRA8888, NV097_SET_TEXTURE_FORMAT_COLOR_LU_IMAGE_B8G8R8A8, 4, false, false, "B8G8R8A8" },
|
||||
{ SDL_PIXELFORMAT_RGB565, NV097_SET_TEXTURE_FORMAT_COLOR_LU_IMAGE_R5G6B5, 2, false, false, "R5G6B5" },
|
||||
{ SDL_PIXELFORMAT_ARGB1555, NV097_SET_TEXTURE_FORMAT_COLOR_LU_IMAGE_A1R5G5B5, 2, false, false, "A1R5G5B5" },
|
||||
{ SDL_PIXELFORMAT_ARGB1555, NV097_SET_TEXTURE_FORMAT_COLOR_LU_IMAGE_X1R5G5B5, 2, false, false, "X1R5G5B5" },
|
||||
{ SDL_PIXELFORMAT_ARGB4444, NV097_SET_TEXTURE_FORMAT_COLOR_LU_IMAGE_A4R4G4B4, 2, false, false, "A4R4G4B4" },
|
||||
|
||||
// yuv color space
|
||||
// Each 4 bytes represent the color for 2 neighboring pixels:
|
||||
// [ U0 | Y0 | V0 | Y1 ]
|
||||
// Y0 is the brightness of pixel 0, Y1 the brightness of pixel 1.
|
||||
// U0 and V0 is the color of both pixels. (second pixel is the one sampled? or averaged? doesn't really matter here)
|
||||
// https://docs.microsoft.com/en-us/windows/win32/medfound/recommended-8-bit-yuv-formats-for-video-rendering#converting-8-bit-yuv-to-rgb888
|
||||
{ SDL_PIXELFORMAT_BGRA8888, NV097_SET_TEXTURE_FORMAT_COLOR_LC_IMAGE_CR8YB8CB8YA8, 2, false, true, "YUY2" },
|
||||
{ SDL_PIXELFORMAT_BGRA8888, NV097_SET_TEXTURE_FORMAT_COLOR_LC_IMAGE_YB8CR8YA8CB8, 2, false, true, "UYVY" },
|
||||
|
||||
//{ SDL_PIXELFORMAT_RGBA8888, NV097_SET_TEXTURE_FORMAT_COLOR_LU_IMAGE_Y16, false, true, "Y16" },
|
||||
//{ SDL_PIXELFORMAT_RGBA8888, NV097_SET_TEXTURE_FORMAT_COLOR_SZ_Y8, true, true, "SZ_Y8" },
|
||||
//{ SDL_PIXELFORMAT_RGBA8888, NV097_SET_TEXTURE_FORMAT_COLOR_LU_IMAGE_Y8, false, true, "Y8" },
|
||||
//{ SDL_PIXELFORMAT_RGBA8888, NV097_SET_TEXTURE_FORMAT_COLOR_SZ_AY8, true, true, "SZ_AY8" },
|
||||
//{ SDL_PIXELFORMAT_RGBA8888, NV097_SET_TEXTURE_FORMAT_COLOR_LU_IMAGE_AY8, false, true, "AY8" },
|
||||
//{ SDL_PIXELFORMAT_RGBA8888, NV097_SET_TEXTURE_FORMAT_COLOR_SZ_A8, true, true, "SZ_A8" },
|
||||
//{ SDL_PIXELFORMAT_RGBA8888, NV097_SET_TEXTURE_FORMAT_COLOR_SZ_A8Y8, true, true, "SZ_A8Y8" },
|
||||
|
||||
// misc formats
|
||||
//{ SDL_PIXELFORMAT_RGBA8888, NV097_SET_TEXTURE_FORMAT_COLOR_L_DXT1_A1R5G5B5, false, true, "DXT1" },
|
||||
//{ SDL_PIXELFORMAT_RGBA8888, NV097_SET_TEXTURE_FORMAT_COLOR_L_DXT23_A8R8G8B8, false, true, "DXT3" },
|
||||
//{ SDL_PIXELFORMAT_RGBA8888, NV097_SET_TEXTURE_FORMAT_COLOR_L_DXT45_A8R8G8B8, false, true, "DXT5" },
|
||||
//{ SDL_PIXELFORMAT_RGBA8888, NV097_SET_TEXTURE_FORMAT_COLOR_SZ_G8B8, true, true, "SZ_G8B8" },
|
||||
{ SDL_PIXELFORMAT_RGBA8888, NV097_SET_TEXTURE_FORMAT_COLOR_LU_IMAGE_G8B8, 2, false, true, "G8B8" },
|
||||
//{ SDL_PIXELFORMAT_RGBA8888, NV097_SET_TEXTURE_FORMAT_COLOR_D16, false, true, "D16" }, // TODO: implement in xemu
|
||||
//{ SDL_PIXELFORMAT_RGBA8888, NV097_SET_TEXTURE_FORMAT_COLOR_LIN_F16, false, true, "LIN_F16" }, // TODO: implement in xemu
|
||||
//{ SDL_PIXELFORMAT_RGBA8888, NV097_SET_TEXTURE_FORMAT_COLOR_SZ_R8B8, true, true, "SZ_R8B8" },
|
||||
//{ SDL_PIXELFORMAT_RGBA8888, NV097_SET_TEXTURE_FORMAT_COLOR_SZ_R6G5B5, true, true, "R6G5B5" }
|
||||
|
||||
// TODO: define others here
|
||||
};
|
||||
|
||||
// bitscan forward
|
||||
int bsf(int val) {
|
||||
__asm bsf eax, val
|
||||
}
|
||||
|
||||
/* Main program function */
|
||||
int main(void)
|
||||
{
|
||||
uint32_t *p;
|
||||
int i, status;
|
||||
int width = 640, height = 480;
|
||||
float m_viewport[4][4];
|
||||
int format_map_index = 0;
|
||||
bool toggleFormat;
|
||||
int texWidth = 256, texHeight = 256;
|
||||
SDL_GameController *gameController;
|
||||
|
||||
XVideoSetMode(width, height, 32, REFRESH_DEFAULT);
|
||||
|
||||
// initialize input for the first gamepad
|
||||
SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER);
|
||||
gameController = SDL_GameControllerOpen(0);
|
||||
if (!gameController) {
|
||||
debugPrint("Failed to initialize input for gamepad 0");
|
||||
Sleep(2000);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if ((status = pb_init())) {
|
||||
debugPrint("pb_init Error %d\n", status);
|
||||
Sleep(2000);
|
||||
return 1;
|
||||
}
|
||||
|
||||
pb_show_front_screen();
|
||||
|
||||
/* Load constant rendering things (shaders, geometry) */
|
||||
init_shader();
|
||||
|
||||
// real nv2a hardware seems to cache this and not honor updates? have separate vertex buffers for swizzled and linear for now...
|
||||
alloc_vertices = MmAllocateContiguousMemoryEx(sizeof(vertices), 0, MAXRAM, 0, PAGE_WRITECOMBINE | PAGE_READWRITE);
|
||||
alloc_vertices_swizzled = MmAllocateContiguousMemoryEx(sizeof(vertices), 0, MAXRAM, 0, PAGE_WRITECOMBINE | PAGE_READWRITE);
|
||||
memcpy(alloc_vertices, vertices, sizeof(vertices));
|
||||
memcpy(alloc_vertices_swizzled, vertices, sizeof(vertices));
|
||||
num_vertices = sizeof(vertices)/sizeof(vertices[0]);
|
||||
for (int i = 0; i < num_vertices; i++) {
|
||||
if (alloc_vertices[i].texcoord[0]) alloc_vertices[i].texcoord[0] = texWidth * 1.0f;
|
||||
if (alloc_vertices[i].texcoord[1]) alloc_vertices[i].texcoord[1] = texHeight * 1.0f;
|
||||
}
|
||||
|
||||
// allocate texture memory buffer large enough for all types
|
||||
void *texMem = MmAllocateContiguousMemoryEx(texWidth * texHeight * 4, 0, MAXRAM, 0, PAGE_WRITECOMBINE | PAGE_READWRITE);
|
||||
int texError = update_texture_memory(texMem, format_map[format_map_index], texWidth, texHeight);
|
||||
|
||||
/* Create view matrix (our camera is static) */
|
||||
matrix_unit(m_view);
|
||||
create_world_view(m_view, v_cam_pos, v_cam_rot);
|
||||
|
||||
/* Create projection matrix */
|
||||
matrix_unit(m_proj);
|
||||
create_view_screen(m_proj, (float)width/(float)height, -1.0f, 1.0f, -1.0f, 1.0f, 1.0f, 10000.0f);
|
||||
|
||||
/* Create viewport matrix, combine with projection */
|
||||
matrix_viewport(m_viewport, 0, 0, width, height, 0, 65536.0f);
|
||||
matrix_multiply(m_proj, m_proj, (float*)m_viewport);
|
||||
|
||||
/* Create local->world matrix given our updated object */
|
||||
matrix_unit(m_model);
|
||||
|
||||
while(1) {
|
||||
|
||||
// cycle current texture based on A or B button presses
|
||||
SDL_GameControllerUpdate();
|
||||
bool aPress = SDL_GameControllerGetButton(gameController, SDL_CONTROLLER_BUTTON_A);
|
||||
bool bPress = SDL_GameControllerGetButton(gameController, SDL_CONTROLLER_BUTTON_B);
|
||||
if (aPress || bPress) {
|
||||
if (toggleFormat) {
|
||||
// TODO: back doesn't wrap as intended, re-do logic
|
||||
format_map_index = (format_map_index + (aPress ? 1 : -1)) % (sizeof(format_map) / sizeof(format_map[0]));
|
||||
texError = update_texture_memory(texMem, format_map[format_map_index], texWidth, texHeight);
|
||||
}
|
||||
toggleFormat = false;
|
||||
} else toggleFormat = true;
|
||||
|
||||
pb_wait_for_vbl();
|
||||
pb_reset();
|
||||
pb_target_back_buffer();
|
||||
|
||||
/* Clear depth & stencil buffers */
|
||||
pb_erase_depth_stencil_buffer(0, 0, width, height);
|
||||
pb_fill(0, 0, width, height, 0xff000000);
|
||||
pb_erase_text_screen();
|
||||
|
||||
while(pb_busy()) {
|
||||
/* Wait for completion... */
|
||||
}
|
||||
|
||||
/*
|
||||
* Setup texture stages
|
||||
*/
|
||||
|
||||
/* Enable texture stage 0 */
|
||||
/* FIXME: Use constants instead of the hardcoded values below */
|
||||
p = pb_begin();
|
||||
|
||||
// first one seems to be needed
|
||||
p = pb_push1(p, NV097_SET_FRONT_FACE, NV097_SET_FRONT_FACE_V_CCW);
|
||||
p = pb_push1(p, NV097_SET_DEPTH_TEST_ENABLE, true);
|
||||
|
||||
// Enable alpha blending functionality
|
||||
p = pb_push1(p, NV097_SET_BLEND_ENABLE, true);
|
||||
|
||||
// Set the alpha blend source (s) and destination (d) factors
|
||||
p = pb_push1(p, NV097_SET_BLEND_FUNC_SFACTOR, NV097_SET_BLEND_FUNC_SFACTOR_V_SRC_ALPHA);
|
||||
p = pb_push1(p, NV097_SET_BLEND_FUNC_DFACTOR, NV097_SET_BLEND_FUNC_SFACTOR_V_ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
// yuv requires color space conversion
|
||||
if (format_map[format_map_index].XboxFormat == NV097_SET_TEXTURE_FORMAT_COLOR_LC_IMAGE_CR8YB8CB8YA8 ||
|
||||
format_map[format_map_index].XboxFormat == NV097_SET_TEXTURE_FORMAT_COLOR_LC_IMAGE_YB8CR8YA8CB8) {
|
||||
p = pb_push1(p, NV097_SET_CONTROL0,
|
||||
MASK(NV097_SET_CONTROL0_COLOR_SPACE_CONVERT, NV097_SET_CONTROL0_COLOR_SPACE_CONVERT_CRYCB_TO_RGB));
|
||||
}
|
||||
|
||||
DWORD format_mask = MASK(NV097_SET_TEXTURE_FORMAT_CONTEXT_DMA, 1) |
|
||||
MASK(NV097_SET_TEXTURE_FORMAT_CUBEMAP_ENABLE, 0) |
|
||||
MASK(NV097_SET_TEXTURE_FORMAT_BORDER_SOURCE, NV097_SET_TEXTURE_FORMAT_BORDER_SOURCE_COLOR) |
|
||||
MASK(NV097_SET_TEXTURE_FORMAT_DIMENSIONALITY, 2) |
|
||||
MASK(NV097_SET_TEXTURE_FORMAT_COLOR, format_map[format_map_index].XboxFormat) |
|
||||
MASK(NV097_SET_TEXTURE_FORMAT_MIPMAP_LEVELS, 1) |
|
||||
MASK(NV097_SET_TEXTURE_FORMAT_BASE_SIZE_U, format_map[format_map_index].XboxSwizzled ? bsf(texWidth) : 0) |
|
||||
MASK(NV097_SET_TEXTURE_FORMAT_BASE_SIZE_V, format_map[format_map_index].XboxSwizzled ? bsf(texHeight) : 0) |
|
||||
MASK(NV097_SET_TEXTURE_FORMAT_BASE_SIZE_P, 0);
|
||||
p = pb_push2(p,NV20_TCL_PRIMITIVE_3D_TX_OFFSET(0),(DWORD)texMem & 0x03ffffff,format_mask); //set stage 0 texture address & format
|
||||
if (!format_map[format_map_index].XboxSwizzled) {
|
||||
p = pb_push1(p,NV20_TCL_PRIMITIVE_3D_TX_NPOT_PITCH(0),(format_map[format_map_index].XboxBpp * texWidth)<<16); //set stage 0 texture pitch (pitch<<16)
|
||||
p = pb_push1(p,NV20_TCL_PRIMITIVE_3D_TX_NPOT_SIZE(0),(texWidth<<16)|texHeight); //set stage 0 texture width & height ((witdh<<16)|height)
|
||||
}
|
||||
p = pb_push1(p,NV20_TCL_PRIMITIVE_3D_TX_WRAP(0),0x00030303);//set stage 0 texture modes (0x0W0V0U wrapping: 1=wrap 2=mirror 3=clamp 4=border 5=clamp to edge)
|
||||
p = pb_push1(p,NV20_TCL_PRIMITIVE_3D_TX_ENABLE(0),0x4003ffc0); //set stage 0 texture enable flags
|
||||
p = pb_push1(p,NV20_TCL_PRIMITIVE_3D_TX_FILTER(0),0x04074000); //set stage 0 texture filters (AA!)
|
||||
|
||||
pb_end(p);
|
||||
|
||||
/* Disable other texture stages */
|
||||
p = pb_begin();
|
||||
p = pb_push1(p,NV20_TCL_PRIMITIVE_3D_TX_ENABLE(1),0x0003ffc0);//set stage 1 texture enable flags (bit30 disabled)
|
||||
p = pb_push1(p,NV20_TCL_PRIMITIVE_3D_TX_ENABLE(2),0x0003ffc0);//set stage 2 texture enable flags (bit30 disabled)
|
||||
p = pb_push1(p,NV20_TCL_PRIMITIVE_3D_TX_ENABLE(3),0x0003ffc0);//set stage 3 texture enable flags (bit30 disabled)
|
||||
p = pb_push1(p,NV20_TCL_PRIMITIVE_3D_TX_WRAP(1),0x00030303);//set stage 1 texture modes (0x0W0V0U wrapping: 1=wrap 2=mirror 3=clamp 4=border 5=clamp to edge)
|
||||
p = pb_push1(p,NV20_TCL_PRIMITIVE_3D_TX_WRAP(2),0x00030303);//set stage 2 texture modes (0x0W0V0U wrapping: 1=wrap 2=mirror 3=clamp 4=border 5=clamp to edge)
|
||||
p = pb_push1(p,NV20_TCL_PRIMITIVE_3D_TX_WRAP(3),0x00030303);//set stage 3 texture modes (0x0W0V0U wrapping: 1=wrap 2=mirror 3=clamp 4=border 5=clamp to edge)
|
||||
p = pb_push1(p,NV20_TCL_PRIMITIVE_3D_TX_FILTER(1),0x02022000);//set stage 1 texture filters (no AA, stage not even used)
|
||||
p = pb_push1(p,NV20_TCL_PRIMITIVE_3D_TX_FILTER(2),0x02022000);//set stage 2 texture filters (no AA, stage not even used)
|
||||
p = pb_push1(p,NV20_TCL_PRIMITIVE_3D_TX_FILTER(3),0x02022000);//set stage 3 texture filters (no AA, stage not even used)
|
||||
pb_end(p);
|
||||
|
||||
/* Send shader constants
|
||||
*
|
||||
* WARNING: Changing shader source code may impact constant locations!
|
||||
* Check the intermediate file (*.inl) for the expected locations after
|
||||
* changing the code.
|
||||
*/
|
||||
p = pb_begin();
|
||||
|
||||
/* Set shader constants cursor at C0 */
|
||||
p = pb_push1(p, NV20_TCL_PRIMITIVE_3D_VP_UPLOAD_CONST_ID, 96);
|
||||
|
||||
/* Send the model matrix */
|
||||
pb_push(p++, NV20_TCL_PRIMITIVE_3D_VP_UPLOAD_CONST_X, 16);
|
||||
memcpy(p, m_model, 16*4); p+=16;
|
||||
|
||||
/* Send the view matrix */
|
||||
pb_push(p++, NV20_TCL_PRIMITIVE_3D_VP_UPLOAD_CONST_X, 16);
|
||||
memcpy(p, m_view, 16*4); p+=16;
|
||||
|
||||
/* Send the projection matrix */
|
||||
pb_push(p++, NV20_TCL_PRIMITIVE_3D_VP_UPLOAD_CONST_X, 16);
|
||||
memcpy(p, m_proj, 16*4); p+=16;
|
||||
|
||||
/* Send camera position */
|
||||
pb_push(p++, NV20_TCL_PRIMITIVE_3D_VP_UPLOAD_CONST_X, 4);
|
||||
memcpy(p, v_cam_pos, 4*4); p+=4;
|
||||
|
||||
/* Send light direction */
|
||||
pb_push(p++, NV20_TCL_PRIMITIVE_3D_VP_UPLOAD_CONST_X, 4);
|
||||
memcpy(p, v_light_dir, 4*4); p+=4;
|
||||
|
||||
/* Send shader constants */
|
||||
float constants_0[4] = {0, 0, 0, 0};
|
||||
pb_push(p++, NV20_TCL_PRIMITIVE_3D_VP_UPLOAD_CONST_X, 4);
|
||||
memcpy(p, constants_0, 4*4); p+=4;
|
||||
|
||||
/* Clear all attributes */
|
||||
pb_push(p++,NV097_SET_VERTEX_DATA_ARRAY_FORMAT,16);
|
||||
for(i = 0; i < 16; i++) {
|
||||
*(p++) = 2;
|
||||
}
|
||||
pb_end(p);
|
||||
|
||||
/*
|
||||
* Setup vertex attributes
|
||||
*/
|
||||
|
||||
Vertex *vptr = format_map[format_map_index].XboxSwizzled ? alloc_vertices_swizzled : alloc_vertices;
|
||||
|
||||
/* Set vertex position attribute */
|
||||
set_attrib_pointer(NV2A_VERTEX_ATTR_POSITION, NV097_SET_VERTEX_DATA_ARRAY_FORMAT_TYPE_F,
|
||||
3, sizeof(Vertex), &vptr[0].pos);
|
||||
|
||||
/* Set texture coordinate attribute */
|
||||
set_attrib_pointer(NV2A_VERTEX_ATTR_TEXTURE0, NV097_SET_VERTEX_DATA_ARRAY_FORMAT_TYPE_F,
|
||||
2, sizeof(Vertex), &vptr[0].texcoord);
|
||||
|
||||
/* Set vertex normal attribute */
|
||||
set_attrib_pointer(NV2A_VERTEX_ATTR_NORMAL, NV097_SET_VERTEX_DATA_ARRAY_FORMAT_TYPE_F,
|
||||
3, sizeof(Vertex), &vptr[0].normal);
|
||||
|
||||
/* Begin drawing triangles */
|
||||
draw_arrays(NV097_SET_BEGIN_END_OP_TRIANGLES, 0, num_vertices);
|
||||
|
||||
/* Draw some text on the screen */
|
||||
pb_print("N: %s\n", format_map[format_map_index].Name);
|
||||
pb_print("F: 0x%x\n", format_map[format_map_index].XboxFormat);
|
||||
pb_print("SZ: %d\n", format_map[format_map_index].XboxSwizzled);
|
||||
pb_print("C: %d\n", format_map[format_map_index].RequireConversion);
|
||||
pb_print("W: %d\n", texWidth);
|
||||
pb_print("H: %d\n", texHeight);
|
||||
pb_print("P: %d\n", format_map[format_map_index].XboxBpp * texWidth);
|
||||
pb_print("ERR: %d\n", texError);
|
||||
pb_draw_text_screen();
|
||||
|
||||
while(pb_busy()) {
|
||||
/* Wait for completion... */
|
||||
}
|
||||
|
||||
/* Swap buffers (if we can) */
|
||||
while (pb_finished()) {
|
||||
/* Not ready to swap yet */
|
||||
}
|
||||
}
|
||||
|
||||
/* Unreachable cleanup code */
|
||||
SDL_GameControllerClose(gameController);
|
||||
SDL_QuitSubSystem(SDL_INIT_GAMECONTROLLER);
|
||||
MmFreeContiguousMemory(alloc_vertices);
|
||||
MmFreeContiguousMemory(alloc_vertices_swizzled);
|
||||
MmFreeContiguousMemory(texMem);
|
||||
pb_show_debug_screen();
|
||||
pb_kill();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static int update_texture_memory(void *texMem, TextureFormatInfo format, int width, int height)
|
||||
{
|
||||
// create source surface
|
||||
SDL_Surface *gradient_surf = SDL_CreateRGBSurfaceWithFormat(0, width, height, 32, SDL_PIXELFORMAT_RGBA8888);
|
||||
if (gradient_surf == NULL)
|
||||
return 1;
|
||||
|
||||
if (SDL_LockSurface(gradient_surf))
|
||||
return 2;
|
||||
|
||||
// TODO: have different color patterns controlled by alternate gamepad button(s)
|
||||
// generate basic gradient pattern
|
||||
uint32_t *pixels = gradient_surf->pixels;
|
||||
for (int y = 0; y < height; y++)
|
||||
for (int x = 0; x < width; x++) {
|
||||
int xNorm = x * 255.0f / width;
|
||||
int yNorm = y * 255.0f / height;
|
||||
pixels[y * width + x] = SDL_MapRGBA(gradient_surf->format, yNorm, xNorm, 255 - yNorm, xNorm + yNorm);
|
||||
}
|
||||
|
||||
SDL_UnlockSurface(gradient_surf);
|
||||
|
||||
// if conversion required, do so, otherwise use SDL to convert
|
||||
if (format.RequireConversion) {
|
||||
uint8_t *dstP = (uint8_t*)texMem;
|
||||
|
||||
// TODO: potential reference material - https://github.com/scalablecory/colors/blob/master/color.c
|
||||
switch (format.XboxFormat) {
|
||||
case NV097_SET_TEXTURE_FORMAT_COLOR_LC_IMAGE_CR8YB8CB8YA8: // YUY2 aka YUYV
|
||||
for (int y = 0; y < height; y++)
|
||||
for (int x = 0; x < width; x += 2) {
|
||||
uint8_t R0, G0, B0, R1, G1, B1;
|
||||
SDL_GetRGB(pixels[y * width + x], gradient_surf->format, &R0, &G0, &B0);
|
||||
SDL_GetRGB(pixels[y * width + x + 1], gradient_surf->format, &R1, &G1, &B1);
|
||||
dstP[0] = (0.257f * R0) + (0.504f * G0) + (0.098f * B0) + 16; // Y0
|
||||
dstP[1] = -(0.148f * R1) - (0.291f * G1) + (0.439f * B1) + 128; // U
|
||||
dstP[2] = (0.257f * R1) + (0.504f * G1) + (0.098f * B1) + 16; // Y1
|
||||
dstP[3] = (0.439f * R1) - (0.368f * G1) - (0.071f * B1) + 128; // V
|
||||
dstP += 4;
|
||||
}
|
||||
break;
|
||||
case NV097_SET_TEXTURE_FORMAT_COLOR_LC_IMAGE_YB8CR8YA8CB8: // UYVY
|
||||
for (int y = 0; y < height; y++)
|
||||
for (int x = 0; x < width; x += 2) {
|
||||
uint8_t R0, G0, B0, R1, G1, B1;
|
||||
SDL_GetRGB(pixels[y * width + x], gradient_surf->format, &R0, &G0, &B0);
|
||||
SDL_GetRGB(pixels[y * width + x + 1], gradient_surf->format, &R1, &G1, &B1);
|
||||
dstP[0] = -(0.148f * R1) - (0.291f * G1) + (0.439f * B1) + 128; // U
|
||||
dstP[1] = (0.257f * R0) + (0.504f * G0) + (0.098f * B0) + 16; // Y0
|
||||
dstP[2] = (0.439f * R1) - (0.368f * G1) - (0.071f * B1) + 128; // V
|
||||
dstP[3] = (0.257f * R1) + (0.504f * G1) + (0.098f * B1) + 16; // Y1
|
||||
dstP += 4;
|
||||
}
|
||||
break;
|
||||
case NV097_SET_TEXTURE_FORMAT_COLOR_LU_IMAGE_G8B8:
|
||||
// TODO: for now, just let default gradient happen
|
||||
break;
|
||||
default:
|
||||
SDL_FreeSurface(gradient_surf);
|
||||
return 3;
|
||||
break;
|
||||
}
|
||||
|
||||
// TODO: swizzling
|
||||
|
||||
SDL_FreeSurface(gradient_surf);
|
||||
} else {
|
||||
|
||||
// standard SDL conversion to destination format
|
||||
SDL_Surface *new_surf = SDL_ConvertSurfaceFormat(gradient_surf, format.SdlFormat, 0);
|
||||
SDL_FreeSurface(gradient_surf);
|
||||
if (!new_surf)
|
||||
return 4;
|
||||
|
||||
// copy pixels over to texture memory, swizzling if desired
|
||||
if (format.XboxSwizzled) {
|
||||
swizzle_rect((uint8_t*)new_surf->pixels, new_surf->w, new_surf->h, texMem, new_surf->pitch, new_surf->format->BytesPerPixel);
|
||||
} else {
|
||||
memcpy(texMem, new_surf->pixels, new_surf->pitch * new_surf->h);
|
||||
}
|
||||
|
||||
SDL_FreeSurface(new_surf);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Construct a viewport transformation matrix */
|
||||
static void matrix_viewport(float out[4][4], float x, float y, float width, float height, float z_min, float z_max)
|
||||
{
|
||||
memset(out, 0, 4*4*sizeof(float));
|
||||
out[0][0] = width/2.0f;
|
||||
out[1][1] = height/-2.0f;
|
||||
out[2][2] = (z_max - z_min)/2.0f;
|
||||
out[3][3] = 1.0f;
|
||||
out[3][0] = x + width/2.0f;
|
||||
out[3][1] = y + height/2.0f;
|
||||
out[3][2] = (z_min + z_max)/2.0f;
|
||||
}
|
||||
|
||||
/* Load the shader we will render with */
|
||||
static void init_shader(void)
|
||||
{
|
||||
uint32_t *p;
|
||||
int i;
|
||||
|
||||
/* Setup vertex shader */
|
||||
uint32_t vs_program[] = {
|
||||
#include "vs.inl"
|
||||
};
|
||||
|
||||
p = pb_begin();
|
||||
|
||||
/* Set run address of shader */
|
||||
p = pb_push1(p, NV097_SET_TRANSFORM_PROGRAM_START, 0);
|
||||
|
||||
/* Set execution mode */
|
||||
p = pb_push1(p, NV097_SET_TRANSFORM_EXECUTION_MODE,
|
||||
MASK(NV097_SET_TRANSFORM_EXECUTION_MODE_MODE, NV097_SET_TRANSFORM_EXECUTION_MODE_MODE_PROGRAM)
|
||||
| MASK(NV097_SET_TRANSFORM_EXECUTION_MODE_RANGE_MODE, NV097_SET_TRANSFORM_EXECUTION_MODE_RANGE_MODE_PRIV));
|
||||
|
||||
p = pb_push1(p, NV097_SET_TRANSFORM_PROGRAM_CXT_WRITE_EN, 0);
|
||||
pb_end(p);
|
||||
|
||||
/* Set cursor and begin copying program */
|
||||
p = pb_begin();
|
||||
p = pb_push1(p, NV097_SET_TRANSFORM_PROGRAM_LOAD, 0);
|
||||
pb_end(p);
|
||||
|
||||
/* Copy program instructions (16-bytes each) */
|
||||
for (i=0; i<sizeof(vs_program)/16; i++) {
|
||||
p = pb_begin();
|
||||
pb_push(p++, NV097_SET_TRANSFORM_PROGRAM, 4);
|
||||
memcpy(p, &vs_program[i*4], 4*4);
|
||||
p+=4;
|
||||
pb_end(p);
|
||||
}
|
||||
|
||||
/* Setup fragment shader */
|
||||
p = pb_begin();
|
||||
#include "ps.inl"
|
||||
pb_end(p);
|
||||
}
|
||||
|
||||
/* Set an attribute pointer */
|
||||
static void set_attrib_pointer(unsigned int index, unsigned int format, unsigned int size, unsigned int stride, const void* data)
|
||||
{
|
||||
uint32_t *p = pb_begin();
|
||||
p = pb_push1(p, NV097_SET_VERTEX_DATA_ARRAY_FORMAT + index*4,
|
||||
MASK(NV097_SET_VERTEX_DATA_ARRAY_FORMAT_TYPE, format) | \
|
||||
MASK(NV097_SET_VERTEX_DATA_ARRAY_FORMAT_SIZE, size) | \
|
||||
MASK(NV097_SET_VERTEX_DATA_ARRAY_FORMAT_STRIDE, stride));
|
||||
p = pb_push1(p, NV097_SET_VERTEX_DATA_ARRAY_OFFSET + index*4, (uint32_t)data & 0x03ffffff);
|
||||
pb_end(p);
|
||||
}
|
||||
|
||||
/* Send draw commands for the triangles */
|
||||
static void draw_arrays(unsigned int mode, int start, int count)
|
||||
{
|
||||
uint32_t *p = pb_begin();
|
||||
p = pb_push1(p, NV097_SET_BEGIN_END, mode);
|
||||
|
||||
p = pb_push1(p, 0x40000000|NV097_DRAW_ARRAYS, //bit 30 means all params go to same register 0x1810
|
||||
MASK(NV097_DRAW_ARRAYS_COUNT, (count-1)) | MASK(NV097_DRAW_ARRAYS_START_INDEX, start));
|
||||
|
||||
p = pb_push1(p, NV097_SET_BEGIN_END, NV097_SET_BEGIN_END_OP_END);
|
||||
pb_end(p);
|
||||
}
|
352
math3d.c
Normal file
352
math3d.c
Normal file
@ -0,0 +1,352 @@
|
||||
//port of ooPo's ps2sdk math3d library
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
|
||||
#include "math3d.h"
|
||||
|
||||
unsigned long times(void *);
|
||||
#define cpu_ticks() times(0)
|
||||
|
||||
|
||||
|
||||
//vector functions
|
||||
|
||||
void vector_apply(VECTOR output, VECTOR input0, MATRIX input1)
|
||||
{
|
||||
VECTOR work;
|
||||
|
||||
work[_X]=input0[_X]*input1[_11]+input0[_Y]*input1[_12]+input0[_Z]*input1[_13]+input0[_W]*input1[_14];
|
||||
work[_Y]=input0[_X]*input1[_21]+input0[_Y]*input1[_22]+input0[_Z]*input1[_23]+input0[_W]*input1[_24];
|
||||
work[_Z]=input0[_X]*input1[_31]+input0[_Y]*input1[_32]+input0[_Z]*input1[_33]+input0[_W]*input1[_34];
|
||||
work[_W]=input0[_X]*input1[_41]+input0[_Y]*input1[_42]+input0[_Z]*input1[_43]+input0[_W]*input1[_44];
|
||||
|
||||
// Output the result.
|
||||
vector_copy(output, work);
|
||||
}
|
||||
|
||||
void vector_clamp(VECTOR output, VECTOR input0, float min, float max)
|
||||
{
|
||||
VECTOR work;
|
||||
|
||||
// Copy the vector.
|
||||
vector_copy(work, input0);
|
||||
|
||||
// Clamp the minimum values.
|
||||
if (work[_X] < min) { work[_X] = min; }
|
||||
if (work[_Y] < min) { work[_Y] = min; }
|
||||
if (work[_Z] < min) { work[_Z] = min; }
|
||||
if (work[_W] < min) { work[_W] = min; }
|
||||
|
||||
// Clamp the maximum values.
|
||||
if (work[_X] > max) { work[_X] = max; }
|
||||
if (work[_Y] > max) { work[_Y] = max; }
|
||||
if (work[_Z] > max) { work[_Z] = max; }
|
||||
if (work[_W] > max) { work[_W] = max; }
|
||||
|
||||
// Output the result.
|
||||
vector_copy(output, work);
|
||||
}
|
||||
|
||||
void vector_copy(VECTOR output, VECTOR input0)
|
||||
{
|
||||
memcpy(output,input0,sizeof(VECTOR));
|
||||
}
|
||||
|
||||
float vector_innerproduct(VECTOR input0, VECTOR input1)
|
||||
{
|
||||
VECTOR work0, work1;
|
||||
|
||||
// Normalize the first vector.
|
||||
work0[_X] = (input0[_X] / input0[_W]);
|
||||
work0[_Y] = (input0[_Y] / input0[_W]);
|
||||
work0[_Z] = (input0[_Z] / input0[_W]);
|
||||
work0[_W] = 1.00f;
|
||||
|
||||
// Normalize the second vector.
|
||||
work1[_X] = (input1[_X] / input1[_W]);
|
||||
work1[_Y] = (input1[_Y] / input1[_W]);
|
||||
work1[_Z] = (input1[_Z] / input1[_W]);
|
||||
work1[_W] = 1.00f;
|
||||
|
||||
// Return the inner product.
|
||||
return (work0[_X] * work1[_X]) + (work0[_Y] * work1[_Y]) + (work0[_Z] * work1[_Z]);
|
||||
}
|
||||
|
||||
void vector_multiply(VECTOR output, VECTOR input0, VECTOR input1)
|
||||
{
|
||||
VECTOR work;
|
||||
|
||||
// Multiply the vectors together.
|
||||
work[_X] = input0[_X] * input1[_X];
|
||||
work[_Y] = input0[_Y] * input1[_Y];
|
||||
work[_Z] = input0[_Z] * input1[_Z];
|
||||
work[_W] = input0[_W] * input1[_W];
|
||||
|
||||
// Output the result.
|
||||
vector_copy(output, work);
|
||||
}
|
||||
|
||||
void vector_normalize(VECTOR output, VECTOR input0)
|
||||
{
|
||||
float k;
|
||||
|
||||
k=1.0f/sqrt(input0[_X]*input0[_X]+input0[_Y]*input0[_Y]+input0[_Z]*input0[_Z]);
|
||||
output[_X]*=k;
|
||||
output[_Y]*=k;
|
||||
output[_Z]*=k;
|
||||
}
|
||||
|
||||
void vector_outerproduct(VECTOR output, VECTOR input0, VECTOR input1)
|
||||
{
|
||||
VECTOR work;
|
||||
|
||||
work[_X]=input0[_Y]*input1[_Z]-input0[_Z]*input1[_Y];
|
||||
work[_Y]=input0[_Z]*input1[_X]-input0[_X]*input1[_Z];
|
||||
work[_Z]=input0[_X]*input1[_Y]-input0[_Y]*input1[_X];
|
||||
|
||||
// Output the result.
|
||||
vector_copy(output, work);
|
||||
}
|
||||
|
||||
//matrices function
|
||||
|
||||
void matrix_copy(MATRIX output, MATRIX input0)
|
||||
{
|
||||
memcpy(output,input0,sizeof(MATRIX));
|
||||
}
|
||||
|
||||
void matrix_inverse(MATRIX output, MATRIX input0)
|
||||
{
|
||||
MATRIX work;
|
||||
|
||||
// Calculate the inverse of the matrix.
|
||||
matrix_transpose(work, input0);
|
||||
work[_14] = 0.00f;
|
||||
work[_24] = 0.00f;
|
||||
work[_34] = 0.00f;
|
||||
work[_41] = -(input0[_41] * work[_11] + input0[_42] * work[_21] + input0[_43] * work[_31]);
|
||||
work[_42] = -(input0[_41] * work[_12] + input0[_42] * work[_22] + input0[_43] * work[_32]);
|
||||
work[_43] = -(input0[_41] * work[_13] + input0[_42] * work[_23] + input0[_43] * work[_33]);
|
||||
work[_44] = 1.00f;
|
||||
|
||||
// Output the result.
|
||||
matrix_copy(output, work);
|
||||
}
|
||||
|
||||
void matrix_multiply(MATRIX output, MATRIX input0, MATRIX input1)
|
||||
{
|
||||
MATRIX work;
|
||||
|
||||
work[_11]=input0[_11]*input1[_11]+input0[_12]*input1[_21]+input0[_13]*input1[_31]+input0[_14]*input1[_41];
|
||||
work[_12]=input0[_11]*input1[_12]+input0[_12]*input1[_22]+input0[_13]*input1[_32]+input0[_14]*input1[_42];
|
||||
work[_13]=input0[_11]*input1[_13]+input0[_12]*input1[_23]+input0[_13]*input1[_33]+input0[_14]*input1[_43];
|
||||
work[_14]=input0[_11]*input1[_14]+input0[_12]*input1[_24]+input0[_13]*input1[_34]+input0[_14]*input1[_44];
|
||||
work[_21]=input0[_21]*input1[_11]+input0[_22]*input1[_21]+input0[_23]*input1[_31]+input0[_24]*input1[_41];
|
||||
work[_22]=input0[_21]*input1[_12]+input0[_22]*input1[_22]+input0[_23]*input1[_32]+input0[_24]*input1[_42];
|
||||
work[_23]=input0[_21]*input1[_13]+input0[_22]*input1[_23]+input0[_23]*input1[_33]+input0[_24]*input1[_43];
|
||||
work[_24]=input0[_21]*input1[_14]+input0[_22]*input1[_24]+input0[_23]*input1[_34]+input0[_24]*input1[_44];
|
||||
work[_31]=input0[_31]*input1[_11]+input0[_32]*input1[_21]+input0[_33]*input1[_31]+input0[_34]*input1[_41];
|
||||
work[_32]=input0[_31]*input1[_12]+input0[_32]*input1[_22]+input0[_33]*input1[_32]+input0[_34]*input1[_42];
|
||||
work[_33]=input0[_31]*input1[_13]+input0[_32]*input1[_23]+input0[_33]*input1[_33]+input0[_34]*input1[_43];
|
||||
work[_34]=input0[_31]*input1[_14]+input0[_32]*input1[_24]+input0[_33]*input1[_34]+input0[_34]*input1[_44];
|
||||
work[_41]=input0[_41]*input1[_11]+input0[_42]*input1[_21]+input0[_43]*input1[_31]+input0[_44]*input1[_41];
|
||||
work[_42]=input0[_41]*input1[_12]+input0[_42]*input1[_22]+input0[_43]*input1[_32]+input0[_44]*input1[_42];
|
||||
work[_43]=input0[_41]*input1[_13]+input0[_42]*input1[_23]+input0[_43]*input1[_33]+input0[_44]*input1[_43];
|
||||
work[_44]=input0[_41]*input1[_14]+input0[_42]*input1[_24]+input0[_43]*input1[_34]+input0[_44]*input1[_44];
|
||||
|
||||
// Output the result.
|
||||
matrix_copy(output, work);
|
||||
}
|
||||
|
||||
void matrix_rotate(MATRIX output, MATRIX input0, VECTOR input1)
|
||||
{
|
||||
MATRIX work;
|
||||
|
||||
// Apply the z-axis rotation.
|
||||
matrix_unit(work);
|
||||
work[_11] = cosf(input1[2]);
|
||||
work[_12] = sinf(input1[2]);
|
||||
work[_21] = -sinf(input1[2]);
|
||||
work[_22] = cosf(input1[2]);
|
||||
matrix_multiply(output, input0, work);
|
||||
|
||||
// Apply the y-axis rotation.
|
||||
matrix_unit(work);
|
||||
work[_11] = cosf(input1[1]);
|
||||
work[_13] = -sinf(input1[1]);
|
||||
work[_31] = sinf(input1[1]);
|
||||
work[_33] = cosf(input1[1]);
|
||||
matrix_multiply(output, output, work);
|
||||
|
||||
// Apply the x-axis rotation.
|
||||
matrix_unit(work);
|
||||
work[_22] = cosf(input1[0]);
|
||||
work[_23] = sinf(input1[0]);
|
||||
work[_32] = -sinf(input1[0]);
|
||||
work[_33] = cosf(input1[0]);
|
||||
matrix_multiply(output, output, work);
|
||||
}
|
||||
|
||||
void matrix_scale(MATRIX output, MATRIX input0, VECTOR input1)
|
||||
{
|
||||
MATRIX work;
|
||||
|
||||
// Apply the scaling.
|
||||
matrix_unit(work);
|
||||
work[_11] = input1[_X];
|
||||
work[_22] = input1[_Y];
|
||||
work[_33] = input1[_Z];
|
||||
matrix_multiply(output, input0, work);
|
||||
}
|
||||
|
||||
void matrix_translate(MATRIX output, MATRIX input0, VECTOR input1)
|
||||
{
|
||||
MATRIX work;
|
||||
|
||||
// Apply the translation.
|
||||
matrix_unit(work);
|
||||
work[_41] = input1[_X];
|
||||
work[_42] = input1[_Y];
|
||||
work[_43] = input1[_Z];
|
||||
matrix_multiply(output, input0, work);
|
||||
}
|
||||
|
||||
void matrix_transpose(MATRIX output, MATRIX input0)
|
||||
{
|
||||
MATRIX work;
|
||||
|
||||
// Transpose the matrix.
|
||||
work[_11] = input0[_11];
|
||||
work[_12] = input0[_21];
|
||||
work[_13] = input0[_31];
|
||||
work[_14] = input0[_41];
|
||||
work[_21] = input0[_12];
|
||||
work[_22] = input0[_22];
|
||||
work[_23] = input0[_32];
|
||||
work[_24] = input0[_42];
|
||||
work[_31] = input0[_13];
|
||||
work[_32] = input0[_23];
|
||||
work[_33] = input0[_33];
|
||||
work[_34] = input0[_43];
|
||||
work[_41] = input0[_14];
|
||||
work[_42] = input0[_24];
|
||||
work[_43] = input0[_34];
|
||||
work[_44] = input0[_44];
|
||||
|
||||
// Output the result.
|
||||
matrix_copy(output, work);
|
||||
}
|
||||
|
||||
void matrix_unit(MATRIX output)
|
||||
{
|
||||
// Create a unit matrix.
|
||||
memset(output, 0, sizeof(MATRIX));
|
||||
output[_11] = 1.00f;
|
||||
output[_22] = 1.00f;
|
||||
output[_33] = 1.00f;
|
||||
output[_44] = 1.00f;
|
||||
}
|
||||
|
||||
//creation functions
|
||||
|
||||
void create_local_world(MATRIX local_world, VECTOR translation, VECTOR rotation)
|
||||
{
|
||||
// Create the local_world matrix.
|
||||
matrix_unit(local_world);
|
||||
matrix_rotate(local_world, local_world, rotation);
|
||||
matrix_translate(local_world, local_world, translation);
|
||||
}
|
||||
|
||||
void create_local_light(MATRIX local_light, VECTOR rotation)
|
||||
{
|
||||
// Create the local_light matrix.
|
||||
matrix_unit(local_light);
|
||||
matrix_rotate(local_light, local_light, rotation);
|
||||
}
|
||||
|
||||
|
||||
void create_world_view(MATRIX world_view, VECTOR translation, VECTOR rotation)
|
||||
{
|
||||
VECTOR work0, work1;
|
||||
|
||||
// Reverse the translation.
|
||||
work0[_X] = -translation[_X];
|
||||
work0[_Y] = -translation[_Y];
|
||||
work0[_Z] = -translation[_Z];
|
||||
work0[_W] = translation[_W];
|
||||
|
||||
// Reverse the rotation.
|
||||
work1[_X] = -rotation[_X];
|
||||
work1[_Y] = -rotation[_Y];
|
||||
work1[_Z] = -rotation[_Z];
|
||||
work1[_W] = rotation[_W];
|
||||
|
||||
// Create the world_view matrix.
|
||||
matrix_unit(world_view);
|
||||
matrix_translate(world_view, world_view, work0);
|
||||
matrix_rotate(world_view, world_view, work1);
|
||||
}
|
||||
|
||||
void create_view_screen(MATRIX view_screen, float aspect, float left, float right, float bottom, float top, float near, float far)
|
||||
{
|
||||
/* We want to create a matrix that transforms
|
||||
field of view frustum (a truncated pyramid)
|
||||
into a normalized cuboid (for fast hardware clipping):
|
||||
w, 0, 0, 0,
|
||||
0, -h, 0, 0,
|
||||
0, 0, (f+n) / (f-n), -1,
|
||||
0, 0, (2*f*n) / (f-n), 0
|
||||
(w:width,h:height,n:z near,f:z far)
|
||||
*/
|
||||
|
||||
// Apply the aspect ratio adjustment.
|
||||
left = (left * aspect); right = (right * aspect);
|
||||
|
||||
// Create the view_screen matrix.
|
||||
/* matrix_unit(view_screen);
|
||||
view_screen[_11] = (2 * near) / (right - left);
|
||||
view_screen[_22] = (2 * near) / (top - bottom);
|
||||
view_screen[_31] = (right + left) / (right - left);
|
||||
view_screen[_32] = (top + bottom) / (top - bottom);
|
||||
view_screen[_33] = (far + near) / (far - near);
|
||||
view_screen[_34] = -1.00f;
|
||||
view_screen[_43] = (2 * far * near) / (far - near);
|
||||
view_screen[_44] = 0.00f;
|
||||
|
||||
//This is good for ps2 clipping, where pixel is considered visible if:
|
||||
//-w < x < w
|
||||
//-w < y < w
|
||||
//-w < z < w
|
||||
//It's not automatic, it's done by using 'clipw' and testing flags in vu1 code
|
||||
//Result of the test allows to exclude entire triangle
|
||||
*/
|
||||
|
||||
//For xbox1 clipping, pixel is considered visible if:
|
||||
//-w < x < w
|
||||
//-w < y < w
|
||||
// 0 < z < w
|
||||
//It's automatic and verified for each pixel before pixel shader is called
|
||||
|
||||
//so we need this :
|
||||
matrix_unit(view_screen);
|
||||
view_screen[_11] = (2 * near) / (right - left);
|
||||
view_screen[_22] = (2 * near) / (top - bottom);
|
||||
view_screen[_31] = - (right + left) / (right - left);
|
||||
view_screen[_32] = - (top + bottom) / (top - bottom);
|
||||
view_screen[_33] = - far / (far - near);
|
||||
view_screen[_34] = - 1.00f;
|
||||
view_screen[_43] = near * far / (far - near);
|
||||
view_screen[_44] = 0.00f;
|
||||
}
|
||||
|
||||
void create_local_screen(MATRIX local_screen, MATRIX local_world, MATRIX world_view, MATRIX view_screen)
|
||||
{
|
||||
// Create the local_screen matrix.
|
||||
matrix_unit(local_screen);
|
||||
matrix_multiply(local_screen, local_screen, local_world);
|
||||
matrix_multiply(local_screen, local_screen, world_view);
|
||||
matrix_multiply(local_screen, local_screen, view_screen);
|
||||
}
|
||||
|
106
math3d.h
Normal file
106
math3d.h
Normal file
@ -0,0 +1,106 @@
|
||||
//port of ooPo's ps2sdk math3d library
|
||||
|
||||
#ifndef _MATH3D_H_
|
||||
#define _MATH3D_H_
|
||||
|
||||
typedef float VECTOR[4];
|
||||
typedef float MATRIX[16];
|
||||
|
||||
//vector indices
|
||||
#define _X 0
|
||||
#define _Y 1
|
||||
#define _Z 2
|
||||
#define _W 3
|
||||
|
||||
//4x4 matrices indices
|
||||
#define _11 0
|
||||
#define _12 1
|
||||
#define _13 2
|
||||
#define _14 3
|
||||
#define _21 4
|
||||
#define _22 5
|
||||
#define _23 6
|
||||
#define _24 7
|
||||
#define _31 8
|
||||
#define _32 9
|
||||
#define _33 10
|
||||
#define _34 11
|
||||
#define _41 12
|
||||
#define _42 13
|
||||
#define _43 14
|
||||
#define _44 15
|
||||
|
||||
|
||||
//vector functions
|
||||
|
||||
void vector_apply(VECTOR output, VECTOR input0, MATRIX input1);
|
||||
// Multiply a vector by a matrix, returning a vector.
|
||||
|
||||
void vector_clamp(VECTOR output, VECTOR input0, float min, float max);
|
||||
// Clamp a vector's values by cutting them off at a minimum and maximum value.
|
||||
|
||||
void vector_copy(VECTOR output, VECTOR input0);
|
||||
// Copy a vector.
|
||||
|
||||
float vector_innerproduct(VECTOR input0, VECTOR input1);
|
||||
// Calculate the inner product of two vectors. Returns a scalar value.
|
||||
|
||||
void vector_multiply(VECTOR output, VECTOR input0, VECTOR input1);
|
||||
// Multiply two vectors together.
|
||||
|
||||
void vector_normalize(VECTOR output, VECTOR input0);
|
||||
// Normalize a vector by determining its length and dividing its values by this value.
|
||||
|
||||
void vector_outerproduct(VECTOR output, VECTOR input0, VECTOR input1);
|
||||
// Calculate the outer product of two vectors.
|
||||
|
||||
//matrices functions
|
||||
|
||||
void matrix_copy(MATRIX output, MATRIX input0);
|
||||
// Copy a matrix.
|
||||
|
||||
void matrix_inverse(MATRIX output, MATRIX input0);
|
||||
// Calculate the inverse of a matrix.
|
||||
|
||||
void matrix_multiply(MATRIX output, MATRIX input0, MATRIX input1);
|
||||
// Multiply two matrices together.
|
||||
|
||||
void matrix_rotate(MATRIX output, MATRIX input0, VECTOR input1);
|
||||
// Create a rotation matrix and apply it to the specified input matrix.
|
||||
|
||||
void matrix_scale(MATRIX output, MATRIX input0, VECTOR input1);
|
||||
// Create a scaling matrix and apply it to the specified input matrix.
|
||||
|
||||
void matrix_translate(MATRIX output, MATRIX input0, VECTOR input1);
|
||||
// Create a translation matrix and apply it to the specified input matrix.
|
||||
|
||||
void matrix_transpose(MATRIX output, MATRIX input0);
|
||||
// Transpose a matrix.
|
||||
|
||||
void matrix_unit(MATRIX output);
|
||||
// Create a unit matrix.
|
||||
|
||||
//creation functions
|
||||
|
||||
void create_local_world(MATRIX local_world, VECTOR translation, VECTOR rotation);
|
||||
// Create a local_world matrix given a translation and rotation.
|
||||
// Commonly used to describe an object's position and orientation.
|
||||
|
||||
void create_local_light(MATRIX local_light, VECTOR rotation);
|
||||
// Create a local_light matrix given a rotation.
|
||||
// Commonly used to transform an object's normals for lighting calculations.
|
||||
|
||||
void create_world_view(MATRIX world_view, VECTOR translation, VECTOR rotation);
|
||||
// Create a world_view matrix given a translation and rotation.
|
||||
// Commonly used to describe a camera's position and rotation.
|
||||
|
||||
void create_view_screen(MATRIX view_screen, float aspect, float left, float right, float bottom, float top, float near, float far);
|
||||
// Create a view_screen matrix given an aspect and clipping plane values.
|
||||
// Functionally similar to the opengl function: glFrustum()
|
||||
|
||||
void create_local_screen(MATRIX local_screen, MATRIX local_world, MATRIX world_view, MATRIX view_screen);
|
||||
// Create a local_screen matrix given a local_world, world_view and view_screen matrix.
|
||||
// Commonly used with vector_apply() to transform vertices for rendering.
|
||||
|
||||
|
||||
#endif
|
14
ps.ps.cg
Normal file
14
ps.ps.cg
Normal file
@ -0,0 +1,14 @@
|
||||
struct vOut {
|
||||
float4 col : COLOR;
|
||||
float2 tex0 : TEXCOORD0;
|
||||
};
|
||||
|
||||
float4 main(
|
||||
vOut I,
|
||||
uniform sampler2D colorMap,
|
||||
uniform sampler2D normalMap
|
||||
) : COLOR
|
||||
{
|
||||
float4 color = tex2D(colorMap, I.tex0.xy);
|
||||
return color * I.col;
|
||||
}
|
163
swizzle.c
Normal file
163
swizzle.c
Normal file
@ -0,0 +1,163 @@
|
||||
/*
|
||||
* QEMU texture swizzling routines
|
||||
*
|
||||
* Copyright (c) 2015 Jannik Vogel
|
||||
* Copyright (c) 2013 espes
|
||||
* Copyright (c) 2007-2010 The Nouveau Project.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include "swizzle.h"
|
||||
|
||||
/* This should be pretty straightforward.
|
||||
* It creates a bit pattern like ..zyxzyxzyx from ..xxx, ..yyy and ..zzz
|
||||
* If there are no bits left from any component it will pack the other masks
|
||||
* more tighly (Example: zzxzxzyx = Fewer x than z and even fewer y)
|
||||
*/
|
||||
static void generate_swizzle_masks(unsigned int width,
|
||||
unsigned int height,
|
||||
unsigned int depth,
|
||||
uint32_t* mask_x,
|
||||
uint32_t* mask_y,
|
||||
uint32_t* mask_z)
|
||||
{
|
||||
uint32_t x = 0, y = 0, z = 0;
|
||||
uint32_t bit = 1;
|
||||
uint32_t mask_bit = 1;
|
||||
bool done;
|
||||
do {
|
||||
done = true;
|
||||
if (bit < width) { x |= mask_bit; mask_bit <<= 1; done = false; }
|
||||
if (bit < height) { y |= mask_bit; mask_bit <<= 1; done = false; }
|
||||
if (bit < depth) { z |= mask_bit; mask_bit <<= 1; done = false; }
|
||||
bit <<= 1;
|
||||
} while(!done);
|
||||
assert(x ^ y ^ z == (mask_bit - 1));
|
||||
*mask_x = x;
|
||||
*mask_y = y;
|
||||
*mask_z = z;
|
||||
}
|
||||
|
||||
/* This fills a pattern with a value if your value has bits abcd and your
|
||||
* pattern is 11010100100 this will return: 0a0b0c00d00
|
||||
*/
|
||||
static uint32_t fill_pattern(uint32_t pattern, uint32_t value)
|
||||
{
|
||||
uint32_t result = 0;
|
||||
uint32_t bit = 1;
|
||||
while(value) {
|
||||
if (pattern & bit) {
|
||||
/* Copy bit to result */
|
||||
result |= value & 1 ? bit : 0;
|
||||
value >>= 1;
|
||||
}
|
||||
bit <<= 1;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
static unsigned int get_swizzled_offset(
|
||||
unsigned int x, unsigned int y, unsigned int z,
|
||||
uint32_t mask_x, uint32_t mask_y, uint32_t mask_z,
|
||||
unsigned int bytes_per_pixel)
|
||||
{
|
||||
return bytes_per_pixel * (fill_pattern(mask_x, x)
|
||||
| fill_pattern(mask_y, y)
|
||||
| fill_pattern(mask_z, z));
|
||||
}
|
||||
|
||||
void swizzle_box(
|
||||
const uint8_t *src_buf,
|
||||
unsigned int width,
|
||||
unsigned int height,
|
||||
unsigned int depth,
|
||||
uint8_t *dst_buf,
|
||||
unsigned int row_pitch,
|
||||
unsigned int slice_pitch,
|
||||
unsigned int bytes_per_pixel)
|
||||
{
|
||||
uint32_t mask_x, mask_y, mask_z;
|
||||
generate_swizzle_masks(width, height, depth, &mask_x, &mask_y, &mask_z);
|
||||
|
||||
int x, y, z;
|
||||
for (z = 0; z < depth; z++) {
|
||||
for (y = 0; y < height; y++) {
|
||||
for (x = 0; x < width; x++) {
|
||||
const uint8_t *src = src_buf
|
||||
+ y * row_pitch + x * bytes_per_pixel;
|
||||
uint8_t *dst = dst_buf + get_swizzled_offset(x, y, 0,
|
||||
mask_x, mask_y, 0,
|
||||
bytes_per_pixel);
|
||||
memcpy(dst, src, bytes_per_pixel);
|
||||
}
|
||||
}
|
||||
src_buf += slice_pitch;
|
||||
}
|
||||
}
|
||||
|
||||
void unswizzle_box(
|
||||
const uint8_t *src_buf,
|
||||
unsigned int width,
|
||||
unsigned int height,
|
||||
unsigned int depth,
|
||||
uint8_t *dst_buf,
|
||||
unsigned int row_pitch,
|
||||
unsigned int slice_pitch,
|
||||
unsigned int bytes_per_pixel)
|
||||
{
|
||||
uint32_t mask_x, mask_y, mask_z;
|
||||
generate_swizzle_masks(width, height, depth, &mask_x, &mask_y, &mask_z);
|
||||
|
||||
int x, y, z;
|
||||
for (z = 0; z < depth; z++) {
|
||||
for (y = 0; y < height; y++) {
|
||||
for (x = 0; x < width; x++) {
|
||||
const uint8_t *src = src_buf
|
||||
+ get_swizzled_offset(x, y, z, mask_x, mask_y, mask_z,
|
||||
bytes_per_pixel);
|
||||
uint8_t *dst = dst_buf + y * row_pitch + x * bytes_per_pixel;
|
||||
memcpy(dst, src, bytes_per_pixel);
|
||||
}
|
||||
}
|
||||
dst_buf += slice_pitch;
|
||||
}
|
||||
}
|
||||
|
||||
void unswizzle_rect(
|
||||
const uint8_t *src_buf,
|
||||
unsigned int width,
|
||||
unsigned int height,
|
||||
uint8_t *dst_buf,
|
||||
unsigned int pitch,
|
||||
unsigned int bytes_per_pixel)
|
||||
{
|
||||
unswizzle_box(src_buf, width, height, 1, dst_buf, pitch, 0, bytes_per_pixel);
|
||||
}
|
||||
|
||||
void swizzle_rect(
|
||||
const uint8_t *src_buf,
|
||||
unsigned int width,
|
||||
unsigned int height,
|
||||
uint8_t *dst_buf,
|
||||
unsigned int pitch,
|
||||
unsigned int bytes_per_pixel)
|
||||
{
|
||||
swizzle_box(src_buf, width, height, 1, dst_buf, pitch, 0, bytes_per_pixel);
|
||||
}
|
60
swizzle.h
Normal file
60
swizzle.h
Normal file
@ -0,0 +1,60 @@
|
||||
/*
|
||||
* QEMU texture swizzling routines
|
||||
*
|
||||
* Copyright (c) 2015 Jannik Vogel
|
||||
* Copyright (c) 2013 espes
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef HW_XBOX_SWIZZLE_H
|
||||
#define HW_XBOX_SWIZZLE_H
|
||||
|
||||
void swizzle_box(
|
||||
const uint8_t *src_buf,
|
||||
unsigned int width,
|
||||
unsigned int height,
|
||||
unsigned int depth,
|
||||
uint8_t *dst_buf,
|
||||
unsigned int row_pitch,
|
||||
unsigned int slice_pitch,
|
||||
unsigned int bytes_per_pixel);
|
||||
|
||||
void unswizzle_box(
|
||||
const uint8_t *src_buf,
|
||||
unsigned int width,
|
||||
unsigned int height,
|
||||
unsigned int depth,
|
||||
uint8_t *dst_buf,
|
||||
unsigned int row_pitch,
|
||||
unsigned int slice_pitch,
|
||||
unsigned int bytes_per_pixel);
|
||||
|
||||
void unswizzle_rect(
|
||||
const uint8_t *src_buf,
|
||||
unsigned int width,
|
||||
unsigned int height,
|
||||
uint8_t *dst_buf,
|
||||
unsigned int pitch,
|
||||
unsigned int bytes_per_pixel);
|
||||
|
||||
void swizzle_rect(
|
||||
const uint8_t *src_buf,
|
||||
unsigned int width,
|
||||
unsigned int height,
|
||||
uint8_t *dst_buf,
|
||||
unsigned int pitch,
|
||||
unsigned int bytes_per_pixel);
|
||||
|
||||
#endif
|
38
verts.h
Normal file
38
verts.h
Normal file
@ -0,0 +1,38 @@
|
||||
struct Vertex vertices[] = {
|
||||
{ {-0.500000, -0.500000, 0.500000}, {1.000000, 1.000000}, {0.000000, -1.000000, -0.000000} },
|
||||
{ {-0.500000, -0.500000, -0.500000}, {1.000000, 0.000000}, {0.000000, -1.000000, -0.000000} },
|
||||
{ {0.500000, -0.500000, -0.500000}, {0.000000, 0.000000}, {0.000000, -1.000000, -0.000000} },
|
||||
{ {0.500000, -0.500000, -0.500000}, {0.000000, 0.000000}, {0.000000, -1.000000, -0.000000} },
|
||||
{ {0.500000, -0.500000, 0.500000}, {0.000000, 1.000000}, {0.000000, -1.000000, -0.000000} },
|
||||
{ {-0.500000, -0.500000, 0.500000}, {1.000000, 1.000000}, {0.000000, -1.000000, -0.000000} },
|
||||
{ {-0.500000, 0.500000, 0.500000}, {0.000000, 1.000000}, {0.000000, 1.000000, -0.000000} },
|
||||
{ {0.500000, 0.500000, 0.500000}, {1.000000, 1.000000}, {0.000000, 1.000000, -0.000000} },
|
||||
{ {0.500000, 0.500000, -0.500000}, {1.000000, 0.000000}, {0.000000, 1.000000, -0.000000} },
|
||||
{ {0.500000, 0.500000, -0.500000}, {1.000000, 0.000000}, {0.000000, 1.000000, -0.000000} },
|
||||
{ {-0.500000, 0.500000, -0.500000}, {0.000000, 0.000000}, {0.000000, 1.000000, -0.000000} },
|
||||
{ {-0.500000, 0.500000, 0.500000}, {0.000000, 1.000000}, {0.000000, 1.000000, -0.000000} },
|
||||
{ {-0.500000, -0.500000, 0.500000}, {0.000000, 1.000000}, {0.000000, 0.000000, 1.000000} },
|
||||
{ {0.500000, -0.500000, 0.500000}, {1.000000, 1.000000}, {0.000000, 0.000000, 1.000000} },
|
||||
{ {0.500000, 0.500000, 0.500000}, {1.000000, 0.000000}, {0.000000, 0.000000, 1.000000} },
|
||||
{ {0.500000, 0.500000, 0.500000}, {1.000000, 0.000000}, {0.000000, 0.000000, 1.000000} },
|
||||
{ {-0.500000, 0.500000, 0.500000}, {0.000000, 0.000000}, {0.000000, 0.000000, 1.000000} },
|
||||
{ {-0.500000, -0.500000, 0.500000}, {0.000000, 1.000000}, {0.000000, 0.000000, 1.000000} },
|
||||
{ {0.500000, -0.500000, 0.500000}, {0.000000, 1.000000}, {1.000000, 0.000000, -0.000000} },
|
||||
{ {0.500000, -0.500000, -0.500000}, {1.000000, 1.000000}, {1.000000, 0.000000, -0.000000} },
|
||||
{ {0.500000, 0.500000, -0.500000}, {1.000000, 0.000000}, {1.000000, 0.000000, -0.000000} },
|
||||
{ {0.500000, 0.500000, -0.500000}, {1.000000, 0.000000}, {1.000000, 0.000000, -0.000000} },
|
||||
{ {0.500000, 0.500000, 0.500000}, {0.000000, 0.000000}, {1.000000, 0.000000, -0.000000} },
|
||||
{ {0.500000, -0.500000, 0.500000}, {0.000000, 1.000000}, {1.000000, 0.000000, -0.000000} },
|
||||
{ {0.500000, -0.500000, -0.500000}, {0.000000, 1.000000}, {0.000000, 0.000000, -1.000000} },
|
||||
{ {-0.500000, -0.500000, -0.500000}, {1.000000, 1.000000}, {0.000000, 0.000000, -1.000000} },
|
||||
{ {-0.500000, 0.500000, -0.500000}, {1.000000, 0.000000}, {0.000000, 0.000000, -1.000000} },
|
||||
{ {-0.500000, 0.500000, -0.500000}, {1.000000, 0.000000}, {0.000000, 0.000000, -1.000000} },
|
||||
{ {0.500000, 0.500000, -0.500000}, {0.000000, 0.000000}, {0.000000, 0.000000, -1.000000} },
|
||||
{ {0.500000, -0.500000, -0.500000}, {0.000000, 1.000000}, {0.000000, 0.000000, -1.000000} },
|
||||
{ {-0.500000, -0.500000, -0.500000}, {0.000000, 1.000000}, {-1.000000, 0.000000, -0.000000} },
|
||||
{ {-0.500000, -0.500000, 0.500000}, {1.000000, 1.000000}, {-1.000000, 0.000000, -0.000000} },
|
||||
{ {-0.500000, 0.500000, 0.500000}, {1.000000, 0.000000}, {-1.000000, 0.000000, -0.000000} },
|
||||
{ {-0.500000, 0.500000, 0.500000}, {1.000000, 0.000000}, {-1.000000, 0.000000, -0.000000} },
|
||||
{ {-0.500000, 0.500000, -0.500000}, {0.000000, 0.000000}, {-1.000000, 0.000000, -0.000000} },
|
||||
{ {-0.500000, -0.500000, -0.500000}, {0.000000, 1.000000}, {-1.000000, 0.000000, -0.000000} }
|
||||
};
|
42
vs.vs.cg
Normal file
42
vs.vs.cg
Normal file
@ -0,0 +1,42 @@
|
||||
struct vIn {
|
||||
float3 norm : NORMAL;
|
||||
float2 tex : TEXCOORD;
|
||||
float3 pos : POSITION;
|
||||
};
|
||||
|
||||
struct vOut {
|
||||
float4 pos : POSITION;
|
||||
float4 col : COLOR;
|
||||
float2 tex0 : TEXCOORD0; // Our diffuse map
|
||||
};
|
||||
|
||||
vOut main(
|
||||
vIn I,
|
||||
uniform float4x4 m_model,
|
||||
uniform float4x4 m_view,
|
||||
uniform float4x4 m_proj,
|
||||
uniform float4 camera_pos,
|
||||
uniform float4 light_dir
|
||||
)
|
||||
{
|
||||
vOut result;
|
||||
|
||||
// Transform position and normal
|
||||
float4 pos = mul(float4(I.pos.xyz, 1.0), m_model);
|
||||
float3 norm = normalize(mul(float4(I.norm.xyz, 0.0f), m_model).xyz);
|
||||
|
||||
// Calculate diffuse light direction and intensity
|
||||
float3 light_direction = normalize(light_dir.xyz);
|
||||
float light_diffuse = max(dot(norm.xyz, light_direction), 0);
|
||||
|
||||
// Transform pos to screen space
|
||||
pos = mul(pos, m_view);
|
||||
pos = mul(pos, m_proj);
|
||||
pos.xyz = pos.xyz / pos.w;
|
||||
|
||||
result.pos = pos;
|
||||
result.col = light_diffuse;
|
||||
result.tex0 = I.tex;
|
||||
|
||||
return result;
|
||||
}
|
Loading…
Reference in New Issue
Block a user