softgpu: Move triangle rasterization code to a new file.

This commit is contained in:
Tony Wasserka 2013-06-25 16:15:09 +02:00 committed by neobrain
parent adbe80c290
commit 142f2a3688
7 changed files with 130 additions and 61 deletions

View file

@ -1019,6 +1019,8 @@ add_library(GPU OBJECT
GPU/Software/SoftGpu.h
GPU/Software/TransformUnit.cpp
GPU/Software/TransformUnit.h
GPU/Software/Rasterizer.cpp
GPU/Software/Rasterizer.h
GPU/ge_constants.h)
setup_target_project(GPU GPU)

View file

@ -14,6 +14,7 @@ set(SRCS
GLES/VertexDecoder.cpp
GLES/VertexShaderGenerator.cpp
Null/NullGpu.cpp
Software/Rasterizer.cpp
Software/SoftGpu.cpp
Software/TransformUnit.cpp
)

View file

@ -162,6 +162,7 @@
<ClInclude Include="GPUState.h" />
<ClInclude Include="Math3D.h" />
<ClInclude Include="Null\NullGpu.h" />
<ClInclude Include="Software\Rasterizer.h" />
<ClInclude Include="Software\SoftGpu.h" />
<ClInclude Include="Software\TransformUnit.h" />
</ItemGroup>
@ -185,6 +186,7 @@
<ClCompile Include="GPUState.cpp" />
<ClCompile Include="Math3D.cpp" />
<ClCompile Include="Null\NullGpu.cpp" />
<ClCompile Include="Software\Rasterizer.cpp" />
<ClCompile Include="Software\SoftGpu.cpp" />
<ClCompile Include="Software\TransformUnit.cpp" />
</ItemGroup>

View file

@ -68,6 +68,9 @@
<ClInclude Include="GLES\TextureScaler.h">
<Filter>GLES</Filter>
</ClInclude>
<ClInclude Include="Software\Rasterizer.h">
<Filter>Software</Filter>
</ClInclude>
<ClInclude Include="Software\SoftGpu.h">
<Filter>Software</Filter>
</ClInclude>
@ -123,6 +126,9 @@
<ClCompile Include="GLES\TextureScaler.cpp">
<Filter>GLES</Filter>
</ClCompile>
<ClCompile Include="Software\Rasterizer.cpp">
<Filter>Software</Filter>
</ClCompile>
<ClCompile Include="Software\SoftGpu.cpp">
<Filter>Software</Filter>
</ClCompile>

View file

@ -0,0 +1,90 @@
// Copyright (c) 2013- PPSSPP Project.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, version 2.0 or later versions.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License 2.0 for more details.
// A copy of the GPL 2.0 should have been included with the program.
// If not, see http://www.gnu.org/licenses/
// Official git repository and contact information can be found at
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
#include "../GPUState.h"
#include "Rasterizer.h"
const int FB_WIDTH = 480;
const int FB_HEIGHT = 272;
extern u8* fb;
namespace Rasterizer {
static void DrawVLine(u8* target, DrawingCoords a, DrawingCoords b)
{
if (a.y > b.y) {
DrawVLine(target, b, a);
return;
}
for (int y = a.y; y < b.y; ++y) {
float u = (float)(y-a.y)/(float)(b.y-a.y);
int x = (1-u)*a.x+u*b.x;
if (x < gstate.getScissorX1()) continue;
if (x > gstate.getScissorX2()) continue;
if (y < gstate.getScissorY1()) continue;
if (y > gstate.getScissorY2()) continue;
target[x*4+y*FB_WIDTH*4] = 0xff;
target[x*4+y*FB_WIDTH*4+1] = 0xff;
target[x*4+y*FB_WIDTH*4+2] = 0xff;
target[x*4+y*FB_WIDTH*4+3] = 0xff;
}
}
static void DrawLine(u8* target, DrawingCoords a, DrawingCoords b)
{
if (a.x > b.x) {
DrawLine(target, b, a);
return;
}
if (a.y > b.y && a.x - b.x < a.y - b.y)
{
DrawVLine(target, a, b);
return;
}
if (a.y < b.y && a.x - b.x < b.y - a.y)
{
DrawVLine(target, a, b);
return;
}
for (int x = a.x; x < b.x; ++x) {
float u = (float)(x-a.x)/(float)(b.x-a.x);
int y = (1-u)*a.y+u*b.y;
if (x < gstate.getScissorX1()) continue;
if (x > gstate.getScissorX2()) continue;
if (y < gstate.getScissorY1()) continue;
if (y > gstate.getScissorY2()) continue;
target[x*4+y*FB_WIDTH*4] = 0xff;
target[x*4+y*FB_WIDTH*4+1] = 0xff;
target[x*4+y*FB_WIDTH*4+2] = 0xff;
target[x*4+y*FB_WIDTH*4+3] = 0xff;
}
}
void DrawTriangle(DrawingCoords vertices[3])
{
// TODO: Well yeah, that's not quite it, yet.. :p
DrawLine(fb, vertices[0], vertices[1]);
DrawLine(fb, vertices[1], vertices[2]);
DrawLine(fb, vertices[2], vertices[0]);
}
} // namespace

26
GPU/Software/Rasterizer.h Normal file
View file

@ -0,0 +1,26 @@
// Copyright (c) 2013- PPSSPP Project.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, version 2.0 or later versions.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License 2.0 for more details.
// A copy of the GPL 2.0 should have been included with the program.
// If not, see http://www.gnu.org/licenses/
// Official git repository and contact information can be found at
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
#pragma once
#include "TransformUnit.h" // for DrawingCoords
namespace Rasterizer {
void DrawTriangle(DrawingCoords vertices[3]);
}

View file

@ -15,13 +15,11 @@
// Official git repository and contact information can be found at
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
#include "TransformUnit.h"
#include "../GPUState.h"
#include "../GLES/VertexDecoder.h"
const int FB_WIDTH = 480;
const int FB_HEIGHT = 272;
extern u8* fb;
#include "TransformUnit.h"
#include "Rasterizer.h"
WorldCoords TransformUnit::ModelToWorld(const ModelCoords& coords)
{
@ -68,60 +66,6 @@ DrawingCoords TransformUnit::ScreenToDrawing(const ScreenCoords& coords)
return ret;
}
static void DrawVLine(u8* target, DrawingCoords a, DrawingCoords b)
{
if (a.y > b.y) {
DrawVLine(target, b, a);
return;
}
for (int y = a.y; y < b.y; ++y) {
float u = (float)(y-a.y)/(float)(b.y-a.y);
int x = (1-u)*a.x+u*b.x;
if (x < gstate.getScissorX1()) continue;
if (x > gstate.getScissorX2()) continue;
if (y < gstate.getScissorY1()) continue;
if (y > gstate.getScissorY2()) continue;
target[x*4+y*FB_WIDTH*4] = 0xff;
target[x*4+y*FB_WIDTH*4+1] = 0xff;
target[x*4+y*FB_WIDTH*4+2] = 0xff;
target[x*4+y*FB_WIDTH*4+3] = 0xff;
}
}
static void DrawLine(u8* target, DrawingCoords a, DrawingCoords b)
{
if (a.x > b.x) {
DrawLine(target, b, a);
return;
}
if (a.y > b.y && a.x - b.x < a.y - b.y)
{
DrawVLine(target, a, b);
return;
}
if (a.y < b.y && a.x - b.x < b.y - a.y)
{
DrawVLine(target, a, b);
return;
}
for (int x = a.x; x < b.x; ++x) {
float u = (float)(x-a.x)/(float)(b.x-a.x);
int y = (1-u)*a.y+u*b.y;
if (x < gstate.getScissorX1()) continue;
if (x > gstate.getScissorX2()) continue;
if (y < gstate.getScissorY1()) continue;
if (y > gstate.getScissorY2()) continue;
target[x*4+y*FB_WIDTH*4] = 0xff;
target[x*4+y*FB_WIDTH*4+1] = 0xff;
target[x*4+y*FB_WIDTH*4+2] = 0xff;
target[x*4+y*FB_WIDTH*4+3] = 0xff;
}
}
void TransformUnit::SubmitPrimitive(void* vertices, u32 prim_type, int vertex_count, u32 vertex_type)
{
// TODO: Cache VertexDecoder objects
@ -163,9 +107,7 @@ void TransformUnit::SubmitPrimitive(void* vertices, u32 prim_type, int vertex_co
}
dcoords[i] = DrawingCoords(TransformUnit::ScreenToDrawing(TransformUnit::ClipToScreen(ccoords)));
}
DrawLine(fb, dcoords[0], dcoords[1]);
DrawLine(fb, dcoords[1], dcoords[2]);
DrawLine(fb, dcoords[2], dcoords[0]);
Rasterizer::DrawTriangle(dcoords);
skip:;
}
}