~ppsspp/ppsspp/ppsspp_1.3.0

« back to all changes in this revision

Viewing changes to GPU/Common/PostShader.cpp

  • Committer: Sérgio Benjamim
  • Date: 2017-01-02 00:12:05 UTC
  • Revision ID: sergio_br2@yahoo.com.br-20170102001205-cxbta9za203nmjwm
1.3.0 source (from ppsspp_1.3.0-r160.p5.l1762.a165.t83~56~ubuntu16.04.1.tar.xz).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright (c) 2013- PPSSPP Project.
 
2
 
 
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.
 
6
 
 
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.
 
11
 
 
12
// A copy of the GPL 2.0 should have been included with the program.
 
13
// If not, see http://www.gnu.org/licenses/
 
14
 
 
15
// Official git repository and contact information can be found at
 
16
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
 
17
 
 
18
 
 
19
// Postprocessing shader manager
 
20
 
 
21
#include <string>
 
22
#include <vector>
 
23
#include <algorithm>
 
24
 
 
25
#include "file/ini_file.h"
 
26
#include "file/file_util.h"
 
27
#include "file/vfs.h"
 
28
#include "gfx_es2/gpu_features.h"
 
29
 
 
30
#include "Core/Config.h"
 
31
#include "GPU/Common/PostShader.h"
 
32
 
 
33
static std::vector<ShaderInfo> shaderInfo;
 
34
 
 
35
// Scans the directories for shader ini files and collects info about all the shaders found.
 
36
// Additionally, scan the VFS assets. (TODO)
 
37
 
 
38
void LoadPostShaderInfo(std::vector<std::string> directories) {
 
39
        shaderInfo.clear();
 
40
        ShaderInfo off;
 
41
        off.name = "Off";
 
42
        off.section = "Off";
 
43
        off.outputResolution = false;
 
44
        off.isUpscalingFilter = false;
 
45
        shaderInfo.push_back(off);
 
46
 
 
47
        for (size_t d = 0; d < directories.size(); d++) {
 
48
                std::vector<FileInfo> fileInfo;
 
49
                getFilesInDir(directories[d].c_str(), &fileInfo, "ini:");
 
50
 
 
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:");
 
54
                }
 
55
 
 
56
                for (size_t f = 0; f < fileInfo.size(); f++) {
 
57
                        IniFile ini;
 
58
                        bool success = false;
 
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);
 
66
 
 
67
                        if (ini.LoadFromVFS(name) || ini.Load(fileInfo[f].fullName)) {
 
68
                                success = true;
 
69
                                // vsh load. meh.
 
70
                        }
 
71
                        if (!success)
 
72
                                continue;
 
73
 
 
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 &section = ini.Sections()[i];
 
77
                                if (section.Exists("Fragment") && section.Exists("Vertex")) {
 
78
                                        // Valid shader!
 
79
                                        ShaderInfo info;
 
80
                                        std::string temp;
 
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);
 
89
 
 
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)
 
95
                                                        continue;
 
96
                                        }
 
97
 
 
98
                                        auto beginErase = std::find(shaderInfo.begin(), shaderInfo.end(), info.name);
 
99
                                        if (beginErase != shaderInfo.end()) {
 
100
                                                shaderInfo.erase(beginErase, shaderInfo.end());
 
101
                                        }
 
102
                                        shaderInfo.push_back(info);
 
103
                                }
 
104
                        }
 
105
                }
 
106
        }
 
107
}
 
108
 
 
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);
 
115
}
 
116
 
 
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];
 
122
        }
 
123
        return 0;
 
124
}
 
125
 
 
126
const std::vector<ShaderInfo> &GetAllPostShaderInfo() {
 
127
        LoadAllPostShaderInfo();
 
128
        return shaderInfo;
 
129
}