ScummVM API documentation
pipeline.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #ifndef BACKENDS_GRAPHICS_OPENGL_PIPELINES_PIPELINE_H
23 #define BACKENDS_GRAPHICS_OPENGL_PIPELINES_PIPELINE_H
24 
25 #include "graphics/opengl/system_headers.h"
26 #include "graphics/opengl/texture.h"
27 
28 #include "math/matrix4.h"
29 
30 namespace OpenGL {
31 
32 class Framebuffer;
33 
40 class Pipeline {
41 public:
45  static void disable() { if (activePipeline) activePipeline->deactivate(); }
46 
47  Pipeline();
48  virtual ~Pipeline() { if (isActive()) deactivate(); }
49 
56  void activate();
57 
61  void deactivate();
62 
71  Framebuffer *setFramebuffer(Framebuffer *framebuffer);
72 
81  virtual void setColor(GLfloat r, GLfloat g, GLfloat b, GLfloat a) = 0;
82 
89  inline void drawTexture(const Texture &texture, const GLfloat *coordinates, const GLfloat *texcoords) {
90  drawTextureInternal(texture, coordinates, texcoords);
91  }
92 
93  inline void drawTexture(const Texture &texture, const GLfloat *coordinates) {
94  drawTextureInternal(texture, coordinates, texture.getTexCoords());
95  }
96 
97  inline void drawTexture(const Texture &texture, GLfloat x, GLfloat y, GLfloat w, GLfloat h) {
98  const GLfloat coordinates[4*2] = {
99  x, y,
100  x + w, y,
101  x, y + h,
102  x + w, y + h
103  };
104  drawTextureInternal(texture, coordinates, texture.getTexCoords());
105  }
106 
107  inline void drawTexture(const Texture &texture, GLfloat x, GLfloat y, GLfloat w, GLfloat h, const Common::Rect &clip) {
108  const GLfloat coordinates[4*2] = {
109  x, y,
110  x + w, y,
111  x, y + h,
112  x + w, y + h
113  };
114 
115  const uint tw = texture.getWidth(),
116  th = texture.getHeight();
117 
118  if (tw == 0 || th == 0) {
119  // Nothing to display
120  return;
121  }
122 
123  const GLfloat texcoords[4*2] = {
124  (float)clip.left / tw, (float)clip.top / th,
125  (float)clip.right / tw, (float)clip.top / th,
126  (float)clip.left / tw, (float)clip.bottom / th,
127  (float)clip.right / tw, (float)clip.bottom / th
128  };
129 
130  drawTextureInternal(texture, coordinates, texcoords);
131  }
132 
138  virtual void setProjectionMatrix(const Math::Matrix4 &projectionMatrix) = 0;
139 
140 protected:
147  virtual void activateInternal();
148 
152  virtual void deactivateInternal();
153 
154  virtual void drawTextureInternal(const Texture &texture, const GLfloat *coordinates, const GLfloat *texcoords) = 0;
155 
156  bool isActive() const { return activePipeline == this; }
157 
158  Framebuffer *_activeFramebuffer;
159 
160 private:
162  static Pipeline *activePipeline;
163 };
164 
165 } // End of namespace OpenGL
166 
167 #endif
Framebuffer * setFramebuffer(Framebuffer *framebuffer)
T left
Definition: rect.h:170
virtual void setProjectionMatrix(const Math::Matrix4 &projectionMatrix)=0
uint getHeight() const
Definition: texture.h:140
Definition: framebuffer.h:38
Definition: rect.h:524
uint getWidth() const
Definition: texture.h:135
T right
Definition: rect.h:171
static void disable()
Definition: pipeline.h:45
Definition: renderbuffer.h:27
Definition: texture.h:48
virtual void activateInternal()
void drawTexture(const Texture &texture, const GLfloat *coordinates, const GLfloat *texcoords)
Definition: pipeline.h:89
const GLfloat * getTexCoords() const
Definition: texture.h:155
virtual void deactivateInternal()
virtual void setColor(GLfloat r, GLfloat g, GLfloat b, GLfloat a)=0
Definition: pipeline.h:40