1
// Copyright (c) 2013- PPSSPP Project.
3
// This program is free software: you can redistribute it and/or modify
4
// it under the terms of the GNU General Public License as published by
5
// the Free Software Foundation, version 2.0 or later versions.
7
// This program is distributed in the hope that it will be useful,
8
// but WITHOUT ANY WARRANTY; without even the implied warranty of
9
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
// GNU General Public License 2.0 for more details.
12
// A copy of the GPL 2.0 should have been included with the program.
13
// If not, see http://www.gnu.org/licenses/
15
// Official git repository and contact information can be found at
16
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
19
// Postprocessing shader manager
25
#include "file/ini_file.h"
26
#include "file/file_util.h"
28
#include "gfx_es2/gpu_features.h"
30
#include "Core/Config.h"
31
#include "GPU/Common/PostShader.h"
33
static std::vector<ShaderInfo> shaderInfo;
35
// Scans the directories for shader ini files and collects info about all the shaders found.
36
// Additionally, scan the VFS assets. (TODO)
38
void LoadPostShaderInfo(std::vector<std::string> directories) {
43
off.outputResolution = false;
44
off.isUpscalingFilter = false;
45
shaderInfo.push_back(off);
47
for (size_t d = 0; d < directories.size(); d++) {
48
std::vector<FileInfo> fileInfo;
49
getFilesInDir(directories[d].c_str(), &fileInfo, "ini:");
51
if (fileInfo.size() == 0) {
52
// TODO: Really gotta fix the filter, now it's gonna open shaders as ini files..
53
VFSGetFileListing(directories[d].c_str(), &fileInfo, "ini:");
56
for (size_t f = 0; f < fileInfo.size(); f++) {
59
std::string name = fileInfo[f].fullName;
60
std::string path = directories[d];
61
// Hack around Android VFS path bug. really need to redesign this.
62
if (name.substr(0, 7) == "assets/")
63
name = name.substr(7);
64
if (path.substr(0, 7) == "assets/")
65
path = path.substr(7);
67
if (ini.LoadFromVFS(name) || ini.Load(fileInfo[f].fullName)) {
74
// Alright, let's loop through the sections and see if any is a shader.
75
for (size_t i = 0; i < ini.Sections().size(); i++) {
76
IniFile::Section §ion = ini.Sections()[i];
77
if (section.Exists("Fragment") && section.Exists("Vertex")) {
81
info.section = section.name();
82
section.Get("Name", &info.name, section.name().c_str());
83
section.Get("Fragment", &temp, "");
84
info.fragmentShaderFile = path + "/" + temp;
85
section.Get("Vertex", &temp, "");
86
info.vertexShaderFile = path + "/" + temp;
87
section.Get("OutputResolution", &info.outputResolution, false);
88
section.Get("Upscaling", &info.isUpscalingFilter, false);
90
// Let's ignore shaders we can't support. TODO: Not a very good check
91
if (gl_extensions.IsGLES && !gl_extensions.GLES3) {
92
bool requiresIntegerSupport;
93
section.Get("RequiresIntSupport", &requiresIntegerSupport, false);
94
if (requiresIntegerSupport)
98
auto beginErase = std::find(shaderInfo.begin(), shaderInfo.end(), info.name);
99
if (beginErase != shaderInfo.end()) {
100
shaderInfo.erase(beginErase, shaderInfo.end());
102
shaderInfo.push_back(info);
109
// Scans the directories for shader ini files and collects info about all the shaders found.
110
void LoadAllPostShaderInfo() {
111
std::vector<std::string> directories;
112
directories.push_back("shaders");
113
directories.push_back(g_Config.memStickDirectory + "PSP/shaders");
114
LoadPostShaderInfo(directories);
117
const ShaderInfo *GetPostShaderInfo(std::string name) {
118
LoadAllPostShaderInfo();
119
for (size_t i = 0; i < shaderInfo.size(); i++) {
120
if (shaderInfo[i].section == name)
121
return &shaderInfo[i];
126
const std::vector<ShaderInfo> &GetAllPostShaderInfo() {
127
LoadAllPostShaderInfo();