Merge revisions r5532 through r5538 from trunk to ogl-es-

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/branches/ogl-es@5539 dfc29bdd-3216-0410-991c-e03cc46cb475
master
cutealien 2017-08-30 13:20:12 +00:00
parent 5450247e6b
commit 7bd44b9733
9 changed files with 98 additions and 60 deletions

View File

@ -133,6 +133,7 @@ video::E_VERTEX_TYPE getVertexTypeForMaterialType(video::E_MATERIAL_TYPE materia
CColorControl::CColorControl(gui::IGUIEnvironment* guiEnv, const core::position2d<s32> & pos, const wchar_t *text, IGUIElement* parent, s32 id)
: gui::IGUIElement(gui::EGUIET_ELEMENT, guiEnv, parent,id, core::rect< s32 >(pos, pos+core::dimension2d<s32>(80, 75)))
, DirtyFlag(true)
, Color(0)
, ColorStatic(0)
, EditAlpha(0)
, EditRed(0)
@ -421,7 +422,7 @@ void CTextureControl::updateTextures(video::IVideoDriver * driver)
/*
Control which allows setting some of the material values for a meshscenenode
*/
void SMaterialControl::init(scene::IMeshSceneNode* node, IrrlichtDevice * device, const core::position2d<s32> & pos, const wchar_t * description)
void CMaterialControl::init(scene::IMeshSceneNode* node, IrrlichtDevice * device, const core::position2d<s32> & pos, const wchar_t * description)
{
if ( Initialized || !node || !device) // initializing twice or with invalid data not allowed
return;
@ -465,6 +466,7 @@ void SMaterialControl::init(scene::IMeshSceneNode* node, IrrlichtDevice * device
// Controls for selecting the material textures
guiEnv->addStaticText(L"Textures", core::rect<s32>(pos.X, top, pos.X+60, top+15), false, false, 0, -1, false);
top += 15;
for (irr::u32 i=0; i<irr::video::MATERIAL_MAX_TEXTURES; ++i)
{
TextureControls[i] = new CTextureControl(guiEnv, Driver, core::position2di(pos.X, top), guiEnv->getRootGUIElement());
@ -474,7 +476,7 @@ void SMaterialControl::init(scene::IMeshSceneNode* node, IrrlichtDevice * device
Initialized = true;
}
void SMaterialControl::update(scene::IMeshSceneNode* sceneNode, scene::IMeshSceneNode* sceneNode2T, scene::IMeshSceneNode* sceneNodeTangents)
void CMaterialControl::update(scene::IMeshSceneNode* sceneNode, scene::IMeshSceneNode* sceneNode2T, scene::IMeshSceneNode* sceneNodeTangents)
{
if ( !Initialized )
return;
@ -527,24 +529,24 @@ void SMaterialControl::update(scene::IMeshSceneNode* sceneNode, scene::IMeshScen
TextureControls[i]->resetDirty();
}
void SMaterialControl::updateTextures()
void CMaterialControl::updateTextures()
{
for (irr::u32 i=0; i<irr::video::MATERIAL_MAX_TEXTURES; ++i)
TextureControls[i]->updateTextures(Driver);
}
void SMaterialControl::selectTextures(const irr::core::stringw& name)
void CMaterialControl::selectTextures(const irr::core::stringw& name)
{
for (irr::u32 i=0; i<irr::video::MATERIAL_MAX_TEXTURES; ++i)
TextureControls[i]->selectTextureByName(name);
}
bool SMaterialControl::isLightingEnabled() const
bool CMaterialControl::isLightingEnabled() const
{
return ButtonLighting && ButtonLighting->isPressed();
}
void SMaterialControl::updateMaterial(video::SMaterial & material)
void CMaterialControl::updateMaterial(video::SMaterial & material)
{
TypicalColorsControl->updateMaterialColors(material);
material.Lighting = ButtonLighting->isPressed();
@ -561,7 +563,7 @@ void SMaterialControl::updateMaterial(video::SMaterial & material)
Control to allow setting the color values of a lightscenenode.
*/
void SLightNodeControl::init(scene::ILightSceneNode* node, gui::IGUIEnvironment* guiEnv, const core::position2d<s32> & pos, const wchar_t * description)
void CLightNodeControl::init(scene::ILightSceneNode* node, gui::IGUIEnvironment* guiEnv, const core::position2d<s32> & pos, const wchar_t * description)
{
if ( Initialized || !node || !guiEnv) // initializing twice or with invalid data not allowed
return;
@ -573,7 +575,7 @@ void SLightNodeControl::init(scene::ILightSceneNode* node, gui::IGUIEnvironment*
Initialized = true;
}
void SLightNodeControl::update(scene::ILightSceneNode* node)
void CLightNodeControl::update(scene::ILightSceneNode* node)
{
if ( !Initialized )
return;
@ -665,6 +667,7 @@ bool CApp::init(int argc, char *argv[])
Device = createDevice(Config.DriverType, Config.ScreenSize);
if (!Device)
return false;
Device->setWindowCaption( core::stringw(video::DRIVER_TYPE_NAMES[Config.DriverType]).c_str() );
Device->setEventReceiver(this);
@ -698,8 +701,6 @@ bool CApp::init(int argc, char *argv[])
subMenuFile->addSeparator();
subMenuFile->addItem(L"Quit", GUI_ID_QUIT);
const s32 controlsTop = 20;
// a static camera
Camera = smgr->addCameraSceneNode (0, core::vector3df(0, 40, -40),
core::vector3df(0, 10, 0),
@ -715,8 +716,11 @@ bool CApp::init(int argc, char *argv[])
core::vector3df(0.f, 45.f, 0.f),
core::vector3df(1.0f, 1.0f, 1.0f));
SceneNode->getMaterial(0) = defaultMaterial;
MeshMaterialControl.init( SceneNode, Device, core::position2d<s32>(10,controlsTop), L"Material" );
MeshMaterialControl.selectTextures(core::stringw("CARO_A8R8G8B8")); // set a useful default texture
const s32 controlsTop = 20;
MeshMaterialControl = new CMaterialControl();
MeshMaterialControl->init( SceneNode, Device, core::position2d<s32>(10,controlsTop), L"Material" );
MeshMaterialControl->selectTextures(core::stringw("CARO_A8R8G8B8")); // set a useful default texture
// create nodes with other vertex types
scene::IMesh * mesh2T = MeshManipulator->createMeshWith2TCoords(SceneNode->getMesh());
@ -733,7 +737,8 @@ bool CApp::init(int argc, char *argv[])
NodeLight = smgr->addLightSceneNode(0, core::vector3df(0, 0, -40),
video::SColorf(1.0f, 1.0f, 1.0f),
35.0f);
LightControl.init(NodeLight, guiEnv, core::position2d<s32>(550,controlsTop), L"Dynamic light" );
LightControl = new CLightNodeControl();
LightControl->init(NodeLight, guiEnv, core::position2d<s32>(550,controlsTop), L"Dynamic light" );
// one large cube around everything. That's mainly to make the light more obvious.
scene::IMeshSceneNode* backgroundCube = smgr->addCubeSceneNode (200.0f, 0, -1, core::vector3df(0, 0, 0),
@ -783,8 +788,8 @@ bool CApp::update()
gui::IGUISkin * skin = guiEnv->getSkin();
// update our controls
MeshMaterialControl.update(SceneNode, SceneNode2T, SceneNodeTangents);
LightControl.update(NodeLight);
MeshMaterialControl->update(SceneNode, SceneNode2T, SceneNodeTangents);
LightControl->update(NodeLight);
// Update vertices
if ( ControlVertexColors->isDirty() )
@ -836,7 +841,7 @@ bool CApp::update()
smgr->drawAll();
guiEnv->drawAll();
if ( MeshMaterialControl.isLightingEnabled() )
if ( MeshMaterialControl->isLightingEnabled() )
{
// draw a line from the light to the target
video::SMaterial lineMaterial;
@ -859,6 +864,13 @@ bool CApp::update()
void CApp::quit()
{
IsRunning = false;
delete LightControl;
LightControl = NULL;
delete MeshMaterialControl;
MeshMaterialControl = NULL;
if ( ControlVertexColors )
{
ControlVertexColors->drop();
@ -949,7 +961,7 @@ void CApp::createDefaultTextures(video::IVideoDriver * driver)
void CApp::loadTexture(const io::path &name)
{
Device->getVideoDriver()->getTexture(name);
MeshMaterialControl.updateTextures();
MeshMaterialControl->updateTextures();
}
void CApp::RotateHorizontal(irr::scene::ISceneNode* node, irr::f32 angle)

View File

@ -133,10 +133,11 @@ private:
/*
Control which allows setting some of the material values for a meshscenenode
*/
struct SMaterialControl
class CMaterialControl
{
public:
// constructor
SMaterialControl()
CMaterialControl()
: Initialized(false), Driver(0)
, TypicalColorsControl(0), ButtonLighting(0), InfoLighting(0), ComboMaterial(0)
{
@ -145,7 +146,7 @@ struct SMaterialControl
}
// Destructor
~SMaterialControl()
~CMaterialControl()
{
for (irr::u32 i=0; i<irr::video::MATERIAL_MAX_TEXTURES; ++i)
{
@ -182,13 +183,14 @@ protected:
/*
Control to allow setting the color values of a lightscenenode.
*/
struct SLightNodeControl
class CLightNodeControl
{
public:
// constructor
SLightNodeControl() : Initialized(false), TypicalColorsControl(0)
CLightNodeControl() : Initialized(false), TypicalColorsControl(0)
{}
~SLightNodeControl()
~CLightNodeControl()
{
if ( TypicalColorsControl )
TypicalColorsControl->drop();
@ -238,6 +240,8 @@ public:
, SceneNode(0), SceneNode2T(0), SceneNodeTangents(0), NodeLight(0)
, CameraRotationAxis(irr::core::vector3df(1,0,0))
, LightRotationAxis(irr::core::vector3df(1,0,0))
, MeshMaterialControl(0)
, LightControl(0)
, ControlVertexColors(0)
, GlobalAmbient(0)
, MousePressed(false)
@ -303,8 +307,8 @@ private:
irr::scene::ILightSceneNode* NodeLight;
irr::core::vector3df CameraRotationAxis;
irr::core::vector3df LightRotationAxis;
SMaterialControl MeshMaterialControl;
SLightNodeControl LightControl;
CMaterialControl* MeshMaterialControl;
CLightNodeControl* LightControl;
CColorControl* ControlVertexColors;
CColorControl* GlobalAmbient;
bool KeysPressed[irr::KEY_KEY_CODES_COUNT];

View File

@ -36,7 +36,7 @@ namespace io
virtual long getSize() const = 0;
//! Get the current position in the file.
/** \return Current position in the file in bytes. */
/** \return Current position in the file in bytes on success or -1L on failure. */
virtual long getPos() const = 0;
//! Get name of file.

View File

@ -32,7 +32,7 @@ namespace io
virtual bool seek(long finalPos, bool relativeMovement = false) = 0;
//! Get the current position in the file.
/** \return Current position in the file in bytes. */
/** \return Current position in the file in bytes on success or -1L on failure */
virtual long getPos() const = 0;
//! Get name of file.

View File

@ -13,7 +13,7 @@ namespace irr
namespace video
{
//! An enum for the color format of textures used by the Irrlicht Engine.
/** A color format specifies how color information is stored.
/** A color format specifies how color information is stored.
NOTE: Byte order in memory is usually flipped (it's probably correct in bitmap files, but flipped on reading).
So for example ECF_A8R8G8B8 is BGRA in memory same as in DX9's D3DFMT_A8R8G8B8 format.
*/
@ -129,6 +129,43 @@ namespace video
ECF_UNKNOWN
};
//! Names for ECOLOR_FORMAT types
const c8* const ColorFormatNames[ECF_UNKNOWN+1] =
{
"A1R5G5B5",
"R5G6B5",
"R8G8B8",
"A8R8G8B8",
"DXT1",
"DXT2",
"DXT3",
"DXT4",
"DXT5",
"PVRTC_RGB2",
"PVRTC_ARGB2",
"PVRTC_RGB4",
"PVRTC_ARGB4",
"PVRTC2_ARGB2",
"PVRTC2_ARGB4",
"ETC1",
"ETC2_RGB",
"ETC2_ARGB",
"R16F",
"G16R16F",
"A16B16G16R16F",
"R32F",
"G32R32F",
"A32B32G32R32F",
"R8",
"R8G8",
"R16",
"R16G16",
"D16",
"D32",
"D24S8",
0
};
//! Creates a 16 bit A1R5G5B5 color
inline u16 RGBA16(u32 r, u32 g, u32 b, u32 a=0xFF)

View File

@ -224,7 +224,7 @@ namespace io
\return Returns how much bytes were read. */
virtual int read(void* buffer, int sizeToRead) = 0;
//! Returns size of file in bytes
//! Returns size of file in bytes on success or -1L on failure.
virtual long getSize() const = 0;
};
@ -317,7 +317,7 @@ namespace io
//! Returns the value of an attribute as integer.
/** \param name Name of the attribute.
\param defaultNotFound Value returned when name does not exist
\return Value of the attribute as integer or value of defaultNotFound
\return Value of the attribute as integer or value of defaultNotFound
when name was not found or 0 when value could not be interpreted as integer */
virtual int getAttributeValueAsInt(const char_type* name, int defaultNotFound=0) const = 0;
@ -331,14 +331,14 @@ namespace io
//! Returns the value of an attribute as float.
/** \param name: Name of the attribute.
\param defaultNotFound Value returned when name does not exist.
\return Value of the attribute as float or value of defaultNotFound parameter on failure
\return Value of the attribute as float or value of defaultNotFound parameter on failure
or 0 when value could not be interpreted as float. */
virtual float getAttributeValueAsFloat(const char_type* name, float defaultNotFound=0.f) const = 0;
//! Returns the value of an attribute as float.
/** \param idx: Zero based index, should be something between 0 and getAttributeCount()-1.
\param defaultNotFound Value returned when index does not exist.
\return Value of the attribute as float or value of defaultNotFound parameter on failure
\return Value of the attribute as float or value of defaultNotFound parameter on failure
or 0 when value could not be interpreted as float. */
virtual float getAttributeValueAsFloat(int idx, float defaultNotFound=0.f) const = 0;

View File

@ -182,7 +182,7 @@ bool COSOperator::getProcessorSpeedMHz(u32* MHz) const
*MHz = CpuClock.hz;
return true;
#else
// could probably be read from "/proc/cpuinfo" or "/proc/cpufreq"
// read from "/proc/cpuinfo"
FILE* file = fopen("/proc/cpuinfo", "r");
if (file)
{
@ -196,12 +196,13 @@ bool COSOperator::getProcessorSpeedMHz(u32* MHz) const
pos = str.findNext(':', pos);
if (pos != -1)
{
*MHz = core::fast_atof(str.c_str()+pos+1);
while ( str[++pos] == ' ' );
*MHz = core::fast_atof(str.c_str()+pos);
}
}
fclose(file);
}
return (*MHz != 0);
return (MHz && *MHz != 0);
#endif
}

View File

@ -155,7 +155,10 @@ public:
Pitch = Size.Width * IImage::getBitsPerPixelFromFormat(ColorFormat) / 8;
Driver->getColorFormatParameters(ColorFormat, InternalFormat, PixelFormat, PixelType, &Converter);
if ( !Driver->getColorFormatParameters(ColorFormat, InternalFormat, PixelFormat, PixelType, &Converter) )
{
os::Printer::log("COpenGLCoreTexture: Color format is not supported", ColorFormatNames[ColorFormat < ECF_UNKNOWN?ColorFormat:ECF_UNKNOWN], ELL_ERROR);
}
glGenTextures(1, &TextureName);
@ -453,7 +456,11 @@ protected:
OriginalColorFormat = image->getColorFormat();
ColorFormat = getBestColorFormat(OriginalColorFormat);
Driver->getColorFormatParameters(ColorFormat, InternalFormat, PixelFormat, PixelType, &Converter);
if ( !Driver->getColorFormatParameters(ColorFormat, InternalFormat, PixelFormat, PixelType, &Converter) )
{
os::Printer::log("getImageValues: Color format is not supported", ColorFormatNames[ColorFormat < ECF_UNKNOWN?ColorFormat:ECF_UNKNOWN], ELL_ERROR);
// not quitting as it will use some alternative internal format
}
if (IImage::isCompressedFormat(image->getColorFormat()))
{

View File

@ -4204,9 +4204,7 @@ bool COpenGLDriver::getColorFormatParameters(ECOLOR_FORMAT format, GLint& intern
pixelFormat = GL_DEPTH_STENCIL_EXT;
pixelType = GL_UNSIGNED_INT_24_8_EXT;
}
else
#endif
os::Printer::log("ECF_D24S8 color format is not supported", ELL_ERROR);
break;
case ECF_R8:
if (queryOpenGLFeature(COpenGLExtensionHandler::IRR_ARB_texture_rg))
@ -4216,8 +4214,6 @@ bool COpenGLDriver::getColorFormatParameters(ECOLOR_FORMAT format, GLint& intern
pixelFormat = GL_RED;
pixelType = GL_UNSIGNED_BYTE;
}
else
os::Printer::log("ECF_R8 color format is not supported", ELL_ERROR);
break;
case ECF_R8G8:
if (queryOpenGLFeature(COpenGLExtensionHandler::IRR_ARB_texture_rg))
@ -4227,8 +4223,6 @@ bool COpenGLDriver::getColorFormatParameters(ECOLOR_FORMAT format, GLint& intern
pixelFormat = GL_RG;
pixelType = GL_UNSIGNED_BYTE;
}
else
os::Printer::log("ECF_R8G8 color format is not supported", ELL_ERROR);
break;
case ECF_R16:
if (queryOpenGLFeature(COpenGLExtensionHandler::IRR_ARB_texture_rg))
@ -4238,8 +4232,6 @@ bool COpenGLDriver::getColorFormatParameters(ECOLOR_FORMAT format, GLint& intern
pixelFormat = GL_RED;
pixelType = GL_UNSIGNED_SHORT;
}
else
os::Printer::log("ECF_R16 color format is not supported", ELL_ERROR);
break;
case ECF_R16G16:
if (queryOpenGLFeature(COpenGLExtensionHandler::IRR_ARB_texture_rg))
@ -4249,8 +4241,6 @@ bool COpenGLDriver::getColorFormatParameters(ECOLOR_FORMAT format, GLint& intern
pixelFormat = GL_RG;
pixelType = GL_UNSIGNED_SHORT;
}
else
os::Printer::log("ECF_R16G16 color format is not supported", ELL_ERROR);
break;
case ECF_R16F:
if (queryOpenGLFeature(COpenGLExtensionHandler::IRR_ARB_texture_rg))
@ -4265,8 +4255,6 @@ bool COpenGLDriver::getColorFormatParameters(ECOLOR_FORMAT format, GLint& intern
#endif
pixelType = GL_FLOAT;
}
else
os::Printer::log("ECF_R16F color format is not supported", ELL_ERROR);
break;
case ECF_G16R16F:
if (queryOpenGLFeature(COpenGLExtensionHandler::IRR_ARB_texture_rg))
@ -4281,8 +4269,6 @@ bool COpenGLDriver::getColorFormatParameters(ECOLOR_FORMAT format, GLint& intern
#endif
pixelType = GL_FLOAT;
}
else
os::Printer::log("ECF_G16R16F color format is not supported", ELL_ERROR);
break;
case ECF_A16B16G16R16F:
if (queryOpenGLFeature(COpenGLExtensionHandler::IRR_ARB_texture_float))
@ -4297,8 +4283,6 @@ bool COpenGLDriver::getColorFormatParameters(ECOLOR_FORMAT format, GLint& intern
#endif
pixelType = GL_FLOAT;
}
else
os::Printer::log("ECF_A16B16G16R16F color format is not supported", ELL_ERROR);
break;
case ECF_R32F:
if (queryOpenGLFeature(COpenGLExtensionHandler::IRR_ARB_texture_rg))
@ -4308,8 +4292,6 @@ bool COpenGLDriver::getColorFormatParameters(ECOLOR_FORMAT format, GLint& intern
pixelFormat = GL_RED;
pixelType = GL_FLOAT;
}
else
os::Printer::log("ECF_R32F color format is not supported", ELL_ERROR);
break;
case ECF_G32R32F:
if (queryOpenGLFeature(COpenGLExtensionHandler::IRR_ARB_texture_rg))
@ -4319,8 +4301,6 @@ bool COpenGLDriver::getColorFormatParameters(ECOLOR_FORMAT format, GLint& intern
pixelFormat = GL_RG;
pixelType = GL_FLOAT;
}
else
os::Printer::log("ECF_G32R32F color format is not supported", ELL_ERROR);
break;
case ECF_A32B32G32R32F:
if (queryOpenGLFeature(COpenGLExtensionHandler::IRR_ARB_texture_float))
@ -4330,11 +4310,8 @@ bool COpenGLDriver::getColorFormatParameters(ECOLOR_FORMAT format, GLint& intern
pixelFormat = GL_RGBA;
pixelType = GL_FLOAT;
}
else
os::Printer::log("ECF_A32B32G32R32F color format is not supported", ELL_ERROR);
break;
default:
os::Printer::log("Unsupported texture format", ELL_ERROR);
break;
}