Skip to content

Commit c3f24d0

Browse files
committed
Depth Peeling. Day 384.
1 parent fe01609 commit c3f24d0

6 files changed

Lines changed: 52 additions & 19 deletions

File tree

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ osx_handmade
33

44
A port of Handmade Hero (http://handmadehero.org) for OS X.
55

6-
This repository works with Casey's source code from handmade_hero_day_380.
6+
This repository works with Casey's source code from handmade_hero_day_384.
77

88

99
2017-04-01 Note:
@@ -17,8 +17,8 @@ apply the patch by running:
1717
This patches a problem in handmade_opengl.cpp. Mac OS X supports an OpenGL 3.2
1818
core profile, but not an OpenGL 3.0 core profile. The OpenGL C code works okay
1919
as-is, but the Handmde Hero GLSL shader language is set to 1.3, which Mac OS X
20-
refuses to compile. For now, simply changing the GLSL version to 1.5 fixes the
21-
issue.
20+
refuses to compile under an OpenGL 3.2 core profile. For now, simply changing
21+
the GLSL version to 1.5 fixes the issue.
2222

2323

2424
Compiling and Running

code/osx_handmade.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ typedef void gl_get_program_iv(GLuint program, GLenum pname, GLint *params);
6464
typedef void type_glBindVertexArray(GLuint array);
6565
typedef void type_glGenVertexArrays(GLsizei n, GLuint *arrays);
6666
typedef GLubyte* type_glGetStringi(GLenum name, GLuint index);
67+
typedef GLubyte* type_glGetStringi(GLenum name, GLuint index);
68+
69+
typedef void type_glDeleteFramebuffers(GLsizei n, const GLuint* framebuffers);
6770

6871
global_variable gl_tex_image_2d_multisample *glTexImage2DMultisample;
6972
global_variable gl_bind_framebuffer* glBindFramebuffer;
@@ -96,6 +99,7 @@ global_variable gl_get_program_iv *glGetProgramiv;
9699

97100
OpenGLGlobalFunction(glBindVertexArray);
98101
OpenGLGlobalFunction(glGenVertexArrays);
102+
OpenGLGlobalFunction(glDeleteFramebuffers);
99103

100104

101105
//#include "handmade_intrinsics.h"

code/osx_handmade.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -258,9 +258,6 @@ void OSXCompleteAllWork(platform_work_queue *Queue);
258258

259259
typedef struct osx_game_data
260260
{
261-
// graphics
262-
uint TextureId;
263-
264261
// input
265262
IOHIDManagerRef HIDManager;
266263
int HIDX;

code/osx_handmade_game.cpp

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ void OSXSetupOpenGL(osx_game_data* GameData)
144144
glTexImage2DMultisample = (gl_tex_image_2d_multisample *)dlsym(Image, "glTexImage2DMultisample");
145145
glBlitFramebuffer = (gl_blit_framebuffer *)dlsym(Image, "glBlitFramebuffer");
146146

147+
OSXGetOpenGLFunction(Image, glDeleteFramebuffers);
147148
#if 0
148149
glAttachShader = (gl_attach_shader *)dlsym("glAttachShader");
149150
glCompileShader = (gl_compile_shader *)dlsym("glCompileShader");
@@ -185,13 +186,14 @@ void OSXSetupOpenGL(osx_game_data* GameData)
185186
Assert(glValidateProgram);
186187
Assert(glGetProgramiv);
187188

189+
//OpenGL.SupportsSRGBFramebuffer = true;
188190
OpenGLInit(Info, OpenGL.SupportsSRGBFramebuffer);
189191

190-
glGenTextures(1, &GameData->TextureId);
191-
192-
//OpenGLDefaultInternalTextureFormat = GL_RGBA8;
192+
#if 0
193+
OpenGLDefaultInternalTextureFormat = GL_RGBA8;
193194
//OpenGLDefaultInternalTextureFormat = GL_SRGB8_ALPHA8;
194-
//glEnable(GL_FRAMEBUFFER_SRGB);
195+
glEnable(GL_FRAMEBUFFER_SRGB);
196+
#endif
195197
}
196198
else
197199
{
@@ -548,8 +550,7 @@ void OSXDisplayBufferInWindow(platform_work_queue* RenderQueue,
548550
rectangle2i DrawRegion,
549551
u32 WindowWidth,
550552
u32 WindowHeight,
551-
memory_arena* TempArena,
552-
GLuint TextureId)
553+
memory_arena* TempArena)
553554
{
554555
temporary_memory TempMem = BeginTemporaryMemory(TempArena);
555556

@@ -611,7 +612,7 @@ void OSXProcessFrameAndRunGameLogic(osx_game_data* GameData, CGRect WindowFrame,
611612

612613
BEGIN_BLOCK("Input Processing");
613614

614-
game_render_commands RenderCommands = RenderCommandStruct(
615+
game_render_commands RenderCommands = DefaultRenderCommands(
615616
GameData->PushBufferSize,
616617
GameData->PushBuffer,
617618
(u32)GameData->RenderBuffer.Width,
@@ -621,7 +622,7 @@ void OSXProcessFrameAndRunGameLogic(osx_game_data* GameData, CGRect WindowFrame,
621622
GameData->BitmapArray,
622623
&OpenGL.WhiteBitmap);
623624

624-
rectangle2i DrawRegion = AspectRatioFit(RenderCommands.Width, RenderCommands.Height,
625+
rectangle2i DrawRegion = AspectRatioFit(RenderCommands.Settings.Width, RenderCommands.Settings.Height,
625626
WindowFrame.size.width, WindowFrame.size.height);
626627

627628
game_controller_input* OldKeyboardController = GetController(GameData->OldInput, 0);
@@ -657,8 +658,8 @@ void OSXProcessFrameAndRunGameLogic(osx_game_data* GameData, CGRect WindowFrame,
657658
r32 MouseX = (r32)MouseLocation.x;
658659
r32 MouseY = (r32)MouseLocation.y;
659660

660-
GameData->NewInput->MouseX = RenderCommands.Width * Clamp01MapToRange(DrawRegion.MinX, MouseX, DrawRegion.MaxX);
661-
GameData->NewInput->MouseY = RenderCommands.Height * Clamp01MapToRange(DrawRegion.MinY, MouseY, DrawRegion.MaxY);
661+
GameData->NewInput->MouseX = RenderCommands.Settings.Width * Clamp01MapToRange(DrawRegion.MinX, MouseX, DrawRegion.MaxX);
662+
GameData->NewInput->MouseY = RenderCommands.Settings.Height * Clamp01MapToRange(DrawRegion.MinY, MouseY, DrawRegion.MaxY);
662663

663664

664665
GameData->NewInput->MouseZ = 0; // TODO(casey): Support mousewheel?
@@ -934,8 +935,10 @@ void OSXProcessFrameAndRunGameLogic(osx_game_data* GameData, CGRect WindowFrame,
934935
DrawRegion,
935936
WindowFrame.size.width,
936937
WindowFrame.size.height,
937-
&FrameTempArena,
938-
GameData->TextureId);
938+
&FrameTempArena);
939+
940+
RenderCommands.PushBufferDataAt = RenderCommands.PushBufferBase;
941+
RenderCommands.VertexCount = 0;
939942

940943
END_BLOCK();
941944
}

fix_handmade_hero_source.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#!/bin/sh
22

3-
patch cpp/code/handmade_opengl.cpp -i handmade_opengl.cpp.day380.patch
3+
patch cpp/code/handmade_opengl.cpp -i handmade_opengl.cpp.day384.patch
44

handmade_opengl.cpp.day384.patch

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
--- cpp/code/handmade_opengl.cpp 2017-05-09 12:41:47.000000000 -0400
2+
+++ handmade_opengl.cpp 2017-05-09 12:42:19.000000000 -0400
3+
@@ -608,7 +608,7 @@
4+
{
5+
char Defines[1024];
6+
FormatString(sizeof(Defines), Defines,
7+
- "#version 130\n"
8+
+ "#version 150\n"
9+
"#define ShaderSimTexWriteSRGB %d\n"
10+
"#define ShaderSimTexReadSRGB %d\n"
11+
"#define DepthPeel %d\n",
12+
@@ -728,7 +728,7 @@
13+
{
14+
char Defines[1024];
15+
FormatString(sizeof(Defines), Defines,
16+
- "#version 130\n"
17+
+ "#version 150\n"
18+
"#define ShaderSimTexWriteSRGB %d\n"
19+
"#define ShaderSimTexReadSRGB %d\n"
20+
"#define DepthPeel %d\n",
21+
@@ -813,7 +813,7 @@
22+
{
23+
char Defines[1024];
24+
FormatString(sizeof(Defines), Defines,
25+
- "#version 130\n"
26+
+ "#version 150\n"
27+
"#define ShaderSimTexWriteSRGB %d\n"
28+
"#define ShaderSimTexReadSRGB %d\n",
29+
OpenGL.ShaderSimTexWriteSRGB,

0 commit comments

Comments
 (0)