add Intel build support for the OpenCL cloth demo, and use the bullet_logo.png

Thanks to ggjunker for the patch, see Issue 533
This commit is contained in:
erwin.coumans
2011-09-13 01:52:42 +00:00
parent c8b3c9e306
commit 1e360bdb6b
28 changed files with 4885 additions and 812 deletions

View File

@@ -45,8 +45,8 @@ IF (USE_GLUT)
# ${BULLET_PHYSICS_SOURCE_DIR}/Demos/OpenGL/GLDebugDrawer.cpp
../gl_win.cpp
../clstuff.cpp
../bmpLoader.cpp
../bmpLoader.h
../clstuff.h
../gl_win.h
../cloth.h
@@ -73,8 +73,7 @@ IF (NOT INTERNAL_CREATE_DISTRIBUTABLE_MSVC_PROJECTFILES)
ENDIF(CMAKE_CL_64)
ENDIF(WIN32)
ADD_CUSTOM_COMMAND( TARGET AppOpenCLClothDemo_AMD POST_BUILD
COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different ${BULLET_PHYSICS_SOURCE_DIR}/Demos/OpenCLClothDemo/amdFlag.bmp ${CMAKE_CURRENT_BINARY_DIR}
COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different ${BULLET_PHYSICS_SOURCE_DIR}/Demos/OpenCLClothDemo/atiFlag.bmp ${CMAKE_CURRENT_BINARY_DIR}
COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different ${BULLET_PHYSICS_SOURCE_DIR}/bullet_logo.png ${CMAKE_CURRENT_BINARY_DIR}
)
ENDIF(NOT INTERNAL_CREATE_DISTRIBUTABLE_MSVC_PROJECTFILES)

View File

@@ -39,8 +39,6 @@ IF (USE_GLUT)
${BULLET_PHYSICS_SOURCE_DIR}/Demos/SharedOpenCL/btOclCommon.cpp
../gl_win.cpp
../clstuff.cpp
../bmpLoader.cpp
../bmpLoader.h
../clstuff.h
../gl_win.h

View File

@@ -1,5 +1,9 @@
SUBDIRS( MiniCL )
IF(BUILD_INTEL_OPENCL_DEMOS)
SUBDIRS(Intel)
ENDIF()
IF(BUILD_AMD_OPENCL_DEMOS)
SUBDIRS(AMD)
ENDIF()

View File

@@ -0,0 +1,86 @@
INCLUDE_DIRECTORIES(
${BULLET_PHYSICS_SOURCE_DIR}/src
${BULLET_PHYSICS_SOURCE_DIR}/Demos/SharedOpenCL
${BULLET_PHYSICS_SOURCE_DIR}/Demos/OpenGL
${INTEL_OPENCL_INCLUDES}
)
ADD_DEFINITIONS(-DUSE_INTEL_OPENCL)
ADD_DEFINITIONS(-DCL_PLATFORM_INTEL)
IF (CMAKE_CL_64)
SET(CMAK_GLEW_LIBRARY
${BULLET_PHYSICS_SOURCE_DIR}/Glut/glew64.lib )
ELSE(CMAKE_CL_64)
SET(CMAK_GLEW_LIBRARY ${BULLET_PHYSICS_SOURCE_DIR}/Glut/glew32.lib )
ENDIF(CMAKE_CL_64)
IF (USE_GLUT)
LINK_LIBRARIES(
OpenGLSupport
BulletSoftBodySolvers_OpenCL_Intel
BulletMultiThreaded
BulletSoftBody
BulletDynamics
BulletCollision
LinearMath
${GLUT_glut_LIBRARY}
${OPENGL_gl_LIBRARY}
${OPENGL_glu_LIBRARY}
${CMAK_GLEW_LIBRARY}
${INTEL_OPENCL_LIBRARIES}
)
ADD_EXECUTABLE(AppOpenCLClothDemo_Intel
../cl_cloth_demo.cpp
${BULLET_PHYSICS_SOURCE_DIR}/Demos/SharedOpenCL/btOclUtils.h
${BULLET_PHYSICS_SOURCE_DIR}/Demos/SharedOpenCL/btOclCommon.h
${BULLET_PHYSICS_SOURCE_DIR}/Demos/SharedOpenCL/btOclUtils.cpp
${BULLET_PHYSICS_SOURCE_DIR}/Demos/SharedOpenCL/btOclCommon.cpp
# ${BULLET_PHYSICS_SOURCE_DIR}/Demos/OpenGL/GLDebugDrawer.cpp
../gl_win.cpp
../clstuff.cpp
../clstuff.h
../gl_win.h
../cloth.h
)
ELSE (USE_GLUT)
ENDIF (USE_GLUT)
IF (NOT INTERNAL_CREATE_DISTRIBUTABLE_MSVC_PROJECTFILES)
IF(WIN32)
IF (CMAKE_CL_64)
ADD_CUSTOM_COMMAND( TARGET AppOpenCLClothDemo_Intel POST_BUILD
COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different ${BULLET_PHYSICS_SOURCE_DIR}/glut64.dll ${CMAKE_CURRENT_BINARY_DIR}
)
ADD_CUSTOM_COMMAND( TARGET AppOpenCLClothDemo_Intel POST_BUILD
COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different ${BULLET_PHYSICS_SOURCE_DIR}/GLEW64.DLL ${CMAKE_CURRENT_BINARY_DIR})
ELSE(CMAKE_CL_64)
ADD_CUSTOM_COMMAND( TARGET AppOpenCLClothDemo_Intel POST_BUILD
COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different ${BULLET_PHYSICS_SOURCE_DIR}/GLUT32.DLL ${CMAKE_CURRENT_BINARY_DIR}
)
ADD_CUSTOM_COMMAND( TARGET AppOpenCLClothDemo_Intel POST_BUILD
COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different ${BULLET_PHYSICS_SOURCE_DIR}/GLEW32.DLL ${CMAKE_CURRENT_BINARY_DIR})
ENDIF(CMAKE_CL_64)
ENDIF(WIN32)
ADD_CUSTOM_COMMAND( TARGET AppOpenCLClothDemo_Intel POST_BUILD
COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different ${BULLET_PHYSICS_SOURCE_DIR}/bullet_logo.png ${CMAKE_CURRENT_BINARY_DIR}
)
ENDIF(NOT INTERNAL_CREATE_DISTRIBUTABLE_MSVC_PROJECTFILES)
IF (UNIX)
TARGET_LINK_LIBRARIES(AppOpenCLClothDemo_Intel pthread)
ENDIF(UNIX)
IF (INTERNAL_ADD_POSTFIX_EXECUTABLE_NAMES)
SET_TARGET_PROPERTIES(AppOpenCLClothDemo_Intel PROPERTIES DEBUG_POSTFIX "_Debug")
SET_TARGET_PROPERTIES(AppOpenCLClothDemo_Intel PROPERTIES MINSIZEREL_POSTFIX "_MinsizeRel")
SET_TARGET_PROPERTIES(AppOpenCLClothDemo_Intel PROPERTIES RELWITHDEBINFO_POSTFIX "_RelWithDebugInfo")
ENDIF(INTERNAL_ADD_POSTFIX_EXECUTABLE_NAMES)

View File

@@ -40,8 +40,6 @@ IF (USE_GLUT)
../cl_cloth_demo.cpp
../gl_win.cpp
../clstuff.cpp
../bmpLoader.cpp
../bmpLoader.h
../clstuff.h
../gl_win.h
${BULLET_PHYSICS_SOURCE_DIR}/src/BulletMultiThreaded/GpuSoftBodySolvers/OpenCL/MiniCL/MiniCLTaskWrap.cpp
@@ -77,8 +75,7 @@ ENDIF(WIN32)
IF(NOT INTERNAL_CREATE_DISTRIBUTABLE_MSVC_PROJECTFILES)
ADD_CUSTOM_COMMAND( TARGET AppOpenCLClothDemo_Mini POST_BUILD
COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different ${BULLET_PHYSICS_SOURCE_DIR}/Demos/OpenCLClothDemo/amdFlag.bmp ${CMAKE_CURRENT_BINARY_DIR}
COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different ${BULLET_PHYSICS_SOURCE_DIR}/Demos/OpenCLClothDemo/atiFlag.bmp ${CMAKE_CURRENT_BINARY_DIR}
COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different ${BULLET_PHYSICS_SOURCE_DIR}/bullet_logo.png ${CMAKE_CURRENT_BINARY_DIR}
)
ENDIF()
IF (UNIX)

View File

@@ -46,8 +46,6 @@ IF (USE_GLUT)
${BULLET_PHYSICS_SOURCE_DIR}/Demos/SharedOpenCL/btOclCommon.cpp
../gl_win.cpp
../clstuff.cpp
../bmpLoader.cpp
../bmpLoader.h
../clstuff.h
../gl_win.h

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 MiB

View File

@@ -1,325 +0,0 @@
/*
Bullet Continuous Collision Detection and Physics Library
Copyright (c) 2010 Advanced Micro Devices
This software is provided 'as-is', without any express or implied warranty.
In no event will the authors be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it freely,
subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "bmpLoader.h"
#include <new>
#include <cstring>
#include <cstdio>
namespace amd
{
static const short bitMapID = 19778;
void
BitMap::releaseResources(void)
{
if (pixels_ != NULL) {
delete[] pixels_;
}
if (colors_ != NULL) {
delete[] colors_;
}
pixels_ = NULL;
colors_ = NULL;
isLoaded_ = false;
}
BitMap& BitMap::operator=(const BitMap& rhs)
{
if (this == &rhs) {
return *this;
}
// Copy header
id = rhs.id;
size = rhs.size;
reserved1 = rhs.reserved1;
reserved2 = rhs.reserved2;
offset = rhs.offset;
// Copy header info
sizeInfo = rhs.sizeInfo;
width = rhs.width;
height = rhs.height;
planes = rhs.planes;
bitsPerPixel = rhs.bitsPerPixel;
compression = rhs.compression;
imageSize = rhs.imageSize;
xPelsPerMeter = rhs.xPelsPerMeter;
yPelsPerMeter = rhs.yPelsPerMeter;
clrUsed = rhs.clrUsed;
clrImportant = rhs.clrImportant;
numColors_ = rhs.numColors_;
isLoaded_ = rhs.isLoaded_;
pixels_ = NULL;
colors_ = NULL;
if (isLoaded_) {
if (rhs.colors_ != NULL) {
colors_ = new ColorPalette[numColors_];
if (colors_ == NULL) {
isLoaded_ = false;
return *this;
}
memcpy(colors_, rhs.colors_, numColors_ * sizeof(ColorPalette));
}
pixels_ = new uchar4[width * height];
if (pixels_ == NULL) {
delete[] colors_;
colors_ = NULL;
isLoaded_ = false;
return *this;
}
memcpy(pixels_, rhs.pixels_, width * height * sizeof(uchar4));
}
return *this;
}
void
BitMap::load(const char * filename)
{
// Release any existing resources
releaseResources();
// Open BMP file
FILE * fd = fopen(filename, "rb");
// Opened OK
if (fd != NULL) {
// Read header
fread((BitMapHeader *)this, sizeof(BitMapHeader), 1, fd);
// Failed to read header
if (ferror(fd)) {
fclose(fd);
return;
}
// Confirm that we have a bitmap file
if (id != bitMapID) {
fclose(fd);
return;
}
// Read map info header
fread((BitMapInfoHeader *)this, sizeof(BitMapInfoHeader), 1, fd);
// Failed to read map info header
if (ferror(fd)) {
fclose(fd);
return;
}
// No support for compressed images
if (compression) {
fclose(fd);
return;
}
// Support only 8 or 24 bits images
if (bitsPerPixel < 8) {
fclose(fd);
return;
}
// Store number of colors
numColors_ = 1 << bitsPerPixel;
//load the palate for 8 bits per pixel
if(bitsPerPixel == 8) {
colors_ = new ColorPalette[numColors_];
if (colors_ == NULL) {
fclose(fd);
return;
}
fread(
(char *)colors_,
numColors_ * sizeof(ColorPalette),
1,
fd);
// Failed to read colors
if (ferror(fd)) {
fclose(fd);
return;
}
}
// Allocate buffer to hold all pixels
unsigned int sizeBuffer = size - offset;
unsigned char * tmpPixels = new unsigned char[sizeBuffer];
if (tmpPixels == NULL) {
delete colors_;
colors_ = NULL;
fclose(fd);
return;
}
// Read pixels from file, including any padding
fread(tmpPixels, sizeBuffer * sizeof(unsigned char), 1, fd);
// Failed to read pixel data
if (ferror(fd)) {
delete colors_;
colors_ = NULL;
delete tmpPixels;
fclose(fd);
return;
}
// Allocate image
pixels_ = new uchar4[width * height];
if (pixels_ == NULL) {
delete colors_;
colors_ = NULL;
delete tmpPixels;
fclose(fd);
return;
}
// Set image, including w component (white)
memset(pixels_, 0xff, width * height * sizeof(uchar4));
unsigned int index = 0;
for(int y = 0; y < height; y++) {
for(int x = 0; x < width; x++) {
// Read RGB values
if (bitsPerPixel == 8) {
pixels_[(y * width + x)] = colors_[tmpPixels[index++]];
}
else { // 24 bit
pixels_[(y * width + x)].z = tmpPixels[index++];
pixels_[(y * width + x)].y = tmpPixels[index++];
pixels_[(y * width + x)].x = tmpPixels[index++];
}
}
// Handle padding
for(int x = 0; x < (4 - (3 * width) % 4) % 4; x++) {
index++;
}
}
// Loaded file so we can close the file.
fclose(fd);
delete[] tmpPixels;
// Loaded file so record this fact
isLoaded_ = true;
}
}
int
BitMap::colorIndex(uchar4 color)
{
for (int i = 0; i < numColors_; i++) {
if (colors_[i].x == color.x &&
colors_[i].y == color.y &&
colors_[i].z == color.z &&
colors_[i].w == color.w) {
return i;
}
}
return 0;
}
bool
BitMap::write(const char * filename)
{
if (!isLoaded_) {
return false;
}
// Open BMP file
FILE * fd = fopen(filename, "wb");
// Opened OK
if (fd != NULL) {
// Write header
fwrite((BitMapHeader *)this, sizeof(BitMapHeader), 1, fd);
// Failed to write header
if (ferror(fd)) {
fclose(fd);
return false;
}
// Write map info header
fwrite((BitMapInfoHeader *)this, sizeof(BitMapInfoHeader), 1, fd);
// Failed to write map info header
if (ferror(fd)) {
fclose(fd);
return false;
}
// Write palate for 8 bits per pixel
if(bitsPerPixel == 8) {
fwrite(
(char *)colors_,
numColors_ * sizeof(ColorPalette),
1,
fd);
// Failed to write colors
if (ferror(fd)) {
fclose(fd);
return false;
}
}
for(int y = 0; y < height; y++) {
for(int x = 0; x < width; x++) {
// Read RGB values
if (bitsPerPixel == 8) {
fputc(
colorIndex(
pixels_[(y * width + x)]),
fd);
}
else { // 24 bit
fputc(pixels_[(y * width + x)].z, fd);
fputc(pixels_[(y * width + x)].y, fd);
fputc(pixels_[(y * width + x)].x, fd);
if (ferror(fd)) {
fclose(fd);
return false;
}
}
}
// Add padding
for(int x = 0; x < (4 - (3 * width) % 4) % 4; x++) {
fputc(0, fd);
}
}
return true;
}
return false;
}
} // amd

View File

@@ -1,200 +0,0 @@
/*
Bullet Continuous Collision Detection and Physics Library
Copyright (c) 2010 Advanced Micro Devices
This software is provided 'as-is', without any express or implied warranty.
In no event will the authors be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it freely,
subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#ifndef BMPLOADER_H_
#define BMPLOADER_H_
#include <stdlib.h>
namespace amd
{
//! @fixme this needs to be moved to common types header?
#pragma pack(1)
typedef struct
{
unsigned char x;
unsigned char y;
unsigned char z;
unsigned char w;
} uchar4;
typedef uchar4 ColorPalette;
//! \struct Bitmap header info
typedef struct {
short id;
int size;
short reserved1;
short reserved2;
int offset;
} BitMapHeader;
//! \struct Bitmap info header
typedef struct {
int sizeInfo;
int width;
int height;
short planes;
short bitsPerPixel;
unsigned compression;
unsigned imageSize;
int xPelsPerMeter;
int yPelsPerMeter;
int clrUsed;
int clrImportant;
} BitMapInfoHeader;
//! \class Bitmap used to load a bitmap image from a file.
class BitMap : public BitMapHeader, public BitMapInfoHeader
{
private:
uchar4 * pixels_;
int numColors_;
ColorPalette * colors_;
bool isLoaded_;
void releaseResources(void);
int colorIndex(uchar4 color);
public:
//! \brief Default constructor
BitMap()
: pixels_(NULL),
numColors_(0),
colors_(NULL),
isLoaded_(false)
{}
/*!\brief Constructor
*
* Tries to load bitmap image from filename provided.
*
* \param filename pointer to null terminated string that is the path and
* filename to the bitmap image to be loaded.
*
* In the base of an error, e.g. the bitmap file could not be loaded for
* some reason, then a following call to isLoaded will return false.
*/
BitMap(const char * filename)
: pixels_(NULL),
numColors_(0),
colors_(NULL),
isLoaded_(false)
{
load(filename);
}
/*! \brief Copy constructor
*
* \param rhs is the bitmap to be copied (cloned).
*/
BitMap(const BitMap& rhs)
{
*this = rhs;
}
//! \brief Destructor
~BitMap()
{
releaseResources();
}
/*! \brief Assignment
* \param rhs is the bitmap to be assigned (cloned).
*/
BitMap& operator=(const BitMap& rhs);
/*! \brief Load Bitmap image
*
* \param filename is a pointer to a null terminated string that is the
* path and filename name to the the bitmap file to be loaded.
*
* In the base of an error, e.g. the bitmap file could not be loaded for
* some reason, then a following call to isLoaded will return false.
*/
void
load(const char * filename);
/*! \brief Write Bitmap image
*
* \param filename is a pointer to a null terminated string that is the
* path and filename name to the the bitmap file to be written.
*
* \return In the case that the bitmap is written true is returned. In
* the case that a bitmap image is not already loaded or the write fails
* for some reason false is returned.
*/
bool
write(const char * filename);
/*! \brief Get image width
*
* \return If a bitmap image has been successfully loaded, then the width
* image is returned, otherwise -1;
*/
int
getWidth(void) const
{
if (isLoaded_) {
return width;
}
else {
return -1;
}
}
/*! \brief Get image height
*
* \return If a bitmap image has been successfully loaded, then the height
* image is returned, otherwise -1.
*/
int
getHeight(void) const
{
if (isLoaded_) {
return height;
}
else {
return -1;
}
}
/*! \brief Get image width
*
* \return If a bitmap image has been successfully loaded, then returns
* a pointer to image's pixels, otherwise NULL.
*/
const uchar4 *
getPixels(void) const { return pixels_; }
/*! \brief Is an image currently loaded
*
* \return If a bitmap image has been successfully loaded, then returns
* true, otherwise if an image could not be loaded or an image has yet
* to be loaded false is returned.
*/
bool
isLoaded(void) const { return isLoaded_; }
};
#pragma pack()
}
#endif // BMPLOADER_H_

View File

@@ -1,189 +0,0 @@
//
// Copyright (c) 2008 Advanced Micro Devices, Inc. All rights reserved.
//
#ifndef BMPLOADER_H_
#define BMPLOADER_H_
#include <cstdlib>
#include <iostream>
namespace amd
{
//! @fixme this needs to be moved to common types header?
#pragma pack(1)
typedef struct
{
unsigned char x;
unsigned char y;
unsigned char z;
unsigned char w;
} uchar4;
typedef uchar4 ColorPalette;
//! \struct Bitmap header info
typedef struct {
short id;
int size;
short reserved1;
short reserved2;
int offset;
} BitMapHeader;
//! \struct Bitmap info header
typedef struct {
int sizeInfo;
int width;
int height;
short planes;
short bitsPerPixel;
unsigned compression;
unsigned imageSize;
int xPelsPerMeter;
int yPelsPerMeter;
int clrUsed;
int clrImportant;
} BitMapInfoHeader;
//! \class Bitmap used to load a bitmap image from a file.
class BitMap : public BitMapHeader, public BitMapInfoHeader
{
private:
uchar4 * pixels_;
int numColors_;
ColorPalette * colors_;
bool isLoaded_;
void releaseResources(void);
int colorIndex(uchar4 color);
public:
//! \brief Default constructor
BitMap()
: pixels_(NULL),
numColors_(0),
colors_(NULL),
isLoaded_(false)
{}
/*!\brief Constructor
*
* Tries to load bitmap image from filename provided.
*
* \param filename pointer to null terminated string that is the path and
* filename to the bitmap image to be loaded.
*
* In the base of an error, e.g. the bitmap file could not be loaded for
* some reason, then a following call to isLoaded will return false.
*/
BitMap(const char * filename)
: pixels_(NULL),
numColors_(0),
colors_(NULL),
isLoaded_(false)
{
load(filename);
}
/*! \brief Copy constructor
*
* \param rhs is the bitmap to be copied (cloned).
*/
BitMap(const BitMap& rhs)
{
*this = rhs;
}
//! \brief Destructor
~BitMap()
{
releaseResources();
}
/*! \brief Assignment
* \param rhs is the bitmap to be assigned (cloned).
*/
BitMap& operator=(const BitMap& rhs);
/*! \brief Load Bitmap image
*
* \param filename is a pointer to a null terminated string that is the
* path and filename name to the the bitmap file to be loaded.
*
* In the base of an error, e.g. the bitmap file could not be loaded for
* some reason, then a following call to isLoaded will return false.
*/
void
load(const char * filename);
/*! \brief Write Bitmap image
*
* \param filename is a pointer to a null terminated string that is the
* path and filename name to the the bitmap file to be written.
*
* \return In the case that the bitmap is written true is returned. In
* the case that a bitmap image is not already loaded or the write fails
* for some reason false is returned.
*/
bool
write(const char * filename);
/*! \brief Get image width
*
* \return If a bitmap image has been successfully loaded, then the width
* image is returned, otherwise -1;
*/
int
getWidth(void) const
{
if (isLoaded_) {
return width;
}
else {
return -1;
}
}
/*! \brief Get image height
*
* \return If a bitmap image has been successfully loaded, then the height
* image is returned, otherwise -1.
*/
int
getHeight(void) const
{
if (isLoaded_) {
return height;
}
else {
return -1;
}
}
/*! \brief Get image width
*
* \return If a bitmap image has been successfully loaded, then returns
* a pointer to image's pixels, otherwise NULL.
*/
const uchar4 *
getPixels(void) const { return pixels_; }
/*! \brief Is an image currently loaded
*
* \return If a bitmap image has been successfully loaded, then returns
* true, otherwise if an image could not be loaded or an image has yet
* to be loaded false is returned.
*/
bool
isLoaded(void) const { return isLoaded_; }
};
#pragma pack()
}
#endif // BMPLOADER_H_

View File

@@ -41,7 +41,7 @@ const int numFlags = 5;
const int clothWidth = 40;
const int clothHeight = 60;//60;
float _windAngle = 1.0;//0.4;
float _windStrength = 15;
float _windStrength = 10.;
@@ -256,7 +256,7 @@ void createFlag( btSoftBodySolver &solver, int width, int height, btAlignedObjec
}
float rotateAngleRoundZ = 0.5;
float rotateAngleRoundZ = 0.0;
float rotateAngleRoundX = 0.5;
btMatrix3x3 defaultRotate;
defaultRotate[0] = btVector3(cos(rotateAngleRoundZ), sin(rotateAngleRoundZ), 0.f);
@@ -589,8 +589,8 @@ int main(int argc, char *argv[])
m_dynamicsWorld->stepSimulation(1./60.,0);
std::string flagTexs[] = {
"atiFlag.bmp",
"amdFlag.bmp",
"bullet_logo.png",
"bullet_logo.png",
};
int numFlagTexs = 2;

View File

@@ -16,7 +16,8 @@ subject to the following restrictions:
#include "gl_win.h" //for OpenGL stuff
#include "bmpLoader.h"
#include "stb_image.h"
#include <string>
#include <cstring>
#include "LinearMath/btScalar.h"
@@ -84,7 +85,7 @@ class piece_of_cloth
glEnable(GL_DEPTH_TEST);
glColor3f(0.0f, 1.0f, 1.0f);
glColor3f(1.0f, 1.0f, 1.0f);
#ifdef USE_GPU_COPY
int error = 0;
glBindBuffer(GL_ARRAY_BUFFER, clothVBO);
@@ -134,82 +135,60 @@ class piece_of_cloth
void create_texture(std::string filename)
{
amd::BitMap texBMP(filename.c_str());
int width,height,n;
unsigned char *data = stbi_load(filename.c_str(), &width, &height, &n, 0);
if ( !texBMP.isLoaded() )
{
//alternative path
char newPath[1024];
sprintf(newPath,"Demos/OpenCLClothDemo/%s",filename.c_str());
texBMP.load(newPath);
if (!texBMP.isLoaded())
GLubyte* image=new GLubyte[512*256*4];
for(int y=0;y<256;++y)
{
const int t=y>>4;
GLubyte* pi=image+y*512*4;
for(int x=0;x<512;++x)
{
sprintf(newPath,"../../../../../Demos/OpenCLClothDemo/%s",filename.c_str());
texBMP.load(newPath);
const int s=x>>5;
const GLubyte b=180;
GLubyte c=b+((s+t&1)&1)*(255-b);
pi[0]=pi[1]=pi[2]=c;pi[3]=1;pi+=4;
}
}
if ( texBMP.isLoaded() ) {
glEnable(GL_TEXTURE_2D);
glGenTextures(1, &m_texture);
glBindTexture(GL_TEXTURE_2D, m_texture);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
glTexImage2D(
GL_TEXTURE_2D,
0,
GL_RGBA8,
texBMP.getWidth(),
texBMP.getHeight(),
0,
GL_RGBA,
GL_UNSIGNED_BYTE,
texBMP.getPixels());
glBindTexture(GL_TEXTURE_2D, 0);
}
else {
printf("ERROR: could not load bitmap, using placeholder\n");
GLubyte* image=new GLubyte[256*256*3];
for(int y=0;y<256;++y)
if ( data )
{
for (int i=0;i<width;i++)
{
for (int j=0;j<height;j++)
{
const int t=y>>4;
GLubyte* pi=image+y*256*3;
for(int x=0;x<256;++x)
{
const int s=x>>4;
const GLubyte b=180;
GLubyte c=b+((s+t&1)&1)*(255-b);
pi[0]=pi[1]=pi[2]=c;pi+=3;
}
}
int offsetx = (512-width)/2;
int offsety = (256-height)/2;
glGenTextures(1,(GLuint*)&m_texture);
glBindTexture(GL_TEXTURE_2D,m_texture);
glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_MODULATE);
glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_LINEAR);
glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR_MIPMAP_LINEAR);
glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_REPEAT);
glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_REPEAT);
gluBuild2DMipmaps(GL_TEXTURE_2D,3,256,256,GL_RGB,GL_UNSIGNED_BYTE,image);
delete[] image;
GLubyte* pi=image+((j+offsety)*512+i+offsetx)*4;
const GLubyte* src=data+(j*width+i)*4;
pi[0] = src[0];
pi[1] = src[1];
pi[2] = src[2];
pi[3] = 1;
}
}
}
else
{
printf("ERROR: could not load bitmap, using placeholder\n");
}
glGenTextures(1,(GLuint*)&m_texture);
glBindTexture(GL_TEXTURE_2D,m_texture);
glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_MODULATE);
glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_LINEAR);
glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR_MIPMAP_LINEAR);
glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_REPEAT);
glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_REPEAT);
gluBuild2DMipmaps(GL_TEXTURE_2D,4,512,256,GL_RGBA,GL_UNSIGNED_BYTE,image);
delete[] image;
}
void create_buffers(int width_, int height_)
@@ -237,8 +216,8 @@ class piece_of_cloth
cpu_buffer[y*width+x].normal[0] = 1;
cpu_buffer[y*width+x].normal[1] = 0;
cpu_buffer[y*width+x].normal[2] = 0;
cpu_buffer[y*width+x].texcoord[0] = x/((float)(width-1));
cpu_buffer[y*width+x].texcoord[1] = y/((float)(height-1));
cpu_buffer[y*width+x].texcoord[0] = 1*x/((float)(width-1));
cpu_buffer[y*width+x].texcoord[1] = (1.f-4*y/((float)(height-1)));
}
}

View File

@@ -34,6 +34,8 @@ void initCL( void* glCtx, void* glDC )
#if defined(CL_PLATFORM_MINI_CL)
cl_device_type deviceType = CL_DEVICE_TYPE_CPU;//or use CL_DEVICE_TYPE_DEBUG to debug MiniCL
#elif defined(CL_PLATFORM_INTEL)
cl_device_type deviceType = CL_DEVICE_TYPE_CPU;
#elif defined(CL_PLATFORM_AMD)
cl_device_type deviceType = CL_DEVICE_TYPE_GPU;
#elif defined(CL_PLATFORM_NVIDIA)

Binary file not shown.

Before

Width:  |  Height:  |  Size: 768 KiB