cinera_handmade.network/cmuratori/hero/code/code368.hmml

125 lines
8.4 KiB
Plaintext
Raw Normal View History

[video output=day368 member=cmuratori stream_platform=twitch stream_username=handmade_hero project=code title="Compiling and Linking Shaders in OpenGL" vod_platform=youtube id=37KXLsjTRBo annotator=Miblo]
[0:08][Recap and set the stage for the day]
[4:06][Attend to the "Getting max allowed samples for texture correctly" issue[ref
site="GitHub"
page="HandmadeHero/cpp Issues"
url="https://github.com/HandmadeHero/cpp/issues"]]
[6:16]["Martins is almost always right"][quote 553]
[7:00][handmade_opengl.cpp: #define GL_MAX_COLOR_TEXTURE_SAMPLES and GL_MAX_DEPTH_TEXTURE_SAMPLES for OpenGLRenderCommands() to use]
[9:24][handmade_opengl.cpp: Drawing to the framebuffer and why we must call glBlitFramebuffer() to do a multisample resolve]
[12:12][Research glBlitFramebuffer()[ref
site="docs.GL"
page="glBlitFramebuffer"
url="http://docs.gl/gl3/glBlitFramebuffer"]]
[14:19][Research how to do the multisample resolve[ref
site="Khronos Wiki"
page="Multisampling"
url=https://www.khronos.org/opengl/wiki/Multisampling]]
[15:48][handmade_opengl.cpp: Enable OpenGLRenderCommands() to bind the framebuffer and perform the multisample resolve]
[20:28][handmade_opengl.cpp: #define GL_READ_FRAMEBUFFER and GL_DRAW_FRAMEBUFFER from the corearb.h[ref
site="Khronos"
page="glcorearb.h"
url="https://www.khronos.org/registry/OpenGL/api/GL/glcorearb.h"]]
[21:13][win32_handmade.cpp: typedef gl_blit_framebuffer]
[23:27][Run the game to see that it just worked][quote 554]
[23:49][handmade_opengl.cpp: Re-enable the Z-buffer in OpenGLRenderCommands()]
[29:32][Consider which Image Format to use[ref
site="Khronos Wiki"
page="Image Format"
url="https://www.khronos.org/opengl/wiki/Image_Format"]]
[33:25][Run the game to see that we have a depth buffer and multisample antialiasing, but that our colours are wrong]
[36:41][handmade_opengl.cpp: Make OpenGLRenderCommands() correctly iterate over the render targets]
[37:57][Determine that we are unable to set sRGB texture rendering on this graphics card]
[39:21][win32_handmade.cpp: Prevent Win32SetPixelFormat() from setting the depth bits]
[41:32][Run the game to see that the depth buffering is still working just fine]
[42:21][Why we did the multisample]
[45:04][View the cutscene and note that the projection and sRGB are incorrect]
[46:52][Blackboard: Our rendering pipeline]
[54:20][Blackboard: Using a Z-bias to cheat the values passed to the depth buffer]
[58:41][Blackboard: Object placement matrix]
[1:00:58][handmade_render_group.h: Add a ZBias to render_entry_bitmap]
[1:03:09][Run the game to see disastrous results and explain why]
[1:04:24][handmade_render_group.cpp: Make PushBitmap() set the ZBias and run the game to see everybody sucked out to infinity and beyond]
[1:05:25][handmade_render_group.cpp: Make PushBitmap() compute the ZBias in proportion to the Height]
[1:06:07][A few introductory words on shaders]
[1:09:32][Creating shaders in OpenGL[ref
site="docs.GL"
page="glShaderSource"
url=http://docs.gl/gl3/glShaderSource]]
[1:12:57][handmade_opengl.cpp Remove OpenGLSetScreenspace()]
[1:13:22][handmade_opengl.cpp: Introduce OpenGLCreateProgram() in conjunction with docs.GL[ref
site="docs.GL"
page="glShaderSource"
url=http://docs.gl/gl3/glShaderSource][ref
site="docs.GL"
page="glCreateShader"
url=http://docs.gl/gl3/glCreateShader][ref
site="docs.GL"
page="glCompileShader"
url=http://docs.gl/gl3/glCompileShader][ref
site="docs.GL"
page="glLinkProgram"
url=http://docs.gl/gl3/glLinkProgram][ref
site="docs.GL"
page="glCreateProgram"
url=http://docs.gl/gl3/glCreateProgram][ref
site="docs.GL"
page="glAttachShader"
url=http://docs.gl/gl3/glAttachShader]]
[1:21:31][Summarise the shader creation process]
[1:22:52][win32_handmade.cpp: Bind the shader functions we need[ref
site="Khronos"
page="glcorearb.h"
url="https://www.khronos.org/registry/OpenGL/api/GL/glcorearb.h"]]
[1:32:47][Compile and run to see our crazy w coordinate]
[1:33:56][Create handmade_opengl.h]
[1:36:18][handmade_opengl.cpp: Make OpenGLInit() call OpenGLCreateProgram(), and write here docs for Header, Vertex and Fragment code]
[1:41:57][Run the game to find that we got through the compilation phase okay, and determine to enable OpenGLCreateProgram() to perform error handling]
[1:44:21][handmade_opengl.cpp: Enable OpenGLCreateProgram() to log shader info and assert on validation failure[ref
site=docs.GL
page="glValidateProgram"
url=http://docs.gl/gl3/glValidateProgram][ref
site=docs.GL
page="glGetProgram"
url=http://docs.gl/gl3/glGetProgram][ref
site=docs.GL
page="glGetProgramInfoLog"
url=http://docs.gl/gl3/glGetProgramInfoLog][ref
site=docs.GL
page="glGetShaderInfoLog"
url=http://docs.gl/gl3/glGetShaderInfoLog][ref
site="Khronos"
page="glcorearb.h"
url="https://www.khronos.org/registry/OpenGL/api/GL/glcorearb.h"]]
[1:53:23][Compile and step into OpenGLCreateProgram() to see that we pass shader validation]
[1:55:06][Q&A][:speech]
[1:55:13][@fr0styninja][Cam died]
[1:56:05][@soysaucethekid][For some of the OpenGL function typedefs, you have the WINAPI entrypoint and others don't. I thought it was necessary to have it or else you get run-time errors when calling those functions (or at least I did)]
[1:57:13][@thesizik][Instead of Z-bias, why not make the sprite cards stand up at a steeper angle, and make them trapezoidal to undo the perspective foreshortening?]
[1:58:14][@bimbinel][When you started writing the placeholder shader code you mentioned something about “C++ ??? docs” that are not yet fully implemented. What is this feature exactly?[ref
site="Wikipedia"
page="Here document"
url="https://en.wikipedia.org/wiki/Here_document"]]
[2:01:36][@pepevel][Do you think the Google's angle library (that translates OpenGL to DirectX calls) would solve the sRGB problem on your graphics card?]
[2:02:24][@gunstarrhero][Why are you downsizing 8 pixels into one using blit and not using 32 bit math and rendering 6 back into 2 with a subtract to finalize 8? 2 pass out of 8 bit back to render allows alpha on/off values and colour value attach. ( A|C| instead of colour value) where alpha belongs in blit, define each pixel]
[2:03:24][@insofaras][You can pass NULL as the length param to glShaderSource and it treats all the strings as null terminated]
[2:03:35][handmade_opengl.cpp: Make OpenGLCreateProgram() pass NULL to glShaderSource()]
[2:04:44][@fr0styninja][Can't we just adjust gamma in the shaders?]
[2:05:27][@fr0styninja][Regarding checking shaders status. Believe best practice is checking GL_COMPILE_STATUS after compiling a shader and then GL_LINK_STATUS after linking a program]
[2:06:25][@bimbinel][Are you eventually going to move shader code into the asset packs, or are you going to keep it inline?]
[2:06:45][@thesizik][Won't there still be problems if a tree is in front of a tall block, if the sprite still technically intersects the tile above?]
[2:08:04][@aceflameseer][Will you implement shader "hotloading"?]
[2:10:01][@enemymouse][Hotloading seems safest with the use of BindAttribLocation, correct, so as not to have to chase locations all over the place?]
[2:10:46][@xyane][Last time I was here you talked about the int32x types. What are your thoughts on type space vs cache utilization?]
[2:12:17][@ratchetfreak][If you recreate the program when hot reloading, you should probably free the old shaders and program]
[2:13:52][@abarishu][Are those programs cleared automatically when the game exits?]
[2:14:43][@macielda][Do you have opinions about Temporal AA?]
[2:14:52][@xyane][I assume that you dont give much thought to how hot data is? I remember a talk by Andrei that you could get a few percent speed up just from organizing the data according to hotness]
[2:17:04][@abarishu]["Unless there is a bug in the driver or in Windows..." Yeah, there are never any bugs in those]
[2:18:14][@xyane][Will you eventually be doing such a pass over Handmade Hero?]
[2:18:32][@pepevel][Should you add a \\n at the end of each line with the format you are using? Wouldn't it be parsed by OpenGL as a long comment as it is now?]
[2:19:44][@starchypancakes][Hey Casey, I got a job as a gameplay programmer! Wouldn't have happened without this stream, not in a million years]
[2:20:23][A few words on gameplay programming][:speech]
[2:22:37][Wrap the rest of the stream up with well wishes for @starchypancakes][:speech][quote 555]
[/video]