From: ljsebald <ljs...@us...> - 2024-01-29 04:18:23
|
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "A pseudo Operating System for the Dreamcast.". The branch, master has been updated via 4db9950241c058af8b638506624976dd03a3dc13 (commit) via 9a69bf7996c660d0de16136c0894ad824283c357 (commit) via cc7941fde2be0fbf418894e17055e11ae82e8e46 (commit) from 42f4e9aee02c38aaeb6aa63688d1910f2b47853d (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit 4db9950241c058af8b638506624976dd03a3dc13 Author: Falco Girgis <gyr...@gm...> Date: Sun Jan 28 22:18:05 2024 -0600 Fixed Newlib's getpid() and Implemented kill() (#457) * Fixed getpid() - Our implementation of getpid() for newlib was sketchily returning the current thread ID as the process ID - We're now using a signle constnant value, KOS_PID, as the single process ID for a KOS executable, which is returned by getpid() * Updated clock_getcpuclockid() to support new pid. * Addressing review feedback. commit 9a69bf7996c660d0de16136c0894ad824283c357 Author: Falco Girgis <gyr...@gm...> Date: Sun Jan 28 22:16:34 2024 -0600 Fixed libparallax bubbles and rotocube examples (#474) * Fixed libparallax bubbles and rotocube examples - Both required a libparallax update as well as minor changes - Neither were calling the new pvr_dr_finish() to relinquish SQ ownership when using direct rendering - Bubbles was interleaving pvr_prim() with direct rendering, which already took ownership over the SQs commit cc7941fde2be0fbf418894e17055e11ae82e8e46 Author: OniEnzeru <152...@us...> Date: Sun Jan 28 21:15:32 2024 -0700 2D Textured Quad w/PNGs via stb_image (#470) Created Textured Quad example for GLDC using stb_image loaded PNGs ----------------------------------------------------------------------- Summary of changes: examples/dreamcast/gldc/2D_tex_quad/Makefile | 41 ++++ examples/dreamcast/gldc/2D_tex_quad/main.cpp | 249 +++++++++++++++++++++ examples/dreamcast/gldc/2D_tex_quad/output.gif | Bin 0 -> 8683566 bytes .../dreamcast/gldc/2D_tex_quad/romdisk/crate.png | Bin 0 -> 9676 bytes examples/dreamcast/parallax/bubbles/bubbles.c | 10 +- examples/dreamcast/parallax/rotocube/rotocube.c | 2 + include/kos/thread.h | 11 +- kernel/libc/newlib/newlib_getpid.c | 7 +- kernel/libc/newlib/newlib_kill.c | 4 +- kernel/libc/posix/clock_gettime.c | 4 +- 10 files changed, 316 insertions(+), 12 deletions(-) create mode 100644 examples/dreamcast/gldc/2D_tex_quad/Makefile create mode 100644 examples/dreamcast/gldc/2D_tex_quad/main.cpp create mode 100644 examples/dreamcast/gldc/2D_tex_quad/output.gif create mode 100644 examples/dreamcast/gldc/2D_tex_quad/romdisk/crate.png diff --git a/examples/dreamcast/gldc/2D_tex_quad/Makefile b/examples/dreamcast/gldc/2D_tex_quad/Makefile new file mode 100644 index 00000000..0d0fd51b --- /dev/null +++ b/examples/dreamcast/gldc/2D_tex_quad/Makefile @@ -0,0 +1,41 @@ +# +# KallistiOS ##version## +# +# examples/dreamcast/gldc/2D_tex_quad/Makefile +# Copyright (C) 2024 Jason Rost (OniEnzeru) +# + + +# Directories +KOS_ROMDISK_DIR := romdisk + +# File aggregators +SRCS := main.cpp +OBJS := main.o romdisk.o + +# Compiler Flags +KOS_CPPSTD := -std=c++20 +LDLIBS := -lstb_image -lGL -lkmg -lkosutils -lm + +TARGET = 2D_tex_quad.elf + +.PHONY: all clean push + +all: rm-elf $(TARGET) +include $(KOS_BASE)/Makefile.rules + +clean: rm-elf + -rm -rf $(OBJS) romdisk.* + +$(TARGET): $(OBJS) + kos-c++ -o $(TARGET) $(OBJS) $(LDLIBS) + +dist: $(TARGET) + -rm -f $(OBJS) + $(KOS_STRIP) $(TARGET) + +rm-elf: + -rm -f $(TARGET) + +run: $(TARGET) + $(KOS_LOADER) -x $(TARGET) diff --git a/examples/dreamcast/gldc/2D_tex_quad/main.cpp b/examples/dreamcast/gldc/2D_tex_quad/main.cpp new file mode 100644 index 00000000..33c012bf --- /dev/null +++ b/examples/dreamcast/gldc/2D_tex_quad/main.cpp @@ -0,0 +1,249 @@ +/* + KallistiOS ##version## + examples/dreamcast/gldc/2D_tex_quad/main.cpp + Copyright (C) 2024 Jason Rost (Oni Enzeru) + + Example of 2D Orthographic perspective rendering + of a textured quad using PNGs and GLdc. +*/ + +#include <kos.h> +#include <kos/img.h> + +// ..:: GLdc ::.. +#include <GL/gl.h> +#include <GL/glu.h> +#include <GL/glext.h> +#include <GL/glkos.h> + +// ..:: STB_Image from KOS-Port +#include <stb_image/stb_image.h> + + +void GL_Init(uint16_t w, uint16_t h) { + // Set "background" color to light blue + glClearColor(0.10f, 0.5f, 1.0f, 1.0f); + glEnable(GL_TEXTURE_2D); + + // Expect Counter Clockwise vertex order + glFrontFace(GL_CCW); + + // Enable Transparancy + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + + //Depth test not needed for 2D + glDisable(GL_DEPTH_TEST); + + // Set Orthographic ( 2D ) Camera + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + + // Screen / Camera coords + // Left Right Bottom Top Near Far + glOrtho(0.0f, (float)w, 0.0f, (float)h, -1.0f, 1.0f); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); +} + +int main(int argc, char **argv) { + // Setup for Controller + maple_device_t *cont; + cont_state_t *state; + cont = maple_enum_type(0, MAPLE_FUNC_CONTROLLER); + + // Texture ID + GLuint texture; + + // Initialize KOS + dbglog_set_level(DBG_WARNING); + printf("\n..:: 2D Textured Quad Example - Start ::..\n"); + glKosInit(); + + // Set screen size and init GLDC + GL_Init(640, 480); + + // Generate a texture and link it to our ID + glGenTextures(1, &texture); + glBindTexture(GL_TEXTURE_2D, texture); + + // Set texture parameters best suited for Pixel Art ( Hard edge no repeat for scaling ) + // Prevents blur on scale. + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP ); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP ); + + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); // Scale down filter + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); // Scale up filter + + // Load PNG via stb_image + int width, height, nr_channels; + //stbi_set_flip_vertically_on_load(true); // Flip img onload due to GL expecting top left (0,0) + unsigned char *data = stbi_load("/rd/crate.png", &width, &height, &nr_channels, 0); + + // texture load debug + printf("..:: STB_IMAGE Data ::..\n"); + printf("nr_channels: %d\n", nr_channels); + printf("width: %d\n", width); + printf("height: %d\n", height); + + // If data is loaded, apply texture formats and assign the data + if(data) { + glTexImage2D(GL_TEXTURE_2D, + 0, + GL_RGBA, + width, + height, + 0, + GL_RGBA, + GL_UNSIGNED_BYTE, + data); + + // Currently REQUIRED for OpenGLdc w/PNGs on Dreamcast + glGenerateMipmapEXT(GL_TEXTURE_2D); + } + else { + printf("Failed to load texture!\n"); + } + + // Cleanup + stbi_image_free(data); + + // ..:: Output any GL Errors + GLenum error = glGetError(); + if(error != GL_NO_ERROR) { + printf("OpenGL error: %x\n", error); + } + // ..:: Vertex / UV Data setup + float uv[4][2] = { + // UVs are in reverse Y order to flip image + // GL expects 0,0 to be the bottom left corner of an image while + // real world coordinates are typically top left. + // alt- use: stbi_set_flip_vertically_on_load(true); before loading texture. + // X // Y + {0.0f, 0.0f}, + {1.0f, 0.0f}, + {1.0f, 1.0f}, + {0.0f, 1.0f} + }; + + float xyz[4][3] = { + // Remember these are Counter-clockwise + /* (-1,-1)-----( 0,-1)-----( 1,-1) + | | | + | | | + | | | + (-1, 0)-----( 0, 0)-----( 1, 0) + | | | + | | | + | | | + (-1, 1)-----( 0, 1)-----( 1, 1) + */ + // X Y Z + { -1.0f, 1.0f, 1.0f }, // Bottom Left + { 1.0f, 1.0f, 1.0f }, // Bottom Right + { 1.0f, -1.0f, 1.0f }, // Top Right + { -1.0f, -1.0f, 1.0f } // Top Left + }; + // ..:: Setup some variables to manipulate position and rotation of our quad + float pos_x = 320.0f; + float pos_y = 240.0f; + float rot = 0.0f; + + while(1) { + //..:: Check Controller Input + state = (cont_state_t *)maple_dev_status(cont); + + if(!state) { + printf("Error reading controller\n"); + break; + } + + // Close program on Start Button + if(state->start) + break; + + int16_t x_axis = state->joyx; + int16_t y_axis = state->joyy; + + //..:: Rotation on Triggers + // Rotate CCW + if(state->ltrig >= 255) { + rot += 4.0f; + } + + // Rotate CW + if(state->rtrig >= 255) { + rot -= 4.0f; + } + + //..:: Scale on Y / B + // Scale up + if(state->y) { + width = height += 4.0f; + } + + // Scale down + if(state->b) { + width = height -= 4.0f; + } + + // ..:: Begin GL Drawing + glClearColor(0.10f, 0.5f, 1.0f, 1.0f); // Sets background Color + glClear(GL_COLOR_BUFFER_BIT); // Clears screen to that color + + pos_x += state->joyx * 0.05; + pos_y -= state->joyy * 0.05; + + // Apply texture data to all draw calls until next bind + glBindTexture(GL_TEXTURE_2D, texture); + + glPushMatrix(); + + glLoadIdentity(); + + // Matrix transforms are applied in reverse order. + // Order should ALWAYS be: + // 1) Translate + // 2) Rotate + // 3) Scale + // Scaling "First" ( last in code ) allows all other transforms to be scaled as well. + + // Move quad to screen position + // X Y Z + glTranslatef(pos_x, pos_y, 0.0f); + // val X-axis Y-axis Z-axis + glRotatef(rot, 0.0f, 0.0f, 1.0f); // rotate only on enabled Axis (1.0f) + // tex_w tex_h Z doesn't change + glScalef(width, height, 0.0f ); + + glBegin(GL_QUADS); + // Remember these are Counter-clockwise + // Bottom Left + glTexCoord2fv(&uv[0][0]); + glVertex3f(xyz[0][0], xyz[0][1], xyz[0][2]); + + // Bottom Right + glTexCoord2fv(&uv[1][0]); + glVertex3f(xyz[1][0], xyz[1][1], xyz[1][2]); + + // Top Right + glTexCoord2fv(&uv[2][0]); + glVertex3f(xyz[2][0], xyz[2][1], xyz[2][2]); + + // Top Left + glTexCoord2fv(&uv[3][0]); + glVertex3f(xyz[3][0], xyz[3][1], xyz[3][2]); + + glEnd(); + + glPopMatrix(); + + // Finish the frame and flush to screen + glKosSwapBuffers(); + } + + // ..:: Cleanup Memory + glDeleteTextures(1, &texture); + + return 0; +} diff --git a/examples/dreamcast/gldc/2D_tex_quad/output.gif b/examples/dreamcast/gldc/2D_tex_quad/output.gif new file mode 100644 index 00000000..52a7c8ed Binary files /dev/null and b/examples/dreamcast/gldc/2D_tex_quad/output.gif differ diff --git a/examples/dreamcast/gldc/2D_tex_quad/romdisk/crate.png b/examples/dreamcast/gldc/2D_tex_quad/romdisk/crate.png new file mode 100644 index 00000000..65aaa542 Binary files /dev/null and b/examples/dreamcast/gldc/2D_tex_quad/romdisk/crate.png differ diff --git a/examples/dreamcast/parallax/bubbles/bubbles.c b/examples/dreamcast/parallax/bubbles/bubbles.c index 303ad907..5e4c54d4 100644 --- a/examples/dreamcast/parallax/bubbles/bubbles.c +++ b/examples/dreamcast/parallax/bubbles/bubbles.c @@ -27,7 +27,7 @@ the same, but it uses the Parallax functions instead of KGL. static float phase = 0.0f; static pvr_poly_cxt_t cxt; static pvr_poly_hdr_t hdr; -static pvr_dr_state_t dr_state; +static plx_dr_state_t dr_state; static void sphere(float radius, int slices, int stacks) { int i, j; float pitch, pitch2; @@ -37,6 +37,9 @@ static void sphere(float radius, int slices, int stacks) { /* Put our own polygon header */ pvr_prim(&hdr, sizeof(hdr)); + /* Setup our Direct Render state: pick a store queue and setup QACR0/1 */ + plx_dr_init(&dr_state); + /* Initialize xmtrx with the values from KGL */ plx_mat_identity(); plx_mat3d_apply(PLX_MAT_SCREENVIEW); @@ -84,6 +87,8 @@ static void sphere(float radius, int slices, int stacks) { } } } + + plx_dr_finish(); } #define SPHERE_CNT 12 @@ -98,9 +103,6 @@ static void sphere_frame_opaque(void) { pvr_scene_begin(); pvr_list_begin(PVR_LIST_OP_POLY); - /* Setup our Direct Render state: pick a store queue and setup QACR0/1 */ - pvr_dr_init(&dr_state); - plx_mat3d_identity(); plx_mat3d_translate(0.0f, 0.0f, -12.0f); plx_mat3d_rotate(r * 2, 0.75f, 1.0f, 0.5f); diff --git a/examples/dreamcast/parallax/rotocube/rotocube.c b/examples/dreamcast/parallax/rotocube/rotocube.c index 35427f40..347562f9 100644 --- a/examples/dreamcast/parallax/rotocube/rotocube.c +++ b/examples/dreamcast/parallax/rotocube/rotocube.c @@ -78,6 +78,8 @@ void drawcube(void) { plx_vert_indm3(&dr, PLX_VERT, -3, 3, 3, color); plx_vert_indm3(&dr, PLX_VERT, 3, 3, -3, color); plx_vert_indm3(&dr, PLX_VERT_EOS, 3, 3, 3, color); + + plx_dr_finish(); } // Draws the wave in the background (2D) diff --git a/include/kos/thread.h b/include/kos/thread.h index a8d2a903..6c09dd5a 100644 --- a/include/kos/thread.h +++ b/include/kos/thread.h @@ -66,14 +66,21 @@ __BEGIN_DECLS \sa semaphore_t, mutex_t, kthread_once_t, kthread_key_t, rw_semaphore_t */ -/** \brief Maximal thread priority. +/** \brief Process ID + + This macro defines the single process ID that encompasses all of KOS and the + running application along with all of its threads. +*/ +#define KOS_PID 1 + +/** \brief Maximal thread priority This macro defines the maximum value for a thread's priority. Note that the larger this number, the lower the priority of the thread. */ #define PRIO_MAX 4096 -/** \brief Default thread priority. +/** \brief Default thread priority Threads are created by default with the priority specified. */ diff --git a/kernel/libc/newlib/newlib_getpid.c b/kernel/libc/newlib/newlib_getpid.c index 677a7f32..244394cb 100644 --- a/kernel/libc/newlib/newlib_getpid.c +++ b/kernel/libc/newlib/newlib_getpid.c @@ -1,14 +1,15 @@ /* KallistiOS ##version## newlib_getpid.c - Copyright (C)2004 Megan Potter + Copyright (C) 2004 Megan Potter + Copyright (C) 2024 Falco Girgis */ #include <kos/thread.h> #include <sys/reent.h> -int _getpid_r(struct _reent * re) { +int _getpid_r(struct _reent *re) { (void)re; - return thd_current->tid; + return KOS_PID; } diff --git a/kernel/libc/newlib/newlib_kill.c b/kernel/libc/newlib/newlib_kill.c index 9c715bc7..5b5d026b 100644 --- a/kernel/libc/newlib/newlib_kill.c +++ b/kernel/libc/newlib/newlib_kill.c @@ -1,14 +1,14 @@ /* KallistiOS ##version## newlib_kill.c - Copyright (C)2004 Megan Potter + Copyright (C) 2004 Megan Potter */ #include <sys/reent.h> #include <errno.h> -int _kill_r(struct _reent * reent, int pid, int sig) { +int _kill_r(struct _reent *reent, int pid, int sig) { (void)pid; (void)sig; reent->_errno = EINVAL; diff --git a/kernel/libc/posix/clock_gettime.c b/kernel/libc/posix/clock_gettime.c index 0ec1ea06..16f952f6 100644 --- a/kernel/libc/posix/clock_gettime.c +++ b/kernel/libc/posix/clock_gettime.c @@ -4,6 +4,8 @@ Copyright (C) 2023, 2024 Falco Girgis */ +#include <kos/thread.h> + #include <arch/timer.h> #include <arch/rtc.h> @@ -17,7 +19,7 @@ int clock_getcpuclockid(pid_t pid, clockid_t *clock_id) { /* pid of 0 means the current process, and we only support a single process. */ - if(pid) + if(pid != 0 || pid != KOS_PID) return ESRCH; assert(clock_id); hooks/post-receive -- A pseudo Operating System for the Dreamcast. |