Advertisement
xerpi

DisplayList class v1

Jul 17th, 2013
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.49 KB | None | 0 0
  1. #ifndef _DISPLAYLIST_H_
  2. #define _DISPLAYLIST_H_
  3.  
  4. #include <vector>
  5. #include <stdlib.h>
  6. #include <gccore.h>
  7. #include "Image.h"
  8.  
  9. #include "grass_png.h"
  10.  
  11. typedef struct _vec2f32 {
  12.     f32 x, y;
  13. }Vector2f32;
  14.  
  15.  
  16. enum DispListCmdID {
  17.     DISPLISTCMD_POSITION,
  18.     DISPLISTCMD_TEXCOORD,
  19.     DISPLISTCMD_IMAGE
  20. };
  21.  
  22.  
  23. class DisplayList
  24. {
  25. public:
  26.     DisplayList(void) {
  27.  
  28.     }
  29.  
  30.     ~DisplayList() {
  31.         clear();
  32.     }
  33.  
  34.     void render() {
  35.  
  36.         std::vector <guVector>::iterator   posIt = positionList.begin();
  37.         if(positionList.size() == 0) return;
  38.         std::vector <Vector2f32>::iterator texIt = texCoordList.begin();
  39.         std::vector <Image *>::iterator    imgIt = imageList.begin();
  40.         std::vector <int>::iterator        cmdIt = commandList.begin();
  41.  
  42.         GX_Begin(GX_TRIANGLESTRIP, GX_VTXFMT0, positionList.size());
  43.  
  44.         for(; cmdIt != commandList.end(); ++cmdIt) {
  45.             switch(*cmdIt)
  46.             {
  47.             case DISPLISTCMD_POSITION:
  48.                 GX_Position3f32(posIt->x, posIt->y, posIt->z); ++posIt;
  49.                 break;
  50.             case DISPLISTCMD_TEXCOORD:
  51.                 GX_TexCoord2f32(texIt->x, texIt->y); ++texIt;
  52.                 break;
  53.             case DISPLISTCMD_IMAGE:
  54.                 (*imgIt)->setGX(GX_VTXFMT0); ++imgIt;
  55.                 break;
  56.             default:
  57.                 break;
  58.             }
  59.         }
  60.         GX_End();
  61.         GX_Flush();
  62.     }
  63.  
  64.     void clear() {
  65.         positionList.clear();
  66.         texCoordList.clear();
  67.         imageList.clear();
  68.         commandList.clear();
  69.     }
  70.  
  71.     void addPosition(guVector &v) {
  72.         positionList.push_back(v);
  73.         commandList.push_back(DISPLISTCMD_POSITION);
  74.     }
  75.  
  76.     void addPosition(float x, float y, float z) {
  77.         positionList.push_back({x, y, z});
  78.         commandList.push_back(DISPLISTCMD_POSITION);
  79.     }
  80.  
  81.     void addTexCoord(Vector2f32 &v) {
  82.         texCoordList.push_back(v);
  83.         commandList.push_back(DISPLISTCMD_TEXCOORD);
  84.     }
  85.  
  86.     void addTexCoord(float s, float t) {
  87.         texCoordList.push_back({s, t});
  88.         commandList.push_back(DISPLISTCMD_TEXCOORD);
  89.     }
  90.  
  91.     void addImage(Image *p) {
  92.         imageList.push_back(p);
  93.         commandList.push_back(DISPLISTCMD_IMAGE);
  94.     }
  95.  
  96.  
  97. private:
  98.     std::vector <guVector>    positionList;
  99.     std::vector <Vector2f32>  texCoordList;
  100.     std::vector <Image *>     imageList;
  101.     std::vector <int>         commandList;
  102.  
  103. };
  104.  
  105. #endif // _DISPLAYLIST_H_
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement