First part of render texture commit
Added NzContext::EnsureContext and NzContext::GetThreadContext Added NzCube Added NzRect::GetCenter Added methods to send vectors to shaders Added NzRenderer::SetViewport Fixed NzRect::ExtendTo calculations Fixed NzImage::Update checks with level > 0 No longer use glTexStorage when creating a texture to prevent a bug NzBuffer's Lock and Unlock operations renamed to Map and Unmap NzVector2/3/4 can now cast implicitly to a pointer Optimized compilation time of String.hpp Optimized normalisaton of quaternions Optimized passing uniforms to shaders Quaternion now automaticaly Normalize h Removed macro definition of NAZARA_RENDERER_OPENGL from Renderer Removed implicit cast from NzVector2/3/4 to NzString Renamed nzBufferLock to nzBufferAccess Renamed NzRenderTarget::CanActivate to IsValid
This commit is contained in:
@@ -9,8 +9,7 @@
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Core/Hashable.hpp>
|
||||
#include <istream>
|
||||
#include <ostream>
|
||||
#include <iosfwd>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
|
||||
58
include/Nazara/Math/Cube.hpp
Normal file
58
include/Nazara/Math/Cube.hpp
Normal file
@@ -0,0 +1,58 @@
|
||||
// Copyright (C) 2012 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine".
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_CUBE_HPP
|
||||
#define NAZARA_CUBE_HPP
|
||||
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <Nazara/Math/Vector3.hpp>
|
||||
|
||||
template<typename T>
|
||||
class NzCube
|
||||
{
|
||||
public:
|
||||
NzCube();
|
||||
NzCube(T X, T Y, T Z, T Width, T Height, T Depth);
|
||||
NzCube(T cube[6]);
|
||||
template<typename U> explicit NzCube(const NzCube<U>& rect);
|
||||
NzCube(const NzCube& rect) = default;
|
||||
~NzCube() = default;
|
||||
|
||||
bool Contains(T X, T Y, T Z) const;
|
||||
bool Contains(const NzVector3<T>& point) const;
|
||||
bool Contains(const NzCube& rect) const;
|
||||
|
||||
void ExtendTo(const NzVector3<T>& point);
|
||||
void ExtendTo(const NzCube& rect);
|
||||
|
||||
NzVector3<T> GetCenter() const;
|
||||
|
||||
bool Intersect(const NzCube& rect) const;
|
||||
bool Intersect(const NzCube& rect, NzCube& intersection) const;
|
||||
|
||||
bool IsValid() const;
|
||||
|
||||
NzString ToString() const;
|
||||
|
||||
operator NzString() const;
|
||||
|
||||
T& operator[](unsigned int i);
|
||||
T operator[](unsigned int i) const;
|
||||
|
||||
T x, y, z, width, height, depth;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
std::ostream& operator<<(std::ostream& out, const NzCube<T>& vec);
|
||||
|
||||
typedef NzCube<double> NzCubed;
|
||||
typedef NzCube<float> NzCubef;
|
||||
typedef NzCube<int> NzCubei;
|
||||
typedef NzCube<unsigned int> NzCubeui;
|
||||
|
||||
#include <Nazara/Math/Cube.inl>
|
||||
|
||||
#endif // NAZARA_CUBE_HPP
|
||||
183
include/Nazara/Math/Cube.inl
Normal file
183
include/Nazara/Math/Cube.inl
Normal file
@@ -0,0 +1,183 @@
|
||||
// Copyright (C) 2012 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine".
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Core/StringStream.hpp>
|
||||
#include <algorithm>
|
||||
#include <Nazara/Core/Debug.hpp>
|
||||
|
||||
template<typename T>
|
||||
NzCube<T>::NzCube()
|
||||
{
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
NzCube<T>::NzCube(T X, T Y, T Z, T Width, T Height, T Depth) :
|
||||
x(X),
|
||||
y(Y),
|
||||
z(Z),
|
||||
width(Width),
|
||||
height(Height),
|
||||
depth(Depth)
|
||||
{
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
NzCube<T>::NzCube(T vec[6]) :
|
||||
x(vec[0]),
|
||||
y(vec[1]),
|
||||
z(vec[2]),
|
||||
width(vec[3]),
|
||||
height(vec[4]),
|
||||
depth(vec[5])
|
||||
{
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
template<typename U>
|
||||
NzCube<T>::NzCube(const NzCube<U>& rect) :
|
||||
x(static_cast<T>(rect.x)),
|
||||
y(static_cast<T>(rect.y)),
|
||||
z(static_cast<T>(rect.z)),
|
||||
width(static_cast<T>(rect.width)),
|
||||
height(static_cast<T>(rect.height)),
|
||||
depth(static_cast<T>(rect.depth))
|
||||
{
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
bool NzCube<T>::Contains(T X, T Y, T Z) const
|
||||
{
|
||||
return X >= x && X < x+width &&
|
||||
Y >= y && Y < y+height &&
|
||||
Z >= z && Z < z+depth;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
bool NzCube<T>::Contains(const NzVector3<T>& point) const
|
||||
{
|
||||
return Contains(point.x, point.y, point.z);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
bool NzCube<T>::Contains(const NzCube<T>& rect) const
|
||||
{
|
||||
return Contains(rect.x, rect.y, rect.z) &&
|
||||
Contains(rect.x + rect.width, rect.y + rect.height, rect.z + rect.depth);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void NzCube<T>::ExtendTo(const NzVector3<T>& point)
|
||||
{
|
||||
x = std::min(x, point.x);
|
||||
y = std::min(y, point.y);
|
||||
z = std::min(z, point.z);
|
||||
width = std::max(x+width, point.x)-x;
|
||||
height = std::max(y+height, point.x)-y;
|
||||
depth = std::max(z+depth, point.x)-z;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void NzCube<T>::ExtendTo(const NzCube& rect)
|
||||
{
|
||||
x = std::min(x, rect.x);
|
||||
y = std::min(y, rect.y);
|
||||
z = std::min(y, rect.z);
|
||||
width = std::max(x+width, rect.x+rect.width)-x;
|
||||
height = std::max(x+height, rect.y+rect.height)-y;
|
||||
depth = std::max(x+depth, rect.z+rect.depth)-z;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
NzVector3<T> NzCube<T>::GetCenter() const
|
||||
{
|
||||
return NzVector3<T>((x+width)/2, (y+height)/2, (z+depth)/2);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
bool NzCube<T>::Intersect(const NzCube& rect) const
|
||||
{
|
||||
NzCube intersection; // Optimisé par le compilateur
|
||||
return Intersect(rect, intersection);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
bool NzCube<T>::Intersect(const NzCube& rect, NzCube& intersection) const
|
||||
{
|
||||
T left = std::max(x, rect.x);
|
||||
T right = std::min(x+width, rect.x+rect.width);
|
||||
T top = std::max(y, rect.y);
|
||||
T bottom = std::min(y+height, rect.y+rect.height);
|
||||
T up = std::max(z, rect.z);
|
||||
T down = std::min(z+depth, rect.z+rect.depth);
|
||||
|
||||
if (left < right && top < bottom && up < down)
|
||||
{
|
||||
intersection.x = left;
|
||||
intersection.y = top;
|
||||
intersection.z = up;
|
||||
intersection.width = right-left;
|
||||
intersection.height = bottom-top;
|
||||
intersection.depth = down-up;
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
bool NzCube<T>::IsValid() const
|
||||
{
|
||||
return width > 0 && height > 0 && depth > 0;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
NzString NzCube<T>::ToString() const
|
||||
{
|
||||
NzStringStream ss;
|
||||
|
||||
return ss << "Cube(" << x << ", " << y << ", " << z << ", " << width << ", " << height << ", " << depth << ')';
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
NzCube<T>::operator NzString() const
|
||||
{
|
||||
return ToString();
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
T& NzCube<T>::operator[](unsigned int i)
|
||||
{
|
||||
if (i >= 6)
|
||||
{
|
||||
NzStringStream ss;
|
||||
ss << __FILE__ << ':' << __LINE__ << ": Index out of range (" << i << " >= 4)";
|
||||
|
||||
throw std::domain_error(ss.ToString());
|
||||
}
|
||||
|
||||
return *(&x+i);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
T NzCube<T>::operator[](unsigned int i) const
|
||||
{
|
||||
if (i >= 6)
|
||||
{
|
||||
NzStringStream ss;
|
||||
ss << __FILE__ << ':' << __LINE__ << ": Index out of range (" << i << " >= 4)";
|
||||
|
||||
throw std::domain_error(ss.ToString());
|
||||
}
|
||||
|
||||
return *(&x+i);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
std::ostream& operator<<(std::ostream& out, const NzCube<T>& rect)
|
||||
{
|
||||
return out << rect.ToString();
|
||||
}
|
||||
|
||||
#include <Nazara/Core/DebugOff.hpp>
|
||||
@@ -47,13 +47,11 @@ template<typename T> class NzQuaternion
|
||||
//NzMatrix3<T> ToRotationMatrix() const;
|
||||
NzString ToString() const;
|
||||
|
||||
NzQuaternion operator+(const NzQuaternion& quat) const;
|
||||
NzQuaternion operator*(const NzQuaternion& quat) const;
|
||||
NzVector3<T> operator*(const NzVector3<T>& vec) const;
|
||||
NzQuaternion operator*(T scale) const;
|
||||
NzQuaternion operator/(const NzQuaternion& quat) const;
|
||||
|
||||
NzQuaternion operator+=(const NzQuaternion& quat);
|
||||
NzQuaternion operator*=(const NzQuaternion& quat);
|
||||
NzQuaternion operator*=(T scale);
|
||||
NzQuaternion operator/=(const NzQuaternion& quat);
|
||||
|
||||
@@ -76,17 +76,21 @@ double NzQuaternion<T>::Magnitude() const
|
||||
template<typename T>
|
||||
double NzQuaternion<T>::Normalize()
|
||||
{
|
||||
double length = Magnitude();
|
||||
T squaredLength = SquaredMagnitude();
|
||||
|
||||
if (length != 0.0)
|
||||
if (std::fabs(squaredLength) > 0.00001 && std::fabs(squaredLength - 1.0) > 0.00001)
|
||||
{
|
||||
double length = std::sqrt(squaredLength);
|
||||
|
||||
w /= length;
|
||||
x /= length;
|
||||
y /= length;
|
||||
z /= length;
|
||||
}
|
||||
|
||||
return length;
|
||||
return length;
|
||||
}
|
||||
else
|
||||
return std::sqrt(squaredLength);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
@@ -102,6 +106,8 @@ void NzQuaternion<T>::Set(T W, T X, T Y, T Z)
|
||||
x = X;
|
||||
y = Y;
|
||||
z = Z;
|
||||
|
||||
Normalize();
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
@@ -111,6 +117,8 @@ void NzQuaternion<T>::Set(T quat[4])
|
||||
x = quat[1];
|
||||
y = quat[2];
|
||||
z = quat[3];
|
||||
|
||||
Normalize();
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
@@ -195,35 +203,32 @@ NzString NzQuaternion<T>::ToString() const
|
||||
return ss << "Quaternion(" << w << " | " << x << ", " << y << ", " << z << ')';
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
NzQuaternion<T> NzQuaternion<T>::operator+(const NzQuaternion& quat) const
|
||||
{
|
||||
return NzQuaternion(w + quat.w,
|
||||
x + quat.x,
|
||||
y + quat.y,
|
||||
z + quat.z);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
NzQuaternion<T> NzQuaternion<T>::operator*(const NzQuaternion& quat) const
|
||||
{
|
||||
return NzQuaternion(w * quat.w - x * quat.x - y * quat.y - z * quat.z,
|
||||
w * quat.x + x * quat.w + y * quat.z - z * quat.y,
|
||||
w * quat.y + y * quat.w + z * quat.x - x * quat.z,
|
||||
w * quat.z + z * quat.w + x * quat.y - y * quat.x);
|
||||
NzQuaternion result(w * quat.w - x * quat.x - y * quat.y - z * quat.z,
|
||||
w * quat.x + x * quat.w + y * quat.z - z * quat.y,
|
||||
w * quat.y + y * quat.w + z * quat.x - x * quat.z,
|
||||
w * quat.z + z * quat.w + x * quat.y - y * quat.x);
|
||||
|
||||
result.Normalize();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
NzVector3<T> NzQuaternion<T>::operator*(const NzVector3<T>& vec) const
|
||||
{
|
||||
NzVector3<T> uv, uuv;
|
||||
NzVector3<T> qvec(x, y, z);
|
||||
uv = qvec.CrossProduct(vec);
|
||||
uuv = qvec.CrossProduct(uv);
|
||||
uv *= 2.0 * w;
|
||||
uuv *= 2.0;
|
||||
NzVector3<T> normal(vec);
|
||||
normal.Normalise();
|
||||
|
||||
NzQuaternion qvec(0.0, normal.x, normal.y, normal.z);
|
||||
NzQuaternion result;
|
||||
|
||||
result = operator*(qvec * GetConjugate());
|
||||
|
||||
return NzVector3<T>(result.x, result.y, result.z);
|
||||
|
||||
return vec + uv + uuv;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
@@ -241,24 +246,12 @@ NzQuaternion<T> NzQuaternion<T>::operator/(const NzQuaternion& quat) const
|
||||
return GetConjugate(quat) * (*this);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
NzQuaternion<T> NzQuaternion<T>::operator+=(const NzQuaternion& quat)
|
||||
{
|
||||
w += quat.w;
|
||||
x += quat.x;
|
||||
y += quat.y;
|
||||
z += quat.z;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
NzQuaternion<T> NzQuaternion<T>::operator*=(const NzQuaternion& quat)
|
||||
{
|
||||
NzQuaternion q(*this);
|
||||
operator=(q * quat);
|
||||
|
||||
return *this;
|
||||
return operator=(q * quat);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
@@ -276,9 +269,8 @@ template<typename T>
|
||||
NzQuaternion<T> NzQuaternion<T>::operator/=(const NzQuaternion& quat)
|
||||
{
|
||||
NzQuaternion q(*this);
|
||||
operator=(q / quat);
|
||||
|
||||
return *this;
|
||||
return operator=(q / quat);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
|
||||
@@ -28,6 +28,8 @@ class NzRect
|
||||
void ExtendTo(const NzVector2<T>& point);
|
||||
void ExtendTo(const NzRect& rect);
|
||||
|
||||
NzVector2<T> GetCenter() const;
|
||||
|
||||
bool Intersect(const NzRect& rect) const;
|
||||
bool Intersect(const NzRect& rect, NzRect& intersection) const;
|
||||
|
||||
|
||||
@@ -65,7 +65,7 @@ void NzRect<T>::ExtendTo(const NzVector2<T>& point)
|
||||
x = std::min(x, point.x);
|
||||
y = std::min(y, point.y);
|
||||
width = std::max(x+width, point.x)-x;
|
||||
height = std::max(x+width, point.x)-y;
|
||||
height = std::max(y+height, point.y)-y;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
@@ -74,7 +74,13 @@ void NzRect<T>::ExtendTo(const NzRect& rect)
|
||||
x = std::min(x, rect.x);
|
||||
y = std::min(y, rect.y);
|
||||
width = std::max(x+width, rect.x+rect.width)-x;
|
||||
height = std::max(x+width, rect.x+rect.height)-y;
|
||||
height = std::max(x+height, rect.y+rect.height)-y;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
NzVector2<T> NzRect<T>::GetCenter() const
|
||||
{
|
||||
return NzVector2<T>((x+width)/2, (y+height)/2);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
@@ -97,7 +103,7 @@ bool NzRect<T>::Intersect(const NzRect& rect, NzRect& intersection) const
|
||||
intersection.x = left;
|
||||
intersection.y = top;
|
||||
intersection.width = right-left;
|
||||
intersection.height = top-bottom;
|
||||
intersection.height = bottom-top;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -33,7 +33,8 @@ template<typename T> class NzVector2
|
||||
|
||||
NzString ToString() const;
|
||||
|
||||
operator NzString() const;
|
||||
operator T*();
|
||||
operator const T*() const;
|
||||
|
||||
T& operator[](unsigned int i);
|
||||
T operator[](unsigned int i) const;
|
||||
|
||||
@@ -136,9 +136,15 @@ NzString NzVector2<T>::ToString() const
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
NzVector2<T>::operator NzString() const
|
||||
NzVector2<T>::operator T*()
|
||||
{
|
||||
return ToString();
|
||||
return &x;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
NzVector2<T>::operator const T*() const
|
||||
{
|
||||
return &x;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
|
||||
@@ -34,7 +34,8 @@ template<typename T> class NzVector3
|
||||
|
||||
NzString ToString() const;
|
||||
|
||||
operator NzString() const;
|
||||
operator T*();
|
||||
operator const T*() const;
|
||||
|
||||
T& operator[](unsigned int i);
|
||||
T operator[](unsigned int i) const;
|
||||
|
||||
@@ -153,9 +153,15 @@ NzString NzVector3<T>::ToString() const
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
NzVector3<T>::operator NzString() const
|
||||
NzVector3<T>::operator T*()
|
||||
{
|
||||
return ToString();
|
||||
return &x;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
NzVector3<T>::operator const T*() const
|
||||
{
|
||||
return &x;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
|
||||
@@ -28,7 +28,8 @@ template<typename T> class NzVector4
|
||||
|
||||
NzString ToString() const;
|
||||
|
||||
operator NzString() const;
|
||||
operator T*();
|
||||
operator const T*() const;
|
||||
|
||||
T& operator[](unsigned int i);
|
||||
T operator[](unsigned int i) const;
|
||||
|
||||
@@ -120,9 +120,15 @@ NzString NzVector4<T>::ToString() const
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
NzVector4<T>::operator NzString() const
|
||||
NzVector4<T>::operator T*()
|
||||
{
|
||||
return ToString();
|
||||
return &x;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
NzVector4<T>::operator const T*() const
|
||||
{
|
||||
return &x;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
|
||||
@@ -17,22 +17,27 @@
|
||||
#include <Nazara/Core/Config.hpp>
|
||||
|
||||
///TODO: Rajouter des tests d'identification de compilateurs
|
||||
// NAZARA_THREADLOCAL n'existe qu'en attendant le support complet de thread_local
|
||||
#if defined(_MSC_VER)
|
||||
#define NAZARA_COMPILER_MSVC
|
||||
#define NAZARA_DEPRECATED(txt) __declspec(deprecated(txt))
|
||||
#define NAZARA_FUNCTION __FUNCSIG__
|
||||
#define NAZARA_THREADLOCAL __declspec(thread)
|
||||
#elif defined(__GNUC__)
|
||||
#define NAZARA_COMPILER_GCC
|
||||
#define NAZARA_DEPRECATED(txt) __attribute__((__deprecated__(txt)))
|
||||
#define NAZARA_FUNCTION __PRETTY_FUNCTION__
|
||||
#define NAZARA_THREADLOCAL __thread
|
||||
#elif defined(__BORLANDC__)
|
||||
#define NAZARA_COMPILER_BORDLAND
|
||||
#define NAZARA_DEPRECATED(txt)
|
||||
#define NAZARA_FUNCTION __FUNC__
|
||||
#define NAZARA_THREADLOCAL __declspec(thread)
|
||||
#else
|
||||
#define NAZARA_COMPILER_UNKNOWN
|
||||
#define NAZARA_DEPRECATED(txt)
|
||||
#define NAZARA_FUNCTION __func__ // __func__ est standard depuis le C++11
|
||||
#define NAZARA_THREADLOCAL thread_local
|
||||
#error This compiler is not fully supported
|
||||
#endif
|
||||
|
||||
|
||||
@@ -11,12 +11,12 @@
|
||||
#include <Nazara/Core/NonCopyable.hpp>
|
||||
#include <Nazara/Utility/Resource.hpp>
|
||||
|
||||
enum nzBufferLock
|
||||
enum nzBufferAccess
|
||||
{
|
||||
nzBufferLock_DiscardAndWrite,
|
||||
nzBufferLock_ReadOnly,
|
||||
nzBufferLock_ReadWrite,
|
||||
nzBufferLock_WriteOnly
|
||||
nzBufferAccess_DiscardAndWrite,
|
||||
nzBufferAccess_ReadOnly,
|
||||
nzBufferAccess_ReadWrite,
|
||||
nzBufferAccess_WriteOnly
|
||||
};
|
||||
|
||||
enum nzBufferStorage
|
||||
@@ -68,8 +68,8 @@ class NAZARA_API NzBuffer : public NzResource, NzNonCopyable
|
||||
|
||||
bool IsHardware() const;
|
||||
|
||||
void* Lock(nzBufferLock lock, unsigned int offset = 0, unsigned int length = 0);
|
||||
bool Unlock();
|
||||
void* Map(nzBufferAccess access, unsigned int offset = 0, unsigned int length = 0);
|
||||
bool Unmap();
|
||||
|
||||
static bool IsSupported(nzBufferStorage storage);
|
||||
|
||||
|
||||
@@ -30,11 +30,12 @@ class NAZARA_API NzContext
|
||||
bool SetActive(bool active);
|
||||
void SwapBuffers();
|
||||
|
||||
static const NzContext* GetCurrent();
|
||||
static bool EnsureContext();
|
||||
static NzContext* GetCurrent();
|
||||
static const NzContext* GetReference();
|
||||
static const NzContext* GetThreadContext();
|
||||
static bool InitializeReference();
|
||||
static void UninitializeReference();
|
||||
static NzContext* GetThreadContext();
|
||||
static bool Initialize();
|
||||
static void Uninitialize();
|
||||
|
||||
private:
|
||||
NzContextParameters m_parameters;
|
||||
|
||||
@@ -30,8 +30,8 @@ class NAZARA_API NzIndexBuffer
|
||||
bool IsHardware() const;
|
||||
bool IsSequential() const;
|
||||
|
||||
void* Lock(nzBufferLock lock, unsigned int offset = 0, unsigned int length = 0);
|
||||
bool Unlock();
|
||||
void* Map(nzBufferAccess access, unsigned int offset = 0, unsigned int length = 0);
|
||||
bool Unmap();
|
||||
|
||||
private:
|
||||
NzBuffer* m_buffer;
|
||||
|
||||
@@ -37,6 +37,7 @@ class NAZARA_API NzOpenGL
|
||||
DebugOutput,
|
||||
FP64,
|
||||
FrameBufferObject,
|
||||
SeparateShaderObjects,
|
||||
Texture3D,
|
||||
TextureCompression_s3tc,
|
||||
TextureStorage,
|
||||
@@ -131,6 +132,17 @@ NAZARA_API extern PFNGLLINKPROGRAMPROC glLinkProgram;
|
||||
NAZARA_API extern PFNGLMAPBUFFERPROC glMapBuffer;
|
||||
NAZARA_API extern PFNGLMAPBUFFERRANGEPROC glMapBufferRange;
|
||||
NAZARA_API extern PFNGLPOLYGONMODEPROC glPolygonMode;
|
||||
NAZARA_API extern PFNGLPROGRAMUNIFORM1DPROC glProgramUniform1d;
|
||||
NAZARA_API extern PFNGLPROGRAMUNIFORM1FPROC glProgramUniform1f;
|
||||
NAZARA_API extern PFNGLPROGRAMUNIFORM1IPROC glProgramUniform1i;
|
||||
NAZARA_API extern PFNGLPROGRAMUNIFORM2DVPROC glProgramUniform2dv;
|
||||
NAZARA_API extern PFNGLPROGRAMUNIFORM2FVPROC glProgramUniform2fv;
|
||||
NAZARA_API extern PFNGLPROGRAMUNIFORM3DVPROC glProgramUniform3dv;
|
||||
NAZARA_API extern PFNGLPROGRAMUNIFORM3FVPROC glProgramUniform3fv;
|
||||
NAZARA_API extern PFNGLPROGRAMUNIFORM4DVPROC glProgramUniform4dv;
|
||||
NAZARA_API extern PFNGLPROGRAMUNIFORM4FVPROC glProgramUniform4fv;
|
||||
NAZARA_API extern PFNGLPROGRAMUNIFORMMATRIX4DVPROC glProgramUniformMatrix4dv;
|
||||
NAZARA_API extern PFNGLPROGRAMUNIFORMMATRIX4FVPROC glProgramUniformMatrix4fv;
|
||||
NAZARA_API extern PFNGLREADPIXELSPROC glReadPixels;
|
||||
NAZARA_API extern PFNGLRENDERBUFFERSTORAGEPROC glRenderbufferStorage;
|
||||
NAZARA_API extern PFNGLSCISSORPROC glScissor;
|
||||
|
||||
@@ -21,15 +21,16 @@ class NAZARA_API NzRenderTarget
|
||||
NzRenderTarget() = default;
|
||||
virtual ~NzRenderTarget();
|
||||
|
||||
virtual bool CanActivate() const = 0;
|
||||
|
||||
virtual NzRenderTargetParameters GetRenderTargetParameters() const = 0;
|
||||
|
||||
#ifdef NAZARA_RENDERER_OPENGL
|
||||
#ifndef NAZARA_RENDERER_COMMON
|
||||
virtual bool HasContext() const = 0;
|
||||
#endif
|
||||
|
||||
virtual unsigned int GetHeight() const = 0;
|
||||
virtual NzRenderTargetParameters GetParameters() const = 0;
|
||||
virtual unsigned int GetWidth() const = 0;
|
||||
|
||||
bool IsActive() const;
|
||||
virtual bool IsValid() const = 0;
|
||||
|
||||
bool SetActive(bool active);
|
||||
|
||||
|
||||
@@ -10,13 +10,10 @@
|
||||
#define NAZARA_RENDERWINDOW_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Renderer/RenderTarget.hpp>
|
||||
#include <Nazara/Renderer/Config.hpp>
|
||||
#include <Nazara/Utility/Window.hpp>
|
||||
|
||||
#ifndef NAZARA_RENDERER_COMMON
|
||||
#include <Nazara/Renderer/ContextParameters.hpp>
|
||||
#endif
|
||||
#include <Nazara/Renderer/RenderTarget.hpp>
|
||||
#include <Nazara/Utility/Window.hpp>
|
||||
|
||||
class NzContext;
|
||||
class NzImage;
|
||||
@@ -25,16 +22,12 @@ struct NzContextParameters;
|
||||
|
||||
class NAZARA_API NzRenderWindow : public NzRenderTarget, public NzWindow
|
||||
{
|
||||
friend class NzTexture;
|
||||
|
||||
public:
|
||||
NzRenderWindow();
|
||||
NzRenderWindow(NzVideoMode mode, const NzString& title, nzUInt32 style = NzWindow::Default, const NzContextParameters& parameters = NzContextParameters());
|
||||
NzRenderWindow(NzWindowHandle handle, const NzContextParameters& parameters = NzContextParameters());
|
||||
virtual ~NzRenderWindow();
|
||||
|
||||
bool CanActivate() const;
|
||||
|
||||
bool CopyToImage(NzImage* image); ///TODO: Const
|
||||
bool CopyToTexture(NzTexture* texture); ///TODO: Const
|
||||
|
||||
@@ -45,14 +38,20 @@ class NAZARA_API NzRenderWindow : public NzRenderTarget, public NzWindow
|
||||
|
||||
void EnableVerticalSync(bool enabled);
|
||||
|
||||
NzRenderTargetParameters GetRenderTargetParameters() const;
|
||||
|
||||
#ifndef NAZARA_RENDERER_COMMON
|
||||
NzContextParameters GetContextParameters() const;
|
||||
#endif
|
||||
|
||||
unsigned int GetHeight() const;
|
||||
NzRenderTargetParameters GetParameters() const;
|
||||
unsigned int GetWidth() const;
|
||||
|
||||
#ifndef NAZARA_RENDERER_COMMON
|
||||
bool HasContext() const;
|
||||
#endif
|
||||
|
||||
bool IsValid() const;
|
||||
|
||||
protected:
|
||||
bool Activate();
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#define NAZARA_RENDERER_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Math/Rect.hpp>
|
||||
#include <map>
|
||||
#include <tuple>
|
||||
|
||||
@@ -87,7 +88,6 @@ enum nzRendererComparison
|
||||
|
||||
enum nzRendererParameter
|
||||
{
|
||||
nzRendererParameter_AlphaTest,
|
||||
nzRendererParameter_Blend,
|
||||
nzRendererParameter_ColorWrite,
|
||||
nzRendererParameter_DepthTest,
|
||||
@@ -135,10 +135,12 @@ class NAZARA_API NzRenderer
|
||||
unsigned int GetMaxTextureUnits() const;
|
||||
NzShader* GetShader() const;
|
||||
NzRenderTarget* GetTarget() const;
|
||||
NzRectui GetViewport() const;
|
||||
|
||||
bool HasCapability(nzRendererCap capability) const;
|
||||
bool Initialize();
|
||||
|
||||
void SetBlendFunc(nzBlendFunc src, nzBlendFunc dest);
|
||||
void SetClearColor(const NzColor& color);
|
||||
void SetClearColor(nzUInt8 r, nzUInt8 g, nzUInt8 b, nzUInt8 a = 255);
|
||||
void SetClearDepth(double depth);
|
||||
@@ -156,6 +158,7 @@ class NAZARA_API NzRenderer
|
||||
bool SetTarget(NzRenderTarget* target);
|
||||
bool SetVertexBuffer(const NzVertexBuffer* vertexBuffer);
|
||||
bool SetVertexDeclaration(const NzVertexDeclaration* vertexDeclaration);
|
||||
void SetViewport(const NzRectui& viewport);
|
||||
|
||||
void Uninitialize();
|
||||
|
||||
|
||||
@@ -11,6 +11,9 @@
|
||||
#include <Nazara/Core/NonCopyable.hpp>
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <Nazara/Math/Matrix4.hpp>
|
||||
#include <Nazara/Math/Vector2.hpp>
|
||||
#include <Nazara/Math/Vector3.hpp>
|
||||
#include <Nazara/Math/Vector4.hpp>
|
||||
#include <Nazara/Utility/Resource.hpp>
|
||||
|
||||
enum nzShaderLanguage
|
||||
@@ -66,6 +69,12 @@ class NAZARA_API NzShader : public NzResource, NzNonCopyable
|
||||
bool SendInteger(const NzString& name, int value);
|
||||
bool SendMatrix(const NzString& name, const NzMatrix4d& matrix);
|
||||
bool SendMatrix(const NzString& name, const NzMatrix4f& matrix);
|
||||
bool SendVector(const NzString& name, const NzVector2d& vector);
|
||||
bool SendVector(const NzString& name, const NzVector2f& vector);
|
||||
bool SendVector(const NzString& name, const NzVector3d& vector);
|
||||
bool SendVector(const NzString& name, const NzVector3f& vector);
|
||||
bool SendVector(const NzString& name, const NzVector4d& vector);
|
||||
bool SendVector(const NzString& name, const NzVector4f& vector);
|
||||
bool SendTexture(const NzString& name, NzTexture* texture);
|
||||
|
||||
void Unlock();
|
||||
|
||||
@@ -39,7 +39,9 @@ class NAZARA_API NzTexture : public NzResource, NzNonCopyable
|
||||
explicit NzTexture(const NzImage& image);
|
||||
~NzTexture();
|
||||
|
||||
bool Bind();
|
||||
#ifndef NAZARA_RENDERER_COMMON
|
||||
bool Bind() const;
|
||||
#endif
|
||||
|
||||
bool Create(nzImageType type, nzPixelFormat format, unsigned int width, unsigned int height, unsigned int depth = 1, nzUInt8 levelCount = 1, bool lock = false);
|
||||
void Destroy();
|
||||
@@ -60,6 +62,7 @@ class NAZARA_API NzTexture : public NzResource, NzNonCopyable
|
||||
|
||||
bool IsCompressed() const;
|
||||
bool IsCubemap() const;
|
||||
bool IsTarget() const;
|
||||
bool IsValid() const;
|
||||
|
||||
bool LoadFromFile(const NzString& filePath, const NzImageParams& params = NzImageParams());
|
||||
@@ -76,10 +79,10 @@ class NAZARA_API NzTexture : public NzResource, NzNonCopyable
|
||||
|
||||
bool Update(const NzImage& image, nzUInt8 level = 0);
|
||||
bool Update(const NzImage& image, const NzRectui& rect, unsigned int z = 0, nzUInt8 level = 0);
|
||||
//bool Update(const NzImage& image, const NzCubeui& cube, nzUInt8 level = 0);
|
||||
bool Update(const NzImage& image, const NzCubeui& cube, nzUInt8 level = 0);
|
||||
bool Update(const nzUInt8* pixels, nzUInt8 level = 0);
|
||||
bool Update(const nzUInt8* pixels, const NzRectui& rect, unsigned int z = 0, nzUInt8 level = 0);
|
||||
//bool Update(const nzUInt8* pixels, const NzCubeui& cube, nzUInt8 level = 0);
|
||||
bool Update(const nzUInt8* pixels, const NzCubeui& cube, nzUInt8 level = 0);
|
||||
bool UpdateFace(nzCubemapFace face, const NzImage& image, nzUInt8 level = 0);
|
||||
bool UpdateFace(nzCubemapFace face, const NzImage& image, const NzRectui& rect, nzUInt8 level = 0);
|
||||
bool UpdateFace(nzCubemapFace face, const nzUInt8* pixels, nzUInt8 level = 0);
|
||||
@@ -92,6 +95,8 @@ class NAZARA_API NzTexture : public NzResource, NzNonCopyable
|
||||
static bool IsTypeSupported(nzImageType type);
|
||||
|
||||
private:
|
||||
void SetTarget(bool isTarget);
|
||||
|
||||
NzTextureImpl* m_impl;
|
||||
};
|
||||
|
||||
|
||||
@@ -29,8 +29,8 @@ class NAZARA_API NzVertexBuffer
|
||||
|
||||
bool IsHardware() const;
|
||||
|
||||
void* Lock(nzBufferLock lock, unsigned int offset = 0, unsigned int length = 0);
|
||||
bool Unlock();
|
||||
void* Map(nzBufferAccess access, unsigned int offset = 0, unsigned int length = 0);
|
||||
bool Unmap();
|
||||
|
||||
private:
|
||||
NzBuffer* m_buffer;
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Core/Color.hpp>
|
||||
#include <Nazara/Core/InputStream.hpp>
|
||||
#include <Nazara/Math/Cube.hpp>
|
||||
#include <Nazara/Math/Rect.hpp>
|
||||
#include <Nazara/Utility/ResourceLoader.hpp>
|
||||
#include <Nazara/Utility/PixelFormat.hpp>
|
||||
@@ -104,7 +105,7 @@ class NAZARA_API NzImage : public NzResource, public NzResourceLoader<NzImage, N
|
||||
|
||||
bool Update(const nzUInt8* pixels, nzUInt8 level = 0);
|
||||
bool Update(const nzUInt8* pixels, const NzRectui& rect, unsigned int z = 0, nzUInt8 level = 0);
|
||||
//bool Update(const nzUInt8* pixels, const NzCubeui& cube, nzUInt8 level = 0);
|
||||
bool Update(const nzUInt8* pixels, const NzCubeui& cube, nzUInt8 level = 0);
|
||||
bool UpdateFace(nzCubemapFace face, const nzUInt8* pixels, nzUInt8 level = 0);
|
||||
bool UpdateFace(nzCubemapFace face, const nzUInt8* pixels, const NzRectui& rect, nzUInt8 level = 0);
|
||||
|
||||
|
||||
@@ -35,6 +35,16 @@ enum nzPixelFormat
|
||||
nzPixelFormat_RGB5A1, // 1*nzUInt16
|
||||
nzPixelFormat_RGB8, // 3*nzUInt8
|
||||
nzPixelFormat_RGBA8, // 4*nzUInt8
|
||||
/*
|
||||
nzPixelFormat_Depth16,
|
||||
nzPixelFormat_Depth24,
|
||||
nzPixelFormat_Depth24Stencil8,
|
||||
nzPixelFormat_Depth32,
|
||||
nzPixelFormat_Stencil1,
|
||||
nzPixelFormat_Stencil4,
|
||||
nzPixelFormat_Stencil8,
|
||||
nzPixelFormat_Stencil16,
|
||||
*/
|
||||
|
||||
nzPixelFormat_Count
|
||||
};
|
||||
|
||||
@@ -35,7 +35,7 @@ inline bool NzPixelFormat::Convert(nzPixelFormat srcFormat, nzPixelFormat dstFor
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!func(static_cast<const nzUInt8*>(src), static_cast<const nzUInt8*>(src) + GetBPP(srcFormat), static_cast<nzUInt8*>(dst)))
|
||||
if (!func(reinterpret_cast<const nzUInt8*>(src), reinterpret_cast<const nzUInt8*>(src) + GetBPP(srcFormat), reinterpret_cast<nzUInt8*>(dst)))
|
||||
{
|
||||
NazaraError("Pixel format conversion from " + ToString(srcFormat) + " to " + ToString(dstFormat) + " failed");
|
||||
return false;
|
||||
@@ -48,7 +48,7 @@ inline bool NzPixelFormat::Convert(nzPixelFormat srcFormat, nzPixelFormat dstFor
|
||||
{
|
||||
if (srcFormat == dstFormat)
|
||||
{
|
||||
std::memcpy(dst, start, static_cast<const nzUInt8*>(end)-static_cast<const nzUInt8*>(start));
|
||||
std::memcpy(dst, start, reinterpret_cast<const nzUInt8*>(end)-reinterpret_cast<const nzUInt8*>(start));
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ inline bool NzPixelFormat::Convert(nzPixelFormat srcFormat, nzPixelFormat dstFor
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!func(static_cast<const nzUInt8*>(start), static_cast<const nzUInt8*>(end), static_cast<nzUInt8*>(dst)))
|
||||
if (!func(reinterpret_cast<const nzUInt8*>(start), reinterpret_cast<const nzUInt8*>(end), reinterpret_cast<nzUInt8*>(dst)))
|
||||
{
|
||||
NazaraError("Pixel format conversion from " + ToString(srcFormat) + " to " + ToString(dstFormat) + " failed");
|
||||
return false;
|
||||
@@ -72,10 +72,6 @@ inline nzUInt8 NzPixelFormat::GetBPP(nzPixelFormat format)
|
||||
{
|
||||
switch (format)
|
||||
{
|
||||
case nzPixelFormat_Count:
|
||||
case nzPixelFormat_Undefined:
|
||||
return 0;
|
||||
|
||||
case nzPixelFormat_BGR8:
|
||||
return 3;
|
||||
|
||||
@@ -132,6 +128,11 @@ inline nzUInt8 NzPixelFormat::GetBPP(nzPixelFormat format)
|
||||
|
||||
case nzPixelFormat_RGBA8:
|
||||
return 4;
|
||||
|
||||
case nzPixelFormat_Count:
|
||||
case nzPixelFormat_Undefined:
|
||||
NazaraError("Invalid pixel format");
|
||||
return 0;
|
||||
}
|
||||
|
||||
NazaraInternalError("Invalid pixel format");
|
||||
@@ -152,9 +153,19 @@ inline bool NzPixelFormat::HasAlpha(nzPixelFormat format)
|
||||
case nzPixelFormat_RGBA8:
|
||||
return true;
|
||||
|
||||
default:
|
||||
case nzPixelFormat_BGR8:
|
||||
case nzPixelFormat_DXT1:
|
||||
case nzPixelFormat_L8:
|
||||
case nzPixelFormat_RGB8:
|
||||
return false;
|
||||
|
||||
case nzPixelFormat_Count:
|
||||
case nzPixelFormat_Undefined:
|
||||
break;
|
||||
}
|
||||
|
||||
NazaraError("Invalid pixel format");
|
||||
return false;
|
||||
}
|
||||
|
||||
inline bool NzPixelFormat::IsCompressed(nzPixelFormat format)
|
||||
@@ -258,13 +269,13 @@ inline NzString NzPixelFormat::ToString(nzPixelFormat format)
|
||||
case nzPixelFormat_RGBA8:
|
||||
return "RGBA8";
|
||||
|
||||
default:
|
||||
NazaraInternalError("Invalid pixel format");
|
||||
|
||||
case nzPixelFormat_Count:
|
||||
case nzPixelFormat_Undefined:
|
||||
return "Invalid format";
|
||||
break;
|
||||
}
|
||||
|
||||
NazaraError("Invalid pixel format");
|
||||
return "Invalid format";
|
||||
}
|
||||
|
||||
#include <Nazara/Utility/DebugOff.hpp>
|
||||
|
||||
Reference in New Issue
Block a user