Added b3Printf, b3Warning and b3Error that can be re-routed to custom handlers.

See in src/Bullet3Common/b3Logging.h for details
This commit is contained in:
erwin coumans
2013-06-03 13:10:27 -07:00
parent 70b4ead641
commit 76b0d7697a
21 changed files with 321 additions and 175 deletions

View File

@@ -399,10 +399,16 @@ const char* g_deviceName = "blaat";
extern bool useNewBatchingKernel;
#include "Bullet3Common/b3Vector3.h"
FILE* defaultOutput = stdout;
void myprintf(const char* msg)
{
fprintf(defaultOutput,msg);
}
int main(int argc, char* argv[])
{
FILE* defaultOutput = stdout;
b3SetCustomPrintfFunc(myprintf);
b3Vector3 test(1,2,3);
test.x = 1;
test.y = 4;
@@ -690,9 +696,9 @@ int main(int argc, char* argv[])
fprintf(defaultOutput," Preferred cl_platform index%d\n", ci.preferredOpenCLPlatformIndex);
fprintf(defaultOutput,"\n");
b3OpenCLUtils::printPlatformInfo(defaultOutput, demo->getInternalData()->m_platformId);
b3OpenCLUtils::printPlatformInfo( demo->getInternalData()->m_platformId);
fprintf(defaultOutput,"\n");
b3OpenCLUtils::printDeviceInfo(defaultOutput, demo->getInternalData()->m_clDevice);
b3OpenCLUtils::printDeviceInfo( demo->getInternalData()->m_clDevice);
fprintf(defaultOutput,"\n");
do
{

View File

@@ -83,7 +83,7 @@ sth_stash* initFont(GLPrimitiveRenderer* primRender)
unsigned char* data = (unsigned char*) data2;
if (!(droidRegular = sth_add_font_from_memory(stash, data)))
{
printf("error!\n");
b3Error("error!\n");
}
err = glGetError();

View File

@@ -50,7 +50,10 @@ function createProject(vendor)
"../../src/Bullet3Geometry/b3ConvexHullComputer.h",
"../../src/Bullet3Common/b3AlignedAllocator.cpp",
"../../src/Bullet3Common/b3Quickprof.cpp",
"../../src/Bullet3Common/b3Quickprof.h"
"../../src/Bullet3Common/b3Quickprof.h",
"../../src/Bullet3Common/b3Logging.cpp",
"../../src/Bullet3Common/b3Logging.h",
}
if os.is("Windows") then

View File

@@ -39,6 +39,8 @@
"../OpenGLTrueTypeFont/opengl_fontstashcallbacks.h",
"../../src/Bullet3Geometry/b3ConvexHullComputer.cpp",
"../../src/Bullet3Geometry/b3ConvexHullComputer.h",
"../../src/Bullet3Common/b3Logging.h",
"../../src/Bullet3Common/b3Logging.cpp",
"../../src/Bullet3Common/b3AlignedAllocator.cpp",
"../../src/Bullet3Common/b3Quickprof.cpp",
"../../src/Bullet3Common/b3Quickprof.h",

View File

@@ -180,7 +180,7 @@ struct InternalDataRenderer : public GLInstanceRendererInternalData
}
void keyboardCallback(unsigned char key, int x, int y)
{
printf("world\n");
// printf("world\n");
}
};
@@ -637,7 +637,7 @@ void GLInstancingRenderer::writeTransforms()
}
} else
{
printf("ERROR glMapBuffer failed\n");
b3Error("ERROR glMapBuffer failed\n");
}
glUnmapBuffer( GL_ARRAY_BUFFER);
//if this glFinish is removed, the animation is not always working/blocks

View File

@@ -3,6 +3,7 @@
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include "Bullet3Common/b3Logging.h"
// Load the shader from the source text
void gltLoadShaderSrc(const char *szShaderSrc, GLuint shader)
@@ -89,8 +90,8 @@ GLuint gltLoadShaderPair(const char *szVertexProg, const char *szFragmentProg)
&actualLen,
infoLog);
printf("Warning/Error in GLSL shader:\n");
printf("%s\n",infoLog);
b3Error("Warning/Error in GLSL shader:\n");
b3Error("%s\n",infoLog);
glDeleteProgram(hReturn);
return (GLuint)NULL;
}

View File

@@ -25,7 +25,7 @@ subject to the following restrictions:
static void printGLString(const char *name, GLenum s) {
const char *v = (const char *) glGetString(s);
printf("GL %s = %s\n", name, v);
b3Printf("GL %s = %s\n", name, v);
}

View File

@@ -127,7 +127,7 @@ void* b3AlignedAllocInternal (size_t size, int alignment,int line,char* filen
ret = (void *)(real);//??
}
printf("allocation#%d at address %x, from %s,line %d, size %d\n",b3g_numAlignedAllocs,real, filename,line,size);
b3Printf("allocation#%d at address %x, from %s,line %d, size %d\n",b3g_numAlignedAllocs,real, filename,line,size);
int* ptr = (int*)ret;
*ptr = 12;
@@ -145,12 +145,12 @@ void b3AlignedFreeInternal (void* ptr,int line,char* filename)
int size = *((int*)(ptr)-2);
b3g_totalBytesAlignedAllocs -= size;
printf("free #%d at address %x, from %s,line %d, size %d\n",b3g_numAlignedFree,real, filename,line,size);
b3Printf("free #%d at address %x, from %s,line %d, size %d\n",b3g_numAlignedFree,real, filename,line,size);
b3s_freeFunc(real);
} else
{
printf("NULL ptr\n");
b3Printf("NULL ptr\n");
}
}
@@ -161,7 +161,7 @@ void* b3AlignedAllocInternal (size_t size, int alignment)
b3g_numAlignedAllocs++;
void* ptr;
ptr = b3s_alignedAllocFunc(size, alignment);
// printf("b3AlignedAllocInternal %d, %x\n",size,ptr);
// b3Printf("b3AlignedAllocInternal %d, %x\n",size,ptr);
return ptr;
}
@@ -173,7 +173,7 @@ void b3AlignedFreeInternal (void* ptr)
}
b3g_numAlignedFree++;
// printf("b3AlignedFreeInternal %x\n",ptr);
// b3Printf("b3AlignedFreeInternal %x\n",ptr);
b3s_alignedFreeFunc(ptr);
}

View File

@@ -0,0 +1,69 @@
#include "b3Logging.h"
#include <stdio.h>
#include <stdarg.h>
void b3PrintfFuncDefault(const char* msg)
{
printf(msg);
}
void b3WarningMessageFuncDefault(const char* msg)
{
printf(msg);
}
void b3ErrorMessageFuncDefault(const char* msg)
{
printf(msg);
}
static b3PrintfFunc* b3s_printfFunc = b3PrintfFuncDefault;
static b3WarningMessageFunc* b3s_warningMessageFunc = b3WarningMessageFuncDefault;
static b3ErrorMessageFunc* b3s_errorMessageFunc = b3ErrorMessageFuncDefault;
///The developer can route b3Printf output using their own implementation
void b3SetCustomPrintfFunc(b3PrintfFunc* printfFunc)
{
b3s_printfFunc = printfFunc;
}
void b3SetCustomWarningMessageFunc(b3PrintfFunc* warningMessageFunc)
{
b3s_warningMessageFunc = warningMessageFunc;
}
void b3SetCustomErrorMessageFunc(b3PrintfFunc* errorMessageFunc)
{
b3s_errorMessageFunc = errorMessageFunc;
}
void b3OutputPrintfVarArgsInternal(const char *str, ...)
{
char strDebug[1024]={0};
va_list argList;
va_start(argList, str);
vsprintf_s(strDebug,str,argList);
(b3s_printfFunc)(strDebug);
va_end(argList);
}
void b3OutputWarningMessageVarArgsInternal(const char *str, ...)
{
char strDebug[1024]={0};
va_list argList;
va_start(argList, str);
vsprintf_s(strDebug,str,argList);
(b3s_warningMessageFunc)(strDebug);
va_end(argList);
}
void b3OutputErrorMessageVarArgsInternal(const char *str, ...)
{
char strDebug[1024]={0};
va_list argList;
va_start(argList, str);
vsprintf_s(strDebug,str,argList);
(b3s_errorMessageFunc)(strDebug);
va_end(argList);
}

View File

@@ -0,0 +1,30 @@
#ifndef B3_LOGGING_H
#define B3_LOGGING_H
typedef void (b3PrintfFunc)(const char* msg);
typedef void (b3WarningMessageFunc)(const char* msg);
typedef void (b3ErrorMessageFunc)(const char* msg);
///The developer can route b3Printf output using their own implementation
void b3SetCustomPrintfFunc(b3PrintfFunc* printfFunc);
void b3SetCustomWarningMessageFunc(b3WarningMessageFunc* warningMsgFunc);
void b3SetCustomErrorMessageFunc(b3ErrorMessageFunc* errorMsgFunc);
///Don't use those internal functions directly, use the b3Printf or b3SetCustomPrintfFunc instead (or warning/error version)
void b3OutputPrintfVarArgsInternal(const char *str, ...);
void b3OutputWarningMessageVarArgsInternal(const char *str, ...);
void b3OutputErrorMessageVarArgsInternal(const char *str, ...);
///You can also customize the message by uncommenting out a different line below
#define b3Printf(...) b3OutputPrintfVarArgsInternal(__VA_ARGS__)
//#define b3Printf(...) {b3OutputPrintfVarArgsInternal("b3Printf[%s,%d]:",__FILE__,__LINE__);b3OutputPrintfVarArgsInternal(__VA_ARGS__); }
//#define b3Printf b3OutputPrintfVarArgsInternal
//#define b3Printf(...) printf(__VA_ARGS__)
//#define b3Printf(...)
#define b3Warning(...) {b3OutputWarningMessageVarArgsInternal("b3Warning[%s,%d]:\n",__FILE__,__LINE__);b3OutputWarningMessageVarArgsInternal(__VA_ARGS__); }
#define b3Error(...) {b3OutputErrorMessageVarArgsInternal("b3Error[%s,%d]:\n",__FILE__,__LINE__);b3OutputErrorMessageVarArgsInternal(__VA_ARGS__); }
#endif//B3_LOGGING_H

View File

@@ -525,10 +525,10 @@ void b3ProfileManager::dumpRecursive(b3ProfileIterator* profileIterator, int spa
float accumulated_time=0,parent_time = profileIterator->Is_Root() ? b3ProfileManager::Get_Time_Since_Reset() : profileIterator->Get_Current_Parent_Total_Time();
int i;
int frames_since_reset = b3ProfileManager::Get_Frame_Count_Since_Reset();
for (i=0;i<spacing;i++) printf(".");
printf("----------------------------------\n");
for (i=0;i<spacing;i++) printf(".");
printf("Profiling: %s (total running time: %.3f ms) ---\n", profileIterator->Get_Current_Parent_Name(), parent_time );
for (i=0;i<spacing;i++) b3Printf(".");
b3Printf("----------------------------------\n");
for (i=0;i<spacing;i++) b3Printf(".");
b3Printf("Profiling: %s (total running time: %.3f ms) ---\n", profileIterator->Get_Current_Parent_Name(), parent_time );
float totalTime = 0.f;
@@ -541,19 +541,19 @@ void b3ProfileManager::dumpRecursive(b3ProfileIterator* profileIterator, int spa
accumulated_time += current_total_time;
float fraction = parent_time > B3_EPSILON ? (current_total_time / parent_time) * 100 : 0.f;
{
int i; for (i=0;i<spacing;i++) printf(".");
int i; for (i=0;i<spacing;i++) b3Printf(".");
}
printf("%d -- %s (%.2f %%) :: %.3f ms / frame (%d calls)\n",i, profileIterator->Get_Current_Name(), fraction,(current_total_time / (double)frames_since_reset),profileIterator->Get_Current_Total_Calls());
b3Printf("%d -- %s (%.2f %%) :: %.3f ms / frame (%d calls)\n",i, profileIterator->Get_Current_Name(), fraction,(current_total_time / (double)frames_since_reset),profileIterator->Get_Current_Total_Calls());
totalTime += current_total_time;
//recurse into children
}
if (parent_time < accumulated_time)
{
printf("what's wrong\n");
b3Printf("what's wrong\n");
}
for (i=0;i<spacing;i++) printf(".");
printf("%s (%.3f %%) :: %.3f ms\n", "Unaccounted:",parent_time > B3_EPSILON ? ((parent_time - accumulated_time) / parent_time) * 100 : 0.f, parent_time - accumulated_time);
for (i=0;i<spacing;i++) b3Printf(".");
b3Printf("%s (%.3f %%) :: %.3f ms\n", "Unaccounted:",parent_time > B3_EPSILON ? ((parent_time - accumulated_time) / parent_time) * 100 : 0.f, parent_time - accumulated_time);
for (i=0;i<numChildren;i++)
{

View File

@@ -23,12 +23,13 @@ subject to the following restrictions:
#endif
#include <math.h>
#include <stdlib.h>//size_t for MSVC 6.0
#include <float.h>
/* SVN $Revision$ on $Date$ from http://bullet.googlecode.com*/
#define B3_BULLET_VERSION 281
//Original repository is at http://github.com/erwincoumans/bullet3
#define B3_BULLET_VERSION 300
inline int b3GetVersion()
{
@@ -39,6 +40,8 @@ inline int b3GetVersion()
#define B3_DEBUG
#endif
#include "b3Logging.h"//for b3Error
#ifdef _WIN32
@@ -88,7 +91,7 @@ inline int b3GetVersion()
#ifdef B3_DEBUG
#ifdef _MSC_VER
#include <stdio.h>
#define b3Assert(x) { if(!(x)){printf("Assert "__FILE__ ":%u ("#x")\n", __LINE__);__debugbreak(); }}
#define b3Assert(x) { if(!(x)){b3Error("Assert "__FILE__ ":%u ("#x")\n", __LINE__);__debugbreak(); }}
#else//_MSC_VER
#include <assert.h>
#define b3Assert assert
@@ -116,7 +119,7 @@ inline int b3GetVersion()
#ifdef __SPU__
#include <spu_printf.h>
#define printf spu_printf
#define b3Assert(x) {if(!(x)){printf("Assert "__FILE__ ":%u ("#x")\n", __LINE__);spu_hcmpeq(0,0);}}
#define b3Assert(x) {if(!(x)){b3Error("Assert "__FILE__ ":%u ("#x")\n", __LINE__);spu_hcmpeq(0,0);}}
#else
#define b3Assert assert
#endif
@@ -201,7 +204,7 @@ inline int b3GetVersion()
{\
if(!(x))\
{\
printf("Assert %s in line %d, file %s\n",#x, __LINE__, __FILE__);\
b3Error("Assert %s in line %d, file %s\n",#x, __LINE__, __FILE__);\
asm volatile ("int3");\
}\
}

View File

@@ -451,7 +451,7 @@ class b3ConvexHullInternal
#ifdef DEBUG_CONVEX_HULL
void print()
{
printf("V%d (%d, %d, %d)", point.index, point.x, point.y, point.z);
b3Printf("V%d (%d, %d, %d)", point.index, point.x, point.y, point.z);
}
void printGraph();
@@ -537,7 +537,7 @@ class b3ConvexHullInternal
#ifdef DEBUG_CONVEX_HULL
void print()
{
printf("E%p : %d -> %d, n=%p p=%p (0 %d\t%d\t%d) -> (%d %d %d)", this, reverse->target->point.index, target->point.index, next, prev,
b3Printf("E%p : %d -> %d, n=%p p=%p (0 %d\t%d\t%d) -> (%d %d %d)", this, reverse->target->point.index, target->point.index, next, prev,
reverse->target->point.x, reverse->target->point.y, reverse->target->point.z, target->point.x, target->point.y, target->point.z);
}
#endif
@@ -1310,13 +1310,13 @@ void b3ConvexHullInternal::computeInternal(int start, int end, IntermediateHull&
IntermediateHull hull1;
computeInternal(split1, end, hull1);
#ifdef DEBUG_CONVEX_HULL
printf("\n\nMerge\n");
b3Printf("\n\nMerge\n");
result.print();
hull1.print();
#endif
merge(result, hull1);
#ifdef DEBUG_CONVEX_HULL
printf("\n Result\n");
b3Printf("\n Result\n");
result.print();
#endif
}
@@ -1324,28 +1324,28 @@ void b3ConvexHullInternal::computeInternal(int start, int end, IntermediateHull&
#ifdef DEBUG_CONVEX_HULL
void b3ConvexHullInternal::IntermediateHull::print()
{
printf(" Hull\n");
b3Printf(" Hull\n");
for (Vertex* v = minXy; v; )
{
printf(" ");
b3Printf(" ");
v->print();
if (v == maxXy)
{
printf(" maxXy");
b3Printf(" maxXy");
}
if (v == minYx)
{
printf(" minYx");
b3Printf(" minYx");
}
if (v == maxYx)
{
printf(" maxYx");
b3Printf(" maxYx");
}
if (v->next->prev != v)
{
printf(" Inconsistency");
b3Printf(" Inconsistency");
}
printf("\n");
b3Printf("\n");
v = v->next;
if (v == minXy)
{
@@ -1362,14 +1362,14 @@ void b3ConvexHullInternal::IntermediateHull::print()
void b3ConvexHullInternal::Vertex::printGraph()
{
print();
printf("\nEdges\n");
b3Printf("\nEdges\n");
Edge* e = edges;
if (e)
{
do
{
e->print();
printf("\n");
b3Printf("\n");
e = e->next;
} while (e != edges);
do
@@ -1417,7 +1417,7 @@ b3ConvexHullInternal::Edge* b3ConvexHullInternal::findMaxAngle(bool ccw, const V
Edge* minEdge = NULL;
#ifdef DEBUG_CONVEX_HULL
printf("find max edge for %d\n", start->point.index);
b3Printf("find max edge for %d\n", start->point.index);
#endif
Edge* e = start->edges;
if (e)
@@ -1429,7 +1429,7 @@ b3ConvexHullInternal::Edge* b3ConvexHullInternal::findMaxAngle(bool ccw, const V
Point32 t = *e->target - *start;
Rational64 cot(t.dot(sxrxs), t.dot(rxs));
#ifdef DEBUG_CONVEX_HULL
printf(" Angle is %f (%d) for ", (float) b3Atan(cot.toScalar()), (int) cot.isNaN());
b3Printf(" Angle is %f (%d) for ", (float) b3Atan(cot.toScalar()), (int) cot.isNaN());
e->print();
#endif
if (cot.isNaN())
@@ -1455,7 +1455,7 @@ b3ConvexHullInternal::Edge* b3ConvexHullInternal::findMaxAngle(bool ccw, const V
}
}
#ifdef DEBUG_CONVEX_HULL
printf("\n");
b3Printf("\n");
#endif
}
e = e->next;
@@ -1478,7 +1478,7 @@ void b3ConvexHullInternal::findEdgeForCoplanarFaces(Vertex* c0, Vertex* c1, Edge
b3Assert(!perp.isZero());
#ifdef DEBUG_CONVEX_HULL
printf(" Advancing %d %d (%p %p, %d %d)\n", c0->point.index, c1->point.index, start0, start1, start0 ? start0->target->point.index : -1, start1 ? start1->target->point.index : -1);
b3Printf(" Advancing %d %d (%p %p, %d %d)\n", c0->point.index, c1->point.index, start0, start1, start0 ? start0->target->point.index : -1, start1 ? start1->target->point.index : -1);
#endif
btInt64_t maxDot0 = et0.dot(perp);
@@ -1534,7 +1534,7 @@ void b3ConvexHullInternal::findEdgeForCoplanarFaces(Vertex* c0, Vertex* c1, Edge
}
#ifdef DEBUG_CONVEX_HULL
printf(" Starting at %d %d\n", et0.index, et1.index);
b3Printf(" Starting at %d %d\n", et0.index, et1.index);
#endif
btInt64_t dx = maxDot1 - maxDot0;
@@ -1643,7 +1643,7 @@ void b3ConvexHullInternal::findEdgeForCoplanarFaces(Vertex* c0, Vertex* c1, Edge
}
}
#ifdef DEBUG_CONVEX_HULL
printf(" Advanced edges to %d %d\n", et0.index, et1.index);
b3Printf(" Advanced edges to %d %d\n", et0.index, et1.index);
#endif
}
@@ -1753,7 +1753,7 @@ void b3ConvexHullInternal::merge(IntermediateHull& h0, IntermediateHull& h1)
Point64 sxrxs = s.cross(rxs);
#ifdef DEBUG_CONVEX_HULL
printf("\n Checking %d %d\n", c0->point.index, c1->point.index);
b3Printf("\n Checking %d %d\n", c0->point.index, c1->point.index);
#endif
Rational64 minCot0(0, 0);
Edge* min0 = findMaxAngle(false, c0, s, rxs, sxrxs, minCot0);
@@ -1774,7 +1774,7 @@ void b3ConvexHullInternal::merge(IntermediateHull& h0, IntermediateHull& h1)
{
int cmp = !min0 ? 1 : !min1 ? -1 : minCot0.compare(minCot1);
#ifdef DEBUG_CONVEX_HULL
printf(" -> Result %d\n", cmp);
b3Printf(" -> Result %d\n", cmp);
#endif
if (firstRun || ((cmp >= 0) ? !minCot1.isNegativeInfinity() : !minCot0.isNegativeInfinity()))
{
@@ -1807,7 +1807,7 @@ void b3ConvexHullInternal::merge(IntermediateHull& h0, IntermediateHull& h1)
Edge* e1 = min1;
#ifdef DEBUG_CONVEX_HULL
printf(" Found min edges to %d %d\n", e0 ? e0->target->point.index : -1, e1 ? e1->target->point.index : -1);
b3Printf(" Found min edges to %d %d\n", e0 ? e0->target->point.index : -1, e1 ? e1->target->point.index : -1);
#endif
if (cmp == 0)
@@ -2058,7 +2058,7 @@ void b3ConvexHullInternal::compute(const void* coords, bool doubleCoords, int st
computeInternal(0, count, hull);
vertexList = hull.minXy;
#ifdef DEBUG_CONVEX_HULL
printf("max. edges %d (3v = %d)", maxUsedEdgePairs, 3 * count);
b3Printf("max. edges %d (3v = %d)", maxUsedEdgePairs, 3 * count);
#endif
}
@@ -2228,7 +2228,7 @@ bool b3ConvexHullInternal::shiftFace(Face* face, b3Scalar amount, b3AlignedObjec
}
Point64 normal = face->getNormal();
#ifdef DEBUG_CONVEX_HULL
printf("\nShrinking face (%d %d %d) (%d %d %d) (%d %d %d) by (%d %d %d)\n",
b3Printf("\nShrinking face (%d %d %d) (%d %d %d) (%d %d %d) by (%d %d %d)\n",
face->origin.x, face->origin.y, face->origin.z, face->dir0.x, face->dir0.y, face->dir0.z, face->dir1.x, face->dir1.y, face->dir1.z, shift.x, shift.y, shift.z);
#endif
btInt64_t origDot = face->origin.dot(normal);
@@ -2244,9 +2244,9 @@ bool b3ConvexHullInternal::shiftFace(Face* face, b3Scalar amount, b3AlignedObjec
Edge* startEdge = face->nearbyVertex->edges;
#ifdef DEBUG_CONVEX_HULL
printf("Start edge is ");
b3Printf("Start edge is ");
startEdge->print();
printf(", normal is (%lld %lld %lld), shifted dot is %lld\n", normal.x, normal.y, normal.z, shiftedDot);
b3Printf(", normal is (%lld %lld %lld), shifted dot is %lld\n", normal.x, normal.y, normal.z, shiftedDot);
#endif
Rational128 optDot = face->nearbyVertex->dot(normal);
int cmp = optDot.compare(shiftedDot);
@@ -2264,9 +2264,9 @@ bool b3ConvexHullInternal::shiftFace(Face* face, b3Scalar amount, b3AlignedObjec
Rational128 dot = e->target->dot(normal);
b3Assert(dot.compare(origDot) <= 0);
#ifdef DEBUG_CONVEX_HULL
printf("Moving downwards, edge is ");
b3Printf("Moving downwards, edge is ");
e->print();
printf(", dot is %f (%f %lld)\n", (float) dot.toScalar(), (float) optDot.toScalar(), shiftedDot);
b3Printf(", dot is %f (%f %lld)\n", (float) dot.toScalar(), (float) optDot.toScalar(), shiftedDot);
#endif
if (dot.compare(optDot) < 0)
{
@@ -2300,9 +2300,9 @@ bool b3ConvexHullInternal::shiftFace(Face* face, b3Scalar amount, b3AlignedObjec
Rational128 dot = e->target->dot(normal);
b3Assert(dot.compare(origDot) <= 0);
#ifdef DEBUG_CONVEX_HULL
printf("Moving upwards, edge is ");
b3Printf("Moving upwards, edge is ");
e->print();
printf(", dot is %f (%f %lld)\n", (float) dot.toScalar(), (float) optDot.toScalar(), shiftedDot);
b3Printf(", dot is %f (%f %lld)\n", (float) dot.toScalar(), (float) optDot.toScalar(), shiftedDot);
#endif
if (dot.compare(optDot) > 0)
{
@@ -2326,7 +2326,7 @@ bool b3ConvexHullInternal::shiftFace(Face* face, b3Scalar amount, b3AlignedObjec
}
#ifdef SHOW_ITERATIONS
printf("Needed %d iterations to find initial intersection\n", n);
b3Printf("Needed %d iterations to find initial intersection\n", n);
#endif
if (cmp == 0)
@@ -2346,13 +2346,13 @@ bool b3ConvexHullInternal::shiftFace(Face* face, b3Scalar amount, b3AlignedObjec
return true;
}
#ifdef DEBUG_CONVEX_HULL
printf("Checking for outwards edge, current edge is ");
b3Printf("Checking for outwards edge, current edge is ");
e->print();
printf("\n");
b3Printf("\n");
#endif
}
#ifdef SHOW_ITERATIONS
printf("Needed %d iterations to check for complete containment\n", n);
b3Printf("Needed %d iterations to check for complete containment\n", n);
#endif
}
@@ -2369,9 +2369,9 @@ bool b3ConvexHullInternal::shiftFace(Face* face, b3Scalar amount, b3AlignedObjec
m++;
#endif
#ifdef DEBUG_CONVEX_HULL
printf("Intersecting edge is ");
b3Printf("Intersecting edge is ");
intersection->print();
printf("\n");
b3Printf("\n");
#endif
if (cmp == 0)
{
@@ -2397,14 +2397,14 @@ bool b3ConvexHullInternal::shiftFace(Face* face, b3Scalar amount, b3AlignedObjec
}
}
#ifdef SHOW_ITERATIONS
printf("Needed %d iterations to advance intersection\n", n);
b3Printf("Needed %d iterations to advance intersection\n", n);
#endif
}
#ifdef DEBUG_CONVEX_HULL
printf("Advanced intersecting edge to ");
b3Printf("Advanced intersecting edge to ");
intersection->print();
printf(", cmp = %d\n", cmp);
b3Printf(", cmp = %d\n", cmp);
#endif
if (!firstIntersection)
@@ -2433,9 +2433,9 @@ bool b3ConvexHullInternal::shiftFace(Face* face, b3Scalar amount, b3AlignedObjec
b3Assert(e != intersection->reverse);
cmp = e->target->dot(normal).compare(shiftedDot);
#ifdef DEBUG_CONVEX_HULL
printf("Testing edge ");
b3Printf("Testing edge ");
e->print();
printf(" -> cmp = %d\n", cmp);
b3Printf(" -> cmp = %d\n", cmp);
#endif
if (cmp >= 0)
{
@@ -2444,7 +2444,7 @@ bool b3ConvexHullInternal::shiftFace(Face* face, b3Scalar amount, b3AlignedObjec
}
}
#ifdef SHOW_ITERATIONS
printf("Needed %d iterations to find other intersection of face\n", n);
b3Printf("Needed %d iterations to find other intersection of face\n", n);
#endif
if (cmp > 0)
@@ -2462,7 +2462,7 @@ bool b3ConvexHullInternal::shiftFace(Face* face, b3Scalar amount, b3AlignedObjec
e->link(e);
}
#ifdef DEBUG_CONVEX_HULL
printf("1: Removed part contains (%d %d %d)\n", removed->point.x, removed->point.y, removed->point.z);
b3Printf("1: Removed part contains (%d %d %d)\n", removed->point.x, removed->point.y, removed->point.z);
#endif
Point64 n0 = intersection->face->getNormal();
@@ -2533,7 +2533,7 @@ bool b3ConvexHullInternal::shiftFace(Face* face, b3Scalar amount, b3AlignedObjec
removeEdgePair(faceEdge->next);
stack.push_back(removed);
#ifdef DEBUG_CONVEX_HULL
printf("2: Removed part contains (%d %d %d)\n", removed->point.x, removed->point.y, removed->point.z);
b3Printf("2: Removed part contains (%d %d %d)\n", removed->point.x, removed->point.y, removed->point.z);
#endif
}
stack.push_back(NULL);
@@ -2548,7 +2548,7 @@ bool b3ConvexHullInternal::shiftFace(Face* face, b3Scalar amount, b3AlignedObjec
}
}
#ifdef SHOW_ITERATIONS
printf("Needed %d iterations to process all intersections\n", m);
b3Printf("Needed %d iterations to process all intersections\n", m);
#endif
if (cmp > 0)
@@ -2566,7 +2566,7 @@ bool b3ConvexHullInternal::shiftFace(Face* face, b3Scalar amount, b3AlignedObjec
removeEdgePair(firstFaceEdge->next);
stack.push_back(removed);
#ifdef DEBUG_CONVEX_HULL
printf("3: Removed part contains (%d %d %d)\n", removed->point.x, removed->point.y, removed->point.z);
b3Printf("3: Removed part contains (%d %d %d)\n", removed->point.x, removed->point.y, removed->point.z);
#endif
}
stack.push_back(NULL);
@@ -2576,7 +2576,7 @@ bool b3ConvexHullInternal::shiftFace(Face* face, b3Scalar amount, b3AlignedObjec
vertexList = stack[0];
#ifdef DEBUG_CONVEX_HULL
printf("Removing part\n");
b3Printf("Removing part\n");
#endif
#ifdef SHOW_ITERATIONS
n = 0;
@@ -2617,7 +2617,7 @@ bool b3ConvexHullInternal::shiftFace(Face* face, b3Scalar amount, b3AlignedObjec
}
}
#ifdef SHOW_ITERATIONS
printf("Needed %d iterations to remove part\n", n);
b3Printf("Needed %d iterations to remove part\n", n);
#endif
stack.resize(0);
@@ -2636,7 +2636,7 @@ static int getVertexCopy(b3ConvexHullInternal::Vertex* vertex, b3AlignedObjectAr
vertex->copy = index;
vertices.push_back(vertex);
#ifdef DEBUG_CONVEX_HULL
printf("Vertex %d gets index *%d\n", vertex->point.index, index);
b3Printf("Vertex %d gets index *%d\n", vertex->point.index, index);
#endif
}
return index;
@@ -2697,7 +2697,7 @@ b3Scalar b3ConvexHullComputer::compute(const void* coords, bool doubleCoords, in
c->targetVertex = getVertexCopy(e->target, oldVertices);
r->targetVertex = copied;
#ifdef DEBUG_CONVEX_HULL
printf(" CREATE: Vertex *%d has edge to *%d\n", copied, c->getTargetVertex());
b3Printf(" CREATE: Vertex *%d has edge to *%d\n", copied, c->getTargetVertex());
#endif
}
if (prevCopy >= 0)
@@ -2728,14 +2728,14 @@ b3Scalar b3ConvexHullComputer::compute(const void* coords, bool doubleCoords, in
if (e->copy >= 0)
{
#ifdef DEBUG_CONVEX_HULL
printf("Vertex *%d has edge to *%d\n", i, edges[e->copy].getTargetVertex());
b3Printf("Vertex *%d has edge to *%d\n", i, edges[e->copy].getTargetVertex());
#endif
faces.push_back(e->copy);
b3ConvexHullInternal::Edge* f = e;
do
{
#ifdef DEBUG_CONVEX_HULL
printf(" Face *%d\n", edges[f->copy].getTargetVertex());
b3Printf(" Face *%d\n", edges[f->copy].getTargetVertex());
#endif
f->copy = -1;
f = f->reverse->prev;

View File

@@ -19,6 +19,7 @@ subject to the following restrictions:
bool gDebugForceLoadingFromSource = false;
bool gDebugSkipLoadingBinary = false;
#include "Bullet3Common/b3Logging.h"
#include <string.h>
@@ -71,17 +72,17 @@ void MyFatalBreakAPPLE( const char * errstr ,
size_t cb ,
void * user_data )
{
printf("Error: %s\n", errstr);
b3Error("Error: %s\n", errstr);
const char* patloc = strstr(errstr, "Warning");
//find out if it is a warning or error, exit if error
if (patloc)
{
printf("warning\n");
b3Warning("warning\n");
} else
{
printf("error\n");
b3Error("error\n");
b3Assert(0);
}
@@ -112,10 +113,12 @@ int b3OpenCLUtils_clewInit()
#endif
result = clewInit(cl);
if (result!=CLEW_SUCCESS)
printf("clewInit failed with error code %d\n",result);
{
b3Error("clewInit failed with error code %d\n",result);
}
else
{
printf("clewInit succesfull using %s\n",cl);
b3Printf("clewInit succesfull using %s\n",cl);
}
return result;
}
@@ -188,14 +191,14 @@ void b3OpenCLUtils::getPlatformInfo(cl_platform_id platform, b3OpenCLPlatformInf
oclCHECKERROR(ciErrNum,CL_SUCCESS);
}
void b3OpenCLUtils_printPlatformInfo(FILE* f, cl_platform_id platform)
void b3OpenCLUtils_printPlatformInfo( cl_platform_id platform)
{
b3OpenCLPlatformInfo platformInfo;
b3OpenCLUtils::getPlatformInfo (platform, &platformInfo);
fprintf(f,"Platform info:\n");
fprintf(f," CL_PLATFORM_VENDOR: \t\t\t%s\n",platformInfo.m_platformVendor);
fprintf(f," CL_PLATFORM_NAME: \t\t\t%s\n",platformInfo.m_platformName);
fprintf(f," CL_PLATFORM_VERSION: \t\t\t%s\n",platformInfo.m_platformVersion);
b3Printf("Platform info:\n");
b3Printf(" CL_PLATFORM_VENDOR: \t\t\t%s\n",platformInfo.m_platformVendor);
b3Printf(" CL_PLATFORM_NAME: \t\t\t%s\n",platformInfo.m_platformName);
b3Printf(" CL_PLATFORM_VERSION: \t\t\t%s\n",platformInfo.m_platformVersion);
}
@@ -241,7 +244,7 @@ cl_context b3OpenCLUtils_createContextFromPlatform(cl_platform_id platform, cl_d
if (ciErrNum<0)
{
printf("clGetDeviceIDs returned %d\n",ciErrNum);
b3Printf("clGetDeviceIDs returned %d\n",ciErrNum);
return 0;
}
cprops = (NULL == platform) ? NULL : cps;
@@ -272,7 +275,7 @@ cl_context b3OpenCLUtils_createContextFromPlatform(cl_platform_id platform, cl_d
#if defined (__APPLE__)
retContext = clCreateContext(cprops,num_devices,devices,MyFatalBreakAPPLE,NULL,&ciErrNum);
#else
printf("numDevices=%d\n",num_devices);
b3Printf("numDevices=%d\n",num_devices);
retContext = clCreateContext(cprops,num_devices,devices,NULL,NULL,&ciErrNum);
#endif
@@ -500,57 +503,61 @@ void b3OpenCLUtils::getDeviceInfo(cl_device_id device, b3OpenCLDeviceInfo* info)
}
void b3OpenCLUtils_printDeviceInfo(FILE* f, cl_device_id device)
void b3OpenCLUtils_printDeviceInfo(cl_device_id device)
{
b3OpenCLDeviceInfo info;
b3OpenCLUtils::getDeviceInfo(device,&info);
fprintf(f,"Device Info:\n");
fprintf(f," CL_DEVICE_NAME: \t\t\t%s\n", info.m_deviceName);
fprintf(f," CL_DEVICE_VENDOR: \t\t\t%s\n", info.m_deviceVendor);
fprintf(f," CL_DRIVER_VERSION: \t\t\t%s\n", info.m_driverVersion);
b3Printf("Device Info:\n");
b3Printf(" CL_DEVICE_NAME: \t\t\t%s\n", info.m_deviceName);
b3Printf(" CL_DEVICE_VENDOR: \t\t\t%s\n", info.m_deviceVendor);
b3Printf(" CL_DRIVER_VERSION: \t\t\t%s\n", info.m_driverVersion);
if( info.m_deviceType & CL_DEVICE_TYPE_CPU )
fprintf(f," CL_DEVICE_TYPE:\t\t\t%s\n", "CL_DEVICE_TYPE_CPU");
b3Printf(" CL_DEVICE_TYPE:\t\t\t%s\n", "CL_DEVICE_TYPE_CPU");
if( info.m_deviceType & CL_DEVICE_TYPE_GPU )
fprintf(f," CL_DEVICE_TYPE:\t\t\t%s\n", "CL_DEVICE_TYPE_GPU");
b3Printf(" CL_DEVICE_TYPE:\t\t\t%s\n", "CL_DEVICE_TYPE_GPU");
if( info.m_deviceType & CL_DEVICE_TYPE_ACCELERATOR )
fprintf(f," CL_DEVICE_TYPE:\t\t\t%s\n", "CL_DEVICE_TYPE_ACCELERATOR");
b3Printf(" CL_DEVICE_TYPE:\t\t\t%s\n", "CL_DEVICE_TYPE_ACCELERATOR");
if( info.m_deviceType & CL_DEVICE_TYPE_DEFAULT )
fprintf(f," CL_DEVICE_TYPE:\t\t\t%s\n", "CL_DEVICE_TYPE_DEFAULT");
b3Printf(" CL_DEVICE_TYPE:\t\t\t%s\n", "CL_DEVICE_TYPE_DEFAULT");
fprintf(f," CL_DEVICE_MAX_COMPUTE_UNITS:\t\t%u\n", info.m_computeUnits);
fprintf(f," CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS:\t%u\n", info.m_workitemDims);
fprintf(f," CL_DEVICE_MAX_WORK_ITEM_SIZES:\t%u / %u / %u \n", info.m_workItemSize[0], info.m_workItemSize[1], info.m_workItemSize[2]);
fprintf(f," CL_DEVICE_MAX_WORK_GROUP_SIZE:\t%u\n", info.m_workgroupSize);
fprintf(f," CL_DEVICE_MAX_CLOCK_FREQUENCY:\t%u MHz\n", info.m_clockFrequency);
fprintf(f," CL_DEVICE_ADDRESS_BITS:\t\t%u\n", info.m_addressBits);
fprintf(f," CL_DEVICE_MAX_MEM_ALLOC_SIZE:\t\t%u MByte\n", (unsigned int)(info.m_maxMemAllocSize/ (1024 * 1024)));
fprintf(f," CL_DEVICE_GLOBAL_MEM_SIZE:\t\t%u MByte\n", (unsigned int)(info.m_globalMemSize/ (1024 * 1024)));
fprintf(f," CL_DEVICE_ERROR_CORRECTION_SUPPORT:\t%s\n", info.m_errorCorrectionSupport== CL_TRUE ? "yes" : "no");
fprintf(f," CL_DEVICE_LOCAL_MEM_TYPE:\t\t%s\n", info.m_localMemType == 1 ? "local" : "global");
fprintf(f," CL_DEVICE_LOCAL_MEM_SIZE:\t\t%u KByte\n", (unsigned int)(info.m_localMemSize / 1024));
fprintf(f," CL_DEVICE_MAX_CONSTANT_BUFFER_SIZE:\t%u KByte\n", (unsigned int)(info.m_constantBufferSize / 1024));
b3Printf(" CL_DEVICE_MAX_COMPUTE_UNITS:\t\t%u\n", info.m_computeUnits);
b3Printf(" CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS:\t%u\n", info.m_workitemDims);
b3Printf(" CL_DEVICE_MAX_WORK_ITEM_SIZES:\t%u / %u / %u \n", info.m_workItemSize[0], info.m_workItemSize[1], info.m_workItemSize[2]);
b3Printf(" CL_DEVICE_MAX_WORK_GROUP_SIZE:\t%u\n", info.m_workgroupSize);
b3Printf(" CL_DEVICE_MAX_CLOCK_FREQUENCY:\t%u MHz\n", info.m_clockFrequency);
b3Printf(" CL_DEVICE_ADDRESS_BITS:\t\t%u\n", info.m_addressBits);
b3Printf(" CL_DEVICE_MAX_MEM_ALLOC_SIZE:\t\t%u MByte\n", (unsigned int)(info.m_maxMemAllocSize/ (1024 * 1024)));
b3Printf(" CL_DEVICE_GLOBAL_MEM_SIZE:\t\t%u MByte\n", (unsigned int)(info.m_globalMemSize/ (1024 * 1024)));
b3Printf(" CL_DEVICE_ERROR_CORRECTION_SUPPORT:\t%s\n", info.m_errorCorrectionSupport== CL_TRUE ? "yes" : "no");
b3Printf(" CL_DEVICE_LOCAL_MEM_TYPE:\t\t%s\n", info.m_localMemType == 1 ? "local" : "global");
b3Printf(" CL_DEVICE_LOCAL_MEM_SIZE:\t\t%u KByte\n", (unsigned int)(info.m_localMemSize / 1024));
b3Printf(" CL_DEVICE_MAX_CONSTANT_BUFFER_SIZE:\t%u KByte\n", (unsigned int)(info.m_constantBufferSize / 1024));
if( info.m_queueProperties & CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE )
fprintf(f," CL_DEVICE_QUEUE_PROPERTIES:\t\t%s\n", "CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE");
b3Printf(" CL_DEVICE_QUEUE_PROPERTIES:\t\t%s\n", "CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE");
if( info.m_queueProperties & CL_QUEUE_PROFILING_ENABLE )
fprintf(f," CL_DEVICE_QUEUE_PROPERTIES:\t\t%s\n", "CL_QUEUE_PROFILING_ENABLE");
b3Printf(" CL_DEVICE_QUEUE_PROPERTIES:\t\t%s\n", "CL_QUEUE_PROFILING_ENABLE");
fprintf(f," CL_DEVICE_IMAGE_SUPPORT:\t\t%u\n", info.m_imageSupport);
b3Printf(" CL_DEVICE_IMAGE_SUPPORT:\t\t%u\n", info.m_imageSupport);
fprintf(f," CL_DEVICE_MAX_READ_IMAGE_ARGS:\t%u\n", info.m_maxReadImageArgs);
fprintf(f," CL_DEVICE_MAX_WRITE_IMAGE_ARGS:\t%u\n", info.m_maxWriteImageArgs);
fprintf(f,"\n CL_DEVICE_IMAGE <dim>");
fprintf(f,"\t\t\t2D_MAX_WIDTH\t %u\n", info.m_image2dMaxWidth);
fprintf(f,"\t\t\t\t\t2D_MAX_HEIGHT\t %u\n", info.m_image2dMaxHeight);
fprintf(f,"\t\t\t\t\t3D_MAX_WIDTH\t %u\n", info.m_image3dMaxWidth);
fprintf(f,"\t\t\t\t\t3D_MAX_HEIGHT\t %u\n", info.m_image3dMaxHeight);
fprintf(f,"\t\t\t\t\t3D_MAX_DEPTH\t %u\n", info.m_image3dMaxDepth);
b3Printf(" CL_DEVICE_MAX_READ_IMAGE_ARGS:\t%u\n", info.m_maxReadImageArgs);
b3Printf(" CL_DEVICE_MAX_WRITE_IMAGE_ARGS:\t%u\n", info.m_maxWriteImageArgs);
b3Printf("\n CL_DEVICE_IMAGE <dim>");
b3Printf("\t\t\t2D_MAX_WIDTH\t %u\n", info.m_image2dMaxWidth);
b3Printf("\t\t\t\t\t2D_MAX_HEIGHT\t %u\n", info.m_image2dMaxHeight);
b3Printf("\t\t\t\t\t3D_MAX_WIDTH\t %u\n", info.m_image3dMaxWidth);
b3Printf("\t\t\t\t\t3D_MAX_HEIGHT\t %u\n", info.m_image3dMaxHeight);
b3Printf("\t\t\t\t\t3D_MAX_DEPTH\t %u\n", info.m_image3dMaxDepth);
if (info.m_deviceExtensions != 0)
fprintf(f,"\n CL_DEVICE_EXTENSIONS:%s\n",info.m_deviceExtensions);
{
b3Printf("\n CL_DEVICE_EXTENSIONS:%s\n",info.m_deviceExtensions);
}
else
fprintf(f," CL_DEVICE_EXTENSIONS: None\n");
fprintf(f," CL_DEVICE_PREFERRED_VECTOR_WIDTH_<t>\t");
fprintf(f,"CHAR %u, SHORT %u, INT %u,LONG %u, FLOAT %u, DOUBLE %u\n\n\n",
{
b3Printf(" CL_DEVICE_EXTENSIONS: None\n");
}
b3Printf(" CL_DEVICE_PREFERRED_VECTOR_WIDTH_<t>\t");
b3Printf("CHAR %u, SHORT %u, INT %u,LONG %u, FLOAT %u, DOUBLE %u\n\n\n",
info.m_vecWidthChar, info.m_vecWidthShort, info.m_vecWidthInt, info.m_vecWidthLong,info.m_vecWidthFloat, info.m_vecWidthDouble);
@@ -629,17 +636,17 @@ cl_program b3OpenCLUtils_compileCLProgramFromString(cl_context clContext, cl_dev
{
case ERROR_FILE_NOT_FOUND:
{
printf("\nCached file not found %s\n", binaryFileName);
b3Warning("\nCached file not found %s\n", binaryFileName);
break;
}
case ERROR_PATH_NOT_FOUND:
{
printf("\nCached file path not found %s\n", binaryFileName);
b3Warning("\nCached file path not found %s\n", binaryFileName);
break;
}
default:
{
printf("\nFailed reading cached file with errorCode = %d\n", errorCode);
b3Warning("\nFailed reading cached file with errorCode = %d\n", errorCode);
}
}
} else
@@ -648,7 +655,7 @@ cl_program b3OpenCLUtils_compileCLProgramFromString(cl_context clContext, cl_dev
{
DWORD errorCode;
errorCode = GetLastError();
printf("\nGetFileTime errorCode = %d\n", errorCode);
b3Warning("\nGetFileTime errorCode = %d\n", errorCode);
} else
{
binaryFileValid = 1;
@@ -680,7 +687,7 @@ cl_program b3OpenCLUtils_compileCLProgramFromString(cl_context clContext, cl_dev
{
DWORD errorCode;
errorCode = GetLastError();
printf("\nGetFileTime errorCode = %d\n", errorCode);
b3Warning("\nGetFileTime errorCode = %d\n", errorCode);
}
if ( ( modtimeSrc.dwHighDateTime < modtimeBinary.dwHighDateTime)
||(( modtimeSrc.dwHighDateTime == modtimeBinary.dwHighDateTime)&&(modtimeSrc.dwLowDateTime <= modtimeBinary.dwLowDateTime)))
@@ -688,7 +695,7 @@ cl_program b3OpenCLUtils_compileCLProgramFromString(cl_context clContext, cl_dev
fileUpToDate=1;
} else
{
printf("\nCached binary file out-of-date (%s)\n",binaryFileName);
b3Warning("\nCached binary file out-of-date (%s)\n",binaryFileName);
}
CloseHandle(srcFileHandle);
}
@@ -701,17 +708,17 @@ cl_program b3OpenCLUtils_compileCLProgramFromString(cl_context clContext, cl_dev
{
case ERROR_FILE_NOT_FOUND:
{
printf("\nSrc file not found %s\n", clFileNameForCaching);
b3Warning("\nSrc file not found %s\n", clFileNameForCaching);
break;
}
case ERROR_PATH_NOT_FOUND:
{
printf("\nSrc path not found %s\n", clFileNameForCaching);
b3Warning("\nSrc path not found %s\n", clFileNameForCaching);
break;
}
default:
{
printf("\nnSrc file reading errorCode = %d\n", errorCode);
b3Warning("\nnSrc file reading errorCode = %d\n", errorCode);
}
}
@@ -763,7 +770,7 @@ cl_program b3OpenCLUtils_compileCLProgramFromString(cl_context clContext, cl_dev
build_log = (char*)malloc(sizeof(char)*(ret_val_size+1));
clGetProgramBuildInfo(m_cpProgram, device, CL_PROGRAM_BUILD_LOG, ret_val_size, build_log, NULL);
build_log[ret_val_size] = '\0';
printf("%s\n", build_log);
b3Error("%s\n", build_log);
free (build_log);
b3Assert(0);
m_cpProgram = 0;
@@ -861,7 +868,7 @@ cl_program b3OpenCLUtils_compileCLProgramFromString(cl_context clContext, cl_dev
build_log[ret_val_size] = '\0';
printf("Error in clBuildProgram, Line %u in file %s, Log: \n%s\n !!!\n\n", __LINE__, __FILE__, build_log);
b3Error("Error in clBuildProgram, Line %u in file %s, Log: \n%s\n !!!\n\n", __LINE__, __FILE__, build_log);
free (build_log);
if (pErrNum)
*pErrNum = localErrNum;
@@ -904,7 +911,7 @@ cl_program b3OpenCLUtils_compileCLProgramFromString(cl_context clContext, cl_dev
fclose( file );
} else
{
printf("cannot write file %s\n", binaryFileName);
b3Warning("cannot write file %s\n", binaryFileName);
}
}
@@ -928,7 +935,7 @@ cl_kernel b3OpenCLUtils_compileCLKernelFromString(cl_context clContext, cl_devic
cl_program m_cpProgram = prog;
printf("compiling kernel %s ",kernelName);
b3Printf("compiling kernel %s ",kernelName);
if (!m_cpProgram)
{
@@ -940,7 +947,7 @@ cl_kernel b3OpenCLUtils_compileCLKernelFromString(cl_context clContext, cl_devic
kernel = clCreateKernel(m_cpProgram, kernelName, &localErrNum);
if (localErrNum != CL_SUCCESS)
{
printf("Error in clCreateKernel, Line %u in file %s, cannot find kernel function %s !!!\n\n", __LINE__, __FILE__, kernelName);
b3Error("Error in clCreateKernel, Line %u in file %s, cannot find kernel function %s !!!\n\n", __LINE__, __FILE__, kernelName);
assert(0);
if (pErrNum)
*pErrNum = localErrNum;
@@ -951,7 +958,7 @@ cl_kernel b3OpenCLUtils_compileCLKernelFromString(cl_context clContext, cl_devic
{
clReleaseProgram(m_cpProgram);
}
printf("ready. \n");
b3Printf("ready. \n");
if (pErrNum)

View File

@@ -36,7 +36,7 @@ int b3OpenCLUtils_getNumDevices(cl_context cxMainContext);
cl_device_id b3OpenCLUtils_getDevice(cl_context cxMainContext, int nr);
void b3OpenCLUtils_printDeviceInfo(FILE* f, cl_device_id device);
void b3OpenCLUtils_printDeviceInfo(cl_device_id device);
cl_kernel b3OpenCLUtils_compileCLKernelFromString( cl_context clContext,cl_device_id device, const char* kernelSource, const char* kernelName, cl_int* pErrNum, cl_program prog,const char* additionalMacros);
@@ -50,7 +50,7 @@ int b3OpenCLUtils_getNumPlatforms(cl_int* pErrNum);
cl_platform_id b3OpenCLUtils_getPlatform(int nr, cl_int* pErrNum);
void b3OpenCLUtils_printPlatformInfo(FILE* f, cl_platform_id platform);
void b3OpenCLUtils_printPlatformInfo(cl_platform_id platform);
const char* b3OpenCLUtils_getSdkVendorName();
@@ -133,12 +133,7 @@ struct b3OpenCLUtils
static inline void printDeviceInfo(cl_device_id device)
{
b3OpenCLUtils_printDeviceInfo(stdout, device);
}
static inline void printDeviceInfo(FILE* f, cl_device_id device)
{
b3OpenCLUtils_printDeviceInfo(f,device);
b3OpenCLUtils_printDeviceInfo(device);
}
static inline cl_kernel compileCLKernelFromString( cl_context clContext,cl_device_id device, const char* kernelSource, const char* kernelName, cl_int* pErrNum=0, cl_program prog=0,const char* additionalMacros = "" )
@@ -167,12 +162,7 @@ struct b3OpenCLUtils
static inline void printPlatformInfo(cl_platform_id platform)
{
b3OpenCLUtils_printPlatformInfo(stdout, platform);
}
static inline void printPlatformInfo(FILE* f, cl_platform_id platform)
{
b3OpenCLUtils_printPlatformInfo(f,platform);
b3OpenCLUtils_printPlatformInfo(platform);
}
static inline const char* getSdkVendorName()

View File

@@ -22,33 +22,53 @@ cl_context g_cxMainContext;
cl_command_queue g_cqCommandQue;
#include "Bullet3Common/b3Logging.h"
#include <Windows.h>
void myprintf(const char* msg)
{
#ifdef _WINDOWS
OutputDebugStringA(msg);
#else
printf(msg);
#endif
}
int main(int argc, char* argv[])
{
b3SetCustomPrintfFunc(myprintf);
b3SetCustomWarningMessageFunc(myprintf);
b3SetCustomErrorMessageFunc(myprintf);
b3Printf("test b3Printf\n");
b3Warning("test warning\n");
b3Error("test error\n");
int ciErrNum = 0;
cl_device_type deviceType = CL_DEVICE_TYPE_ALL;
const char* vendorSDK = b3OpenCLUtils::getSdkVendorName();
printf("This program was compiled using the %s OpenCL SDK\n",vendorSDK);
b3Printf("This program was compiled using the %s OpenCL SDK\n",vendorSDK);
int numPlatforms = b3OpenCLUtils::getNumPlatforms();
printf("Num Platforms = %d\n", numPlatforms);
b3Printf("Num Platforms = %d\n", numPlatforms);
for (int i=0;i<numPlatforms;i++)
{
cl_platform_id platform = b3OpenCLUtils::getPlatform(i);
b3OpenCLPlatformInfo platformInfo;
b3OpenCLUtils::getPlatformInfo(platform,&platformInfo);
printf("--------------------------------\n");
printf("Platform info for platform nr %d:\n",i);
printf(" CL_PLATFORM_VENDOR: \t\t\t%s\n",platformInfo.m_platformVendor);
printf(" CL_PLATFORM_NAME: \t\t\t%s\n",platformInfo.m_platformName);
printf(" CL_PLATFORM_VERSION: \t\t\t%s\n",platformInfo.m_platformVersion);
b3Printf("--------------------------------\n");
b3Printf("Platform info for platform nr %d:\n",i);
b3Printf(" CL_PLATFORM_VENDOR: \t\t\t%s\n",platformInfo.m_platformVendor);
b3Printf(" CL_PLATFORM_NAME: \t\t\t%s\n",platformInfo.m_platformName);
b3Printf(" CL_PLATFORM_VERSION: \t\t\t%s\n",platformInfo.m_platformVersion);
cl_context context = b3OpenCLUtils::createContextFromPlatform(platform,deviceType,&ciErrNum);
int numDevices = b3OpenCLUtils::getNumDevices(context);
printf("Num Devices = %d\n", numDevices);
b3Printf("Num Devices = %d\n", numDevices);
for (int j=0;j<numDevices;j++)
{
cl_device_id dev = b3OpenCLUtils::getDevice(context,j);
@@ -65,7 +85,7 @@ int main(int argc, char* argv[])
void* glCtx=0;
void* glDC = 0;
printf("Initialize OpenCL using b3OpenCLUtils::createContextFromType for CL_DEVICE_TYPE_GPU\n");
b3Printf("Initialize OpenCL using b3OpenCLUtils::createContextFromType for CL_DEVICE_TYPE_GPU\n");
g_cxMainContext = b3OpenCLUtils::createContextFromType(deviceType, &ciErrNum, glCtx, glDC);
oclCHECKERROR(ciErrNum, CL_SUCCESS);
@@ -92,9 +112,9 @@ int main(int argc, char* argv[])
}
else {
printf("No OpenCL capable GPU found!");
b3Printf("No OpenCL capable GPU found!");
}
printf("press <Enter>\n");
b3Printf("press <Enter>\n");
getchar();
return 0;
}

View File

@@ -19,7 +19,8 @@ function createProject(vendor)
files {
"main.cpp",
"../../../src/Bullet3OpenCL/Initialize/b3OpenCLUtils.cpp",
"../../../src/Bullet3OpenCL/Initialize/b3OpenCLUtils.h"
"../../../src/Bullet3OpenCL/Initialize/b3OpenCLUtils.h",
"../../../src/Bullet3Common/b3Logging.cpp",
}
end

View File

@@ -24,7 +24,9 @@ function createProject(vendor)
"../../../src/Bullet3Common/b3Quickprof.cpp",
"../../../src/Bullet3Common/b3Quickprof.h",
"../../../src/Bullet3OpenCL/Initialize/b3OpenCLUtils.cpp",
"../../../src/Bullet3OpenCL/Initialize/b3OpenCLUtils.h"
"../../../src/Bullet3OpenCL/Initialize/b3OpenCLUtils.h",
"../../../src/Bullet3Common/b3Logging.cpp",
"../../../src/Bullet3Common/b3Logging.h",
}
end

View File

@@ -30,6 +30,9 @@ function createProject(vendor)
"../../../src/Bullet3Common/b3AlignedAllocator.cpp",
"../../../src/Bullet3Common/b3AlignedAllocator.h",
"../../../src/Bullet3Common/b3AlignedObjectArray.h",
"../../../src/Bullet3Common/b3Logging.cpp",
"../../../src/Bullet3Common/b3Logging.h",
}
end

View File

@@ -639,17 +639,23 @@ void b3CommandLineArgs::GetCmdLineArgument<char*>(const char* arg_name, char* &v
extern bool gDebugSkipLoadingBinary;
void myprintf(const char* msg)
{
(void*) msg;
}
int main( int argc, char** argv)
{
//gDebugSkipLoadingBinary = true;
// b3SetCustomPrintfFunc(myprintf);
cl_int ciErrNum;
b3CommandLineArgs args(argc,argv);
args.GetCmdLineArgument("deviceId", gPreferredDeviceId);
args.GetCmdLineArgument("platformId", gPreferredPlatformId);
printf("Initialize OpenCL using b3OpenCLUtils_createContextFromType\n");
b3Printf("Initialize OpenCL using b3OpenCLUtils_createContextFromType\n");
cl_platform_id platformId;
// g_cxMainContext = b3OpenCLUtils_createContextFromType(CL_DEVICE_TYPE_ALL, &ciErrNum, 0, 0,gPreferredDeviceId,gPreferredPlatformId,&platformId);
g_cxMainContext = b3OpenCLUtils_createContextFromType(CL_DEVICE_TYPE_GPU, &ciErrNum, 0, 0,gPreferredDeviceId,gPreferredPlatformId,&platformId);
@@ -661,12 +667,12 @@ int main( int argc, char** argv)
if (!numDev)
{
printf("error: no OpenCL devices\n");
b3Error("error: no OpenCL devices\n");
exit(0);
}
int devId = 0;
g_device = b3OpenCLUtils_getDevice(g_cxMainContext,devId);
b3OpenCLUtils_printDeviceInfo(stdout, g_device);
b3OpenCLUtils_printDeviceInfo(g_device);
// create a command-queue
g_cqCommandQueue = clCreateCommandQueue(g_cxMainContext, g_device, 0, &ciErrNum);
oclCHECKERROR(ciErrNum, CL_SUCCESS);

View File

@@ -29,6 +29,9 @@ function createProject(vendor)
"../../../src/Bullet3Common/b3AlignedObjectArray.h",
"../../../src/Bullet3Common/b3Quickprof.cpp",
"../../../src/Bullet3Common/b3Quickprof.h",
"../../../src/Bullet3Common/b3Logging.cpp",
"../../../src/Bullet3Common/b3Logging.h",
}
end