improve loading performance of large textures:
option to disable tinyrenderer, use p.configureDebugVisualizer(p.COV_ENABLE_TINY_RENDERER,0) also make sure to use p.configureDebugVisualizer(p.COV_ENABLE_RENDERING,0) before loadURDF, and enable rendering afterwards using p.configureDebugVisualizer(p.COV_ENABLE_RENDERING,1) reorder 2 loops, making the flip texels twice as fast (cache coherency), single memcpy of entire texture in tinyrenderer, instead of per-pixel copy (memory layout is the same) add lots of B3_PROFILE timings, to see where time is going
This commit is contained in:
@@ -285,11 +285,18 @@ void TinyRenderObjectData::registerMeshShape(const float* vertices, int numVerti
|
||||
{
|
||||
if (0==m_model)
|
||||
{
|
||||
m_model = new Model();
|
||||
m_model->setColorRGBA(rgbaColor);
|
||||
{
|
||||
B3_PROFILE("setColorRGBA");
|
||||
|
||||
m_model = new Model();
|
||||
m_model->setColorRGBA(rgbaColor);
|
||||
}
|
||||
if (textureImage)
|
||||
{
|
||||
m_model->setDiffuseTextureFromData(textureImage,textureWidth,textureHeight);
|
||||
{
|
||||
B3_PROFILE("setDiffuseTextureFromData");
|
||||
m_model->setDiffuseTextureFromData(textureImage, textureWidth, textureHeight);
|
||||
}
|
||||
} else
|
||||
{
|
||||
/*char relativeFileName[1024];
|
||||
@@ -299,25 +306,33 @@ void TinyRenderObjectData::registerMeshShape(const float* vertices, int numVerti
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
m_model->reserveMemory(numVertices,numIndices);
|
||||
for (int i=0;i<numVertices;i++)
|
||||
{
|
||||
m_model->addVertex(vertices[i*9],
|
||||
vertices[i*9+1],
|
||||
vertices[i*9+2],
|
||||
vertices[i*9+4],
|
||||
vertices[i*9+5],
|
||||
vertices[i*9+6],
|
||||
vertices[i*9+7],
|
||||
vertices[i*9+8]);
|
||||
}
|
||||
for (int i=0;i<numIndices;i+=3)
|
||||
{
|
||||
m_model->addTriangle(indices[i],indices[i],indices[i],
|
||||
indices[i+1],indices[i+1],indices[i+1],
|
||||
indices[i+2],indices[i+2],indices[i+2]);
|
||||
}
|
||||
{
|
||||
B3_PROFILE("reserveMemory");
|
||||
m_model->reserveMemory(numVertices, numIndices);
|
||||
}
|
||||
{
|
||||
B3_PROFILE("addVertex");
|
||||
for (int i = 0; i < numVertices; i++)
|
||||
{
|
||||
m_model->addVertex(vertices[i * 9],
|
||||
vertices[i * 9 + 1],
|
||||
vertices[i * 9 + 2],
|
||||
vertices[i * 9 + 4],
|
||||
vertices[i * 9 + 5],
|
||||
vertices[i * 9 + 6],
|
||||
vertices[i * 9 + 7],
|
||||
vertices[i * 9 + 8]);
|
||||
}
|
||||
}
|
||||
{
|
||||
B3_PROFILE("addTriangle");
|
||||
for (int i = 0; i < numIndices; i += 3)
|
||||
{
|
||||
m_model->addTriangle(indices[i], indices[i], indices[i],
|
||||
indices[i + 1], indices[i + 1], indices[i + 1],
|
||||
indices[i + 2], indices[i + 2], indices[i + 2]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include "model.h"
|
||||
|
||||
#include "Bullet3Common/b3Logging.h"
|
||||
Model::Model(const char *filename) : verts_(), faces_(), norms_(), uv_(), diffusemap_(), normalmap_(), specularmap_() {
|
||||
std::ifstream in;
|
||||
in.open (filename, std::ifstream::in);
|
||||
@@ -51,24 +51,22 @@ Model::Model():verts_(), faces_(), norms_(), uv_(), diffusemap_(), normalmap_(),
|
||||
|
||||
void Model::setDiffuseTextureFromData(unsigned char* textureImage,int textureWidth,int textureHeight)
|
||||
{
|
||||
diffusemap_ = TGAImage(textureWidth, textureHeight, TGAImage::RGB);
|
||||
for (int i=0;i<textureWidth;i++)
|
||||
{
|
||||
for (int j=0;j<textureHeight;j++)
|
||||
{
|
||||
TGAColor color;
|
||||
color.bgra[0] = textureImage[(i+j*textureWidth)*3+0];
|
||||
color.bgra[1] = textureImage[(i+j*textureWidth)*3+1];
|
||||
color.bgra[2] = textureImage[(i+j*textureWidth)*3+2];
|
||||
color.bgra[3] = 255;
|
||||
|
||||
color.bytespp = 3;
|
||||
diffusemap_.set(i,j,color);
|
||||
|
||||
}
|
||||
B3_PROFILE("new TGAImage");
|
||||
diffusemap_ = TGAImage(textureWidth, textureHeight, TGAImage::RGB);
|
||||
}
|
||||
TGAColor color;
|
||||
color.bgra[3] = 255;
|
||||
|
||||
color.bytespp = 3;
|
||||
{
|
||||
B3_PROFILE("copy texels");
|
||||
memcpy(diffusemap_.buffer(), textureImage, textureHeight*textureWidth * 3);
|
||||
}
|
||||
{
|
||||
B3_PROFILE("flip_vertically");
|
||||
diffusemap_.flip_vertically();
|
||||
}
|
||||
|
||||
diffusemap_.flip_vertically();
|
||||
}
|
||||
|
||||
void Model::loadDiffuseTexture(const char* relativeFileName)
|
||||
|
||||
@@ -10,13 +10,13 @@ TGAImage::TGAImage() : data(NULL), width(0), height(0), bytespp(0) {}
|
||||
TGAImage::TGAImage(int w, int h, int bpp) : data(NULL), width(w), height(h), bytespp(bpp) {
|
||||
unsigned long nbytes = width*height*bytespp;
|
||||
data = new unsigned char[nbytes];
|
||||
memset(data, 0, nbytes);
|
||||
//memset(data, 0, nbytes);
|
||||
}
|
||||
|
||||
TGAImage::TGAImage(const TGAImage &img) : data(NULL), width(img.width), height(img.height), bytespp(img.bytespp) {
|
||||
unsigned long nbytes = width*height*bytespp;
|
||||
data = new unsigned char[nbytes];
|
||||
memcpy(data, img.data, nbytes);
|
||||
//memcpy(data, img.data, nbytes);
|
||||
}
|
||||
|
||||
TGAImage::~TGAImage() {
|
||||
|
||||
Reference in New Issue
Block a user