author | sheepluva |
Sun, 19 Jan 2014 14:58:54 +0100 | |
changeset 10018 | bdf75f0350bd |
parent 10016 | 59a6d65fcb60 |
child 10021 | 7f36194af01c |
permissions | -rw-r--r-- |
4976 | 1 |
(* |
2 |
* Hedgewars, a free turn based strategy game |
|
9998 | 3 |
* Copyright (c) 2004-2014 Andrey Korotaev <unC0Rr@gmail.com> |
4976 | 4 |
* |
5 |
* This program is free software; you can redistribute it and/or modify |
|
6 |
* it under the terms of the GNU General Public License as published by |
|
7 |
* the Free Software Foundation; version 2 of the License |
|
8 |
* |
|
9 |
* This program is distributed in the hope that it will be useful, |
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 |
* GNU General Public License for more details. |
|
13 |
* |
|
14 |
* You should have received a copy of the GNU General Public License |
|
15 |
* along with this program; if not, write to the Free Software |
|
16 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
|
17 |
*) |
|
18 |
||
4375 | 19 |
{$INCLUDE "options.inc"} |
20 |
||
21 |
unit uTextures; |
|
22 |
interface |
|
23 |
uses SDLh, uTypes; |
|
24 |
||
25 |
function NewTexture(width, height: Longword; buf: Pointer): PTexture; |
|
6303 | 26 |
procedure Surface2GrayScale(surf: PSDL_Surface); |
4375 | 27 |
function Surface2Tex(surf: PSDL_Surface; enableClamp: boolean): PTexture; |
10018
bdf75f0350bd
(experimental) merging the new procedures for different pixel representations (1D/2D arrays) into a single procedure with the algorithm and two procedures for the different mapping. - because redundant code sucks (at least twice)
sheepluva
parents:
10016
diff
changeset
|
28 |
procedure PrettifySurfaceAlpha(surf: PSDL_Surface; pixels: PLongwordArray); |
bdf75f0350bd
(experimental) merging the new procedures for different pixel representations (1D/2D arrays) into a single procedure with the algorithm and two procedures for the different mapping. - because redundant code sucks (at least twice)
sheepluva
parents:
10016
diff
changeset
|
29 |
procedure PrettifyAlpha2D(pixels: TLandArray; height, width: LongWord); |
4375 | 30 |
procedure FreeTexture(tex: PTexture); |
9655
e154ccca4dad
Tinted crosshair (without that cool white dot in the middle)
unc0rr
parents:
9080
diff
changeset
|
31 |
procedure FreeAndNilTexture(var tex: PTexture); |
4375 | 32 |
|
33 |
procedure initModule; |
|
34 |
procedure freeModule; |
|
35 |
||
36 |
implementation |
|
6394
f0a9042e7387
yay, finally osx (and likely windows) fullscreen switch works like on linux! ALL textures had to be destroyed and recreated only after the new window got created. In other news, the new window must be cleaned with glClear to skip a first frame of garbage and AddProgress is only called the first time.
koda
parents:
6390
diff
changeset
|
37 |
uses GLunit, uUtils, uVariables, uConsts, uDebug, uConsole; |
4375 | 38 |
|
39 |
var TextureList: PTexture; |
|
40 |
||
41 |
||
42 |
procedure SetTextureParameters(enableClamp: Boolean); |
|
43 |
begin |
|
44 |
if enableClamp and ((cReducedQuality and rqClampLess) = 0) then |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6467
diff
changeset
|
45 |
begin |
4375 | 46 |
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
47 |
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE) |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6467
diff
changeset
|
48 |
end; |
4375 | 49 |
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
50 |
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR) |
|
51 |
end; |
|
52 |
||
53 |
procedure ResetVertexArrays(texture: PTexture); |
|
54 |
begin |
|
55 |
with texture^ do |
|
56 |
begin |
|
57 |
vb[0].X:= 0; |
|
58 |
vb[0].Y:= 0; |
|
59 |
vb[1].X:= w; |
|
60 |
vb[1].Y:= 0; |
|
61 |
vb[2].X:= w; |
|
62 |
vb[2].Y:= h; |
|
63 |
vb[3].X:= 0; |
|
64 |
vb[3].Y:= h; |
|
65 |
||
66 |
tb[0].X:= 0; |
|
67 |
tb[0].Y:= 0; |
|
68 |
tb[1].X:= rx; |
|
69 |
tb[1].Y:= 0; |
|
70 |
tb[2].X:= rx; |
|
71 |
tb[2].Y:= ry; |
|
72 |
tb[3].X:= 0; |
|
73 |
tb[3].Y:= ry |
|
74 |
end; |
|
75 |
end; |
|
76 |
||
77 |
function NewTexture(width, height: Longword; buf: Pointer): PTexture; |
|
78 |
begin |
|
79 |
new(NewTexture); |
|
80 |
NewTexture^.PrevTexture:= nil; |
|
81 |
NewTexture^.NextTexture:= nil; |
|
82 |
NewTexture^.Scale:= 1; |
|
83 |
if TextureList <> nil then |
|
84 |
begin |
|
85 |
TextureList^.PrevTexture:= NewTexture; |
|
86 |
NewTexture^.NextTexture:= TextureList |
|
87 |
end; |
|
88 |
TextureList:= NewTexture; |
|
89 |
||
90 |
NewTexture^.w:= width; |
|
91 |
NewTexture^.h:= height; |
|
92 |
NewTexture^.rx:= 1.0; |
|
93 |
NewTexture^.ry:= 1.0; |
|
94 |
||
95 |
ResetVertexArrays(NewTexture); |
|
96 |
||
97 |
glGenTextures(1, @NewTexture^.id); |
|
98 |
||
99 |
glBindTexture(GL_TEXTURE_2D, NewTexture^.id); |
|
100 |
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, buf); |
|
101 |
||
102 |
SetTextureParameters(true); |
|
103 |
end; |
|
104 |
||
6303 | 105 |
procedure Surface2GrayScale(surf: PSDL_Surface); |
6305
5f7480c2a08d
Set default water colours in greyscale mode in case the theme does not define them, decrement piano weapon on use
nemo
parents:
6303
diff
changeset
|
106 |
var tw, x, y: Longword; |
6303 | 107 |
fromP4: PLongWordArray; |
108 |
begin |
|
109 |
fromP4:= Surf^.pixels; |
|
110 |
for y:= 0 to Pred(Surf^.h) do |
|
111 |
begin |
|
112 |
for x:= 0 to Pred(Surf^.w) do |
|
113 |
begin |
|
114 |
tw:= fromP4^[x]; |
|
115 |
tw:= round((tw shr RShift and $FF) * RGB_LUMINANCE_RED + |
|
116 |
(tw shr GShift and $FF) * RGB_LUMINANCE_GREEN + |
|
117 |
(tw shr BShift and $FF) * RGB_LUMINANCE_BLUE); |
|
118 |
if tw > 255 then tw:= 255; |
|
119 |
tw:= (tw and $FF shl RShift) or (tw and $FF shl BShift) or (tw and $FF shl GShift) or (fromP4^[x] and AMask); |
|
120 |
fromP4^[x]:= tw; |
|
121 |
end; |
|
122 |
fromP4:= @(fromP4^[Surf^.pitch div 4]) |
|
123 |
end; |
|
124 |
end; |
|
6467 | 125 |
|
10016
59a6d65fcb60
(experimental) make the mysterious borders around land/hats/etc that appear on zoom vanish
sheepluva
parents:
9998
diff
changeset
|
126 |
{ this will make invisible pixels that have a visible neighbor have the |
59a6d65fcb60
(experimental) make the mysterious borders around land/hats/etc that appear on zoom vanish
sheepluva
parents:
9998
diff
changeset
|
127 |
same color as their visible neighbor, so that bilinear filtering won't |
59a6d65fcb60
(experimental) make the mysterious borders around land/hats/etc that appear on zoom vanish
sheepluva
parents:
9998
diff
changeset
|
128 |
display a "wrongly" colored border when zoomed in } |
10018
bdf75f0350bd
(experimental) merging the new procedures for different pixel representations (1D/2D arrays) into a single procedure with the algorithm and two procedures for the different mapping. - because redundant code sucks (at least twice)
sheepluva
parents:
10016
diff
changeset
|
129 |
procedure PrettifyAlpha(row1, row2: PLongwordArray; firsti, lasti: LongWord); |
10016
59a6d65fcb60
(experimental) make the mysterious borders around land/hats/etc that appear on zoom vanish
sheepluva
parents:
9998
diff
changeset
|
130 |
var |
10018
bdf75f0350bd
(experimental) merging the new procedures for different pixel representations (1D/2D arrays) into a single procedure with the algorithm and two procedures for the different mapping. - because redundant code sucks (at least twice)
sheepluva
parents:
10016
diff
changeset
|
131 |
i: Longword; |
10016
59a6d65fcb60
(experimental) make the mysterious borders around land/hats/etc that appear on zoom vanish
sheepluva
parents:
9998
diff
changeset
|
132 |
lpi, cpi, bpi: boolean; // was last/current/bottom neighbor pixel invisible? |
59a6d65fcb60
(experimental) make the mysterious borders around land/hats/etc that appear on zoom vanish
sheepluva
parents:
9998
diff
changeset
|
133 |
begin |
10018
bdf75f0350bd
(experimental) merging the new procedures for different pixel representations (1D/2D arrays) into a single procedure with the algorithm and two procedures for the different mapping. - because redundant code sucks (at least twice)
sheepluva
parents:
10016
diff
changeset
|
134 |
for i:=firsti to lasti do |
10016
59a6d65fcb60
(experimental) make the mysterious borders around land/hats/etc that appear on zoom vanish
sheepluva
parents:
9998
diff
changeset
|
135 |
begin |
10018
bdf75f0350bd
(experimental) merging the new procedures for different pixel representations (1D/2D arrays) into a single procedure with the algorithm and two procedures for the different mapping. - because redundant code sucks (at least twice)
sheepluva
parents:
10016
diff
changeset
|
136 |
// use first pixel in row1 as starting point |
bdf75f0350bd
(experimental) merging the new procedures for different pixel representations (1D/2D arrays) into a single procedure with the algorithm and two procedures for the different mapping. - because redundant code sucks (at least twice)
sheepluva
parents:
10016
diff
changeset
|
137 |
if i = firsti then |
bdf75f0350bd
(experimental) merging the new procedures for different pixel representations (1D/2D arrays) into a single procedure with the algorithm and two procedures for the different mapping. - because redundant code sucks (at least twice)
sheepluva
parents:
10016
diff
changeset
|
138 |
lpi:= ((row1^[i] and AMask) = 0) |
10016
59a6d65fcb60
(experimental) make the mysterious borders around land/hats/etc that appear on zoom vanish
sheepluva
parents:
9998
diff
changeset
|
139 |
else |
59a6d65fcb60
(experimental) make the mysterious borders around land/hats/etc that appear on zoom vanish
sheepluva
parents:
9998
diff
changeset
|
140 |
begin |
10018
bdf75f0350bd
(experimental) merging the new procedures for different pixel representations (1D/2D arrays) into a single procedure with the algorithm and two procedures for the different mapping. - because redundant code sucks (at least twice)
sheepluva
parents:
10016
diff
changeset
|
141 |
cpi:= ((row1^[i] and AMask) = 0); |
10016
59a6d65fcb60
(experimental) make the mysterious borders around land/hats/etc that appear on zoom vanish
sheepluva
parents:
9998
diff
changeset
|
142 |
if cpi <> lpi then |
59a6d65fcb60
(experimental) make the mysterious borders around land/hats/etc that appear on zoom vanish
sheepluva
parents:
9998
diff
changeset
|
143 |
begin |
59a6d65fcb60
(experimental) make the mysterious borders around land/hats/etc that appear on zoom vanish
sheepluva
parents:
9998
diff
changeset
|
144 |
// invisible pixels get colors from visible neighbors |
10018
bdf75f0350bd
(experimental) merging the new procedures for different pixel representations (1D/2D arrays) into a single procedure with the algorithm and two procedures for the different mapping. - because redundant code sucks (at least twice)
sheepluva
parents:
10016
diff
changeset
|
145 |
if (row1^[i] and AMask) = 0 then |
10016
59a6d65fcb60
(experimental) make the mysterious borders around land/hats/etc that appear on zoom vanish
sheepluva
parents:
9998
diff
changeset
|
146 |
begin |
10018
bdf75f0350bd
(experimental) merging the new procedures for different pixel representations (1D/2D arrays) into a single procedure with the algorithm and two procedures for the different mapping. - because redundant code sucks (at least twice)
sheepluva
parents:
10016
diff
changeset
|
147 |
row1^[i]:= row1^[i-1] and not AMask; |
10016
59a6d65fcb60
(experimental) make the mysterious borders around land/hats/etc that appear on zoom vanish
sheepluva
parents:
9998
diff
changeset
|
148 |
// as this pixel is invisible and already colored correctly now, no point in further comparing it |
59a6d65fcb60
(experimental) make the mysterious borders around land/hats/etc that appear on zoom vanish
sheepluva
parents:
9998
diff
changeset
|
149 |
lpi:= cpi; |
59a6d65fcb60
(experimental) make the mysterious borders around land/hats/etc that appear on zoom vanish
sheepluva
parents:
9998
diff
changeset
|
150 |
continue; |
59a6d65fcb60
(experimental) make the mysterious borders around land/hats/etc that appear on zoom vanish
sheepluva
parents:
9998
diff
changeset
|
151 |
end |
59a6d65fcb60
(experimental) make the mysterious borders around land/hats/etc that appear on zoom vanish
sheepluva
parents:
9998
diff
changeset
|
152 |
else |
10018
bdf75f0350bd
(experimental) merging the new procedures for different pixel representations (1D/2D arrays) into a single procedure with the algorithm and two procedures for the different mapping. - because redundant code sucks (at least twice)
sheepluva
parents:
10016
diff
changeset
|
153 |
row1^[i-1]:= row1^[i] and not AMask; |
10016
59a6d65fcb60
(experimental) make the mysterious borders around land/hats/etc that appear on zoom vanish
sheepluva
parents:
9998
diff
changeset
|
154 |
lpi:= cpi; |
59a6d65fcb60
(experimental) make the mysterious borders around land/hats/etc that appear on zoom vanish
sheepluva
parents:
9998
diff
changeset
|
155 |
end; |
59a6d65fcb60
(experimental) make the mysterious borders around land/hats/etc that appear on zoom vanish
sheepluva
parents:
9998
diff
changeset
|
156 |
end; |
59a6d65fcb60
(experimental) make the mysterious borders around land/hats/etc that appear on zoom vanish
sheepluva
parents:
9998
diff
changeset
|
157 |
// also check bottom neighbor, lpi is now current pixel info |
10018
bdf75f0350bd
(experimental) merging the new procedures for different pixel representations (1D/2D arrays) into a single procedure with the algorithm and two procedures for the different mapping. - because redundant code sucks (at least twice)
sheepluva
parents:
10016
diff
changeset
|
158 |
if row2 <> nil then |
10016
59a6d65fcb60
(experimental) make the mysterious borders around land/hats/etc that appear on zoom vanish
sheepluva
parents:
9998
diff
changeset
|
159 |
begin |
10018
bdf75f0350bd
(experimental) merging the new procedures for different pixel representations (1D/2D arrays) into a single procedure with the algorithm and two procedures for the different mapping. - because redundant code sucks (at least twice)
sheepluva
parents:
10016
diff
changeset
|
160 |
bpi:= ((row2^[i] and AMask) = 0); |
10016
59a6d65fcb60
(experimental) make the mysterious borders around land/hats/etc that appear on zoom vanish
sheepluva
parents:
9998
diff
changeset
|
161 |
if cpi <> bpi then |
59a6d65fcb60
(experimental) make the mysterious borders around land/hats/etc that appear on zoom vanish
sheepluva
parents:
9998
diff
changeset
|
162 |
begin |
59a6d65fcb60
(experimental) make the mysterious borders around land/hats/etc that appear on zoom vanish
sheepluva
parents:
9998
diff
changeset
|
163 |
if cpi then |
10018
bdf75f0350bd
(experimental) merging the new procedures for different pixel representations (1D/2D arrays) into a single procedure with the algorithm and two procedures for the different mapping. - because redundant code sucks (at least twice)
sheepluva
parents:
10016
diff
changeset
|
164 |
row1^[i]:= row2^[i] and not AMask |
10016
59a6d65fcb60
(experimental) make the mysterious borders around land/hats/etc that appear on zoom vanish
sheepluva
parents:
9998
diff
changeset
|
165 |
else |
10018
bdf75f0350bd
(experimental) merging the new procedures for different pixel representations (1D/2D arrays) into a single procedure with the algorithm and two procedures for the different mapping. - because redundant code sucks (at least twice)
sheepluva
parents:
10016
diff
changeset
|
166 |
row2^[i]:= row1^[i] and not AMask; |
10016
59a6d65fcb60
(experimental) make the mysterious borders around land/hats/etc that appear on zoom vanish
sheepluva
parents:
9998
diff
changeset
|
167 |
end; |
59a6d65fcb60
(experimental) make the mysterious borders around land/hats/etc that appear on zoom vanish
sheepluva
parents:
9998
diff
changeset
|
168 |
end; |
59a6d65fcb60
(experimental) make the mysterious borders around land/hats/etc that appear on zoom vanish
sheepluva
parents:
9998
diff
changeset
|
169 |
end; |
59a6d65fcb60
(experimental) make the mysterious borders around land/hats/etc that appear on zoom vanish
sheepluva
parents:
9998
diff
changeset
|
170 |
end; |
6467 | 171 |
|
10018
bdf75f0350bd
(experimental) merging the new procedures for different pixel representations (1D/2D arrays) into a single procedure with the algorithm and two procedures for the different mapping. - because redundant code sucks (at least twice)
sheepluva
parents:
10016
diff
changeset
|
172 |
procedure PrettifySurfaceAlpha(surf: PSDL_Surface; pixels: PLongwordArray); |
bdf75f0350bd
(experimental) merging the new procedures for different pixel representations (1D/2D arrays) into a single procedure with the algorithm and two procedures for the different mapping. - because redundant code sucks (at least twice)
sheepluva
parents:
10016
diff
changeset
|
173 |
var |
bdf75f0350bd
(experimental) merging the new procedures for different pixel representations (1D/2D arrays) into a single procedure with the algorithm and two procedures for the different mapping. - because redundant code sucks (at least twice)
sheepluva
parents:
10016
diff
changeset
|
174 |
// current row index, second last row index of array, width and first/last i of row |
bdf75f0350bd
(experimental) merging the new procedures for different pixel representations (1D/2D arrays) into a single procedure with the algorithm and two procedures for the different mapping. - because redundant code sucks (at least twice)
sheepluva
parents:
10016
diff
changeset
|
175 |
r, slr, w, si, li: LongWord; |
bdf75f0350bd
(experimental) merging the new procedures for different pixel representations (1D/2D arrays) into a single procedure with the algorithm and two procedures for the different mapping. - because redundant code sucks (at least twice)
sheepluva
parents:
10016
diff
changeset
|
176 |
begin |
bdf75f0350bd
(experimental) merging the new procedures for different pixel representations (1D/2D arrays) into a single procedure with the algorithm and two procedures for the different mapping. - because redundant code sucks (at least twice)
sheepluva
parents:
10016
diff
changeset
|
177 |
w:= surf^.w; |
bdf75f0350bd
(experimental) merging the new procedures for different pixel representations (1D/2D arrays) into a single procedure with the algorithm and two procedures for the different mapping. - because redundant code sucks (at least twice)
sheepluva
parents:
10016
diff
changeset
|
178 |
slr:= surf^.h - 2; |
bdf75f0350bd
(experimental) merging the new procedures for different pixel representations (1D/2D arrays) into a single procedure with the algorithm and two procedures for the different mapping. - because redundant code sucks (at least twice)
sheepluva
parents:
10016
diff
changeset
|
179 |
si:= 0; |
bdf75f0350bd
(experimental) merging the new procedures for different pixel representations (1D/2D arrays) into a single procedure with the algorithm and two procedures for the different mapping. - because redundant code sucks (at least twice)
sheepluva
parents:
10016
diff
changeset
|
180 |
li:= w - 1; |
bdf75f0350bd
(experimental) merging the new procedures for different pixel representations (1D/2D arrays) into a single procedure with the algorithm and two procedures for the different mapping. - because redundant code sucks (at least twice)
sheepluva
parents:
10016
diff
changeset
|
181 |
for r:= 0 to slr do |
bdf75f0350bd
(experimental) merging the new procedures for different pixel representations (1D/2D arrays) into a single procedure with the algorithm and two procedures for the different mapping. - because redundant code sucks (at least twice)
sheepluva
parents:
10016
diff
changeset
|
182 |
begin |
bdf75f0350bd
(experimental) merging the new procedures for different pixel representations (1D/2D arrays) into a single procedure with the algorithm and two procedures for the different mapping. - because redundant code sucks (at least twice)
sheepluva
parents:
10016
diff
changeset
|
183 |
PrettifyAlpha(pixels, pixels, si, li); |
bdf75f0350bd
(experimental) merging the new procedures for different pixel representations (1D/2D arrays) into a single procedure with the algorithm and two procedures for the different mapping. - because redundant code sucks (at least twice)
sheepluva
parents:
10016
diff
changeset
|
184 |
// move indices to next row |
bdf75f0350bd
(experimental) merging the new procedures for different pixel representations (1D/2D arrays) into a single procedure with the algorithm and two procedures for the different mapping. - because redundant code sucks (at least twice)
sheepluva
parents:
10016
diff
changeset
|
185 |
si:= si + w; |
bdf75f0350bd
(experimental) merging the new procedures for different pixel representations (1D/2D arrays) into a single procedure with the algorithm and two procedures for the different mapping. - because redundant code sucks (at least twice)
sheepluva
parents:
10016
diff
changeset
|
186 |
li:= li + w; |
bdf75f0350bd
(experimental) merging the new procedures for different pixel representations (1D/2D arrays) into a single procedure with the algorithm and two procedures for the different mapping. - because redundant code sucks (at least twice)
sheepluva
parents:
10016
diff
changeset
|
187 |
end; |
bdf75f0350bd
(experimental) merging the new procedures for different pixel representations (1D/2D arrays) into a single procedure with the algorithm and two procedures for the different mapping. - because redundant code sucks (at least twice)
sheepluva
parents:
10016
diff
changeset
|
188 |
// don't forget last row |
bdf75f0350bd
(experimental) merging the new procedures for different pixel representations (1D/2D arrays) into a single procedure with the algorithm and two procedures for the different mapping. - because redundant code sucks (at least twice)
sheepluva
parents:
10016
diff
changeset
|
189 |
PrettifyAlpha(pixels, nil, si, li); |
bdf75f0350bd
(experimental) merging the new procedures for different pixel representations (1D/2D arrays) into a single procedure with the algorithm and two procedures for the different mapping. - because redundant code sucks (at least twice)
sheepluva
parents:
10016
diff
changeset
|
190 |
end; |
bdf75f0350bd
(experimental) merging the new procedures for different pixel representations (1D/2D arrays) into a single procedure with the algorithm and two procedures for the different mapping. - because redundant code sucks (at least twice)
sheepluva
parents:
10016
diff
changeset
|
191 |
|
bdf75f0350bd
(experimental) merging the new procedures for different pixel representations (1D/2D arrays) into a single procedure with the algorithm and two procedures for the different mapping. - because redundant code sucks (at least twice)
sheepluva
parents:
10016
diff
changeset
|
192 |
procedure PrettifyAlpha2D(pixels: TLandArray; height, width: LongWord); |
bdf75f0350bd
(experimental) merging the new procedures for different pixel representations (1D/2D arrays) into a single procedure with the algorithm and two procedures for the different mapping. - because redundant code sucks (at least twice)
sheepluva
parents:
10016
diff
changeset
|
193 |
var |
bdf75f0350bd
(experimental) merging the new procedures for different pixel representations (1D/2D arrays) into a single procedure with the algorithm and two procedures for the different mapping. - because redundant code sucks (at least twice)
sheepluva
parents:
10016
diff
changeset
|
194 |
// current y; last x, second last y of array; |
bdf75f0350bd
(experimental) merging the new procedures for different pixel representations (1D/2D arrays) into a single procedure with the algorithm and two procedures for the different mapping. - because redundant code sucks (at least twice)
sheepluva
parents:
10016
diff
changeset
|
195 |
y, lx, sly: LongWord; |
bdf75f0350bd
(experimental) merging the new procedures for different pixel representations (1D/2D arrays) into a single procedure with the algorithm and two procedures for the different mapping. - because redundant code sucks (at least twice)
sheepluva
parents:
10016
diff
changeset
|
196 |
begin |
bdf75f0350bd
(experimental) merging the new procedures for different pixel representations (1D/2D arrays) into a single procedure with the algorithm and two procedures for the different mapping. - because redundant code sucks (at least twice)
sheepluva
parents:
10016
diff
changeset
|
197 |
sly:= height - 2; |
bdf75f0350bd
(experimental) merging the new procedures for different pixel representations (1D/2D arrays) into a single procedure with the algorithm and two procedures for the different mapping. - because redundant code sucks (at least twice)
sheepluva
parents:
10016
diff
changeset
|
198 |
lx:= width - 1; |
bdf75f0350bd
(experimental) merging the new procedures for different pixel representations (1D/2D arrays) into a single procedure with the algorithm and two procedures for the different mapping. - because redundant code sucks (at least twice)
sheepluva
parents:
10016
diff
changeset
|
199 |
for y:= 0 to sly do |
bdf75f0350bd
(experimental) merging the new procedures for different pixel representations (1D/2D arrays) into a single procedure with the algorithm and two procedures for the different mapping. - because redundant code sucks (at least twice)
sheepluva
parents:
10016
diff
changeset
|
200 |
begin |
bdf75f0350bd
(experimental) merging the new procedures for different pixel representations (1D/2D arrays) into a single procedure with the algorithm and two procedures for the different mapping. - because redundant code sucks (at least twice)
sheepluva
parents:
10016
diff
changeset
|
201 |
PrettifyAlpha(PLongWordArray(pixels[y]), PLongWordArray(pixels[y+1]), 0, lx); |
bdf75f0350bd
(experimental) merging the new procedures for different pixel representations (1D/2D arrays) into a single procedure with the algorithm and two procedures for the different mapping. - because redundant code sucks (at least twice)
sheepluva
parents:
10016
diff
changeset
|
202 |
end; |
bdf75f0350bd
(experimental) merging the new procedures for different pixel representations (1D/2D arrays) into a single procedure with the algorithm and two procedures for the different mapping. - because redundant code sucks (at least twice)
sheepluva
parents:
10016
diff
changeset
|
203 |
// don't forget last row |
bdf75f0350bd
(experimental) merging the new procedures for different pixel representations (1D/2D arrays) into a single procedure with the algorithm and two procedures for the different mapping. - because redundant code sucks (at least twice)
sheepluva
parents:
10016
diff
changeset
|
204 |
PrettifyAlpha(PLongWordArray(pixels[sly+1]), nil, 0, lx); |
bdf75f0350bd
(experimental) merging the new procedures for different pixel representations (1D/2D arrays) into a single procedure with the algorithm and two procedures for the different mapping. - because redundant code sucks (at least twice)
sheepluva
parents:
10016
diff
changeset
|
205 |
end; |
bdf75f0350bd
(experimental) merging the new procedures for different pixel representations (1D/2D arrays) into a single procedure with the algorithm and two procedures for the different mapping. - because redundant code sucks (at least twice)
sheepluva
parents:
10016
diff
changeset
|
206 |
|
4375 | 207 |
function Surface2Tex(surf: PSDL_Surface; enableClamp: boolean): PTexture; |
208 |
var tw, th, x, y: Longword; |
|
209 |
tmpp: pointer; |
|
210 |
fromP4, toP4: PLongWordArray; |
|
211 |
begin |
|
8027
e5ba3dd12531
make stats-only mode work headless. also skip a few things to save time/memory.
nemo
parents:
7151
diff
changeset
|
212 |
if cOnlyStats then exit(nil); |
4375 | 213 |
new(Surface2Tex); |
214 |
Surface2Tex^.PrevTexture:= nil; |
|
215 |
Surface2Tex^.NextTexture:= nil; |
|
216 |
if TextureList <> nil then |
|
217 |
begin |
|
218 |
TextureList^.PrevTexture:= Surface2Tex; |
|
219 |
Surface2Tex^.NextTexture:= TextureList |
|
220 |
end; |
|
221 |
TextureList:= Surface2Tex; |
|
222 |
||
223 |
Surface2Tex^.w:= surf^.w; |
|
224 |
Surface2Tex^.h:= surf^.h; |
|
225 |
||
226 |
if (surf^.format^.BytesPerPixel <> 4) then |
|
227 |
begin |
|
228 |
TryDo(false, 'Surface2Tex failed, expecting 32 bit surface', true); |
|
229 |
Surface2Tex^.id:= 0; |
|
230 |
exit |
|
231 |
end; |
|
232 |
||
233 |
glGenTextures(1, @Surface2Tex^.id); |
|
234 |
||
235 |
glBindTexture(GL_TEXTURE_2D, Surface2Tex^.id); |
|
236 |
||
237 |
if SDL_MustLock(surf) then |
|
238 |
SDLTry(SDL_LockSurface(surf) >= 0, true); |
|
239 |
||
5441
39962b855540
Add grayscale option for 3d, helps with colour clashing
nemo
parents:
4976
diff
changeset
|
240 |
fromP4:= Surf^.pixels; |
39962b855540
Add grayscale option for 3d, helps with colour clashing
nemo
parents:
4976
diff
changeset
|
241 |
|
6982 | 242 |
if GrayScale then |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6467
diff
changeset
|
243 |
Surface2GrayScale(Surf); |
6303 | 244 |
|
10016
59a6d65fcb60
(experimental) make the mysterious borders around land/hats/etc that appear on zoom vanish
sheepluva
parents:
9998
diff
changeset
|
245 |
PrettifySurfaceAlpha(surf, fromP4); |
59a6d65fcb60
(experimental) make the mysterious borders around land/hats/etc that appear on zoom vanish
sheepluva
parents:
9998
diff
changeset
|
246 |
|
4375 | 247 |
if (not SupportNPOTT) and (not (isPowerOf2(Surf^.w) and isPowerOf2(Surf^.h))) then |
248 |
begin |
|
249 |
tw:= toPowerOf2(Surf^.w); |
|
250 |
th:= toPowerOf2(Surf^.h); |
|
251 |
||
252 |
Surface2Tex^.rx:= Surf^.w / tw; |
|
253 |
Surface2Tex^.ry:= Surf^.h / th; |
|
254 |
||
7151 | 255 |
tmpp:= GetMem(tw * th * surf^.format^.BytesPerPixel); |
4375 | 256 |
|
257 |
fromP4:= Surf^.pixels; |
|
258 |
toP4:= tmpp; |
|
259 |
||
260 |
for y:= 0 to Pred(Surf^.h) do |
|
261 |
begin |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6467
diff
changeset
|
262 |
for x:= 0 to Pred(Surf^.w) do |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6467
diff
changeset
|
263 |
toP4^[x]:= fromP4^[x]; |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6467
diff
changeset
|
264 |
for x:= Surf^.w to Pred(tw) do |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6467
diff
changeset
|
265 |
toP4^[x]:= 0; |
4375 | 266 |
toP4:= @(toP4^[tw]); |
267 |
fromP4:= @(fromP4^[Surf^.pitch div 4]) |
|
268 |
end; |
|
269 |
||
270 |
for y:= Surf^.h to Pred(th) do |
|
271 |
begin |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6467
diff
changeset
|
272 |
for x:= 0 to Pred(tw) do |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6467
diff
changeset
|
273 |
toP4^[x]:= 0; |
4375 | 274 |
toP4:= @(toP4^[tw]) |
275 |
end; |
|
276 |
||
277 |
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tw, th, 0, GL_RGBA, GL_UNSIGNED_BYTE, tmpp); |
|
278 |
||
279 |
FreeMem(tmpp, tw * th * surf^.format^.BytesPerPixel) |
|
280 |
end |
|
281 |
else |
|
282 |
begin |
|
283 |
Surface2Tex^.rx:= 1.0; |
|
284 |
Surface2Tex^.ry:= 1.0; |
|
285 |
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, surf^.w, surf^.h, 0, GL_RGBA, GL_UNSIGNED_BYTE, surf^.pixels); |
|
286 |
end; |
|
287 |
||
288 |
ResetVertexArrays(Surface2Tex); |
|
289 |
||
290 |
if SDL_MustLock(surf) then |
|
291 |
SDL_UnlockSurface(surf); |
|
292 |
||
293 |
SetTextureParameters(enableClamp); |
|
294 |
end; |
|
295 |
||
4901 | 296 |
// deletes texture and frees the memory allocated for it. |
297 |
// if nil is passed nothing is done |
|
4375 | 298 |
procedure FreeTexture(tex: PTexture); |
299 |
begin |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6467
diff
changeset
|
300 |
if tex <> nil then |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6467
diff
changeset
|
301 |
begin |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6467
diff
changeset
|
302 |
if tex^.NextTexture <> nil then |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6467
diff
changeset
|
303 |
tex^.NextTexture^.PrevTexture:= tex^.PrevTexture; |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6467
diff
changeset
|
304 |
if tex^.PrevTexture <> nil then |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6467
diff
changeset
|
305 |
tex^.PrevTexture^.NextTexture:= tex^.NextTexture |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6467
diff
changeset
|
306 |
else |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6467
diff
changeset
|
307 |
TextureList:= tex^.NextTexture; |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6467
diff
changeset
|
308 |
glDeleteTextures(1, @tex^.id); |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6467
diff
changeset
|
309 |
Dispose(tex); |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6467
diff
changeset
|
310 |
end |
4375 | 311 |
end; |
312 |
||
9655
e154ccca4dad
Tinted crosshair (without that cool white dot in the middle)
unc0rr
parents:
9080
diff
changeset
|
313 |
procedure FreeAndNilTexture(var tex: PTexture); |
e154ccca4dad
Tinted crosshair (without that cool white dot in the middle)
unc0rr
parents:
9080
diff
changeset
|
314 |
begin |
e154ccca4dad
Tinted crosshair (without that cool white dot in the middle)
unc0rr
parents:
9080
diff
changeset
|
315 |
FreeTexture(tex); |
e154ccca4dad
Tinted crosshair (without that cool white dot in the middle)
unc0rr
parents:
9080
diff
changeset
|
316 |
tex:= nil |
e154ccca4dad
Tinted crosshair (without that cool white dot in the middle)
unc0rr
parents:
9080
diff
changeset
|
317 |
end; |
e154ccca4dad
Tinted crosshair (without that cool white dot in the middle)
unc0rr
parents:
9080
diff
changeset
|
318 |
|
4375 | 319 |
procedure initModule; |
320 |
begin |
|
321 |
TextureList:= nil; |
|
322 |
end; |
|
323 |
||
324 |
procedure freeModule; |
|
325 |
begin |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6467
diff
changeset
|
326 |
if TextureList <> nil then |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6467
diff
changeset
|
327 |
WriteToConsole('FIXME FIXME FIXME. App shutdown without full cleanup of texture list; read game0.log and please report this problem'); |
6390
3807d4cad077
This should have been added before. add log spew if this ever happens. We should hopefully identify the various circumstances and make sure it is all cleaned up so the list becomes unnecessary.
nemo
parents:
6380
diff
changeset
|
328 |
while TextureList <> nil do |
3807d4cad077
This should have been added before. add log spew if this ever happens. We should hopefully identify the various circumstances and make sure it is all cleaned up so the list becomes unnecessary.
nemo
parents:
6380
diff
changeset
|
329 |
begin |
3807d4cad077
This should have been added before. add log spew if this ever happens. We should hopefully identify the various circumstances and make sure it is all cleaned up so the list becomes unnecessary.
nemo
parents:
6380
diff
changeset
|
330 |
AddFileLog('Texture not freed: width='+inttostr(LongInt(TextureList^.w))+' height='+inttostr(LongInt(TextureList^.h))+' priority='+inttostr(round(TextureList^.priority*1000))); |
3807d4cad077
This should have been added before. add log spew if this ever happens. We should hopefully identify the various circumstances and make sure it is all cleaned up so the list becomes unnecessary.
nemo
parents:
6380
diff
changeset
|
331 |
FreeTexture(TextureList); |
3807d4cad077
This should have been added before. add log spew if this ever happens. We should hopefully identify the various circumstances and make sure it is all cleaned up so the list becomes unnecessary.
nemo
parents:
6380
diff
changeset
|
332 |
end |
4375 | 333 |
end; |
334 |
||
4901 | 335 |
end. |