Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5318 in orxonox.OLD


Ignore:
Timestamp:
Oct 8, 2005, 1:08:09 PM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: new ReadFileArray function for shader

Location:
trunk/src
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/graphics/graphics_engine.cc

    r5286 r5318  
    2424#include "debug.h"
    2525#include "text_engine.h"
    26 
     26#include "shader.h"
    2727#include "ini_parser.h"
    2828#include "substring.h"
     29
    2930
    3031using namespace std;
     
    544545{
    545546  GraphicsEngine::storeMatrices();
     547  Shader::suspendShader();
    546548  Render2D::getInstance()->draw(E2D_ALL_LAYERS);
     549  Shader::restoreShader();
    547550  LightManager::getInstance()->draw();
    548551}
  • trunk/src/lib/graphics/render2D/render_2d.cc

    r5317 r5318  
    2323#include "element_2d.h"
    2424
    25 #include "shader.h"
    26 
    2725#include <math.h>
    2826
    2927using namespace std;
    30 
    31 
    3228
    3329/**
     
    126122void Render2D::draw(unsigned int layer) const
    127123{
    128   Shader::suspendShader();
    129 
    130124  GraphicsEngine::enter2DMode();
    131125
     
    149143  }
    150144  GraphicsEngine::leave2DMode();
    151 
    152   Shader::restoreShader();
    153145}
  • trunk/src/lib/graphics/shader.cc

    r5317 r5318  
    2222#include <stdio.h>
    2323#include "debug.h"
     24#include "array.h"
    2425
    2526
     
    6667/**
    6768 * standard deconstructor
    68 */
     69 */
    6970Shader::~Shader ()
    7071{
     72  if (storedShader == this)
     73    Shader::deactivateShader();
     74
    7175  // delete what has to be deleted here
    7276  this->deleteProgram(SHADER_VERTEX);
     
    7983  if (this->shaderProgram != 0)
    8084    glDeleteObjectARB(this->shaderProgram);
     85
    8186}
    8287
     
    9398
    9499
    95   const char* program = fileRead(fileName);
     100  Array<char*>* program = fileReadArray(fileName);
    96101  if (program == NULL)
    97102    return false;
     103
    98104  if (type == SHADER_VERTEX && GLEW_ARB_vertex_shader)
    99105  {
     
    114120  if (shader != 0)
    115121    {
    116       glShaderSourceARB(shader, 1, (const GLcharARB**)&program, NULL);
    117       try {
     122      glShaderSourceARB(shader, program->getCount(), (const GLcharARB**)program->getArray(), NULL);
    118123        glCompileShaderARB(shader);
    119       }
    120       catch (...)
    121         {
    122124          this->printError(shader);
    123         }
    124125      glAttachObjectARB(this->shaderProgram, shader);
    125       delete[] program;
    126126    }
     127    delete program;
    127128}
    128129
     
    153154}
    154155
     156
     157Array<char*>* Shader::fileReadArray(const char* fileName)
     158{
     159  FILE*    stream;           //< The stream we use to read the file.
     160
     161  if( (stream = fopen (fileName, "rt")) == NULL)
     162  {
     163    PRINTF(1)("Shader could not open %s\n", fileName);
     164    return NULL;
     165  }
     166  Array<char*>* file = new Array<char*>;
     167
     168  char lineBuffer[PARSELINELENGHT];
     169  char* addString;
     170  while(fgets (lineBuffer, PARSELINELENGHT, stream) != NULL)
     171  {
     172    addString = new char[strlen(lineBuffer)+1];
     173    strcpy(addString, lineBuffer);
     174    file->addEntry(addString);
     175  }
     176  fclose(stream);
     177  file->finalizeArray();
     178  return file;
     179}
     180
     181
     182
    155183void Shader::activateShader()
    156184{
  • trunk/src/lib/graphics/shader.h

    r5317 r5318  
    1010#include "glincl.h"
    1111
     12template<class T> class Array;
    1213
    1314typedef enum
     
    3536
    3637  char* fileRead(const char* fileName);
     38  Array<char*>* fileReadArray(const char* fileName);
    3739
    3840  static bool checkShaderAbility();
    3941
    4042  inline static bool shaderActive() { return (Shader::storedShader != NULL)?true:false; };
    41   inline static void suspendShader() { Shader* currShader=storedShader; if (currShader!= NULL) { Shader::deactivateShader(); Shader::storedShader = currShader;} };
     43  inline static void suspendShader() { Shader* currShader = storedShader; if (storedShader!= NULL) { Shader::deactivateShader(); Shader::storedShader = currShader;} };
    4244  inline static void restoreShader() { if (storedShader != NULL) storedShader->activateShader(); storedShader = NULL; };
    4345
  • trunk/src/story_entities/world.cc

    r5298 r5318  
    7474#include "npc.h"
    7575#include "npc2.h"
     76#include "shader.h"
    7677
    7778SHELL_COMMAND(speed, World, setSpeed);
     
    143144  // erease everything that is left.
    144145  delete NullParent::getInstance();
     146  Shader::suspendShader();
    145147
    146148  // unload the resources !!
Note: See TracChangeset for help on using the changeset viewer.