Add VFPU::Float (but it is broken)
[ipdf/code.git] / src / graphicsbuffer.h
1 #ifndef _GRAPHICSBUFFER_H
2 #define _GRAPHICSBUFFER_H
3
4 #include <SDL.h>
5 #include "gl_core44.h"
6
7
8 namespace IPDF
9 {
10         /**
11          * Implementation of an OpenGL buffer, with some extra cleverness.
12          */
13         class GraphicsBuffer
14         {
15         public:
16                 enum BufferType
17                 {
18                         BufferTypeVertex,               // A Vertex Buffer
19                         BufferTypeIndex,                // An Index Buffer
20                         BufferTypePixelPack,            // Pixel Pack buffer
21                         BufferTypePixelUnpack,
22                         BufferTypeUniform,              // Uniform/Constant buffer
23                         BufferTypeTexture,              // I was hoping to avoid this one.
24                         BufferTypeDrawIndirect
25                 };
26                 
27                 enum BufferUsage
28                 {
29                         BufferUsageStaticDraw,
30                         BufferUsageStaticRead,
31                         BufferUsageStaticCopy,
32                         BufferUsageDynamicDraw,
33                         BufferUsageDynamicRead,
34                         BufferUsageDynamicCopy,
35                         BufferUsageStreamDraw,
36                         BufferUsageStreamRead,
37                         BufferUsageStreamCopy
38                 };
39                 
40                 GraphicsBuffer();
41                 ~GraphicsBuffer();
42                 
43                 void SetType(BufferType bufType);
44                 void SetUsage(BufferUsage bufUsage);
45                 
46                 void *Map(bool read, bool write, bool invalidate);
47                 void *MapRange(int offset, int length, bool read, bool write, bool invalidate);
48                 
49                 void UnMap();
50                 
51                 void Upload(size_t length, const void *data);
52                 void UploadRange(size_t length, intptr_t offset, const void *data);
53
54                 void Resize(size_t length);
55                 const size_t GetSize() const { return m_buffer_size; }
56
57                 void Invalidate();
58
59                 // WARNING: The buffer handle can change for (almost) no reason.
60                 // If you do _anything_ to the buffer, you'll need to call this
61                 // again to see if we've recreated it in a vain attempt to outsmart
62                 // the driver.
63                 GLuint GetHandle() const { return m_buffer_handle; }
64                 
65                 void Bind() const;
66         private:
67                 bool RecreateBuffer(const void *data = NULL);
68                 GLuint m_buffer_handle;
69                 BufferType m_buffer_type;
70                 BufferUsage m_buffer_usage;
71                 void *m_map_pointer;
72                 size_t m_buffer_size;
73                 bool m_invalidated;
74                 bool m_buffer_shape_dirty;
75                 bool m_faking_map;
76         };
77
78 }
79
80 #endif // _SCREEN_H

UCC git Repository :: git.ucc.asn.au