Experimenting with GUI in PairBench, still preliminary. Goal is to make it easier to add variables that can be tuned using GUI/gwen
Pre-compile PairBench OpenCL kernel
This commit is contained in:
@@ -13,94 +13,45 @@
|
||||
#include "Bullet3OpenCL/ParallelPrimitives/b3LauncherCL.h"
|
||||
#include "../../../btgui/Timing/b3Quickprof.h"
|
||||
#include "../gwenUserInterface.h"
|
||||
#include "../GwenInternalData.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "pairsKernel.h"
|
||||
|
||||
static b3KeyboardCallback oldCallback = 0;
|
||||
|
||||
char* gPairBenchFileName = 0;
|
||||
|
||||
extern bool useShadowMap;
|
||||
float maxExtents = -1e30f;
|
||||
int largeCount = 0;
|
||||
|
||||
float timeStepPos = 0.000166666;
|
||||
float mAmplitude = 251.f;
|
||||
int dimensions[3]={10,10,10};
|
||||
const char* axisNames[3] = {"# x-axis","# y-axis","# z-axis"};
|
||||
extern bool gReset;
|
||||
|
||||
#define MSTRINGIFY(A) #A
|
||||
|
||||
static const char* s_pairBenchKernelString = MSTRINGIFY(
|
||||
__kernel void moveObjectsKernel(__global float4* posOrnColors, int numObjects)
|
||||
struct BroadphaseEntry
|
||||
{
|
||||
int iGID = get_global_id(0);
|
||||
if (iGID>=numObjects)
|
||||
return;
|
||||
__global float4* positions = &posOrnColors[0];
|
||||
if (iGID<0.5*numObjects)
|
||||
{
|
||||
positions[iGID].y +=0.01f;
|
||||
}
|
||||
__global float4* colors = &posOrnColors[numObjects*2];
|
||||
colors[iGID] = (float4)(0,0,1,1);
|
||||
}
|
||||
const char* m_name;
|
||||
b3GpuBroadphaseInterface::CreateFunc* m_createFunc;
|
||||
};
|
||||
|
||||
__kernel void colorPairsKernel(__global float4* posOrnColors, int numObjects, __global const int4* pairs, int numPairs)
|
||||
|
||||
|
||||
static PairBench* sPairDemo = 0;
|
||||
|
||||
#define BP_COMBO_INDEX 123
|
||||
|
||||
static int curSelectedBroadphase = 0;
|
||||
static BroadphaseEntry allBroadphases[]=
|
||||
{
|
||||
int iPairId = get_global_id(0);
|
||||
if (iPairId>=numPairs)
|
||||
return;
|
||||
__global float4* colors = &posOrnColors[numObjects*2];
|
||||
|
||||
int iObjectA = pairs[iPairId].x;
|
||||
int iObjectB = pairs[iPairId].y;
|
||||
colors[iObjectA] = (float4)(1,0,0,1);
|
||||
colors[iObjectB] = (float4)(1,0,0,1);
|
||||
}
|
||||
|
||||
__kernel void
|
||||
sineWaveKernel( __global float4* posOrnColors, __global float* pBodyTimes,const int numNodes)
|
||||
{
|
||||
int nodeID = get_global_id(0);
|
||||
float timeStepPos = 0.000166666;
|
||||
float mAmplitude = 51.f;
|
||||
if( nodeID < numNodes )
|
||||
{
|
||||
pBodyTimes[nodeID] += timeStepPos;
|
||||
float4 position = posOrnColors[nodeID];
|
||||
position.x = native_cos(pBodyTimes[nodeID]*2.17f)*mAmplitude + native_sin(pBodyTimes[nodeID])*mAmplitude*0.5f;
|
||||
position.y = native_cos(pBodyTimes[nodeID]*1.38f)*mAmplitude + native_sin(pBodyTimes[nodeID]*mAmplitude);
|
||||
position.z = native_cos(pBodyTimes[nodeID]*2.17f)*mAmplitude + native_sin(pBodyTimes[nodeID]*0.777f)*mAmplitude;
|
||||
|
||||
posOrnColors[nodeID] = position;
|
||||
__global float4* colors = &posOrnColors[numNodes*2];
|
||||
colors[nodeID] = (float4)(0,0,1,1);
|
||||
}
|
||||
}
|
||||
|
||||
typedef struct
|
||||
{
|
||||
float fx;
|
||||
float fy;
|
||||
float fz;
|
||||
int uw;
|
||||
} b3AABBCL;
|
||||
|
||||
__kernel void updateAabbSimple( __global float4* posOrnColors, const int numNodes, __global b3AABBCL* pAABB)
|
||||
{
|
||||
int nodeId = get_global_id(0);
|
||||
if( nodeId < numNodes )
|
||||
{
|
||||
float4 position = posOrnColors[nodeId];
|
||||
float4 halfExtents = (float4)(1.01f,1.01f,1.01f,0.f);
|
||||
pAABB[nodeId*2].fx = position.x-halfExtents.x;
|
||||
pAABB[nodeId*2].fy = position.y-halfExtents.y;
|
||||
pAABB[nodeId*2].fz = position.z-halfExtents.z;
|
||||
pAABB[nodeId*2].uw = nodeId;
|
||||
pAABB[nodeId*2+1].fx = position.x+halfExtents.x;
|
||||
pAABB[nodeId*2+1].fy = position.y+halfExtents.y;
|
||||
pAABB[nodeId*2+1].fz = position.z+halfExtents.z;
|
||||
pAABB[nodeId*2+1].uw = nodeId;
|
||||
}
|
||||
}
|
||||
|
||||
);
|
||||
{"Gpu Grid",b3GpuGridBroadphase::CreateFunc},
|
||||
{"Gpu 1-Sap",b3GpuSapBroadphase::CreateFunc},
|
||||
|
||||
};
|
||||
|
||||
|
||||
struct PairBenchInternalData
|
||||
@@ -126,6 +77,10 @@ struct PairBenchInternalData
|
||||
m_updateAabbSimple(0)
|
||||
{
|
||||
}
|
||||
|
||||
int m_oldYposition;
|
||||
|
||||
b3AlignedObjectArray<Gwen::Controls::Base*> m_myControls;
|
||||
};
|
||||
|
||||
|
||||
@@ -165,27 +120,215 @@ static inline float parseFloat(const char*& token)
|
||||
return f;
|
||||
}
|
||||
|
||||
extern bool useShadowMap;
|
||||
enum PairToggleButtons
|
||||
{
|
||||
MY_RESET = 1024,
|
||||
};
|
||||
|
||||
|
||||
#define PAIRS_CL_PROGRAM_PATH "Demos3/GpuDemos/broadphase/pairsKernel.cl"
|
||||
|
||||
|
||||
|
||||
|
||||
struct PairComboBoxHander :public Gwen::Event::Handler
|
||||
{
|
||||
|
||||
int m_buttonId;
|
||||
int m_active;
|
||||
|
||||
PairComboBoxHander (int buttonId)
|
||||
:m_buttonId(buttonId),
|
||||
m_active(false)
|
||||
{
|
||||
}
|
||||
|
||||
void onSelect( Gwen::Controls::Base* pControl )
|
||||
{
|
||||
if (m_active)
|
||||
{
|
||||
Gwen::Controls::ComboBox* but = (Gwen::Controls::ComboBox*) pControl;
|
||||
|
||||
Gwen::String str = Gwen::Utility::UnicodeToString( but->GetSelectedItem()->GetText());
|
||||
|
||||
int numItems = sizeof(allBroadphases)/sizeof(BroadphaseEntry);
|
||||
|
||||
//find selected item
|
||||
for (int i=0;i<numItems;i++)
|
||||
{
|
||||
if (strcmp(str.c_str(),allBroadphases[i].m_name)==0)
|
||||
{
|
||||
curSelectedBroadphase=i;
|
||||
sPairDemo->deleteBroadphase();
|
||||
sPairDemo->createBroadphase(dimensions[0],dimensions[1],dimensions[2]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
template<typename T>
|
||||
struct MySliderEventHandler : public Gwen::Event::Handler
|
||||
{
|
||||
Gwen::Controls::TextBox* m_label;
|
||||
char m_variableName[1024];
|
||||
T* m_targetValue;
|
||||
|
||||
MySliderEventHandler(const char* varName, Gwen::Controls::TextBox* label, T* target)
|
||||
:m_label(label),
|
||||
m_targetValue(target)
|
||||
{
|
||||
memcpy(m_variableName,varName,strlen(varName)+1);
|
||||
}
|
||||
|
||||
|
||||
void SliderMoved( Gwen::Controls::Base* pControl )
|
||||
{
|
||||
Gwen::Controls::Slider* pSlider = (Gwen::Controls::Slider*)pControl;
|
||||
//printf("value = %f\n", pSlider->GetValue());//UnitPrint( Utility::Format( L"Slider Value: %.2f", pSlider->GetValue() ) );
|
||||
char txt[1024];
|
||||
T v = T(pSlider->GetValue());
|
||||
|
||||
(*m_targetValue) = v;
|
||||
int val = int(v);//todo: specialize on template type
|
||||
sprintf(txt,"%s : %d", m_variableName,val);
|
||||
m_label->SetText(txt);
|
||||
}
|
||||
};
|
||||
|
||||
void PairBench::initPhysics(const ConstructionInfo& ci)
|
||||
{
|
||||
|
||||
m_instancingRenderer = ci.m_instancingRenderer;
|
||||
sPairDemo = this;
|
||||
useShadowMap = false;
|
||||
|
||||
m_data->m_gui = ci.m_gui;
|
||||
|
||||
//remember the old position in the GUI, to restore at exit
|
||||
|
||||
GwenInternalData* data = m_data->m_gui->getInternalData();
|
||||
m_data->m_oldYposition = data->m_curYposition;
|
||||
|
||||
|
||||
|
||||
data->m_curYposition+=40;
|
||||
|
||||
{
|
||||
|
||||
|
||||
int startItem = 0;
|
||||
int numBroadphases = sizeof(allBroadphases)/sizeof(BroadphaseEntry);
|
||||
|
||||
Gwen::Controls::ComboBox* combobox = new Gwen::Controls::ComboBox(data->m_demoPage->GetPage());
|
||||
PairComboBoxHander* handler = new PairComboBoxHander(555);
|
||||
m_data->m_myControls.push_back(combobox);
|
||||
|
||||
|
||||
combobox->onSelection.Add(handler,&PairComboBoxHander::onSelect);
|
||||
int ypos = data->m_curYposition;
|
||||
combobox->SetPos(10, ypos );
|
||||
combobox->SetWidth( 100 );
|
||||
|
||||
|
||||
for (int i=0;i<numBroadphases;i++)
|
||||
{
|
||||
Gwen::Controls::MenuItem* item = combobox->AddItem(Gwen::Utility::StringToUnicode(allBroadphases[i].m_name));
|
||||
if (i==startItem)
|
||||
combobox->OnItemSelected(item);
|
||||
}
|
||||
|
||||
handler->m_active = true;
|
||||
|
||||
data->m_curYposition+=22;
|
||||
}
|
||||
|
||||
if (1)
|
||||
for (int i=0;i<3;i++)
|
||||
{
|
||||
{
|
||||
Gwen::Controls::TextBox* label = new Gwen::Controls::TextBox(data->m_demoPage->GetPage());
|
||||
m_data->m_myControls.push_back(label);
|
||||
label->SetText( "Text Label" );
|
||||
label->SetPos( 10, 10 + 25 );
|
||||
label->SetWidth(100);
|
||||
label->SetPos(10,data->m_curYposition);
|
||||
data->m_curYposition+=22;
|
||||
|
||||
Gwen::Controls::HorizontalSlider* pSlider = new Gwen::Controls::HorizontalSlider( data->m_demoPage->GetPage());
|
||||
m_data->m_myControls.push_back(pSlider);
|
||||
pSlider->SetPos( 10, data->m_curYposition );
|
||||
pSlider->SetSize( 100, 20 );
|
||||
pSlider->SetRange( 0, 100 );
|
||||
pSlider->SetValue( dimensions[i] );
|
||||
char labelName[1024];
|
||||
sprintf(labelName,"%s",axisNames[0]);
|
||||
MySliderEventHandler<int>* handler = new MySliderEventHandler<int>(labelName,label,&dimensions[i]);
|
||||
pSlider->onValueChanged.Add( handler, &MySliderEventHandler<int>::SliderMoved );
|
||||
handler->SliderMoved(pSlider);
|
||||
float v = pSlider->GetValue();
|
||||
data->m_curYposition+=22;
|
||||
}
|
||||
}
|
||||
if (1)
|
||||
{
|
||||
{
|
||||
Gwen::Controls::TextBox* label = new Gwen::Controls::TextBox(data->m_demoPage->GetPage());
|
||||
m_data->m_myControls.push_back(label);
|
||||
const char* labelName = "Scale: ";
|
||||
label->SetText( labelName);
|
||||
label->SetPos( 10, 10 + 25 );
|
||||
label->SetWidth(100);
|
||||
label->SetPos(10,data->m_curYposition);
|
||||
data->m_curYposition+=22;
|
||||
|
||||
Gwen::Controls::HorizontalSlider* pSlider = new Gwen::Controls::HorizontalSlider( data->m_demoPage->GetPage());
|
||||
m_data->m_myControls.push_back(pSlider);
|
||||
pSlider->SetPos( 10, data->m_curYposition );
|
||||
pSlider->SetSize( 100, 20 );
|
||||
pSlider->SetRange( 0, 300);
|
||||
pSlider->SetValue( mAmplitude );
|
||||
|
||||
MySliderEventHandler<float>* handler = new MySliderEventHandler<float>(labelName,label,&mAmplitude);
|
||||
pSlider->onValueChanged.Add( handler, &MySliderEventHandler<float>::SliderMoved );
|
||||
handler->SliderMoved(pSlider);
|
||||
float v = pSlider->GetValue();
|
||||
data->m_curYposition+=22;
|
||||
}
|
||||
}
|
||||
//pSlider->onValueChanged.Add( this, &Slider::SliderMoved );
|
||||
|
||||
|
||||
data->m_curYposition+=22;
|
||||
|
||||
/*m_data->m_gui->registerToggleButton(MY_RESET,"reset");
|
||||
sOldCallback = m_data->m_gui->getToggleButtonCallback();
|
||||
m_data->m_gui->setToggleButtonCallback(PairButtonCallback);
|
||||
*/
|
||||
|
||||
int startItem = 0;
|
||||
//m_data->m_gui->registerComboBox(BP_COMBO_INDEX,numBroadphases,&mydemonames[0],startItem);
|
||||
|
||||
//sOldComboCallback = m_data->m_gui->getComboBoxCallback();
|
||||
|
||||
//m_data->m_gui->setComboBoxCallback(PairComboBoxCallback);
|
||||
|
||||
|
||||
initCL(ci.preferredOpenCLDeviceIndex,ci.preferredOpenCLPlatformIndex);
|
||||
|
||||
if (m_clData->m_clContext)
|
||||
{
|
||||
m_data->m_broadphaseGPU = new b3GpuSapBroadphase(m_clData->m_clContext,m_clData->m_clDevice,m_clData->m_clQueue);
|
||||
//m_data->m_broadphaseGPU = new b3GpuGridBroadphase(m_clData->m_clContext,m_clData->m_clDevice,m_clData->m_clQueue);
|
||||
|
||||
cl_program pairBenchProg=0;
|
||||
cl_int err;
|
||||
cl_program pairBenchProg=b3OpenCLUtils::compileCLProgramFromString(m_clData->m_clContext,m_clData->m_clDevice,pairsKernelsCL,&err,"",PAIRS_CL_PROGRAM_PATH);
|
||||
int errNum=0;
|
||||
m_data->m_moveObjectsKernel = b3OpenCLUtils::compileCLKernelFromString(m_clData->m_clContext,m_clData->m_clDevice,s_pairBenchKernelString,"moveObjectsKernel",&errNum,pairBenchProg);
|
||||
m_data->m_sineWaveKernel = b3OpenCLUtils::compileCLKernelFromString(m_clData->m_clContext,m_clData->m_clDevice,s_pairBenchKernelString,"sineWaveKernel",&errNum,pairBenchProg);
|
||||
m_data->m_colorPairsKernel = b3OpenCLUtils::compileCLKernelFromString(m_clData->m_clContext,m_clData->m_clDevice,s_pairBenchKernelString,"colorPairsKernel",&errNum,pairBenchProg);
|
||||
m_data->m_updateAabbSimple = b3OpenCLUtils::compileCLKernelFromString(m_clData->m_clContext,m_clData->m_clDevice,s_pairBenchKernelString,"updateAabbSimple",&errNum,pairBenchProg);
|
||||
m_data->m_moveObjectsKernel = b3OpenCLUtils::compileCLKernelFromString(m_clData->m_clContext,m_clData->m_clDevice,pairsKernelsCL,"moveObjectsKernel",&errNum,pairBenchProg);
|
||||
m_data->m_sineWaveKernel = b3OpenCLUtils::compileCLKernelFromString(m_clData->m_clContext,m_clData->m_clDevice,pairsKernelsCL,"sineWaveKernel",&errNum,pairBenchProg);
|
||||
m_data->m_colorPairsKernel = b3OpenCLUtils::compileCLKernelFromString(m_clData->m_clContext,m_clData->m_clDevice,pairsKernelsCL,"colorPairsKernel",&errNum,pairBenchProg);
|
||||
m_data->m_updateAabbSimple = b3OpenCLUtils::compileCLKernelFromString(m_clData->m_clContext,m_clData->m_clDevice,pairsKernelsCL,"updateAabbSimple",&errNum,pairBenchProg);
|
||||
|
||||
}
|
||||
|
||||
@@ -197,16 +340,26 @@ void PairBench::initPhysics(const ConstructionInfo& ci)
|
||||
|
||||
}
|
||||
|
||||
m_instancingRenderer = ci.m_instancingRenderer;
|
||||
|
||||
|
||||
#ifndef B3_NO_PROFILE
|
||||
b3ProfileManager::CleanupMemory();
|
||||
#endif //B3_NO_PROFILE
|
||||
|
||||
createBroadphase(ci.arraySizeX,ci.arraySizeY,ci.arraySizeZ);
|
||||
|
||||
}
|
||||
|
||||
void PairBench::createBroadphase(int arraySizeX, int arraySizeY, int arraySizeZ)
|
||||
{
|
||||
|
||||
|
||||
m_data->m_broadphaseGPU = (allBroadphases[curSelectedBroadphase].m_createFunc)(m_clData->m_clContext,m_clData->m_clDevice,m_clData->m_clQueue);
|
||||
|
||||
int strideInBytes = 9*sizeof(float);
|
||||
int numVertices = sizeof(cube_vertices)/strideInBytes;
|
||||
int numIndices = sizeof(cube_vertices)/sizeof(int);
|
||||
int shapeId = ci.m_instancingRenderer->registerShape(&cube_vertices[0],numVertices,cube_indices,numIndices);
|
||||
int shapeId = m_instancingRenderer->registerShape(&cube_vertices[0],numVertices,cube_indices,numIndices);
|
||||
int group=1;
|
||||
int mask=1;
|
||||
int index=10;
|
||||
@@ -294,12 +447,12 @@ void PairBench::initPhysics(const ConstructionInfo& ci)
|
||||
if (l>500)
|
||||
{
|
||||
b3Vector4 color=b3MakeVector4(0,1,0,0.1);
|
||||
int id = ci.m_instancingRenderer->registerGraphicsInstance(shapeId,position,orn,color,scaling);
|
||||
int id = m_instancingRenderer->registerGraphicsInstance(shapeId,position,orn,color,scaling);
|
||||
m_data->m_broadphaseGPU->createLargeProxy(aabbMin,aabbMax,index,group,mask);
|
||||
} else
|
||||
{
|
||||
b3Vector4 color=b3MakeVector4(1,0,0,1);
|
||||
int id = ci.m_instancingRenderer->registerGraphicsInstance(shapeId,position,orn,color,scaling);
|
||||
int id = m_instancingRenderer->registerGraphicsInstance(shapeId,position,orn,color,scaling);
|
||||
m_data->m_broadphaseGPU->createProxy(aabbMin,aabbMax,index,group,mask);
|
||||
index++;
|
||||
}
|
||||
@@ -327,18 +480,18 @@ void PairBench::initPhysics(const ConstructionInfo& ci)
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i=0;i<ci.arraySizeX;i++)
|
||||
for (int i=0;i<arraySizeX;i++)
|
||||
{
|
||||
for (int j=0;j<ci.arraySizeY;j++)
|
||||
for (int j=0;j<arraySizeY;j++)
|
||||
{
|
||||
for (int k=0;k<ci.arraySizeZ;k++)
|
||||
for (int k=0;k<arraySizeZ;k++)
|
||||
{
|
||||
b3Vector3 position=b3MakeVector3(k*3,i*3,j*3);
|
||||
b3Quaternion orn(0,0,0,1);
|
||||
|
||||
b3Vector4 color=b3MakeVector4(0,1,0,1);
|
||||
b3Vector4 scaling=b3MakeVector4(1,1,1,1);
|
||||
int id = ci.m_instancingRenderer->registerGraphicsInstance(shapeId,position,orn,color,scaling);
|
||||
int id = m_instancingRenderer->registerGraphicsInstance(shapeId,position,orn,color,scaling);
|
||||
b3Vector3 aabbHalfExtents=b3MakeVector3(1,1,1);
|
||||
|
||||
b3Vector3 aabbMin = position-aabbHalfExtents;
|
||||
@@ -364,17 +517,37 @@ void PairBench::initPhysics(const ConstructionInfo& ci)
|
||||
|
||||
m_instancingRenderer->writeTransforms();
|
||||
m_data->m_broadphaseGPU->writeAabbsToGpu();
|
||||
|
||||
}
|
||||
|
||||
void PairBench::deleteBroadphase()
|
||||
{
|
||||
delete m_data->m_broadphaseGPU;
|
||||
m_data->m_broadphaseGPU = 0;
|
||||
delete m_data->m_instancePosOrnColor;
|
||||
m_data->m_instancePosOrnColor = 0;
|
||||
delete m_data->m_bodyTimes;
|
||||
m_data->m_bodyTimes = 0;
|
||||
|
||||
m_data->m_broadphaseGPU = 0;
|
||||
m_instancingRenderer->removeAllInstances();
|
||||
}
|
||||
|
||||
void PairBench::exitPhysics()
|
||||
{
|
||||
delete m_data->m_broadphaseGPU;
|
||||
delete m_data->m_instancePosOrnColor;
|
||||
delete m_data->m_bodyTimes;
|
||||
m_data->m_broadphaseGPU = 0;
|
||||
|
||||
m_data->m_gui->getInternalData()->m_curYposition = m_data->m_oldYposition;
|
||||
|
||||
for (int i=0;i<m_data->m_myControls.size();i++)
|
||||
{
|
||||
delete m_data->m_myControls[i];
|
||||
}
|
||||
|
||||
sPairDemo = 0;
|
||||
|
||||
m_window->setKeyboardCallback(oldCallback);
|
||||
exitCL();
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -434,6 +607,9 @@ void PairBench::clientMoveAndDisplay()
|
||||
b3LauncherCL launcher(m_clData->m_clQueue, m_data->m_sineWaveKernel,"m_sineWaveKernel");
|
||||
launcher.setBuffer(m_data->m_instancePosOrnColor->getBufferCL() );
|
||||
launcher.setBuffer(m_data->m_bodyTimes->getBufferCL() );
|
||||
|
||||
launcher.setConst(timeStepPos);
|
||||
launcher.setConst(mAmplitude);
|
||||
launcher.setConst( numObjects);
|
||||
launcher.launch1D( numObjects);
|
||||
clFinish(m_clData->m_clQueue);
|
||||
@@ -471,7 +647,8 @@ void PairBench::clientMoveAndDisplay()
|
||||
|
||||
|
||||
b3AlignedObjectArray<b3Vector4> posOrnColorsCpu;
|
||||
m_data->m_instancePosOrnColor->copyToHost(posOrnColorsCpu);
|
||||
if (m_data->m_instancePosOrnColor)
|
||||
m_data->m_instancePosOrnColor->copyToHost(posOrnColorsCpu);
|
||||
|
||||
|
||||
|
||||
@@ -502,8 +679,8 @@ void PairBench::clientMoveAndDisplay()
|
||||
int sz = sizeof(b3Int4)*64*numObjects;
|
||||
|
||||
m_data->m_broadphaseGPU->calculateOverlappingPairs(16*numObjects);
|
||||
//int numPairs = m_data->m_broadphaseGPU->getNumOverlap();
|
||||
//printf("numPairs = %d\n", numPairs);
|
||||
int numPairs = m_data->m_broadphaseGPU->getNumOverlap();
|
||||
printf("numPairs = %d\n", numPairs);
|
||||
dt = cl.getTimeMicroseconds()-dt;
|
||||
}
|
||||
|
||||
|
||||
@@ -11,15 +11,20 @@ class PairBench : public GpuDemo
|
||||
|
||||
struct PairBenchInternalData* m_data;
|
||||
|
||||
|
||||
|
||||
public:
|
||||
|
||||
PairBench();
|
||||
virtual ~PairBench();
|
||||
|
||||
virtual void initPhysics(const ConstructionInfo& ci);
|
||||
|
||||
virtual void exitPhysics();
|
||||
|
||||
|
||||
void createBroadphase(int xdim, int ydim, int zdim);
|
||||
void deleteBroadphase();
|
||||
|
||||
virtual const char* getName()
|
||||
{
|
||||
return "PairBench";
|
||||
|
||||
70
Demos3/GpuDemos/broadphase/pairsKernel.cl
Normal file
70
Demos3/GpuDemos/broadphase/pairsKernel.cl
Normal file
@@ -0,0 +1,70 @@
|
||||
__kernel void moveObjectsKernel(__global float4* posOrnColors, int numObjects)
|
||||
{
|
||||
int iGID = get_global_id(0);
|
||||
if (iGID>=numObjects)
|
||||
return;
|
||||
__global float4* positions = &posOrnColors[0];
|
||||
if (iGID<0.5*numObjects)
|
||||
{
|
||||
positions[iGID].y +=0.01f;
|
||||
}
|
||||
__global float4* colors = &posOrnColors[numObjects*2];
|
||||
colors[iGID] = (float4)(0,0,1,1);
|
||||
}
|
||||
|
||||
__kernel void colorPairsKernel(__global float4* posOrnColors, int numObjects, __global const int4* pairs, int numPairs)
|
||||
{
|
||||
int iPairId = get_global_id(0);
|
||||
if (iPairId>=numPairs)
|
||||
return;
|
||||
__global float4* colors = &posOrnColors[numObjects*2];
|
||||
|
||||
int iObjectA = pairs[iPairId].x;
|
||||
int iObjectB = pairs[iPairId].y;
|
||||
colors[iObjectA] = (float4)(1,0,0,1);
|
||||
colors[iObjectB] = (float4)(1,0,0,1);
|
||||
}
|
||||
|
||||
__kernel void
|
||||
sineWaveKernel( __global float4* posOrnColors, __global float* pBodyTimes,float timeStepPos, float mAmplitude,const int numNodes)
|
||||
{
|
||||
int nodeID = get_global_id(0);
|
||||
if( nodeID < numNodes )
|
||||
{
|
||||
pBodyTimes[nodeID] += timeStepPos;
|
||||
float4 position = posOrnColors[nodeID];
|
||||
position.x = native_cos(pBodyTimes[nodeID]*2.17f)*mAmplitude + native_sin(pBodyTimes[nodeID])*mAmplitude*0.5f;
|
||||
position.y = native_cos(pBodyTimes[nodeID]*1.38f)*mAmplitude + native_sin(pBodyTimes[nodeID]*mAmplitude);
|
||||
position.z = native_cos(pBodyTimes[nodeID]*2.17f)*mAmplitude + native_sin(pBodyTimes[nodeID]*0.777f)*mAmplitude;
|
||||
|
||||
posOrnColors[nodeID] = position;
|
||||
__global float4* colors = &posOrnColors[numNodes*2];
|
||||
colors[nodeID] = (float4)(0,0,1,1);
|
||||
}
|
||||
}
|
||||
|
||||
typedef struct
|
||||
{
|
||||
float fx;
|
||||
float fy;
|
||||
float fz;
|
||||
int uw;
|
||||
} b3AABBCL;
|
||||
|
||||
__kernel void updateAabbSimple( __global float4* posOrnColors, const int numNodes, __global b3AABBCL* pAABB)
|
||||
{
|
||||
int nodeId = get_global_id(0);
|
||||
if( nodeId < numNodes )
|
||||
{
|
||||
float4 position = posOrnColors[nodeId];
|
||||
float4 halfExtents = (float4)(1.01f,1.01f,1.01f,0.f);
|
||||
pAABB[nodeId*2].fx = position.x-halfExtents.x;
|
||||
pAABB[nodeId*2].fy = position.y-halfExtents.y;
|
||||
pAABB[nodeId*2].fz = position.z-halfExtents.z;
|
||||
pAABB[nodeId*2].uw = nodeId;
|
||||
pAABB[nodeId*2+1].fx = position.x+halfExtents.x;
|
||||
pAABB[nodeId*2+1].fy = position.y+halfExtents.y;
|
||||
pAABB[nodeId*2+1].fz = position.z+halfExtents.z;
|
||||
pAABB[nodeId*2+1].uw = nodeId;
|
||||
}
|
||||
}
|
||||
68
Demos3/GpuDemos/broadphase/pairsKernel.h
Normal file
68
Demos3/GpuDemos/broadphase/pairsKernel.h
Normal file
@@ -0,0 +1,68 @@
|
||||
//this file is autogenerated using stringify.bat (premake --stringify) in the build folder of this project
|
||||
static const char* pairsKernelsCL= \
|
||||
"__kernel void moveObjectsKernel(__global float4* posOrnColors, int numObjects)\n"
|
||||
"{\n"
|
||||
" int iGID = get_global_id(0);\n"
|
||||
" if (iGID>=numObjects)\n"
|
||||
" return;\n"
|
||||
" __global float4* positions = &posOrnColors[0];\n"
|
||||
" if (iGID<0.5*numObjects)\n"
|
||||
" {\n"
|
||||
" positions[iGID].y +=0.01f;\n"
|
||||
" }\n"
|
||||
" __global float4* colors = &posOrnColors[numObjects*2];\n"
|
||||
" colors[iGID] = (float4)(0,0,1,1);\n"
|
||||
"}\n"
|
||||
"__kernel void colorPairsKernel(__global float4* posOrnColors, int numObjects, __global const int4* pairs, int numPairs)\n"
|
||||
"{\n"
|
||||
" int iPairId = get_global_id(0);\n"
|
||||
" if (iPairId>=numPairs)\n"
|
||||
" return;\n"
|
||||
" __global float4* colors = &posOrnColors[numObjects*2];\n"
|
||||
" int iObjectA = pairs[iPairId].x;\n"
|
||||
" int iObjectB = pairs[iPairId].y;\n"
|
||||
" colors[iObjectA] = (float4)(1,0,0,1);\n"
|
||||
" colors[iObjectB] = (float4)(1,0,0,1);\n"
|
||||
"}\n"
|
||||
"__kernel void \n"
|
||||
" sineWaveKernel( __global float4* posOrnColors, __global float* pBodyTimes,float timeStepPos, float mAmplitude,const int numNodes)\n"
|
||||
"{\n"
|
||||
" int nodeID = get_global_id(0);\n"
|
||||
" if( nodeID < numNodes )\n"
|
||||
" {\n"
|
||||
" pBodyTimes[nodeID] += timeStepPos;\n"
|
||||
" float4 position = posOrnColors[nodeID];\n"
|
||||
" position.x = native_cos(pBodyTimes[nodeID]*2.17f)*mAmplitude + native_sin(pBodyTimes[nodeID])*mAmplitude*0.5f;\n"
|
||||
" position.y = native_cos(pBodyTimes[nodeID]*1.38f)*mAmplitude + native_sin(pBodyTimes[nodeID]*mAmplitude);\n"
|
||||
" position.z = native_cos(pBodyTimes[nodeID]*2.17f)*mAmplitude + native_sin(pBodyTimes[nodeID]*0.777f)*mAmplitude;\n"
|
||||
" \n"
|
||||
" posOrnColors[nodeID] = position;\n"
|
||||
" __global float4* colors = &posOrnColors[numNodes*2];\n"
|
||||
" colors[nodeID] = (float4)(0,0,1,1);\n"
|
||||
" }\n"
|
||||
"}\n"
|
||||
"typedef struct \n"
|
||||
"{\n"
|
||||
" float fx;\n"
|
||||
" float fy;\n"
|
||||
" float fz;\n"
|
||||
" int uw;\n"
|
||||
"} b3AABBCL;\n"
|
||||
"__kernel void updateAabbSimple( __global float4* posOrnColors, const int numNodes, __global b3AABBCL* pAABB)\n"
|
||||
"{\n"
|
||||
" int nodeId = get_global_id(0);\n"
|
||||
" if( nodeId < numNodes )\n"
|
||||
" {\n"
|
||||
" float4 position = posOrnColors[nodeId];\n"
|
||||
" float4 halfExtents = (float4)(1.01f,1.01f,1.01f,0.f);\n"
|
||||
" pAABB[nodeId*2].fx = position.x-halfExtents.x;\n"
|
||||
" pAABB[nodeId*2].fy = position.y-halfExtents.y;\n"
|
||||
" pAABB[nodeId*2].fz = position.z-halfExtents.z;\n"
|
||||
" pAABB[nodeId*2].uw = nodeId;\n"
|
||||
" pAABB[nodeId*2+1].fx = position.x+halfExtents.x;\n"
|
||||
" pAABB[nodeId*2+1].fy = position.y+halfExtents.y;\n"
|
||||
" pAABB[nodeId*2+1].fz = position.z+halfExtents.z;\n"
|
||||
" pAABB[nodeId*2+1].uw = nodeId; \n"
|
||||
" }\n"
|
||||
"}\n"
|
||||
;
|
||||
51
Demos3/GpuDemos/gwenInternalData.h
Normal file
51
Demos3/GpuDemos/gwenInternalData.h
Normal file
@@ -0,0 +1,51 @@
|
||||
#ifndef GWEN_INTERNAL_DATA_H
|
||||
#define GWEN_INTERNAL_DATA_H
|
||||
|
||||
#include "OpenGLWindow/GwenOpenGL3CoreRenderer.h"
|
||||
#include "OpenGLWindow/GLPrimitiveRenderer.h"
|
||||
#include "Gwen/Platform.h"
|
||||
#include "Gwen/Controls/TreeControl.h"
|
||||
#include "Gwen/Controls/RadioButtonController.h"
|
||||
#include "Gwen/Controls/VerticalSlider.h"
|
||||
#include "Gwen/Controls/HorizontalSlider.h"
|
||||
#include "Gwen/Controls/GroupBox.h"
|
||||
#include "Gwen/Controls/CheckBox.h"
|
||||
#include "Gwen/Controls/StatusBar.h"
|
||||
#include "Gwen/Controls/Button.h"
|
||||
#include "Gwen/Controls/ComboBox.h"
|
||||
#include "Gwen/Controls/MenuStrip.h"
|
||||
#include "Gwen/Controls/Slider.h"
|
||||
#include "Gwen/Controls/Property/Text.h"
|
||||
#include "Gwen/Controls/SplitterBar.h"
|
||||
#include "Bullet3Common/b3AlignedObjectArray.h"
|
||||
#include "Gwen/Gwen.h"
|
||||
#include "Gwen/Align.h"
|
||||
#include "Gwen/Utility.h"
|
||||
#include "Gwen/Controls/WindowControl.h"
|
||||
#include "Gwen/Controls/TabControl.h"
|
||||
#include "Gwen/Controls/ListBox.h"
|
||||
#include "Gwen/Skins/Simple.h"
|
||||
//#include "Gwen/Skins/TexturedBase.h"
|
||||
|
||||
|
||||
struct GwenInternalData
|
||||
{
|
||||
struct sth_stash;
|
||||
class GwenOpenGL3CoreRenderer* pRenderer;
|
||||
Gwen::Skin::Simple skin;
|
||||
Gwen::Controls::Canvas* pCanvas;
|
||||
GLPrimitiveRenderer* m_primRenderer;
|
||||
Gwen::Controls::TabButton* m_demoPage;
|
||||
int m_curYposition;
|
||||
|
||||
Gwen::Controls::Label* m_rightStatusBar;
|
||||
Gwen::Controls::Label* m_leftStatusBar;
|
||||
|
||||
b3AlignedObjectArray<struct Gwen::Event::Handler*> m_handlers;
|
||||
b3ToggleButtonCallback m_toggleButtonCallback;
|
||||
b3ComboBoxCallback m_comboBoxCallback;
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif//GWEN_INTERNAL_DATA_H
|
||||
@@ -1,48 +1,7 @@
|
||||
|
||||
#include "gwenUserInterface.h"
|
||||
#include "OpenGLWindow/GwenOpenGL3CoreRenderer.h"
|
||||
#include "OpenGLWindow/GLPrimitiveRenderer.h"
|
||||
#include "Gwen/Platform.h"
|
||||
#include "Gwen/Controls/TreeControl.h"
|
||||
#include "Gwen/Controls/RadioButtonController.h"
|
||||
#include "Gwen/Controls/VerticalSlider.h"
|
||||
#include "Gwen/Controls/HorizontalSlider.h"
|
||||
#include "Gwen/Controls/GroupBox.h"
|
||||
#include "Gwen/Controls/CheckBox.h"
|
||||
#include "Gwen/Controls/StatusBar.h"
|
||||
#include "Gwen/Controls/Button.h"
|
||||
#include "Gwen/Controls/ComboBox.h"
|
||||
#include "Gwen/Controls/MenuStrip.h"
|
||||
#include "Gwen/Controls/Property/Text.h"
|
||||
#include "Gwen/Controls/SplitterBar.h"
|
||||
#include "Bullet3Common/b3AlignedObjectArray.h"
|
||||
#include "Gwen/Gwen.h"
|
||||
#include "Gwen/Align.h"
|
||||
#include "Gwen/Utility.h"
|
||||
#include "Gwen/Controls/WindowControl.h"
|
||||
#include "Gwen/Controls/TabControl.h"
|
||||
#include "Gwen/Controls/ListBox.h"
|
||||
#include "Gwen/Skins/Simple.h"
|
||||
//#include "Gwen/Skins/TexturedBase.h"
|
||||
#include "gwenInternalData.h"
|
||||
|
||||
|
||||
struct GwenInternalData
|
||||
{
|
||||
struct sth_stash;
|
||||
class GwenOpenGL3CoreRenderer* pRenderer;
|
||||
Gwen::Skin::Simple skin;
|
||||
Gwen::Controls::Canvas* pCanvas;
|
||||
GLPrimitiveRenderer* m_primRenderer;
|
||||
Gwen::Controls::TabButton* m_demoPage;
|
||||
|
||||
Gwen::Controls::Label* m_rightStatusBar;
|
||||
Gwen::Controls::Label* m_leftStatusBar;
|
||||
|
||||
b3AlignedObjectArray<struct Gwen::Event::Handler*> m_handlers;
|
||||
b3ToggleButtonCallback m_toggleButtonCallback;
|
||||
b3ComboBoxCallback m_comboBoxCallback;
|
||||
|
||||
};
|
||||
GwenUserInterface::GwenUserInterface()
|
||||
{
|
||||
m_data = new GwenInternalData();
|
||||
@@ -170,6 +129,7 @@ void GwenUserInterface::setStatusBarMessage(const char* message, bool isLeft)
|
||||
|
||||
void GwenUserInterface::init(int width, int height,struct sth_stash* stash,float retinaScale)
|
||||
{
|
||||
m_data->m_curYposition = 20;
|
||||
m_data->m_primRenderer = new GLPrimitiveRenderer(width,height);
|
||||
m_data->pRenderer = new GwenOpenGL3CoreRenderer(m_data->m_primRenderer,stash,width,height,retinaScale);
|
||||
|
||||
@@ -259,6 +219,10 @@ void GwenUserInterface::init(int width, int height,struct sth_stash* stash,float
|
||||
*/
|
||||
}
|
||||
|
||||
b3ToggleButtonCallback GwenUserInterface::getToggleButtonCallback()
|
||||
{
|
||||
return m_data->m_toggleButtonCallback;
|
||||
}
|
||||
|
||||
void GwenUserInterface::setToggleButtonCallback(b3ToggleButtonCallback callback)
|
||||
{
|
||||
@@ -272,13 +236,14 @@ void GwenUserInterface::registerToggleButton(int buttonId, const char* name)
|
||||
Gwen::Controls::Button* but = new Gwen::Controls::Button(m_data->m_demoPage->GetPage());
|
||||
|
||||
///some heuristic to find the button location
|
||||
int ypos = m_data->m_handlers.size()*20;
|
||||
int ypos = m_data->m_curYposition;
|
||||
but->SetPos(10, ypos );
|
||||
but->SetWidth( 100 );
|
||||
//but->SetBounds( 200, 30, 300, 200 );
|
||||
|
||||
MyButtonHander* handler = new MyButtonHander(m_data, buttonId);
|
||||
m_data->m_handlers.push_back(handler);
|
||||
m_data->m_curYposition+=22;
|
||||
but->onToggle.Add(handler, &MyButtonHander::onButtonA);
|
||||
but->SetIsToggle(true);
|
||||
but->SetToggleState(false);
|
||||
@@ -291,6 +256,10 @@ void GwenUserInterface::setComboBoxCallback(b3ComboBoxCallback callback)
|
||||
m_data->m_comboBoxCallback = callback;
|
||||
}
|
||||
|
||||
b3ComboBoxCallback GwenUserInterface::getComboBoxCallback()
|
||||
{
|
||||
return m_data->m_comboBoxCallback;
|
||||
}
|
||||
void GwenUserInterface::registerComboBox(int comboboxId, int numItems, const char** items, int startItem)
|
||||
{
|
||||
Gwen::Controls::ComboBox* combobox = new Gwen::Controls::ComboBox(m_data->m_demoPage->GetPage());
|
||||
@@ -298,7 +267,7 @@ void GwenUserInterface::registerComboBox(int comboboxId, int numItems, const cha
|
||||
m_data->m_handlers.push_back(handler);
|
||||
|
||||
combobox->onSelection.Add(handler,&MyComboBoxHander::onSelect);
|
||||
int ypos = m_data->m_handlers.size()*20;
|
||||
int ypos = m_data->m_curYposition;
|
||||
combobox->SetPos(10, ypos );
|
||||
combobox->SetWidth( 100 );
|
||||
//box->SetPos(120,130);
|
||||
@@ -309,6 +278,9 @@ void GwenUserInterface::registerComboBox(int comboboxId, int numItems, const cha
|
||||
combobox->OnItemSelected(item);
|
||||
}
|
||||
|
||||
m_data->m_curYposition+=22;
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -26,12 +26,21 @@ class GwenUserInterface
|
||||
bool mouseButtonCallback(int button, int state, float x, float y);
|
||||
|
||||
void setToggleButtonCallback(b3ToggleButtonCallback callback);
|
||||
b3ToggleButtonCallback getToggleButtonCallback();
|
||||
|
||||
void registerToggleButton(int buttonId, const char* name);
|
||||
|
||||
void setComboBoxCallback(b3ComboBoxCallback callback);
|
||||
b3ComboBoxCallback getComboBoxCallback();
|
||||
void registerComboBox(int buttonId, int numItems, const char** items, int startItem = 0);
|
||||
|
||||
void setStatusBarMessage(const char* message, bool isLeft=true);
|
||||
|
||||
GwenInternalData* getInternalData()
|
||||
{
|
||||
return m_data;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#endif //_GWEN_USER_INTERFACE_H
|
||||
|
||||
Reference in New Issue
Block a user