// File: /workspace/github_cpp_makefile_star2_O3/tomfunkhouser[P]gaps/pkgs/R3Utils/R3SurfelViewer.cpp
// Function: gaps::R3SurfelViewer::CompileShaders()
void R3SurfelViewer::
CompileShaders(void)
{
  // Inline GLSL 1.1 vertex shader definition
  const GLchar* vertex_shader_source =
       "#version 110\n"
       "attribute vec3 inPosition;"
       "attribute vec3 inColor;"
       "uniform float pointSize;"
       "varying vec4 vertexColor;"
       "void main()"
       "{"
       "    gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;"
       "    vertexColor = gl_Color;"
       "    gl_PointSize = pointSize;" // Replicate the current functionality
       // Alternative: uncomment to divide by clip space w to scale based on distance.
       // If we do this, we also need to increase the pointSize to compensate:
       //"    gl_PointSize = pointSize / gl_Position.w;"
       "}";
                                                                                  // Inline GLSL 1.1 fragment shader definition
  const GLchar* fragment_shader_source =
       "#version 110\n"
       "varying vec4 vertexColor;"
       "void main()"
       "{"
       "        gl_FragColor = vertexColor;"
       "}";

  // Compile the vertex shader
  vertex_shader = glCreateShader(GL_VERTEX_SHADER);
  glShaderSource(vertex_shader, 1, &vertex_shader_source, 0);
  glCompileShader(vertex_shader);

  // Check if vertex shader is compiled
  int is_compiled = 0;
  glGetShaderiv(vertex_shader, GL_COMPILE_STATUS, &is_compiled);
  if (!is_compiled) {
    int log_length = 0;
    glGetShaderiv(vertex_shader, GL_INFO_LOG_LENGTH, &log_length);
    char* log_contents = new char[log_length + 1];
    glGetShaderInfoLog(vertex_shader, log_length, &log_length, log_contents);
    RNFail("Error: Failed to compile the vertex shader: %s\n", log_contents);
    delete[] log_contents;
    DeleteShaders();
    return;
  }
                                                                                     
  // Compile the fragment shader
  fragment_shader = glCreateShader(GL_FRAGMENT_SHADER);
  glShaderSource(fragment_shader, 1, &fragment_shader_source, 0);
  glCompileShader(fragment_shader);

  // Check if fragment shader is compiled
  is_compiled = 0;
  glGetShaderiv(fragment_shader, GL_COMPILE_STATUS, &is_compiled);
  if (!is_compiled) {
    int log_length = 0;
    glGetShaderiv(fragment_shader, GL_INFO_LOG_LENGTH, &log_length);
    char* log_contents = new char[log_length + 1];
    glGetShaderInfoLog(fragment_shader, log_length, &log_length, log_contents);
    RNFail("Error: Failed to compile the fragment shader: %s\n", log_contents);
    delete[] log_contents;
    DeleteShaders();
    return;
  }
                                                                                     
  // Link the shader program
  shader_program = glCreateProgram();
  glAttachShader(shader_program, vertex_shader);
  glAttachShader(shader_program, fragment_shader);
  glLinkProgram(shader_program);

  // Check if shader is linked
  int is_linked = 0;
  glGetProgramiv(shader_program, GL_LINK_STATUS, &is_linked);
  if (!is_linked) {
    int log_length = 0;
    glGetProgramiv(shader_program, GL_INFO_LOG_LENGTH, &log_length);
    char* log_contents = new char[log_length + 1];
    glGetProgramInfoLog(shader_program, log_length, &log_length, log_contents);
    RNFail("Error: Failed to link the shader program: %s\n", log_contents);
    delete[] log_contents;
    DeleteShaders();
    return;
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdi, %rbx
leaq 0x104748(%rip), %rax    # 0x138956
leaq 0x20(%rsp), %r14
movq %rax, (%r14)
leaq 0x104829(%rip), %rax    # 0x138a46
movq %rax, 0x10(%rsp)
movq 0x187d07(%rip), %r13    # 0x1bbf30
movl $0x8b31, %edi           # imm = 0x8B31
callq *(%r13)
movl %eax, 0x60c(%rbx)
movq 0x187cd9(%rip), %r12    # 0x1bbf18
movl %eax, %edi
movl $0x1, %esi
movq %r14, %rdx
xorl %ecx, %ecx
callq *(%r12)
movq 0x187ca2(%rip), %rbp    # 0x1bbef8
movl 0x60c(%rbx), %edi
callq *(%rbp)
leaq 0xc(%rsp), %r14
movl $0x0, (%r14)
movq 0x187c6e(%rip), %r15    # 0x1bbee0
movl 0x60c(%rbx), %edi
movl $0x8b81, %esi           # imm = 0x8B81
movq %r14, %rdx
callq *(%r15)
cmpl $0x0, (%r14)
je 0x3439d
movl $0x8b30, %edi           # imm = 0x8B30
callq *(%r13)
movl %eax, 0x610(%rbx)
leaq 0x10(%rsp), %rdx
movl %eax, %edi
movl $0x1, %esi
xorl %ecx, %ecx
callq *(%r12)
movl 0x610(%rbx), %edi
callq *(%rbp)
leaq 0xc(%rsp), %r14
movl $0x0, (%r14)
movl 0x610(%rbx), %edi
movl $0x8b81, %esi           # imm = 0x8B81
movq %r14, %rdx
callq *(%r15)
cmpl $0x0, (%r14)
je 0x343ec
movq 0x187c23(%rip), %rax    # 0x1bbf08
callq *(%rax)
movl %eax, 0x608(%rbx)
movq 0x187ce4(%rip), %r14    # 0x1bbfd8
movl 0x60c(%rbx), %esi
movl %eax, %edi
callq *(%r14)
movl 0x608(%rbx), %edi
movl 0x610(%rbx), %esi
callq *(%r14)
movq 0x187c9b(%rip), %rax    # 0x1bbfb0
movl 0x608(%rbx), %edi
callq *(%rax)
leaq 0x8(%rsp), %r14
movl $0x0, (%r14)
movq 0x187ca0(%rip), %r15    # 0x1bbfd0
movl 0x608(%rbx), %edi
movl $0x8b82, %esi           # imm = 0x8B82
movq %r14, %rdx
callq *(%r15)
cmpl $0x0, (%r14)
jne 0x34457
leaq 0x1c(%rsp), %r14
movl $0x0, (%r14)
movl 0x608(%rbx), %edi
movl $0x8b84, %esi           # imm = 0x8B84
movq %r14, %rdx
callq *(%r15)
movslq (%r14), %r15
movq %r15, %rdi
incq %rdi
callq 0x27040
movq %rax, %r12
movq 0x187bb8(%rip), %rax    # 0x1bbf38
movl 0x608(%rbx), %edi
movl %r15d, %esi
movq %r14, %rdx
movq %r12, %rcx
callq *(%rax)
leaq 0x104767(%rip), %rdi    # 0x138aff
jmp 0x34439
leaq 0x8(%rsp), %r14
movl $0x0, (%r14)
movl 0x60c(%rbx), %edi
movl $0x8b84, %esi           # imm = 0x8B84
movq %r14, %rdx
callq *(%r15)
movslq (%r14), %r15
movq %r15, %rdi
incq %rdi
callq 0x27040
movq %rax, %r12
movq 0x187b86(%rip), %rax    # 0x1bbf58
movl 0x60c(%rbx), %edi
movl %r15d, %esi
movq %r14, %rdx
movq %r12, %rcx
callq *(%rax)
leaq 0x1046b3(%rip), %rdi    # 0x138a9d
jmp 0x34439
leaq 0x8(%rsp), %r14
movl $0x0, (%r14)
movl 0x610(%rbx), %edi
movl $0x8b84, %esi           # imm = 0x8B84
movq %r14, %rdx
callq *(%r15)
movslq (%r14), %r15
movq %r15, %rdi
incq %rdi
callq 0x27040
movq %rax, %r12
movq 0x187b37(%rip), %rax    # 0x1bbf58
movl 0x610(%rbx), %edi
movl %r15d, %esi
movq %r14, %rdx
movq %r12, %rcx
callq *(%rax)
leaq 0x104694(%rip), %rdi    # 0x138acd
movq %r12, %rsi
xorl %eax, %eax
callq 0xe853a
movq %r12, %rdi
callq 0x27c80
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x390(%rax)
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq