erebus

changeset 0:4abdce1361b9

initial commit
author John Tsiombikas <nuclear@member.fsf.org>
date Sun, 27 Apr 2014 16:02:47 +0300
parents
children 59a72293f9bd
files erebus.sln erebus.vcxproj erebus.vcxproj.filters liberebus/liberebus.vcxproj liberebus/liberebus.vcxproj.filters liberebus/src/brdf.cc liberebus/src/brdf.h liberebus/src/bvol.cc liberebus/src/bvol.h liberebus/src/camera.cc liberebus/src/camera.h liberebus/src/color.h liberebus/src/erebus.cc liberebus/src/erebus.h liberebus/src/erebus_impl.h liberebus/src/geomobj.h liberebus/src/image.h liberebus/src/image.inl liberebus/src/object.cc liberebus/src/object.h liberebus/src/scene.h liberebus/src/snode.h liberebus/src/texture.h src/main.cc src/opengl.cc src/opengl.h src/sdr.c src/sdr.h
diffstat 28 files changed, 2319 insertions(+), 0 deletions(-) [+]
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/erebus.sln	Sun Apr 27 16:02:47 2014 +0300
     1.3 @@ -0,0 +1,39 @@
     1.4 +
     1.5 +Microsoft Visual Studio Solution File, Format Version 12.00
     1.6 +# Visual Studio 2013
     1.7 +VisualStudioVersion = 12.0.21005.1
     1.8 +MinimumVisualStudioVersion = 10.0.40219.1
     1.9 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "erebus", "erebus.vcxproj", "{55E5C1D8-DF5A-4380-A77F-4D317165E7BB}"
    1.10 +	ProjectSection(ProjectDependencies) = postProject
    1.11 +		{6172E997-FB04-4DB6-A1CC-20135451E62B} = {6172E997-FB04-4DB6-A1CC-20135451E62B}
    1.12 +	EndProjectSection
    1.13 +EndProject
    1.14 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "liberebus", "liberebus\liberebus.vcxproj", "{6172E997-FB04-4DB6-A1CC-20135451E62B}"
    1.15 +EndProject
    1.16 +Global
    1.17 +	GlobalSection(SolutionConfigurationPlatforms) = preSolution
    1.18 +		Debug|Win32 = Debug|Win32
    1.19 +		Debug|x64 = Debug|x64
    1.20 +		Release|Win32 = Release|Win32
    1.21 +		Release|x64 = Release|x64
    1.22 +	EndGlobalSection
    1.23 +	GlobalSection(ProjectConfigurationPlatforms) = postSolution
    1.24 +		{55E5C1D8-DF5A-4380-A77F-4D317165E7BB}.Debug|Win32.ActiveCfg = Debug|Win32
    1.25 +		{55E5C1D8-DF5A-4380-A77F-4D317165E7BB}.Debug|Win32.Build.0 = Debug|Win32
    1.26 +		{55E5C1D8-DF5A-4380-A77F-4D317165E7BB}.Debug|x64.ActiveCfg = Debug|x64
    1.27 +		{55E5C1D8-DF5A-4380-A77F-4D317165E7BB}.Debug|x64.Build.0 = Debug|x64
    1.28 +		{55E5C1D8-DF5A-4380-A77F-4D317165E7BB}.Release|Win32.ActiveCfg = Release|Win32
    1.29 +		{55E5C1D8-DF5A-4380-A77F-4D317165E7BB}.Release|Win32.Build.0 = Release|Win32
    1.30 +		{55E5C1D8-DF5A-4380-A77F-4D317165E7BB}.Release|x64.ActiveCfg = Release|x64
    1.31 +		{55E5C1D8-DF5A-4380-A77F-4D317165E7BB}.Release|x64.Build.0 = Release|x64
    1.32 +		{6172E997-FB04-4DB6-A1CC-20135451E62B}.Debug|Win32.ActiveCfg = Debug|Win32
    1.33 +		{6172E997-FB04-4DB6-A1CC-20135451E62B}.Debug|Win32.Build.0 = Debug|Win32
    1.34 +		{6172E997-FB04-4DB6-A1CC-20135451E62B}.Debug|x64.ActiveCfg = Debug|Win32
    1.35 +		{6172E997-FB04-4DB6-A1CC-20135451E62B}.Release|Win32.ActiveCfg = Release|Win32
    1.36 +		{6172E997-FB04-4DB6-A1CC-20135451E62B}.Release|Win32.Build.0 = Release|Win32
    1.37 +		{6172E997-FB04-4DB6-A1CC-20135451E62B}.Release|x64.ActiveCfg = Release|Win32
    1.38 +	EndGlobalSection
    1.39 +	GlobalSection(SolutionProperties) = preSolution
    1.40 +		HideSolutionNode = FALSE
    1.41 +	EndGlobalSection
    1.42 +EndGlobal
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/erebus.vcxproj	Sun Apr 27 16:02:47 2014 +0300
     2.3 @@ -0,0 +1,163 @@
     2.4 +<?xml version="1.0" encoding="utf-8"?>
     2.5 +<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
     2.6 +  <ItemGroup Label="ProjectConfigurations">
     2.7 +    <ProjectConfiguration Include="Debug|Win32">
     2.8 +      <Configuration>Debug</Configuration>
     2.9 +      <Platform>Win32</Platform>
    2.10 +    </ProjectConfiguration>
    2.11 +    <ProjectConfiguration Include="Debug|x64">
    2.12 +      <Configuration>Debug</Configuration>
    2.13 +      <Platform>x64</Platform>
    2.14 +    </ProjectConfiguration>
    2.15 +    <ProjectConfiguration Include="Release|Win32">
    2.16 +      <Configuration>Release</Configuration>
    2.17 +      <Platform>Win32</Platform>
    2.18 +    </ProjectConfiguration>
    2.19 +    <ProjectConfiguration Include="Release|x64">
    2.20 +      <Configuration>Release</Configuration>
    2.21 +      <Platform>x64</Platform>
    2.22 +    </ProjectConfiguration>
    2.23 +  </ItemGroup>
    2.24 +  <ItemGroup>
    2.25 +    <ClCompile Include="src\main.cc" />
    2.26 +    <ClCompile Include="src\opengl.cc" />
    2.27 +    <ClCompile Include="src\sdr.c" />
    2.28 +  </ItemGroup>
    2.29 +  <ItemGroup>
    2.30 +    <ClInclude Include="src\opengl.h" />
    2.31 +    <ClInclude Include="src\sdr.h" />
    2.32 +  </ItemGroup>
    2.33 +  <PropertyGroup Label="Globals">
    2.34 +    <ProjectGuid>{55E5C1D8-DF5A-4380-A77F-4D317165E7BB}</ProjectGuid>
    2.35 +    <Keyword>Win32Proj</Keyword>
    2.36 +    <RootNamespace>erebus</RootNamespace>
    2.37 +  </PropertyGroup>
    2.38 +  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
    2.39 +  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
    2.40 +    <ConfigurationType>Application</ConfigurationType>
    2.41 +    <UseDebugLibraries>true</UseDebugLibraries>
    2.42 +    <PlatformToolset>v120</PlatformToolset>
    2.43 +    <CharacterSet>Unicode</CharacterSet>
    2.44 +  </PropertyGroup>
    2.45 +  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
    2.46 +    <ConfigurationType>Application</ConfigurationType>
    2.47 +    <UseDebugLibraries>true</UseDebugLibraries>
    2.48 +    <PlatformToolset>v120</PlatformToolset>
    2.49 +    <CharacterSet>Unicode</CharacterSet>
    2.50 +  </PropertyGroup>
    2.51 +  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
    2.52 +    <ConfigurationType>Application</ConfigurationType>
    2.53 +    <UseDebugLibraries>false</UseDebugLibraries>
    2.54 +    <PlatformToolset>v120</PlatformToolset>
    2.55 +    <WholeProgramOptimization>true</WholeProgramOptimization>
    2.56 +    <CharacterSet>Unicode</CharacterSet>
    2.57 +  </PropertyGroup>
    2.58 +  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
    2.59 +    <ConfigurationType>Application</ConfigurationType>
    2.60 +    <UseDebugLibraries>false</UseDebugLibraries>
    2.61 +    <PlatformToolset>v120</PlatformToolset>
    2.62 +    <WholeProgramOptimization>true</WholeProgramOptimization>
    2.63 +    <CharacterSet>Unicode</CharacterSet>
    2.64 +  </PropertyGroup>
    2.65 +  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
    2.66 +  <ImportGroup Label="ExtensionSettings">
    2.67 +  </ImportGroup>
    2.68 +  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
    2.69 +    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
    2.70 +  </ImportGroup>
    2.71 +  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
    2.72 +    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
    2.73 +  </ImportGroup>
    2.74 +  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
    2.75 +    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
    2.76 +  </ImportGroup>
    2.77 +  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
    2.78 +    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
    2.79 +  </ImportGroup>
    2.80 +  <PropertyGroup Label="UserMacros" />
    2.81 +  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
    2.82 +    <LinkIncremental>true</LinkIncremental>
    2.83 +  </PropertyGroup>
    2.84 +  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
    2.85 +    <LinkIncremental>true</LinkIncremental>
    2.86 +  </PropertyGroup>
    2.87 +  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
    2.88 +    <LinkIncremental>false</LinkIncremental>
    2.89 +  </PropertyGroup>
    2.90 +  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
    2.91 +    <LinkIncremental>false</LinkIncremental>
    2.92 +  </PropertyGroup>
    2.93 +  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
    2.94 +    <ClCompile>
    2.95 +      <PrecompiledHeader>
    2.96 +      </PrecompiledHeader>
    2.97 +      <WarningLevel>Level3</WarningLevel>
    2.98 +      <Optimization>Disabled</Optimization>
    2.99 +      <PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
   2.100 +      <DisableSpecificWarnings>4244;4305;4996</DisableSpecificWarnings>
   2.101 +    </ClCompile>
   2.102 +    <Link>
   2.103 +      <SubSystem>Console</SubSystem>
   2.104 +      <GenerateDebugInformation>true</GenerateDebugInformation>
   2.105 +      <AdditionalDependencies>opengl32.lib;glut32.lib;glew32.lib;libvmath.lib;libimago2.lib;jpeglib.lib;libpng.lib;zlib.lib;liberebus.lib;%(AdditionalDependencies)</AdditionalDependencies>
   2.106 +      <AdditionalLibraryDirectories>$(SolutionDir)\liberebus\$(Configuration);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
   2.107 +    </Link>
   2.108 +  </ItemDefinitionGroup>
   2.109 +  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
   2.110 +    <ClCompile>
   2.111 +      <PrecompiledHeader>
   2.112 +      </PrecompiledHeader>
   2.113 +      <WarningLevel>Level3</WarningLevel>
   2.114 +      <Optimization>Disabled</Optimization>
   2.115 +      <PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
   2.116 +      <DisableSpecificWarnings>4244;4305;4996</DisableSpecificWarnings>
   2.117 +    </ClCompile>
   2.118 +    <Link>
   2.119 +      <SubSystem>Console</SubSystem>
   2.120 +      <GenerateDebugInformation>true</GenerateDebugInformation>
   2.121 +      <AdditionalDependencies>opengl32.lib;glut32.lib;glew32.lib;libvmath.lib;libimago2.lib;jpeglib.lib;libpng.lib;zlib.lib;%(AdditionalDependencies)</AdditionalDependencies>
   2.122 +    </Link>
   2.123 +  </ItemDefinitionGroup>
   2.124 +  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
   2.125 +    <ClCompile>
   2.126 +      <WarningLevel>Level3</WarningLevel>
   2.127 +      <PrecompiledHeader>
   2.128 +      </PrecompiledHeader>
   2.129 +      <Optimization>MaxSpeed</Optimization>
   2.130 +      <FunctionLevelLinking>true</FunctionLevelLinking>
   2.131 +      <IntrinsicFunctions>true</IntrinsicFunctions>
   2.132 +      <PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
   2.133 +      <DisableSpecificWarnings>4244;4305;4996</DisableSpecificWarnings>
   2.134 +    </ClCompile>
   2.135 +    <Link>
   2.136 +      <SubSystem>Console</SubSystem>
   2.137 +      <GenerateDebugInformation>true</GenerateDebugInformation>
   2.138 +      <EnableCOMDATFolding>true</EnableCOMDATFolding>
   2.139 +      <OptimizeReferences>true</OptimizeReferences>
   2.140 +      <AdditionalDependencies>opengl32.lib;glut32.lib;glew32.lib;libvmath.lib;libimago2.lib;jpeglib.lib;libpng.lib;zlib.lib;liberebus.lib;%(AdditionalDependencies)</AdditionalDependencies>
   2.141 +      <AdditionalLibraryDirectories>$(SolutionDir)\liberebus\$(Configuration);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
   2.142 +    </Link>
   2.143 +  </ItemDefinitionGroup>
   2.144 +  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
   2.145 +    <ClCompile>
   2.146 +      <WarningLevel>Level3</WarningLevel>
   2.147 +      <PrecompiledHeader>
   2.148 +      </PrecompiledHeader>
   2.149 +      <Optimization>MaxSpeed</Optimization>
   2.150 +      <FunctionLevelLinking>true</FunctionLevelLinking>
   2.151 +      <IntrinsicFunctions>true</IntrinsicFunctions>
   2.152 +      <PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
   2.153 +      <DisableSpecificWarnings>4244;4305;4996</DisableSpecificWarnings>
   2.154 +    </ClCompile>
   2.155 +    <Link>
   2.156 +      <SubSystem>Console</SubSystem>
   2.157 +      <GenerateDebugInformation>true</GenerateDebugInformation>
   2.158 +      <EnableCOMDATFolding>true</EnableCOMDATFolding>
   2.159 +      <OptimizeReferences>true</OptimizeReferences>
   2.160 +      <AdditionalDependencies>opengl32.lib;glut32.lib;glew32.lib;libvmath.lib;libimago2.lib;jpeglib.lib;libpng.lib;zlib.lib;%(AdditionalDependencies)</AdditionalDependencies>
   2.161 +    </Link>
   2.162 +  </ItemDefinitionGroup>
   2.163 +  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
   2.164 +  <ImportGroup Label="ExtensionTargets">
   2.165 +  </ImportGroup>
   2.166 +</Project>
   2.167 \ No newline at end of file
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/erebus.vcxproj.filters	Sun Apr 27 16:02:47 2014 +0300
     3.3 @@ -0,0 +1,36 @@
     3.4 +<?xml version="1.0" encoding="utf-8"?>
     3.5 +<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
     3.6 +  <ItemGroup>
     3.7 +    <Filter Include="Source Files">
     3.8 +      <UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
     3.9 +      <Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
    3.10 +    </Filter>
    3.11 +    <Filter Include="Header Files">
    3.12 +      <UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
    3.13 +      <Extensions>h;hh;hpp;hxx;hm;inl;inc;xsd</Extensions>
    3.14 +    </Filter>
    3.15 +    <Filter Include="Resource Files">
    3.16 +      <UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
    3.17 +      <Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
    3.18 +    </Filter>
    3.19 +  </ItemGroup>
    3.20 +  <ItemGroup>
    3.21 +    <ClCompile Include="src\main.cc">
    3.22 +      <Filter>Source Files</Filter>
    3.23 +    </ClCompile>
    3.24 +    <ClCompile Include="src\opengl.cc">
    3.25 +      <Filter>Source Files</Filter>
    3.26 +    </ClCompile>
    3.27 +    <ClCompile Include="src\sdr.c">
    3.28 +      <Filter>Source Files</Filter>
    3.29 +    </ClCompile>
    3.30 +  </ItemGroup>
    3.31 +  <ItemGroup>
    3.32 +    <ClInclude Include="src\opengl.h">
    3.33 +      <Filter>Header Files</Filter>
    3.34 +    </ClInclude>
    3.35 +    <ClInclude Include="src\sdr.h">
    3.36 +      <Filter>Header Files</Filter>
    3.37 +    </ClInclude>
    3.38 +  </ItemGroup>
    3.39 +</Project>
    3.40 \ No newline at end of file
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/liberebus/liberebus.vcxproj	Sun Apr 27 16:02:47 2014 +0300
     4.3 @@ -0,0 +1,102 @@
     4.4 +<?xml version="1.0" encoding="utf-8"?>
     4.5 +<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
     4.6 +  <ItemGroup Label="ProjectConfigurations">
     4.7 +    <ProjectConfiguration Include="Debug|Win32">
     4.8 +      <Configuration>Debug</Configuration>
     4.9 +      <Platform>Win32</Platform>
    4.10 +    </ProjectConfiguration>
    4.11 +    <ProjectConfiguration Include="Release|Win32">
    4.12 +      <Configuration>Release</Configuration>
    4.13 +      <Platform>Win32</Platform>
    4.14 +    </ProjectConfiguration>
    4.15 +  </ItemGroup>
    4.16 +  <ItemGroup>
    4.17 +    <ClInclude Include="src\brdf.h" />
    4.18 +    <ClInclude Include="src\bvol.h" />
    4.19 +    <ClInclude Include="src\camera.h" />
    4.20 +    <ClInclude Include="src\color.h" />
    4.21 +    <ClInclude Include="src\erebus.h" />
    4.22 +    <ClInclude Include="src\erebus_impl.h" />
    4.23 +    <ClInclude Include="src\geomobj.h" />
    4.24 +    <ClInclude Include="src\image.h" />
    4.25 +    <ClInclude Include="src\object.h" />
    4.26 +    <ClInclude Include="src\scene.h" />
    4.27 +    <ClInclude Include="src\snode.h" />
    4.28 +    <ClInclude Include="src\texture.h" />
    4.29 +  </ItemGroup>
    4.30 +  <ItemGroup>
    4.31 +    <ClCompile Include="src\brdf.cc" />
    4.32 +    <ClCompile Include="src\bvol.cc" />
    4.33 +    <ClCompile Include="src\camera.cc" />
    4.34 +    <ClCompile Include="src\erebus.cc" />
    4.35 +    <ClCompile Include="src\object.cc" />
    4.36 +  </ItemGroup>
    4.37 +  <ItemGroup>
    4.38 +    <None Include="src\image.inl" />
    4.39 +  </ItemGroup>
    4.40 +  <PropertyGroup Label="Globals">
    4.41 +    <ProjectGuid>{6172E997-FB04-4DB6-A1CC-20135451E62B}</ProjectGuid>
    4.42 +    <Keyword>Win32Proj</Keyword>
    4.43 +    <RootNamespace>liberebus</RootNamespace>
    4.44 +  </PropertyGroup>
    4.45 +  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
    4.46 +  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
    4.47 +    <ConfigurationType>StaticLibrary</ConfigurationType>
    4.48 +    <UseDebugLibraries>true</UseDebugLibraries>
    4.49 +    <PlatformToolset>v120</PlatformToolset>
    4.50 +    <CharacterSet>Unicode</CharacterSet>
    4.51 +  </PropertyGroup>
    4.52 +  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
    4.53 +    <ConfigurationType>StaticLibrary</ConfigurationType>
    4.54 +    <UseDebugLibraries>false</UseDebugLibraries>
    4.55 +    <PlatformToolset>v120</PlatformToolset>
    4.56 +    <WholeProgramOptimization>true</WholeProgramOptimization>
    4.57 +    <CharacterSet>Unicode</CharacterSet>
    4.58 +  </PropertyGroup>
    4.59 +  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
    4.60 +  <ImportGroup Label="ExtensionSettings">
    4.61 +  </ImportGroup>
    4.62 +  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
    4.63 +    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
    4.64 +  </ImportGroup>
    4.65 +  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
    4.66 +    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
    4.67 +  </ImportGroup>
    4.68 +  <PropertyGroup Label="UserMacros" />
    4.69 +  <PropertyGroup />
    4.70 +  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
    4.71 +    <ClCompile>
    4.72 +      <PrecompiledHeader>
    4.73 +      </PrecompiledHeader>
    4.74 +      <WarningLevel>Level3</WarningLevel>
    4.75 +      <Optimization>Disabled</Optimization>
    4.76 +      <PreprocessorDefinitions>WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
    4.77 +      <DisableSpecificWarnings>4244</DisableSpecificWarnings>
    4.78 +    </ClCompile>
    4.79 +    <Link>
    4.80 +      <SubSystem>Windows</SubSystem>
    4.81 +      <GenerateDebugInformation>true</GenerateDebugInformation>
    4.82 +    </Link>
    4.83 +  </ItemDefinitionGroup>
    4.84 +  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
    4.85 +    <ClCompile>
    4.86 +      <WarningLevel>Level3</WarningLevel>
    4.87 +      <PrecompiledHeader>
    4.88 +      </PrecompiledHeader>
    4.89 +      <Optimization>MaxSpeed</Optimization>
    4.90 +      <FunctionLevelLinking>true</FunctionLevelLinking>
    4.91 +      <IntrinsicFunctions>true</IntrinsicFunctions>
    4.92 +      <PreprocessorDefinitions>WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
    4.93 +      <DisableSpecificWarnings>4244</DisableSpecificWarnings>
    4.94 +    </ClCompile>
    4.95 +    <Link>
    4.96 +      <SubSystem>Windows</SubSystem>
    4.97 +      <GenerateDebugInformation>true</GenerateDebugInformation>
    4.98 +      <EnableCOMDATFolding>true</EnableCOMDATFolding>
    4.99 +      <OptimizeReferences>true</OptimizeReferences>
   4.100 +    </Link>
   4.101 +  </ItemDefinitionGroup>
   4.102 +  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
   4.103 +  <ImportGroup Label="ExtensionTargets">
   4.104 +  </ImportGroup>
   4.105 +</Project>
   4.106 \ No newline at end of file
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/liberebus/liberebus.vcxproj.filters	Sun Apr 27 16:02:47 2014 +0300
     5.3 @@ -0,0 +1,77 @@
     5.4 +<?xml version="1.0" encoding="utf-8"?>
     5.5 +<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
     5.6 +  <ItemGroup>
     5.7 +    <Filter Include="Source Files">
     5.8 +      <UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
     5.9 +      <Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
    5.10 +    </Filter>
    5.11 +    <Filter Include="Header Files">
    5.12 +      <UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
    5.13 +      <Extensions>h;hh;hpp;hxx;hm;inl;inc;xsd</Extensions>
    5.14 +    </Filter>
    5.15 +    <Filter Include="Resource Files">
    5.16 +      <UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
    5.17 +      <Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
    5.18 +    </Filter>
    5.19 +  </ItemGroup>
    5.20 +  <ItemGroup>
    5.21 +    <ClInclude Include="src\erebus.h">
    5.22 +      <Filter>Header Files</Filter>
    5.23 +    </ClInclude>
    5.24 +    <ClInclude Include="src\camera.h">
    5.25 +      <Filter>Header Files</Filter>
    5.26 +    </ClInclude>
    5.27 +    <ClInclude Include="src\image.h">
    5.28 +      <Filter>Header Files</Filter>
    5.29 +    </ClInclude>
    5.30 +    <ClInclude Include="src\scene.h">
    5.31 +      <Filter>Header Files</Filter>
    5.32 +    </ClInclude>
    5.33 +    <ClInclude Include="src\snode.h">
    5.34 +      <Filter>Header Files</Filter>
    5.35 +    </ClInclude>
    5.36 +    <ClInclude Include="src\object.h">
    5.37 +      <Filter>Header Files</Filter>
    5.38 +    </ClInclude>
    5.39 +    <ClInclude Include="src\geomobj.h">
    5.40 +      <Filter>Header Files</Filter>
    5.41 +    </ClInclude>
    5.42 +    <ClInclude Include="src\bvol.h">
    5.43 +      <Filter>Header Files</Filter>
    5.44 +    </ClInclude>
    5.45 +    <ClInclude Include="src\brdf.h">
    5.46 +      <Filter>Header Files</Filter>
    5.47 +    </ClInclude>
    5.48 +    <ClInclude Include="src\color.h">
    5.49 +      <Filter>Header Files</Filter>
    5.50 +    </ClInclude>
    5.51 +    <ClInclude Include="src\texture.h">
    5.52 +      <Filter>Header Files</Filter>
    5.53 +    </ClInclude>
    5.54 +    <ClInclude Include="src\erebus_impl.h">
    5.55 +      <Filter>Header Files</Filter>
    5.56 +    </ClInclude>
    5.57 +  </ItemGroup>
    5.58 +  <ItemGroup>
    5.59 +    <ClCompile Include="src\erebus.cc">
    5.60 +      <Filter>Source Files</Filter>
    5.61 +    </ClCompile>
    5.62 +    <ClCompile Include="src\camera.cc">
    5.63 +      <Filter>Source Files</Filter>
    5.64 +    </ClCompile>
    5.65 +    <ClCompile Include="src\object.cc">
    5.66 +      <Filter>Source Files</Filter>
    5.67 +    </ClCompile>
    5.68 +    <ClCompile Include="src\bvol.cc">
    5.69 +      <Filter>Source Files</Filter>
    5.70 +    </ClCompile>
    5.71 +    <ClCompile Include="src\brdf.cc">
    5.72 +      <Filter>Source Files</Filter>
    5.73 +    </ClCompile>
    5.74 +  </ItemGroup>
    5.75 +  <ItemGroup>
    5.76 +    <None Include="src\image.inl">
    5.77 +      <Filter>Header Files</Filter>
    5.78 +    </None>
    5.79 +  </ItemGroup>
    5.80 +</Project>
    5.81 \ No newline at end of file
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/liberebus/src/brdf.cc	Sun Apr 27 16:02:47 2014 +0300
     6.3 @@ -0,0 +1,130 @@
     6.4 +#include "brdf.h"
     6.5 +#include "erebus_impl.h"
     6.6 +
     6.7 +ReflAttrib::ReflAttrib()
     6.8 +	: value(1), color(1, 1, 1), map(0)
     6.9 +{
    6.10 +}
    6.11 +
    6.12 +ReflAttrib::ReflAttrib(const Color &col, Texture *tex)
    6.13 +{
    6.14 +	set_color(col);
    6.15 +	map = tex;
    6.16 +}
    6.17 +
    6.18 +void ReflAttrib::set_value(float val)
    6.19 +{
    6.20 +	value = val;
    6.21 +	color = Color{val, val, val};
    6.22 +}
    6.23 +
    6.24 +void ReflAttrib::set_color(const Color &col)
    6.25 +{
    6.26 +	color = col;
    6.27 +	value = color_luminance(col);
    6.28 +}
    6.29 +
    6.30 +void ReflAttrib::set_map(Texture *tex)
    6.31 +{
    6.32 +	map = tex;
    6.33 +}
    6.34 +
    6.35 +Texture *ReflAttrib::get_map() const
    6.36 +{
    6.37 +	return map;
    6.38 +}
    6.39 +
    6.40 +float ReflAttrib::get_value() const
    6.41 +{
    6.42 +	return value;
    6.43 +}
    6.44 +
    6.45 +float ReflAttrib::get_value(float u, float v) const
    6.46 +{
    6.47 +	return map ? value * color_luminance(map->lookup(u, v)) : value;
    6.48 +}
    6.49 +
    6.50 +const Color &ReflAttrib::get_color() const
    6.51 +{
    6.52 +	return color;
    6.53 +}
    6.54 +
    6.55 +Color ReflAttrib::get_color(float u, float v) const
    6.56 +{
    6.57 +	return map ? color * map->lookup(u, v) : color;
    6.58 +}
    6.59 +
    6.60 +// ---- class Reflectance ----
    6.61 +ReflAttrib Reflectance::def_attrib;
    6.62 +
    6.63 +Reflectance::Reflectance()
    6.64 +{
    6.65 +	set_default_attribs();
    6.66 +}
    6.67 +
    6.68 +void Reflectance::set_attrib(const char *name, const Color &color, Texture *tex)
    6.69 +{
    6.70 +	attrib[name] = ReflAttrib{color, tex};
    6.71 +}
    6.72 +
    6.73 +ReflAttrib &Reflectance::get_attrib(const char *name)
    6.74 +{
    6.75 +	auto it = attrib.find(name);
    6.76 +	if(it == attrib.end()) {
    6.77 +		return def_attrib;
    6.78 +	}
    6.79 +	return it->second;
    6.80 +}
    6.81 +
    6.82 +const ReflAttrib &Reflectance::get_attrib(const char *name) const
    6.83 +{
    6.84 +	auto it = attrib.find(name);
    6.85 +	if(it == attrib.end()) {
    6.86 +		return def_attrib;
    6.87 +	}
    6.88 +	return it->second;
    6.89 +}
    6.90 +
    6.91 +float Reflectance::get_attrib_value(const char *name) const
    6.92 +{
    6.93 +	return get_attrib(name).get_value();
    6.94 +}
    6.95 +
    6.96 +float Reflectance::get_attrib_value(const char *name, float u, float v) const
    6.97 +{
    6.98 +	return get_attrib(name).get_value(u, v);
    6.99 +}
   6.100 +
   6.101 +Color Reflectance::get_attrib_color(const char *name) const
   6.102 +{
   6.103 +	return get_attrib(name).get_color();
   6.104 +}
   6.105 +
   6.106 +Color Reflectance::get_attrib_color(const char *name, float u, float v) const
   6.107 +{
   6.108 +	return get_attrib(name).get_color(u, v);
   6.109 +}
   6.110 +
   6.111 +float Reflectance::sample(const Vector3 &norm, const Vector3 &outdir, Vector3 *indir) const
   6.112 +{
   6.113 +	*indir = sample_dir(norm, outdir);
   6.114 +	return eval(norm, outdir, *indir);
   6.115 +}
   6.116 +
   6.117 +// --- class LambertRefl ---
   6.118 +
   6.119 +void LambertRefl::set_default_attribs()
   6.120 +{
   6.121 +	set_attrib("color", Color(1, 1, 1));
   6.122 +}
   6.123 +
   6.124 +Vector3 LambertRefl::sample_dir(const Vector3 &norm, const Vector3 &outdir) const
   6.125 +{
   6.126 +	Vector3 dir = Vector3{randf(-1, 1), randf(-1, 1), randf(-1, 1)}.normalized();
   6.127 +	return dot_product(dir, norm) < 0.0 ? -dir : dir;
   6.128 +}
   6.129 +
   6.130 +float LambertRefl::eval(const Vector3 &norm, const Vector3 &outdir, const Vector3 &indir) const
   6.131 +{
   6.132 +	return dot_product(norm, outdir);
   6.133 +}
   6.134 \ No newline at end of file
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/liberebus/src/brdf.h	Sun Apr 27 16:02:47 2014 +0300
     7.3 @@ -0,0 +1,67 @@
     7.4 +#ifndef BRDF_H_
     7.5 +#define BRDF_H_
     7.6 +
     7.7 +#include <map>
     7.8 +#include <string>
     7.9 +#include "color.h"
    7.10 +#include "texture.h"
    7.11 +
    7.12 +class ReflAttrib {
    7.13 +private:
    7.14 +	float value;
    7.15 +	Color color;
    7.16 +	Texture *map;
    7.17 +
    7.18 +public:
    7.19 +
    7.20 +	ReflAttrib();
    7.21 +	explicit ReflAttrib(const Color &color, Texture *tex = 0);
    7.22 +
    7.23 +	void set_value(float val);
    7.24 +	void set_color(const Color &col);
    7.25 +
    7.26 +	void set_map(Texture *tex);
    7.27 +	Texture *get_map() const;
    7.28 +
    7.29 +	float get_value() const;
    7.30 +	float get_value(float u, float v) const;
    7.31 +	const Color &get_color() const;
    7.32 +	Color get_color(float u, float v) const;
    7.33 +};
    7.34 +
    7.35 +
    7.36 +class Reflectance {
    7.37 +private:
    7.38 +	static ReflAttrib def_attrib;
    7.39 +	std::map<std::string, ReflAttrib> attrib;
    7.40 +
    7.41 +	virtual void set_default_attribs();
    7.42 +
    7.43 +public:
    7.44 +	Reflectance();
    7.45 +	virtual ~Reflectance() = default;
    7.46 +
    7.47 +	virtual void set_attrib(const char *name, const Color &color, Texture *tex = 0);
    7.48 +	virtual ReflAttrib &get_attrib(const char *name);
    7.49 +	virtual const ReflAttrib &get_attrib(const char *name) const;
    7.50 +
    7.51 +	virtual float get_attrib_value(const char *name) const;
    7.52 +	virtual float get_attrib_value(const char *name, float u, float v) const;
    7.53 +	virtual Color get_attrib_color(const char *name) const;
    7.54 +	virtual Color get_attrib_color(const char *name, float u, float v) const;
    7.55 +
    7.56 +	virtual Vector3 sample_dir(const Vector3 &norm, const Vector3 &outdir) const = 0;
    7.57 +	virtual float sample(const Vector3 &norm, const Vector3 &outdir, Vector3 *indir) const;
    7.58 +	virtual float eval(const Vector3 &norm, const Vector3 &outdir, const Vector3 &indir) const = 0;
    7.59 +};
    7.60 +
    7.61 +class LambertRefl : public Reflectance {
    7.62 +private:
    7.63 +	void set_default_attribs() override;
    7.64 +
    7.65 +public:
    7.66 +	Vector3 sample_dir(const Vector3 &norm, const Vector3 &outdir) const override;
    7.67 +	float eval(const Vector3 &norm, const Vector3 &outdir, const Vector3 &indir) const override;
    7.68 +};
    7.69 +
    7.70 +#endif	// BRDF_H_
    7.71 \ No newline at end of file
     8.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.2 +++ b/liberebus/src/bvol.cc	Sun Apr 27 16:02:47 2014 +0300
     8.3 @@ -0,0 +1,38 @@
     8.4 +#include "bvol.h"
     8.5 +
     8.6 +bool AABox::intersect(const Ray &ray) const
     8.7 +{
     8.8 +	Vector3 param[2] = {vmin, vmax};
     8.9 +	Vector3 inv_dir(1.0 / ray.dir.x, 1.0 / ray.dir.y, 1.0 / ray.dir.z);
    8.10 +	int sign[3] = {inv_dir.x < 0, inv_dir.y < 0, inv_dir.z < 0};
    8.11 +
    8.12 +	float tmin = (param[sign[0]].x - ray.origin.x) * inv_dir.x;
    8.13 +	float tmax = (param[1 - sign[0]].x - ray.origin.x) * inv_dir.x;
    8.14 +	float tymin = (param[sign[1]].y - ray.origin.y) * inv_dir.y;
    8.15 +	float tymax = (param[1 - sign[1]].y - ray.origin.y) * inv_dir.y;
    8.16 +
    8.17 +	if(tmin > tymax || tymin > tmax) {
    8.18 +		return false;
    8.19 +	}
    8.20 +	if(tymin > tmin) {
    8.21 +		tmin = tymin;
    8.22 +	}
    8.23 +	if(tymax < tmax) {
    8.24 +		tmax = tymax;
    8.25 +	}
    8.26 +
    8.27 +	float tzmin = (param[sign[2]].z - ray.origin.z) * inv_dir.z;
    8.28 +	float tzmax = (param[1 - sign[2]].z - ray.origin.z) * inv_dir.z;
    8.29 +
    8.30 +	if(tmin > tzmax || tzmin > tmax) {
    8.31 +		return false;
    8.32 +	}
    8.33 +	if(tzmin > tmin) {
    8.34 +		tmin = tzmin;
    8.35 +	}
    8.36 +	if(tzmax < tmax) {
    8.37 +		tmax = tzmax;
    8.38 +	}
    8.39 +
    8.40 +	return true;
    8.41 +}
    8.42 \ No newline at end of file
     9.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.2 +++ b/liberebus/src/bvol.h	Sun Apr 27 16:02:47 2014 +0300
     9.3 @@ -0,0 +1,16 @@
     9.4 +#ifndef BVOL_H_
     9.5 +#define BVOL_H_
     9.6 +
     9.7 +#include "vmath/ray.h"
     9.8 +
     9.9 +class AABox {
    9.10 +public:
    9.11 +	Vector3 vmin, vmax;
    9.12 +
    9.13 +	AABox() : vmin(-0.5, -0.5, -0.5), vmax(0.5, 0.5, 0.5) {}
    9.14 +	AABox(const Vector3 &v0, const Vector3 &v1) : vmin(v0), vmax(v1) {}
    9.15 +
    9.16 +	bool intersect(const Ray &ray) const;
    9.17 +};
    9.18 +
    9.19 +#endif	// BVOL_H_
    9.20 \ No newline at end of file
    10.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.2 +++ b/liberebus/src/camera.cc	Sun Apr 27 16:02:47 2014 +0300
    10.3 @@ -0,0 +1,207 @@
    10.4 +#include <stdio.h>
    10.5 +#include <math.h>
    10.6 +#include "camera.h"
    10.7 +
    10.8 +static void calc_sample_pos_rec(int sidx, float xsz, float ysz, float *pos);
    10.9 +
   10.10 +Camera::Camera()
   10.11 +{
   10.12 +	vfov = M_PI / 4.0;
   10.13 +	cached_matrix_valid = false;
   10.14 +
   10.15 +	rdir_cache_width = rdir_cache_height = 0;
   10.16 +	rdir_cache = 0;
   10.17 +}
   10.18 +
   10.19 +Camera::Camera(const Vector3 &p)
   10.20 +	: pos(p)
   10.21 +{
   10.22 +	vfov = M_PI / 4.0;
   10.23 +	cached_matrix_valid = false;
   10.24 +
   10.25 +	rdir_cache_width = rdir_cache_height = 0;
   10.26 +	rdir_cache = 0;
   10.27 +}
   10.28 +
   10.29 +Camera::~Camera()
   10.30 +{
   10.31 +	delete [] rdir_cache;
   10.32 +}
   10.33 +
   10.34 +void Camera::set_fov(float vfov)
   10.35 +{
   10.36 +	this->vfov = vfov;
   10.37 +
   10.38 +	// invalidate the dir cache
   10.39 +	delete [] rdir_cache;
   10.40 +}
   10.41 +
   10.42 +float Camera::get_fov() const
   10.43 +{
   10.44 +	return vfov;
   10.45 +}
   10.46 +
   10.47 +void Camera::set_position(const Vector3 &pos)
   10.48 +{
   10.49 +	this->pos = pos;
   10.50 +	cached_matrix_valid = false;	// invalidate the cached matrix
   10.51 +}
   10.52 +
   10.53 +const Vector3 &Camera::get_position() const
   10.54 +{
   10.55 +	return pos;
   10.56 +}
   10.57 +
   10.58 +const Matrix4x4 &Camera::get_matrix() const
   10.59 +{
   10.60 +	if(!cached_matrix_valid) {
   10.61 +		calc_matrix(&cached_matrix);
   10.62 +		cached_matrix_valid = true;
   10.63 +	}
   10.64 +	return cached_matrix;
   10.65 +}
   10.66 +
   10.67 +Vector2 Camera::calc_sample_pos(int x, int y, int xsz, int ysz, int sample) const
   10.68 +{
   10.69 +	float ppos[2];
   10.70 +	float aspect = (float)xsz / (float)ysz;
   10.71 +
   10.72 +	float pwidth = 2.0 * aspect / (float)xsz;
   10.73 +	float pheight = 2.0 / (float)ysz;
   10.74 +
   10.75 +	ppos[0] = (float)x * pwidth - aspect;
   10.76 +	ppos[1] = 1.0 - (float)y * pheight;
   10.77 +
   10.78 +	calc_sample_pos_rec(sample, pwidth, pheight, ppos);
   10.79 +	return Vector2(ppos[0], ppos[1]);
   10.80 +}
   10.81 +
   10.82 +Ray Camera::get_primary_ray(int x, int y, int xsz, int ysz, int sample) const
   10.83 +{
   10.84 +#pragma omp single
   10.85 +	{
   10.86 +		if(!rdir_cache || rdir_cache_width != xsz || rdir_cache_height != ysz) {
   10.87 +			printf("calculating primary ray direction cache\n");
   10.88 +
   10.89 +			delete [] rdir_cache;
   10.90 +			rdir_cache = new Vector3[xsz * ysz];
   10.91 +
   10.92 +#pragma omp parallel for
   10.93 +			for(int i=0; i<ysz; i++) {
   10.94 +				Vector3 *rdir = rdir_cache + i * xsz;
   10.95 +				for(int j=0; j<xsz; j++) {
   10.96 +					Vector2 ppos = calc_sample_pos(j, i, xsz, ysz, 0);
   10.97 +
   10.98 +					rdir->x = ppos.x;
   10.99 +					rdir->y = ppos.y;
  10.100 +					rdir->z = 1.0 / tan(vfov / 2.0);
  10.101 +					rdir->normalize();
  10.102 +
  10.103 +					rdir++;
  10.104 +				}
  10.105 +			}
  10.106 +			rdir_cache_width = xsz;
  10.107 +			rdir_cache_height = ysz;
  10.108 +		}
  10.109 +	}
  10.110 +
  10.111 +	Ray ray;
  10.112 +	ray.origin = pos;
  10.113 +	ray.dir = rdir_cache[y * xsz + x];
  10.114 +
  10.115 +	// transform the ray direction with the camera matrix
  10.116 +	Matrix4x4 mat = get_matrix();
  10.117 +	mat.m[0][3] = mat.m[1][3] = mat.m[2][3] = mat.m[3][0] = mat.m[3][1] = mat.m[3][2] = 0.0;
  10.118 +	mat.m[3][3] = 1.0;
  10.119 +
  10.120 +	ray.dir = ray.dir.transformed(mat);
  10.121 +	return ray;
  10.122 +}
  10.123 +
  10.124 +TargetCamera::TargetCamera() {}
  10.125 +
  10.126 +TargetCamera::TargetCamera(const Vector3 &pos, const Vector3 &targ)
  10.127 +	: Camera(pos), target(targ)
  10.128 +{
  10.129 +}
  10.130 +
  10.131 +void TargetCamera::set_target(const Vector3 &targ)
  10.132 +{
  10.133 +	target = targ;
  10.134 +	cached_matrix_valid = false; // invalidate the cached matrix
  10.135 +}
  10.136 +
  10.137 +const Vector3 &TargetCamera::get_target() const
  10.138 +{
  10.139 +	return target;
  10.140 +}
  10.141 +
  10.142 +void TargetCamera::calc_matrix(Matrix4x4 *mat) const
  10.143 +{
  10.144 +	Vector3 up(0, 1, 0);
  10.145 +	Vector3 dir = (target - pos).normalized();
  10.146 +	Vector3 right = cross_product(up, dir);
  10.147 +	up = cross_product(dir, right);
  10.148 +
  10.149 +	*mat = Matrix4x4(
  10.150 +			right.x, up.x, dir.x, pos.x,
  10.151 +			right.y, up.y, dir.y, pos.y,
  10.152 +			right.z, up.z, dir.z, pos.z,
  10.153 +			0.0, 0.0, 0.0, 1.0);
  10.154 +}
  10.155 +
  10.156 +void FlyCamera::input_move(float x, float y, float z)
  10.157 +{
  10.158 +	static const Vector3 vfwd(0, 0, 1), vright(1, 0, 0);
  10.159 +
  10.160 +	Vector3 k = vfwd.transformed(rot);
  10.161 +	Vector3	i = vright.transformed(rot);
  10.162 +	Vector3 j = cross_product(k, i);
  10.163 +
  10.164 +	pos += i * x + j * y + k * z;
  10.165 +	cached_matrix_valid = false;
  10.166 +}
  10.167 +
  10.168 +void FlyCamera::input_rotate(float x, float y, float z)
  10.169 +{
  10.170 +	Vector3 axis(x, y, z);
  10.171 +	float axis_len = axis.length();
  10.172 +	if(fabs(axis_len) < 1e-5) {
  10.173 +		return;
  10.174 +	}
  10.175 +	rot.rotate(axis / axis_len, -axis_len);
  10.176 +	rot.normalize();
  10.177 +
  10.178 +	cached_matrix_valid = false;
  10.179 +}
  10.180 +
  10.181 +void FlyCamera::calc_matrix(Matrix4x4 *mat) const
  10.182 +{
  10.183 +	Matrix4x4 tmat;
  10.184 +	tmat.set_translation(pos);
  10.185 +
  10.186 +	Matrix3x3 rmat = rot.get_rotation_matrix();
  10.187 +
  10.188 +	*mat = tmat * Matrix4x4(rmat);
  10.189 +}
  10.190 +
  10.191 +/* generates a sample position for sample number sidx, in the unit square
  10.192 + * by recursive subdivision and jittering
  10.193 + */
  10.194 +static void calc_sample_pos_rec(int sidx, float xsz, float ysz, float *pos)
  10.195 +{
  10.196 +    static const float subpt[4][2] = {
  10.197 +        {-0.25, -0.25}, {0.25, -0.25}, {-0.25, 0.25}, {0.25, 0.25}
  10.198 +    };
  10.199 +
  10.200 +    if(!sidx) {
  10.201 +        return;
  10.202 +    }
  10.203 +
  10.204 +    /* determine which quadrant to recurse into */
  10.205 +    int quadrant = ((sidx - 1) % 4);
  10.206 +    pos[0] += subpt[quadrant][0] * xsz;
  10.207 +    pos[1] += subpt[quadrant][1] * ysz;
  10.208 +
  10.209 +    calc_sample_pos_rec((sidx - 1) / 4, xsz / 2, ysz / 2, pos);
  10.210 +}
    11.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    11.2 +++ b/liberebus/src/camera.h	Sun Apr 27 16:02:47 2014 +0300
    11.3 @@ -0,0 +1,61 @@
    11.4 +#ifndef CAMERA_H_
    11.5 +#define CAMERA_H_
    11.6 +
    11.7 +#include "vmath/vmath.h"
    11.8 +
    11.9 +class Camera {
   11.10 +protected:
   11.11 +	Vector3 pos;
   11.12 +	float vfov;	// vertical field of view in radians
   11.13 +
   11.14 +	mutable Matrix4x4 cached_matrix;
   11.15 +	mutable bool cached_matrix_valid;
   11.16 +
   11.17 +	mutable Vector3 *rdir_cache;
   11.18 +	mutable int rdir_cache_width, rdir_cache_height;
   11.19 +
   11.20 +	virtual void calc_matrix(Matrix4x4 *mat) const = 0;
   11.21 +
   11.22 +	Vector2 calc_sample_pos(int x, int y, int xsz, int ysz, int sample) const;
   11.23 +
   11.24 +public:
   11.25 +	Camera();
   11.26 +	Camera(const Vector3 &pos);
   11.27 +	virtual ~Camera();
   11.28 +
   11.29 +	virtual void set_fov(float vfov);
   11.30 +	virtual float get_fov() const;
   11.31 +
   11.32 +	virtual void set_position(const Vector3 &pos);
   11.33 +	virtual const Vector3 &get_position() const;
   11.34 +	virtual const Matrix4x4 &get_matrix() const;
   11.35 +
   11.36 +	virtual Ray get_primary_ray(int x, int y, int xsz, int ysz, int sample = 0) const;
   11.37 +};
   11.38 +
   11.39 +class TargetCamera : public Camera {
   11.40 +protected:
   11.41 +	Vector3 target;
   11.42 +
   11.43 +	void calc_matrix(Matrix4x4 *mat) const;
   11.44 +
   11.45 +public:
   11.46 +	TargetCamera();
   11.47 +	TargetCamera(const Vector3 &pos, const Vector3 &targ);
   11.48 +
   11.49 +	virtual void set_target(const Vector3 &targ);
   11.50 +	virtual const Vector3 &get_target() const;
   11.51 +};
   11.52 +
   11.53 +class FlyCamera : public Camera {
   11.54 +protected:
   11.55 +	Quaternion rot;
   11.56 +
   11.57 +	void calc_matrix(Matrix4x4 *mat) const;
   11.58 +
   11.59 +public:
   11.60 +	void input_move(float x, float y, float z);
   11.61 +	void input_rotate(float x, float y, float z);
   11.62 +};
   11.63 +
   11.64 +#endif	// CAMERA_H_
    12.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    12.2 +++ b/liberebus/src/color.h	Sun Apr 27 16:02:47 2014 +0300
    12.3 @@ -0,0 +1,10 @@
    12.4 +#ifndef COLOR_H_
    12.5 +#define COLOR_H_
    12.6 +
    12.7 +#include "vmath/vector.h"
    12.8 +
    12.9 +typedef Vector3 Color;
   12.10 +
   12.11 +inline float color_luminance(const Color &c) { return c[0] * 0.2126 + c[1] * 0.7152 + c[2] * 0.0722; }
   12.12 +
   12.13 +#endif	// COLOR_H_
   12.14 \ No newline at end of file
    13.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    13.2 +++ b/liberebus/src/erebus.cc	Sun Apr 27 16:02:47 2014 +0300
    13.3 @@ -0,0 +1,159 @@
    13.4 +#include <string.h>
    13.5 +#include <limits.h>
    13.6 +#include <chrono>
    13.7 +#include <random>
    13.8 +#include "erebus.h"
    13.9 +#include "vmath/vector.h"
   13.10 +#include "image.h"
   13.11 +
   13.12 +using namespace std::chrono;
   13.13 +
   13.14 +struct Rect {
   13.15 +	int x, y, width, height;
   13.16 +
   13.17 +	bool operator ==(const Rect &r) { return memcmp(this, &r, sizeof r) == 0; }
   13.18 +	bool operator !=(const Rect &r) { return memcmp(this, &r, sizeof r) != 0; }
   13.19 +};
   13.20 +
   13.21 +#define INVALID_RECT	Rect{0, 0, 0, 0}
   13.22 +
   13.23 +struct erebus {
   13.24 +	Image<float> fbimg;
   13.25 +	Vector4 options[ERB_NUM_OPTIONS];
   13.26 +
   13.27 +	// render state
   13.28 +	long cur_time;
   13.29 +	int cur_pixel_x, cur_pixel_y;
   13.30 +	Rect cur_rect;
   13.31 +};
   13.32 +
   13.33 +static void render_pixel(struct erebus *ctx, int x, int y);
   13.34 +
   13.35 +static std::mt19937 rnd_gen;
   13.36 +
   13.37 +extern "C" {
   13.38 +
   13.39 +struct erebus *erb_init(void)
   13.40 +{
   13.41 +	struct erebus *ctx;
   13.42 +	try {
   13.43 +		ctx = new struct erebus;
   13.44 +	}
   13.45 +	catch(...) {
   13.46 +		return 0;
   13.47 +	}
   13.48 +
   13.49 +	ctx->cur_time = 0;
   13.50 +	ctx->cur_rect = INVALID_RECT;
   13.51 +	return ctx;
   13.52 +}
   13.53 +
   13.54 +void erb_destroy(struct erebus *ctx)
   13.55 +{
   13.56 +	delete ctx;
   13.57 +}
   13.58 +
   13.59 +void erb_setopti(struct erebus *ctx, enum erb_option opt, int val)
   13.60 +{
   13.61 +	ctx->options[opt].x;
   13.62 +}
   13.63 +void erb_setoptf(struct erebus *ctx, enum erb_option opt, float val)
   13.64 +{
   13.65 +	ctx->options[opt].x = val;
   13.66 +}
   13.67 +void erb_setoptfv(struct erebus *ctx, enum erb_option opt, float *vec)
   13.68 +{
   13.69 +	for(int i=0; i<4; i++) {
   13.70 +		ctx->options[opt][i] = vec[i];
   13.71 +	}
   13.72 +}
   13.73 +
   13.74 +int erb_getopti(struct erebus *ctx, enum erb_option opt)
   13.75 +{
   13.76 +	return ctx->options[opt].x;
   13.77 +}
   13.78 +float erb_getoptf(struct erebus *ctx, enum erb_option opt)
   13.79 +{
   13.80 +	return ctx->options[opt].x;
   13.81 +}
   13.82 +float *erb_getoptfv(struct erebus *ctx, enum erb_option opt)
   13.83 +{
   13.84 +	return &ctx->options[opt].x;
   13.85 +}
   13.86 +
   13.87 +float *erb_get_framebuffer(struct erebus *ctx)
   13.88 +{
   13.89 +	return ctx->fbimg.get_pixels();
   13.90 +}
   13.91 +
   13.92 +void erb_begin_frame(struct erebus *ctx, long ms)
   13.93 +{
   13.94 +	ctx->cur_time = ms;
   13.95 +}
   13.96 +
   13.97 +int erb_render(struct erebus *ctx, long timeout)
   13.98 +{
   13.99 +	return erb_render_rect(ctx, 0, 0, ctx->fbimg.get_width(), ctx->fbimg.get_height(), timeout);
  13.100 +}
  13.101 +
  13.102 +int erb_render_rect(struct erebus *ctx, int x, int y, int width, int height, long timeout)
  13.103 +{
  13.104 +	if(!width || !height) return -1;
  13.105 +
  13.106 +	Rect rect{x, y, width, height};
  13.107 +	if(ctx->cur_rect != rect) {
  13.108 +		ctx->cur_rect = rect;
  13.109 +		ctx->cur_pixel_x = x;
  13.110 +		ctx->cur_pixel_y = y;
  13.111 +	}
  13.112 +
  13.113 +	if(timeout > 0) {
  13.114 +		auto start_time = monotonic_clock::now();
  13.115 +		while(duration_cast<milliseconds>(monotonic_clock::now() - start_time).count() < timeout) {
  13.116 +			render_pixel(ctx, ctx->cur_pixel_x, ctx->cur_pixel_y);
  13.117 +
  13.118 +			if(++ctx->cur_pixel_x >= ctx->cur_rect.width) {
  13.119 +				if(++ctx->cur_pixel_y >= ctx->cur_rect.height) {
  13.120 +					ctx->cur_rect = INVALID_RECT;
  13.121 +					return 0;
  13.122 +				}
  13.123 +			}
  13.124 +		}
  13.125 +		return 1;
  13.126 +	}
  13.127 +
  13.128 +	for(int i=0; i<height; i++) {
  13.129 +		for(int j=0; j<width; j++) {
  13.130 +			render_pixel(ctx, j, i);
  13.131 +		}
  13.132 +	}
  13.133 +	return 0;
  13.134 +}
  13.135 +
  13.136 +int erb_get_progress(struct erebus *ctx)
  13.137 +{
  13.138 +	return 0;	// TODO
  13.139 +}
  13.140 +
  13.141 +int erb_load_scene(struct erebus *ctx, const char *fname)
  13.142 +{
  13.143 +	//delete ctx->scene;
  13.144 +	//ctx->scene = new Scene;
  13.145 +
  13.146 +	return false;	// TODO
  13.147 +}
  13.148 +
  13.149 +}	// extern "C"
  13.150 +
  13.151 +float randf(float low, float high)
  13.152 +{
  13.153 +	std::uniform_real_distribution<float> unirnd(low, high);
  13.154 +	return unirnd(rnd_gen);
  13.155 +}
  13.156 +
  13.157 +static void render_pixel(struct erebus *ctx, int x, int y)
  13.158 +{
  13.159 +	float *pix = ctx->fbimg.get_pixels() + (y * ctx->fbimg.get_width() + x) * 4;
  13.160 +	pix[0] = pix[1] = pix[2] = 0.0f;
  13.161 +	pix[3] = 1.0f;
  13.162 +}
  13.163 \ No newline at end of file
    14.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    14.2 +++ b/liberebus/src/erebus.h	Sun Apr 27 16:02:47 2014 +0300
    14.3 @@ -0,0 +1,46 @@
    14.4 +#ifndef LIBEREBUS_H_
    14.5 +#define LIBEREBUS_H_
    14.6 +
    14.7 +struct erebus;
    14.8 +
    14.9 +enum erb_option {
   14.10 +	ERB_OPT_WIDTH,
   14.11 +	ERB_OPT_HEIGHT,
   14.12 +	ERB_OPT_MAX_ITER,
   14.13 +	ERB_OPT_NUM_THREADS,
   14.14 +	ERB_OPT_GAMMA,
   14.15 +
   14.16 +	ERB_NUM_OPTIONS
   14.17 +};
   14.18 +
   14.19 +#ifdef __cplusplus
   14.20 +extern "C" {
   14.21 +#endif
   14.22 +
   14.23 +struct erebus *erb_init(void);
   14.24 +void erb_destroy(struct erebus *ctx);
   14.25 +
   14.26 +void erb_setopti(struct erebus *ctx, enum erb_option opt, int val);
   14.27 +void erb_setoptf(struct erebus *ctx, enum erb_option opt, float val);
   14.28 +void erb_setoptfv(struct erebus *ctx, enum erb_option opt, float *vec);
   14.29 +
   14.30 +int erb_getopti(struct erebus *ctx, enum erb_option opt);
   14.31 +float erb_getoptf(struct erebus *ctx, enum erb_option opt);
   14.32 +float *erb_getoptfv(struct erebus *ctx, enum erb_option opt);
   14.33 +
   14.34 +float *erb_get_framebuffer(struct erebus *ctx);
   14.35 +
   14.36 +void erb_begin_frame(struct erebus *ctx, long ms);
   14.37 +int erb_render(struct erebus *ctx, long timeout);
   14.38 +int erb_render_rect(struct erebus *ctx, int x, int y, int width, int height, long timeout);
   14.39 +
   14.40 +int erb_get_progress(struct erebus *ctx);
   14.41 +
   14.42 +int erb_load_scene(struct erebus *ctx, const char *fname);
   14.43 +
   14.44 +#ifdef __cplusplus
   14.45 +}
   14.46 +#endif
   14.47 +
   14.48 +
   14.49 +#endif	/* LIBEREBUS_H_ */
   14.50 \ No newline at end of file
    15.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    15.2 +++ b/liberebus/src/erebus_impl.h	Sun Apr 27 16:02:47 2014 +0300
    15.3 @@ -0,0 +1,6 @@
    15.4 +#ifndef EREBUS_IMPL_H_
    15.5 +#define EREBUS_IMPL_H_
    15.6 +
    15.7 +float randf(float low = 0.0f, float high = 1.0f);
    15.8 +
    15.9 +#endif	// EREBUS_IMPL_H_
   15.10 \ No newline at end of file
    16.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    16.2 +++ b/liberebus/src/geomobj.h	Sun Apr 27 16:02:47 2014 +0300
    16.3 @@ -0,0 +1,50 @@
    16.4 +#ifndef GEOMOBJ_H_
    16.5 +#define GEOMOBJ_H_
    16.6 +
    16.7 +#include "object.h"
    16.8 +#include "brdf.h"
    16.9 +
   16.10 +class GeomObject : public Object {
   16.11 +public:
   16.12 +	Reflectance *brdf;
   16.13 +
   16.14 +	ObjType get_type() const override;
   16.15 +
   16.16 +	bool intersect(const Ray &ray, RayHit *hit = 0) const override;
   16.17 +};
   16.18 +
   16.19 +class Sphere : public GeomObject {
   16.20 +public:
   16.21 +	bool intersect(const Ray &ray, RayHit *hit = 0) const override;
   16.22 +};
   16.23 +
   16.24 +class Box : public GeomObject {
   16.25 +public:
   16.26 +	bool intersect(const Ray &ray, RayHit *hit = 0) const override;
   16.27 +};
   16.28 +
   16.29 +class Triangle : public GeomObject {
   16.30 +public:
   16.31 +	Vector3 v[3];
   16.32 +	Vector3 normal;
   16.33 +	Vector3 vnorm[3];
   16.34 +	Vector2 vtex[3];
   16.35 +
   16.36 +	bool intersect(const Ray &ray, RayHit *hit = 0) const override;
   16.37 +};
   16.38 +
   16.39 +class Mesh : public GeomObject {
   16.40 +private:
   16.41 +	std::vector<Triangle> faces;
   16.42 +
   16.43 +public:
   16.44 +	void begin();
   16.45 +	void vertex(float x, float y, float z);
   16.46 +	void normal(float x, float y, float z);
   16.47 +	void texcoord(float u, float v);
   16.48 +	void end();
   16.49 +
   16.50 +	bool intersect(const Ray &ray, RayHit *hit = 0) const override;
   16.51 +};
   16.52 +
   16.53 +#endif	// GEOMOBJ_H_
   16.54 \ No newline at end of file
    17.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    17.2 +++ b/liberebus/src/image.h	Sun Apr 27 16:02:47 2014 +0300
    17.3 @@ -0,0 +1,35 @@
    17.4 +#ifndef IMAGE_H_
    17.5 +#define IMAGE_H_
    17.6 +
    17.7 +template <typename T>
    17.8 +class Image {
    17.9 +private:
   17.10 +	int width, height;
   17.11 +	T *pixels;
   17.12 +	bool own_pixels;
   17.13 +
   17.14 +public:
   17.15 +	Image();
   17.16 +	~Image();
   17.17 +
   17.18 +	Image(const Image &img);
   17.19 +	Image &operator =(const Image &img);
   17.20 +
   17.21 +	Image(const Image &&img);
   17.22 +	Image &&operator =(const Image &&img);
   17.23 +
   17.24 +	void create(int xsz, int ysz, const T *pix = 0);
   17.25 +	void destroy();
   17.26 +
   17.27 +	int get_width() const;
   17.28 +	int get_height() const;
   17.29 +
   17.30 +	void set_pixels(int xsz, int ysz, T *pix);
   17.31 +	T *get_pixels() const;
   17.32 +
   17.33 +	bool load(const char *fname);
   17.34 +};
   17.35 +
   17.36 +#include "image.inl"
   17.37 +
   17.38 +#endif	// IMAGE_H_
    18.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    18.2 +++ b/liberebus/src/image.inl	Sun Apr 27 16:02:47 2014 +0300
    18.3 @@ -0,0 +1,143 @@
    18.4 +#include <string.h>
    18.5 +#include "imago2.h"
    18.6 +#include "image.h"
    18.7 +
    18.8 +template <typename T>
    18.9 +Image<T>::Image()
   18.10 +{
   18.11 +	pixels = 0;
   18.12 +	own_pixels = true;
   18.13 +	width = height = 0;
   18.14 +}
   18.15 +
   18.16 +template <typename T>
   18.17 +Image<T>::~Image()
   18.18 +{
   18.19 +	destroy();
   18.20 +}
   18.21 +
   18.22 +template <typename T>
   18.23 +Image<T>::Image(const Image<T> &img)
   18.24 +{
   18.25 +	pixels = 0;
   18.26 +	own_pixels = false;
   18.27 +
   18.28 +	create(img.width, img.height, img.pixels);
   18.29 +}
   18.30 +
   18.31 +template <typename T>
   18.32 +Image<T> &Image<T>::operator =(const Image<T> &img)
   18.33 +{
   18.34 +	if(this != &img) {
   18.35 +		destroy();
   18.36 +		create(img.width, img.height, img.pixels);
   18.37 +	}
   18.38 +	return *this;
   18.39 +}
   18.40 +
   18.41 +template <typename T>
   18.42 +Image<T>::Image(const Image<T> &&img)
   18.43 +{
   18.44 +	width = img.width;
   18.45 +	height = img.height;
   18.46 +	pixels = img.pixels;
   18.47 +	own_pixels = img.own_pixels;
   18.48 +
   18.49 +	img.pixels = 0;
   18.50 +	img.width = img.height = 0;
   18.51 +}
   18.52 +
   18.53 +template <typename T>
   18.54 +Image<T> &&Image<T>::operator =(const Image<T> &&img)
   18.55 +{
   18.56 +	if(this != &img) {
   18.57 +		width = img.width;
   18.58 +		height = img.height;
   18.59 +		pixels = img.pixels;
   18.60 +		own_pixels = img.own_pixels;
   18.61 +
   18.62 +		img.pixels = 0;
   18.63 +		img.width = img.height = 0;
   18.64 +	}
   18.65 +	return *this;
   18.66 +}
   18.67 +
   18.68 +template <typename T>
   18.69 +void Image<T>::create(int xsz, int ysz, const T *pixels)
   18.70 +{
   18.71 +	destroy();
   18.72 +
   18.73 +	this->pixels = new T[xsz * ysz * 4];
   18.74 +	if(pixels) {
   18.75 +		memcpy(this->pixels, pixels, xsz * ysz * 4 * sizeof(T));
   18.76 +	} else {
   18.77 +		memset(this->pixels, 0, xsz * ysz * 4 * sizeof(T));
   18.78 +	}
   18.79 +	width = xsz;
   18.80 +	height = ysz;
   18.81 +	own_pixels = true;
   18.82 +}
   18.83 +
   18.84 +template <typename T>
   18.85 +void Image<T>::destroy()
   18.86 +{
   18.87 +	if(own_pixels) {
   18.88 +		delete [] pixels;
   18.89 +	}
   18.90 +	pixels = 0;
   18.91 +	width = height = 0;
   18.92 +	own_pixels = true;
   18.93 +}
   18.94 +
   18.95 +template <typename T>
   18.96 +int Image<T>::get_width() const
   18.97 +{
   18.98 +	return width;
   18.99 +}
  18.100 +
  18.101 +template <typename T>
  18.102 +int Image<T>::get_height() const
  18.103 +{
  18.104 +	return height;
  18.105 +}
  18.106 +
  18.107 +template <typename T>
  18.108 +void Image<T>::set_pixels(int xsz, int ysz, T *pixels)
  18.109 +{
  18.110 +	destroy();
  18.111 +
  18.112 +	this->pixels = pixels;
  18.113 +	width = xsz;
  18.114 +	height = ysz;
  18.115 +	own_pixels = false;
  18.116 +}
  18.117 +
  18.118 +template <typename T>
  18.119 +T *Image<T>::get_pixels() const
  18.120 +{
  18.121 +	return pixels;
  18.122 +}
  18.123 +
  18.124 +bool Image<unsigned char>::load(const char *fname)
  18.125 +{
  18.126 +	int xsz, ysz;
  18.127 +	unsigned char *pix = (unsigned char*)img_load_pixels(fname, &xsz, &ysz, IMG_FMT_RGBA32);
  18.128 +	if(!pix) {
  18.129 +		return false;
  18.130 +	}
  18.131 +
  18.132 +	create(xsz, ysz, pix);
  18.133 +	return true;
  18.134 +}
  18.135 +
  18.136 +bool Image<float>::load(const char *fname)
  18.137 +{
  18.138 +	int xsz, ysz;
  18.139 +	float *pix = (float*)img_load_pixels(fname, &xsz, &ysz, IMG_FMT_RGBAF);
  18.140 +	if(!pix) {
  18.141 +		return false;
  18.142 +	}
  18.143 +
  18.144 +	create(xsz, ysz, pix);
  18.145 +	return true;
  18.146 +}
  18.147 \ No newline at end of file
    19.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    19.2 +++ b/liberebus/src/object.cc	Sun Apr 27 16:02:47 2014 +0300
    19.3 @@ -0,0 +1,60 @@
    19.4 +#include "object.h"
    19.5 +
    19.6 +Object::Object()
    19.7 +{
    19.8 +	name = "<unnamed>";
    19.9 +	inv_xform_valid = false;
   19.10 +}
   19.11 +
   19.12 +ObjType Object::get_type() const
   19.13 +{
   19.14 +	return ObjType::null;
   19.15 +}
   19.16 +
   19.17 +void Object::set_name(const char *name)
   19.18 +{
   19.19 +	this->name = name;
   19.20 +}
   19.21 +
   19.22 +const char *Object::get_name() const
   19.23 +{
   19.24 +	return name.c_str();
   19.25 +}
   19.26 +
   19.27 +void Object::set_xform(const Matrix4x4 &mat)
   19.28 +{
   19.29 +	xform = mat;
   19.30 +	inv_xform_valid = false;
   19.31 +}
   19.32 +
   19.33 +void Object::set_xform(const Matrix4x4 &mat, const Matrix4x4 &inv_mat)
   19.34 +{
   19.35 +	xform = mat;
   19.36 +	inv_xform = inv_mat;
   19.37 +	inv_xform_valid = true;
   19.38 +}
   19.39 +
   19.40 +Matrix4x4 &Object::get_xform()
   19.41 +{
   19.42 +	inv_xform_valid = false;
   19.43 +	return xform;
   19.44 +}
   19.45 +
   19.46 +const Matrix4x4 &Object::get_xform() const
   19.47 +{
   19.48 +	return xform;
   19.49 +}
   19.50 +
   19.51 +const Matrix4x4 &Object::get_inv_xform() const
   19.52 +{
   19.53 +	if(!inv_xform_valid) {
   19.54 +		inv_xform = xform.inverse();
   19.55 +		inv_xform_valid = true;
   19.56 +	}
   19.57 +	return inv_xform;
   19.58 +}
   19.59 +
   19.60 +bool Object::intersect(const Ray &ray, RayHit *hit) const
   19.61 +{
   19.62 +	return false;
   19.63 +}
   19.64 \ No newline at end of file
    20.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    20.2 +++ b/liberebus/src/object.h	Sun Apr 27 16:02:47 2014 +0300
    20.3 @@ -0,0 +1,44 @@
    20.4 +#ifndef OBJECT_H_
    20.5 +#define OBJECT_H_
    20.6 +
    20.7 +#include <string>
    20.8 +#include "vmath/ray.h"
    20.9 +
   20.10 +class Object;
   20.11 +
   20.12 +struct RayHit {
   20.13 +	float dist;
   20.14 +	const Ray world_ray, local_ray;
   20.15 +
   20.16 +	const Object *obj, *subobj;
   20.17 +};
   20.18 +
   20.19 +enum class ObjType { null, geom, camera };
   20.20 +
   20.21 +class Object {
   20.22 +private:
   20.23 +	std::string name;
   20.24 +	Matrix4x4 xform;
   20.25 +	mutable Matrix4x4 inv_xform;
   20.26 +	mutable bool inv_xform_valid;
   20.27 +
   20.28 +public:
   20.29 +	Object();
   20.30 +	virtual ~Object() = default;
   20.31 +
   20.32 +	virtual ObjType get_type() const;
   20.33 +
   20.34 +	virtual void set_name(const char *name);
   20.35 +	virtual const char *get_name() const;
   20.36 +
   20.37 +	virtual void set_xform(const Matrix4x4 &mat);
   20.38 +	virtual void set_xform(const Matrix4x4 &mat, const Matrix4x4 &inv_mat);
   20.39 +
   20.40 +	virtual Matrix4x4 &get_xform();	// invalidates inv_xform
   20.41 +	virtual const Matrix4x4 &get_xform() const;
   20.42 +	virtual const Matrix4x4 &get_inv_xform() const;
   20.43 +
   20.44 +	virtual bool intersect(const Ray &ray, RayHit *hit = 0) const;
   20.45 +};
   20.46 +
   20.47 +#endif	// OBJECT_H_
   20.48 \ No newline at end of file
    21.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    21.2 +++ b/liberebus/src/scene.h	Sun Apr 27 16:02:47 2014 +0300
    21.3 @@ -0,0 +1,23 @@
    21.4 +#ifndef SCENE_H_
    21.5 +#define SCENE_H_
    21.6 +
    21.7 +#include <vector>
    21.8 +#include "snode.h"
    21.9 +#include "camera.h"
   21.10 +
   21.11 +class Scene {
   21.12 +private:
   21.13 +	std::vector<Object*> objects;
   21.14 +	std::vector<SceneNode*> nodes;
   21.15 +
   21.16 +	Camera *active_cam;
   21.17 +
   21.18 +public:
   21.19 +	Scene();
   21.20 +	~Scene();
   21.21 +
   21.22 +	void add_object(Object *obj);
   21.23 +	Object *get_object(int idx);
   21.24 +};
   21.25 +
   21.26 +#endif	// SCENE_H_
   21.27 \ No newline at end of file
    22.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    22.2 +++ b/liberebus/src/snode.h	Sun Apr 27 16:02:47 2014 +0300
    22.3 @@ -0,0 +1,41 @@
    22.4 +#ifndef SNODE_H_
    22.5 +#define SNODE_H_
    22.6 +
    22.7 +#include <vector>
    22.8 +#include "object.h"
    22.9 +#include "vmath/vmath.h"
   22.10 +
   22.11 +class SceneNode {
   22.12 +private:
   22.13 +	Vector3 pos;
   22.14 +	Quaternion rot;
   22.15 +	Vector3 scale;
   22.16 +
   22.17 +	std::vector<Object*> obj;
   22.18 +
   22.19 +	SceneNode *parent;
   22.20 +	std::vector<SceneNode*> children;
   22.21 +
   22.22 +public:
   22.23 +	void add_child(SceneNode *node);
   22.24 +
   22.25 +	int get_num_children() const;
   22.26 +	SceneNode *get_child(int idx) const;
   22.27 +
   22.28 +	void set_position(const Vector3 &pos);
   22.29 +	void set_rotation(const Quaternion &rot);
   22.30 +	void set_scaling(const Vector3 &scale);
   22.31 +
   22.32 +	const Vector3 &get_node_position() const;
   22.33 +	const Quaternion &get_node_rotation() const;
   22.34 +	const Vector3 &get_node_scaling() const;
   22.35 +
   22.36 +	const Vector3 &get_position() const;
   22.37 +	const Quaternion &get_rotation() const;
   22.38 +	const Vector3 &get_scaling() const;
   22.39 +
   22.40 +	void update_node(long msec = 0) const;
   22.41 +	void update(long msec = 0) const;
   22.42 +};
   22.43 +
   22.44 +#endif	// SNODE_H_
   22.45 \ No newline at end of file
    23.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    23.2 +++ b/liberebus/src/texture.h	Sun Apr 27 16:02:47 2014 +0300
    23.3 @@ -0,0 +1,30 @@
    23.4 +#ifndef TEXTURE_H_
    23.5 +#define TEXTURE_H_
    23.6 +
    23.7 +#include "image.h"
    23.8 +#include "color.h"
    23.9 +
   23.10 +class Texture {
   23.11 +public:
   23.12 +	Image<float> img;
   23.13 +
   23.14 +	inline Color lookup(float u, float v) const;
   23.15 +
   23.16 +	bool load(const char *fname) { return img.load(fname); }
   23.17 +};
   23.18 +
   23.19 +
   23.20 +inline Color Texture::lookup(float u, float v) const
   23.21 +{
   23.22 +	int xsz = img.get_width();
   23.23 +	int ysz = img.get_height();
   23.24 +
   23.25 +	int x = (float)u / (float)xsz;
   23.26 +	int y = (float)v / (float)ysz;
   23.27 +
   23.28 +	float *pix = img.get_pixels() + ((y % ysz) * xsz + (x % xsz)) * 4;
   23.29 +	return Color(pix[0], pix[1], pix[2]);
   23.30 +}
   23.31 +
   23.32 +
   23.33 +#endif	// TEXTURE_H_
   23.34 \ No newline at end of file
    24.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    24.2 +++ b/src/main.cc	Sun Apr 27 16:02:47 2014 +0300
    24.3 @@ -0,0 +1,141 @@
    24.4 +#include <stdio.h>
    24.5 +#include <stdlib.h>
    24.6 +#include <assert.h>
    24.7 +#include "opengl.h"
    24.8 +
    24.9 +static bool init();
   24.10 +static void cleanup();
   24.11 +static void resize_rtarget(int xsz, int ysz);
   24.12 +static void update_rect(int x, int y, int xsz, int ysz, float *pixels);
   24.13 +static void display();
   24.14 +static void reshape(int x, int y);
   24.15 +static void keyb(unsigned char key, int x, int y);
   24.16 +static void mouse(int bn, int st, int x, int y);
   24.17 +static int next_pow2(int x);
   24.18 +
   24.19 +static int width, height, rtex_width, rtex_height;
   24.20 +static unsigned int rtex;
   24.21 +
   24.22 +int main(int argc, char **argv)
   24.23 +{
   24.24 +	glutInitWindowSize(1024, 600);
   24.25 +	glutInit(&argc, argv);
   24.26 +	glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);
   24.27 +	glutCreateWindow("erebus OpenGL frontend");
   24.28 +
   24.29 +	glutDisplayFunc(display);
   24.30 +	glutReshapeFunc(reshape);
   24.31 +	glutKeyboardFunc(keyb);
   24.32 +	glutMouseFunc(mouse);
   24.33 +
   24.34 +	if(!init()) {
   24.35 +		return 1;
   24.36 +	}
   24.37 +	atexit(cleanup);
   24.38 +
   24.39 +	glutMainLoop();
   24.40 +}
   24.41 +
   24.42 +static bool init()
   24.43 +{
   24.44 +	return true;
   24.45 +}
   24.46 +
   24.47 +static void cleanup()
   24.48 +{
   24.49 +}
   24.50 +
   24.51 +static void resize_rtarget(int xsz, int ysz)
   24.52 +{
   24.53 +	static unsigned char *defpix;
   24.54 +
   24.55 +	width = xsz;
   24.56 +	height = ysz;
   24.57 +
   24.58 +	if(xsz <= rtex_width && ysz <= rtex_height) {
   24.59 +		return;
   24.60 +	}
   24.61 +	rtex_width = next_pow2(xsz);
   24.62 +	rtex_height = next_pow2(ysz);
   24.63 +
   24.64 +	printf("resizing framebuffer texture: %dx%d\n", rtex_width, rtex_height);
   24.65 +
   24.66 +	if(!rtex) {
   24.67 +		glGenTextures(1, &rtex);
   24.68 +	}
   24.69 +
   24.70 +	delete [] defpix;
   24.71 +	defpix = new unsigned char[rtex_width * rtex_height * 4];
   24.72 +	unsigned char *ptr = defpix;
   24.73 +	for(int i=0; i<rtex_height; i++) {
   24.74 +		for(int j=0; j<rtex_width; j++) {
   24.75 +			bool chess = ((i >> 4) & 1) == ((j >> 4) & 1);
   24.76 +
   24.77 +			int val = chess ? 64 : 48;
   24.78 +
   24.79 +			*ptr++ = val;
   24.80 +			*ptr++ = val;
   24.81 +			*ptr++ = val;
   24.82 +			*ptr++ = 255;
   24.83 +		}
   24.84 +	}
   24.85 +
   24.86 +	glBindTexture(GL_TEXTURE_2D, rtex);
   24.87 +	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
   24.88 +	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
   24.89 +	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F_ARB, rtex_width, rtex_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, defpix);
   24.90 +}
   24.91 +
   24.92 +static void update_rect(int x, int y, int xsz, int ysz, float *pixels)
   24.93 +{
   24.94 +	glBindTexture(GL_TEXTURE_2D, rtex);
   24.95 +	glTexSubImage2D(GL_TEXTURE_2D, 0, x, y, xsz, ysz, GL_RGBA, GL_FLOAT, pixels);
   24.96 +}
   24.97 +
   24.98 +static void display()
   24.99 +{
  24.100 +	glBindTexture(GL_TEXTURE_2D, rtex);
  24.101 +	glEnable(GL_TEXTURE_2D);
  24.102 +
  24.103 +	float maxu = (float)width / (float)rtex_width;
  24.104 +	float maxv = (float)height / (float)rtex_height;
  24.105 +
  24.106 +	glBegin(GL_QUADS);
  24.107 +	glTexCoord2f(0, maxv); glVertex2f(-1, -1);
  24.108 +	glTexCoord2f(maxu, maxv); glVertex2f(1, -1);
  24.109 +	glTexCoord2f(maxu, 0); glVertex2f(1, 1);
  24.110 +	glTexCoord2f(0, 0); glVertex2f(-1, 1);
  24.111 +	glEnd();
  24.112 +
  24.113 +	glDisable(GL_TEXTURE_2D);
  24.114 +
  24.115 +	glutSwapBuffers();
  24.116 +	assert(glGetError() == GL_NO_ERROR);
  24.117 +}
  24.118 +
  24.119 +static void reshape(int x, int y)
  24.120 +{
  24.121 +	glViewport(0, 0, x, y);
  24.122 +	resize_rtarget(x, y);
  24.123 +}
  24.124 +
  24.125 +static void keyb(unsigned char key, int x, int y)
  24.126 +{
  24.127 +	switch(key) {
  24.128 +	case 27:
  24.129 +		exit(0);
  24.130 +	}
  24.131 +}
  24.132 +
  24.133 +static void mouse(int bn, int st, int x, int y)
  24.134 +{
  24.135 +}
  24.136 +
  24.137 +static int next_pow2(int x)
  24.138 +{
  24.139 +	int res = 2;
  24.140 +	while(res < x) {
  24.141 +		res <<= 1;
  24.142 +	}
  24.143 +	return res;
  24.144 +}
  24.145 \ No newline at end of file
    25.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    25.2 +++ b/src/opengl.cc	Sun Apr 27 16:02:47 2014 +0300
    25.3 @@ -0,0 +1,63 @@
    25.4 +#include "opengl.h"
    25.5 +#include <vmath/vmath.h>
    25.6 +
    25.7 +
    25.8 +
    25.9 +void load_matrix(const Matrix4x4 &m)
   25.10 +{
   25.11 +#ifdef SINGLE_PRECISION_MATH
   25.12 +	if(glLoadTransposeMatrixfARB) {
   25.13 +		glLoadTransposeMatrixfARB((float*)&m);
   25.14 +	} else {
   25.15 +		Matrix4x4 tmat = m.transposed();
   25.16 +		glLoadMatrixf((float*)&tmat);
   25.17 +	}
   25.18 +#else
   25.19 +	if(glLoadTransposeMatrixdARB) {
   25.20 +		glLoadTransposeMatrixdARB((double*)&m);
   25.21 +	} else {
   25.22 +		Matrix4x4 tmat = m.transposed();
   25.23 +		glLoadMatrixd((double*)&tmat);
   25.24 +	}
   25.25 +#endif
   25.26 +}
   25.27 +
   25.28 +void mult_matrix(const Matrix4x4 &m)
   25.29 +{
   25.30 +#ifdef SINGLE_PRECISION_MATH
   25.31 +	if(glMultTransposeMatrixfARB) {
   25.32 +		glMultTransposeMatrixfARB((float*)&m);
   25.33 +	} else {
   25.34 +		Matrix4x4 tmat = m.transposed();
   25.35 +		glMultMatrixf((float*)&tmat);
   25.36 +	}
   25.37 +#else
   25.38 +	if(glMultTransposeMatrixdARB) {
   25.39 +		glMultTransposeMatrixdARB((double*)&m);
   25.40 +	} else {
   25.41 +		Matrix4x4 tmat = m.transposed();
   25.42 +		glMultMatrixd((double*)&tmat);
   25.43 +	}
   25.44 +#endif
   25.45 +}
   25.46 +
   25.47 +const char *strglerr(int err)
   25.48 +{
   25.49 +	static const char *errnames[] = {
   25.50 +		"GL_INVALID_ENUM",
   25.51 +		"GL_INVALID_VALUE",
   25.52 +		"GL_INVALID_OPERATION",
   25.53 +		"GL_STACK_OVERFLOW",
   25.54 +		"GL_STACK_UNDERFLOW",
   25.55 +		"GL_OUT_OF_MEMORY",
   25.56 +		"GL_INVALID_FRAMEBUFFER_OPERATION"
   25.57 +	};
   25.58 +
   25.59 +	if(!err) {
   25.60 +		return "GL_NO_ERROR";
   25.61 +	}
   25.62 +	if(err < GL_INVALID_ENUM || err > GL_OUT_OF_MEMORY) {
   25.63 +		return "<invalid gl error>";
   25.64 +	}
   25.65 +	return errnames[err - GL_INVALID_ENUM];
   25.66 +}
    26.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    26.2 +++ b/src/opengl.h	Sun Apr 27 16:02:47 2014 +0300
    26.3 @@ -0,0 +1,29 @@
    26.4 +#ifndef OPENGL_H_
    26.5 +#define OPENGL_H_
    26.6 +
    26.7 +#include <GL/glew.h>
    26.8 +
    26.9 +#ifndef __APPLE__
   26.10 +#include <GL/glut.h>
   26.11 +#else
   26.12 +#include <GLUT/glut.h>
   26.13 +#endif
   26.14 +
   26.15 +#define CHECKGLERR	\
   26.16 +	do { \
   26.17 +		int err = glGetError(); \
   26.18 +		if(err) { \
   26.19 +			fprintf(stderr, "%s:%d: OpenGL error 0x%x: %s\n", __FILE__, __LINE__, err, strglerr(err)); \
   26.20 +			abort(); \
   26.21 +		} \
   26.22 +	} while(0)
   26.23 +
   26.24 +
   26.25 +class Matrix4x4;
   26.26 +
   26.27 +void load_matrix(const Matrix4x4 &m);
   26.28 +void mult_matrix(const Matrix4x4 &m);
   26.29 +
   26.30 +const char *strglerr(int err);
   26.31 +
   26.32 +#endif	/* OPENGL_H_ */
    27.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    27.2 +++ b/src/sdr.c	Sun Apr 27 16:02:47 2014 +0300
    27.3 @@ -0,0 +1,427 @@
    27.4 +/*
    27.5 +Printblobs - halftoning display hack
    27.6 +Copyright (C) 2013  John Tsiombikas <nuclear@member.fsf.org>
    27.7 +
    27.8 +This program is free software: you can redistribute it and/or modify
    27.9 +it under the terms of the GNU General Public License as published by
   27.10 +the Free Software Foundation, either version 3 of the License, or
   27.11 +(at your option) any later version.
   27.12 +
   27.13 +This program is distributed in the hope that it will be useful,
   27.14 +but WITHOUT ANY WARRANTY; without even the implied warranty of
   27.15 +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   27.16 +GNU General Public License for more details.
   27.17 +
   27.18 +You should have received a copy of the GNU General Public License
   27.19 +along with this program.  If not, see <http://www.gnu.org/licenses/>.
   27.20 +*/
   27.21 +#include <stdio.h>
   27.22 +#include <stdlib.h>
   27.23 +#include <string.h>
   27.24 +#include <errno.h>
   27.25 +#include <stdarg.h>
   27.26 +#include <assert.h>
   27.27 +#include <GL/glew.h>
   27.28 +
   27.29 +#if defined(unix) || defined(__unix__)
   27.30 +#include <unistd.h>
   27.31 +#include <sys/stat.h>
   27.32 +#endif	/* unix */
   27.33 +
   27.34 +#include "sdr.h"
   27.35 +
   27.36 +static const char *sdrtypestr(unsigned int sdrtype);
   27.37 +
   27.38 +unsigned int create_vertex_shader(const char *src)
   27.39 +{
   27.40 +	return create_shader(src, GL_VERTEX_SHADER);
   27.41 +}
   27.42 +
   27.43 +unsigned int create_pixel_shader(const char *src)
   27.44 +{
   27.45 +	return create_shader(src, GL_FRAGMENT_SHADER);
   27.46 +}
   27.47 +
   27.48 +unsigned int create_tessctl_shader(const char *src)
   27.49 +{
   27.50 +	return create_shader(src, GL_TESS_CONTROL_SHADER);
   27.51 +}
   27.52 +
   27.53 +unsigned int create_tesseval_shader(const char *src)
   27.54 +{
   27.55 +	return create_shader(src, GL_TESS_EVALUATION_SHADER);
   27.56 +}
   27.57 +
   27.58 +unsigned int create_geometry_shader(const char *src)
   27.59 +{
   27.60 +	return create_shader(src, GL_GEOMETRY_SHADER);
   27.61 +}
   27.62 +
   27.63 +unsigned int create_shader(const char *src, unsigned int sdr_type)
   27.64 +{
   27.65 +	unsigned int sdr;
   27.66 +	int success, info_len;
   27.67 +	char *info_str = 0;
   27.68 +	GLenum err;
   27.69 +
   27.70 +	sdr = glCreateShader(sdr_type);
   27.71 +	assert(glGetError() == GL_NO_ERROR);
   27.72 +	glShaderSource(sdr, 1, &src, 0);
   27.73 +	err = glGetError();
   27.74 +	assert(err == GL_NO_ERROR);
   27.75 +	glCompileShader(sdr);
   27.76 +	assert(glGetError() == GL_NO_ERROR);
   27.77 +
   27.78 +	glGetShaderiv(sdr, GL_COMPILE_STATUS, &success);
   27.79 +	assert(glGetError() == GL_NO_ERROR);
   27.80 +	glGetShaderiv(sdr, GL_INFO_LOG_LENGTH, &info_len);
   27.81 +	assert(glGetError() == GL_NO_ERROR);
   27.82 +
   27.83 +	if(info_len) {
   27.84 +		if((info_str = malloc(info_len + 1))) {
   27.85 +			glGetShaderInfoLog(sdr, info_len, 0, info_str);
   27.86 +			assert(glGetError() == GL_NO_ERROR);
   27.87 +		}
   27.88 +	}
   27.89 +
   27.90 +	if(success) {
   27.91 +		fprintf(stderr, info_str ? "done: %s\n" : "done\n", info_str);
   27.92 +	} else {
   27.93 +		fprintf(stderr, info_str ? "failed: %s\n" : "failed\n", info_str);
   27.94 +		glDeleteShader(sdr);
   27.95 +		sdr = 0;
   27.96 +	}
   27.97 +
   27.98 +	free(info_str);
   27.99 +	return sdr;
  27.100 +}
  27.101 +
  27.102 +void free_shader(unsigned int sdr)
  27.103 +{
  27.104 +	glDeleteShader(sdr);
  27.105 +}
  27.106 +
  27.107 +unsigned int load_vertex_shader(const char *fname)
  27.108 +{
  27.109 +	return load_shader(fname, GL_VERTEX_SHADER);
  27.110 +}
  27.111 +
  27.112 +unsigned int load_pixel_shader(const char *fname)
  27.113 +{
  27.114 +	return load_shader(fname, GL_FRAGMENT_SHADER);
  27.115 +}
  27.116 +
  27.117 +unsigned int load_tessctl_shader(const char *fname)
  27.118 +{
  27.119 +	return load_shader(fname, GL_TESS_CONTROL_SHADER);
  27.120 +}
  27.121 +
  27.122 +unsigned int load_tesseval_shader(const char *fname)
  27.123 +{
  27.124 +	return load_shader(fname, GL_TESS_EVALUATION_SHADER);
  27.125 +}
  27.126 +
  27.127 +unsigned int load_geometry_shader(const char *fname)
  27.128 +{
  27.129 +	return load_shader(fname, GL_GEOMETRY_SHADER);
  27.130 +}
  27.131 +
  27.132 +unsigned int load_shader(const char *fname, unsigned int sdr_type)
  27.133 +{
  27.134 +#if defined(unix) || defined(__unix__)
  27.135 +	struct stat st;
  27.136 +#endif
  27.137 +	unsigned int sdr;
  27.138 +	size_t filesize;
  27.139 +	FILE *fp;
  27.140 +	char *src;
  27.141 +
  27.142 +	if(!(fp = fopen(fname, "r"))) {
  27.143 +		fprintf(stderr, "failed to open shader %s: %s\n", fname, strerror(errno));
  27.144 +		return 0;
  27.145 +	}
  27.146 +
  27.147 +#if defined(unix) || defined(__unix__)
  27.148 +	fstat(fileno(fp), &st);
  27.149 +	filesize = st.st_size;
  27.150 +#else
  27.151 +	fseek(fp, 0, SEEK_END);
  27.152 +	filesize = ftell(fp);
  27.153 +	fseek(fp, 0, SEEK_SET);
  27.154 +#endif	/* unix */
  27.155 +
  27.156 +	if(!(src = malloc(filesize + 1))) {
  27.157 +		fclose(fp);
  27.158 +		return 0;
  27.159 +	}
  27.160 +	fread(src, 1, filesize, fp);
  27.161 +	src[filesize] = 0;
  27.162 +	fclose(fp);
  27.163 +
  27.164 +	fprintf(stderr, "compiling %s shader: %s... ", sdrtypestr(sdr_type), fname);
  27.165 +	sdr = create_shader(src, sdr_type);
  27.166 +
  27.167 +	free(src);
  27.168 +	return sdr;
  27.169 +}
  27.170 +
  27.171 +
  27.172 +unsigned int get_vertex_shader(const char *fname)
  27.173 +{
  27.174 +	return get_shader(fname, GL_VERTEX_SHADER);
  27.175 +}
  27.176 +
  27.177 +unsigned int get_pixel_shader(const char *fname)
  27.178 +{
  27.179 +	return get_shader(fname, GL_FRAGMENT_SHADER);
  27.180 +}
  27.181 +
  27.182 +unsigned int get_tessctl_shader(const char *fname)
  27.183 +{
  27.184 +	return get_shader(fname, GL_TESS_CONTROL_SHADER);
  27.185 +}
  27.186 +
  27.187 +unsigned int get_tesseval_shader(const char *fname)
  27.188 +{
  27.189 +	return get_shader(fname, GL_TESS_EVALUATION_SHADER);
  27.190 +}
  27.191 +
  27.192 +unsigned int get_geometry_shader(const char *fname)
  27.193 +{
  27.194 +	return get_shader(fname, GL_GEOMETRY_SHADER);
  27.195 +}
  27.196 +
  27.197 +unsigned int get_shader(const char *fname, unsigned int sdr_type)
  27.198 +{
  27.199 +	unsigned int sdr;
  27.200 +	if(!(sdr = load_shader(fname, sdr_type))) {
  27.201 +		return 0;
  27.202 +	}
  27.203 +	return sdr;
  27.204 +}
  27.205 +
  27.206 +
  27.207 +/* ---- gpu programs ---- */
  27.208 +
  27.209 +unsigned int create_program(void)
  27.210 +{
  27.211 +	unsigned int prog = glCreateProgram();
  27.212 +	assert(glGetError() == GL_NO_ERROR);
  27.213 +	return prog;
  27.214 +}
  27.215 +
  27.216 +unsigned int create_program_link(unsigned int sdr0, ...)
  27.217 +{
  27.218 +	unsigned int prog, sdr;
  27.219 +	va_list ap;
  27.220 +
  27.221 +	if(!(prog = create_program())) {
  27.222 +		return 0;
  27.223 +	}
  27.224 +
  27.225 +	attach_shader(prog, sdr0);
  27.226 +	if(glGetError()) {
  27.227 +		return 0;
  27.228 +	}
  27.229 +
  27.230 +	va_start(ap, sdr0);
  27.231 +	while((sdr = va_arg(ap, unsigned int))) {
  27.232 +		attach_shader(prog, sdr);
  27.233 +		if(glGetError()) {
  27.234 +			return 0;
  27.235 +		}
  27.236 +	}
  27.237 +	va_end(ap);
  27.238 +
  27.239 +	if(link_program(prog) == -1) {
  27.240 +		free_program(prog);
  27.241 +		return 0;
  27.242 +	}
  27.243 +	return prog;
  27.244 +}
  27.245 +
  27.246 +unsigned int create_program_load(const char *vfile, const char *pfile)
  27.247 +{
  27.248 +	unsigned int vs = 0, ps = 0;
  27.249 +
  27.250 +	if(vfile && *vfile && !(vs = get_vertex_shader(vfile))) {
  27.251 +		return 0;
  27.252 +	}
  27.253 +	if(pfile && *pfile && !(ps = get_pixel_shader(pfile))) {
  27.254 +		return 0;
  27.255 +	}
  27.256 +	return create_program_link(vs, ps, 0);
  27.257 +}
  27.258 +
  27.259 +void free_program(unsigned int sdr)
  27.260 +{
  27.261 +	glDeleteProgram(sdr);
  27.262 +}
  27.263 +
  27.264 +void attach_shader(unsigned int prog, unsigned int sdr)
  27.265 +{
  27.266 +	glAttachShader(prog, sdr);
  27.267 +	assert(glGetError() == GL_NO_ERROR);
  27.268 +}
  27.269 +
  27.270 +int link_program(unsigned int prog)
  27.271 +{
  27.272 +	int linked, info_len, retval = 0;
  27.273 +	char *info_str = 0;
  27.274 +
  27.275 +	glLinkProgram(prog);
  27.276 +	assert(glGetError() == GL_NO_ERROR);
  27.277 +	glGetProgramiv(prog, GL_LINK_STATUS, &linked);
  27.278 +	assert(glGetError() == GL_NO_ERROR);
  27.279 +	glGetProgramiv(prog, GL_INFO_LOG_LENGTH, &info_len);
  27.280 +	assert(glGetError() == GL_NO_ERROR);
  27.281 +
  27.282 +	if(info_len) {
  27.283 +		if((info_str = malloc(info_len + 1))) {
  27.284 +			glGetProgramInfoLog(prog, info_len, 0, info_str);
  27.285 +			assert(glGetError() == GL_NO_ERROR);
  27.286 +		}
  27.287 +	}
  27.288 +
  27.289 +	if(linked) {
  27.290 +		fprintf(stderr, info_str ? "linking done: %s\n" : "linking done\n", info_str);
  27.291 +	} else {
  27.292 +		fprintf(stderr, info_str ? "linking failed: %s\n" : "linking failed\n", info_str);
  27.293 +		retval = -1;
  27.294 +	}
  27.295 +
  27.296 +	free(info_str);
  27.297 +	return retval;
  27.298 +}
  27.299 +
  27.300 +int bind_program(unsigned int prog)
  27.301 +{
  27.302 +	GLenum err;
  27.303 +
  27.304 +	glUseProgram(prog);
  27.305 +	if(prog && (err = glGetError()) != GL_NO_ERROR) {
  27.306 +		/* maybe the program is not linked, try linking first */
  27.307 +		if(err == GL_INVALID_OPERATION) {
  27.308 +			if(link_program(prog) == -1) {
  27.309 +				return -1;
  27.310 +			}
  27.311 +			glUseProgram(prog);
  27.312 +			return glGetError() == GL_NO_ERROR ? 0 : -1;
  27.313 +		}
  27.314 +		return -1;
  27.315 +	}
  27.316 +	return 0;
  27.317 +}
  27.318 +
  27.319 +/* ugly but I'm not going to write the same bloody code over and over */
  27.320 +#define BEGIN_UNIFORM_CODE \
  27.321 +	int loc, curr_prog; \
  27.322 +	glGetIntegerv(GL_CURRENT_PROGRAM, &curr_prog); \
  27.323 +	if((unsigned int)curr_prog != prog && bind_program(prog) == -1) { \
  27.324 +		return -1; \
  27.325 +	} \
  27.326 +	if((loc = glGetUniformLocation(prog, name)) != -1)
  27.327 +
  27.328 +#define END_UNIFORM_CODE \
  27.329 +	if((unsigned int)curr_prog != prog) { \
  27.330 +		bind_program(curr_prog); \
  27.331 +	} \
  27.332 +	return loc == -1 ? -1 : 0
  27.333 +
  27.334 +int set_uniform_int(unsigned int prog, const char *name, int val)
  27.335 +{
  27.336 +	BEGIN_UNIFORM_CODE {
  27.337 +		glUniform1i(loc, val);
  27.338 +	}
  27.339 +	END_UNIFORM_CODE;
  27.340 +}
  27.341 +
  27.342 +int set_uniform_float(unsigned int prog, const char *name, float val)
  27.343 +{
  27.344 +	BEGIN_UNIFORM_CODE {
  27.345 +		glUniform1f(loc, val);
  27.346 +	}
  27.347 +	END_UNIFORM_CODE;
  27.348 +}
  27.349 +
  27.350 +int set_uniform_float2(unsigned int prog, const char *name, float x, float y)
  27.351 +{
  27.352 +	BEGIN_UNIFORM_CODE {
  27.353 +		glUniform2f(loc, x, y);
  27.354 +	}
  27.355 +	END_UNIFORM_CODE;
  27.356 +}
  27.357 +
  27.358 +int set_uniform_float3(unsigned int prog, const char *name, float x, float y, float z)
  27.359 +{
  27.360 +	BEGIN_UNIFORM_CODE {
  27.361 +		glUniform3f(loc, x, y, z);
  27.362 +	}
  27.363 +	END_UNIFORM_CODE;
  27.364 +}
  27.365 +
  27.366 +int set_uniform_float4(unsigned int prog, const char *name, float x, float y, float z, float w)
  27.367 +{
  27.368 +	BEGIN_UNIFORM_CODE {
  27.369 +		glUniform4f(loc, x, y, z, w);
  27.370 +	}
  27.371 +	END_UNIFORM_CODE;
  27.372 +}
  27.373 +
  27.374 +int set_uniform_matrix4(unsigned int prog, const char *name, float *mat)
  27.375 +{
  27.376 +	BEGIN_UNIFORM_CODE {
  27.377 +		glUniformMatrix4fv(loc, 1, GL_FALSE, mat);
  27.378 +	}
  27.379 +	END_UNIFORM_CODE;
  27.380 +}
  27.381 +
  27.382 +int set_uniform_matrix4_transposed(unsigned int prog, const char *name, float *mat)
  27.383 +{
  27.384 +	BEGIN_UNIFORM_CODE {
  27.385 +		glUniformMatrix4fv(loc, 1, GL_TRUE, mat);
  27.386 +	}
  27.387 +	END_UNIFORM_CODE;
  27.388 +}
  27.389 +
  27.390 +int get_attrib_loc(unsigned int prog, const char *name)
  27.391 +{
  27.392 +	int loc, curr_prog;
  27.393 +
  27.394 +	glGetIntegerv(GL_CURRENT_PROGRAM, &curr_prog);
  27.395 +	if((unsigned int)curr_prog != prog && bind_program(prog) == -1) {
  27.396 +		return -1;
  27.397 +	}
  27.398 +
  27.399 +	loc = glGetAttribLocation(prog, (char*)name);
  27.400 +
  27.401 +	if((unsigned int)curr_prog != prog) {
  27.402 +		bind_program(curr_prog);
  27.403 +	}
  27.404 +	return loc;
  27.405 +}
  27.406 +
  27.407 +void set_attrib_float3(int attr_loc, float x, float y, float z)
  27.408 +{
  27.409 +	glVertexAttrib3f(attr_loc, x, y, z);
  27.410 +}
  27.411 +
  27.412 +static const char *sdrtypestr(unsigned int sdrtype)
  27.413 +{
  27.414 +	switch(sdrtype) {
  27.415 +	case GL_VERTEX_SHADER:
  27.416 +		return "vertex";
  27.417 +	case GL_FRAGMENT_SHADER:
  27.418 +		return "pixel";
  27.419 +	case GL_TESS_CONTROL_SHADER:
  27.420 +		return "tessellation control";
  27.421 +	case GL_TESS_EVALUATION_SHADER:
  27.422 +		return "tessellation evaluation";
  27.423 +	case GL_GEOMETRY_SHADER:
  27.424 +		return "geometry";
  27.425 +
  27.426 +	default:
  27.427 +		break;
  27.428 +	}
  27.429 +	return "<unknown>";
  27.430 +}
    28.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    28.2 +++ b/src/sdr.h	Sun Apr 27 16:02:47 2014 +0300
    28.3 @@ -0,0 +1,76 @@
    28.4 +/*
    28.5 +Printblobs - halftoning display hack
    28.6 +Copyright (C) 2013  John Tsiombikas <nuclear@member.fsf.org>
    28.7 +
    28.8 +This program is free software: you can redistribute it and/or modify
    28.9 +it under the terms of the GNU General Public License as published by
   28.10 +the Free Software Foundation, either version 3 of the License, or
   28.11 +(at your option) any later version.
   28.12 +
   28.13 +This program is distributed in the hope that it will be useful,
   28.14 +but WITHOUT ANY WARRANTY; without even the implied warranty of
   28.15 +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   28.16 +GNU General Public License for more details.
   28.17 +
   28.18 +You should have received a copy of the GNU General Public License
   28.19 +along with this program.  If not, see <http://www.gnu.org/licenses/>.
   28.20 +*/
   28.21 +#ifndef SDR_H_
   28.22 +#define SDR_H_
   28.23 +
   28.24 +#ifdef __cplusplus
   28.25 +extern "C" {
   28.26 +#endif	/* __cplusplus */
   28.27 +
   28.28 +/* ---- shaders ---- */
   28.29 +unsigned int create_vertex_shader(const char *src);
   28.30 +unsigned int create_pixel_shader(const char *src);
   28.31 +unsigned int create_tessctl_shader(const char *src);
   28.32 +unsigned int create_tesseval_shader(const char *src);
   28.33 +unsigned int create_geometry_shader(const char *src);
   28.34 +unsigned int create_shader(const char *src, unsigned int sdr_type);
   28.35 +void free_shader(unsigned int sdr);
   28.36 +
   28.37 +unsigned int load_vertex_shader(const char *fname);
   28.38 +unsigned int load_pixel_shader(const char *fname);
   28.39 +unsigned int load_tessctl_shader(const char *fname);
   28.40 +unsigned int load_tesseval_shader(const char *fname);
   28.41 +unsigned int load_geometry_shader(const char *fname);
   28.42 +unsigned int load_shader(const char *src, unsigned int sdr_type);
   28.43 +
   28.44 +unsigned int get_vertex_shader(const char *fname);
   28.45 +unsigned int get_pixel_shader(const char *fname);
   28.46 +unsigned int get_tessctl_shader(const char *fname);
   28.47 +unsigned int get_tesseval_shader(const char *fname);
   28.48 +unsigned int get_geometry_shader(const char *fname);
   28.49 +unsigned int get_shader(const char *fname, unsigned int sdr_type);
   28.50 +
   28.51 +int add_shader(const char *fname, unsigned int sdr);
   28.52 +int remove_shader(const char *fname);
   28.53 +
   28.54 +/* ---- gpu programs ---- */
   28.55 +unsigned int create_program(void);
   28.56 +unsigned int create_program_link(unsigned int sdr0, ...);
   28.57 +unsigned int create_program_load(const char *vfile, const char *pfile);
   28.58 +void free_program(unsigned int sdr);
   28.59 +
   28.60 +void attach_shader(unsigned int prog, unsigned int sdr);
   28.61 +int link_program(unsigned int prog);
   28.62 +int bind_program(unsigned int prog);
   28.63 +
   28.64 +int set_uniform_int(unsigned int prog, const char *name, int val);
   28.65 +int set_uniform_float(unsigned int prog, const char *name, float val);
   28.66 +int set_uniform_float2(unsigned int prog, const char *name, float x, float y);
   28.67 +int set_uniform_float3(unsigned int prog, const char *name, float x, float y, float z);
   28.68 +int set_uniform_float4(unsigned int prog, const char *name, float x, float y, float z, float w);
   28.69 +int set_uniform_matrix4(unsigned int prog, const char *name, float *mat);
   28.70 +int set_uniform_matrix4_transposed(unsigned int prog, const char *name, float *mat);
   28.71 +
   28.72 +int get_attrib_loc(unsigned int prog, const char *name);
   28.73 +void set_attrib_float3(int attr_loc, float x, float y, float z);
   28.74 +
   28.75 +#ifdef __cplusplus
   28.76 +}
   28.77 +#endif	/* __cplusplus */
   28.78 +
   28.79 +#endif	/* SDR_H_ */