Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/new_class_id/src/lib/graphics/shader.cc @ 9818

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

Switching to new Shader layout, with Shader and ShaderData. Shaders do not render for the time being

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