VertexManagerBase.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. // Copyright 2010 Dolphin Emulator Project
  2. // Licensed under GPLv2+
  3. // Refer to the license.txt file included.
  4. #pragma once
  5. #include <vector>
  6. #include "Common/CommonFuncs.h"
  7. #include "Common/CommonTypes.h"
  8. #include "VideoCommon/DataReader.h"
  9. #include "VideoCommon/NativeVertexFormat.h"
  10. class NativeVertexFormat;
  11. class PointerWrap;
  12. enum PrimitiveType {
  13. PRIMITIVE_POINTS,
  14. PRIMITIVE_LINES,
  15. PRIMITIVE_TRIANGLES,
  16. };
  17. struct Slope
  18. {
  19. float dfdx;
  20. float dfdy;
  21. float f0;
  22. bool dirty;
  23. };
  24. class VertexManager
  25. {
  26. private:
  27. static const u32 SMALLEST_POSSIBLE_VERTEX = sizeof(float)*3; // 3 pos
  28. static const u32 LARGEST_POSSIBLE_VERTEX = sizeof(float)*45 + sizeof(u32)*2; // 3 pos, 3*3 normal, 2*u32 color, 8*4 tex, 1 posMat
  29. static const u32 MAX_PRIMITIVES_PER_COMMAND = (u16)-1;
  30. public:
  31. static const u32 MAXVBUFFERSIZE = ROUND_UP_POW2(MAX_PRIMITIVES_PER_COMMAND * LARGEST_POSSIBLE_VERTEX);
  32. // We may convert triangle-fans to triangle-lists, almost 3x as many indices.
  33. static const u32 MAXIBUFFERSIZE = ROUND_UP_POW2(MAX_PRIMITIVES_PER_COMMAND * 3);
  34. VertexManager();
  35. // needs to be virtual for DX11's dtor
  36. virtual ~VertexManager();
  37. static DataReader PrepareForAdditionalData(int primitive, u32 count, u32 stride, bool cullall);
  38. static void FlushData(u32 count, u32 stride);
  39. static void Flush();
  40. virtual ::NativeVertexFormat* CreateNativeVertexFormat() = 0;
  41. static void DoState(PointerWrap& p);
  42. protected:
  43. virtual void vDoState(PointerWrap& p) { }
  44. static PrimitiveType current_primitive_type;
  45. virtual void ResetBuffer(u32 stride) = 0;
  46. static u8* s_pCurBufferPointer;
  47. static u8* s_pBaseBufferPointer;
  48. static u8* s_pEndBufferPointer;
  49. static u32 GetRemainingSize();
  50. static u32 GetRemainingIndices(int primitive);
  51. static Slope s_zslope;
  52. static void CalculateZSlope(NativeVertexFormat* format);
  53. static bool s_cull_all;
  54. private:
  55. static bool s_is_flushed;
  56. virtual void vFlush(bool useDstAlpha) = 0;
  57. virtual void CreateDeviceObjects() {}
  58. virtual void DestroyDeviceObjects() {}
  59. };
  60. extern VertexManager *g_vertex_manager;