Slightly better results
[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 SetName(const char *name);
44                 void SetType(BufferType bufType);
45                 void SetUsage(BufferUsage bufUsage);
46                 
47                 void *Map(bool read, bool write, bool invalidate);
48                 void *MapRange(int offset, int length, bool read, bool write, bool invalidate);
49                 
50                 void UnMap();
51                 
52                 void Upload(size_t length, const void *data);
53                 void UploadRange(size_t length, intptr_t offset, const void *data);
54
55                 void Resize(size_t length);
56                 const size_t GetSize() const { return m_buffer_size; }
57
58                 void Invalidate();
59
60                 // WARNING: The buffer handle can change for (almost) no reason.
61                 // If you do _anything_ to the buffer, you'll need to call this
62                 // again to see if we've recreated it in a vain attempt to outsmart
63                 // the driver.
64                 GLuint GetHandle() const { return m_buffer_handle; }
65                 
66                 void Bind() const;
67                 void BindRange(size_t start, size_t size) const;
68         private:
69                 bool RecreateBuffer(const void *data = NULL);
70                 GLuint m_buffer_handle;
71                 BufferType m_buffer_type;
72                 BufferUsage m_buffer_usage;
73                 void *m_map_pointer;
74                 size_t m_buffer_size;
75                 bool m_invalidated;
76                 bool m_buffer_shape_dirty;
77                 bool m_faking_map;
78                 const char *m_name;
79         };
80
81 }
82
83 #endif // _SCREEN_H

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