File: glsl2h.pl

package info (click to toggle)
pcsx2 1.6.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, sid
  • size: 28,424 kB
  • sloc: cpp: 299,797; ansic: 23,973; lisp: 2,689; asm: 908; perl: 852; sh: 789; xml: 116; makefile: 60
file content (116 lines) | stat: -rwxr-xr-x 3,603 bytes parent folder | download | duplicates (2)
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
#!/usr/bin/perl

# PCSX2 - PS2 Emulator for PCs
# Copyright (C) 2002-2014  PCSX2 Dev Team
#
# PCSX2 is free software: you can redistribute it and/or modify it under the terms
# of the GNU Lesser General Public License as published by the Free Software Found-
# ation, either version 3 of the License, or (at your option) any later version.
#
# PCSX2 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 for more details.
#
# You should have received a copy of the GNU General Public License along with PCSX2.
# If not, see <http://www.gnu.org/licenses/>.

use strict;
use warnings;
use File::Spec;
use File::Basename;
use File::Copy;
use Cwd 'abs_path';

# Allow to use the script without the module. I don't want a full PERL as a dependency of PCSX2!
my $g_disable_md5 = 0;
eval {
    require Digest::file;
    require Digest::MD5;
    Digest::file->import(qw/digest_file_hex/);
    Digest::MD5->import(qw/md5_hex/);
    1;
} or do {
    $g_disable_md5 = 1;
    print "Disable MD5\n";
};

########################
# ZZOGL
########################
my @zz_res  = qw/ps2hw_gl4.glsl/;
my $zz_path = File::Spec->catdir(dirname(abs_path($0)), "..", "plugins", "zzogl-pg", "opengl");
my $zz_out = File::Spec->catdir($zz_path, "ps2hw_gl4.h");
glsl2h($zz_path, $zz_out, \@zz_res);

sub glsl2h {
    my $in_dir = shift;
    my $out_file = shift;
    my $glsl_files = shift;

    my $include = "";
    if ($in_dir =~ /GSdx/) {
        $include = "#include \"stdafx.h\""
    }

    my $header = <<EOS;
/*
 *  This file was generated by ./linux_various/glsl2h.pl script. Don't edit it manually !
 *
 *  GLSL input directory: $in_dir
 *  GLSL input files: @$glsl_files
 *
 *  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; either version 2, or (at your option)
 *  any later version.
 *
 *  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 for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with GNU Make; see the file COPYING.  If not, write to
 *  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA USA.
 *  http://www.gnu.org/copyleft/gpl.html
 *
 */

#pragma once

$include
EOS

    my $data = $header;

    foreach my $file (@{$glsl_files}) {
        my $name = $file;
        $name =~ s/\./_/;
        $data .= "\nstatic const char* const $name =\n";

        open(my $GLSL, File::Spec->catfile($in_dir, $file)) or die "$! : $file";
        my $line;
        while(defined($line = <$GLSL>)) {
            chomp $line;
            $line =~ s/\\/\\\\/g;
            $line =~ s/"/\\"/g;
            $data .= "\t\"$line\\n\"\n";
        }
        $data .= "\t;\n";
    }

    # Rewriting the file will trigger a relink (even if the content is the
    # same). So we check first the content with md5 digest
    if ( -e $out_file and not $g_disable_md5) {
        my $old_md5 = digest_file_hex($out_file, "MD5");
        my $new_md5 = md5_hex($data);

        if ($old_md5 ne $new_md5) {
            open(my $H, ">$out_file") or die;
            print $H $data;
        }
    } else {
        open(my $H, ">$out_file") or die;
        print $H $data;
    }
}