ManaPlus
Namespaces | Macros | Functions | Variables
normalopenglgraphics.cpp File Reference

(986a3bf)

#include "render/normalopenglgraphics.h"
#include "render/vertexes/imagecollection.h"
#include "resources/imagerect.h"
#include "resources/openglimagehelper.h"
#include "resources/image/image.h"
#include "utils/sdlcheckutils.h"
#include "debug.h"
#include "render/graphics_drawImageRect.hpp"
#include "render/graphics_calcImageRect.hpp"

Go to the source code of this file.

Namespaces

 anonymous_namespace{normalopenglgraphics.cpp}
 

Macros

#define vertFill2D(tVar, vVar, x1, y1, x2, y2, dstX, dstY, w, h)
 
#define vertFillNv(tVar, vVar, srcX, srcY, dstX, dstY, w, h)
 

Functions

static void bindPointerIntFloat (const GLint *const vert, const GLfloat *const tex) A_INLINE
 
static void bindPointerInt (const GLint *const vert, const GLint *const tex) A_INLINE
 
static void drawQuad (const Image *const image, const int srcX, const int srcY, const int dstX, const int dstY, const int width, const int height) A_INLINE
 
static void drawRescaledQuad (const Image *const image, const int srcX, const int srcY, const int dstX, const int dstY, const int width, const int height, const int desiredWidth, const int desiredHeight) A_INLINE
 

Variables

const void * anonymous_namespace{normalopenglgraphics.cpp}::vertPtr = 0
 

Macro Definition Documentation

◆ vertFill2D

#define vertFill2D (   tVar,
  vVar,
  x1,
  y1,
  x2,
  y2,
  dstX,
  dstY,
  w,
 
)
Value:
tVar[vp + 0] = x1; \
tVar[vp + 1] = y1; \
tVar[vp + 2] = x2; \
tVar[vp + 3] = y1; \
tVar[vp + 4] = x2; \
tVar[vp + 5] = y2; \
tVar[vp + 6] = x1; \
tVar[vp + 7] = y2; \
vVar[vp + 0] = dstX; \
vVar[vp + 1] = dstY; \
vVar[vp + 2] = dstX + w; \
vVar[vp + 3] = dstY; \
vVar[vp + 4] = dstX + w; \
vVar[vp + 5] = dstY + h; \
vVar[vp + 6] = dstX; \
vVar[vp + 7] = dstY + h

Definition at line 48 of file normalopenglgraphics.cpp.

◆ vertFillNv

#define vertFillNv (   tVar,
  vVar,
  srcX,
  srcY,
  dstX,
  dstY,
  w,
 
)
Value:
tVar[vp + 0] = srcX; \
tVar[vp + 1] = srcY; \
tVar[vp + 2] = srcX + w; \
tVar[vp + 3] = srcY; \
tVar[vp + 4] = srcX + w; \
tVar[vp + 5] = srcY + h; \
tVar[vp + 6] = srcX; \
tVar[vp + 7] = srcY + h; \
vVar[vp + 0] = dstX; \
vVar[vp + 1] = dstY; \
vVar[vp + 2] = dstX + w; \
vVar[vp + 3] = dstY; \
vVar[vp + 4] = dstX + w; \
vVar[vp + 5] = dstY + h; \
vVar[vp + 6] = dstX; \
vVar[vp + 7] = dstY + h

Definition at line 67 of file normalopenglgraphics.cpp.

Function Documentation

◆ bindPointerInt()

static void bindPointerInt ( const GLint *const  vert,
const GLint *const  tex 
)
inlinestatic

Definition at line 216 of file normalopenglgraphics.cpp.

218 {
219  if (vertPtr != vert)
220  {
221  vertPtr = vert;
222  glVertexPointer(2, GL_INT, 0, vert);
223  glTexCoordPointer(2, GL_INT, 0, tex);
224  }
225 }

References anonymous_namespace{normalopenglgraphics.cpp}::vertPtr.

Referenced by drawQuad(), NormalOpenGLGraphics::drawQuadArrayii(), NormalOpenGLGraphics::drawQuadArrayiiCached(), drawRescaledQuad(), and NormalOpenGLGraphics::testDraw().

◆ bindPointerIntFloat()

static void bindPointerIntFloat ( const GLint *const  vert,
const GLfloat *const  tex 
)
inlinestatic

Definition at line 202 of file normalopenglgraphics.cpp.

204 {
205  if (vertPtr != vert)
206  {
207  vertPtr = vert;
208  glVertexPointer(2, GL_INT, 0, vert);
209  glTexCoordPointer(2, GL_FLOAT, 0, tex);
210  }
211 }

References anonymous_namespace{normalopenglgraphics.cpp}::vertPtr.

Referenced by drawQuad(), NormalOpenGLGraphics::drawQuadArrayfi(), NormalOpenGLGraphics::drawQuadArrayfiCached(), drawRescaledQuad(), and NormalOpenGLGraphics::testDraw().

◆ drawQuad()

static void drawQuad ( const Image *const  image,
const int  srcX,
const int  srcY,
const int  dstX,
const int  dstY,
const int  width,
const int  height 
)
inlinestatic

Definition at line 233 of file normalopenglgraphics.cpp.

237 {
238  if (OpenGLImageHelper::mTextureType == GL_TEXTURE_2D)
239  {
240  const float tw = static_cast<float>(image->mTexWidth);
241  const float th = static_cast<float>(image->mTexHeight);
242  // Find OpenGL normalized texture coordinates.
243  const float texX1 = static_cast<float>(srcX) / tw;
244  const float texY1 = static_cast<float>(srcY) / th;
245  const float texX2 = static_cast<float>(srcX + width) / tw;
246  const float texY2 = static_cast<float>(srcY + height) / th;
247 
248  GLfloat tex[] =
249  {
250  texX1, texY1,
251  texX2, texY1,
252  texX2, texY2,
253  texX1, texY2
254  };
255 
256  GLint vert[] =
257  {
258  dstX, dstY,
259  dstX + width, dstY,
260  dstX + width, dstY + height,
261  dstX, dstY + height
262  };
263 
264  bindPointerIntFloat(&vert[0], &tex[0]);
265 #ifdef DEBUG_DRAW_CALLS
266  NormalOpenGLGraphics::mDrawCalls ++;
267 #endif // DEBUG_DRAW_CALLS
268 
269  glDrawArrays(GL_QUADS, 0, 4);
270 #ifdef OPENGLERRORS
272 #endif // OPENGLERRORS
273  }
274  else
275  {
276  GLint tex[] =
277  {
278  srcX, srcY,
279  srcX + width, srcY,
280  srcX + width, srcY + height,
281  srcX, srcY + height
282  };
283  GLint vert[] =
284  {
285  dstX, dstY,
286  dstX + width, dstY,
287  dstX + width, dstY + height,
288  dstX, dstY + height
289  };
290 
291  bindPointerInt(&vert[0], &tex[0]);
292 #ifdef DEBUG_DRAW_CALLS
293  NormalOpenGLGraphics::mDrawCalls ++;
294 #endif // DEBUG_DRAW_CALLS
295 
296  glDrawArrays(GL_QUADS, 0, 4);
297 #ifdef OPENGLERRORS
299 #endif // OPENGLERRORS
300  }
301 }
static void logError()
GraphicsManager graphicsManager
static void bindPointerIntFloat(const GLint *const vert, const GLfloat *const tex) A_INLINE
static void bindPointerInt(const GLint *const vert, const GLint *const tex) A_INLINE

References bindPointerInt(), bindPointerIntFloat(), graphicsManager, GraphicsManager::logError(), and OpenGLImageHelper::mTextureType.

◆ drawRescaledQuad()

static void drawRescaledQuad ( const Image *const  image,
const int  srcX,
const int  srcY,
const int  dstX,
const int  dstY,
const int  width,
const int  height,
const int  desiredWidth,
const int  desiredHeight 
)
inlinestatic

Definition at line 311 of file normalopenglgraphics.cpp.

317 {
318  if (OpenGLImageHelper::mTextureType == GL_TEXTURE_2D)
319  {
320  const float tw = static_cast<float>(image->mTexWidth);
321  const float th = static_cast<float>(image->mTexHeight);
322  // Find OpenGL normalized texture coordinates.
323  const float texX1 = static_cast<float>(srcX) / tw;
324  const float texY1 = static_cast<float>(srcY) / th;
325  const float texX2 = static_cast<float>(srcX + width) / tw;
326  const float texY2 = static_cast<float>(srcY + height) / th;
327 
328  GLfloat tex[] =
329  {
330  texX1, texY1,
331  texX2, texY1,
332  texX2, texY2,
333  texX1, texY2
334  };
335 
336  GLint vert[] =
337  {
338  dstX, dstY,
339  dstX + desiredWidth, dstY,
340  dstX + desiredWidth, dstY + desiredHeight,
341  dstX, dstY + desiredHeight
342  };
343 
344  bindPointerIntFloat(&vert[0], &tex[0]);
345 #ifdef DEBUG_DRAW_CALLS
346  NormalOpenGLGraphics::mDrawCalls ++;
347 #endif // DEBUG_DRAW_CALLS
348 
349  glDrawArrays(GL_QUADS, 0, 4);
350 #ifdef OPENGLERRORS
352 #endif // OPENGLERRORS
353  }
354  else
355  {
356  GLint tex[] =
357  {
358  srcX, srcY,
359  srcX + width, srcY,
360  srcX + width, srcY + height,
361  srcX, srcY + height
362  };
363  GLint vert[] =
364  {
365  dstX, dstY,
366  dstX + desiredWidth, dstY,
367  dstX + desiredWidth, dstY + desiredHeight,
368  dstX, dstY + desiredHeight
369  };
370 
371  bindPointerInt(&vert[0], &tex[0]);
372 #ifdef DEBUG_DRAW_CALLS
373  NormalOpenGLGraphics::mDrawCalls ++;
374 #endif // DEBUG_DRAW_CALLS
375 
376  glDrawArrays(GL_QUADS, 0, 4);
377 #ifdef OPENGLERRORS
379 #endif // OPENGLERRORS
380  }
381 }

References bindPointerInt(), bindPointerIntFloat(), graphicsManager, GraphicsManager::logError(), and OpenGLImageHelper::mTextureType.