Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
Suyu
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
many-archive
Suyu
Commits
a7ae0330
There was an error fetching the commit references. Please try again later.
Commit
a7ae0330
authored
10 years ago
by
Tony Wasserka
Browse files
Options
Downloads
Patches
Plain Diff
Pica/Rasterizer: Implement alpha blending.
parent
e229ff8c
No related branches found
No related tags found
Loading
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/video_core/rasterizer.cpp
+84
-0
84 additions, 0 deletions
src/video_core/rasterizer.cpp
with
84 additions
and
0 deletions
src/video_core/rasterizer.cpp
+
84
−
0
View file @
a7ae0330
...
@@ -25,6 +25,18 @@ static void DrawPixel(int x, int y, const Math::Vec4<u8>& color) {
...
@@ -25,6 +25,18 @@ static void DrawPixel(int x, int y, const Math::Vec4<u8>& color) {
*
(
color_buffer
+
x
+
y
*
registers
.
framebuffer
.
GetWidth
())
=
value
;
*
(
color_buffer
+
x
+
y
*
registers
.
framebuffer
.
GetWidth
())
=
value
;
}
}
static
const
Math
::
Vec4
<
u8
>
GetPixel
(
int
x
,
int
y
)
{
u32
*
color_buffer_u32
=
reinterpret_cast
<
u32
*>
(
Memory
::
GetPointer
(
PAddrToVAddr
(
registers
.
framebuffer
.
GetColorBufferPhysicalAddress
())));
u32
value
=
*
(
color_buffer_u32
+
x
+
y
*
registers
.
framebuffer
.
GetWidth
());
Math
::
Vec4
<
u8
>
ret
;
ret
.
a
()
=
value
>>
24
;
ret
.
r
()
=
(
value
>>
16
)
&
0xFF
;
ret
.
g
()
=
(
value
>>
8
)
&
0xFF
;
ret
.
b
()
=
value
&
0xFF
;
return
ret
;
}
static
u32
GetDepth
(
int
x
,
int
y
)
{
static
u32
GetDepth
(
int
x
,
int
y
)
{
u16
*
depth_buffer
=
reinterpret_cast
<
u16
*>
(
Memory
::
GetPointer
(
PAddrToVAddr
(
registers
.
framebuffer
.
GetDepthBufferPhysicalAddress
())));
u16
*
depth_buffer
=
reinterpret_cast
<
u16
*>
(
Memory
::
GetPointer
(
PAddrToVAddr
(
registers
.
framebuffer
.
GetDepthBufferPhysicalAddress
())));
...
@@ -430,6 +442,78 @@ void ProcessTriangle(const VertexShader::OutputVertex& v0,
...
@@ -430,6 +442,78 @@ void ProcessTriangle(const VertexShader::OutputVertex& v0,
SetDepth
(
x
>>
4
,
y
>>
4
,
z
);
SetDepth
(
x
>>
4
,
y
>>
4
,
z
);
}
}
auto
dest
=
GetPixel
(
x
>>
4
,
y
>>
4
);
if
(
registers
.
output_merger
.
alphablend_enable
)
{
auto
params
=
registers
.
output_merger
.
alpha_blending
;
auto
LookupFactorRGB
=
[
&
](
decltype
(
params
)
::
BlendFactor
factor
)
->
Math
::
Vec3
<
u8
>
{
switch
(
factor
)
{
case
params
.
Zero
:
return
Math
::
Vec3
<
u8
>
(
0
,
0
,
0
);
case
params
.
One
:
return
Math
::
Vec3
<
u8
>
(
255
,
255
,
255
);
case
params
.
SourceAlpha
:
return
Math
::
MakeVec
(
combiner_output
.
a
(),
combiner_output
.
a
(),
combiner_output
.
a
());
case
params
.
OneMinusSourceAlpha
:
return
Math
::
Vec3
<
u8
>
(
255
-
combiner_output
.
a
(),
255
-
combiner_output
.
a
(),
255
-
combiner_output
.
a
());
default:
LOG_CRITICAL
(
HW_GPU
,
"Unknown color blend factor %x"
,
factor
);
exit
(
0
);
break
;
}
};
auto
LookupFactorA
=
[
&
](
decltype
(
params
)
::
BlendFactor
factor
)
->
u8
{
switch
(
factor
)
{
case
params
.
Zero
:
return
0
;
case
params
.
One
:
return
255
;
case
params
.
SourceAlpha
:
return
combiner_output
.
a
();
case
params
.
OneMinusSourceAlpha
:
return
255
-
combiner_output
.
a
();
default:
LOG_CRITICAL
(
HW_GPU
,
"Unknown alpha blend factor %x"
,
factor
);
exit
(
0
);
break
;
}
};
auto
srcfactor
=
Math
::
MakeVec
(
LookupFactorRGB
(
params
.
factor_source_rgb
),
LookupFactorA
(
params
.
factor_source_a
));
auto
dstfactor
=
Math
::
MakeVec
(
LookupFactorRGB
(
params
.
factor_dest_rgb
),
LookupFactorA
(
params
.
factor_dest_a
));
switch
(
params
.
blend_equation_rgb
)
{
case
params
.
Add
:
{
auto
result
=
(
combiner_output
*
srcfactor
+
dest
*
dstfactor
)
/
255
;
result
.
r
()
=
std
::
min
(
255
,
result
.
r
());
result
.
g
()
=
std
::
min
(
255
,
result
.
g
());
result
.
b
()
=
std
::
min
(
255
,
result
.
b
());
combiner_output
=
result
.
Cast
<
u8
>
();
break
;
}
default
:
LOG_CRITICAL
(
HW_GPU
,
"Unknown RGB blend equation %x"
,
params
.
blend_equation_rgb
.
Value
());
exit
(
0
);
}
}
else
{
LOG_CRITICAL
(
HW_GPU
,
"logic op: %x"
,
registers
.
output_merger
.
logic_op
);
exit
(
0
);
}
DrawPixel
(
x
>>
4
,
y
>>
4
,
combiner_output
);
DrawPixel
(
x
>>
4
,
y
>>
4
,
combiner_output
);
}
}
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment