aboutsummaryrefslogtreecommitdiff
path: root/mp/src/public/togl/osx/cglmbuffer.h
blob: 0b161000a60542dbb1d27912000c2ecb8b7b851c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// cglmprogram.h
//	GLMgr buffers (index / vertex)
//	... maybe add PBO later as well
//===============================================================================

#ifndef CGLMBUFFER_H
#define	CGLMBUFFER_H

#pragma once

// ext links

// http://www.opengl.org/registry/specs/ARB/vertex_buffer_object.txt

//===============================================================================

// tokens not in the SDK headers

//#ifndef	GL_DEPTH_STENCIL_ATTACHMENT_EXT
//	#define GL_DEPTH_STENCIL_ATTACHMENT_EXT 0x84F9
//#endif

//===============================================================================

// forward declarations

class GLMContext;

enum EGLMBufferType
{
	kGLMVertexBuffer,
	kGLMIndexBuffer,
	kGLMUniformBuffer,	// for bindable uniform
	kGLMPixelBuffer,	// for PBO
	
	kGLMNumBufferTypes
};

	// pass this in "options" to constructor to make a dynamic buffer
#define	GLMBufferOptionDynamic	0x00000001

struct GLMBuffLockParams
{
	uint	m_offset;
	uint	m_size;
	bool	m_nonblocking;
	bool	m_discard;
};

class CGLMBuffer
{

public:
	void	Lock( GLMBuffLockParams *params, char **addressOut );
	void	Unlock( void );

//protected:
	friend class GLMContext;			// only GLMContext can make CGLMBuffer objects
	friend class GLMTester;	
	friend class IDirect3D9;
	friend class IDirect3DDevice9;
		
	CGLMBuffer					( GLMContext *ctx, EGLMBufferType type, uint size, uint options );
	~CGLMBuffer					( );	
	
	void	SetModes			( bool asyncMap, bool explicitFlush, bool force = false );
	void	FlushRange			( uint offset, uint size );
	
	GLMContext				*m_ctx;					// link back to parent context
	EGLMBufferType			m_type;
	uint					m_size;
	GLenum					m_buffGLTarget;			// GL_ARRAY_BUFFER_ARB / GL_ELEMENT_BUFFER_ARB	
	GLuint					m_name;					// name of this program in the context	
	uint					m_revision;				// bump anytime the size changes or buffer is orphaned
	bool					m_enableAsyncMap;		// mirror of the buffer state
	bool					m_enableExplicitFlush;	// mirror of the buffer state

	bool					m_bound;				// true if bound to context		
	bool					m_mapped;				// is it currently mapped
	uint					m_dirtyMinOffset;		// when equal, range is empty
	uint					m_dirtyMaxOffset;
	
	float					*m_lastMappedAddress;
	
	// --------------------- pseudo-VBO support below here (explicitly for dynamic index buffers)
	bool					m_pseudo;				// true if the m_name is 0, and the backing is plain RAM
	
	// in pseudo mode, there is just one RAM buffer that acts as the backing.
	// expectation is that this mode would only be used for dynamic indices.
	// since indices have to be consumed (copied to command stream) prior to return from a drawing call,
	// there's no need to do any fencing or multibuffering.  orphaning in particular becomes a no-op.
	
	char					*m_pseudoBuf;			// storage for pseudo buffer
};	


#endif