|
40 | 40 | ** Macros and constants |
41 | 41 | */ |
42 | 42 |
|
| 43 | +#if BITTY_EFFECTS_ENABLED |
| 44 | +# pragma message("Effects enabled.") |
| 45 | +#endif /* BITTY_EFFECTS_ENABLED */ |
| 46 | + |
43 | 47 | #ifndef EFFECTS_DEFAULT_FILE |
44 | 48 | # define EFFECTS_DEFAULT_FILE "../effects/default.json" |
45 | 49 | #endif /* EFFECTS_DEFAULT_FILE */ |
@@ -267,31 +271,7 @@ class EffectsImpl : public Effects { |
267 | 271 | return true; |
268 | 272 | } |
269 | 273 | } |
270 | | - const GLchar* vertSrc = |
271 | | - "#version 150\n" |
272 | | - "uniform mat4 ProjMatrix;\n" |
273 | | - "in vec2 Position;\n" |
274 | | - "in vec2 UV;\n" |
275 | | - "in vec4 Color;\n" |
276 | | - "out vec2 Frag_UV;\n" |
277 | | - "out vec4 Frag_Color;\n" |
278 | | - "void main()\n" |
279 | | - "{\n" |
280 | | - " Frag_UV = UV;\n" |
281 | | - " Frag_Color = Color;\n" |
282 | | - " gl_Position = ProjMatrix * vec4(Position.xy, 0, 1);\n" |
283 | | - "}\n"; |
284 | | - const GLchar* fragSrc = |
285 | | - "#version 150\n" |
286 | | - "uniform sampler2D Texture;\n" |
287 | | - "in vec2 Frag_UV;\n" |
288 | | - "in vec4 Frag_Color;\n" |
289 | | - "out vec4 Out_Color;\n" |
290 | | - "void main()\n" |
291 | | - "{\n" |
292 | | - " Out_Color = Frag_Color * texture(Texture, Frag_UV.st);\n" |
293 | | - "}\n"; |
294 | | - _material.open(vertSrc, fragSrc, workspace); |
| 274 | + useDefault(workspace); |
295 | 275 |
|
296 | 276 | return true; |
297 | 277 | } |
@@ -321,9 +301,15 @@ class EffectsImpl : public Effects { |
321 | 301 | return true; |
322 | 302 | } |
323 | 303 |
|
324 | | - virtual bool use(class Workspace* workspace, const char* config) override { |
| 304 | + virtual bool use(class Workspace* workspace, const char* material) override { |
| 305 | + if (!material) { |
| 306 | + useDefault(workspace); |
| 307 | + |
| 308 | + return true; |
| 309 | + } |
| 310 | + |
325 | 311 | Json::Ptr json(Json::create()); |
326 | | - if (!json->fromString(config)) |
| 312 | + if (!json->fromString(material)) |
327 | 313 | return false; |
328 | 314 | rapidjson::Document doc; |
329 | 315 | if (!json->toJson(doc)) |
@@ -488,6 +474,35 @@ class EffectsImpl : public Effects { |
488 | 474 |
|
489 | 475 | SDL_GL_SwapWindow(window); |
490 | 476 | } |
| 477 | + |
| 478 | +private: |
| 479 | + void useDefault(Workspace* workspace) { |
| 480 | + const GLchar* vertSrc = |
| 481 | + "#version 150\n" |
| 482 | + "uniform mat4 ProjMatrix;\n" |
| 483 | + "in vec2 Position;\n" |
| 484 | + "in vec2 UV;\n" |
| 485 | + "in vec4 Color;\n" |
| 486 | + "out vec2 Frag_UV;\n" |
| 487 | + "out vec4 Frag_Color;\n" |
| 488 | + "void main()\n" |
| 489 | + "{\n" |
| 490 | + " Frag_UV = UV;\n" |
| 491 | + " Frag_Color = Color;\n" |
| 492 | + " gl_Position = ProjMatrix * vec4(Position.xy, 0, 1);\n" |
| 493 | + "}\n"; |
| 494 | + const GLchar* fragSrc = |
| 495 | + "#version 150\n" |
| 496 | + "uniform sampler2D Texture;\n" |
| 497 | + "in vec2 Frag_UV;\n" |
| 498 | + "in vec4 Frag_Color;\n" |
| 499 | + "out vec4 Out_Color;\n" |
| 500 | + "void main()\n" |
| 501 | + "{\n" |
| 502 | + " Out_Color = Frag_Color * texture(Texture, Frag_UV.st);\n" |
| 503 | + "}\n"; |
| 504 | + _material.open(vertSrc, fragSrc, workspace); |
| 505 | + } |
491 | 506 | }; |
492 | 507 | #else /* BITTY_EFFECTS_ENABLED && Platform macro. */ |
493 | 508 | class EffectsImpl : public Effects { |
|
0 commit comments