~ubuntu-branches/debian/sid/coin2/sid

« back to all changes in this revision

Viewing changes to src/shaders/SoGLShaderProgramElement.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Steve M. Robbins
  • Date: 2008-06-28 02:38:17 UTC
  • mfrom: (1.2.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20080628023817-lgrh0u677j1gcqgf
Tags: 2.5.0-2
* debian/control: Change suggests from libopenal0 to libopenal0a.
  Closes: #488001.  Change ${Source-Version} to ${binary:Version}.
  Update to standards version 3.8.0.

* debian/rules: Do not ignore errors in clean rule.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**************************************************************************\
 
2
 *
 
3
 *  This file is part of the Coin 3D visualization library.
 
4
 *  Copyright (C) 1998-2007 by Systems in Motion.  All rights reserved.
 
5
 *
 
6
 *  This library is free software; you can redistribute it and/or
 
7
 *  modify it under the terms of the GNU General Public License
 
8
 *  ("GPL") version 2 as published by the Free Software Foundation.
 
9
 *  See the file LICENSE.GPL at the root directory of this source
 
10
 *  distribution for additional information about the GNU GPL.
 
11
 *
 
12
 *  For using Coin with software that can not be combined with the GNU
 
13
 *  GPL, and for taking advantage of the additional benefits of our
 
14
 *  support services, please contact Systems in Motion about acquiring
 
15
 *  a Coin Professional Edition License.
 
16
 *
 
17
 *  See http://www.coin3d.org/ for more information.
 
18
 *
 
19
 *  Systems in Motion, Postboks 1283, Pirsenteret, 7462 Trondheim, NORWAY.
 
20
 *  http://www.sim.no/  sales@sim.no  coin-support@coin3d.org
 
21
 *
 
22
\**************************************************************************/
 
23
 
 
24
#include <Inventor/elements/SoGLShaderProgramElement.h>
 
25
 
 
26
#include <assert.h>
 
27
 
 
28
#include <Inventor/elements/SoGLCacheContextElement.h>
 
29
#include "SoGLShaderProgram.h"
 
30
 
 
31
// *************************************************************************
 
32
 
 
33
SO_ELEMENT_SOURCE(SoGLShaderProgramElement);
 
34
 
 
35
// *************************************************************************
 
36
 
 
37
void
 
38
SoGLShaderProgramElement::initClass(void)
 
39
{
 
40
  SO_ELEMENT_INIT_CLASS(SoGLShaderProgramElement, inherited);
 
41
}
 
42
 
 
43
SoGLShaderProgramElement::~SoGLShaderProgramElement()
 
44
{
 
45
  this->shaderProgram = NULL;
 
46
}
 
47
 
 
48
void
 
49
SoGLShaderProgramElement::init(SoState *state)
 
50
{
 
51
  inherited::init(state);
 
52
  this->shaderProgram = NULL;
 
53
}
 
54
 
 
55
void
 
56
SoGLShaderProgramElement::set(SoState* const state, SoNode *const node,
 
57
                              SoGLShaderProgram* program)
 
58
{
 
59
  SoGLShaderProgramElement* element =
 
60
    (SoGLShaderProgramElement*)inherited::getElement(state,classStackIndex, node);
 
61
  if (program != element->shaderProgram) {
 
62
    if (element->shaderProgram) element->shaderProgram->disable(state);
 
63
    element->shaderProgram = program;
 
64
    // don't enable new program here. The node will call enable()
 
65
    // after setting up all the objects
 
66
  }
 
67
}
 
68
 
 
69
SoGLShaderProgram *
 
70
SoGLShaderProgramElement::get(SoState *state)
 
71
{
 
72
  const SoElement *element = getConstElement(state, classStackIndex);
 
73
  assert(element);
 
74
  return ((const SoGLShaderProgramElement *)element)->shaderProgram;
 
75
}
 
76
 
 
77
void
 
78
SoGLShaderProgramElement::push(SoState * state)
 
79
{
 
80
  SoGLShaderProgramElement * prev = (SoGLShaderProgramElement *) getNextInStack();
 
81
  assert(prev);
 
82
  this->shaderProgram = prev->shaderProgram;
 
83
  // capture previous element since we might or might not change the
 
84
  // GL state in set/pop
 
85
  prev->capture(state);
 
86
}
 
87
 
 
88
void
 
89
SoGLShaderProgramElement::pop(SoState * state, const SoElement * prevTopElement)
 
90
{
 
91
  SoGLShaderProgramElement * elem = (SoGLShaderProgramElement *)prevTopElement;
 
92
  if (this->shaderProgram != elem->shaderProgram) {
 
93
    if (elem->shaderProgram) elem->shaderProgram->disable(state);
 
94
    if (this->shaderProgram) this->shaderProgram->enable(state);
 
95
  }
 
96
}
 
97
 
 
98
SbBool 
 
99
SoGLShaderProgramElement::matches(const SoElement * element) const
 
100
{
 
101
  SoGLShaderProgramElement * elem = (SoGLShaderProgramElement*) element;
 
102
 
 
103
  if (elem->shaderProgram) {
 
104
    // just use elem->objectid to avoid allocating a new SbList
 
105
    elem->objectids.truncate(0);
 
106
    elem->shaderProgram->getShaderObjectIds(elem->objectids);
 
107
    return this->objectids == elem->objectids;    
 
108
  } 
 
109
  // no shader program, return TRUE if cache had no shader objects
 
110
  return this->objectids.getLength() == 0;
 
111
}
 
112
 
 
113
SoElement * 
 
114
SoGLShaderProgramElement::copyMatchInfo(void) const
 
115
{
 
116
  assert(getTypeId().canCreateInstance());
 
117
  SoGLShaderProgramElement * element =
 
118
    (SoGLShaderProgramElement *)(getTypeId().createInstance());
 
119
  
 
120
  if (this->shaderProgram) this->shaderProgram->getShaderObjectIds(element->objectids);
 
121
  return element;
 
122
}