Repository navigation
Expand file tree
/
Copy pathvscreen.cpp
More file actions
160 lines (145 loc) · 4.42 KB
/
Copy pathvscreen.cpp
File metadata and controls
160 lines (145 loc) · 4.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
///////////////////////////////////////////////////////////////
//
// vscreen: Off-Screen Screen (RGBA Sprite 2D Rendering)
//
//
// 19.04.2013 14:08 - created [extracted from main.cpp]
// 29.05.2013 11:56 - added support to render partially off-screen sprites
// 30.05.2013 10:30 - fixed off-screen sprite rendering bug
//
// (partial source) //
void VScreen::Clear(DWORD color)
{
DWORD* ptr;
DWORD* ptrEnd;
::GdiFlush();
ptr = this->surfScr.pData;
ptrEnd = ptr + (this->surfScr.height * this->surfScr.width);
while(ptr < ptrEnd)
{
*ptr = color;
ptr++;
}
}
void VScreen::RenderBegin(void)
{
::GdiFlush();
}
void VScreen::RenderQuad(Quad* pQuad, DWORD color)
{
DWORD* ptr;
DWORD* ptrLineEnd;
DWORD* ptrEnd;
DWORD* ptrStop;
// ::GdiFlush() is assumed
ptr = this->surfScr.pData + (pQuad->y * this->surfScr.width) + pQuad->x;
ptrLineEnd = ptr + pQuad->width;
ptrStop = this->surfScr.pData + (this->surfScr.height * this->surfScr.width);
ptrEnd = ptr + ((pQuad->height - 1) * this->surfScr.width) + pQuad->width;
if(ptrEnd > ptrStop)
{
ptrEnd = ptrStop;
}
while(ptr < ptrEnd)
{
if(ptr < ptrLineEnd)
{
*ptr = color;
ptr++;
}
else
{
// one line lower, step back by rect-width
ptr += this->surfScr.width - pQuad->width;
// advance line end
ptrLineEnd += this->surfScr.width;
}
}
}
void VScreen::BlitARGB(Surface* pDstSurface, INT dstX, INT dstY, Surface* pSrcSurface, UINT srcX, UINT srcY, DWORD blitWidth, DWORD blitHeight)
{
DWORD* ptrSrc;
DWORD* ptrDst;
DWORD* ptrDstLineBegin;
DWORD* ptrDstLineEnd;
DWORD* ptrSrcLineEnd;
DWORD* ptrSrcEnd;
DWORD* ptrDstEnd;
DWORD* ptrSrcStop;
DWORD* ptrDstStop;
ARGB color;
BOOL bNextDstLine;
// ::GdiFlush() is assumed
// adjust some pointers
ptrSrc = pSrcSurface->pData + (srcY * pSrcSurface->width) + srcX;
ptrDst = pDstSurface->pData + (dstY * pDstSurface->width) + dstX;
ptrDstLineBegin = pDstSurface->pData + (dstY * pDstSurface->width);
if(ptrDstLineBegin < pDstSurface->pData)
{
ptrDstLineBegin = pDstSurface->pData;
}
ptrDstLineEnd = ptrDstLineBegin + pDstSurface->width;
ptrSrcLineEnd = ptrSrc + blitWidth;
ptrSrcStop = pSrcSurface->pData + (pSrcSurface->height * pSrcSurface->width);
ptrDstStop = pDstSurface->pData + (pDstSurface->height * pDstSurface->width);
ptrSrcEnd = ptrSrc + ((blitHeight-1) * pSrcSurface->width) + blitWidth;
ptrDstEnd = ptrDst + ((blitHeight-1) * pDstSurface->width) + blitWidth;
if(ptrSrcEnd > ptrSrcStop)
{
ptrSrcEnd = ptrSrcStop;
}
if(ptrDstEnd > ptrDstStop)
{
ptrDstEnd = ptrDstStop;
}
// perform line-by-line block transfer
bNextDstLine = FALSE;
while((ptrSrc < ptrSrcEnd) && (ptrDst < ptrDstEnd))
{
if(ptrSrc < ptrSrcLineEnd)
{
// skip off-screen pixels
if((ptrDst >= ptrDstLineBegin) && (ptrDst < ptrDstLineEnd))
{
// skip transparent pixels
color.dword = *ptrSrc;
if(color.alpha == 0xFF)
{
*ptrDst = color.dword;
}
bNextDstLine = TRUE;
}
ptrSrc++;
ptrDst++;
}
else
{
// one line lower, step back by blit-width
ptrSrc += pSrcSurface->width - blitWidth;
ptrDst += pDstSurface->width - blitWidth;
// advance line boundaries
ptrSrcLineEnd += pSrcSurface->width;
if(bNextDstLine != FALSE)
{
ptrDstLineBegin += pDstSurface->width;
ptrDstLineEnd += pDstSurface->width;
bNextDstLine = FALSE;
}
}
}
}
void VScreen::RenderSprite(DWORD type, INT x, INT y)
{
Quad* pst;
pst = &this->spriteTex[type];
/// this->BlitARGB(this->pbm, x, y, this->scrWidth, this->scrHeight, this->ptex, pst->x, pst->y, this->texWidth, this->texHeight, pst->width, pst->height);
this->BlitARGB(&this->surfScr, x, y, &this->surfTex, pst->x, pst->y, pst->width, pst->height);
}
void VScreen::RenderEnd(void)
{
// do-nothing
}
void VScreen::PresentTo(HDC hdc)
{
::BitBlt(hdc, 0, 0, this->surfScr.width, this->surfScr.height, this->hdc, 0, 0, SRCCOPY);
}