Skip to content

Commit

Permalink
Merge pull request #1816 from seanpaultaylor/next
Browse files Browse the repository at this point in the history
Adds map/unmap buffer for Mesh and MeshPart
  • Loading branch information
seanpaultaylor committed Jan 28, 2016
2 parents c1893ab + b6654c8 commit 8710b24
Show file tree
Hide file tree
Showing 13 changed files with 187 additions and 63 deletions.
10 changes: 5 additions & 5 deletions gameplay/gameplay.pro
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ TEMPLATE = lib
CONFIG += staticlib
CONFIG += c++11
CONFIG -= qt

#DEFINES += GP_NO_PLATFORM
CONFIG(debug, debug|release): DEFINES += _DEBUG

SOURCES += src/AbsoluteLayout.cpp \
src/AIAgent.cpp \
Expand Down Expand Up @@ -548,18 +547,19 @@ linux: INCLUDEPATH += /usr/include/harfbuzz

macx: OBJECTIVE_SOURCES += src/PlatformMacOSX.mm
macx: OBJECTIVE_SOURCES += src/gameplay-main-macosx.mm
macx: QMAKE_CXXFLAGS += -x c++ -stdlib=libc++ -w -arch x86_64
macx: QMAKE_OBJECTIVE_CFLAGS += -x objective-c++ -stdlib=libc++ -w -arch x86_64
macx: QMAKE_CXXFLAGS += -x c++ -x objective-c++ -stdlib=libc++ -w -arch x86_64
macx: LIBS += -F/System/Library/Frameworks -framework GameKit
macx: LIBS += -F/System/Library/Frameworks -framework IOKit
macx: LIBS += -F/System/Library/Frameworks -framework QuartzCore
macx: LIBS += -F/System/Library/Frameworks -framework OpenAL
macx: LIBS += -F/System/Library/Frameworks -framework OpenGL
macx: LIBS += -F/System/Library/Frameworks -framework Cocoa
macx: LIBS += -F/System/Library/Frameworks -framework Foundation

win32: SOURCES += src/PlatformWindows.cpp
win32: SOURCES += src/gameplay-main-windows.cpp
win32: DEFINES += WIN32 _UNICODE UNICODE
win32: INCLUDEPATH += $$(DXSDK_DIR)Include
win32: INCLUDEPATH += $$(DXSDK_DIR)/Include
win32: QMAKE_CXXFLAGS_WARN_ON -= -w34100
win32: QMAKE_CXXFLAGS_WARN_ON -= -w34189
win32: QMAKE_CXXFLAGS_WARN_ON -= -w4302
15 changes: 13 additions & 2 deletions gameplay/src/Mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,6 @@ bool Mesh::isDynamic() const
return _dynamic;
}


Mesh::PrimitiveType Mesh::getPrimitiveType() const
{
return _primitiveType;
Expand All @@ -262,7 +261,19 @@ void Mesh::setPrimitiveType(PrimitiveType type)
_primitiveType = type;
}

void Mesh::setVertexData(const float* vertexData, unsigned int vertexStart, unsigned int vertexCount)
void* Mesh::mapVertexBuffer(MapAccess access)
{
GL_ASSERT( glBindBuffer(GL_ARRAY_BUFFER, _vertexBuffer) );

return (void*)glMapBuffer(GL_ARRAY_BUFFER, access);
}

bool Mesh::unmapVertexBuffer()
{
return glUnmapBuffer(GL_ARRAY_BUFFER);
}

void Mesh::setVertexData(const void* vertexData, unsigned int vertexStart, unsigned int vertexCount)
{
GL_ASSERT( glBindBuffer(GL_ARRAY_BUFFER, _vertexBuffer) );

Expand Down
45 changes: 44 additions & 1 deletion gameplay/src/Mesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,16 @@ class Mesh : public Ref
POINTS = GL_POINTS
};

/**
* Defines mapping access/usage.
*/
enum MapAccess
{
MAP_READ_ONLY = GL_READ_ONLY,
MAP_WRITE_ONLY = GL_WRITE_ONLY,
MAP_READ_WRITE = GL_READ_WRITE
};

/**
* Constructs a new mesh with the specified vertex format.
*
Expand Down Expand Up @@ -200,14 +210,47 @@ class Mesh : public Ref
*/
void setPrimitiveType(Mesh::PrimitiveType type);

/**
* Maps the vertex buffer for the specified access.
*
* Mapping vertex data causes a synchronizing issue. To avoid gpu idle
* If GPU is still working with the buffer object, mapVertexBuffer will not
* return until GPU finishes its job with the corresponding buffer object.
*
* To avoid waiting (idle), you can call first setVertexBuffer with NULL pointer,
* then call mapVertexBuffer(). In this case, the previous data will be discarded
* and mapVertexBuffer() returns a new allocated pointer immediately even if GPU is
* still working with the previous data.
*
* However, this method is valid only if you want to update entire data set because
* you discard the previous data. If you want to change only portion of data or to
* read data, you better not release the previous data.
*
* After modifying the data of VBO, it must be unmapped the buffer object from the client's
* memory. unmapVertexBuffer returns true if success. When it returns false, the contents of
* vertex buffer become corrupted while the buffer was mapped. The corruption results from screen
* resolution change or window system specific events. In this case, the data must be resubmitted.
*
* @param access The access for which the data can be use. Ex. read, write, read_write.
* @return The mapped vertex buffer
*/
void* mapVertexBuffer(Mesh::MapAccess access);

/**
* Unmaps the vertex buffer.
*
* @return false if unmapping buffer was unsuccessful
*/
bool unmapVertexBuffer();

/**
* Sets the specified vertex data into the mapped vertex buffer.
*
* @param vertexData The vertex data to be set.
* @param vertexStart The index of the starting vertex (0 by default).
* @param vertexCount The number of vertices to be set (default is 0, for all vertices).
*/
void setVertexData(const float* vertexData, unsigned int vertexStart = 0, unsigned int vertexCount = 0);
void setVertexData(const void* vertexData, unsigned int vertexStart = 0, unsigned int vertexCount = 0);

/**
* Creates and adds a new part of primitive data defining how the vertices are connected.
Expand Down
16 changes: 14 additions & 2 deletions gameplay/src/MeshPart.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,16 @@ IndexBufferHandle MeshPart::getIndexBuffer() const
return _indexBuffer;
}

bool MeshPart::isDynamic() const
void* MeshPart::mapIndexBuffer(Mesh::MapAccess access)
{
return _dynamic;
GL_ASSERT( glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _indexBuffer) );

return (void*)glMapBuffer(GL_ELEMENT_ARRAY_BUFFER, access);
}

bool MeshPart::unmapIndexBuffer()
{
return glUnmapBuffer(GL_ELEMENT_ARRAY_BUFFER);
}

void MeshPart::setIndexData(const void* indexData, unsigned int indexStart, unsigned int indexCount)
Expand Down Expand Up @@ -123,4 +130,9 @@ void MeshPart::setIndexData(const void* indexData, unsigned int indexStart, unsi
}
}

bool MeshPart::isDynamic() const
{
return _dynamic;
}

}
39 changes: 36 additions & 3 deletions gameplay/src/MeshPart.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,37 @@ class MeshPart
IndexBufferHandle getIndexBuffer() const;

/**
* Determines if the indices are dynamic.
* Maps the index buffer for the specified access.
*
* @return true if the part is dynamic; false otherwise.
* Mapping index data causes a synchronizing issue. To avoid gpu idle
* If GPU is still working with the buffer object, mapIndexBuffer will not
* return until GPU finishes its job with the corresponding buffer object.
*
* To avoid waiting (idle), you can call first setIndexData with NULL pointer,
* then call mapIndexBuffer(). In this case, the previous data will be discarded
* and mapIndexData() returns a new allocated pointer immediately even if GPU is
* still working with the previous data.
*
* However, this method is valid only if you want to update entire data set because
* you discard the previous data. If you want to change only portion of data or to
* read data, you better not release the previous data.
*
* After modifying the data of VBO, it must be unmapped the buffer object from the client's
* memory. unmapIndexBuffer returns true if success. When it returns false, the contents of
* index buffer become corrupted while the buffer was mapped. The corruption results from screen
* resolution change or window system specific events. In this case, the data must be resubmitted.
*
* @param access The access for which the data can be use. Ex. read, write, read_write.
* @return The mapped index buffer
*/
bool isDynamic() const;
void* mapIndexBuffer(Mesh::MapAccess access);

/**
* Unmaps the index buffer.
*
* @return false if unmapping buffer was unsuccessful
*/
bool unmapIndexBuffer();

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

/**
* Determines if the indices are dynamic.
*
* @return true if the part is dynamic; false otherwise.
*/
bool isDynamic() const;

private:

/**
Expand Down
23 changes: 12 additions & 11 deletions gameplay/src/Properties.h
Original file line number Diff line number Diff line change
Expand Up @@ -524,11 +524,13 @@ class Properties
Properties();

/**
* Constructs the Properties class from a file.
*
* @param stream The stream used for reading the properties from file.
* Constructor.
*/
Properties(Stream* stream);

/**
* Constructor.
*/
Properties(const Properties& copy);

/**
Expand All @@ -538,21 +540,20 @@ class Properties

void readProperties(Stream* stream);

void setDirectoryPath(const std::string* path);

void setDirectoryPath(const std::string& path);

void skipWhiteSpace(Stream* stream);

char* trimWhiteSpace(char* str);

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

// Called by resolveInheritance().
void mergeWith(Properties* overrides);

// Clones the Properties object.
Properties* clone();

void setDirectoryPath(const std::string* path);
void setDirectoryPath(const std::string& path);
// Called after create(); copies info from parents into derived namespaces.
void resolveInheritance(const char* id = NULL);

std::string _namespace;
std::string _id;
Expand Down
6 changes: 4 additions & 2 deletions samples/browser/sample-browser.pro
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ TARGET = sample-browser
TEMPLATE = app
CONFIG += c++11
CONFIG -= qt
CONFIG(debug, debug|release): DEFINES += _DEBUG

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

macx: QMAKE_CXXFLAGS += -x c++ -stdlib=libc++ -w -arch x86_64
macx: QMAKE_OBJECTIVE_CFLAGS += -x objective-c++ -stdlib=libc++ -w -arch x86_64
macx: QMAKE_CXXFLAGS += -x c++ -x objective-c++ -stdlib=libc++ -w -arch x86_64
macx: LIBS += -L$$PWD/../../gameplay/Debug/ -lgameplay
macx: LIBS += -L$$PWD/../../external-deps/lib/macosx/x86_64/ -lgameplay-deps
macx: LIBS += -F/System/Library/Frameworks -framework GameKit
Expand All @@ -99,6 +99,7 @@ macx: LIBS += -F/System/Library/Frameworks -framework QuartzCore
macx: LIBS += -F/System/Library/Frameworks -framework OpenAL
macx: LIBS += -F/System/Library/Frameworks -framework OpenGL
macx: LIBS += -F/System/Library/Frameworks -framework Cocoa
macx: LIBS += -F/System/Library/Frameworks -framework Foundation
macx: QMAKE_POST_LINK += $$quote(rsync -rau $$PWD/../../gameplay/res/shaders ../res$$escape_expand(\n\t))
macx: QMAKE_POST_LINK += $$quote(rsync -rau $$PWD/../../gameplay/res/ui ../res$$escape_expand(\n\t))
macx: QMAKE_POST_LINK += $$quote(cp -rf $$PWD/../../gameplay/res/logo_powered_white.png ../res$$escape_expand(\n\t))
Expand Down Expand Up @@ -128,6 +129,7 @@ win32: LIBS += -L$$(DXSDK_DIR)Lib\x64 -lXInput
win32: INCLUDEPATH += $$(DXSDK_DIR)Include
win32: QMAKE_CXXFLAGS_WARN_ON -= -w34100
win32: QMAKE_CXXFLAGS_WARN_ON -= -w34189
win32: QMAKE_CXXFLAGS_WARN_ON -= -w4302
win32: QMAKE_POST_LINK += $$quote(xcopy ..\..\..\gameplay\res\shaders res\shaders\* /s /y /d$$escape_expand(\n\t))
win32: QMAKE_POST_LINK += $$quote(xcopy ..\..\..\gameplay\res\ui res\ui\* /s /y /d$$escape_expand(\n\t))
win32: QMAKE_POST_LINK += $$quote(copy ..\..\..\gameplay\res\logo_powered_white.png res$$escape_expand(\n\t))
2 changes: 1 addition & 1 deletion samples/browser/src/GestureSample.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ void GestureSample::initialize()
registerGesture(Gesture::GESTURE_DROP);
GP_ASSERT(isGestureRegistered(Gesture::GESTURE_DROP));
}
GP_ASSERT(anySupported == isGestureSupported(Gesture::GESTURE_ANY_SUPPORTED));
//GP_ASSERT(anySupported == isGestureSupported(Gesture::GESTURE_ANY_SUPPORTED));
}

void GestureSample::finalize()
Expand Down
8 changes: 5 additions & 3 deletions samples/character/sample-character.pro
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ TARGET = sample-character
TEMPLATE = app
CONFIG += c++11
CONFIG -= qt
CONFIG(debug, debug|release): DEFINES += _DEBUG

SOURCES += src/CharacterGame.cpp

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

macx: QMAKE_CXXFLAGS += -x c++ -stdlib=libc++ -w -arch x86_64
macx: QMAKE_OBJECTIVE_CFLAGS += -x objective-c++ -stdlib=libc++ -w -arch x86_64
macx: QMAKE_CXXFLAGS += -x c++ -x objective-c++ -stdlib=libc++ -w -arch x86_64
macx: LIBS += -L$$PWD/../../gameplay/Debug/ -lgameplay
macx: LIBS += -L$$PWD/../../external-deps/lib/macosx/x86_64/ -lgameplay-deps
macx: LIBS += -F/System/Library/Frameworks -framework GameKit
Expand All @@ -50,7 +50,8 @@ macx: LIBS += -F/System/Library/Frameworks -framework QuartzCore
macx: LIBS += -F/System/Library/Frameworks -framework OpenAL
macx: LIBS += -F/System/Library/Frameworks -framework OpenGL
macx: LIBS += -F/System/Library/Frameworks -framework Cocoa
macx: QMAKE_ += $$quote(rsync -rau $$PWD/../../gameplay/res/shaders ../res$$escape_expand(\n\t))
macx: LIBS += -F/System/Library/Frameworks -framework Foundation
macx: QMAKE_POST_LINK += $$quote(rsync -rau $$PWD/../../gameplay/res/shaders ../res$$escape_expand(\n\t))
macx: QMAKE_POST_LINK += $$quote(rsync -rau $$PWD/../../gameplay/res/ui ../res$$escape_expand(\n\t))
macx: QMAKE_POST_LINK += $$quote(cp -rf $$PWD/../../gameplay/res/logo_powered_white.png ../res$$escape_expand(\n\t))
macx
Expand Down Expand Up @@ -78,6 +79,7 @@ win32: LIBS += -L$$(DXSDK_DIR)Lib\x64 -lXInput
win32: INCLUDEPATH += $$(DXSDK_DIR)Include
win32: QMAKE_CXXFLAGS_WARN_ON -= -w34100
win32: QMAKE_CXXFLAGS_WARN_ON -= -w34189
win32: QMAKE_CXXFLAGS_WARN_ON -= -w4302
win32: QMAKE_POST_LINK += $$quote(xcopy ..\..\..\gameplay\res\shaders res\shaders\* /s /y /d$$escape_expand(\n\t))
win32: QMAKE_POST_LINK += $$quote(xcopy ..\..\..\gameplay\res\ui res\ui\* /s /y /d$$escape_expand(\n\t))
win32: QMAKE_POST_LINK += $$quote(copy ..\..\..\gameplay\res\logo_powered_white.png res$$escape_expand(\n\t))
Expand Down
6 changes: 4 additions & 2 deletions samples/racer/sample-racer.pro
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ TARGET = sample-racer
TEMPLATE = app
CONFIG += c++11
CONFIG -= qt
CONFIG(debug, debug|release): DEFINES += _DEBUG

SOURCES += src/RacerGame.cpp

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

macx: QMAKE_CXXFLAGS += -x c++ -stdlib=libc++ -w -arch x86_64
macx: QMAKE_OBJECTIVE_CFLAGS += -x objective-c++ -stdlib=libc++ -w -arch x86_64
macx: QMAKE_CXXFLAGS += -x c++ -x objective-c++ -stdlib=libc++ -w -arch x86_64
macx: LIBS += -L$$PWD/../../gameplay/Debug/ -lgameplay
macx: LIBS += -L$$PWD/../../external-deps/lib/macosx/x86_64/ -lgameplay-deps
macx: LIBS += -F/System/Library/Frameworks -framework GameKit
Expand All @@ -50,6 +50,7 @@ macx: LIBS += -F/System/Library/Frameworks -framework QuartzCore
macx: LIBS += -F/System/Library/Frameworks -framework OpenAL
macx: LIBS += -F/System/Library/Frameworks -framework OpenGL
macx: LIBS += -F/System/Library/Frameworks -framework Cocoa
macx: LIBS += -F/System/Library/Frameworks -framework Foundation
macx: QMAKE_POST_LINK += $$quote(rsync -rau $$PWD/../../gameplay/res/shaders ../res$$escape_expand(\n\t))
macx: QMAKE_POST_LINK += $$quote(rsync -rau $$PWD/../../gameplay/res/ui ../res$$escape_expand(\n\t))
macx: QMAKE_POST_LINK += $$quote(cp -rf $$PWD/../../gameplay/res/logo_powered_white.png ../res$$escape_expand(\n\t))
Expand Down Expand Up @@ -78,6 +79,7 @@ win32: LIBS += -L$$(DXSDK_DIR)Lib\x64 -lXInput
win32: INCLUDEPATH += $$(DXSDK_DIR)Include
win32: QMAKE_CXXFLAGS_WARN_ON -= -w34100
win32: QMAKE_CXXFLAGS_WARN_ON -= -w34189
win32: QMAKE_CXXFLAGS_WARN_ON -= -w4302
win32: QMAKE_POST_LINK += $$quote(xcopy ..\..\..\gameplay\res\shaders res\shaders\* /s /y /d$$escape_expand(\n\t))
win32: QMAKE_POST_LINK += $$quote(xcopy ..\..\..\gameplay\res\ui res\ui\* /s /y /d$$escape_expand(\n\t))
win32: QMAKE_POST_LINK += $$quote(copy ..\..\..\gameplay\res\logo_powered_white.png res$$escape_expand(\n\t))
Expand Down
Loading

0 comments on commit 8710b24

Please sign in to comment.