Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/shaderc
Path: blob/main/glslc/src/file.h
1560 views
1
// Copyright 2015 The Shaderc Authors. All rights reserved.
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
// http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14
15
#ifndef GLSLC_FILE_H_
16
#define GLSLC_FILE_H_
17
18
#include "libshaderc_util/string_piece.h"
19
20
namespace glslc {
21
22
// Given a file name, returns its extension. If no extension exists,
23
// returns an empty string_piece.
24
shaderc_util::string_piece GetFileExtension(
25
const shaderc_util::string_piece& filename);
26
27
// Returns true if the given file name ends with a known shader file extension.
28
inline bool IsStageFile(const shaderc_util::string_piece& filename) {
29
const shaderc_util::string_piece extension =
30
glslc::GetFileExtension(filename);
31
return extension == "vert" || extension == "frag" || extension == "tesc" ||
32
extension == "tese" || extension == "geom" || extension == "comp";
33
}
34
35
// Returns the file extension if is either "glsl" or "hlsl", or an empty
36
// string otherwise.
37
inline std::string GetGlslOrHlslExtension(
38
const shaderc_util::string_piece& filename) {
39
auto extension = glslc::GetFileExtension(filename);
40
if ((extension == "glsl") || (extension == "hlsl")) return extension.str();
41
return "";
42
}
43
44
} // namespace glslc
45
46
#endif // GLSLC_FILE_H_
47
48