don't use GL_LINEAR_MIPMAP_LINEAR for shadow maps
optimize gpu upload (use glBufferSubData instead of glMapBuffer Avoid checking char array against zero.
This commit is contained in:
152
examples/RenderingExamples/DynamicTexturedCubeDemo.cpp
Normal file
152
examples/RenderingExamples/DynamicTexturedCubeDemo.cpp
Normal file
@@ -0,0 +1,152 @@
|
||||
|
||||
#include "DynamicTexturedCubeDemo.h"
|
||||
#include "Bullet3Common/b3Logging.h"
|
||||
#include "../CommonInterfaces/CommonGraphicsAppInterface.h"
|
||||
#include "Bullet3Common/b3Quaternion.h"
|
||||
#include "Bullet3Common/b3AlignedObjectArray.h"
|
||||
#include "../CommonInterfaces/CommonRenderInterface.h"
|
||||
#include "../CommonInterfaces/CommonExampleInterface.h"
|
||||
#include "../CommonInterfaces/CommonGUIHelperInterface.h"
|
||||
#include "GwenGuiSupport/GraphingTexture.h"
|
||||
|
||||
#include "../CommonInterfaces/Common2dCanvasInterface.h"
|
||||
#include "../RenderingExamples/TimeSeriesCanvas.h"
|
||||
#include "../RenderingExamples/TimeSeriesFontData.h"
|
||||
#include "../Importers/ImportMeshUtility/b3ImportMeshUtility.h"
|
||||
#include "../OpenGLWindow/GLInstanceGraphicsShape.h"
|
||||
#include "TinyVRGui.h"
|
||||
#include "../CommonInterfaces/CommonParameterInterface.h"
|
||||
|
||||
class DynamicTexturedCubeDemo : public CommonExampleInterface
|
||||
{
|
||||
CommonGraphicsApp* m_app;
|
||||
float m_x;
|
||||
float m_y;
|
||||
float m_z;
|
||||
b3AlignedObjectArray<int> m_movingInstances;
|
||||
|
||||
|
||||
TinyVRGui* m_tinyVrGUI;
|
||||
|
||||
enum
|
||||
{
|
||||
numCubesX = 1,
|
||||
numCubesY = 1
|
||||
};
|
||||
public:
|
||||
|
||||
DynamicTexturedCubeDemo(CommonGraphicsApp* app)
|
||||
:m_app(app),
|
||||
m_x(0),
|
||||
m_y(0),
|
||||
m_z(0),
|
||||
m_tinyVrGUI(0)
|
||||
{
|
||||
m_app->setUpAxis(2);
|
||||
|
||||
{
|
||||
b3Vector3 extents=b3MakeVector3(100,100,100);
|
||||
extents[m_app->getUpAxis()]=1;
|
||||
|
||||
int xres = 20;
|
||||
int yres = 20;
|
||||
|
||||
b3Vector4 color0=b3MakeVector4(0.1, 0.1, 0.5,1);
|
||||
b3Vector4 color1=b3MakeVector4(0.6, 0.6, 0.6,1);
|
||||
m_app->registerGrid(xres, yres, color0, color1);
|
||||
}
|
||||
|
||||
ComboBoxParams comboParams;
|
||||
comboParams.m_comboboxId = 0;
|
||||
comboParams.m_numItems = 0;
|
||||
comboParams.m_startItem = 0;
|
||||
comboParams.m_callback = 0;//MyComboBoxCallback;
|
||||
comboParams.m_userPointer = 0;//this;
|
||||
|
||||
|
||||
m_tinyVrGUI = new TinyVRGui(comboParams,m_app->m_renderer);
|
||||
m_tinyVrGUI->init();
|
||||
|
||||
m_app->m_renderer->writeTransforms();
|
||||
}
|
||||
virtual ~DynamicTexturedCubeDemo()
|
||||
{
|
||||
delete m_tinyVrGUI;
|
||||
m_app->m_renderer->enableBlend(false);
|
||||
}
|
||||
|
||||
|
||||
virtual void physicsDebugDraw(int debugDrawMode)
|
||||
{
|
||||
|
||||
}
|
||||
virtual void initPhysics()
|
||||
{
|
||||
}
|
||||
virtual void exitPhysics()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
virtual void stepSimulation(float deltaTime)
|
||||
{
|
||||
static b3Transform tr = b3Transform::getIdentity();
|
||||
static b3Scalar t = 0.f;
|
||||
t+=deltaTime;
|
||||
tr.setOrigin(b3MakeVector3(0.,0.,2.)+b3MakeVector3(0.,0.,0.02*b3Sin(t)));
|
||||
|
||||
m_tinyVrGUI->tick(deltaTime,tr);
|
||||
|
||||
m_app->m_renderer->writeTransforms();
|
||||
|
||||
}
|
||||
virtual void renderScene()
|
||||
{
|
||||
|
||||
m_app->m_renderer->renderScene();
|
||||
}
|
||||
|
||||
|
||||
virtual void physicsDebugDraw()
|
||||
{
|
||||
|
||||
}
|
||||
virtual bool mouseMoveCallback(float x,float y)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
virtual bool mouseButtonCallback(int button, int state, float x, float y)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
virtual bool keyboardCallback(int key, int state)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
virtual void resetCamera()
|
||||
{
|
||||
float dist = 1.15;
|
||||
float pitch = 396;
|
||||
float yaw = 33.7;
|
||||
float targetPos[3]={-0.5,0.7,1.45};
|
||||
if (m_app->m_renderer && m_app->m_renderer->getActiveCamera())
|
||||
{
|
||||
m_app->m_renderer->getActiveCamera()->setCameraDistance(dist);
|
||||
m_app->m_renderer->getActiveCamera()->setCameraPitch(pitch);
|
||||
m_app->m_renderer->getActiveCamera()->setCameraYaw(yaw);
|
||||
m_app->m_renderer->getActiveCamera()->setCameraTargetPosition(targetPos[0],targetPos[1],targetPos[2]);
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
class CommonExampleInterface* DynamicTexturedCubeDemoCreateFunc(struct CommonExampleOptions& options)
|
||||
{
|
||||
return new DynamicTexturedCubeDemo(options.m_guiHelper->getAppInterface());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
6
examples/RenderingExamples/DynamicTexturedCubeDemo.h
Normal file
6
examples/RenderingExamples/DynamicTexturedCubeDemo.h
Normal file
@@ -0,0 +1,6 @@
|
||||
#ifndef DYNAMIC_TEXTURED_CUBE_DEMO_H
|
||||
#define DYNAMIC_TEXTURED_CUBE_DEMO_H
|
||||
|
||||
class CommonExampleInterface* DynamicTexturedCubeDemoCreateFunc(struct CommonExampleOptions& options);
|
||||
|
||||
#endif //DYNAMIC_TEXTURED_CUBE_DEMO_H
|
||||
@@ -104,7 +104,7 @@ void TimeSeriesCanvas::addDataSource(const char* dataSourceLabel, unsigned char
|
||||
m_internalData->m_dataSources.push_back(dataSource);
|
||||
|
||||
}
|
||||
void TimeSeriesCanvas::setupTimeSeries(float yScale, int ticksPerSecond, int startTime)
|
||||
void TimeSeriesCanvas::setupTimeSeries(float yScale, int ticksPerSecond, int startTime, bool clearCanvas)
|
||||
{
|
||||
if (0==m_internalData->m_canvasInterface)
|
||||
return;
|
||||
@@ -113,20 +113,23 @@ void TimeSeriesCanvas::setupTimeSeries(float yScale, int ticksPerSecond, int sta
|
||||
m_internalData->m_ticksPerSecond = ticksPerSecond;
|
||||
m_internalData->m_yScale = yScale;
|
||||
m_internalData->m_dataSources.clear();
|
||||
for (int i=0;i<m_internalData->m_width;i++)
|
||||
|
||||
if (clearCanvas)
|
||||
{
|
||||
for (int j=0;j<m_internalData->m_height;j++)
|
||||
for (int i=0;i<m_internalData->m_width;i++)
|
||||
{
|
||||
for (int j=0;j<m_internalData->m_height;j++)
|
||||
{
|
||||
|
||||
m_internalData->m_canvasInterface->setPixel(m_internalData->m_canvasIndex,i,j,
|
||||
m_internalData->m_backgroundRed,
|
||||
m_internalData->m_backgroundGreen,
|
||||
m_internalData->m_backgroundBlue,
|
||||
m_internalData->m_backgroundAlpha);
|
||||
m_internalData->m_canvasInterface->setPixel(m_internalData->m_canvasIndex,i,j,
|
||||
m_internalData->m_backgroundRed,
|
||||
m_internalData->m_backgroundGreen,
|
||||
m_internalData->m_backgroundBlue,
|
||||
m_internalData->m_backgroundAlpha);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
float zeroPixelCoord = m_internalData->m_zero;
|
||||
float pixelsPerUnit = m_internalData->m_pixelsPerUnit;
|
||||
|
||||
@@ -207,7 +210,7 @@ void TimeSeriesCanvas::shift1PixelToLeft()
|
||||
int countdown = resetVal;
|
||||
|
||||
//shift pixture one pixel to the left
|
||||
for (int j=0;j<m_internalData->m_height-48;j++)
|
||||
for (int j=50;j<m_internalData->m_height-48;j++)
|
||||
{
|
||||
for (int i=40;i<this->m_internalData->m_width;i++)
|
||||
{
|
||||
|
||||
@@ -6,17 +6,17 @@ class TimeSeriesCanvas
|
||||
protected:
|
||||
struct TimeSeriesInternalData* m_internalData;
|
||||
void shift1PixelToLeft();
|
||||
void grapicalPrintf(const char* str, void* fontData, int rasterposx,int rasterposy,unsigned char red, unsigned char green, unsigned char blue, unsigned char alpha);
|
||||
|
||||
|
||||
public:
|
||||
|
||||
TimeSeriesCanvas(struct Common2dCanvasInterface* canvasInterface, int width, int height, const char* windowTitle);
|
||||
virtual ~TimeSeriesCanvas();
|
||||
|
||||
void setupTimeSeries(float yScale, int ticksPerSecond, int startTime);
|
||||
void setupTimeSeries(float yScale, int ticksPerSecond, int startTime, bool clearCanvas=true);
|
||||
void addDataSource(const char* dataSourceLabel, unsigned char red,unsigned char green,unsigned char blue);
|
||||
void insertDataAtCurrentTime(float value, int dataSourceIndex, bool connectToPrevious);
|
||||
float getCurrentTime() const;
|
||||
void grapicalPrintf(const char* str, void* fontData, int rasterposx,int rasterposy,unsigned char red, unsigned char green, unsigned char blue, unsigned char alpha);
|
||||
|
||||
virtual void nextTick();
|
||||
|
||||
|
||||
218
examples/RenderingExamples/TinyVRGui.cpp
Normal file
218
examples/RenderingExamples/TinyVRGui.cpp
Normal file
@@ -0,0 +1,218 @@
|
||||
#include "TinyVRGui.h"
|
||||
#include "../CommonInterfaces/CommonGUIHelperInterface.h"
|
||||
#include "../ExampleBrowser/GwenGuiSupport/GraphingTexture.h"
|
||||
|
||||
#include "../CommonInterfaces/Common2dCanvasInterface.h"
|
||||
#include "../RenderingExamples/TimeSeriesCanvas.h"
|
||||
#include "../RenderingExamples/TimeSeriesFontData.h"
|
||||
#include "../Importers/ImportMeshUtility/b3ImportMeshUtility.h"
|
||||
#include "../OpenGLWindow/GLInstanceGraphicsShape.h"
|
||||
|
||||
#include "../CommonInterfaces/CommonRenderInterface.h"
|
||||
#include "../CommonInterfaces/CommonParameterInterface.h"
|
||||
|
||||
|
||||
struct TestCanvasInterface2 : public Common2dCanvasInterface
|
||||
{
|
||||
b3AlignedObjectArray<unsigned char>& m_texelsRGB;
|
||||
int m_width;
|
||||
int m_height;
|
||||
|
||||
TestCanvasInterface2(b3AlignedObjectArray<unsigned char>& texelsRGB, int width, int height)
|
||||
:m_width(width),
|
||||
m_height(height),
|
||||
m_texelsRGB(texelsRGB)
|
||||
{
|
||||
}
|
||||
|
||||
virtual ~TestCanvasInterface2()
|
||||
{}
|
||||
virtual int createCanvas(const char* canvasName, int width, int height)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
virtual void destroyCanvas(int canvasId)
|
||||
{
|
||||
}
|
||||
virtual void setPixel(int canvasId, int x, int y, unsigned char red, unsigned char green,unsigned char blue, unsigned char alpha)
|
||||
{
|
||||
if (x>=0 && x<m_width && y>=0 && y<m_height)
|
||||
{
|
||||
m_texelsRGB[(x+y*m_width)*3+0] = red;
|
||||
m_texelsRGB[(x+y*m_width)*3+1] = green;
|
||||
m_texelsRGB[(x+y*m_width)*3+2] = blue;
|
||||
}
|
||||
}
|
||||
virtual void getPixel(int canvasId, int x, int y, unsigned char& red, unsigned char& green,unsigned char& blue, unsigned char& alpha)
|
||||
{
|
||||
if (x>=0 && x<m_width && y>=0 && y<m_height)
|
||||
{
|
||||
red = m_texelsRGB[(x+y*m_width)*3+0];
|
||||
green = m_texelsRGB[(x+y*m_width)*3+1];
|
||||
blue = m_texelsRGB[(x+y*m_width)*3+2];
|
||||
}
|
||||
}
|
||||
|
||||
virtual void refreshImageData(int canvasId)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
struct TinyVRGuiInternalData
|
||||
{
|
||||
CommonRenderInterface* m_renderer;
|
||||
|
||||
b3AlignedObjectArray<unsigned char> m_texelsRGB;
|
||||
TestCanvasInterface2* m_testCanvas;
|
||||
TimeSeriesCanvas* m_timeSeries;
|
||||
int m_src;
|
||||
int m_textureId;
|
||||
int m_gfxObjectId;
|
||||
|
||||
TinyVRGuiInternalData()
|
||||
:m_renderer(0),
|
||||
m_testCanvas(0),
|
||||
m_timeSeries(0),
|
||||
m_src(-1),
|
||||
m_textureId(-1),
|
||||
m_gfxObjectId(-1)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
TinyVRGui::TinyVRGui(struct ComboBoxParams& params, struct CommonRenderInterface* renderer)
|
||||
{
|
||||
m_data = new TinyVRGuiInternalData;
|
||||
m_data->m_renderer = renderer;
|
||||
|
||||
|
||||
}
|
||||
|
||||
TinyVRGui::~TinyVRGui()
|
||||
{
|
||||
delete m_data->m_timeSeries;
|
||||
delete m_data->m_testCanvas;
|
||||
delete m_data;
|
||||
}
|
||||
|
||||
bool TinyVRGui::init()
|
||||
{
|
||||
{
|
||||
|
||||
|
||||
int width = 256;
|
||||
int height = 256;
|
||||
m_data->m_texelsRGB.resize(width*height*3);
|
||||
for (int i=0;i<width;i++)
|
||||
for (int j=0;j<height;j++)
|
||||
{
|
||||
m_data->m_texelsRGB[(i+j*width)*3+0] = 155;
|
||||
m_data->m_texelsRGB[(i+j*width)*3+1] = 155;
|
||||
m_data->m_texelsRGB[(i+j*width)*3+2] = 255;
|
||||
}
|
||||
|
||||
m_data->m_testCanvas = new TestCanvasInterface2(m_data->m_texelsRGB,width,height);
|
||||
m_data->m_timeSeries = new TimeSeriesCanvas(m_data->m_testCanvas,width,height,"time series");
|
||||
|
||||
|
||||
bool clearCanvas = false;
|
||||
|
||||
m_data->m_timeSeries->setupTimeSeries(3,100, 0,clearCanvas);
|
||||
m_data->m_timeSeries->addDataSource("Some sine wave", 255,0,0);
|
||||
m_data->m_timeSeries->addDataSource("Some cosine wave", 0,255,0);
|
||||
m_data->m_timeSeries->addDataSource("Delta Time (*10)", 0,0,255);
|
||||
m_data->m_timeSeries->addDataSource("Tan", 255,0,255);
|
||||
m_data->m_timeSeries->addDataSource("Some cosine wave2", 255,255,0);
|
||||
m_data->m_timeSeries->addDataSource("Empty source2", 255,0,255);
|
||||
|
||||
m_data->m_textureId = m_data->m_renderer->registerTexture(&m_data->m_texelsRGB[0],width,height);
|
||||
|
||||
{
|
||||
|
||||
const char* fileName = "cube.obj";//"textured_sphere_smooth.obj";
|
||||
//fileName = "cube.obj";
|
||||
|
||||
int shapeId = -1;
|
||||
|
||||
b3ImportMeshData meshData;
|
||||
if (b3ImportMeshUtility::loadAndRegisterMeshFromFileInternal(fileName, meshData))
|
||||
{
|
||||
|
||||
|
||||
shapeId = m_data->m_renderer->registerShape(&meshData.m_gfxShape->m_vertices->at(0).xyzw[0],
|
||||
meshData.m_gfxShape->m_numvertices,
|
||||
&meshData.m_gfxShape->m_indices->at(0),
|
||||
meshData.m_gfxShape->m_numIndices,
|
||||
B3_GL_TRIANGLES,
|
||||
m_data->m_textureId);
|
||||
|
||||
float position[4]={0,0,2,1};
|
||||
float orn[4]={0,0,0,1};
|
||||
float color[4]={1,1,1,1};
|
||||
float scaling[4]={.1,.1,.1,1};
|
||||
|
||||
m_data->m_gfxObjectId = m_data->m_renderer->registerGraphicsInstance(shapeId,position,orn,color,scaling);
|
||||
m_data->m_renderer->writeTransforms();
|
||||
|
||||
|
||||
|
||||
meshData.m_gfxShape->m_scaling[0] = scaling[0];
|
||||
meshData.m_gfxShape->m_scaling[1] = scaling[1];
|
||||
meshData.m_gfxShape->m_scaling[2] = scaling[2];
|
||||
|
||||
|
||||
delete meshData.m_gfxShape;
|
||||
delete meshData.m_textureImage;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
m_data->m_renderer->writeTransforms();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void TinyVRGui::tick(b3Scalar deltaTime, const b3Transform& guiWorldTransform)
|
||||
{
|
||||
float time = m_data->m_timeSeries->getCurrentTime();
|
||||
float v = sinf(time);
|
||||
m_data->m_timeSeries->insertDataAtCurrentTime(v,0,true);
|
||||
v = cosf(time);
|
||||
m_data->m_timeSeries->insertDataAtCurrentTime(v,1,true);
|
||||
v = tanf(time);
|
||||
m_data->m_timeSeries->insertDataAtCurrentTime(v,3,true);
|
||||
m_data->m_timeSeries->insertDataAtCurrentTime(deltaTime*10,2,true);
|
||||
|
||||
m_data->m_timeSeries->nextTick();
|
||||
|
||||
m_data->m_renderer->updateTexture(m_data->m_textureId,&m_data->m_texelsRGB[0]);
|
||||
m_data->m_renderer->writeSingleInstanceTransformToCPU(guiWorldTransform.getOrigin(),guiWorldTransform.getRotation(),m_data->m_gfxObjectId);
|
||||
m_data->m_renderer->writeTransforms();
|
||||
}
|
||||
|
||||
void TinyVRGui::clearTextArea()
|
||||
{
|
||||
int width = 256;
|
||||
int height = 50;
|
||||
for (int i=0;i<width;i++)
|
||||
for (int j=0;j<height;j++)
|
||||
{
|
||||
m_data->m_texelsRGB[(i+j*width)*3+0] = 155;
|
||||
m_data->m_texelsRGB[(i+j*width)*3+1] = 155;
|
||||
m_data->m_texelsRGB[(i+j*width)*3+2] = 255;
|
||||
}
|
||||
}
|
||||
|
||||
void TinyVRGui::grapicalPrintf(const char* str,int rasterposx,int rasterposy,unsigned char red, unsigned char green, unsigned char blue, unsigned char alpha)
|
||||
{
|
||||
m_data->m_timeSeries->grapicalPrintf(str,sTimeSeriesFontData,rasterposx,rasterposy,red,green,blue,alpha);
|
||||
}
|
||||
|
||||
25
examples/RenderingExamples/TinyVRGui.h
Normal file
25
examples/RenderingExamples/TinyVRGui.h
Normal file
@@ -0,0 +1,25 @@
|
||||
|
||||
#ifndef TINY_VR_GUI_H
|
||||
#define TINY_VR_GUI_H
|
||||
|
||||
#include "Bullet3Common/b3Transform.h"
|
||||
|
||||
class TinyVRGui
|
||||
{
|
||||
struct TinyVRGuiInternalData* m_data;
|
||||
|
||||
public:
|
||||
|
||||
TinyVRGui(struct ComboBoxParams& params, struct CommonRenderInterface* renderer);
|
||||
virtual ~TinyVRGui();
|
||||
|
||||
bool init();
|
||||
void tick(b3Scalar deltaTime, const b3Transform& guiWorldTransform);
|
||||
|
||||
void clearTextArea();
|
||||
void grapicalPrintf(const char* str,int rasterposx,int rasterposy,unsigned char red, unsigned char green, unsigned char blue, unsigned char alpha);
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif //TINY_VR_GUI_H
|
||||
Reference in New Issue
Block a user