Commit for 2021.02.16.7z

This commit is contained in:
mrq 2021-02-16 00:00:00 -06:00
parent 3985d59cac
commit 802a448393
16 changed files with 276 additions and 201 deletions

View File

@ -31,7 +31,7 @@ INC_DIR += $(ENGINE_INC_DIR)/$(ARCH)/$(PREFIX)
DEPS +=
ifneq (,$(findstring win64,$(ARCH)))
REQ_DEPS += vulkan json:nlohmann png openal ogg freetype ncurses curl openvr luajit ultralight-ux bullet meshoptimizer # discord
REQ_DEPS += opengl json:nlohmann png openal ogg freetype ncurses curl openvr luajit ultralight-ux bullet meshoptimizer # discord
FLAGS +=
DEPS += -lgdi32
else ifneq (,$(findstring dreamcast,$(ARCH)))
@ -166,10 +166,10 @@ SRCS_SHADERS += $(wildcard bin/data/shaders/*.glsl)
TARGET_SHADERS += $(patsubst %.glsl,%.spv,$(SRCS_SHADERS))
ifneq (,$(findstring dreamcast,$(ARCH)))
#$(ARCH): $(EX_DLL) $(EXT_EX_DLL) $(TARGET) ./bin/dreamcast/$(TARGET_NAME).cdi
$(ARCH): $(TARGET) ./bin/dreamcast/$(TARGET_NAME).cdi
#OBJS = $(patsubst %.cpp,%.$(ARCH).$(PREFIX).o,$(SRCS_DLL)) $(patsubst %.cpp,%.$(ARCH).$(PREFIX).o,$(SRCS_EXT_DLL)) $(patsubst %.cpp,%.$(ARCH).$(PREFIX).o,$(SRCS))
OBJS = $(patsubst %.cpp,%.$(ARCH).$(PREFIX).o,$(SRCS_DLL)) $(patsubst %.cpp,%.$(ARCH).$(PREFIX).o,$(SRCS))
$(ARCH): $(EX_DLL) $(EXT_EX_DLL) $(TARGET) ./bin/dreamcast/$(TARGET_NAME).cdi
#$(ARCH): $(TARGET) ./bin/dreamcast/$(TARGET_NAME).cdi
OBJS = $(patsubst %.cpp,%.$(ARCH).$(PREFIX).o,$(SRCS_DLL)) $(patsubst %.cpp,%.$(ARCH).$(PREFIX).o,$(SRCS_EXT_DLL)) $(patsubst %.cpp,%.$(ARCH).$(PREFIX).o,$(SRCS))
DEPS += -lkallisti -lc -lm -lgcc -lstdc++ -lGLdc -lAL # -l$(LIB_NAME) -l$(EXT_LIB_NAME)
%.$(ARCH).$(PREFIX).o: %.cpp

View File

@ -1,5 +1,4 @@
#include "../main.h"
#if !UF_ENV_DREAMCAST
#include <uf/utils/window/window.h>
#include <uf/utils/io/iostream.h>
@ -20,7 +19,9 @@ void client::initialize() {
uf::renderer::device.window = &client::window;
ext::load();
#if 1
client::config = ext::config;
#else
/* Initialize config */ {
struct {
uf::Serializer ext;
@ -34,6 +35,7 @@ void client::initialize() {
client::config.merge( config.fallback, true );
}
}
#endif
/* Initialize window */ {
// Window size
pod::Vector2i size; {
@ -54,15 +56,13 @@ void client::initialize() {
spec::terminal.setVisible( client::config["window"]["terminal"]["visible"].as<bool>() );
// Ncurses
uf::IoStream::ncurses = client::config["window"]["terminal"]["ncurses"].as<bool>();
// Window's context settings
uf::renderer::settings::width = size.x;
uf::renderer::settings::height = size.y;
client::window.create( size, title );
#if !UF_ENV_DREAMCAST
// Set refresh rate
ext::config["window"]["refresh rate"] = client::window.getRefreshRate();
// Miscellaneous
client::window.setVisible(client::config["window"]["visible"].as<bool>());
client::window.setCursorVisible(client::config["window"]["cursor"]["visible"].as<bool>());
@ -84,6 +84,7 @@ void client::initialize() {
json["window"]["title"] = std::string(title);
uf::hooks.call( hook, json );
}
#endif
/*
uf::hooks.shouldPreferReadable();
if ( client::config["engine"]["hook"]["mode"] == "Readable" ) {
@ -188,8 +189,10 @@ void client::initialize() {
}
*/
}
#if !UF_ENV_DREAMCAST
if ( client::config["window"]["mode"].as<std::string>() == "fullscreen" ) client::window.switchToFullscreen();
if ( client::config["window"]["mode"].as<std::string>() == "borderless" ) client::window.switchToFullscreen( true );
#endif
client::ready = true;
}
void client::tick() {
@ -260,5 +263,4 @@ void client::terminate() {
return;
}
#endif
}
#endif
}

View File

@ -1,107 +1,18 @@
#if 0
#include <uf/ext/ext.h>
#if UF_ENV_DREAMCAST
#include <uf/ext/opengl/opengl.h>
#include <uf/ext/opengl/commands.h>
int main(int argc, char **argv) {
ext::opengl::settings::width = 640;
ext::opengl::settings::height = 480;
ext::opengl::initialize();
{
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glClearDepth(1.0);
glDepthFunc(GL_LESS);
glEnable(GL_DEPTH_TEST);
glShadeModel(GL_SMOOTH);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(90.0f, (GLfloat) ext::opengl::settings::width / (GLfloat) ext::opengl::settings::height, 0.1f, 100.0f); // Calculate The Aspect Ratio Of The Window
glMatrixMode(GL_MODELVIEW);
}
#if 0
while ( true ) {
ext::opengl::tick();
ext::opengl::render();
}
#endif
#if 0
ext::opengl::CommandBuffer commands;
commands.record([]{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glViewport(0, 0, ext::opengl::settings::width, ext::opengl::settings::height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(90.0f,(GLfloat) ext::opengl::settings::width / (GLfloat) ext::opengl::settings::height, 0.1f, 100.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(-1.5f,0.0f,-6.0f);
glBegin(GL_POLYGON);
glColor3f(1.0f,0.0f,0.0f);
glVertex3f( 0.0f, 1.0f, 0.0f);
glColor3f(0.0f,1.0f,0.0f);
glVertex3f( 1.0f,-1.0f, 0.0f);
glColor3f(0.0f,0.0f,1.0f);
glVertex3f(-1.0f,-1.0f, 0.0f);
glEnd();
glTranslatef(3.0f,0.0f,0.0f);
glBegin(GL_QUADS);
glColor3f(0.5f,0.5f,1.0f);
glVertex3f(-1.0f, 1.0f, 0.0f);
glColor3f(0.5f,0.5f,1.0f);
glVertex3f( 1.0f, 1.0f, 0.0f);
glColor3f(0.5f,0.5f,1.0f);
glVertex3f( 1.0f,-1.0f, 0.0f);
glColor3f(0.5f,0.5f,1.0f);
glVertex3f(-1.0f,-1.0f, 0.0f);
glEnd();
});
while ( true ) {
commands.submit();
glKosSwapBuffers();
}
#endif
#if 1
while ( true ) {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glViewport(0, 0, ext::opengl::settings::width, ext::opengl::settings::height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(90.0f,(GLfloat) ext::opengl::settings::width / (GLfloat) ext::opengl::settings::height, 0.1f, 100.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(-1.5f,0.0f,-6.0f);
glBegin(GL_POLYGON);
glColor3f(1.0f,0.0f,0.0f);
glVertex3f( 0.0f, 1.0f, 0.0f);
glColor3f(0.0f,1.0f,0.0f);
glVertex3f( 1.0f,-1.0f, 0.0f);
glColor3f(0.0f,0.0f,1.0f);
glVertex3f(-1.0f,-1.0f, 0.0f);
glEnd();
glTranslatef(3.0f,0.0f,0.0f);
glBegin(GL_QUADS);
glColor3f(0.5f,0.5f,1.0f);
glVertex3f(-1.0f, 1.0f, 0.0f);
glColor3f(0.5f,0.5f,1.0f);
glVertex3f( 1.0f, 1.0f, 0.0f);
glColor3f(0.5f,0.5f,1.0f);
glVertex3f( 1.0f,-1.0f, 0.0f);
glColor3f(0.5f,0.5f,1.0f);
glVertex3f(-1.0f,-1.0f, 0.0f);
glEnd();
glKosSwapBuffers();
}
#endif
ext::opengl::destroy();
return 0;

View File

@ -1,6 +1,5 @@
#include "main.h"
#if !UF_ENV_DREAMCAST
#include <uf/utils/io/iostream.h>
#include <uf/utils/time/time.h>
@ -77,5 +76,4 @@ int main(int argc, char** argv){
ext::terminate();
client::terminate();
return 0;
}
#endif
}

View File

@ -1,6 +1,6 @@
#pragma once
#include <uf/ext/ext.h>
#if !UF_ENV_DREAMCAST
#include <uf/utils/window/window.h>
#include <uf/utils/serialize/serializer.h>
#include <uf/utils/thread/thread.h>
@ -15,5 +15,4 @@ namespace client {
void tick();
void render();
void terminate();
}
#endif
}

View File

@ -54,7 +54,7 @@
#define _arch_dreamcast
#define UF_IO_ROOT "/rc/data/"
#define UF_IO_ROOT "/rd/"
#else
// Unsupported system
#define UF_ENV "Unknown"

View File

@ -12,6 +12,7 @@ namespace ext {
std::vector<CommandBuffer::function_t> commands;
void record( const CommandBuffer::function_t& );
void record( const CommandBuffer& );
void submit();
void flush();
size_t size() const;

View File

@ -113,6 +113,7 @@ namespace ext {
bool process = true;
Material material;
std::unordered_map<std::string, Pipeline> pipelines;
CommandBuffer commands;
~Graphic();
void initialize( const std::string& = "" );

View File

@ -3,6 +3,9 @@ void ext::opengl::Graphic::initializeGeometry( uf::BaseMesh<T, U>& mesh, size_t
if ( mesh.indices.empty() ) mesh.initialize( o );
mesh.updateDescriptor();
descriptor.geometry = mesh;
descriptor.indices = mesh.indices.size();
// already generated, check if we can just update
if ( descriptor.indices > 0 ) {
if ( descriptor.geometry.sizes.vertex == mesh.sizes.vertex && descriptor.geometry.sizes.indices == mesh.sizes.indices && descriptor.indices == mesh.indices.size() ) {

View File

@ -11,9 +11,9 @@
namespace ext {
namespace RENDERER {
struct /*UF_API*/ VertexDescriptor {
ext::RENDERER::enums::Format::type_t format; // VK_FORMAT_R32G32B32_SFLOAT
size_t offset; // offsetof(Vertex, position)
std::string name;
ext::RENDERER::enums::Format::type_t format = 0; // VK_FORMAT_R32G32B32_SFLOAT
size_t offset = 0; // offsetof(Vertex, position)
std::string name = "";
};
}
}
@ -22,8 +22,8 @@ namespace uf {
struct /*UF_API*/ BaseGeometry {
public:
struct {
size_t vertex;
size_t indices;
size_t vertex = 0;
size_t indices = 0;
} sizes;
std::vector<ext::RENDERER::VertexDescriptor> attributes;
};

View File

@ -6,6 +6,9 @@
void ext::opengl::CommandBuffer::record( const CommandBuffer::function_t& command ) {
commands.emplace_back( command );
}
void ext::opengl::CommandBuffer::record( const CommandBuffer& commandBuffer ) {
commands.insert( commands.end(), commandBuffer.commands.begin(), commandBuffer.commands.end() );
}
void ext::opengl::CommandBuffer::submit() {
for ( auto& command : commands ) {
command();

View File

@ -1457,6 +1457,8 @@ void ext::opengl::Graphic::updatePipelines() {
void ext::opengl::Graphic::record( CommandBuffer& commandBuffer, size_t pass, size_t draw ) {
return this->record( commandBuffer, descriptor, pass, draw );
}
#include <uf/ext/gltf/mesh.h>
void ext::opengl::Graphic::record( CommandBuffer& commandBuffer, GraphicDescriptor& descriptor, size_t pass, size_t draw ) {
if ( !process ) return;
/*
@ -1471,7 +1473,6 @@ void ext::opengl::Graphic::record( CommandBuffer& commandBuffer, GraphicDescript
}
pipeline.record(*this, commandBuffer, pass, draw);
*/
Buffer* vertexBuffer = NULL;
Buffer* indexBuffer = NULL;
for ( auto& buffer : buffers ) {
@ -1480,23 +1481,128 @@ void ext::opengl::Graphic::record( CommandBuffer& commandBuffer, GraphicDescript
}
if ( !vertexBuffer || !indexBuffer ) return;
size_t vertexStride = this->descriptor.geometry.sizes.vertex;
size_t vertices = vertexBuffer->size / vertexStride;
size_t indices = this->descriptor.indices; //indexBuffer->size / this->descriptor.geometry.sizes.indices;
uint32_t* indicesPointer = (uint32_t*) indexBuffer->buffer;
uint32_t* indicesPointerEnd = indicesPointer + indices;
size_t vertexStride = this->descriptor.geometry.sizes.vertex;
size_t vertices = vertexBuffer->size / vertexStride;
uint8_t* vertexPointer = (uint8_t*) vertexBuffer->buffer;
uint32_t* indicesPointer = (uint32_t*) indexBuffer->buffer;
std::cout << "Stride: " << vertexStride << " ";
for ( auto& attribute : descriptor.geometry.attributes ) {
std::cout << attribute.name << ": " << attribute.offset << " ";
}
std::cout << std::endl;
uf::renderer::VertexDescriptor vertexAttributePosition, vertexAttributeNormal, vertexAttributeColor, vertexAttributeUv;
for ( auto& attribute : descriptor.geometry.attributes ) {
for ( auto& attribute : this->descriptor.geometry.attributes ) {
if ( attribute.name == "position" ) vertexAttributePosition = attribute;
else if ( attribute.name == "normal" ) vertexAttributeNormal = attribute;
else if ( attribute.name == "color" ) vertexAttributeColor = attribute;
else if ( attribute.name == "uv" ) vertexAttributeUv = attribute;
}
if ( vertexAttributePosition.name == "" ) return;
#if 1
ext::gltf::mesh_t mesh;
{
auto& vertex = mesh.vertices.emplace_back();
vertex.position = pod::Vector3f{ 0.0f, 1.0f, 0.0f};
vertex.uv = pod::Vector2f{0, 0};
vertex.normal = pod::Vector3f{0, 0, 0};
// vertex.color = pod::Vector4f{1.0f,0.0f,0.0f,1.0f};
};
{
auto& vertex = mesh.vertices.emplace_back();
vertex.position = pod::Vector3f{ 1.0f,-1.0f, 0.0f};
vertex.uv = pod::Vector2f{0, 0};
vertex.normal = pod::Vector3f{0, 0, 0};
// vertex.color = pod::Vector4f{0.0f,1.0f,0.0f,1.0f};
};
{
auto& vertex = mesh.vertices.emplace_back();
vertex.position = pod::Vector3f{-1.0f,-1.0f, 0.0f};
vertex.uv = pod::Vector2f{0, 0};
vertex.normal = pod::Vector3f{0, 0, 0};
// vertex.color = pod::Vector4f{0.0f,0.0f,1.0f,1.0f};
};
mesh.indices = { 0, 1, 2 };
mesh.updateDescriptor();
for ( auto& attribute : mesh.attributes ) {
if ( attribute.name == "position" ) vertexAttributePosition = attribute;
else if ( attribute.name == "normal" ) vertexAttributeNormal = attribute;
else if ( attribute.name == "color" ) vertexAttributeColor = attribute;
else if ( attribute.name == "uv" ) vertexAttributeUv = attribute;
}
vertices = mesh.vertices.size();
indices = mesh.indices.size();
vertexStride = mesh.sizes.vertex;
vertexPointer = (uint8_t*) mesh.vertices.data();
indicesPointer = (uint32_t*) mesh.indices.data();
/*
std::cout << "Strides: " << vertexStride << " ";
for ( auto& attribute : mesh.attributes ) {
std::cout << attribute.name << ": " << attribute.offset << " ";
}
std::cout << std::endl;
std::cout << "Real: ";
for ( auto& index : mesh.indices ) {
auto& vertex = mesh.vertices[index];
std::cout << uf::vector::toString(vertex.position) << " ";
}
std::cout << std::endl;
commandBuffer.record([=]{
glBegin(GL_POLYGON);
for ( auto& glVertex : mesh.vertices ) {
glColor3f(glVertex.color[0], glVertex.color[1], glVertex.color[2]);
// glTexCoord2f(glVertex.uv[0], glVertex.uv[1]);
// glNormal3f(glVertex.normal[0], glVertex.normal[1], glVertex.normal[2]);
glVertex3f(glVertex.position[0], glVertex.position[1], glVertex.position[2]);
}
glEnd();
});
*/
#endif
#if 1
commandBuffer.record([=]{
glBegin(GL_POLYGON);
size_t currentIndex = 0;
size_t vertexColorState = 0;
while ( currentIndex < indices ) {
uint32_t index = indicesPointer[currentIndex++];
uint8_t* vertex = vertexPointer + (index * vertexStride);
if ( vertexAttributeNormal.name != "" ) {
float* normal = (float*) (vertex + vertexAttributeNormal.offset);
// glNormal3f(normal[0], normal[1], normal[2]);
}
if ( vertexAttributeColor.name != "" ) {
float* color = (float*) (vertex + vertexAttributeColor.offset);
glColor3f(color[0], color[1], color[2]);
} else {
switch ( vertexColorState ) {
case 0: glColor3f(1.0f, 0.0f, 0.0f); break;
case 1: glColor3f(0.0f, 1.0f, 0.0f); break;
case 2: glColor3f(0.0f, 0.0f, 1.0f); break;
}
if ( ++vertexColorState > 2 ) vertexColorState = 0;
}
if ( vertexAttributeUv.name != "" ) {
float* uv = (float*) (vertex + vertexAttributeUv.offset);
// glTexCoord2f(uv[0], uv[1]);
}
{
float* position = (float*) (vertex + vertexAttributePosition.offset);
glVertex3f(position[0], position[1], position[2]);
}
}
glEnd();
});
#if 0
struct GLvertex {
pod::Vector3f position = {};
pod::Vector3f normal = {};
@ -1504,7 +1610,6 @@ void ext::opengl::Graphic::record( CommandBuffer& commandBuffer, GraphicDescript
pod::Vector2f uv = {};
};
std::vector<GLvertex> glMesh;
size_t vertexColorState = 0;
while ( indicesPointer < indicesPointerEnd ) {
auto& glVertex = glMesh.emplace_back();
@ -1512,20 +1617,25 @@ void ext::opengl::Graphic::record( CommandBuffer& commandBuffer, GraphicDescript
uint32_t index = *(indicesPointer++);
uint8_t* vertex = vertexPointer + (index * vertexStride);
// std::cout << index << " ";
if ( vertexAttributePosition.name != "" ) {
/*float positionX*/ glVertex.position[0]= *((float*) (vertex + vertexAttributePosition.offset + sizeof(float) * 0));
/*float positionY*/ glVertex.position[1]= *((float*) (vertex + vertexAttributePosition.offset + sizeof(float) * 1));
/*float positionZ*/ glVertex.position[2]= *((float*) (vertex + vertexAttributePosition.offset + sizeof(float) * 2));
float* position = (float*) (vertex + vertexAttributePosition.offset);
glVertex.position[0]= *(position++);
glVertex.position[1]= *(position++);
glVertex.position[2]= *(position++);
}
if ( vertexAttributeNormal.name != "" ) {
/*float normalX*/ glVertex.normal[0]= *((float*) (vertex + vertexAttributeNormal.offset + sizeof(float) * 0));
/*float normalY*/ glVertex.normal[1]= *((float*) (vertex + vertexAttributeNormal.offset + sizeof(float) * 1));
/*float normalZ*/ glVertex.normal[2]= *((float*) (vertex + vertexAttributeNormal.offset + sizeof(float) * 2));
float* normal = (float*) (vertex + vertexAttributeNormal.offset);
glVertex.normal[0]= *(normal++);
glVertex.normal[1]= *(normal++);
glVertex.normal[2]= *(normal++);
}
if ( vertexAttributeColor.name != "" ) {
/*float colorR*/ glVertex.color[0] = *((float*) (vertex + vertexAttributeColor.offset + sizeof(float) * 0));
/*float colorG*/ glVertex.color[1] = *((float*) (vertex + vertexAttributeColor.offset + sizeof(float) * 1));
/*float colorB*/ glVertex.color[2] = *((float*) (vertex + vertexAttributeColor.offset + sizeof(float) * 2));
float* color = (float*) (vertex + vertexAttributeColor.offset);
glVertex.color[0] = *(color++);
glVertex.color[1] = *(color++);
glVertex.color[2] = *(color++);
} else {
switch ( vertexColorState ) {
case 0: glVertex.color = {1, 0, 0}; break;
@ -1535,32 +1645,30 @@ void ext::opengl::Graphic::record( CommandBuffer& commandBuffer, GraphicDescript
if ( ++vertexColorState > 2 ) vertexColorState = 0;
}
if ( vertexAttributeUv.name != "" ) {
/*float uvU*/ glVertex.uv[0] = *((float*) (vertex + vertexAttributeUv.offset + sizeof(float) * 0));
/*float uvV*/ glVertex.uv[1] = *((float*) (vertex + vertexAttributeUv.offset + sizeof(float) * 1));
float* uv = (float*) (vertex + vertexAttributeUv.offset);
glVertex.uv[0] = *(uv++);
glVertex.uv[1] = *(uv++);
}
}
#if 0
commandBuffer.record([=]{
glBegin(GL_POLYGON);
for ( auto& glVertex : glMesh ) {
glVertex3f(glVertex.position[0], glVertex.position[1], glVertex.position[2]);
glNormal3f(glVertex.normal[0], glVertex.normal[1], glVertex.normal[2]);
glColor3f(glVertex.color[0], glVertex.color[1], glVertex.color[2]);
glTexCoord2f(glVertex.uv[0], glVertex.uv[1]);
// glTexCoord2f(glVertex.uv[0], glVertex.uv[1]);
// glNormal3f(glVertex.normal[0], glVertex.normal[1], glVertex.normal[2]);
glVertex3f(glVertex.position[0], glVertex.position[1], glVertex.position[2]);
}
glEnd();
});
#else
commandBuffer.record([=]{
glBegin(GL_POLYGON);
glColor3f(1.0f,0.0f,0.0f);
glVertex3f( 0.0f, 1.0f, 0.0f);
glColor3f(0.0f,1.0f,0.0f);
glVertex3f( 1.0f,-1.0f, 0.0f);
glColor3f(0.0f,0.0f,1.0f);
glVertex3f(-1.0f,-1.0f, 0.0f);
glEnd();
});
/*
std::cout << std::endl;
std::cout << "Parsed: ";
for ( auto& glVertex : glMesh ) {
std::cout << uf::vector::toString(glVertex.position) << " ";
}
std::cout << std::endl;
*/
#endif
#endif
#if 0
// Bind triangle vertex buffer (contains position and colors)

View File

@ -26,10 +26,10 @@ std::vector<std::string> ext::opengl::settings::requestedInstanceExtensions;
ext::opengl::enums::Filter::type_t ext::opengl::settings::swapchainUpscaleFilter = ext::opengl::enums::Filter::LINEAR;
bool ext::opengl::settings::experimental::rebuildOnTickBegin = false;
bool ext::opengl::settings::experimental::rebuildOnTickBegin = true;
bool ext::opengl::settings::experimental::waitOnRenderEnd = false;
bool ext::opengl::settings::experimental::individualPipelines = false;
bool ext::opengl::settings::experimental::multithreadedCommandRecording = false;
bool ext::opengl::settings::experimental::individualPipelines = true;
bool ext::opengl::settings::experimental::multithreadedCommandRecording = true;
std::string ext::opengl::settings::experimental::deferredMode = "";
bool ext::opengl::settings::experimental::deferredReconstructPosition = false;
bool ext::opengl::settings::experimental::deferredAliasOutputToSwapchain = true;

View File

@ -53,16 +53,21 @@ void ext::opengl::RenderMode::bindGraphicPushConstants( ext::opengl::Graphic* po
}
void ext::opengl::RenderMode::createCommandBuffers() {
if ( this->getName() != "" ) return;
// if ( this->getName() != "" ) return;
this->execute = true;
this->synchronize();
float width = this->width > 0 ? this->width : ext::opengl::settings::width;
float height = this->height > 0 ? this->height : ext::opengl::settings::height;
#if 0
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
auto& commands = getCommands();
commands.flush();
#if 1
commands.record([]{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
});
commands.record([]{
glViewport(0, 0, ext::opengl::settings::width, ext::opengl::settings::height);
glMatrixMode(GL_PROJECTION);
@ -71,30 +76,9 @@ void ext::opengl::RenderMode::createCommandBuffers() {
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(-1.5f,0.0f,-6.0f);
glBegin(GL_POLYGON);
glColor3f(1.0f,0.0f,0.0f);
glVertex3f( 0.0f, 1.0f, 0.0f);
glColor3f(0.0f,1.0f,0.0f);
glVertex3f( 1.0f,-1.0f, 0.0f);
glColor3f(0.0f,0.0f,1.0f);
glVertex3f(-1.0f,-1.0f, 0.0f);
glEnd();
glTranslatef(3.0f,0.0f,0.0f);
glBegin(GL_QUADS);
glColor3f(0.5f,0.5f,1.0f);
glVertex3f(-1.0f, 1.0f, 0.0f);
glColor3f(0.5f,0.5f,1.0f);
glVertex3f( 1.0f, 1.0f, 0.0f);
glColor3f(0.5f,0.5f,1.0f);
glVertex3f( 1.0f,-1.0f, 0.0f);
glColor3f(0.5f,0.5f,1.0f);
glVertex3f(-1.0f,-1.0f, 0.0f);
glEnd();
});
#endif
#if 1
auto& commands = getCommands();
commands.flush();
#if 0
commands.record([]{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
});
@ -118,8 +102,7 @@ void ext::opengl::RenderMode::createCommandBuffers() {
glColor3f(0.0f,0.0f,1.0f);
glVertex3f(-1.0f,-1.0f, 0.0f);
glEnd();
});
commands.record([]{
glTranslatef(3.0f,0.0f,0.0f);
glBegin(GL_QUADS);
glColor3f(0.5f,0.5f,1.0f);
@ -134,8 +117,46 @@ void ext::opengl::RenderMode::createCommandBuffers() {
});
#endif
#if 0
auto& commands = getCommands();
commands.flush();
{
struct GLvertex {
pod::Vector3f position = {};
pod::Vector3f normal = {};
pod::Vector3f color = {};
pod::Vector2f uv = {};
};
std::vector<GLvertex> glMesh;
glMesh.push_back({
.position = pod::Vector3f{ 0.0f, 1.0f, 0.0f},
.normal = pod::Vector3f{0, 0, 0},
.color = pod::Vector3f{1.0f,0.0f,0.0f},
.uv = pod::Vector2f{0, 0},
});
glMesh.push_back({
.position = pod::Vector3f{ 1.0f,-1.0f, 0.0f},
.normal = pod::Vector3f{0, 0, 0},
.color = pod::Vector3f{0.0f,1.0f,0.0f},
.uv = pod::Vector2f{0, 0},
});
glMesh.push_back({
.position = pod::Vector3f{-1.0f,-1.0f, 0.0f},
.normal = pod::Vector3f{0, 0, 0},
.color = pod::Vector3f{0.0f,0.0f,1.0f},
.uv = pod::Vector2f{0, 0},
});
commands.record([=]{
glTranslatef(-1.5f,0.0f,-6.0f);
glBegin(GL_POLYGON);
for ( auto& glVertex : glMesh ) {
glColor3f(glVertex.color[0], glVertex.color[1], glVertex.color[2]);
// glTexCoord2f(glVertex.uv[0], glVertex.uv[1]);
// glNormal3f(glVertex.normal[0], glVertex.normal[1], glVertex.normal[2]);
glVertex3f(glVertex.position[0], glVertex.position[1], glVertex.position[2]);
}
glEnd();
});
}
#endif
#if 1
std::vector<uf::Entity*> entities;
std::function<void(uf::Entity*)> filter = [&]( uf::Entity* entity ) {
if ( !entity->hasComponent<uf::Graphic>() ) return;
@ -152,36 +173,58 @@ void ext::opengl::RenderMode::createCommandBuffers() {
auto& controller = scene->getController();
auto& camera = controller.getComponent<uf::Camera>();
auto& controllerTransform = controller.getComponent<pod::Transform<>>();
auto& sceneMetadata = scene->getComponent<uf::Serializer>();
/*
if ( !ext::json::isNull( sceneMetadata["system"]["renderer"]["clear values"][0] ) ) {
auto& v = sceneMetadata["system"]["renderer"]["clear values"][0];
commands.record([=](){
commands.record([&](){
glClearColor(v[0].as<float>(), v[1].as<float>(), v[2].as<float>(), v[3].as<float>());
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
});
}
*/
auto& view = camera.getView();
auto& projection = camera.getProjection();
commands.record([=](){
auto rotation = uf::matrix::inverse( uf::quaternion::matrix( controllerTransform.orientation ) );
/*
commands.record([&](){
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glLoadMatrixf( &projection[0] );
});
*/
for ( auto* pointer : entities ) {
uf::Object& entity = pointer->as<uf::Object>();
auto& graphic = entity.getComponent<uf::Graphic>();
/*
auto& transform = entity.getComponent<pod::Transform<>>();
auto model = view * uf::transform::model( transform );
commands.record([=](){
commands.record([&](){
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glLoadMatrixf( &model[0] );
});
*/
/*
auto transform = uf::transform::flatten( entity.getComponent<pod::Transform<>>() );
commands.record([&](){
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef( transform.position.x, transform.position.y, transform.position.z );
});
*/
/*
commands.record([&](){
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
// glTranslatef(-1.5f,0.0f,-6.0f);
});
*/
commands.record([&](){
glMatrixMode(GL_MODELVIEW);
glLoadMatrixf( &rotation[0] );
glTranslatef(-1.5f,0.0f,-6.0f);
});
auto descriptor = bindGraphicDescriptor(graphic.descriptor, currentSubpass);
graphic.record( commands, descriptor, currentPass, currentDraw++ );
}
@ -240,11 +283,11 @@ void ext::opengl::RenderMode::bindPipelines( const std::vector<ext::opengl::Grap
}
void ext::opengl::RenderMode::render() {
auto& commands = getCommands(this->mostRecentCommandPoolId);
commands.submit();
#if UF_ENV_DREAMCAST
glKosSwapBuffers();
#else
auto& commands = getCommands( this->mostRecentCommandPoolId );
commands.submit();
if (device && device->context && device->context->setActive(true)) {
device->context->display();
}

View File

@ -69,7 +69,7 @@ UF_API_CALL spec::dreamcast::Window::Window( const spec::dreamcast::Window::vect
this->create(size, title);
}
void UF_API_CALL spec::dreamcast::Window::create( const spec::dreamcast::Window::vector_t& _size, const spec::dreamcast::Window::title_t& title ) {
dbglog_set_level(DBG_WARNING);
//dbglog_set_level(DBG_WARNING);
::controller.device = maple_enum_type(0, MAPLE_FUNC_CONTROLLER);
::keyboard.device = maple_enum_type(0, MAPLE_FUNC_KEYBOARD);
}
@ -86,7 +86,7 @@ spec::dreamcast::Window::vector_t UF_API_CALL spec::dreamcast::Window::getPositi
return { 0, 0 };
}
spec::dreamcast::Window::vector_t UF_API_CALL spec::dreamcast::Window::getSize() const {
return { 0, 0 };
return { 640, 480 };
}
size_t UF_API_CALL spec::dreamcast::Window::getRefreshRate() const {
return 60;
@ -99,7 +99,7 @@ void UF_API_CALL spec::dreamcast::Window::setPosition( const spec::dreamcast::Wi
void UF_API_CALL spec::dreamcast::Window::setMousePosition( const spec::dreamcast::Window::vector_t& position ) {
}
spec::dreamcast::Window::vector_t UF_API_CALL spec::dreamcast::Window::getMousePosition( ) {
return { 0, 0 };
return { 320, 240 };
}
void UF_API_CALL spec::dreamcast::Window::setSize( const spec::dreamcast::Window::vector_t& size ) {
}
@ -193,7 +193,7 @@ void UF_API_CALL spec::dreamcast::Window::setMouseGrabbed(bool state) {
void UF_API_CALL spec::dreamcast::Window::grabMouse(bool state) {
}
pod::Vector2ui UF_API_CALL spec::dreamcast::Window::getResolution() {
return { 0, 0 };
return { 640, 480 };
}
void UF_API_CALL spec::dreamcast::Window::switchToFullscreen( bool borderless ) {
}

View File

@ -74,6 +74,9 @@ namespace {
namespace {
std::string getConfig() {
#if 1
return uf::io::readAsString(uf::io::root+"/config.json");
#else
struct {
bool initialized = false;
uf::Serializer file;
@ -104,13 +107,17 @@ namespace {
config.fallback["window"]["keyboard"]["repeat"] = true;
config.fallback["engine"]["scenes"]["start"] = "StartMenu";
config.fallback["engine"]["scenes"]["lights"]["max"] = 32;
config.fallback["engine"]["scenes"]["lights"]["max"] = 32;
config.fallback["engine"]["hook"]["mode"] = "Readable";
config.fallback["engine"]["limiters"]["framerate"] = 60;
config.fallback["engine"]["limiters"]["deltaTime"] = 120;
config.fallback["engine"]["threads"]["workers"] = "auto";
config.fallback["engine"]["threads"]["frame limiter"] = 144;
#if UF_ENV_DREAMCAST
config.fallback["engine"]["memory pool"]["size"] = "1 MiB";
#else
config.fallback["engine"]["memory pool"]["size"] = "512 MiB";
#endif
config.fallback["engine"]["memory pool"]["globalOverride"] = false;
config.fallback["engine"]["memory pool"]["subPools"] = true;
}
@ -126,6 +133,7 @@ namespace {
config.initialized = true;
return config.merged;
#endif
}
}
@ -156,7 +164,6 @@ void EXT_API ext::initialize() {
uf::iostream << "Arguments: " << uf::Serializer(arguments) << "\n";
if ( modified ) uf::iostream << "New config: " << ::config << "\n";
}
/* Seed */ {
srand(time(NULL));
}
@ -463,7 +470,6 @@ void EXT_API ext::initialize() {
pod::Thread& threadMain = uf::thread::has("Main") ? uf::thread::get("Main") : uf::thread::create( "Main", false );
pod::Thread& threadPhysics = uf::thread::has("Physics") ? uf::thread::get("Physics") : uf::thread::create( "Physics", true );
}
#if UF_USE_DISCORD
/* Discord */ if ( ::config["engine"]["ext"]["discord"]["enabled"].as<bool>() ) {
ext::discord::initialize();