Merging r6493 through r6517 from trunk to ogl-es branch

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/branches/ogl-es@6518 dfc29bdd-3216-0410-991c-e03cc46cb475
This commit is contained in:
cutealien
2023-08-03 19:12:11 +00:00
parent 1de0ec5459
commit e9c494503d
16 changed files with 216 additions and 85 deletions

View File

@ -108,17 +108,97 @@ namespace scene
\param numVertices Number of vertices in the array.
\param indices Pointer to index array.
\param numIndices Number of indices in array. */
virtual void append(const void* const vertices, u32 numVertices, const u16* const indices, u32 numIndices) IRR_OVERRIDE
virtual void append(const void* const vertices, u32 numVertices, const u16* const indices, u32 numIndices, bool updateBoundingBox=true) IRR_OVERRIDE
{
// TODO
// We simply assume it has the same vertex and index type as this object. If other types are passed this will crash
append(getVertexType(), vertices, numVertices, getIndexType(), indices, numIndices, updateBoundingBox);
}
//! Append the meshbuffer to the current buffer
/** Only works for compatible vertex types
\param other Buffer to append to this one. */
virtual void append(const IMeshBuffer* const other) IRR_OVERRIDE
/** \param other Buffer to append to this one. */
virtual void append(const IMeshBuffer* const other, bool updateBoundingBox=true) IRR_OVERRIDE
{
// TODO
append(other->getVertexType(), other->getVertices(), other->getVertexCount(), other->getIndexType(), other->getIndices(), other->getIndexCount(), updateBoundingBox);
}
void append(video::E_VERTEX_TYPE vertexType, const void* const vertices, u32 numVertices, video::E_INDEX_TYPE indexType, const void* const indices, u32 numIndices, bool updateBoundingBox)
{
if (vertices == getVertices() || indices == getIndices()) // can't do that because we're doing reallocations on those blocks
return;
const u32 vertexCount = getVertexCount();
VertexBuffer->reallocate(vertexCount+numVertices, false);
if ( vertexType == getVertexType() )
{
const irr::u32 typeSize = getVertexPitchFromType(vertexType);
VertexBuffer->set_used(vertexCount+numVertices);
irr::u8* target = &static_cast<irr::u8*>(VertexBuffer->pointer())[vertexCount*typeSize];
memcpy(target, vertices, numVertices*typeSize);
}
else
{
switch ( vertexType )
{
case video::EVT_STANDARD:
for (u32 i=0; i<numVertices; ++i)
{
VertexBuffer->push_back(static_cast<const video::S3DVertex*>(vertices)[i]);
}
break;
case video::EVT_2TCOORDS:
for (u32 i=0; i<numVertices; ++i)
{
VertexBuffer->push_back(static_cast<const video::S3DVertex2TCoords*>(vertices)[i]);
}
break;
case video::EVT_TANGENTS:
for (u32 i=0; i<numVertices; ++i)
{
VertexBuffer->push_back(static_cast<const video::S3DVertexTangents*>(vertices)[i]);
}
break;
}
}
if ( updateBoundingBox && numVertices > 0)
{
if ( vertexCount == 0 )
BoundingBox.reset( static_cast<const video::S3DVertex*>(vertices)[0].Pos );
const u32 typePitch = getVertexPitchFromType(vertexType);
const irr::u8* v8 = static_cast<const irr::u8*>(vertices);
for (u32 i=0; i<numVertices; ++i, v8 += typePitch)
{
BoundingBox.addInternalPoint(reinterpret_cast<const video::S3DVertex*>(v8)->Pos);
}
}
IndexBuffer->reallocate(getIndexCount()+numIndices, false);
switch ( indexType )
{
case video::EIT_16BIT:
{
const irr::u16* indices16 = reinterpret_cast<const irr::u16*>(indices);
for (u32 i=0; i<numIndices; ++i)
{
// Note: This can overflow, not checked. Will result in broken models, but no crashes.
IndexBuffer->push_back(indices16[i]+vertexCount);
}
break;
}
case video::EIT_32BIT:
{
const irr::u32* indices32 = reinterpret_cast<const irr::u32*>(indices);
for (u32 i=0; i<numIndices; ++i)
{
IndexBuffer->push_back(indices32[i]+vertexCount);
}
break;
}
}
setDirty();
}

View File

@ -191,59 +191,48 @@ namespace scene
//! Append the vertices and indices to the current buffer
/** Only works for compatible types, i.e. either the same type
or the main buffer is of standard type. Otherwise, behavior is
undefined.
undefined. Also can't append it's own vertices/indices to itself.
*/
virtual void append(const void* const vertices, u32 numVertices, const u16* const indices, u32 numIndices) IRR_OVERRIDE
virtual void append(const void* const vertices, u32 numVertices, const u16* const indices, u32 numIndices, bool updateBoundingBox=true) IRR_OVERRIDE
{
if (vertices == getVertices())
if (vertices == getVertices() || indices == getIndices()) // can't do that because we're doing reallocations on those blocks
return;
const u32 vertexCount = getVertexCount();
u32 i;
Vertices.reallocate(vertexCount+numVertices);
Vertices.reallocate(vertexCount+numVertices, false);
for (i=0; i<numVertices; ++i)
{
Vertices.push_back(static_cast<const T*>(vertices)[i]);
BoundingBox.addInternalPoint(static_cast<const T*>(vertices)[i].Pos);
}
Indices.reallocate(getIndexCount()+numIndices);
if ( updateBoundingBox && numVertices > 0)
{
if ( vertexCount == 0 )
BoundingBox.reset(static_cast<const T*>(vertices)[0].Pos);
for (i=0; i<numVertices; ++i)
BoundingBox.addInternalPoint(static_cast<const T*>(vertices)[i].Pos);
}
Indices.reallocate(getIndexCount()+numIndices, false);
for (i=0; i<numIndices; ++i)
{
Indices.push_back(indices[i]+vertexCount);
}
setDirty();
}
//! Append the meshbuffer to the current buffer
/** Only works for compatible types, i.e. either the same type
or the main buffer is of standard type. Otherwise, behavior is
undefined.
\param other Meshbuffer to be appended to this one.
*/
virtual void append(const IMeshBuffer* const other) IRR_OVERRIDE
virtual void append(const IMeshBuffer* const other, bool updateBoundingBox=true) IRR_OVERRIDE
{
/*
if (this==other)
if ( getVertexType() != other->getVertexType() )
return;
const u32 vertexCount = getVertexCount();
u32 i;
Vertices.reallocate(vertexCount+other->getVertexCount());
for (i=0; i<other->getVertexCount(); ++i)
{
Vertices.push_back(reinterpret_cast<const T*>(other->getVertices())[i]);
}
Indices.reallocate(getIndexCount()+other->getIndexCount());
for (i=0; i<other->getIndexCount(); ++i)
{
Indices.push_back(other->getIndices()[i]+vertexCount);
}
BoundingBox.addInternalBox(other->getBoundingBox());
*/
append(other->getVertices(), other->getVertexCount(), other->getIndices(), other->getIndexCount(), updateBoundingBox);
}

View File

@ -24,7 +24,7 @@ public:
//! Destructor
virtual ~IMaterialRendererServices() {}
//! Return an index constant for the vertex shader based on a name.
//! Return an index constant for the vertex shader based on a uniform variable name.
virtual s32 getVertexShaderConstantID(const c8* name) = 0;
//! Call when you set shader constants outside of IShaderConstantSetCallBack
@ -41,27 +41,8 @@ public:
//! Call this when you are done setting shader constants outside of OnCreate or OnSetConstants
virtual void stopUseProgram() {}
//! Sets a constant for the vertex shader based on a name.
/** This can be used if you used a high level shader language like GLSL
or HLSL to create a shader. Example: If you created a shader which has
variables named 'mWorldViewProj' (containing the WorldViewProjection
matrix) and another one named 'fTime' containing one float, you can set
them in your IShaderConstantSetCallBack derived class like this:
\code
virtual void OnSetConstants(video::IMaterialRendererServices* services, s32 userData)
{
video::IVideoDriver* driver = services->getVideoDriver();
f32 time = (f32)os::Timer::getTime()/100000.0f;
services->setVertexShaderConstant("fTime", &time, 1);
core::matrix4 worldViewProj(driver->getTransform(video::ETS_PROJECTION));
worldViewProj *= driver->getTransform(video::ETS_VIEW);
worldViewProj *= driver->getTransform(video::ETS_WORLD);
services->setVertexShaderConstant("mWorldViewProj", worldViewProj.M, 16);
}
\endcode
\param index Index of the variable
//! Sets a value for a vertex shader uniform variable.
/**\param index Index of the variable (as received from getVertexShaderConstantID)
\param floats Pointer to array of floats
\param count Amount of floats in array.
\return True if successful.
@ -77,7 +58,7 @@ public:
*/
virtual bool setVertexShaderConstant(s32 index, const u32* ints, int count) = 0;
//! Sets a vertex shader constant.
//! Sets a vertex shader constant (or "uniform" in more modern terms)
/** Can be used if you created a shader using pixel/vertex shader
assembler or ARB_fragment_program or ARB_vertex_program.
\param data: Data to be set in the constants
@ -85,14 +66,14 @@ public:
\param constantAmount: Amount of registers to be set. One register consists of 4 floats. */
virtual void setVertexShaderConstant(const f32* data, s32 startRegister, s32 constantAmount=1) = 0;
//! Return an index constant for the pixel shader based on a name.
//! Return an index constant for the pixel shader for the given uniform variable name
virtual s32 getPixelShaderConstantID(const c8* name) = 0;
//! Sets a constant for the pixel shader based on a name.
//! Sets a value for the given pixel shader uniform variable
/** This can be used if you used a high level shader language like GLSL
or HLSL to create a shader. See setVertexShaderConstant() for an
example on how to use this.
\param index Index of the variable
\param index Index of the variable (as received from getPixelShaderConstantID)
\param floats Pointer to array of floats
\param count Amount of floats in array.
\return True if successful. */
@ -116,6 +97,26 @@ public:
virtual void setPixelShaderConstant(const f32* data, s32 startRegister, s32 constantAmount=1) = 0;
//! \deprecated. This method may be removed by Irrlicht 2.0
/** This can be used if you use a high level shader language like GLSL
or HLSL to create a shader. Example: If you created a shader which has
variables named 'mWorldViewProj' (containing the WorldViewProjection
matrix) and another one named 'fTime' containing one float, you can set
them in your IShaderConstantSetCallBack derived class like this:
\code
virtual void OnSetConstants(video::IMaterialRendererServices* services, s32 userData)
{
video::IVideoDriver* driver = services->getVideoDriver();
f32 time = (f32)os::Timer::getTime()/100000.0f;
services->setVertexShaderConstant("fTime", &time, 1);
core::matrix4 worldViewProj(driver->getTransform(video::ETS_PROJECTION));
worldViewProj *= driver->getTransform(video::ETS_VIEW);
worldViewProj *= driver->getTransform(video::ETS_WORLD);
services->setVertexShaderConstant("mWorldViewProj", worldViewProj.M, 16);
}
\endcode
**/
IRR_DEPRECATED bool setVertexShaderConstant(const c8* name, const f32* floats, int count)
{
return setVertexShaderConstant(getVertexShaderConstantID(name), floats, count);

View File

@ -126,19 +126,21 @@ namespace scene
virtual const video::SColor& getColor(u32 i) const = 0;
//! Append the vertices and indices to the current buffer
/** Only works for compatible vertex types
and not implemented for most buffers for now.
/** Only works for compatible vertex and index types
and not implemented for some buffers for now.
\param vertices Pointer to a vertex array.
\param numVertices Number of vertices in the array.
\param indices Pointer to index array.
\param numIndices Number of indices in array. */
virtual void append(const void* const vertices, u32 numVertices, const u16* const indices, u32 numIndices) = 0;
\param numIndices Number of indices in array.
\param updateBoundingBox When true update boundingbox by the added vertices */
virtual void append(const void* const vertices, u32 numVertices, const u16* const indices, u32 numIndices, bool updateBoundingBox=true) = 0;
//! Not supported right now by any meshbuffer
//! Not supported right now by all meshbuffer
//! In theory: Append the meshbuffer to the current buffer
/** Only works for compatible vertex types
\param other Buffer to append to this one. */
virtual void append(const IMeshBuffer* const other) = 0;
/** Only works for compatible vertex and index types
\param other Buffer to append to this one.
s \param updateBoundingBox When true update boundingbox by the added vertices */
virtual void append(const IMeshBuffer* const other, bool updateBoundingBox=true) = 0;
//! get the current hardware mapping hint
virtual E_HARDWARE_MAPPING getHardwareMappingHint_Vertex() const = 0;

View File

@ -392,8 +392,7 @@ namespace video
const io::path& name = "rt", const ECOLOR_FORMAT format = ECF_UNKNOWN) =0;
//! Adds a new render target texture with 6 sides for a cubemap map to the texture cache.
/** NOTE: Only supported on D3D9 so far.
\param sideLen Length of one cubemap side.
/** \param sideLen Length of one cubemap side.
\param name A name for the texture. Later calls of getTexture() with this name will return this texture.
The name can _not_ be empty.
\param format The color format of the render target. Floating point formats are supported.

View File

@ -187,13 +187,13 @@ namespace scene
//! append the vertices and indices to the current buffer
virtual void append(const void* const vertices, u32 numVertices, const u16* const indices, u32 numIndices) IRR_OVERRIDE
virtual void append(const void* const vertices, u32 numVertices, const u16* const indices, u32 numIndices, bool updateBoundingBox) IRR_OVERRIDE
{
// can't do that as it doesn't own the vertex memory
}
//! append the meshbuffer to the current buffer
virtual void append(const IMeshBuffer* const other) IRR_OVERRIDE
virtual void append(const IMeshBuffer* const other, bool updateBoundingBox) IRR_OVERRIDE
{
// can't do that as it doesn't own the vertex memory
}

View File

@ -355,10 +355,10 @@ struct SSkinMeshBuffer : public IMeshBuffer
}
//! append the vertices and indices to the current buffer
virtual void append(const void* const vertices, u32 numVertices, const u16* const indices, u32 numIndices) IRR_OVERRIDE {}
virtual void append(const void* const vertices, u32 numVertices, const u16* const indices, u32 numIndices, bool updateBoundingBox) IRR_OVERRIDE {}
//! append the meshbuffer to the current buffer
virtual void append(const IMeshBuffer* const other) IRR_OVERRIDE {}
virtual void append(const IMeshBuffer* const other, bool updateBoundingBox) IRR_OVERRIDE {}
//! get the current hardware mapping hint for vertex buffers
virtual E_HARDWARE_MAPPING getHardwareMappingHint_Vertex() const IRR_OVERRIDE

View File

@ -721,6 +721,8 @@ inline core::quaternion& quaternion::makeIdentity()
inline core::quaternion& quaternion::rotationFromTo(const vector3df& from, const vector3df& to)
{
// Based on Stan Melax's article in Game Programming Gems
// Optimized by Robert Eisele: https://raw.org/proof/quaternion-from-two-vectors
// Copy, since cannot modify local
vector3df v0 = from;
vector3df v1 = to;
@ -745,10 +747,8 @@ inline core::quaternion& quaternion::rotationFromTo(const vector3df& from, const
return set(axis.X, axis.Y, axis.Z, 0).normalize();
}
const f32 s = sqrtf( (1+d)*2 ); // optimize inv_sqrt
const f32 invs = 1.f / s;
const vector3df c = v0.crossProduct(v1)*invs;
return set(c.X, c.Y, c.Z, s * 0.5f).normalize();
const vector3df c = v0.crossProduct(v1);
return set(c.X, c.Y, c.Z, 1 + d).normalize();
}