Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

Shaders now fully support the ResourceShader Paradigm

File size: 2.3 KB
RevLine 
[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
[7193]26#include "util/loading/resource_manager.h"
[5262]27
[5323]28
[8037]29#ifndef PARSELINELENGTH
30#define PARSELINELENGTH     512       //!< how many chars to read at once
[5262]31#endif
32
[1853]33
[9715]34ObjectListDefinition(Shader);
[1856]35
[9806]36void Shader::Uniform::setV(unsigned int count, float* vv) const
37{
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}
54void Shader::Uniform::setV(unsigned int count, int* vv) const
55{
56  switch (count)
57  {
58    case 1:
59    glUniform1iv(this->uniform, 1, vv);
60    break;
61    case 2:
62    glUniform2iv(this->uniform, 2, vv);
63    break;
64    case 3:
65    glUniform3iv(this->uniform, 3, vv);
66    break;
67    case 4:
68    glUniform4iv(this->uniform, 4, vv);
69    break;
70  }
71}
72
73
74
[9818]75Shader::Shader()
76  : data(new ShaderData)
77{
78 
79}
[9806]80
[3245]81/**
[4838]82 * standard constructor
[3245]83*/
[7221]84Shader::Shader (const std::string& vertexShaderFile, const std::string& fragmentShaderFile)
[9818]85  : data(new ShaderData)
[3365]86{
[9818]87  if (!Shader::checkShaderAbility())
88    PRINTF(2)("Your system does not support shaders\n");
[9819]89  this->load(vertexShaderFile, fragmentShaderFile);
[1853]90
[3543]91}
[5261]92
[9818]93const Shader* Shader::storedShader = NULL;
[5261]94
[9818]95void Shader::activateShader() const
[5261]96{
[9818]97  if (likely (this->getProgram() != 0))
[5262]98  {
[9818]99    glUseProgramObjectARB(this->getProgram());
[5317]100    Shader::storedShader = this;
101  }
[5261]102}
[5266]103void Shader::deactivateShader()
104{
[9806]105  if (storedShader != NULL)
106    glUseProgramObjectARB(0);
107  Shader::storedShader = NULL;
[5266]108}
[5262]109
[5333]110bool Shader::checkShaderAbility()
111{
112  if (GLEW_ARB_shader_objects &&
113      GLEW_ARB_shading_language_100 &&
114      GLEW_ARB_vertex_shader &&
115      GLEW_ARB_fragment_shader)
116    return true;
117  else
118    return false;
119}
[5264]120
[5262]121
Note: See TracBrowser for help on using the repository browser.