Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/ODE/src/lib/graphics/shader.cc @ 10301

Last change on this file since 10301 was 9869, checked in by bensch, 18 years ago

orxonox/trunk: merged the new_class_id branche back to the trunk.
merged with command:
svn merge https://svn.orxonox.net/orxonox/branches/new_class_id trunk -r9683:HEAD
no conflicts… puh..

File size: 2.2 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  switch (count)
38  {
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;
51  }
52}
53void Shader::Uniform::setV(unsigned int count, int* vv) const
54{
55  switch (count)
56  {
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;
69  }
70}
71
72
73
74Shader::Shader()
75  : data(new ShaderData)
76{
77
78}
79
80/**
81 * standard constructor
82*/
83Shader::Shader (const std::string& vertexShaderFile, const std::string& fragmentShaderFile)
84  : data(new ShaderData)
85{
86  if (!Shader::checkShaderAbility())
87    PRINTF(2)("Your system does not support shaders\n");
88  this->load(vertexShaderFile, fragmentShaderFile);
89
90}
91
92const Shader* Shader::storedShader = NULL;
93
94void Shader::activateShader() const
95{
96  if (likely (this->getProgram() != 0))
97  {
98    glUseProgramObjectARB(this->getProgram());
99    Shader::storedShader = this;
100  }
101}
102void Shader::deactivateShader()
103{
104  if (storedShader != NULL)
105    glUseProgramObjectARB(0);
106  Shader::storedShader = NULL;
107}
108
109bool 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}
119
120
Note: See TracBrowser for help on using the repository browser.