Skip to content

Commit 8710b24

Browse files
Merge pull request gameplay3d#1816 from seanpaultaylor/next
Adds map/unmap buffer for Mesh and MeshPart
2 parents c1893ab + b6654c8 commit 8710b24

File tree

13 files changed

+187
-63
lines changed

13 files changed

+187
-63
lines changed

gameplay/gameplay.pro

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ TEMPLATE = lib
99
CONFIG += staticlib
1010
CONFIG += c++11
1111
CONFIG -= qt
12-
13-
#DEFINES += GP_NO_PLATFORM
12+
CONFIG(debug, debug|release): DEFINES += _DEBUG
1413

1514
SOURCES += src/AbsoluteLayout.cpp \
1615
src/AIAgent.cpp \
@@ -548,18 +547,19 @@ linux: INCLUDEPATH += /usr/include/harfbuzz
548547

549548
macx: OBJECTIVE_SOURCES += src/PlatformMacOSX.mm
550549
macx: OBJECTIVE_SOURCES += src/gameplay-main-macosx.mm
551-
macx: QMAKE_CXXFLAGS += -x c++ -stdlib=libc++ -w -arch x86_64
552-
macx: QMAKE_OBJECTIVE_CFLAGS += -x objective-c++ -stdlib=libc++ -w -arch x86_64
550+
macx: QMAKE_CXXFLAGS += -x c++ -x objective-c++ -stdlib=libc++ -w -arch x86_64
553551
macx: LIBS += -F/System/Library/Frameworks -framework GameKit
554552
macx: LIBS += -F/System/Library/Frameworks -framework IOKit
555553
macx: LIBS += -F/System/Library/Frameworks -framework QuartzCore
556554
macx: LIBS += -F/System/Library/Frameworks -framework OpenAL
557555
macx: LIBS += -F/System/Library/Frameworks -framework OpenGL
558556
macx: LIBS += -F/System/Library/Frameworks -framework Cocoa
557+
macx: LIBS += -F/System/Library/Frameworks -framework Foundation
559558

560559
win32: SOURCES += src/PlatformWindows.cpp
561560
win32: SOURCES += src/gameplay-main-windows.cpp
562561
win32: DEFINES += WIN32 _UNICODE UNICODE
563-
win32: INCLUDEPATH += $$(DXSDK_DIR)Include
562+
win32: INCLUDEPATH += $$(DXSDK_DIR)/Include
564563
win32: QMAKE_CXXFLAGS_WARN_ON -= -w34100
565564
win32: QMAKE_CXXFLAGS_WARN_ON -= -w34189
565+
win32: QMAKE_CXXFLAGS_WARN_ON -= -w4302

gameplay/src/Mesh.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,6 @@ bool Mesh::isDynamic() const
251251
return _dynamic;
252252
}
253253

254-
255254
Mesh::PrimitiveType Mesh::getPrimitiveType() const
256255
{
257256
return _primitiveType;
@@ -262,7 +261,19 @@ void Mesh::setPrimitiveType(PrimitiveType type)
262261
_primitiveType = type;
263262
}
264263

265-
void Mesh::setVertexData(const float* vertexData, unsigned int vertexStart, unsigned int vertexCount)
264+
void* Mesh::mapVertexBuffer(MapAccess access)
265+
{
266+
GL_ASSERT( glBindBuffer(GL_ARRAY_BUFFER, _vertexBuffer) );
267+
268+
return (void*)glMapBuffer(GL_ARRAY_BUFFER, access);
269+
}
270+
271+
bool Mesh::unmapVertexBuffer()
272+
{
273+
return glUnmapBuffer(GL_ARRAY_BUFFER);
274+
}
275+
276+
void Mesh::setVertexData(const void* vertexData, unsigned int vertexStart, unsigned int vertexCount)
266277
{
267278
GL_ASSERT( glBindBuffer(GL_ARRAY_BUFFER, _vertexBuffer) );
268279

gameplay/src/Mesh.h

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,16 @@ class Mesh : public Ref
4747
POINTS = GL_POINTS
4848
};
4949

50+
/**
51+
* Defines mapping access/usage.
52+
*/
53+
enum MapAccess
54+
{
55+
MAP_READ_ONLY = GL_READ_ONLY,
56+
MAP_WRITE_ONLY = GL_WRITE_ONLY,
57+
MAP_READ_WRITE = GL_READ_WRITE
58+
};
59+
5060
/**
5161
* Constructs a new mesh with the specified vertex format.
5262
*
@@ -200,14 +210,47 @@ class Mesh : public Ref
200210
*/
201211
void setPrimitiveType(Mesh::PrimitiveType type);
202212

213+
/**
214+
* Maps the vertex buffer for the specified access.
215+
*
216+
* Mapping vertex data causes a synchronizing issue. To avoid gpu idle
217+
* If GPU is still working with the buffer object, mapVertexBuffer will not
218+
* return until GPU finishes its job with the corresponding buffer object.
219+
*
220+
* To avoid waiting (idle), you can call first setVertexBuffer with NULL pointer,
221+
* then call mapVertexBuffer(). In this case, the previous data will be discarded
222+
* and mapVertexBuffer() returns a new allocated pointer immediately even if GPU is
223+
* still working with the previous data.
224+
*
225+
* However, this method is valid only if you want to update entire data set because
226+
* you discard the previous data. If you want to change only portion of data or to
227+
* read data, you better not release the previous data.
228+
*
229+
* After modifying the data of VBO, it must be unmapped the buffer object from the client's
230+
* memory. unmapVertexBuffer returns true if success. When it returns false, the contents of
231+
* vertex buffer become corrupted while the buffer was mapped. The corruption results from screen
232+
* resolution change or window system specific events. In this case, the data must be resubmitted.
233+
*
234+
* @param access The access for which the data can be use. Ex. read, write, read_write.
235+
* @return The mapped vertex buffer
236+
*/
237+
void* mapVertexBuffer(Mesh::MapAccess access);
238+
239+
/**
240+
* Unmaps the vertex buffer.
241+
*
242+
* @return false if unmapping buffer was unsuccessful
243+
*/
244+
bool unmapVertexBuffer();
245+
203246
/**
204247
* Sets the specified vertex data into the mapped vertex buffer.
205248
*
206249
* @param vertexData The vertex data to be set.
207250
* @param vertexStart The index of the starting vertex (0 by default).
208251
* @param vertexCount The number of vertices to be set (default is 0, for all vertices).
209252
*/
210-
void setVertexData(const float* vertexData, unsigned int vertexStart = 0, unsigned int vertexCount = 0);
253+
void setVertexData(const void* vertexData, unsigned int vertexStart = 0, unsigned int vertexCount = 0);
211254

212255
/**
213256
* Creates and adds a new part of primitive data defining how the vertices are connected.

gameplay/src/MeshPart.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,16 @@ IndexBufferHandle MeshPart::getIndexBuffer() const
8282
return _indexBuffer;
8383
}
8484

85-
bool MeshPart::isDynamic() const
85+
void* MeshPart::mapIndexBuffer(Mesh::MapAccess access)
8686
{
87-
return _dynamic;
87+
GL_ASSERT( glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _indexBuffer) );
88+
89+
return (void*)glMapBuffer(GL_ELEMENT_ARRAY_BUFFER, access);
90+
}
91+
92+
bool MeshPart::unmapIndexBuffer()
93+
{
94+
return glUnmapBuffer(GL_ELEMENT_ARRAY_BUFFER);
8895
}
8996

9097
void MeshPart::setIndexData(const void* indexData, unsigned int indexStart, unsigned int indexCount)
@@ -123,4 +130,9 @@ void MeshPart::setIndexData(const void* indexData, unsigned int indexStart, unsi
123130
}
124131
}
125132

133+
bool MeshPart::isDynamic() const
134+
{
135+
return _dynamic;
136+
}
137+
126138
}

gameplay/src/MeshPart.h

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,37 @@ class MeshPart
5858
IndexBufferHandle getIndexBuffer() const;
5959

6060
/**
61-
* Determines if the indices are dynamic.
61+
* Maps the index buffer for the specified access.
6262
*
63-
* @return true if the part is dynamic; false otherwise.
63+
* Mapping index data causes a synchronizing issue. To avoid gpu idle
64+
* If GPU is still working with the buffer object, mapIndexBuffer will not
65+
* return until GPU finishes its job with the corresponding buffer object.
66+
*
67+
* To avoid waiting (idle), you can call first setIndexData with NULL pointer,
68+
* then call mapIndexBuffer(). In this case, the previous data will be discarded
69+
* and mapIndexData() returns a new allocated pointer immediately even if GPU is
70+
* still working with the previous data.
71+
*
72+
* However, this method is valid only if you want to update entire data set because
73+
* you discard the previous data. If you want to change only portion of data or to
74+
* read data, you better not release the previous data.
75+
*
76+
* After modifying the data of VBO, it must be unmapped the buffer object from the client's
77+
* memory. unmapIndexBuffer returns true if success. When it returns false, the contents of
78+
* index buffer become corrupted while the buffer was mapped. The corruption results from screen
79+
* resolution change or window system specific events. In this case, the data must be resubmitted.
80+
*
81+
* @param access The access for which the data can be use. Ex. read, write, read_write.
82+
* @return The mapped index buffer
6483
*/
65-
bool isDynamic() const;
84+
void* mapIndexBuffer(Mesh::MapAccess access);
85+
86+
/**
87+
* Unmaps the index buffer.
88+
*
89+
* @return false if unmapping buffer was unsuccessful
90+
*/
91+
bool unmapIndexBuffer();
6692

6793
/**
6894
* Sets the specified index data into the mapped index buffer.
@@ -74,6 +100,13 @@ class MeshPart
74100
*/
75101
void setIndexData(const void* indexData, unsigned int indexStart, unsigned int indexCount);
76102

103+
/**
104+
* Determines if the indices are dynamic.
105+
*
106+
* @return true if the part is dynamic; false otherwise.
107+
*/
108+
bool isDynamic() const;
109+
77110
private:
78111

79112
/**

gameplay/src/Properties.h

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -524,11 +524,13 @@ class Properties
524524
Properties();
525525

526526
/**
527-
* Constructs the Properties class from a file.
528-
*
529-
* @param stream The stream used for reading the properties from file.
527+
* Constructor.
530528
*/
531529
Properties(Stream* stream);
530+
531+
/**
532+
* Constructor.
533+
*/
532534
Properties(const Properties& copy);
533535

534536
/**
@@ -538,21 +540,20 @@ class Properties
538540

539541
void readProperties(Stream* stream);
540542

543+
void setDirectoryPath(const std::string* path);
544+
545+
void setDirectoryPath(const std::string& path);
546+
541547
void skipWhiteSpace(Stream* stream);
542548

543549
char* trimWhiteSpace(char* str);
544550

545-
// Called after create(); copies info from parents into derived namespaces.
546-
void resolveInheritance(const char* id = NULL);
551+
Properties* clone();
547552

548-
// Called by resolveInheritance().
549553
void mergeWith(Properties* overrides);
550554

551-
// Clones the Properties object.
552-
Properties* clone();
553-
554-
void setDirectoryPath(const std::string* path);
555-
void setDirectoryPath(const std::string& path);
555+
// Called after create(); copies info from parents into derived namespaces.
556+
void resolveInheritance(const char* id = NULL);
556557

557558
std::string _namespace;
558559
std::string _id;

samples/browser/sample-browser.pro

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ TARGET = sample-browser
88
TEMPLATE = app
99
CONFIG += c++11
1010
CONFIG -= qt
11+
CONFIG(debug, debug|release): DEFINES += _DEBUG
1112

1213
SOURCES += src/Audio3DSample.cpp \
1314
src/AudioSample.cpp \
@@ -89,8 +90,7 @@ linux: QMAKE_POST_LINK += $$quote(rsync -rau $$PWD/../../gameplay/res/shaders ..
8990
linux: QMAKE_POST_LINK += $$quote(rsync -rau $$PWD/../../gameplay/res/ui ../res$$escape_expand(\n\t))
9091
linux: QMAKE_POST_LINK += $$quote(cp -rf $$PWD/../../gameplay/res/logo_powered_white.png ../res$$escape_expand(\n\t))
9192

92-
macx: QMAKE_CXXFLAGS += -x c++ -stdlib=libc++ -w -arch x86_64
93-
macx: QMAKE_OBJECTIVE_CFLAGS += -x objective-c++ -stdlib=libc++ -w -arch x86_64
93+
macx: QMAKE_CXXFLAGS += -x c++ -x objective-c++ -stdlib=libc++ -w -arch x86_64
9494
macx: LIBS += -L$$PWD/../../gameplay/Debug/ -lgameplay
9595
macx: LIBS += -L$$PWD/../../external-deps/lib/macosx/x86_64/ -lgameplay-deps
9696
macx: LIBS += -F/System/Library/Frameworks -framework GameKit
@@ -99,6 +99,7 @@ macx: LIBS += -F/System/Library/Frameworks -framework QuartzCore
9999
macx: LIBS += -F/System/Library/Frameworks -framework OpenAL
100100
macx: LIBS += -F/System/Library/Frameworks -framework OpenGL
101101
macx: LIBS += -F/System/Library/Frameworks -framework Cocoa
102+
macx: LIBS += -F/System/Library/Frameworks -framework Foundation
102103
macx: QMAKE_POST_LINK += $$quote(rsync -rau $$PWD/../../gameplay/res/shaders ../res$$escape_expand(\n\t))
103104
macx: QMAKE_POST_LINK += $$quote(rsync -rau $$PWD/../../gameplay/res/ui ../res$$escape_expand(\n\t))
104105
macx: QMAKE_POST_LINK += $$quote(cp -rf $$PWD/../../gameplay/res/logo_powered_white.png ../res$$escape_expand(\n\t))
@@ -128,6 +129,7 @@ win32: LIBS += -L$$(DXSDK_DIR)Lib\x64 -lXInput
128129
win32: INCLUDEPATH += $$(DXSDK_DIR)Include
129130
win32: QMAKE_CXXFLAGS_WARN_ON -= -w34100
130131
win32: QMAKE_CXXFLAGS_WARN_ON -= -w34189
132+
win32: QMAKE_CXXFLAGS_WARN_ON -= -w4302
131133
win32: QMAKE_POST_LINK += $$quote(xcopy ..\..\..\gameplay\res\shaders res\shaders\* /s /y /d$$escape_expand(\n\t))
132134
win32: QMAKE_POST_LINK += $$quote(xcopy ..\..\..\gameplay\res\ui res\ui\* /s /y /d$$escape_expand(\n\t))
133135
win32: QMAKE_POST_LINK += $$quote(copy ..\..\..\gameplay\res\logo_powered_white.png res$$escape_expand(\n\t))

samples/browser/src/GestureSample.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ void GestureSample::initialize()
6060
registerGesture(Gesture::GESTURE_DROP);
6161
GP_ASSERT(isGestureRegistered(Gesture::GESTURE_DROP));
6262
}
63-
GP_ASSERT(anySupported == isGestureSupported(Gesture::GESTURE_ANY_SUPPORTED));
63+
//GP_ASSERT(anySupported == isGestureSupported(Gesture::GESTURE_ANY_SUPPORTED));
6464
}
6565

6666
void GestureSample::finalize()

samples/character/sample-character.pro

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ TARGET = sample-character
88
TEMPLATE = app
99
CONFIG += c++11
1010
CONFIG -= qt
11+
CONFIG(debug, debug|release): DEFINES += _DEBUG
1112

1213
SOURCES += src/CharacterGame.cpp
1314

@@ -40,8 +41,7 @@ linux: QMAKE_POST_LINK += $$quote(rsync -rau $$PWD/../../gameplay/res/ui ../res$
4041
linux: QMAKE_POST_LINK += $$quote(cp -rf $$PWD/../../gameplay/res/logo_powered_white.png ../res$$escape_expand(\n\t))
4142
linux: QMAKE_POST_LINK += $$quote(cp -rf $$PWD/game.dxt.config game.config$$escape_expand(\n\t))
4243

43-
macx: QMAKE_CXXFLAGS += -x c++ -stdlib=libc++ -w -arch x86_64
44-
macx: QMAKE_OBJECTIVE_CFLAGS += -x objective-c++ -stdlib=libc++ -w -arch x86_64
44+
macx: QMAKE_CXXFLAGS += -x c++ -x objective-c++ -stdlib=libc++ -w -arch x86_64
4545
macx: LIBS += -L$$PWD/../../gameplay/Debug/ -lgameplay
4646
macx: LIBS += -L$$PWD/../../external-deps/lib/macosx/x86_64/ -lgameplay-deps
4747
macx: LIBS += -F/System/Library/Frameworks -framework GameKit
@@ -50,7 +50,8 @@ macx: LIBS += -F/System/Library/Frameworks -framework QuartzCore
5050
macx: LIBS += -F/System/Library/Frameworks -framework OpenAL
5151
macx: LIBS += -F/System/Library/Frameworks -framework OpenGL
5252
macx: LIBS += -F/System/Library/Frameworks -framework Cocoa
53-
macx: QMAKE_ += $$quote(rsync -rau $$PWD/../../gameplay/res/shaders ../res$$escape_expand(\n\t))
53+
macx: LIBS += -F/System/Library/Frameworks -framework Foundation
54+
macx: QMAKE_POST_LINK += $$quote(rsync -rau $$PWD/../../gameplay/res/shaders ../res$$escape_expand(\n\t))
5455
macx: QMAKE_POST_LINK += $$quote(rsync -rau $$PWD/../../gameplay/res/ui ../res$$escape_expand(\n\t))
5556
macx: QMAKE_POST_LINK += $$quote(cp -rf $$PWD/../../gameplay/res/logo_powered_white.png ../res$$escape_expand(\n\t))
5657
macx
@@ -78,6 +79,7 @@ win32: LIBS += -L$$(DXSDK_DIR)Lib\x64 -lXInput
7879
win32: INCLUDEPATH += $$(DXSDK_DIR)Include
7980
win32: QMAKE_CXXFLAGS_WARN_ON -= -w34100
8081
win32: QMAKE_CXXFLAGS_WARN_ON -= -w34189
82+
win32: QMAKE_CXXFLAGS_WARN_ON -= -w4302
8183
win32: QMAKE_POST_LINK += $$quote(xcopy ..\..\..\gameplay\res\shaders res\shaders\* /s /y /d$$escape_expand(\n\t))
8284
win32: QMAKE_POST_LINK += $$quote(xcopy ..\..\..\gameplay\res\ui res\ui\* /s /y /d$$escape_expand(\n\t))
8385
win32: QMAKE_POST_LINK += $$quote(copy ..\..\..\gameplay\res\logo_powered_white.png res$$escape_expand(\n\t))

samples/racer/sample-racer.pro

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ TARGET = sample-racer
88
TEMPLATE = app
99
CONFIG += c++11
1010
CONFIG -= qt
11+
CONFIG(debug, debug|release): DEFINES += _DEBUG
1112

1213
SOURCES += src/RacerGame.cpp
1314

@@ -40,8 +41,7 @@ linux: QMAKE_POST_LINK += $$quote(rsync -rau $$PWD/../../gameplay/res/ui ../res$
4041
linux: QMAKE_POST_LINK += $$quote(cp -rf $$PWD/../../gameplay/res/logo_powered_white.png ../res$$escape_expand(\n\t))
4142
linux: QMAKE_POST_LINK += $$quote(cp -rf $$PWD/game.dxt.config game.config$$escape_expand(\n\t))
4243

43-
macx: QMAKE_CXXFLAGS += -x c++ -stdlib=libc++ -w -arch x86_64
44-
macx: QMAKE_OBJECTIVE_CFLAGS += -x objective-c++ -stdlib=libc++ -w -arch x86_64
44+
macx: QMAKE_CXXFLAGS += -x c++ -x objective-c++ -stdlib=libc++ -w -arch x86_64
4545
macx: LIBS += -L$$PWD/../../gameplay/Debug/ -lgameplay
4646
macx: LIBS += -L$$PWD/../../external-deps/lib/macosx/x86_64/ -lgameplay-deps
4747
macx: LIBS += -F/System/Library/Frameworks -framework GameKit
@@ -50,6 +50,7 @@ macx: LIBS += -F/System/Library/Frameworks -framework QuartzCore
5050
macx: LIBS += -F/System/Library/Frameworks -framework OpenAL
5151
macx: LIBS += -F/System/Library/Frameworks -framework OpenGL
5252
macx: LIBS += -F/System/Library/Frameworks -framework Cocoa
53+
macx: LIBS += -F/System/Library/Frameworks -framework Foundation
5354
macx: QMAKE_POST_LINK += $$quote(rsync -rau $$PWD/../../gameplay/res/shaders ../res$$escape_expand(\n\t))
5455
macx: QMAKE_POST_LINK += $$quote(rsync -rau $$PWD/../../gameplay/res/ui ../res$$escape_expand(\n\t))
5556
macx: QMAKE_POST_LINK += $$quote(cp -rf $$PWD/../../gameplay/res/logo_powered_white.png ../res$$escape_expand(\n\t))
@@ -78,6 +79,7 @@ win32: LIBS += -L$$(DXSDK_DIR)Lib\x64 -lXInput
7879
win32: INCLUDEPATH += $$(DXSDK_DIR)Include
7980
win32: QMAKE_CXXFLAGS_WARN_ON -= -w34100
8081
win32: QMAKE_CXXFLAGS_WARN_ON -= -w34189
82+
win32: QMAKE_CXXFLAGS_WARN_ON -= -w4302
8183
win32: QMAKE_POST_LINK += $$quote(xcopy ..\..\..\gameplay\res\shaders res\shaders\* /s /y /d$$escape_expand(\n\t))
8284
win32: QMAKE_POST_LINK += $$quote(xcopy ..\..\..\gameplay\res\ui res\ui\* /s /y /d$$escape_expand(\n\t))
8385
win32: QMAKE_POST_LINK += $$quote(copy ..\..\..\gameplay\res\logo_powered_white.png res$$escape_expand(\n\t))

0 commit comments

Comments
 (0)