author | nemo |
Thu, 20 Apr 2017 11:22:29 -0400 | |
changeset 12299 | 0deabf747b8f |
parent 11537 | bf86c6cb9341 |
child 12770 | d01e9dd5c439 |
permissions | -rw-r--r-- |
4976 | 1 |
(* |
2 |
* Hedgewars, a free turn based strategy game |
|
11046 | 3 |
* Copyright (c) 2004-2015 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 |
|
10108
c68cf030eded
update FSF address. note: two sdl include files (by Sam Lantinga) still have the old FSF address in their copyright - but I ain't gonna touch their copyright headers
sheepluva
parents:
10078
diff
changeset
|
16 |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
4976 | 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); |
9655
e154ccca4dad
Tinted crosshair (without that cool white dot in the middle)
unc0rr
parents:
9080
diff
changeset
|
30 |
procedure FreeAndNilTexture(var tex: PTexture); |
4375 | 31 |
|
32 |
procedure initModule; |
|
33 |
procedure freeModule; |
|
34 |
||
35 |
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
|
36 |
uses GLunit, uUtils, uVariables, uConsts, uDebug, uConsole; |
4375 | 37 |
|
38 |
var TextureList: PTexture; |
|
39 |
||
40 |
||
41 |
procedure SetTextureParameters(enableClamp: Boolean); |
|
42 |
begin |
|
43 |
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
|
44 |
begin |
4375 | 45 |
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
46 |
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
|
47 |
end; |
4375 | 48 |
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
49 |
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR) |
|
50 |
end; |
|
51 |
||
52 |
procedure ResetVertexArrays(texture: PTexture); |
|
53 |
begin |
|
54 |
with texture^ do |
|
55 |
begin |
|
56 |
vb[0].X:= 0; |
|
57 |
vb[0].Y:= 0; |
|
58 |
vb[1].X:= w; |
|
59 |
vb[1].Y:= 0; |
|
60 |
vb[2].X:= w; |
|
61 |
vb[2].Y:= h; |
|
62 |
vb[3].X:= 0; |
|
63 |
vb[3].Y:= h; |
|
64 |
||
65 |
tb[0].X:= 0; |
|
66 |
tb[0].Y:= 0; |
|
67 |
tb[1].X:= rx; |
|
68 |
tb[1].Y:= 0; |
|
69 |
tb[2].X:= rx; |
|
70 |
tb[2].Y:= ry; |
|
71 |
tb[3].X:= 0; |
|
72 |
tb[3].Y:= ry |
|
73 |
end; |
|
74 |
end; |
|
75 |
||
76 |
function NewTexture(width, height: Longword; buf: Pointer): PTexture; |
|
77 |
begin |
|
78 |
new(NewTexture); |
|
79 |
NewTexture^.PrevTexture:= nil; |
|
80 |
NewTexture^.NextTexture:= nil; |
|
81 |
NewTexture^.Scale:= 1; |
|
82 |
if TextureList <> nil then |
|
83 |
begin |
|
84 |
TextureList^.PrevTexture:= NewTexture; |
|
85 |
NewTexture^.NextTexture:= TextureList |
|
86 |
end; |
|
87 |
TextureList:= NewTexture; |
|
88 |
||
89 |
NewTexture^.w:= width; |
|
90 |
NewTexture^.h:= height; |
|
91 |
NewTexture^.rx:= 1.0; |
|
92 |
NewTexture^.ry:= 1.0; |
|
93 |
||
94 |
ResetVertexArrays(NewTexture); |
|
95 |
||
96 |
glGenTextures(1, @NewTexture^.id); |
|
97 |
||
98 |
glBindTexture(GL_TEXTURE_2D, NewTexture^.id); |
|
99 |
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, buf); |
|
100 |
||
101 |
SetTextureParameters(true); |
|
102 |
end; |
|
103 |
||
6303 | 104 |
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
|
105 |
var tw, x, y: Longword; |
6303 | 106 |
fromP4: PLongWordArray; |
107 |
begin |
|
108 |
fromP4:= Surf^.pixels; |
|
109 |
for y:= 0 to Pred(Surf^.h) do |
|
110 |
begin |
|
10017 | 111 |
for x:= 0 to Pred(Surf^.w) do |
6303 | 112 |
begin |
113 |
tw:= fromP4^[x]; |
|
10017 | 114 |
tw:= round((tw shr RShift and $FF) * RGB_LUMINANCE_RED + |
115 |
(tw shr GShift and $FF) * RGB_LUMINANCE_GREEN + |
|
6303 | 116 |
(tw shr BShift and $FF) * RGB_LUMINANCE_BLUE); |
117 |
if tw > 255 then tw:= 255; |
|
118 |
tw:= (tw and $FF shl RShift) or (tw and $FF shl BShift) or (tw and $FF shl GShift) or (fromP4^[x] and AMask); |
|
119 |
fromP4^[x]:= tw; |
|
120 |
end; |
|
10131
4b4a043111f4
- pas2c recognizes typecasts in initialization expressions
unc0rr
parents:
10108
diff
changeset
|
121 |
fromP4:= PLongWordArray(@(fromP4^[Surf^.pitch div 4])) |
6303 | 122 |
end; |
123 |
end; |
|
6467 | 124 |
|
10016
59a6d65fcb60
(experimental) make the mysterious borders around land/hats/etc that appear on zoom vanish
sheepluva
parents:
9998
diff
changeset
|
125 |
{ 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
|
126 |
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
|
127 |
display a "wrongly" colored border when zoomed in } |
10021
7f36194af01c
no idea how I ended up forgetting about the offset I need for same position in different rows (in 1d array); also remove obsolete comment
sheepluva
parents:
10018
diff
changeset
|
128 |
procedure PrettifyAlpha(row1, row2: PLongwordArray; firsti, lasti, ioffset: LongWord); |
7304
8b3575750cd2
Added auto cropping to atlasing
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
7297
diff
changeset
|
129 |
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
|
130 |
i: Longword; |
10016
59a6d65fcb60
(experimental) make the mysterious borders around land/hats/etc that appear on zoom vanish
sheepluva
parents:
9998
diff
changeset
|
131 |
lpi, cpi, bpi: boolean; // was last/current/bottom neighbor pixel invisible? |
7304
8b3575750cd2
Added auto cropping to atlasing
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
7297
diff
changeset
|
132 |
begin |
10021
7f36194af01c
no idea how I ended up forgetting about the offset I need for same position in different rows (in 1d array); also remove obsolete comment
sheepluva
parents:
10018
diff
changeset
|
133 |
// suppress incorrect warning |
7f36194af01c
no idea how I ended up forgetting about the offset I need for same position in different rows (in 1d array); also remove obsolete comment
sheepluva
parents:
10018
diff
changeset
|
134 |
lpi:= true; |
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
|
135 |
for i:=firsti to lasti do |
7304
8b3575750cd2
Added auto cropping to atlasing
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
7297
diff
changeset
|
136 |
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
|
137 |
// 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
|
138 |
if i = firsti then |
10021
7f36194af01c
no idea how I ended up forgetting about the offset I need for same position in different rows (in 1d array); also remove obsolete comment
sheepluva
parents:
10018
diff
changeset
|
139 |
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
|
140 |
else |
7304
8b3575750cd2
Added auto cropping to atlasing
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
7297
diff
changeset
|
141 |
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
|
142 |
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
|
143 |
if cpi <> lpi then |
59a6d65fcb60
(experimental) make the mysterious borders around land/hats/etc that appear on zoom vanish
sheepluva
parents:
9998
diff
changeset
|
144 |
begin |
59a6d65fcb60
(experimental) make the mysterious borders around land/hats/etc that appear on zoom vanish
sheepluva
parents:
9998
diff
changeset
|
145 |
// invisible pixels get colors from visible neighbors |
10021
7f36194af01c
no idea how I ended up forgetting about the offset I need for same position in different rows (in 1d array); also remove obsolete comment
sheepluva
parents:
10018
diff
changeset
|
146 |
if cpi then |
10016
59a6d65fcb60
(experimental) make the mysterious borders around land/hats/etc that appear on zoom vanish
sheepluva
parents:
9998
diff
changeset
|
147 |
begin |
10078 | 148 |
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
|
149 |
// 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
|
150 |
lpi:= cpi; |
59a6d65fcb60
(experimental) make the mysterious borders around land/hats/etc that appear on zoom vanish
sheepluva
parents:
9998
diff
changeset
|
151 |
continue; |
59a6d65fcb60
(experimental) make the mysterious borders around land/hats/etc that appear on zoom vanish
sheepluva
parents:
9998
diff
changeset
|
152 |
end |
59a6d65fcb60
(experimental) make the mysterious borders around land/hats/etc that appear on zoom vanish
sheepluva
parents:
9998
diff
changeset
|
153 |
else |
10078 | 154 |
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
|
155 |
end; |
7304
8b3575750cd2
Added auto cropping to atlasing
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
7297
diff
changeset
|
156 |
end; |
10021
7f36194af01c
no idea how I ended up forgetting about the offset I need for same position in different rows (in 1d array); also remove obsolete comment
sheepluva
parents:
10018
diff
changeset
|
157 |
lpi:= cpi; |
7f36194af01c
no idea how I ended up forgetting about the offset I need for same position in different rows (in 1d array); also remove obsolete comment
sheepluva
parents:
10018
diff
changeset
|
158 |
// also check bottom neighbor |
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
|
159 |
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
|
160 |
begin |
10021
7f36194af01c
no idea how I ended up forgetting about the offset I need for same position in different rows (in 1d array); also remove obsolete comment
sheepluva
parents:
10018
diff
changeset
|
161 |
bpi:= ((row2^[i+ioffset] and AMask) = 0); |
10016
59a6d65fcb60
(experimental) make the mysterious borders around land/hats/etc that appear on zoom vanish
sheepluva
parents:
9998
diff
changeset
|
162 |
if cpi <> bpi then |
59a6d65fcb60
(experimental) make the mysterious borders around land/hats/etc that appear on zoom vanish
sheepluva
parents:
9998
diff
changeset
|
163 |
begin |
59a6d65fcb60
(experimental) make the mysterious borders around land/hats/etc that appear on zoom vanish
sheepluva
parents:
9998
diff
changeset
|
164 |
if cpi then |
10078 | 165 |
row1^[i]:= row2^[i+ioffset] and (not AMask) |
10016
59a6d65fcb60
(experimental) make the mysterious borders around land/hats/etc that appear on zoom vanish
sheepluva
parents:
9998
diff
changeset
|
166 |
else |
10078 | 167 |
row2^[i+ioffset]:= 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
|
168 |
end; |
59a6d65fcb60
(experimental) make the mysterious borders around land/hats/etc that appear on zoom vanish
sheepluva
parents:
9998
diff
changeset
|
169 |
end; |
7304
8b3575750cd2
Added auto cropping to atlasing
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
7297
diff
changeset
|
170 |
end; |
8b3575750cd2
Added auto cropping to atlasing
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
7297
diff
changeset
|
171 |
end; |
8b3575750cd2
Added auto cropping to atlasing
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
7297
diff
changeset
|
172 |
|
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
|
173 |
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
|
174 |
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
|
175 |
// 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
|
176 |
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
|
177 |
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
|
178 |
w:= surf^.w; |
11492
8e221d2a368e
don't attempt to prettify alpha of single-pixel textures (segfault with "digital" theme from forums)
sheepluva
parents:
11342
diff
changeset
|
179 |
// just a single pixel, nothing to do here |
8e221d2a368e
don't attempt to prettify alpha of single-pixel textures (segfault with "digital" theme from forums)
sheepluva
parents:
11342
diff
changeset
|
180 |
if (w < 2) and (surf^.h < 2) then |
8e221d2a368e
don't attempt to prettify alpha of single-pixel textures (segfault with "digital" theme from forums)
sheepluva
parents:
11342
diff
changeset
|
181 |
exit; |
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
|
182 |
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
|
183 |
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
|
184 |
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
|
185 |
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
|
186 |
begin |
10021
7f36194af01c
no idea how I ended up forgetting about the offset I need for same position in different rows (in 1d array); also remove obsolete comment
sheepluva
parents:
10018
diff
changeset
|
187 |
PrettifyAlpha(pixels, pixels, si, li, w); |
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
|
188 |
// 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
|
189 |
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
|
190 |
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
|
191 |
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
|
192 |
// don't forget last row |
10021
7f36194af01c
no idea how I ended up forgetting about the offset I need for same position in different rows (in 1d array); also remove obsolete comment
sheepluva
parents:
10018
diff
changeset
|
193 |
PrettifyAlpha(pixels, nil, si, li, w); |
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
|
194 |
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
|
195 |
|
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 |
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
|
197 |
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
|
198 |
// 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
|
199 |
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
|
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 |
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
|
202 |
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
|
203 |
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
|
204 |
begin |
10021
7f36194af01c
no idea how I ended up forgetting about the offset I need for same position in different rows (in 1d array); also remove obsolete comment
sheepluva
parents:
10018
diff
changeset
|
205 |
PrettifyAlpha(PLongWordArray(pixels[y]), PLongWordArray(pixels[y+1]), 0, lx, 0); |
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
|
206 |
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
|
207 |
// don't forget last row |
10021
7f36194af01c
no idea how I ended up forgetting about the offset I need for same position in different rows (in 1d array); also remove obsolete comment
sheepluva
parents:
10018
diff
changeset
|
208 |
PrettifyAlpha(PLongWordArray(pixels[sly+1]), nil, 0, lx, 0); |
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
|
209 |
end; |
6467 | 210 |
|
4375 | 211 |
function Surface2Tex(surf: PSDL_Surface; enableClamp: boolean): PTexture; |
212 |
var tw, th, x, y: Longword; |
|
213 |
tmpp: pointer; |
|
214 |
fromP4, toP4: PLongWordArray; |
|
215 |
begin |
|
8027
e5ba3dd12531
make stats-only mode work headless. also skip a few things to save time/memory.
nemo
parents:
7151
diff
changeset
|
216 |
if cOnlyStats then exit(nil); |
4375 | 217 |
new(Surface2Tex); |
218 |
Surface2Tex^.PrevTexture:= nil; |
|
219 |
Surface2Tex^.NextTexture:= nil; |
|
220 |
if TextureList <> nil then |
|
221 |
begin |
|
222 |
TextureList^.PrevTexture:= Surface2Tex; |
|
223 |
Surface2Tex^.NextTexture:= TextureList |
|
224 |
end; |
|
225 |
TextureList:= Surface2Tex; |
|
226 |
||
227 |
Surface2Tex^.w:= surf^.w; |
|
228 |
Surface2Tex^.h:= surf^.h; |
|
229 |
||
230 |
if (surf^.format^.BytesPerPixel <> 4) then |
|
231 |
begin |
|
11537 | 232 |
checkFails(false, 'Surface2Tex failed, expecting 32 bit surface', true); |
4375 | 233 |
Surface2Tex^.id:= 0; |
234 |
exit |
|
235 |
end; |
|
236 |
||
237 |
glGenTextures(1, @Surface2Tex^.id); |
|
238 |
||
239 |
glBindTexture(GL_TEXTURE_2D, Surface2Tex^.id); |
|
240 |
||
241 |
if SDL_MustLock(surf) then |
|
11512 | 242 |
if SDLCheck(SDL_LockSurface(surf) >= 0, 'Lock surface', true) then |
243 |
exit(nil); |
|
4375 | 244 |
|
5441
39962b855540
Add grayscale option for 3d, helps with colour clashing
nemo
parents:
4976
diff
changeset
|
245 |
fromP4:= Surf^.pixels; |
39962b855540
Add grayscale option for 3d, helps with colour clashing
nemo
parents:
4976
diff
changeset
|
246 |
|
6982 | 247 |
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
|
248 |
Surface2GrayScale(Surf); |
6303 | 249 |
|
10016
59a6d65fcb60
(experimental) make the mysterious borders around land/hats/etc that appear on zoom vanish
sheepluva
parents:
9998
diff
changeset
|
250 |
PrettifySurfaceAlpha(surf, fromP4); |
59a6d65fcb60
(experimental) make the mysterious borders around land/hats/etc that appear on zoom vanish
sheepluva
parents:
9998
diff
changeset
|
251 |
|
4375 | 252 |
if (not SupportNPOTT) and (not (isPowerOf2(Surf^.w) and isPowerOf2(Surf^.h))) then |
253 |
begin |
|
254 |
tw:= toPowerOf2(Surf^.w); |
|
255 |
th:= toPowerOf2(Surf^.h); |
|
256 |
||
257 |
Surface2Tex^.rx:= Surf^.w / tw; |
|
258 |
Surface2Tex^.ry:= Surf^.h / th; |
|
259 |
||
7151 | 260 |
tmpp:= GetMem(tw * th * surf^.format^.BytesPerPixel); |
4375 | 261 |
|
262 |
fromP4:= Surf^.pixels; |
|
263 |
toP4:= tmpp; |
|
264 |
||
265 |
for y:= 0 to Pred(Surf^.h) do |
|
266 |
begin |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6467
diff
changeset
|
267 |
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
|
268 |
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
|
269 |
for x:= Surf^.w to Pred(tw) do |
10155
ac01a2aeff69
change how textures from non-power-of-2-width textures are filled. this fixes e.g. the vertical lines appearing between Bath theme's horizontL
sheepluva
parents:
10131
diff
changeset
|
270 |
toP4^[x]:= fromP4^[0]; |
10131
4b4a043111f4
- pas2c recognizes typecasts in initialization expressions
unc0rr
parents:
10108
diff
changeset
|
271 |
toP4:= PLongWordArray(@(toP4^[tw])); |
4b4a043111f4
- pas2c recognizes typecasts in initialization expressions
unc0rr
parents:
10108
diff
changeset
|
272 |
fromP4:= PLongWordArray(@(fromP4^[Surf^.pitch div 4])) |
4375 | 273 |
end; |
274 |
||
275 |
for y:= Surf^.h to Pred(th) do |
|
276 |
begin |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6467
diff
changeset
|
277 |
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
|
278 |
toP4^[x]:= 0; |
10131
4b4a043111f4
- pas2c recognizes typecasts in initialization expressions
unc0rr
parents:
10108
diff
changeset
|
279 |
toP4:= PLongWordArray(@(toP4^[tw])) |
4375 | 280 |
end; |
281 |
||
282 |
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tw, th, 0, GL_RGBA, GL_UNSIGNED_BYTE, tmpp); |
|
283 |
||
284 |
FreeMem(tmpp, tw * th * surf^.format^.BytesPerPixel) |
|
285 |
end |
|
286 |
else |
|
287 |
begin |
|
288 |
Surface2Tex^.rx:= 1.0; |
|
289 |
Surface2Tex^.ry:= 1.0; |
|
290 |
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, surf^.w, surf^.h, 0, GL_RGBA, GL_UNSIGNED_BYTE, surf^.pixels); |
|
291 |
end; |
|
292 |
||
293 |
ResetVertexArrays(Surface2Tex); |
|
294 |
||
295 |
if SDL_MustLock(surf) then |
|
296 |
SDL_UnlockSurface(surf); |
|
297 |
||
298 |
SetTextureParameters(enableClamp); |
|
299 |
end; |
|
300 |
||
4901 | 301 |
// deletes texture and frees the memory allocated for it. |
302 |
// if nil is passed nothing is done |
|
9655
e154ccca4dad
Tinted crosshair (without that cool white dot in the middle)
unc0rr
parents:
9080
diff
changeset
|
303 |
procedure FreeAndNilTexture(var tex: PTexture); |
e154ccca4dad
Tinted crosshair (without that cool white dot in the middle)
unc0rr
parents:
9080
diff
changeset
|
304 |
begin |
7304
8b3575750cd2
Added auto cropping to atlasing
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
7297
diff
changeset
|
305 |
if tex <> nil then |
8b3575750cd2
Added auto cropping to atlasing
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
7297
diff
changeset
|
306 |
begin |
10647 | 307 |
if tex^.NextTexture <> nil then |
308 |
tex^.NextTexture^.PrevTexture:= tex^.PrevTexture; |
|
309 |
if tex^.PrevTexture <> nil then |
|
310 |
tex^.PrevTexture^.NextTexture:= tex^.NextTexture |
|
311 |
else |
|
312 |
TextureList:= tex^.NextTexture; |
|
313 |
glDeleteTextures(1, @tex^.id); |
|
314 |
Dispose(tex); |
|
315 |
tex:= nil; |
|
7304
8b3575750cd2
Added auto cropping to atlasing
Wolfgang Steffens <WolfgangSteff@gmail.com>
parents:
7297
diff
changeset
|
316 |
end; |
9655
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; |
|
10647 | 325 |
var tex: PTexture; |
4375 | 326 |
begin |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6467
diff
changeset
|
327 |
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
|
328 |
WriteToConsole('FIXME FIXME FIXME. App shutdown without full cleanup of texture list; read game0.log and please report this problem'); |
10017 | 329 |
while TextureList <> nil do |
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
|
330 |
begin |
10647 | 331 |
tex:= TextureList; |
332 |
AddFileLog('Texture not freed: width='+inttostr(LongInt(tex^.w))+' height='+inttostr(LongInt(tex^.h))+' priority='+inttostr(round(tex^.priority*1000))); |
|
333 |
FreeAndNilTexture(tex); |
|
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
|
334 |
end |
4375 | 335 |
end; |
336 |
||
4901 | 337 |
end. |