Add PSP host.
This commit is contained in:
@ -61,8 +61,10 @@ void BackBuffer::clear(const int32_t clearFlags) {
|
||||
}
|
||||
|
||||
void BackBuffer::bind() {
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
assertNoGLError();
|
||||
#if DAWN_OPENGL_FRAMEBUFFERS
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
assertNoGLError();
|
||||
#endif
|
||||
glViewport(0, 0, (GLsizei)this->width, (GLsizei)this->height);
|
||||
assertNoGLError();
|
||||
}
|
@ -6,11 +6,15 @@
|
||||
# Sources
|
||||
target_sources(${DAWN_TARGET_NAME}
|
||||
PRIVATE
|
||||
Color.cpp
|
||||
BackBuffer.cpp
|
||||
Texture.cpp
|
||||
RenderManager.cpp
|
||||
)
|
||||
|
||||
# Subdirs
|
||||
add_subdirectory(mesh)
|
||||
add_subdirectory(shader)
|
||||
# add_subdirectory(mesh)
|
||||
if(DAWN_OPENGL_SHADERS EQUAL TRUE)
|
||||
message(FATAL_ERROR "DAWN_OPENGL_SHADERS: ${DAWN_OPENGL_SHADERS}")
|
||||
add_subdirectory(shader)
|
||||
endif()
|
84
src/dawnopengl/display/Color.cpp
Normal file
84
src/dawnopengl/display/Color.cpp
Normal file
@ -0,0 +1,84 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "Color.hpp"
|
||||
#include "error/assert.hpp"
|
||||
#include "util/string.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
struct Color Color::fromString(const std::string str) {
|
||||
// Convert to lowercase
|
||||
auto lower = stringToLowercase(str);
|
||||
|
||||
if(stringIncludes(lower, "cornflower")) {
|
||||
return COLOR_CORNFLOWER_BLUE;
|
||||
|
||||
} else if(stringIncludes(lower, "magenta")) {
|
||||
return COLOR_MAGENTA;
|
||||
|
||||
} else if(stringIncludes(lower, "white")) {
|
||||
return COLOR_WHITE;
|
||||
|
||||
} else if(stringIncludes(lower, "black")) {
|
||||
return COLOR_BLACK;
|
||||
|
||||
} else if(stringIncludes(lower, "red")) {
|
||||
return COLOR_RED;
|
||||
|
||||
} else if(stringIncludes(lower, "green")) {
|
||||
return COLOR_GREEN;
|
||||
|
||||
} else if(stringIncludes(lower, "blue")) {
|
||||
return COLOR_BLUE;
|
||||
|
||||
} else if(stringIncludes(lower, "transparent")) {
|
||||
return COLOR_TRANSPARENT;
|
||||
}
|
||||
|
||||
// Hex code?
|
||||
if(lower[0] == '#') {
|
||||
// Remove the hash
|
||||
lower = lower.substr(1);
|
||||
|
||||
// Convert to RGB
|
||||
if(lower.length() == 3) {
|
||||
// Convert to 6 digit hex
|
||||
lower = lower[0] + lower[0] + lower[1] + lower[1] + lower[2] + lower[2];
|
||||
}
|
||||
|
||||
// Convert to RGB
|
||||
return {
|
||||
(float_t)std::stoi(lower.substr(0, 2), nullptr, 16) / 255.0f,
|
||||
(float_t)std::stoi(lower.substr(2, 2), nullptr, 16) / 255.0f,
|
||||
(float_t)std::stoi(lower.substr(4, 2), nullptr, 16) / 255.0f,
|
||||
1.0f
|
||||
};
|
||||
}
|
||||
|
||||
// Split by comma
|
||||
auto splitByComma = stringSplit(str, ",");
|
||||
if(splitByComma.size() == 3) {
|
||||
// RGB
|
||||
return {
|
||||
(float_t)std::stof(splitByComma[0]),
|
||||
(float_t)std::stof(splitByComma[1]),
|
||||
(float_t)std::stof(splitByComma[2]),
|
||||
1.0f
|
||||
};
|
||||
} else if(splitByComma.size() == 4) {
|
||||
// RGBA
|
||||
return {
|
||||
(float_t)std::stof(splitByComma[0]),
|
||||
(float_t)std::stof(splitByComma[1]),
|
||||
(float_t)std::stof(splitByComma[2]),
|
||||
(float_t)std::stof(splitByComma[3])
|
||||
};
|
||||
}
|
||||
|
||||
// TODO: Parse other kinds of colors
|
||||
assertUnreachable("Failed to find a color match for %s", str);
|
||||
return {};
|
||||
}
|
89
src/dawnopengl/display/Color.hpp
Normal file
89
src/dawnopengl/display/Color.hpp
Normal file
@ -0,0 +1,89 @@
|
||||
// Copyright (c) 2022 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "dawn.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
struct ColorU8 {
|
||||
uint8_t r, g, b, a;
|
||||
};
|
||||
|
||||
struct Color final {
|
||||
/**
|
||||
* Returns a color from a string.
|
||||
*
|
||||
* @param str String to parse.
|
||||
* @return Color parsed.
|
||||
*/
|
||||
static struct Color fromString(const std::string str);
|
||||
|
||||
float_t r, g, b, a;
|
||||
|
||||
const struct Color& operator = (const struct Color &val) {
|
||||
this->r = val.r;
|
||||
this->g = val.g;
|
||||
this->b = val.b;
|
||||
this->a = val.a;
|
||||
return *this;
|
||||
}
|
||||
|
||||
struct Color operator * (const float_t &x) {
|
||||
return {
|
||||
r * x,
|
||||
g * x,
|
||||
b * x,
|
||||
a * x
|
||||
};
|
||||
}
|
||||
|
||||
struct Color operator - (const struct Color &color) {
|
||||
return {
|
||||
r - color.r,
|
||||
g - color.g,
|
||||
b - color.b,
|
||||
a - color.a
|
||||
};
|
||||
}
|
||||
|
||||
struct Color operator + (const struct Color &color) {
|
||||
return {
|
||||
r + color.r,
|
||||
g + color.g,
|
||||
b + color.b,
|
||||
a + color.a
|
||||
};
|
||||
}
|
||||
|
||||
const bool_t operator == (const struct Color &other) {
|
||||
return r == other.r && g == other.g && b == other.b && a == other.a;
|
||||
}
|
||||
|
||||
operator struct ColorU8() const {
|
||||
return {
|
||||
(uint8_t)(r * 255),
|
||||
(uint8_t)(g * 255),
|
||||
(uint8_t)(b * 255),
|
||||
(uint8_t)(a * 255)
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
#define COLOR_DEF(r,g,b,a) { r, g, b, a }
|
||||
#define COLOR_WHITE COLOR_DEF(1.0f, 1.0f, 1.0f, 1.0f)
|
||||
#define COLOR_RED COLOR_DEF(1.0f, 0, 0, 1.0f)
|
||||
#define COLOR_GREEN COLOR_DEF(0, 1.0f, 0, 1.0f)
|
||||
#define COLOR_BLUE COLOR_DEF(0, 0, 1.0f, 1.0f)
|
||||
#define COLOR_BLACK COLOR_DEF(0, 0, 0, 1.0f)
|
||||
#define COLOR_MAGENTA COLOR_DEF(1.0f, 0, 1.0f, 1.0f)
|
||||
#define COLOR_DARK_GREY COLOR_DEF(0.2f, 0.2f, 0.2f, 1.0f)
|
||||
#define COLOR_LIGHT_GREY COLOR_DEF(0.8f, 0.8f, 0.8f, 1.0f)
|
||||
#define COLOR_CORNFLOWER_BLUE COLOR_DEF(0.4f, 0.6f, 0.9f, 1.0f)
|
||||
#define COLOR_WHITE_TRANSPARENT COLOR_DEF(1.0f, 1.0f, 1.0f, 0.0f)
|
||||
#define COLOR_BLACK_TRANSPARENT COLOR_DEF(0.0f, 0.0f, 0.0f, 0.0f)
|
||||
#define COLOR_YELLOW COLOR_DEF(1.0f, 1.0f, 0.0f, 1.0f)
|
||||
#define COLOR_CYAN COLOR_DEF(0.0f, 1.0f, 1.0f, 1.0f)
|
||||
#define COLOR_TRANSPARENT COLOR_WHITE_TRANSPARENT
|
||||
}
|
@ -8,9 +8,7 @@
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
RenderManager::RenderManager() :
|
||||
shaderManager()
|
||||
{
|
||||
RenderManager::RenderManager() {
|
||||
}
|
||||
|
||||
void RenderManager::init(const Game &game) {
|
||||
|
@ -6,9 +6,12 @@
|
||||
#pragma once
|
||||
#include "dawn.hpp"
|
||||
#include "display/RenderTarget.hpp"
|
||||
#include "display/shader/ShaderManager.hpp"
|
||||
#include "display/BackBuffer.hpp"
|
||||
|
||||
#if DAWN_OPENGL_SHADERS
|
||||
#include "display/shader/ShaderManager.hpp"
|
||||
#endif
|
||||
|
||||
namespace Dawn {
|
||||
class Game;
|
||||
|
||||
@ -17,7 +20,9 @@ namespace Dawn {
|
||||
std::shared_ptr<BackBuffer> backBuffer = nullptr;
|
||||
|
||||
public:
|
||||
ShaderManager shaderManager;
|
||||
#if DAWN_OPENGL_SHADERS
|
||||
ShaderManager shaderManager;
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Creates a render manager.
|
||||
|
@ -42,7 +42,7 @@ void Texture::setSize(
|
||||
this->id = -1;
|
||||
}
|
||||
|
||||
int32_t maxSize;
|
||||
GLint maxSize;
|
||||
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxSize);
|
||||
assertTrue(width > 0 && width <= maxSize, "Width is out of bounds!");
|
||||
assertTrue(height > 0 && height <= maxSize, "Height is out of bounds!");
|
||||
@ -64,26 +64,7 @@ void Texture::setSize(
|
||||
|
||||
void Texture::updateTextureProperties() {
|
||||
auto setWrapMode = [](GLenum axis, enum TextureWrapMode wm) {
|
||||
switch(wm) {
|
||||
case TextureWrapMode::REPEAT:
|
||||
glTexParameteri(GL_TEXTURE_2D, axis, GL_REPEAT);
|
||||
break;
|
||||
|
||||
case TextureWrapMode::MIRRORED_REPEAT:
|
||||
glTexParameteri(GL_TEXTURE_2D, axis, GL_MIRRORED_REPEAT);
|
||||
break;
|
||||
|
||||
case TextureWrapMode::CLAMP_TO_EDGE:
|
||||
glTexParameteri(GL_TEXTURE_2D, axis, GL_CLAMP_TO_EDGE);
|
||||
break;
|
||||
|
||||
case TextureWrapMode::CLAMP_TO_BORDER:
|
||||
glTexParameteri(GL_TEXTURE_2D, axis, GL_CLAMP_TO_BORDER);
|
||||
break;
|
||||
|
||||
default:
|
||||
assertUnreachable("Unknown wrap mode!");
|
||||
}
|
||||
glTexParameteri(GL_TEXTURE_2D, axis, (GLint)wm);
|
||||
assertNoGLError();
|
||||
};
|
||||
|
||||
@ -124,28 +105,7 @@ void Texture::updateTextureProperties() {
|
||||
void Texture::bufferRaw(const void *data) {
|
||||
assertTrue(this->id != -1, "Texture is not ready!");
|
||||
|
||||
GLenum format;
|
||||
switch(this->format) {
|
||||
case TextureFormat::R:
|
||||
format = GL_RED;
|
||||
break;
|
||||
|
||||
case TextureFormat::RG:
|
||||
format = GL_RG;
|
||||
break;
|
||||
|
||||
case TextureFormat::RGB:
|
||||
format = GL_RGB;
|
||||
break;
|
||||
|
||||
case TextureFormat::RGBA:
|
||||
format = GL_RGBA;
|
||||
break;
|
||||
|
||||
default:
|
||||
assertUnreachable("Unknown texture format!");
|
||||
}
|
||||
|
||||
GLenum format = (GLenum)this->format;
|
||||
GLenum dataFormat;
|
||||
switch(this->dataFormat) {
|
||||
case TextureDataFormat::UNSIGNED_BYTE:
|
||||
@ -168,8 +128,11 @@ void Texture::bufferRaw(const void *data) {
|
||||
0, format, dataFormat, data
|
||||
);
|
||||
assertNoGLError();
|
||||
glGenerateMipmap(GL_TEXTURE_2D);
|
||||
assertNoGLError();
|
||||
|
||||
#if DAWN_OPENGL_MIPMAPS
|
||||
glGenerateMipmap(GL_TEXTURE_2D);
|
||||
assertNoGLError();
|
||||
#endif
|
||||
}
|
||||
|
||||
void Texture::buffer(const struct ColorU8 pixels[]) {
|
||||
|
@ -13,17 +13,21 @@ namespace Dawn {
|
||||
typedef GLuint textureslot_t;
|
||||
|
||||
enum class TextureFormat {
|
||||
R = 1,
|
||||
RG = 2,
|
||||
RGB = 3,
|
||||
RGBA = 4
|
||||
R = GL_RED,
|
||||
#ifdef GL_RG
|
||||
RG = GL_RG,
|
||||
#endif
|
||||
RGB = GL_RGB,
|
||||
RGBA = GL_RGBA
|
||||
};
|
||||
|
||||
enum class TextureWrapMode {
|
||||
REPEAT = 0,
|
||||
MIRRORED_REPEAT = 1,
|
||||
CLAMP_TO_EDGE = 2,
|
||||
CLAMP_TO_BORDER = 3
|
||||
REPEAT = GL_REPEAT,
|
||||
MIRRORED_REPEAT = GL_MIRRORED_REPEAT,
|
||||
CLAMP_TO_EDGE = GL_CLAMP_TO_EDGE,
|
||||
#ifdef GL_CLAMP_TO_BORDER
|
||||
CLAMP_TO_BORDER = GL_CLAMP_TO_BORDER
|
||||
#endif
|
||||
};
|
||||
|
||||
enum class TextureFilterMode {
|
||||
|
Reference in New Issue
Block a user