Windows/WASM platform fixes
This commit is contained in:
parent
de7778b147
commit
3ce7de6134
5 changed files with 27 additions and 11 deletions
|
|
@ -247,30 +247,30 @@ struct mat4 {
|
||||||
// Perspective projection matrix
|
// Perspective projection matrix
|
||||||
// fov: vertical field of view in radians
|
// fov: vertical field of view in radians
|
||||||
// aspect: width / height
|
// aspect: width / height
|
||||||
// near, far: clipping planes
|
// nearPlane, farPlane: clipping planes
|
||||||
static mat4 perspective(float fov, float aspect, float near, float far) {
|
static mat4 perspective(float fov, float aspect, float nearPlane, float farPlane) {
|
||||||
mat4 result;
|
mat4 result;
|
||||||
float tanHalfFov = std::tan(fov / 2.0f);
|
float tanHalfFov = std::tan(fov / 2.0f);
|
||||||
|
|
||||||
result.at(0, 0) = 1.0f / (aspect * tanHalfFov);
|
result.at(0, 0) = 1.0f / (aspect * tanHalfFov);
|
||||||
result.at(1, 1) = 1.0f / tanHalfFov;
|
result.at(1, 1) = 1.0f / tanHalfFov;
|
||||||
result.at(2, 2) = -(far + near) / (far - near);
|
result.at(2, 2) = -(farPlane + nearPlane) / (farPlane - nearPlane);
|
||||||
result.at(2, 3) = -1.0f;
|
result.at(2, 3) = -1.0f;
|
||||||
result.at(3, 2) = -(2.0f * far * near) / (far - near);
|
result.at(3, 2) = -(2.0f * farPlane * nearPlane) / (farPlane - nearPlane);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Orthographic projection matrix
|
// Orthographic projection matrix
|
||||||
static mat4 ortho(float left, float right, float bottom, float top, float near, float far) {
|
static mat4 ortho(float left, float right, float bottom, float top, float nearPlane, float farPlane) {
|
||||||
mat4 result = identity();
|
mat4 result = identity();
|
||||||
|
|
||||||
result.at(0, 0) = 2.0f / (right - left);
|
result.at(0, 0) = 2.0f / (right - left);
|
||||||
result.at(1, 1) = 2.0f / (top - bottom);
|
result.at(1, 1) = 2.0f / (top - bottom);
|
||||||
result.at(2, 2) = -2.0f / (far - near);
|
result.at(2, 2) = -2.0f / (farPlane - nearPlane);
|
||||||
result.at(3, 0) = -(right + left) / (right - left);
|
result.at(3, 0) = -(right + left) / (right - left);
|
||||||
result.at(3, 1) = -(top + bottom) / (top - bottom);
|
result.at(3, 1) = -(top + bottom) / (top - bottom);
|
||||||
result.at(3, 2) = -(far + near) / (far - near);
|
result.at(3, 2) = -(farPlane + nearPlane) / (farPlane - nearPlane);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -51,7 +51,7 @@ PyObject* VoxelPoint::get_bool_member(PyVoxelPointObject* self, void* closure)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
long member = reinterpret_cast<long>(closure);
|
intptr_t member = reinterpret_cast<intptr_t>(closure);
|
||||||
bool value = false;
|
bool value = false;
|
||||||
|
|
||||||
switch (member) {
|
switch (member) {
|
||||||
|
|
@ -82,7 +82,7 @@ int VoxelPoint::set_bool_member(PyVoxelPointObject* self, PyObject* value, void*
|
||||||
}
|
}
|
||||||
|
|
||||||
bool newValue = PyObject_IsTrue(value);
|
bool newValue = PyObject_IsTrue(value);
|
||||||
long member = reinterpret_cast<long>(closure);
|
intptr_t member = reinterpret_cast<intptr_t>(closure);
|
||||||
|
|
||||||
switch (member) {
|
switch (member) {
|
||||||
case VOXEL_WALKABLE:
|
case VOXEL_WALKABLE:
|
||||||
|
|
@ -111,7 +111,7 @@ PyObject* VoxelPoint::get_float_member(PyVoxelPointObject* self, void* closure)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
long member = reinterpret_cast<long>(closure);
|
intptr_t member = reinterpret_cast<intptr_t>(closure);
|
||||||
float value = 0.0f;
|
float value = 0.0f;
|
||||||
|
|
||||||
switch (member) {
|
switch (member) {
|
||||||
|
|
@ -146,7 +146,7 @@ int VoxelPoint::set_float_member(PyVoxelPointObject* self, PyObject* value, void
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
long member = reinterpret_cast<long>(closure);
|
intptr_t member = reinterpret_cast<intptr_t>(closure);
|
||||||
|
|
||||||
switch (member) {
|
switch (member) {
|
||||||
case VOXEL_HEIGHT:
|
case VOXEL_HEIGHT:
|
||||||
|
|
|
||||||
|
|
@ -503,6 +503,10 @@ public:
|
||||||
size_ = Vector2u(256, 256);
|
size_ = Vector2u(256, 256);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
bool loadFromImage(const Image& image) {
|
||||||
|
size_ = image.getSize();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
Vector2u getSize() const { return size_; }
|
Vector2u getSize() const { return size_; }
|
||||||
void setSmooth(bool smooth) {}
|
void setSmooth(bool smooth) {}
|
||||||
bool isSmooth() const { return false; }
|
bool isSmooth() const { return false; }
|
||||||
|
|
|
||||||
|
|
@ -1100,6 +1100,17 @@ bool Texture::loadFromMemory(const void* data, size_t size) {
|
||||||
return textureId_ != 0;
|
return textureId_ != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Texture::loadFromImage(const Image& image) {
|
||||||
|
if (textureId_) {
|
||||||
|
SDL2Renderer::getInstance().deleteTexture(textureId_);
|
||||||
|
}
|
||||||
|
auto imgSize = image.getSize();
|
||||||
|
size_ = imgSize;
|
||||||
|
textureId_ = SDL2Renderer::getInstance().createTexture(
|
||||||
|
imgSize.x, imgSize.y, image.getPixelsPtr());
|
||||||
|
return textureId_ != 0;
|
||||||
|
}
|
||||||
|
|
||||||
void Texture::setSmooth(bool smooth) {
|
void Texture::setSmooth(bool smooth) {
|
||||||
smooth_ = smooth;
|
smooth_ = smooth;
|
||||||
if (textureId_) {
|
if (textureId_) {
|
||||||
|
|
|
||||||
|
|
@ -669,6 +669,7 @@ public:
|
||||||
bool create(unsigned int width, unsigned int height); // Implemented in SDL2Renderer.cpp
|
bool create(unsigned int width, unsigned int height); // Implemented in SDL2Renderer.cpp
|
||||||
bool loadFromFile(const std::string& filename); // Implemented in SDL2Renderer.cpp
|
bool loadFromFile(const std::string& filename); // Implemented in SDL2Renderer.cpp
|
||||||
bool loadFromMemory(const void* data, size_t size); // Implemented in SDL2Renderer.cpp
|
bool loadFromMemory(const void* data, size_t size); // Implemented in SDL2Renderer.cpp
|
||||||
|
bool loadFromImage(const Image& image); // Implemented in SDL2Renderer.cpp
|
||||||
|
|
||||||
Vector2u getSize() const { return size_; }
|
Vector2u getSize() const { return size_; }
|
||||||
void setSize(unsigned int width, unsigned int height) { size_ = Vector2u(width, height); }
|
void setSize(unsigned int width, unsigned int height) { size_ = Vector2u(width, height); }
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue