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 
27 #include "backends/graphics/opengl/framebuffer.h"
28 #include "graphics/opengl/texture.h"
29 
30 #include "math/matrix4.h"
31 
32 namespace OpenGL {
33 
34 class Framebuffer;
35 
42 class Pipeline {
43 public:
44  Pipeline();
45  virtual ~Pipeline() { if (isActive()) deactivate(); }
46 
53  void activate();
54 
58  void deactivate();
59 
68  Framebuffer *setFramebuffer(Framebuffer *framebuffer);
69 
78  virtual void setColor(GLfloat r, GLfloat g, GLfloat b, GLfloat a) = 0;
79 
86  inline void drawTexture(const Texture &texture, const GLfloat *coordinates, const GLfloat *texcoords) {
87  drawTextureInternal(texture, coordinates, texcoords);
88  }
89 
90  inline void drawTexture(const Texture &texture, const GLfloat *coordinates) {
91  drawTextureInternal(texture, coordinates, texture.getTexCoords());
92  }
93 
94  inline void drawTexture(const Texture &texture, GLfloat x, GLfloat y, GLfloat w, GLfloat h) {
95  const GLfloat coordinates[4*2] = {
96  x, y,
97  x + w, y,
98  x, y + h,
99  x + w, y + h
100  };
101  drawTextureInternal(texture, coordinates, texture.getTexCoords());
102  }
103 
104  inline void drawTexture(const Texture &texture, GLfloat x, GLfloat y, GLfloat w, GLfloat h, const Common::Rect &clip) {
105  const GLfloat coordinates[4*2] = {
106  x, y,
107  x + w, y,
108  x, y + h,
109  x + w, y + h
110  };
111 
112  const uint tw = texture.getWidth(),
113  th = texture.getHeight();
114 
115  if (tw == 0 || th == 0) {
116  // Nothing to display
117  return;
118  }
119 
120  const GLfloat texcoords[4*2] = {
121  (float)clip.left / tw, (float)clip.top / th,
122  (float)clip.right / tw, (float)clip.top / th,
123  (float)clip.left / tw, (float)clip.bottom / th,
124  (float)clip.right / tw, (float)clip.bottom / th
125  };
126 
127  drawTextureInternal(texture, coordinates, texcoords);
128  }
129 
135  virtual void setProjectionMatrix(const Math::Matrix4 &projectionMatrix) = 0;
136 
137 protected:
144  virtual void activateInternal();
145 
149  virtual void deactivateInternal();
150 
151  virtual void drawTextureInternal(const Texture &texture, const GLfloat *coordinates, const GLfloat *texcoords) = 0;
152 
153  bool isActive() const { return activePipeline == this; }
154 
155  Framebuffer *_activeFramebuffer;
156 
157 private:
159  static Pipeline *activePipeline;
160 };
161 
162 } // End of namespace OpenGL
163 
164 #endif
Framebuffer * setFramebuffer(Framebuffer *framebuffer)
virtual void setProjectionMatrix(const Math::Matrix4 &projectionMatrix)=0
uint getHeight() const
Definition: texture.h:123
int16 right
Definition: rect.h:146
Definition: framebuffer.h:38
Definition: rect.h:144
uint getWidth() const
Definition: texture.h:118
Definition: renderbuffer.h:27
int16 left
Definition: rect.h:145
Definition: texture.h:47
virtual void activateInternal()
void drawTexture(const Texture &texture, const GLfloat *coordinates, const GLfloat *texcoords)
Definition: pipeline.h:86
const GLfloat * getTexCoords() const
Definition: texture.h:138
virtual void deactivateInternal()
virtual void setColor(GLfloat r, GLfloat g, GLfloat b, GLfloat a)=0
Definition: pipeline.h:42