2013-05-18 09:17:30 +00:00
|
|
|
#!/usr/bin/perl
|
|
|
|
|
2014-04-12 10:44:38 +00:00
|
|
|
# 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/>.
|
|
|
|
|
2013-05-18 09:17:30 +00:00
|
|
|
use strict;
|
|
|
|
use warnings;
|
2013-06-07 19:16:27 +00:00
|
|
|
use File::Spec;
|
2013-06-26 20:09:07 +00:00
|
|
|
use File::Basename;
|
2013-07-06 09:42:46 +00:00
|
|
|
use File::Copy;
|
2013-06-26 20:09:07 +00:00
|
|
|
use Cwd 'abs_path';
|
2013-05-18 09:17:30 +00:00
|
|
|
|
2013-07-07 16:13:11 +00:00
|
|
|
# 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";
|
|
|
|
};
|
|
|
|
|
2015-04-17 18:18:07 +00:00
|
|
|
########################
|
|
|
|
# GSdx
|
|
|
|
########################
|
2013-07-07 16:13:11 +00:00
|
|
|
my $gsdx_path = File::Spec->catdir(dirname(abs_path($0)), "..", "plugins", "GSdx", "res");
|
2015-04-17 21:17:30 +00:00
|
|
|
my $gsdx_out = File::Spec->catdir($gsdx_path, "glsl_source.h");
|
|
|
|
|
2015-04-17 18:18:07 +00:00
|
|
|
# Just a hack to reuse glsl2h function easily
|
2015-04-17 21:17:30 +00:00
|
|
|
$gsdx_path = File::Spec->catdir(dirname(abs_path($0)), "..", "plugins", "GSdx", "res", "glsl");
|
2015-04-17 18:18:07 +00:00
|
|
|
my @tfx_res = qw/tfx_fs.glsl tfx_fs_subroutine.glsl/;
|
|
|
|
my $tfx_all = File::Spec->catdir($gsdx_path, "tfx_fs_all.glsl");
|
2015-04-17 21:17:30 +00:00
|
|
|
|
|
|
|
my @gsdx_res = qw/convert.glsl interlace.glsl merge.glsl shadeboost.glsl tfx_vgs.glsl tfx_fs_all.glsl fxaa.fx/;
|
2015-04-17 18:18:07 +00:00
|
|
|
concat($gsdx_path, $tfx_all, \@tfx_res);
|
|
|
|
|
2014-01-18 14:46:13 +00:00
|
|
|
glsl2h($gsdx_path, $gsdx_out, \@gsdx_res);
|
2013-07-07 16:13:11 +00:00
|
|
|
|
2015-04-17 18:18:07 +00:00
|
|
|
unlink $tfx_all;
|
|
|
|
|
|
|
|
########################
|
|
|
|
# ZZOGL
|
|
|
|
########################
|
2013-07-07 16:13:11 +00:00
|
|
|
my @zz_res = qw/ps2hw_gl4.glsl/;
|
2013-07-06 09:42:46 +00:00
|
|
|
my $zz_path = File::Spec->catdir(dirname(abs_path($0)), "..", "plugins", "zzogl-pg", "opengl");
|
2013-07-07 16:13:11 +00:00
|
|
|
my $zz_out = File::Spec->catdir($zz_path, "ps2hw_gl4.h");
|
|
|
|
glsl2h($zz_path, $zz_out, \@zz_res);
|
2013-07-06 09:42:46 +00:00
|
|
|
|
2015-04-17 18:18:07 +00:00
|
|
|
sub concat {
|
|
|
|
my $in_dir = shift;
|
|
|
|
my $out_file = shift;
|
|
|
|
my $glsl_files = shift;
|
|
|
|
|
|
|
|
my $line;
|
|
|
|
open(my $TMP, ">$out_file");
|
|
|
|
foreach my $file (@{$glsl_files}) {
|
|
|
|
open(my $GLSL, File::Spec->catfile($in_dir, $file)) or die "$! : $file";
|
|
|
|
while(defined($line = <$GLSL>)) {
|
|
|
|
print $TMP $line;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-05-18 09:17:30 +00:00
|
|
|
sub glsl2h {
|
2013-07-07 16:13:11 +00:00
|
|
|
my $in_dir = shift;
|
|
|
|
my $out_file = shift;
|
|
|
|
my $glsl_files = shift;
|
2013-07-06 09:42:46 +00:00
|
|
|
|
|
|
|
my $include = "";
|
2013-07-07 16:13:11 +00:00
|
|
|
if ($in_dir =~ /GSdx/) {
|
2013-07-06 09:42:46 +00:00
|
|
|
$include = "#include \"stdafx.h\""
|
|
|
|
}
|
2013-05-18 09:17:30 +00:00
|
|
|
|
|
|
|
my $header = <<EOS;
|
|
|
|
/*
|
|
|
|
* This file was generated by glsl2h.pl script
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
|
2013-07-06 09:42:46 +00:00
|
|
|
$include
|
2013-05-18 09:17:30 +00:00
|
|
|
EOS
|
|
|
|
|
2013-07-07 16:13:11 +00:00
|
|
|
my $data = $header;
|
|
|
|
|
|
|
|
foreach my $file (@{$glsl_files}) {
|
|
|
|
my $name = $file;
|
|
|
|
$name =~ s/\./_/;
|
|
|
|
$data .= "\nstatic const char* $name =\n";
|
|
|
|
|
2015-04-17 18:18:07 +00:00
|
|
|
open(my $GLSL, File::Spec->catfile($in_dir, $file)) or die "$! : $file";
|
2013-07-07 16:13:11 +00:00
|
|
|
my $line;
|
|
|
|
while(defined($line = <$GLSL>)) {
|
|
|
|
chomp $line;
|
|
|
|
$line =~ s/\\/\\\\/g;
|
|
|
|
$line =~ s/"/\\"/g;
|
|
|
|
$data .= "\t\"$line\\n\"\n";
|
|
|
|
}
|
|
|
|
$data .= "\t;\n";
|
2013-07-06 09:42:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# Rewriting the file will trigger a relink (even if the content is the
|
|
|
|
# same). So we check first the content with md5 digest
|
2013-07-07 16:13:11 +00:00
|
|
|
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;
|
2013-07-06 09:42:46 +00:00
|
|
|
print $H $data;
|
2013-05-18 09:17:30 +00:00
|
|
|
}
|
|
|
|
}
|