Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/lib/graphics/shader.cc @ 10118

Last change on this file since 10118 was 10118, checked in by patrick, 17 years ago

added the copy construtor and tried fixing the shader resource bug. no success

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
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]33ObjectListDefinition(Shader);
[1856]34
[9869]35void Shader::Uniform::setV(unsigned int count, float* vv) const
[3365]36{
[10118]37        if (Shader::isSupported())
[9869]38  switch (count)
[5322]39  {
[9869]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;
[5322]52  }
[3543]53}
[9869]54void Shader::Uniform::setV(unsigned int count, int* vv) const
[5323]55{
[10118]56        if (Shader::isSupported())
[9869]57  switch (count)
[5262]58  {
[9869]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;
[5263]71  }
[9869]72}
[5262]73
[5266]74
[10118]75Shader::Shader(const Shader& shader)
76  : data(shader.data)
77{
[5273]78
[10118]79}
80
81
82
[9869]83Shader::Shader()
[10034]84  : data(NULL)
[5261]85{
[5266]86
[8037]87}
[5266]88
[9869]89/**
90 * standard constructor
91*/
92Shader::Shader (const std::string& vertexShaderFile, const std::string& fragmentShaderFile)
93  : data(new ShaderData)
[8037]94{
[9869]95  if (!Shader::checkShaderAbility())
96    PRINTF(2)("Your system does not support shaders\n");
97  this->load(vertexShaderFile, fragmentShaderFile);
[5266]98
[5318]99}
100
[9869]101const Shader* Shader::storedShader = NULL;
[5318]102
[9869]103void Shader::activateShader() const
[5266]104{
[9869]105  if (likely (this->getProgram() != 0))
[5317]106  {
[9869]107    glUseProgramObjectARB(this->getProgram());
[5317]108    Shader::storedShader = this;
109  }
[5261]110}
[5266]111void Shader::deactivateShader()
112{
[9869]113  if (storedShader != NULL)
114    glUseProgramObjectARB(0);
115  Shader::storedShader = NULL;
[5266]116}
[5262]117
[5333]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}
[5264]128
[5262]129
Note: See TracBrowser for help on using the repository browser.