nanoMMO 0.97.8
Building an MMO: The Engineering Series
Loading...
Searching...
No Matches
glsl.cc
Go to the documentation of this file.
1#include "client/glsl.h"
2
3#include <raylib.h>
4
5#include <optional>
6#include <string>
7#include <string_view>
8
9namespace nanommo {
10namespace {
11
12// The source as the GPU takes it: on a computer, as it is.
13std::optional<std::string> ForThisGpu(const char* source) {
14 if (source == nullptr) {
15 return std::nullopt;
16 }
17 std::string glsl(source);
18#if defined(__EMSCRIPTEN__)
19 constexpr std::string_view kDesktop = "#version 330";
20 if (glsl.starts_with(kDesktop)) {
21 glsl.replace(0, kDesktop.size(),
22 "#version 300 es\n"
23 "precision highp float;\n"
24 "precision highp int;");
25 }
26#endif
27 return glsl;
28}
29
30} // namespace
31
32Shader LoadGlsl(const char* vertex, const char* fragment) {
33 const std::optional<std::string> vs = ForThisGpu(vertex);
34 const std::optional<std::string> fs = ForThisGpu(fragment);
35 return LoadShaderFromMemory(vs ? vs->c_str() : nullptr,
36 fs ? fs->c_str() : nullptr);
37}
38
39} // namespace nanommo
Definition chat.cc:9
Shader LoadGlsl(const char *vertex, const char *fragment)
Definition glsl.cc:32