Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/blink/src/lib/graphics/shader.cc @ 10605

Last change on this file since 10605 was 10143, checked in by bensch, 18 years ago

Shader fixing

File size: 2.4 KB
Line 
1/*
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.
10
11   ### File Specific:
12   main-programmer: Benjamin Grauer
13   co-programmer: ...
14*/
15
16//#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_
17
18#include "shader.h"
19
20#include "compiler.h"
21//#include <stdio.h>
22#include <fstream>
23
24#include "debug.h"
25
26
27
28#ifndef PARSELINELENGTH
29#define PARSELINELENGTH     512       //!< how many chars to read at once
30#endif
31
32
33ObjectListDefinition(Shader);
34
35void Shader::Uniform::setV(unsigned int count, float* vv) const
36{
37        if (Shader::isSupported())
38  switch (count)
39  {
40    case 1:
41    glUniform1fv(this->uniform, 1, vv);
42    break;
43    case 2:
44    glUniform2fv(this->uniform, 2, vv);
45    break;
46    case 3:
47    glUniform3fv(this->uniform, 3, vv);
48    break;
49    case 4:
50    glUniform4fv(this->uniform, 4, vv);
51    break;
52  }
53}
54
55void Shader::Uniform::setV(unsigned int count, int* vv) const
56{
57        if (Shader::isSupported())
58  switch (count)
59  {
60    case 1:
61    glUniform1iv(this->uniform, 1, vv);
62    break;
63    case 2:
64    glUniform2iv(this->uniform, 2, vv);
65    break;
66    case 3:
67    glUniform3iv(this->uniform, 3, vv);
68    break;
69    case 4:
70    glUniform4iv(this->uniform, 4, vv);
71    break;
72  }
73}
74
75
76Shader::Shader(const Shader& shader)
77  : data(shader.data)
78{
79
80}
81
82
83
84Shader::Shader()
85  : data(new ShaderData)
86{
87
88}
89
90/**
91 * standard constructor
92*/
93Shader::Shader (const std::string& vertexShaderFile, const std::string& fragmentShaderFile)
94  : data(new ShaderData)
95{
96  if (!Shader::checkShaderAbility())
97    PRINTF(2)("Your system does not support shaders\n");
98  this->load(vertexShaderFile, fragmentShaderFile);
99}
100
101const Shader* Shader::storedShader = NULL;
102
103void Shader::activateShader() const
104{
105  if (likely (this->getProgram() != 0))
106  {
107    glUseProgramObjectARB(this->getProgram());
108    Shader::storedShader = this;
109  }
110}
111void Shader::deactivateShader()
112{
113  if (storedShader != NULL)
114    glUseProgramObjectARB(0);
115  Shader::storedShader = NULL;
116}
117
118bool Shader::checkShaderAbility()
119{
120  if (GLEW_ARB_shader_objects &&
121      GLEW_ARB_shading_language_100 &&
122      GLEW_ARB_vertex_shader &&
123      GLEW_ARB_fragment_shader)
124    return true;
125  else
126    return false;
127}
128
129
Note: See TracBrowser for help on using the repository browser.