Skip to content

Commit 2273e2e

Browse files
committed
Merge branch 'next' of https://github.com/gameplay3d/GamePlay into next
2 parents f13282e + 8710b24 commit 2273e2e

File tree

16 files changed

+265
-89
lines changed

16 files changed

+265
-89
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/Node.cpp

Lines changed: 40 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -218,23 +218,32 @@ Node* Node::getRootNode() const
218218
}
219219

220220
Node* Node::findNode(const char* id, bool recursive, bool exactMatch) const
221+
{
222+
return findNode(id, recursive, exactMatch, false);
223+
}
224+
225+
Node* Node::findNode(const char* id, bool recursive, bool exactMatch, bool skipSkin) const
221226
{
222227
GP_ASSERT(id);
223228

224-
// If the drawable is a model with a mesh skin, search the skin's hierarchy as well.
225-
Node* rootNode = NULL;
226-
Model* model = dynamic_cast<Model*>(_drawable);
227-
if (model)
229+
// If not skipSkin hierarchy, try searching the skin hierarchy
230+
if (!skipSkin)
228231
{
229-
if (model->getSkin() != NULL && (rootNode = model->getSkin()->_rootNode) != NULL)
232+
// If the drawable is a model with a mesh skin, search the skin's hierarchy as well.
233+
Node* rootNode = NULL;
234+
Model* model = dynamic_cast<Model*>(_drawable);
235+
if (model)
230236
{
231-
if ((exactMatch && rootNode->_id == id) || (!exactMatch && rootNode->_id.find(id) == 0))
232-
return rootNode;
233-
234-
Node* match = rootNode->findNode(id, true, exactMatch);
235-
if (match)
237+
if (model->getSkin() != NULL && (rootNode = model->getSkin()->_rootNode) != NULL)
236238
{
237-
return match;
239+
if ((exactMatch && rootNode->_id == id) || (!exactMatch && rootNode->_id.find(id) == 0))
240+
return rootNode;
241+
242+
Node* match = rootNode->findNode(id, true, exactMatch, true);
243+
if (match)
244+
{
245+
return match;
246+
}
238247
}
239248
}
240249
}
@@ -252,7 +261,7 @@ Node* Node::findNode(const char* id, bool recursive, bool exactMatch) const
252261
{
253262
for (Node* child = getFirstChild(); child != NULL; child = child->getNextSibling())
254263
{
255-
Node* match = child->findNode(id, true, exactMatch);
264+
Node* match = child->findNode(id, true, exactMatch, skipSkin);
256265
if (match)
257266
{
258267
return match;
@@ -263,25 +272,35 @@ Node* Node::findNode(const char* id, bool recursive, bool exactMatch) const
263272
}
264273

265274
unsigned int Node::findNodes(const char* id, std::vector<Node*>& nodes, bool recursive, bool exactMatch) const
275+
{
276+
return findNodes(id, nodes, recursive, exactMatch, false);
277+
}
278+
279+
unsigned int Node::findNodes(const char* id, std::vector<Node*>& nodes, bool recursive, bool exactMatch, bool skipSkin) const
266280
{
267281
GP_ASSERT(id);
268282

269283
// If the drawable is a model with a mesh skin, search the skin's hierarchy as well.
270284
unsigned int count = 0;
271-
Node* rootNode = NULL;
272-
Model* model = dynamic_cast<Model*>(_drawable);
273-
if (model)
285+
286+
if (!skipSkin)
274287
{
275-
if (model->getSkin() != NULL && (rootNode = model->getSkin()->_rootNode) != NULL)
288+
Node* rootNode = NULL;
289+
Model* model = dynamic_cast<Model*>(_drawable);
290+
if (model)
276291
{
277-
if ((exactMatch && rootNode->_id == id) || (!exactMatch && rootNode->_id.find(id) == 0))
292+
if (model->getSkin() != NULL && (rootNode = model->getSkin()->_rootNode) != NULL)
278293
{
279-
nodes.push_back(rootNode);
280-
++count;
294+
if ((exactMatch && rootNode->_id == id) || (!exactMatch && rootNode->_id.find(id) == 0))
295+
{
296+
nodes.push_back(rootNode);
297+
++count;
298+
}
299+
count += rootNode->findNodes(id, nodes, recursive, exactMatch, true);
281300
}
282-
count += rootNode->findNodes(id, nodes, true, exactMatch);
283301
}
284302
}
303+
285304
// Search immediate children first.
286305
for (Node* child = getFirstChild(); child != NULL; child = child->getNextSibling())
287306
{
@@ -297,7 +316,7 @@ unsigned int Node::findNodes(const char* id, std::vector<Node*>& nodes, bool rec
297316
{
298317
for (Node* child = getFirstChild(); child != NULL; child = child->getNextSibling())
299318
{
300-
count += child->findNodes(id, nodes, true, exactMatch);
319+
count += child->findNodes(id, nodes, recursive, exactMatch, skipSkin);
301320
}
302321
}
303322

gameplay/src/Node.h

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -665,6 +665,39 @@ class Node : public Transform, public Ref
665665
*/
666666
void setBoundsDirty();
667667

668+
/**
669+
* Returns the first child node that matches the given ID.
670+
*
671+
* This method checks the specified ID against its immediate child nodes
672+
* but does not check the ID against itself.
673+
* If recursive is true, it also traverses the Node's hierarchy with a breadth first search.
674+
*
675+
* @param id The ID of the child to find.
676+
* @param recursive True to search recursively all the node's children, false for only direct children.
677+
* @param exactMatch true if only nodes whose ID exactly matches the specified ID are returned,
678+
* or false if nodes that start with the given ID are returned.
679+
* @param skipSkin Set true to skip skin hierarchy, initial find may set false to include skin hierarchy.
680+
*
681+
* @return The Node found or NULL if not found.
682+
*/
683+
Node* findNode(const char* id, bool recursive, bool exactMatch, bool skipSkin) const;
684+
685+
686+
/**
687+
* Returns all child nodes that match the given ID.
688+
*
689+
* @param id The ID of the node to find.
690+
* @param nodes A vector of nodes to be populated with matches.
691+
* @param recursive true if a recursive search should be performed, false otherwise.
692+
* @param exactMatch true if only nodes whose ID exactly matches the specified ID are returned,
693+
* or false if nodes that start with the given ID are returned.
694+
* @param skipSkin Set true to skip skin hierarchy, initial find may set false to include skin hierarchy.
695+
*
696+
* @return The number of matches found.
697+
* @script{ignore}
698+
*/
699+
unsigned int findNodes(const char* id, std::vector<Node*>& nodes, bool recursive, bool exactMatch, bool skipSkin) const;
700+
668701
private:
669702

670703
/**

0 commit comments

Comments
 (0)