[4744] | 1 | /* |
---|
[1853] | 2 | orxonox - the future of 3D-vertical-scrollers |
---|
| 3 | |
---|
| 4 | Copyright (C) 2004 orx |
---|
| 5 | |
---|
| 6 | This program is free software; you can redistribute it and/or modify |
---|
| 7 | it under the terms of the GNU General Public License as published by |
---|
| 8 | the Free Software Foundation; either version 2, or (at your option) |
---|
| 9 | any later version. |
---|
[1855] | 10 | |
---|
| 11 | ### File Specific: |
---|
[5261] | 12 | main-programmer: Benjamin Grauer |
---|
[1855] | 13 | co-programmer: ... |
---|
[1853] | 14 | */ |
---|
| 15 | |
---|
[3955] | 16 | //#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_ |
---|
[1853] | 17 | |
---|
[5261] | 18 | #include "shader.h" |
---|
[1853] | 19 | |
---|
[5273] | 20 | #include "compiler.h" |
---|
[8037] | 21 | //#include <stdio.h> |
---|
| 22 | #include <fstream> |
---|
| 23 | |
---|
[5262] | 24 | #include "debug.h" |
---|
| 25 | |
---|
| 26 | |
---|
[5323] | 27 | |
---|
[8037] | 28 | #ifndef PARSELINELENGTH |
---|
| 29 | #define PARSELINELENGTH 512 //!< how many chars to read at once |
---|
[5262] | 30 | #endif |
---|
| 31 | |
---|
[1853] | 32 | |
---|
[9869] | 33 | ObjectListDefinition(Shader); |
---|
[1856] | 34 | |
---|
[9869] | 35 | void Shader::Uniform::setV(unsigned int count, float* vv) const |
---|
[3365] | 36 | { |
---|
[9869] | 37 | switch (count) |
---|
[5322] | 38 | { |
---|
[9869] | 39 | case 1: |
---|
| 40 | glUniform1fv(this->uniform, 1, vv); |
---|
| 41 | break; |
---|
| 42 | case 2: |
---|
| 43 | glUniform2fv(this->uniform, 2, vv); |
---|
| 44 | break; |
---|
| 45 | case 3: |
---|
| 46 | glUniform3fv(this->uniform, 3, vv); |
---|
| 47 | break; |
---|
| 48 | case 4: |
---|
| 49 | glUniform4fv(this->uniform, 4, vv); |
---|
| 50 | break; |
---|
[5322] | 51 | } |
---|
[3543] | 52 | } |
---|
[9869] | 53 | void Shader::Uniform::setV(unsigned int count, int* vv) const |
---|
[5323] | 54 | { |
---|
[9869] | 55 | switch (count) |
---|
[5262] | 56 | { |
---|
[9869] | 57 | case 1: |
---|
| 58 | glUniform1iv(this->uniform, 1, vv); |
---|
| 59 | break; |
---|
| 60 | case 2: |
---|
| 61 | glUniform2iv(this->uniform, 2, vv); |
---|
| 62 | break; |
---|
| 63 | case 3: |
---|
| 64 | glUniform3iv(this->uniform, 3, vv); |
---|
| 65 | break; |
---|
| 66 | case 4: |
---|
| 67 | glUniform4iv(this->uniform, 4, vv); |
---|
| 68 | break; |
---|
[5263] | 69 | } |
---|
[9869] | 70 | } |
---|
[5262] | 71 | |
---|
[5266] | 72 | |
---|
[5273] | 73 | |
---|
[9869] | 74 | Shader::Shader() |
---|
| 75 | : data(new ShaderData) |
---|
[5261] | 76 | { |
---|
[5266] | 77 | |
---|
[8037] | 78 | } |
---|
[5266] | 79 | |
---|
[9869] | 80 | /** |
---|
| 81 | * standard constructor |
---|
| 82 | */ |
---|
| 83 | Shader::Shader (const std::string& vertexShaderFile, const std::string& fragmentShaderFile) |
---|
| 84 | : data(new ShaderData) |
---|
[8037] | 85 | { |
---|
[9869] | 86 | if (!Shader::checkShaderAbility()) |
---|
| 87 | PRINTF(2)("Your system does not support shaders\n"); |
---|
| 88 | this->load(vertexShaderFile, fragmentShaderFile); |
---|
[5266] | 89 | |
---|
[5318] | 90 | } |
---|
| 91 | |
---|
[9869] | 92 | const Shader* Shader::storedShader = NULL; |
---|
[5318] | 93 | |
---|
[9869] | 94 | void Shader::activateShader() const |
---|
[5266] | 95 | { |
---|
[9869] | 96 | if (likely (this->getProgram() != 0)) |
---|
[5317] | 97 | { |
---|
[9869] | 98 | glUseProgramObjectARB(this->getProgram()); |
---|
[5317] | 99 | Shader::storedShader = this; |
---|
| 100 | } |
---|
[5261] | 101 | } |
---|
[5266] | 102 | void Shader::deactivateShader() |
---|
| 103 | { |
---|
[9869] | 104 | if (storedShader != NULL) |
---|
| 105 | glUseProgramObjectARB(0); |
---|
| 106 | Shader::storedShader = NULL; |
---|
[5266] | 107 | } |
---|
[5262] | 108 | |
---|
[5333] | 109 | bool Shader::checkShaderAbility() |
---|
| 110 | { |
---|
| 111 | if (GLEW_ARB_shader_objects && |
---|
| 112 | GLEW_ARB_shading_language_100 && |
---|
| 113 | GLEW_ARB_vertex_shader && |
---|
| 114 | GLEW_ARB_fragment_shader) |
---|
| 115 | return true; |
---|
| 116 | else |
---|
| 117 | return false; |
---|
| 118 | } |
---|
[5264] | 119 | |
---|
[5262] | 120 | |
---|