| @@ -6,9 +6,6 @@ | |||||
| <!-- Global Lol Engine Configuration Settings --> | <!-- Global Lol Engine Configuration Settings --> | ||||
| <!-- ======================================== --> | <!-- ======================================== --> | ||||
| <!-- Use OpenGL instead of Direct3D? --> | |||||
| <UseOpenGL>true</UseOpenGL> | |||||
| <!-- Use Bullet for our physics solver? --> | <!-- Use Bullet for our physics solver? --> | ||||
| <UseBullet>true</UseBullet> | <UseBullet>true</UseBullet> | ||||
| @@ -16,8 +16,8 @@ | |||||
| <ObjectFileName>$(IntDir)/%(Directory)/</ObjectFileName> | <ObjectFileName>$(IntDir)/%(Directory)/</ObjectFileName> | ||||
| <AdditionalIncludeDirectories>$(SolutionDir)\..\src;$(SolutionDir)\..\src\bullet;$(SolutionDir)\..\tools\lolunit;$(PegtlIncludes);$(ImguiIncludes);$(BtPhysIncludes);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> | <AdditionalIncludeDirectories>$(SolutionDir)\..\src;$(SolutionDir)\..\src\bullet;$(SolutionDir)\..\tools\lolunit;$(PegtlIncludes);$(ImguiIncludes);$(BtPhysIncludes);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> | ||||
| <AdditionalIncludeDirectories Condition="'$(Platform)'=='Win32'">$(GlIncludes);$(SdlIncludes);$(FfmpegIncludes);$(AssimpIncludes);$(D3d9Includes);$(XinputIncludes);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> | |||||
| <AdditionalIncludeDirectories Condition="'$(Platform)'=='x64'">$(GlIncludes);$(SdlIncludes);$(FfmpegIncludes);$(AssimpIncludes);$(D3d9Includes);$(XinputIncludes);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> | |||||
| <AdditionalIncludeDirectories Condition="'$(Platform)'=='Win32'">$(GlIncludes);$(SdlIncludes);$(FfmpegIncludes);$(AssimpIncludes);$(XinputIncludes);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> | |||||
| <AdditionalIncludeDirectories Condition="'$(Platform)'=='x64'">$(GlIncludes);$(SdlIncludes);$(FfmpegIncludes);$(AssimpIncludes);$(XinputIncludes);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> | |||||
| <PreprocessorDefinitions>NOMINMAX;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions> | <PreprocessorDefinitions>NOMINMAX;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions> | ||||
| <!-- Escape backslashes for C++, but replace \ with / on the PS4 | <!-- Escape backslashes for C++, but replace \ with / on the PS4 | ||||
| @@ -53,16 +53,13 @@ | |||||
| <Link> | <Link> | ||||
| <!-- FIXME: not for the static library! --> | <!-- FIXME: not for the static library! --> | ||||
| <AdditionalDependencies Condition="'$(Platform)'=='Win32' Or '$(Platform)'=='x64'">kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;$(SdlDeps);$(FfmpegDeps);$(AssimpDeps);$(LibGccDeps);$(GdiDeps);$(XinputDeps);%(AdditionalDependencies)</AdditionalDependencies> | |||||
| <AdditionalDependencies Condition="'$(UseOpenGL)'=='true' And ('$(Platform)'=='Win32' Or '$(Platform)'=='x64')">$(GlDeps);%(AdditionalDependencies)</AdditionalDependencies> | |||||
| <AdditionalDependencies Condition="'$(UseOpenGL)'=='false' And ('$(Platform)'=='Win32' Or '$(Platform)'=='x64')">$(D3d9Deps);%(AdditionalDependencies)</AdditionalDependencies> | |||||
| <AdditionalDependencies Condition="'$(Platform)'=='Win32' Or '$(Platform)'=='x64'">kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;$(SdlDeps);$(FfmpegDeps);$(AssimpDeps);$(LibGccDeps);$(GdiDeps);$(XinputDeps);$(GlDeps);%(AdditionalDependencies)</AdditionalDependencies> | |||||
| <AdditionalDependencies>%(AdditionalDependencies)</AdditionalDependencies> | <AdditionalDependencies>%(AdditionalDependencies)</AdditionalDependencies> | ||||
| <AdditionalLibraryDirectories Condition="'$(Platform)'=='Win32' Or '$(Platform)'=='x64'">$(LibGccLibs);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories> | <AdditionalLibraryDirectories Condition="'$(Platform)'=='Win32' Or '$(Platform)'=='x64'">$(LibGccLibs);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories> | ||||
| <AdditionalLibraryDirectories Condition="'$(Platform)'=='Win32' Or '$(Platform)'=='x64'">$(SdlLibs);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories> | <AdditionalLibraryDirectories Condition="'$(Platform)'=='Win32' Or '$(Platform)'=='x64'">$(SdlLibs);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories> | ||||
| <AdditionalLibraryDirectories Condition="'$(Platform)'=='Win32' Or '$(Platform)'=='x64'">$(FfmpegLibs);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories> | <AdditionalLibraryDirectories Condition="'$(Platform)'=='Win32' Or '$(Platform)'=='x64'">$(FfmpegLibs);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories> | ||||
| <AdditionalLibraryDirectories Condition="'$(Platform)'=='Win32' Or '$(Platform)'=='x64'">$(AssimpLibs);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories> | <AdditionalLibraryDirectories Condition="'$(Platform)'=='Win32' Or '$(Platform)'=='x64'">$(AssimpLibs);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories> | ||||
| <AdditionalLibraryDirectories Condition="'$(Platform)'=='Win32' Or '$(Platform)'=='x64'">$(GlLibs);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories> | <AdditionalLibraryDirectories Condition="'$(Platform)'=='Win32' Or '$(Platform)'=='x64'">$(GlLibs);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories> | ||||
| <AdditionalLibraryDirectories Condition="'$(Platform)'=='Win32' Or '$(Platform)'=='x64'">$(D3d9Libs);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories> | |||||
| <AdditionalLibraryDirectories Condition="'$(Platform)'=='Win32' Or '$(Platform)'=='x64'">$(XinputLibs);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories> | <AdditionalLibraryDirectories Condition="'$(Platform)'=='Win32' Or '$(Platform)'=='x64'">$(XinputLibs);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories> | ||||
| <AdditionalLibraryDirectories>%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories> | <AdditionalLibraryDirectories>%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories> | ||||
| <AdditionalLibraryDirectories Condition="'$(Platform)'=='Orbis'">$(OrbisLibs);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories> | <AdditionalLibraryDirectories Condition="'$(Platform)'=='Orbis'">$(OrbisLibs);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories> | ||||
| @@ -76,15 +76,7 @@ | |||||
| <GlLibs Condition="'$(Platform)'=='x64'">$(GlewDir)\lib\x86_64-w64-mingw32</GlLibs> | <GlLibs Condition="'$(Platform)'=='x64'">$(GlewDir)\lib\x86_64-w64-mingw32</GlLibs> | ||||
| <GlDeps Condition="'$(Platform)'=='Win32'">opengl32.lib;glew32s.lib</GlDeps> | <GlDeps Condition="'$(Platform)'=='Win32'">opengl32.lib;glew32s.lib</GlDeps> | ||||
| <GlDeps Condition="'$(Platform)'=='x64'">opengl32.lib;glew32s.lib</GlDeps> | <GlDeps Condition="'$(Platform)'=='x64'">opengl32.lib;glew32s.lib</GlDeps> | ||||
| <Win32Defines Condition="'$(UseOpenGL)'=='true'">HAVE_GL_2X;USE_GLEW;GLEW_STATIC;$(Win32Defines)</Win32Defines> | |||||
| <!-- Direct3D 9 --> | |||||
| <D3d9Includes>$(DXSDK_DIR)\Include</D3d9Includes> | |||||
| <D3d9Libs Condition="'$(Platform)'=='Win32'">$(DXSDK_DIR)\Lib\x86</D3d9Libs> | |||||
| <D3d9Libs Condition="'$(Platform)'=='x64'">$(DXSDK_DIR)\Lib\x64</D3d9Libs> | |||||
| <D3d9Deps Condition="'$(Configuration)'=='Release'">d3d9.lib;d3dx9.lib</D3d9Deps> | |||||
| <D3d9Deps Condition="'$(Configuration)'=='Debug'">d3d9.lib;d3dx9d.lib</D3d9Deps> | |||||
| <Win32Defines Condition="'$(UseOpenGL)'=='false'">USE_D3D9;$(Win32Defines)</Win32Defines> | |||||
| <Win32Defines>HAVE_GL_2X;USE_GLEW;GLEW_STATIC;$(Win32Defines)</Win32Defines> | |||||
| <!-- Xinput --> | <!-- Xinput --> | ||||
| <XinputIncludes>$(DXSDK_DIR)\Include</XinputIncludes> | <XinputIncludes>$(DXSDK_DIR)\Include</XinputIncludes> | ||||
| @@ -144,9 +136,6 @@ | |||||
| <BuildMacro Include="GlIncludes"><Value>$(GlIncludes)</Value></BuildMacro> | <BuildMacro Include="GlIncludes"><Value>$(GlIncludes)</Value></BuildMacro> | ||||
| <BuildMacro Include="GlLibs"><Value>$(GlLibs)</Value></BuildMacro> | <BuildMacro Include="GlLibs"><Value>$(GlLibs)</Value></BuildMacro> | ||||
| <BuildMacro Include="GlDeps"><Value>$(GlDeps)</Value></BuildMacro> | <BuildMacro Include="GlDeps"><Value>$(GlDeps)</Value></BuildMacro> | ||||
| <BuildMacro Include="D3d9Includes"><Value>$(D3d9Includes)</Value></BuildMacro> | |||||
| <BuildMacro Include="D3d9Libs"><Value>$(D3d9Libs)</Value></BuildMacro> | |||||
| <BuildMacro Include="D3d9Deps"><Value>$(D3d9Deps)</Value></BuildMacro> | |||||
| <BuildMacro Include="XinputIncludes"><Value>$(XinputIncludes)</Value></BuildMacro> | <BuildMacro Include="XinputIncludes"><Value>$(XinputIncludes)</Value></BuildMacro> | ||||
| <BuildMacro Include="XinputLibs"><Value>$(XinputLibs)</Value></BuildMacro> | <BuildMacro Include="XinputLibs"><Value>$(XinputLibs)</Value></BuildMacro> | ||||
| <BuildMacro Include="XinputDeps"><Value>$(XinputDeps)</Value></BuildMacro> | <BuildMacro Include="XinputDeps"><Value>$(XinputDeps)</Value></BuildMacro> | ||||
| @@ -273,16 +273,6 @@ LOL_TRY_LDFLAGS(-framework CoreData, | |||||
| LOL_TRY_LDFLAGS(-framework UIKit, | LOL_TRY_LDFLAGS(-framework UIKit, | ||||
| [LOL_LIBS="${LOL_LIBS} -framework UIKit"]) | [LOL_LIBS="${LOL_LIBS} -framework UIKit"]) | ||||
| dnl Are we on a Direct3D 9 platform? | |||||
| #ac_cv_my_have_d3d9="no" | |||||
| #AC_CHECK_HEADERS(d3d9.h, [ac_cv_my_have_d3d9="yes"]) | |||||
| #if test "${ac_cv_my_have_d3d9}" != "no"; then | |||||
| # D3D_LIBS="${D3D_LIBS} -ld3d9 -ld3dx9 -lxinput" | |||||
| # AC_DEFINE(USE_D3D9, 1, Define to 1 to use DirectX 9) | |||||
| #fi | |||||
| #AM_CONDITIONAL(USE_D3D9, test "${ac_cv_my_have_d3d9}" != "no") | |||||
| LOL_CHECK_OPENGL | LOL_CHECK_OPENGL | ||||
| LOL_CHECK_SDL | LOL_CHECK_SDL | ||||
| @@ -12,12 +12,6 @@ | |||||
| #include "lolgl.h" | #include "lolgl.h" | ||||
| #if defined _WIN32 && defined USE_D3D9 | |||||
| # define FAR | |||||
| # define NEAR | |||||
| # include <d3d9.h> | |||||
| #endif | |||||
| namespace lol | namespace lol | ||||
| { | { | ||||
| @@ -34,13 +28,7 @@ class FramebufferData | |||||
| ivec2 m_size; | ivec2 m_size; | ||||
| bool m_bound; | bool m_bound; | ||||
| #if defined USE_D3D9 | |||||
| IDirect3DDevice9 *m_dev; | |||||
| IDirect3DTexture9 *m_texture; | |||||
| IDirect3DSurface9 *m_surface, *m_back_surface; | |||||
| #else | |||||
| GLuint m_fbo, m_texture, m_depth; | GLuint m_fbo, m_texture, m_depth; | ||||
| #endif | |||||
| }; | }; | ||||
| // | // | ||||
| @@ -52,26 +40,7 @@ uint32_t FramebufferFormat::GetFormat() | |||||
| { | { | ||||
| switch (m_format) | switch (m_format) | ||||
| { | { | ||||
| #if defined USE_D3D9 | |||||
| case R_16_F: return D3DFMT_R16F; | |||||
| case R_32_F: return D3DFMT_R32F; | |||||
| case RG_16: | |||||
| case RG_16_I: | |||||
| case RG_16_UI: return D3DFMT_G16R16; | |||||
| case RG_16_F: return D3DFMT_G16R16F; | |||||
| case RG_32_F: return D3DFMT_G32R32F; | |||||
| case RGB_8: | |||||
| case RGB_8_I: | |||||
| case RGB_8_UI: return D3DFMT_R8G8B8; | |||||
| case RGBA_8: | |||||
| case RGBA_8_I: | |||||
| case RGBA_8_UI: return D3DFMT_A8R8G8B8; | |||||
| case RGBA_16: | |||||
| case RGBA_16_I: | |||||
| case RGBA_16_UI: return D3DFMT_A16B16G16R16; | |||||
| case RGBA_16_F: return D3DFMT_A16B16G16R16F; | |||||
| case RGBA_32_F: return D3DFMT_A32B32G32R32F; | |||||
| #elif defined HAVE_GLES_2X | |||||
| #if defined HAVE_GLES_2X | |||||
| /* FIXME: incomplete */ | /* FIXME: incomplete */ | ||||
| case RGBA_8: | case RGBA_8: | ||||
| case RGBA_8_I: | case RGBA_8_I: | ||||
| @@ -203,9 +172,7 @@ uint32_t FramebufferFormat::GetFormatOrder() | |||||
| { | { | ||||
| switch (m_format) | switch (m_format) | ||||
| { | { | ||||
| #if defined USE_D3D9 | |||||
| /* FIXME: not implemented at all */ | |||||
| #elif defined HAVE_GLES_2X | |||||
| #if defined HAVE_GLES_2X | |||||
| /* FIXME: incomplete */ | /* FIXME: incomplete */ | ||||
| case R_8: case RG_8: case RGB_8: case RGBA_8: | case R_8: case RG_8: case RGB_8: case RGBA_8: | ||||
| case R_8_I: case RG_8_I: case RGB_8_I: case RGBA_8_I: | case R_8_I: case RG_8_I: case RGB_8_I: case RGBA_8_I: | ||||
| @@ -276,42 +243,30 @@ Framebuffer::Framebuffer(ivec2 size, FramebufferFormat fbo_format) | |||||
| { | { | ||||
| m_data->m_size = size; | m_data->m_size = size; | ||||
| m_data->m_bound = false; | m_data->m_bound = false; | ||||
| #if defined USE_D3D9 | |||||
| m_data->m_dev = (IDirect3DDevice9 *)Renderer::Get()->GetDevice(); | |||||
| if (FAILED(m_data->m_dev->CreateTexture(size.x, size.y, 1, | |||||
| D3DUSAGE_RENDERTARGET, | |||||
| (D3DFORMAT)fbo_format.GetFormat(), | |||||
| D3DPOOL_DEFAULT, | |||||
| &m_data->m_texture, nullptr))) | |||||
| Abort(); | |||||
| if (FAILED(m_data->m_texture->GetSurfaceLevel(0, &m_data->m_surface))) | |||||
| Abort(); | |||||
| #else | |||||
| # if GL_VERSION_1_1 | |||||
| #if GL_VERSION_1_1 | |||||
| GLenum internal_format = fbo_format.GetFormat(); | GLenum internal_format = fbo_format.GetFormat(); | ||||
| GLenum format = fbo_format.GetFormatOrder(); | GLenum format = fbo_format.GetFormatOrder(); | ||||
| GLenum depth = GL_DEPTH_COMPONENT; | GLenum depth = GL_DEPTH_COMPONENT; | ||||
| # elif GL_ES_VERSION_2_0 | |||||
| #elif GL_ES_VERSION_2_0 | |||||
| /* In OpenGL ES, internal format and format must match. */ | /* In OpenGL ES, internal format and format must match. */ | ||||
| GLenum internal_format = fbo_format.GetFormat(); | GLenum internal_format = fbo_format.GetFormat(); | ||||
| GLenum format = fbo_format.GetFormat(); | GLenum format = fbo_format.GetFormat(); | ||||
| GLenum depth = GL_DEPTH_COMPONENT16; /* for WebGL */ | GLenum depth = GL_DEPTH_COMPONENT16; /* for WebGL */ | ||||
| # else | |||||
| #else | |||||
| /* In OpenGL ES, internal format and format must match. */ | /* In OpenGL ES, internal format and format must match. */ | ||||
| GLenum internal_format = fbo_format.GetFormat(); | GLenum internal_format = fbo_format.GetFormat(); | ||||
| GLenum format = fbo_format.GetFormat(); | GLenum format = fbo_format.GetFormat(); | ||||
| # endif | |||||
| #endif | |||||
| GLenum wrapmode = GL_CLAMP_TO_EDGE; | GLenum wrapmode = GL_CLAMP_TO_EDGE; | ||||
| GLenum filtering = GL_LINEAR; | GLenum filtering = GL_LINEAR; | ||||
| # if GL_VERSION_1_1 || GL_ES_VERSION_2_0 | |||||
| #if GL_VERSION_1_1 || GL_ES_VERSION_2_0 | |||||
| glGenFramebuffers(1, &m_data->m_fbo); | glGenFramebuffers(1, &m_data->m_fbo); | ||||
| glBindFramebuffer(GL_FRAMEBUFFER, m_data->m_fbo); | glBindFramebuffer(GL_FRAMEBUFFER, m_data->m_fbo); | ||||
| # else | |||||
| #else | |||||
| glGenFramebuffersOES(1, &m_data->m_fbo); | glGenFramebuffersOES(1, &m_data->m_fbo); | ||||
| glBindFramebufferOES(GL_FRAMEBUFFER_OES, m_data->m_fbo); | glBindFramebufferOES(GL_FRAMEBUFFER_OES, m_data->m_fbo); | ||||
| # endif | |||||
| #endif | |||||
| glGenTextures(1, &m_data->m_texture); | glGenTextures(1, &m_data->m_texture); | ||||
| glActiveTexture(GL_TEXTURE0); | glActiveTexture(GL_TEXTURE0); | ||||
| @@ -323,16 +278,16 @@ Framebuffer::Framebuffer(ivec2 size, FramebufferFormat fbo_format) | |||||
| glTexImage2D(GL_TEXTURE_2D, 0, internal_format, size.x, size.y, 0, | glTexImage2D(GL_TEXTURE_2D, 0, internal_format, size.x, size.y, 0, | ||||
| format, GL_UNSIGNED_BYTE, nullptr); | format, GL_UNSIGNED_BYTE, nullptr); | ||||
| # if GL_VERSION_1_1 || GL_ES_VERSION_2_0 | |||||
| #if GL_VERSION_1_1 || GL_ES_VERSION_2_0 | |||||
| glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, | ||||
| GL_TEXTURE_2D, m_data->m_texture, 0); | GL_TEXTURE_2D, m_data->m_texture, 0); | ||||
| # else | |||||
| #else | |||||
| glFramebufferTexture2DOES(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_EXT, | glFramebufferTexture2DOES(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_EXT, | ||||
| GL_TEXTURE_2D, m_data->m_texture, 0); | GL_TEXTURE_2D, m_data->m_texture, 0); | ||||
| # endif | |||||
| #endif | |||||
| m_data->m_depth = GL_INVALID_ENUM; | m_data->m_depth = GL_INVALID_ENUM; | ||||
| # if GL_VERSION_1_1 || GL_ES_VERSION_2_0 | |||||
| #if GL_VERSION_1_1 || GL_ES_VERSION_2_0 | |||||
| if (depth != GL_INVALID_ENUM) | if (depth != GL_INVALID_ENUM) | ||||
| { | { | ||||
| /* XXX: might not work on GL ES, see | /* XXX: might not work on GL ES, see | ||||
| @@ -344,40 +299,34 @@ Framebuffer::Framebuffer(ivec2 size, FramebufferFormat fbo_format) | |||||
| glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, | glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, | ||||
| GL_RENDERBUFFER, m_data->m_depth); | GL_RENDERBUFFER, m_data->m_depth); | ||||
| } | } | ||||
| # endif | |||||
| #endif | |||||
| glBindTexture(GL_TEXTURE_2D, 0); | glBindTexture(GL_TEXTURE_2D, 0); | ||||
| # if GL_VERSION_1_1 || GL_ES_VERSION_2_0 | |||||
| #if GL_VERSION_1_1 || GL_ES_VERSION_2_0 | |||||
| GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER); | GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER); | ||||
| ASSERT(status == GL_FRAMEBUFFER_COMPLETE, | ASSERT(status == GL_FRAMEBUFFER_COMPLETE, | ||||
| "invalid framebuffer status 0x%x", status); | "invalid framebuffer status 0x%x", status); | ||||
| # endif | |||||
| #endif | |||||
| # if GL_VERSION_1_1 || GL_ES_VERSION_2_0 | |||||
| #if GL_VERSION_1_1 || GL_ES_VERSION_2_0 | |||||
| glBindFramebuffer(GL_FRAMEBUFFER, 0); | glBindFramebuffer(GL_FRAMEBUFFER, 0); | ||||
| # else | |||||
| #else | |||||
| glBindFramebufferOES(GL_FRAMEBUFFER_OES, 0); | glBindFramebufferOES(GL_FRAMEBUFFER_OES, 0); | ||||
| # endif | |||||
| #endif | #endif | ||||
| } | } | ||||
| Framebuffer::~Framebuffer() | Framebuffer::~Framebuffer() | ||||
| { | { | ||||
| #if defined USE_D3D9 | |||||
| m_data->m_surface->Release(); | |||||
| m_data->m_texture->Release(); | |||||
| #else | |||||
| # if GL_VERSION_1_1 || GL_ES_VERSION_2_0 | |||||
| #if GL_VERSION_1_1 || GL_ES_VERSION_2_0 | |||||
| glDeleteFramebuffers(1, &m_data->m_fbo); | glDeleteFramebuffers(1, &m_data->m_fbo); | ||||
| # else | |||||
| #else | |||||
| glDeleteFramebuffersOES(1, &m_data->m_fbo); | glDeleteFramebuffersOES(1, &m_data->m_fbo); | ||||
| # endif | |||||
| #endif | |||||
| glDeleteTextures(1, &m_data->m_texture); | glDeleteTextures(1, &m_data->m_texture); | ||||
| # if GL_VERSION_1_1 || GL_ES_VERSION_2_0 | |||||
| #if GL_VERSION_1_1 || GL_ES_VERSION_2_0 | |||||
| if (m_data->m_depth != GL_INVALID_ENUM) | if (m_data->m_depth != GL_INVALID_ENUM) | ||||
| glDeleteRenderbuffers(1, &m_data->m_depth); | glDeleteRenderbuffers(1, &m_data->m_depth); | ||||
| # endif | |||||
| #endif | #endif | ||||
| delete m_data; | delete m_data; | ||||
| } | } | ||||
| @@ -385,11 +334,7 @@ Framebuffer::~Framebuffer() | |||||
| TextureUniform Framebuffer::GetTextureUniform() const | TextureUniform Framebuffer::GetTextureUniform() const | ||||
| { | { | ||||
| TextureUniform ret; | TextureUniform ret; | ||||
| #if defined USE_D3D9 | |||||
| ret.m_flags = (uint64_t)(uintptr_t)m_data->m_texture; | |||||
| #else | |||||
| ret.m_flags = m_data->m_texture; | ret.m_flags = m_data->m_texture; | ||||
| #endif | |||||
| return ret; | return ret; | ||||
| } | } | ||||
| @@ -402,14 +347,10 @@ Image Framebuffer::GetImage() const | |||||
| { | { | ||||
| Image ret(m_data->m_size); | Image ret(m_data->m_size); | ||||
| #if defined USE_D3D9 | |||||
| /* TODO: implement D3D Framebuffer::GetImage() */ | |||||
| #else | |||||
| u8vec4 *buffer = ret.Lock<PixelFormat::RGBA_8>(); | u8vec4 *buffer = ret.Lock<PixelFormat::RGBA_8>(); | ||||
| glReadPixels(0, 0, m_data->m_size.x, m_data->m_size.y, | glReadPixels(0, 0, m_data->m_size.x, m_data->m_size.y, | ||||
| GL_RGBA, GL_UNSIGNED_BYTE, buffer); | GL_RGBA, GL_UNSIGNED_BYTE, buffer); | ||||
| ret.Unlock(buffer); | ret.Unlock(buffer); | ||||
| #endif | |||||
| return ret; | return ret; | ||||
| } | } | ||||
| @@ -418,17 +359,10 @@ void Framebuffer::Bind() | |||||
| { | { | ||||
| ASSERT(!m_data->m_bound, "trying to bind an already bound framebuffer"); | ASSERT(!m_data->m_bound, "trying to bind an already bound framebuffer"); | ||||
| #if defined USE_D3D9 | |||||
| if (FAILED(m_data->m_dev->GetRenderTarget(0, &m_data->m_back_surface))) | |||||
| Abort(); | |||||
| if (FAILED(m_data->m_dev->SetRenderTarget(0, m_data->m_surface))) | |||||
| Abort(); | |||||
| #else | |||||
| # if GL_VERSION_1_1 || GL_ES_VERSION_2_0 | |||||
| #if GL_VERSION_1_1 || GL_ES_VERSION_2_0 | |||||
| glBindFramebuffer(GL_FRAMEBUFFER, m_data->m_fbo); | glBindFramebuffer(GL_FRAMEBUFFER, m_data->m_fbo); | ||||
| # else | |||||
| #else | |||||
| glBindFramebufferOES(GL_FRAMEBUFFER_OES, m_data->m_fbo); | glBindFramebufferOES(GL_FRAMEBUFFER_OES, m_data->m_fbo); | ||||
| # endif | |||||
| #endif | #endif | ||||
| /* FIXME: this should be done in the RenderContext object | /* FIXME: this should be done in the RenderContext object | ||||
| @@ -443,16 +377,10 @@ void Framebuffer::Unbind() | |||||
| { | { | ||||
| ASSERT(m_data->m_bound, "trying to unbind an unbound framebuffer"); | ASSERT(m_data->m_bound, "trying to unbind an unbound framebuffer"); | ||||
| #if defined USE_D3D9 | |||||
| if (FAILED(m_data->m_dev->SetRenderTarget(0, m_data->m_back_surface))) | |||||
| Abort(); | |||||
| m_data->m_back_surface->Release(); | |||||
| #else | |||||
| # if GL_VERSION_1_1 || GL_ES_VERSION_2_0 | |||||
| #if GL_VERSION_1_1 || GL_ES_VERSION_2_0 | |||||
| glBindFramebuffer(GL_FRAMEBUFFER, 0); | glBindFramebuffer(GL_FRAMEBUFFER, 0); | ||||
| # else | |||||
| #else | |||||
| glBindFramebufferOES(GL_FRAMEBUFFER_OES, 0); | glBindFramebufferOES(GL_FRAMEBUFFER_OES, 0); | ||||
| # endif | |||||
| #endif | #endif | ||||
| Renderer::Get()->SetViewport(m_data->m_saved_viewport); | Renderer::Get()->SetViewport(m_data->m_saved_viewport); | ||||
| @@ -12,12 +12,6 @@ | |||||
| #include "lolgl.h" | #include "lolgl.h" | ||||
| #if defined _WIN32 && defined USE_D3D9 | |||||
| # define FAR | |||||
| # define NEAR | |||||
| # include <d3d9.h> | |||||
| #endif | |||||
| namespace lol | namespace lol | ||||
| { | { | ||||
| @@ -31,14 +25,8 @@ class IndexBufferData | |||||
| friend class IndexBuffer; | friend class IndexBuffer; | ||||
| size_t m_size; | size_t m_size; | ||||
| #if defined USE_D3D9 | |||||
| IDirect3DDevice9 *m_dev; | |||||
| IDirect3DIndexBuffer9 *m_ibo; | |||||
| #else | |||||
| GLuint m_ibo; | GLuint m_ibo; | ||||
| uint8_t *m_memory; | uint8_t *m_memory; | ||||
| #endif | |||||
| }; | }; | ||||
| // | // | ||||
| @@ -52,29 +40,16 @@ IndexBuffer::IndexBuffer(size_t size) | |||||
| m_data->m_size = size; | m_data->m_size = size; | ||||
| if (!size) | if (!size) | ||||
| return; | return; | ||||
| #if defined USE_D3D9 | |||||
| m_data->m_dev = (IDirect3DDevice9 *)Renderer::Get()->GetDevice(); | |||||
| if (FAILED(m_data->m_dev->CreateIndexBuffer(size, D3DUSAGE_WRITEONLY, | |||||
| D3DFMT_INDEX16, D3DPOOL_MANAGED, | |||||
| &m_data->m_ibo, nullptr))) | |||||
| Abort(); | |||||
| #else | |||||
| glGenBuffers(1, &m_data->m_ibo); | glGenBuffers(1, &m_data->m_ibo); | ||||
| m_data->m_memory = new uint8_t[size]; | m_data->m_memory = new uint8_t[size]; | ||||
| #endif | |||||
| } | } | ||||
| IndexBuffer::~IndexBuffer() | IndexBuffer::~IndexBuffer() | ||||
| { | { | ||||
| if (m_data->m_size) | if (m_data->m_size) | ||||
| { | { | ||||
| #if defined USE_D3D9 | |||||
| if (FAILED(m_data->m_ibo->Release())) | |||||
| Abort(); | |||||
| #else | |||||
| glDeleteBuffers(1, &m_data->m_ibo); | glDeleteBuffers(1, &m_data->m_ibo); | ||||
| delete[] m_data->m_memory; | delete[] m_data->m_memory; | ||||
| #endif | |||||
| } | } | ||||
| delete m_data; | delete m_data; | ||||
| } | } | ||||
| @@ -89,15 +64,8 @@ void *IndexBuffer::Lock(size_t offset, size_t size) | |||||
| if (!m_data->m_size) | if (!m_data->m_size) | ||||
| return nullptr; | return nullptr; | ||||
| #if defined USE_D3D9 | |||||
| void *ret; | |||||
| if (FAILED(m_data->m_ibo->Lock(offset, size, (void **)&ret, 0))) | |||||
| Abort(); | |||||
| return ret; | |||||
| #else | |||||
| UNUSED(size); | UNUSED(size); | ||||
| return m_data->m_memory + offset; | return m_data->m_memory + offset; | ||||
| #endif | |||||
| } | } | ||||
| void IndexBuffer::Unlock() | void IndexBuffer::Unlock() | ||||
| @@ -105,14 +73,9 @@ void IndexBuffer::Unlock() | |||||
| if (!m_data->m_size) | if (!m_data->m_size) | ||||
| return; | return; | ||||
| #if defined USE_D3D9 | |||||
| if (FAILED(m_data->m_ibo->Unlock())) | |||||
| Abort(); | |||||
| #else | |||||
| glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_data->m_ibo); | glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_data->m_ibo); | ||||
| glBufferData(GL_ELEMENT_ARRAY_BUFFER, m_data->m_size, m_data->m_memory, | glBufferData(GL_ELEMENT_ARRAY_BUFFER, m_data->m_size, m_data->m_memory, | ||||
| GL_STATIC_DRAW); | GL_STATIC_DRAW); | ||||
| #endif | |||||
| } | } | ||||
| void IndexBuffer::Bind() | void IndexBuffer::Bind() | ||||
| @@ -120,15 +83,10 @@ void IndexBuffer::Bind() | |||||
| if (!m_data->m_size) | if (!m_data->m_size) | ||||
| return; | return; | ||||
| #if defined USE_D3D9 | |||||
| if (FAILED(m_data->m_dev->SetIndices(m_data->m_ibo))) | |||||
| Abort(); | |||||
| #else | |||||
| glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_data->m_ibo); | glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_data->m_ibo); | ||||
| /* XXX: not necessary because we kept track of the size */ | /* XXX: not necessary because we kept track of the size */ | ||||
| //int size; | //int size; | ||||
| //glGetBufferParameteriv(GL_ELEMENT_ARRAY_BUFFER, GL_BUFFER_SIZE, &size); | //glGetBufferParameteriv(GL_ELEMENT_ARRAY_BUFFER, GL_BUFFER_SIZE, &size); | ||||
| #endif | |||||
| } | } | ||||
| void IndexBuffer::Unbind() | void IndexBuffer::Unbind() | ||||
| @@ -136,12 +94,7 @@ void IndexBuffer::Unbind() | |||||
| if (!m_data->m_size) | if (!m_data->m_size) | ||||
| return; | return; | ||||
| #if defined USE_D3D9 | |||||
| if (FAILED(m_data->m_dev->SetIndices(nullptr))) | |||||
| Abort(); | |||||
| #else | |||||
| glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); | glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); | ||||
| #endif | |||||
| } | } | ||||
| } /* namespace lol */ | } /* namespace lol */ | ||||
| @@ -15,9 +15,6 @@ | |||||
| #include <cstdlib> | #include <cstdlib> | ||||
| #if defined _WIN32 | #if defined _WIN32 | ||||
| # if defined USE_D3D9 | |||||
| # include <d3d9.h> | |||||
| # endif | |||||
| # define WIN32_LEAN_AND_MEAN 1 | # define WIN32_LEAN_AND_MEAN 1 | ||||
| # include <windows.h> | # include <windows.h> | ||||
| # undef WIN32_LEAN_AND_MEAN | # undef WIN32_LEAN_AND_MEAN | ||||
| @@ -27,11 +24,6 @@ | |||||
| #include "lolgl.h" | #include "lolgl.h" | ||||
| /* FIXME: find a way to pass g_hwnd from the windowing system */ | |||||
| #if defined USE_D3D9 | |||||
| extern HWND g_hwnd; | |||||
| #endif | |||||
| namespace lol | namespace lol | ||||
| { | { | ||||
| @@ -62,12 +54,6 @@ private: | |||||
| DepthMask m_depth_mask; | DepthMask m_depth_mask; | ||||
| CullMode m_cull_mode; | CullMode m_cull_mode; | ||||
| PolygonMode m_polygon_mode; | PolygonMode m_polygon_mode; | ||||
| private: | |||||
| #if defined USE_D3D9 | |||||
| IDirect3D9 *m_d3d_ctx; | |||||
| IDirect3DDevice9 *m_d3d_dev; | |||||
| #endif | |||||
| }; | }; | ||||
| /* | /* | ||||
| @@ -77,42 +63,7 @@ private: | |||||
| Renderer::Renderer(ivec2 size) | Renderer::Renderer(ivec2 size) | ||||
| : m_data(new RendererData()) | : m_data(new RendererData()) | ||||
| { | { | ||||
| #if defined USE_D3D9 | |||||
| /* Create Direct3D context */ | |||||
| m_data->m_d3d_ctx = Direct3DCreate9(D3D_SDK_VERSION); | |||||
| if (!m_data->m_d3d_ctx) | |||||
| { | |||||
| msg::error("cannot initialise D3D\n"); | |||||
| exit(EXIT_FAILURE); | |||||
| } | |||||
| /* Create Direct3D device */ | |||||
| D3DPRESENT_PARAMETERS d3dpp; | |||||
| memset(&d3dpp, 0, sizeof(d3dpp)); | |||||
| d3dpp.BackBufferWidth = size.x; | |||||
| d3dpp.BackBufferHeight = size.y; | |||||
| d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8; | |||||
| d3dpp.BackBufferCount = 1; | |||||
| d3dpp.hDeviceWindow = g_hwnd; | |||||
| # if USE_SDL || USE_OLD_SDL | |||||
| d3dpp.Windowed = TRUE; | |||||
| # endif | |||||
| d3dpp.EnableAutoDepthStencil = TRUE; | |||||
| d3dpp.AutoDepthStencilFormat = D3DFMT_D24S8; | |||||
| d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; | |||||
| d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_ONE; | |||||
| HRESULT hr = m_data->m_d3d_ctx->CreateDevice(0, D3DDEVTYPE_HAL, g_hwnd, | |||||
| D3DCREATE_HARDWARE_VERTEXPROCESSING, | |||||
| &d3dpp, &m_data->m_d3d_dev); | |||||
| if (FAILED(hr)) | |||||
| { | |||||
| msg::error("cannot create D3D device\n"); | |||||
| exit(EXIT_FAILURE); | |||||
| } | |||||
| #else | |||||
| # if defined USE_GLEW && !defined __APPLE__ | |||||
| #if defined USE_GLEW && !defined __APPLE__ | |||||
| /* Initialise GLEW if necessary */ | /* Initialise GLEW if necessary */ | ||||
| GLenum glerr = glewInit(); | GLenum glerr = glewInit(); | ||||
| if (glerr != GLEW_OK) | if (glerr != GLEW_OK) | ||||
| @@ -120,7 +71,6 @@ Renderer::Renderer(ivec2 size) | |||||
| msg::error("cannot initialise GLEW: %s\n", glewGetErrorString(glerr)); | msg::error("cannot initialise GLEW: %s\n", glewGetErrorString(glerr)); | ||||
| exit(EXIT_FAILURE); | exit(EXIT_FAILURE); | ||||
| } | } | ||||
| # endif | |||||
| #endif | #endif | ||||
| /* Initialise rendering states */ | /* Initialise rendering states */ | ||||
| @@ -158,12 +108,8 @@ Renderer::Renderer(ivec2 size) | |||||
| SetPolygonMode(PolygonMode::Fill); | SetPolygonMode(PolygonMode::Fill); | ||||
| /* Add some rendering states that we don't export to the user */ | /* Add some rendering states that we don't export to the user */ | ||||
| #if defined USE_D3D9 | |||||
| /* TODO */ | |||||
| #else | |||||
| # if defined HAVE_GL_2X && !defined __APPLE__ | |||||
| #if defined HAVE_GL_2X && !defined __APPLE__ | |||||
| glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); | glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); | ||||
| # endif | |||||
| #endif | #endif | ||||
| } | } | ||||
| @@ -172,37 +118,12 @@ Renderer::~Renderer() | |||||
| delete m_data; | delete m_data; | ||||
| } | } | ||||
| void *Renderer::GetDevice() | |||||
| { | |||||
| #if defined USE_D3D9 | |||||
| return m_data->m_d3d_dev; | |||||
| #else | |||||
| return nullptr; | |||||
| #endif | |||||
| } | |||||
| /* | /* | ||||
| * Buffer clearing | * Buffer clearing | ||||
| */ | */ | ||||
| void Renderer::Clear(ClearMask mask) | void Renderer::Clear(ClearMask mask) | ||||
| { | { | ||||
| #if defined USE_D3D9 | |||||
| int m = 0; | |||||
| if (mask & ClearMask::Color) | |||||
| m |= D3DCLEAR_TARGET; | |||||
| if (mask & ClearMask::Depth) | |||||
| m |= D3DCLEAR_ZBUFFER; | |||||
| if (mask & ClearMask::Stencil) | |||||
| m |= D3DCLEAR_STENCIL; | |||||
| vec3 tmp = 255.999f * GetClearColor().rgb; | |||||
| D3DCOLOR clear_color = D3DCOLOR_XRGB((int)tmp.r, (int)tmp.g, (int)tmp.b); | |||||
| if (FAILED(m_data->m_d3d_dev->Clear(0, nullptr, m, clear_color, | |||||
| GetClearDepth(), 0))) | |||||
| Abort(); | |||||
| #else | |||||
| GLbitfield m = 0; | GLbitfield m = 0; | ||||
| if (mask & ClearMask::Color) | if (mask & ClearMask::Color) | ||||
| m |= GL_COLOR_BUFFER_BIT; | m |= GL_COLOR_BUFFER_BIT; | ||||
| @@ -211,7 +132,6 @@ void Renderer::Clear(ClearMask mask) | |||||
| if (mask & ClearMask::Stencil) | if (mask & ClearMask::Stencil) | ||||
| m |= GL_STENCIL_BUFFER_BIT; | m |= GL_STENCIL_BUFFER_BIT; | ||||
| glClear(m); | glClear(m); | ||||
| #endif | |||||
| } | } | ||||
| /* | /* | ||||
| @@ -249,14 +169,7 @@ void Renderer::SetViewport(ibox2 viewport) | |||||
| if (m_data->m_viewport == viewport) | if (m_data->m_viewport == viewport) | ||||
| return; | return; | ||||
| #if defined USE_D3D9 | |||||
| D3DVIEWPORT9 vp = { viewport.aa.x, viewport.aa.y, | |||||
| viewport.bb.x, viewport.bb.y, | |||||
| 0.0f, 1.0f }; | |||||
| m_data->m_d3d_dev->SetViewport(&vp); | |||||
| #else | |||||
| glViewport(viewport.aa.x, viewport.aa.y, viewport.bb.x, viewport.bb.y); | glViewport(viewport.aa.x, viewport.aa.y, viewport.bb.x, viewport.bb.y); | ||||
| #endif | |||||
| m_data->m_viewport = viewport; | m_data->m_viewport = viewport; | ||||
| } | } | ||||
| @@ -287,11 +200,7 @@ void Renderer::SetClearColor(vec4 color) | |||||
| if (m_data->m_clear_color == color) | if (m_data->m_clear_color == color) | ||||
| return; | return; | ||||
| #if defined USE_D3D9 | |||||
| /* Nothing to do */ | |||||
| #else | |||||
| glClearColor(color.r, color.g, color.b, color.a); | glClearColor(color.r, color.g, color.b, color.a); | ||||
| #endif | |||||
| m_data->m_clear_color = color; | m_data->m_clear_color = color; | ||||
| } | } | ||||
| @@ -310,9 +219,7 @@ void Renderer::SetClearDepth(float depth) | |||||
| if (m_data->m_clear_depth == depth) | if (m_data->m_clear_depth == depth) | ||||
| return; | return; | ||||
| #if defined USE_D3D9 | |||||
| /* Nothing to do */ | |||||
| #elif defined HAVE_GLES_2X | |||||
| #if defined HAVE_GLES_2X | |||||
| glClearDepthf(depth); | glClearDepthf(depth); | ||||
| #else | #else | ||||
| glClearDepth(depth); | glClearDepth(depth); | ||||
| @@ -335,48 +242,7 @@ void Renderer::SetAlphaFunc(AlphaFunc func, float alpha) | |||||
| if (m_data->m_alpha_func == func && m_data->m_alpha_value == alpha) | if (m_data->m_alpha_func == func && m_data->m_alpha_value == alpha) | ||||
| return; | return; | ||||
| #if defined USE_D3D9 | |||||
| switch (func) | |||||
| { | |||||
| case AlphaFunc::Disabled: | |||||
| break; /* Nothing to do */ | |||||
| case AlphaFunc::Never: | |||||
| m_data->m_d3d_dev->SetRenderState(D3DRS_ALPHAFUNC, D3DCMP_NEVER); | |||||
| break; | |||||
| case AlphaFunc::Less: | |||||
| m_data->m_d3d_dev->SetRenderState(D3DRS_ALPHAFUNC, D3DCMP_LESS); | |||||
| break; | |||||
| case AlphaFunc::Equal: | |||||
| m_data->m_d3d_dev->SetRenderState(D3DRS_ALPHAFUNC, D3DCMP_EQUAL); | |||||
| break; | |||||
| case AlphaFunc::LessOrEqual: | |||||
| m_data->m_d3d_dev->SetRenderState(D3DRS_ALPHAFUNC, D3DCMP_LESSEQUAL); | |||||
| break; | |||||
| case AlphaFunc::Greater: | |||||
| m_data->m_d3d_dev->SetRenderState(D3DRS_ALPHAFUNC, D3DCMP_GREATER); | |||||
| break; | |||||
| case AlphaFunc::NotEqual: | |||||
| m_data->m_d3d_dev->SetRenderState(D3DRS_ALPHAFUNC, D3DCMP_NOTEQUAL); | |||||
| break; | |||||
| case AlphaFunc::GreaterOrEqual: | |||||
| m_data->m_d3d_dev->SetRenderState(D3DRS_ALPHAFUNC, D3DCMP_GREATEREQUAL); | |||||
| break; | |||||
| case AlphaFunc::Always: | |||||
| m_data->m_d3d_dev->SetRenderState(D3DRS_ALPHAFUNC, D3DCMP_ALWAYS); | |||||
| break; | |||||
| } | |||||
| if (func == AlphaFunc::Disabled) | |||||
| { | |||||
| m_data->m_d3d_dev->SetRenderState(D3DRS_ALPHATESTENABLE, FALSE); | |||||
| } | |||||
| else | |||||
| { | |||||
| m_data->m_d3d_dev->SetRenderState(D3DRS_ALPHATESTENABLE, TRUE); | |||||
| m_data->m_d3d_dev->SetRenderState(D3DRS_ALPHAREF, | |||||
| (DWORD)(alpha * 255.999f)); | |||||
| } | |||||
| #elif defined HAVE_GLES_2X | |||||
| #if defined HAVE_GLES_2X | |||||
| /* not supported */ | /* not supported */ | ||||
| #elif defined GL_VERSION_1_1 | #elif defined GL_VERSION_1_1 | ||||
| switch (func) | switch (func) | ||||
| @@ -432,30 +298,6 @@ void Renderer::SetBlendEquation(BlendEquation rgb, BlendEquation alpha) | |||||
| if (m_data->m_blend_rgb == rgb && m_data->m_blend_alpha == alpha) | if (m_data->m_blend_rgb == rgb && m_data->m_blend_alpha == alpha) | ||||
| return; | return; | ||||
| #if defined USE_D3D9 | |||||
| D3DBLEND s1[2] = { D3DBLENDOP_ADD, D3DBLENDOP_ADD }; | |||||
| BlendEquation s2[2] = { rgb, alpha }; | |||||
| for (int i = 0; i < 2; ++i) | |||||
| { | |||||
| switch (s2[i]) | |||||
| { | |||||
| case BlendEquation::Add: | |||||
| s1[i] = D3DBLENDOP_ADD; break; | |||||
| case BlendEquation::Subtract: | |||||
| s1[i] = D3DBLENDOP_SUBTRACT; break; | |||||
| case BlendEquation::ReverseSubtract: | |||||
| s1[i] = D3DBLENDOP_REVSUBTRACT; break; | |||||
| case BlendEquation::Min: | |||||
| s1[i] = D3DBLENDOP_MIN; break; | |||||
| case BlendEquation::Max: | |||||
| s1[i] = D3DBLENDOP_MAX; break; | |||||
| } | |||||
| } | |||||
| m_data->m_d3d_dev->SetRenderState(D3DRS_BLENDOP, s1[0]); | |||||
| m_data->m_d3d_dev->SetRenderState(D3DRS_BLENDOPALPHA, s1[1]); | |||||
| #else | |||||
| GLenum s1[2] = { GL_FUNC_ADD, GL_FUNC_ADD }; | GLenum s1[2] = { GL_FUNC_ADD, GL_FUNC_ADD }; | ||||
| BlendEquation s2[2] = { rgb, alpha }; | BlendEquation s2[2] = { rgb, alpha }; | ||||
| @@ -484,7 +326,6 @@ void Renderer::SetBlendEquation(BlendEquation rgb, BlendEquation alpha) | |||||
| } | } | ||||
| glBlendEquationSeparate(s1[0], s1[1]); | glBlendEquationSeparate(s1[0], s1[1]); | ||||
| #endif | |||||
| m_data->m_blend_rgb = rgb; | m_data->m_blend_rgb = rgb; | ||||
| m_data->m_blend_alpha = alpha; | m_data->m_blend_alpha = alpha; | ||||
| @@ -509,63 +350,6 @@ void Renderer::SetBlendFunc(BlendFunc src, BlendFunc dst) | |||||
| if (m_data->m_blend_src == src && m_data->m_blend_dst == dst) | if (m_data->m_blend_src == src && m_data->m_blend_dst == dst) | ||||
| return; | return; | ||||
| #if defined USE_D3D9 | |||||
| D3DBLEND s1[2] = { D3DBLEND_ONE, D3DBLEND_ZERO }; | |||||
| BlendFunc s2[2] = { src, dst }; | |||||
| for (int i = 0; i < 2; ++i) | |||||
| { | |||||
| switch (s2[i]) | |||||
| { | |||||
| case BlendFunc::Disabled: | |||||
| break; /* Nothing to do */ | |||||
| case BlendFunc::Zero: | |||||
| s1[i] = D3DBLEND_ZERO; break; | |||||
| case BlendFunc::One: | |||||
| s1[i] = D3DBLEND_ONE; break; | |||||
| case BlendFunc::SrcColor: | |||||
| s1[i] = D3DBLEND_SRCCOLOR; break; | |||||
| case BlendFunc::OneMinusSrcColor: | |||||
| s1[i] = D3DBLEND_INVSRCCOLOR; break; | |||||
| case BlendFunc::DstColor: | |||||
| s1[i] = D3DBLEND_DESTCOLOR; break; | |||||
| case BlendFunc::OneMinusDstColor: | |||||
| s1[i] = D3DBLEND_INVDESTCOLOR; break; | |||||
| case BlendFunc::SrcAlpha: | |||||
| s1[i] = D3DBLEND_SRCALPHA; break; | |||||
| case BlendFunc::OneMinusSrcAlpha: | |||||
| s1[i] = D3DBLEND_INVSRCALPHA; break; | |||||
| case BlendFunc::DstAlpha: | |||||
| s1[i] = D3DBLEND_DESTALPHA; break; | |||||
| case BlendFunc::OneMinusDstAlpha: | |||||
| s1[i] = D3DBLEND_INVDESTALPHA; break; | |||||
| /* FiXME: these can be supported using D3DPBLENDCAPS_BLENDFACTOR */ | |||||
| case BlendFunc::ConstantColor: | |||||
| ASSERT(0, "BlendFunc::ConstantColor not supported"); | |||||
| break; | |||||
| case BlendFunc::OneMinusConstantColor: | |||||
| ASSERT(0, "BlendFunc::OneMinusConstantColor not supported"); | |||||
| break; | |||||
| case BlendFunc::ConstantAlpha: | |||||
| ASSERT(0, "BlendFunc::ConstantAlpha not supported"); | |||||
| break; | |||||
| case BlendFunc::OneMinusConstantAlpha: | |||||
| ASSERT(0, "BlendFunc::OneMinusConstantAlpha not supported"); | |||||
| break; | |||||
| } | |||||
| } | |||||
| if (src == BlendFunc::Disabled) | |||||
| { | |||||
| m_data->m_d3d_dev->SetRenderState(D3DRS_ALPHABLENDENABLE, 0); | |||||
| } | |||||
| else | |||||
| { | |||||
| m_data->m_d3d_dev->SetRenderState(D3DRS_ALPHABLENDENABLE, 1); | |||||
| m_data->m_d3d_dev->SetRenderState(D3DRS_SRCBLEND, s1[0]); | |||||
| m_data->m_d3d_dev->SetRenderState(D3DRS_DESTBLEND, s1[1]); | |||||
| } | |||||
| #else | |||||
| GLenum s1[2] = { GL_ONE, GL_ZERO }; | GLenum s1[2] = { GL_ONE, GL_ZERO }; | ||||
| BlendFunc s2[2] = { src, dst }; | BlendFunc s2[2] = { src, dst }; | ||||
| @@ -615,7 +399,6 @@ void Renderer::SetBlendFunc(BlendFunc src, BlendFunc dst) | |||||
| glEnable(GL_BLEND); | glEnable(GL_BLEND); | ||||
| glBlendFunc(s1[0], s1[1]); | glBlendFunc(s1[0], s1[1]); | ||||
| } | } | ||||
| #endif | |||||
| m_data->m_blend_src = src; | m_data->m_blend_src = src; | ||||
| m_data->m_blend_dst = dst; | m_data->m_blend_dst = dst; | ||||
| @@ -640,42 +423,6 @@ void Renderer::SetDepthFunc(DepthFunc func) | |||||
| if (m_data->m_depth_func == func) | if (m_data->m_depth_func == func) | ||||
| return; | return; | ||||
| #if defined USE_D3D9 | |||||
| switch (func) | |||||
| { | |||||
| case DepthFunc::Disabled: | |||||
| break; /* Nothing to do */ | |||||
| case DepthFunc::Never: | |||||
| m_data->m_d3d_dev->SetRenderState(D3DRS_ZFUNC, D3DCMP_NEVER); | |||||
| break; | |||||
| case DepthFunc::Less: | |||||
| m_data->m_d3d_dev->SetRenderState(D3DRS_ZFUNC, D3DCMP_LESS); | |||||
| break; | |||||
| case DepthFunc::Equal: | |||||
| m_data->m_d3d_dev->SetRenderState(D3DRS_ZFUNC, D3DCMP_EQUAL); | |||||
| break; | |||||
| case DepthFunc::LessOrEqual: | |||||
| m_data->m_d3d_dev->SetRenderState(D3DRS_ZFUNC, D3DCMP_LESSEQUAL); | |||||
| break; | |||||
| case DepthFunc::Greater: | |||||
| m_data->m_d3d_dev->SetRenderState(D3DRS_ZFUNC, D3DCMP_GREATER); | |||||
| break; | |||||
| case DepthFunc::NotEqual: | |||||
| m_data->m_d3d_dev->SetRenderState(D3DRS_ZFUNC, D3DCMP_NOTEQUAL); | |||||
| break; | |||||
| case DepthFunc::GreaterOrEqual: | |||||
| m_data->m_d3d_dev->SetRenderState(D3DRS_ZFUNC, D3DCMP_GREATEREQUAL); | |||||
| break; | |||||
| case DepthFunc::Always: | |||||
| m_data->m_d3d_dev->SetRenderState(D3DRS_ZFUNC, D3DCMP_ALWAYS); | |||||
| break; | |||||
| } | |||||
| if (func == DepthFunc::Disabled) | |||||
| m_data->m_d3d_dev->SetRenderState(D3DRS_ZENABLE, D3DZB_FALSE); | |||||
| else | |||||
| m_data->m_d3d_dev->SetRenderState(D3DRS_ZENABLE, D3DZB_TRUE); | |||||
| #else | |||||
| switch (func) | switch (func) | ||||
| { | { | ||||
| case DepthFunc::Disabled: | case DepthFunc::Disabled: | ||||
| @@ -702,7 +449,6 @@ void Renderer::SetDepthFunc(DepthFunc func) | |||||
| glDisable(GL_DEPTH_TEST); | glDisable(GL_DEPTH_TEST); | ||||
| else | else | ||||
| glEnable(GL_DEPTH_TEST); | glEnable(GL_DEPTH_TEST); | ||||
| #endif | |||||
| m_data->m_depth_func = func; | m_data->m_depth_func = func; | ||||
| } | } | ||||
| @@ -721,17 +467,10 @@ void Renderer::SetDepthMask(DepthMask mask) | |||||
| if (m_data->m_depth_mask == mask) | if (m_data->m_depth_mask == mask) | ||||
| return; | return; | ||||
| #if defined USE_D3D9 | |||||
| if (mask == DepthMask::Disabled) | |||||
| m_data->m_d3d_dev->SetRenderState(D3DRS_ZWRITEENABLE, D3DZB_FALSE); | |||||
| else | |||||
| m_data->m_d3d_dev->SetRenderState(D3DRS_ZWRITEENABLE, D3DZB_TRUE); | |||||
| #else | |||||
| if (mask == DepthMask::Disabled) | if (mask == DepthMask::Disabled) | ||||
| glDepthMask(GL_FALSE); | glDepthMask(GL_FALSE); | ||||
| else | else | ||||
| glDepthMask(GL_TRUE); | glDepthMask(GL_TRUE); | ||||
| #endif | |||||
| m_data->m_depth_mask = mask; | m_data->m_depth_mask = mask; | ||||
| } | } | ||||
| @@ -750,20 +489,6 @@ void Renderer::SetCullMode(CullMode mode) | |||||
| if (m_data->m_cull_mode == mode) | if (m_data->m_cull_mode == mode) | ||||
| return; | return; | ||||
| #if defined USE_D3D9 | |||||
| switch (mode) | |||||
| { | |||||
| case CullMode::Disabled: | |||||
| m_data->m_d3d_dev->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE); | |||||
| break; | |||||
| case CullMode::Clockwise: | |||||
| m_data->m_d3d_dev->SetRenderState(D3DRS_CULLMODE, D3DCULL_CW); | |||||
| break; | |||||
| case CullMode::CounterClockwise: | |||||
| m_data->m_d3d_dev->SetRenderState(D3DRS_CULLMODE, D3DCULL_CCW); | |||||
| break; | |||||
| } | |||||
| #else | |||||
| switch (mode) | switch (mode) | ||||
| { | { | ||||
| case CullMode::Disabled: | case CullMode::Disabled: | ||||
| @@ -780,7 +505,6 @@ void Renderer::SetCullMode(CullMode mode) | |||||
| glFrontFace(GL_CCW); | glFrontFace(GL_CCW); | ||||
| break; | break; | ||||
| } | } | ||||
| #endif | |||||
| m_data->m_cull_mode = mode; | m_data->m_cull_mode = mode; | ||||
| } | } | ||||
| @@ -799,20 +523,7 @@ void Renderer::SetPolygonMode(PolygonMode mode) | |||||
| if (m_data->m_polygon_mode == mode) | if (m_data->m_polygon_mode == mode) | ||||
| return; | return; | ||||
| #if defined USE_D3D9 | |||||
| switch (mode) | |||||
| { | |||||
| case PolygonMode::Point: | |||||
| m_data->m_d3d_dev->SetRenderState(D3DRS_FILLMODE, D3DFILL_POINT); | |||||
| break; | |||||
| case PolygonMode::Line: | |||||
| m_data->m_d3d_dev->SetRenderState(D3DRS_FILLMODE, D3DFILL_WIREFRAME); | |||||
| break; | |||||
| case PolygonMode::Fill: | |||||
| m_data->m_d3d_dev->SetRenderState(D3DRS_FILLMODE, D3DFILL_SOLID); | |||||
| break; | |||||
| } | |||||
| #elif defined HAVE_GLES_2X | |||||
| #if defined HAVE_GLES_2X | |||||
| /* not supported */ | /* not supported */ | ||||
| #elif defined GL_VERSION_1_1 | #elif defined GL_VERSION_1_1 | ||||
| switch (mode) | switch (mode) | ||||
| @@ -19,13 +19,6 @@ | |||||
| # define WIN32_LEAN_AND_MEAN 1 | # define WIN32_LEAN_AND_MEAN 1 | ||||
| # include <windows.h> | # include <windows.h> | ||||
| # undef WIN32_LEAN_AND_MEAN | # undef WIN32_LEAN_AND_MEAN | ||||
| # if defined USE_D3D9 | |||||
| # include <algorithm> | |||||
| using std::min; | |||||
| using std::max; | |||||
| # include <d3d9.h> | |||||
| # include <d3dx9shader.h> | |||||
| # endif | |||||
| #endif | #endif | ||||
| #include "pegtl.hh" | #include "pegtl.hh" | ||||
| @@ -82,17 +75,10 @@ class ShaderData | |||||
| private: | private: | ||||
| String m_name; | String m_name; | ||||
| #if defined USE_D3D9 | |||||
| IDirect3DDevice9 *m_dev; | |||||
| IDirect3DVertexShader9 *vert_shader; | |||||
| IDirect3DPixelShader9 *frag_shader; | |||||
| ID3DXConstantTable *vert_table, *frag_table; | |||||
| #else | |||||
| GLuint prog_id, vert_id, frag_id; | GLuint prog_id, vert_id, frag_id; | ||||
| // Benlitz: using a simple array could be faster since there is never more than a few attribute locations to store | // Benlitz: using a simple array could be faster since there is never more than a few attribute locations to store | ||||
| map<uint64_t, GLint> attrib_locations; | map<uint64_t, GLint> attrib_locations; | ||||
| map<uint64_t, bool> attrib_errors; | map<uint64_t, bool> attrib_errors; | ||||
| #endif | |||||
| uint32_t vert_crc, frag_crc; | uint32_t vert_crc, frag_crc; | ||||
| /* Shader patcher */ | /* Shader patcher */ | ||||
| @@ -238,39 +224,15 @@ Shader::Shader(String const &name, | |||||
| { | { | ||||
| data->m_name = name; | data->m_name = name; | ||||
| #if defined USE_D3D9 | |||||
| ID3DXBuffer *shader_code, *error_msg; | |||||
| HRESULT hr; | |||||
| D3DXMACRO macros[] = | |||||
| { | |||||
| { "LOL_TEST_MACRO", "1" }, | |||||
| { nullptr, nullptr } | |||||
| }; | |||||
| #else | |||||
| char errbuf[4096]; | char errbuf[4096]; | ||||
| String shader_code; | String shader_code; | ||||
| GLchar const *gl_code; | GLchar const *gl_code; | ||||
| GLint status; | GLint status; | ||||
| GLsizei len; | GLsizei len; | ||||
| #endif | |||||
| /* Compile vertex shader */ | /* Compile vertex shader */ | ||||
| data->vert_crc = ShaderData::Hash(vert); | data->vert_crc = ShaderData::Hash(vert); | ||||
| #if defined USE_D3D9 | |||||
| data->m_dev = (IDirect3DDevice9 *)Renderer::Get()->GetDevice(); | |||||
| hr = D3DXCompileShader(vert, (UINT)strlen(vert), macros, nullptr, "main", | |||||
| "vs_3_0", 0, &shader_code, &error_msg, | |||||
| &data->vert_table); | |||||
| if (FAILED(hr)) | |||||
| { | |||||
| msg::error("failed to compile vertex shader %s: %s\n", name.C(), | |||||
| error_msg ? error_msg->GetBufferPointer() : "error"); | |||||
| msg::error("shader source:\n%s\n", vert); | |||||
| } | |||||
| data->m_dev->CreateVertexShader((DWORD *)shader_code->GetBufferPointer(), | |||||
| &data->vert_shader); | |||||
| shader_code->Release(); | |||||
| #else | |||||
| shader_code = ShaderData::Patch(vert, ShaderType::Vertex); | shader_code = ShaderData::Patch(vert, ShaderType::Vertex); | ||||
| data->vert_id = glCreateShader(GL_VERTEX_SHADER); | data->vert_id = glCreateShader(GL_VERTEX_SHADER); | ||||
| gl_code = shader_code.C(); | gl_code = shader_code.C(); | ||||
| @@ -290,24 +252,10 @@ Shader::Shader(String const &name, | |||||
| msg::debug("compile log for vertex shader %s: %s\n", name.C(), errbuf); | msg::debug("compile log for vertex shader %s: %s\n", name.C(), errbuf); | ||||
| msg::debug("shader source:\n%s\n", shader_code.C()); | msg::debug("shader source:\n%s\n", shader_code.C()); | ||||
| } | } | ||||
| #endif | |||||
| /* Compile fragment shader */ | /* Compile fragment shader */ | ||||
| data->frag_crc = ShaderData::Hash(frag); | data->frag_crc = ShaderData::Hash(frag); | ||||
| #if defined USE_D3D9 | |||||
| hr = D3DXCompileShader(frag, (UINT)strlen(frag), macros, nullptr, "main", | |||||
| "ps_3_0", 0, &shader_code, &error_msg, | |||||
| &data->frag_table); | |||||
| if (FAILED(hr)) | |||||
| { | |||||
| msg::error("failed to compile fragment shader %s: %s\n", name.C(), | |||||
| error_msg ? error_msg->GetBufferPointer() : "error"); | |||||
| msg::error("shader source:\n%s\n", frag); | |||||
| } | |||||
| data->m_dev->CreatePixelShader((DWORD *)shader_code->GetBufferPointer(), | |||||
| &data->frag_shader); | |||||
| shader_code->Release(); | |||||
| #else | |||||
| shader_code = ShaderData::Patch(frag, ShaderType::Fragment); | shader_code = ShaderData::Patch(frag, ShaderType::Fragment); | ||||
| data->frag_id = glCreateShader(GL_FRAGMENT_SHADER); | data->frag_id = glCreateShader(GL_FRAGMENT_SHADER); | ||||
| gl_code = shader_code.C(); | gl_code = shader_code.C(); | ||||
| @@ -328,28 +276,7 @@ Shader::Shader(String const &name, | |||||
| name.C(), errbuf); | name.C(), errbuf); | ||||
| msg::debug("shader source:\n%s\n", shader_code.C()); | msg::debug("shader source:\n%s\n", shader_code.C()); | ||||
| } | } | ||||
| #endif | |||||
| #if defined USE_D3D9 | |||||
| /* FIXME: this is only debug code, we don't need it. */ | |||||
| D3DXCONSTANTTABLE_DESC desc; | |||||
| data->frag_table->GetDesc(&desc); | |||||
| for (int i = 0; i < desc.Constants; i++) | |||||
| { | |||||
| D3DXCONSTANT_DESC cdesc; | |||||
| UINT count = 1; | |||||
| D3DXHANDLE h = data->frag_table->GetConstant(nullptr, i); | |||||
| data->frag_table->GetConstantDesc(h, &cdesc, &count); | |||||
| } | |||||
| data->vert_table->GetDesc(&desc); | |||||
| for (int i = 0; i < desc.Constants; i++) | |||||
| { | |||||
| D3DXCONSTANT_DESC cdesc; | |||||
| UINT count = 1; | |||||
| D3DXHANDLE h = data->vert_table->GetConstant(nullptr, i); | |||||
| data->frag_table->GetConstantDesc(h, &cdesc, &count); | |||||
| } | |||||
| #else | |||||
| /* Create program */ | /* Create program */ | ||||
| data->prog_id = glCreateProgram(); | data->prog_id = glCreateProgram(); | ||||
| glAttachShader(data->prog_id, data->vert_id); | glAttachShader(data->prog_id, data->vert_id); | ||||
| @@ -431,7 +358,6 @@ Shader::Shader(String const &name, | |||||
| } | } | ||||
| delete[] name_buffer; | delete[] name_buffer; | ||||
| #endif | |||||
| } | } | ||||
| int Shader::GetAttribCount() const | int Shader::GetAttribCount() const | ||||
| @@ -444,8 +370,7 @@ ShaderAttrib Shader::GetAttribLocation(VertexUsage usage, int index) const | |||||
| ShaderAttrib ret; | ShaderAttrib ret; | ||||
| ret.m_flags = (uint64_t)(uint16_t)usage.ToScalar() << 16; | ret.m_flags = (uint64_t)(uint16_t)usage.ToScalar() << 16; | ||||
| ret.m_flags |= (uint64_t)(uint16_t)index; | ret.m_flags |= (uint64_t)(uint16_t)index; | ||||
| #if defined USE_D3D9 | |||||
| #else | |||||
| GLint l = -1; | GLint l = -1; | ||||
| if (!data->attrib_locations.try_get(ret.m_flags, l)) | if (!data->attrib_locations.try_get(ret.m_flags, l)) | ||||
| @@ -459,7 +384,6 @@ ShaderAttrib Shader::GetAttribLocation(VertexUsage usage, int index) const | |||||
| } | } | ||||
| } | } | ||||
| ret.m_flags |= (uint64_t)(uint32_t)l << 32; | ret.m_flags |= (uint64_t)(uint32_t)l << 32; | ||||
| #endif | |||||
| return ret; | return ret; | ||||
| } | } | ||||
| @@ -470,36 +394,8 @@ ShaderUniform Shader::GetUniformLocation(String const& uni) const | |||||
| ShaderUniform Shader::GetUniformLocation(char const *uni) const | ShaderUniform Shader::GetUniformLocation(char const *uni) const | ||||
| { | { | ||||
| ShaderUniform ret; | ShaderUniform ret; | ||||
| #if defined USE_D3D9 | |||||
| /* Global variables are prefixed with "$" */ | |||||
| String tmpname = String("$") + uni; | |||||
| D3DXCONSTANT_DESC cdesc; | |||||
| D3DXHANDLE hr; | |||||
| UINT count; | |||||
| count = 0; | |||||
| hr = data->frag_table->GetConstantByName(nullptr, tmpname.C()); | |||||
| if (hr) | |||||
| data->frag_table->GetConstantDesc(hr, &cdesc, &count); | |||||
| if (count) | |||||
| { | |||||
| ret.frag = cdesc.RegisterIndex; | |||||
| ret.flags |= 1; | |||||
| } | |||||
| count = 0; | |||||
| hr = data->vert_table->GetConstantByName(nullptr, tmpname.C()); | |||||
| if (hr) | |||||
| data->vert_table->GetConstantDesc(hr, &cdesc, &count); | |||||
| if (count) | |||||
| { | |||||
| ret.vert = cdesc.RegisterIndex; | |||||
| ret.flags |= 2; | |||||
| } | |||||
| #else | |||||
| ret.frag = (uintptr_t)glGetUniformLocation(data->prog_id, uni); | ret.frag = (uintptr_t)glGetUniformLocation(data->prog_id, uni); | ||||
| ret.vert = 0; | ret.vert = 0; | ||||
| #endif | |||||
| return ret; | return ret; | ||||
| } | } | ||||
| @@ -509,135 +405,65 @@ ShaderUniform Shader::GetUniformLocation(char const *uni) const | |||||
| void Shader::SetUniform(ShaderUniform const &uni, int i) | void Shader::SetUniform(ShaderUniform const &uni, int i) | ||||
| { | { | ||||
| #if defined USE_D3D9 | |||||
| SetUniform(uni, ivec4(i, 0, 0, 0)); | |||||
| #else | |||||
| glUniform1i((GLint)uni.frag, i); | glUniform1i((GLint)uni.frag, i); | ||||
| #endif | |||||
| } | } | ||||
| void Shader::SetUniform(ShaderUniform const &uni, ivec2 const &v) | void Shader::SetUniform(ShaderUniform const &uni, ivec2 const &v) | ||||
| { | { | ||||
| #if defined USE_D3D9 | |||||
| SetUniform(uni, ivec4(v, 0, 0)); | |||||
| #else | |||||
| glUniform2i((GLint)uni.frag, v.x, v.y); | glUniform2i((GLint)uni.frag, v.x, v.y); | ||||
| #endif | |||||
| } | } | ||||
| void Shader::SetUniform(ShaderUniform const &uni, ivec3 const &v) | void Shader::SetUniform(ShaderUniform const &uni, ivec3 const &v) | ||||
| { | { | ||||
| #if defined USE_D3D9 | |||||
| SetUniform(uni, ivec4(v, 0)); | |||||
| #else | |||||
| glUniform3i((GLint)uni.frag, v.x, v.y, v.z); | glUniform3i((GLint)uni.frag, v.x, v.y, v.z); | ||||
| #endif | |||||
| } | } | ||||
| void Shader::SetUniform(ShaderUniform const &uni, ivec4 const &v) | void Shader::SetUniform(ShaderUniform const &uni, ivec4 const &v) | ||||
| { | { | ||||
| #if defined USE_D3D9 | |||||
| if (uni.flags & 1) | |||||
| data->m_dev->SetPixelShaderConstantI((UINT)uni.frag, &v[0], 1); | |||||
| if (uni.flags & 2) | |||||
| data->m_dev->SetVertexShaderConstantI((UINT)uni.vert, &v[0], 1); | |||||
| #else | |||||
| glUniform4i((GLint)uni.frag, v.x, v.y, v.z, v.w); | glUniform4i((GLint)uni.frag, v.x, v.y, v.z, v.w); | ||||
| #endif | |||||
| } | } | ||||
| void Shader::SetUniform(ShaderUniform const &uni, float f) | void Shader::SetUniform(ShaderUniform const &uni, float f) | ||||
| { | { | ||||
| #if defined USE_D3D9 | |||||
| SetUniform(uni, vec4(f, 0, 0, 0)); | |||||
| #else | |||||
| glUniform1f((GLint)uni.frag, f); | glUniform1f((GLint)uni.frag, f); | ||||
| #endif | |||||
| } | } | ||||
| void Shader::SetUniform(ShaderUniform const &uni, vec2 const &v) | void Shader::SetUniform(ShaderUniform const &uni, vec2 const &v) | ||||
| { | { | ||||
| #if defined USE_D3D9 | |||||
| SetUniform(uni, vec4(v, 0, 0)); | |||||
| #else | |||||
| glUniform2fv((GLint)uni.frag, 1, &v[0]); | glUniform2fv((GLint)uni.frag, 1, &v[0]); | ||||
| #endif | |||||
| } | } | ||||
| void Shader::SetUniform(ShaderUniform const &uni, vec3 const &v) | void Shader::SetUniform(ShaderUniform const &uni, vec3 const &v) | ||||
| { | { | ||||
| #if defined USE_D3D9 | |||||
| SetUniform(uni, vec4(v, 0)); | |||||
| #else | |||||
| glUniform3fv((GLint)uni.frag, 1, &v[0]); | glUniform3fv((GLint)uni.frag, 1, &v[0]); | ||||
| #endif | |||||
| } | } | ||||
| void Shader::SetUniform(ShaderUniform const &uni, vec4 const &v) | void Shader::SetUniform(ShaderUniform const &uni, vec4 const &v) | ||||
| { | { | ||||
| #if defined USE_D3D9 | |||||
| if (uni.flags & 1) | |||||
| data->m_dev->SetPixelShaderConstantF((UINT)uni.frag, &v[0], 1); | |||||
| if (uni.flags & 2) | |||||
| data->m_dev->SetVertexShaderConstantF((UINT)uni.vert, &v[0], 1); | |||||
| #else | |||||
| glUniform4fv((GLint)uni.frag, 1, &v[0]); | glUniform4fv((GLint)uni.frag, 1, &v[0]); | ||||
| #endif | |||||
| } | } | ||||
| void Shader::SetUniform(ShaderUniform const &uni, mat2 const &m) | void Shader::SetUniform(ShaderUniform const &uni, mat2 const &m) | ||||
| { | { | ||||
| #if defined USE_D3D9 | |||||
| /* FIXME: do we need padding here like for the mat3 version? */ | |||||
| if (uni.flags & 1) | |||||
| data->m_dev->SetPixelShaderConstantF((UINT)uni.frag, &m[0][0], 1); | |||||
| if (uni.flags & 2) | |||||
| data->m_dev->SetVertexShaderConstantF((UINT)uni.vert, &m[0][0], 1); | |||||
| #else | |||||
| glUniformMatrix2fv((GLint)uni.frag, 1, GL_FALSE, &m[0][0]); | glUniformMatrix2fv((GLint)uni.frag, 1, GL_FALSE, &m[0][0]); | ||||
| #endif | |||||
| } | } | ||||
| void Shader::SetUniform(ShaderUniform const &uni, mat3 const &m) | void Shader::SetUniform(ShaderUniform const &uni, mat3 const &m) | ||||
| { | { | ||||
| #if defined USE_D3D9 | |||||
| /* Padding matrix columns is necessary on DirectX. We need to create | |||||
| * a new data structure; a 4×4 matrix will do. */ | |||||
| mat4 tmp(m, 1.0f); | |||||
| if (uni.flags & 1) | |||||
| data->m_dev->SetPixelShaderConstantF((UINT)uni.frag, &tmp[0][0], 3); | |||||
| if (uni.flags & 2) | |||||
| data->m_dev->SetVertexShaderConstantF((UINT)uni.vert, &tmp[0][0], 3); | |||||
| #else | |||||
| glUniformMatrix3fv((GLint)uni.frag, 1, GL_FALSE, &m[0][0]); | glUniformMatrix3fv((GLint)uni.frag, 1, GL_FALSE, &m[0][0]); | ||||
| #endif | |||||
| } | } | ||||
| void Shader::SetUniform(ShaderUniform const &uni, mat4 const &m) | void Shader::SetUniform(ShaderUniform const &uni, mat4 const &m) | ||||
| { | { | ||||
| #if defined USE_D3D9 | |||||
| if (uni.flags & 1) | |||||
| data->m_dev->SetPixelShaderConstantF((UINT)uni.frag, &m[0][0], 4); | |||||
| if (uni.flags & 2) | |||||
| data->m_dev->SetVertexShaderConstantF((UINT)uni.vert, &m[0][0], 4); | |||||
| #else | |||||
| glUniformMatrix4fv((GLint)uni.frag, 1, GL_FALSE, &m[0][0]); | glUniformMatrix4fv((GLint)uni.frag, 1, GL_FALSE, &m[0][0]); | ||||
| #endif | |||||
| } | } | ||||
| void Shader::SetUniform(ShaderUniform const &uni, TextureUniform tex, int index) | void Shader::SetUniform(ShaderUniform const &uni, TextureUniform tex, int index) | ||||
| { | { | ||||
| #if defined USE_D3D9 | |||||
| data->m_dev->SetTexture(index, (LPDIRECT3DTEXTURE9)tex.m_flags); | |||||
| data->m_dev->SetSamplerState(index, D3DSAMP_MAGFILTER, tex.m_attrib & 0xff); | |||||
| data->m_dev->SetSamplerState(index, D3DSAMP_MINFILTER, (tex.m_attrib >> 8) & 0xff); | |||||
| data->m_dev->SetSamplerState(index, D3DSAMP_MIPFILTER, (tex.m_attrib >> 16) & 0xff); | |||||
| #else | |||||
| glActiveTexture(GL_TEXTURE0 + index); | glActiveTexture(GL_TEXTURE0 + index); | ||||
| //glEnable(GL_TEXTURE_2D); | //glEnable(GL_TEXTURE_2D); | ||||
| glBindTexture(GL_TEXTURE_2D, (int)tex.m_flags); | glBindTexture(GL_TEXTURE_2D, (int)tex.m_flags); | ||||
| SetUniform(uni, index); | SetUniform(uni, index); | ||||
| #endif | |||||
| } | } | ||||
| /* | /* | ||||
| @@ -646,103 +472,43 @@ void Shader::SetUniform(ShaderUniform const &uni, TextureUniform tex, int index) | |||||
| void Shader::SetUniform(ShaderUniform const &uni, array<float> const &v) | void Shader::SetUniform(ShaderUniform const &uni, array<float> const &v) | ||||
| { | { | ||||
| #if defined USE_D3D9 | |||||
| /* FIXME: this will not work properly because we don't know how tell DX9 | |||||
| * it's a bunch of floats instead of vec4. */ | |||||
| if (uni.flags & 1) | |||||
| data->m_dev->SetPixelShaderConstantF((UINT)uni.frag, | |||||
| &v[0], v.count() / 4); | |||||
| if (uni.flags & 2) | |||||
| data->m_dev->SetVertexShaderConstantF((UINT)uni.vert, | |||||
| &v[0], v.count() / 4); | |||||
| #else | |||||
| glUniform1fv((GLint)uni.frag, (GLsizei)v.count(), &v[0]); | glUniform1fv((GLint)uni.frag, (GLsizei)v.count(), &v[0]); | ||||
| #endif | |||||
| } | } | ||||
| void Shader::SetUniform(ShaderUniform const &uni, array<vec2> const &v) | void Shader::SetUniform(ShaderUniform const &uni, array<vec2> const &v) | ||||
| { | { | ||||
| #if defined USE_D3D9 | |||||
| /* FIXME: this will not work properly because we don't know how tell DX9 | |||||
| * it's a bunch of vec2 instead of vec4. */ | |||||
| if (uni.flags & 1) | |||||
| data->m_dev->SetPixelShaderConstantF((UINT)uni.frag, | |||||
| &v[0][0], v.count() / 2); | |||||
| if (uni.flags & 2) | |||||
| data->m_dev->SetVertexShaderConstantF((UINT)uni.vert, | |||||
| &v[0][0], v.count() / 2); | |||||
| #else | |||||
| glUniform2fv((GLint)uni.frag, (GLsizei)v.count(), &v[0][0]); | glUniform2fv((GLint)uni.frag, (GLsizei)v.count(), &v[0][0]); | ||||
| #endif | |||||
| } | } | ||||
| void Shader::SetUniform(ShaderUniform const &uni, array<vec3> const &v) | void Shader::SetUniform(ShaderUniform const &uni, array<vec3> const &v) | ||||
| { | { | ||||
| #if defined USE_D3D9 | |||||
| /* FIXME: this will not work properly because we don't know how tell DX9 | |||||
| * it's a bunch of vec3 instead of vec4. */ | |||||
| if (uni.flags & 1) | |||||
| data->m_dev->SetPixelShaderConstantF((UINT)uni.frag, | |||||
| &v[0][0], v.count()); | |||||
| if (uni.flags & 2) | |||||
| data->m_dev->SetVertexShaderConstantF((UINT)uni.vert, | |||||
| &v[0][0], v.count()); | |||||
| #else | |||||
| glUniform3fv((GLint)uni.frag, (GLsizei)v.count(), &v[0][0]); | glUniform3fv((GLint)uni.frag, (GLsizei)v.count(), &v[0][0]); | ||||
| #endif | |||||
| } | } | ||||
| void Shader::SetUniform(ShaderUniform const &uni, array<vec4> const &v) | void Shader::SetUniform(ShaderUniform const &uni, array<vec4> const &v) | ||||
| { | { | ||||
| #if defined USE_D3D9 | |||||
| if (uni.flags & 1) | |||||
| data->m_dev->SetPixelShaderConstantF((UINT)uni.frag, | |||||
| &v[0][0], v.count()); | |||||
| if (uni.flags & 2) | |||||
| data->m_dev->SetVertexShaderConstantF((UINT)uni.vert, | |||||
| &v[0][0], v.count()); | |||||
| #else | |||||
| glUniform4fv((GLint)uni.frag, (GLsizei)v.count(), &v[0][0]); | glUniform4fv((GLint)uni.frag, (GLsizei)v.count(), &v[0][0]); | ||||
| #endif | |||||
| } | } | ||||
| void Shader::Bind() const | void Shader::Bind() const | ||||
| { | { | ||||
| #if defined USE_D3D9 | |||||
| HRESULT hr; | |||||
| hr = data->m_dev->SetVertexShader(data->vert_shader); | |||||
| hr = data->m_dev->SetPixelShader(data->frag_shader); | |||||
| #else | |||||
| glUseProgram(data->prog_id); | glUseProgram(data->prog_id); | ||||
| #endif | |||||
| } | } | ||||
| void Shader::Unbind() const | void Shader::Unbind() const | ||||
| { | { | ||||
| #if defined USE_D3D9 | |||||
| HRESULT hr; | |||||
| hr = data->m_dev->SetVertexShader(nullptr); | |||||
| hr = data->m_dev->SetPixelShader(nullptr); | |||||
| #else | |||||
| /* FIXME: untested */ | /* FIXME: untested */ | ||||
| glUseProgram(0); | glUseProgram(0); | ||||
| #endif | |||||
| } | } | ||||
| Shader::~Shader() | Shader::~Shader() | ||||
| { | { | ||||
| #if defined USE_D3D9 | |||||
| data->vert_shader->Release(); | |||||
| data->vert_table->Release(); | |||||
| data->frag_shader->Release(); | |||||
| data->frag_table->Release(); | |||||
| #else | |||||
| glDetachShader(data->prog_id, data->vert_id); | glDetachShader(data->prog_id, data->vert_id); | ||||
| glDetachShader(data->prog_id, data->frag_id); | glDetachShader(data->prog_id, data->frag_id); | ||||
| glDeleteShader(data->vert_id); | glDeleteShader(data->vert_id); | ||||
| glDeleteShader(data->frag_id); | glDeleteShader(data->frag_id); | ||||
| glDeleteProgram(data->prog_id); | glDeleteProgram(data->prog_id); | ||||
| #endif | |||||
| delete data; | delete data; | ||||
| } | } | ||||
| @@ -751,7 +517,6 @@ int ShaderData::GetVersion() | |||||
| { | { | ||||
| static int version = 0; | static int version = 0; | ||||
| #if !defined USE_D3D9 | |||||
| if (!version) | if (!version) | ||||
| { | { | ||||
| #if defined HAVE_GLES_2X | #if defined HAVE_GLES_2X | ||||
| @@ -793,7 +558,6 @@ int ShaderData::GetVersion() | |||||
| glDeleteShader(id); | glDeleteShader(id); | ||||
| #endif | #endif | ||||
| } | } | ||||
| #endif | |||||
| return version; | return version; | ||||
| } | } | ||||
| @@ -12,12 +12,6 @@ | |||||
| #include "lolgl.h" | #include "lolgl.h" | ||||
| #if defined _WIN32 && defined USE_D3D9 | |||||
| # define FAR | |||||
| # define NEAR | |||||
| # include <d3d9.h> | |||||
| #endif | |||||
| namespace lol | namespace lol | ||||
| { | { | ||||
| @@ -33,17 +27,9 @@ class TextureData | |||||
| ivec2 m_size; | ivec2 m_size; | ||||
| PixelFormat m_format; | PixelFormat m_format; | ||||
| #if defined USE_D3D9 | |||||
| IDirect3DDevice9 *m_dev; | |||||
| IDirect3DTexture9 *m_texture; | |||||
| D3DTEXTUREFILTERTYPE m_mag_filter; | |||||
| D3DTEXTUREFILTERTYPE m_min_filter; | |||||
| D3DTEXTUREFILTERTYPE m_mip_filter; | |||||
| #else | |||||
| GLuint m_texture; | GLuint m_texture; | ||||
| GLint m_internal_format; | GLint m_internal_format; | ||||
| GLenum m_gl_format, m_gl_type; | GLenum m_gl_format, m_gl_type; | ||||
| #endif | |||||
| int m_bytes_per_elem; | int m_bytes_per_elem; | ||||
| }; | }; | ||||
| @@ -62,52 +48,6 @@ Texture::Texture(ivec2 size, PixelFormat format) | |||||
| m_data->m_size = size; | m_data->m_size = size; | ||||
| m_data->m_format = format; | m_data->m_format = format; | ||||
| #if defined USE_D3D9 | |||||
| m_data->m_dev = (IDirect3DDevice9 *)Renderer::Get()->GetDevice(); | |||||
| static struct | |||||
| { | |||||
| D3DFORMAT format; | |||||
| int bytes; | |||||
| } | |||||
| const d3d_formats[] = | |||||
| { | |||||
| /* Unknown */ | |||||
| { D3DFMT_UNKNOWN, 0 }, | |||||
| /* FIXME: this is all mixed up for the RGBA/ARGB combinations */ | |||||
| # if defined USE_D3D9 | |||||
| { D3DFMT_L8, 1 }, /* Y_8 */ | |||||
| { D3DFMT_R8G8B8, 3 }, /* RGB_8 */ | |||||
| { D3DFMT_A8R8G8B8, 4 }, /* RGBA_8 */ | |||||
| { D3DFMT_UNKNOWN, 0 }, /* Y_F32 */ | |||||
| { D3DFMT_UNKNOWN, 0 }, /* RGB_F32 */ | |||||
| { D3DFMT_UNKNOWN, 0 }, /* RGBA_F32 */ | |||||
| # else | |||||
| { D3DFMT_LIN_L8, 1 }, | |||||
| { D3DFMT_UNKNOWN, 0 }, | |||||
| /* By default the X360 will swizzle the texture. Ask for linear. */ | |||||
| { D3DFMT_LIN_A8R8G8B8, 4 }, | |||||
| { D3DFMT_UNKNOWN, 0 }, /* Y_F32 */ | |||||
| { D3DFMT_UNKNOWN, 0 }, /* RGB_F32 */ | |||||
| { D3DFMT_UNKNOWN, 0 }, /* RGBA_F32 */ | |||||
| # endif | |||||
| }; | |||||
| D3DFORMAT d3d_format = GET_CLAMPED(d3d_formats, format).format; | |||||
| ASSERT(d3d_format != D3DFMT_UNKNOWN, | |||||
| "unsupported texture format %d\n", format); | |||||
| # if defined USE_D3D9 | |||||
| int d3d_usage = D3DUSAGE_DYNAMIC; | |||||
| # else | |||||
| int d3d_usage = D3DUSAGE_WRITEONLY; | |||||
| # endif | |||||
| m_data->m_dev->CreateTexture(m_data->m_size.x, m_data->m_size.y, 1, | |||||
| d3d_usage, d3d_format, | |||||
| D3DPOOL_DEFAULT, &m_data->m_texture, nullptr); | |||||
| m_data->m_bytes_per_elem = GET_CLAMPED(d3d_formats, format).bytes; | |||||
| #else | |||||
| static struct | static struct | ||||
| { | { | ||||
| GLint internal_format; | GLint internal_format; | ||||
| @@ -146,93 +86,38 @@ Texture::Texture(ivec2 size, PixelFormat format) | |||||
| glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); | ||||
| glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); | ||||
| #endif | |||||
| } | } | ||||
| TextureUniform Texture::GetTextureUniform() const | TextureUniform Texture::GetTextureUniform() const | ||||
| { | { | ||||
| TextureUniform ret; | TextureUniform ret; | ||||
| #if defined USE_D3D9 | |||||
| ret.m_flags = (uint64_t)(uintptr_t)m_data->m_texture; | |||||
| ret.m_attrib = m_data->m_mag_filter; | |||||
| ret.m_attrib |= m_data->m_min_filter << 8; | |||||
| ret.m_attrib |= m_data->m_mip_filter << 16; | |||||
| #else | |||||
| ret.m_flags = m_data->m_texture; | ret.m_flags = m_data->m_texture; | ||||
| #endif | |||||
| return ret; | return ret; | ||||
| } | } | ||||
| void Texture::Bind() | void Texture::Bind() | ||||
| { | { | ||||
| #if defined USE_D3D9 | |||||
| m_data->m_dev->SetTexture(0, m_data->m_texture); | |||||
| #else | |||||
| # if !defined HAVE_GLES_2X | |||||
| #if !defined HAVE_GLES_2X | |||||
| glEnable(GL_TEXTURE_2D); | glEnable(GL_TEXTURE_2D); | ||||
| # endif | |||||
| glBindTexture(GL_TEXTURE_2D, m_data->m_texture); | |||||
| #endif | #endif | ||||
| glBindTexture(GL_TEXTURE_2D, m_data->m_texture); | |||||
| } | } | ||||
| void Texture::SetData(void *data) | void Texture::SetData(void *data) | ||||
| { | { | ||||
| #if defined USE_D3D9 | |||||
| D3DLOCKED_RECT rect; | |||||
| # if defined USE_D3D9 | |||||
| m_data->m_texture->LockRect(0, &rect, nullptr, D3DLOCK_DISCARD); | |||||
| # else | |||||
| m_data->m_texture->LockRect(0, &rect, nullptr, 0); | |||||
| # endif | |||||
| memcpy(rect.pBits, data, rect.Pitch * m_data->m_size.y); | |||||
| m_data->m_texture->UnlockRect(0); | |||||
| #else | |||||
| glTexImage2D(GL_TEXTURE_2D, 0, m_data->m_internal_format, | glTexImage2D(GL_TEXTURE_2D, 0, m_data->m_internal_format, | ||||
| m_data->m_size.x, m_data->m_size.y, 0, | m_data->m_size.x, m_data->m_size.y, 0, | ||||
| m_data->m_gl_format, m_data->m_gl_type, data); | m_data->m_gl_format, m_data->m_gl_type, data); | ||||
| #endif | |||||
| } | } | ||||
| void Texture::SetSubData(ivec2 origin, ivec2 size, void *data) | void Texture::SetSubData(ivec2 origin, ivec2 size, void *data) | ||||
| { | { | ||||
| #if defined USE_D3D9 | |||||
| D3DLOCKED_RECT rect; | |||||
| m_data->m_texture->LockRect(0, &rect, nullptr, 0); | |||||
| int stride = size.x * m_data->m_bytes_per_elem; | |||||
| for (int j = 0; j < size.y; j++) | |||||
| { | |||||
| uint8_t *dst = (uint8_t *)rect.pBits + (origin.y + j) * rect.Pitch; | |||||
| uint8_t *src = (uint8_t *)data + j * stride; | |||||
| memcpy(dst, src, stride); | |||||
| } | |||||
| m_data->m_texture->UnlockRect(0); | |||||
| #else | |||||
| glTexSubImage2D(GL_TEXTURE_2D, 0, origin.x, origin.y, size.x, size.y, | glTexSubImage2D(GL_TEXTURE_2D, 0, origin.x, origin.y, size.x, size.y, | ||||
| m_data->m_gl_format, m_data->m_gl_type, data); | m_data->m_gl_format, m_data->m_gl_type, data); | ||||
| #endif | |||||
| } | } | ||||
| void Texture::SetMagFiltering(TextureMagFilter filter) | void Texture::SetMagFiltering(TextureMagFilter filter) | ||||
| { | { | ||||
| #if defined USE_D3D9 | |||||
| // In DirectX, texture filtering is a per-texture-unit state | |||||
| switch (filter) | |||||
| { | |||||
| case TextureMagFilter::LINEAR_TEXEL: | |||||
| m_data->m_mag_filter = D3DTEXF_LINEAR; | |||||
| break; | |||||
| case TextureMagFilter::NEAREST_TEXEL: | |||||
| default: | |||||
| m_data->m_mag_filter = D3DTEXF_POINT; | |||||
| break; | |||||
| } | |||||
| #else | |||||
| glBindTexture(GL_TEXTURE_2D, m_data->m_texture); | glBindTexture(GL_TEXTURE_2D, m_data->m_texture); | ||||
| GLenum gl_filter; | GLenum gl_filter; | ||||
| switch (filter) | switch (filter) | ||||
| @@ -246,40 +131,10 @@ void Texture::SetMagFiltering(TextureMagFilter filter) | |||||
| break; | break; | ||||
| } | } | ||||
| glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, gl_filter); | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, gl_filter); | ||||
| #endif | |||||
| } | } | ||||
| void Texture::SetMinFiltering(TextureMinFilter filter) | void Texture::SetMinFiltering(TextureMinFilter filter) | ||||
| { | { | ||||
| #if defined USE_D3D9 | |||||
| // In DirectX, texture filtering is a per-texture-unit state | |||||
| #define F(x, y) \ | |||||
| m_data->m_min_filter = x; m_data->m_mip_filter = y; | |||||
| switch (filter) | |||||
| { | |||||
| case TextureMinFilter::LINEAR_TEXEL_NO_MIPMAP: | |||||
| F(D3DTEXF_POINT, D3DTEXF_NONE); | |||||
| break; | |||||
| case TextureMinFilter::NEAREST_TEXEL_NEAREST_MIPMAP: | |||||
| F(D3DTEXF_POINT, D3DTEXF_POINT); | |||||
| break; | |||||
| case TextureMinFilter::LINEAR_TEXEL_NEAREST_MIPMAP: | |||||
| F(D3DTEXF_LINEAR, D3DTEXF_POINT); | |||||
| break; | |||||
| case TextureMinFilter::NEAREST_TEXEL_LINEAR_MIPMAP: | |||||
| F(D3DTEXF_POINT, D3DTEXF_LINEAR); | |||||
| break; | |||||
| case TextureMinFilter::LINEAR_TEXEL_LINEAR_MIPMAP: | |||||
| F(D3DTEXF_LINEAR, D3DTEXF_LINEAR); | |||||
| break; | |||||
| case TextureMinFilter::NEAREST_TEXEL_NO_MIPMAP: | |||||
| default: | |||||
| F(D3DTEXF_POINT, D3DTEXF_NONE); | |||||
| break; | |||||
| } | |||||
| #undef F | |||||
| #else | |||||
| glBindTexture(GL_TEXTURE_2D, m_data->m_texture); | glBindTexture(GL_TEXTURE_2D, m_data->m_texture); | ||||
| GLenum gl_filter; | GLenum gl_filter; | ||||
| switch (filter) | switch (filter) | ||||
| @@ -305,27 +160,17 @@ void Texture::SetMinFiltering(TextureMinFilter filter) | |||||
| break; | break; | ||||
| } | } | ||||
| glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, gl_filter); | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, gl_filter); | ||||
| #endif | |||||
| } | } | ||||
| void Texture::GenerateMipmaps() | void Texture::GenerateMipmaps() | ||||
| { | { | ||||
| #if defined USE_D3D9 | |||||
| m_data->m_texture->->GenerateMipSubLevels(); | |||||
| #else | |||||
| glBindTexture(GL_TEXTURE_2D, m_data->m_texture); | glBindTexture(GL_TEXTURE_2D, m_data->m_texture); | ||||
| glGenerateMipmap(GL_TEXTURE_2D); | glGenerateMipmap(GL_TEXTURE_2D); | ||||
| #endif | |||||
| } | } | ||||
| Texture::~Texture() | Texture::~Texture() | ||||
| { | { | ||||
| #if defined USE_D3D9 | |||||
| m_data->m_texture->Release(); | |||||
| #else | |||||
| glDeleteTextures(1, &m_data->m_texture); | glDeleteTextures(1, &m_data->m_texture); | ||||
| #endif | |||||
| delete m_data; | delete m_data; | ||||
| } | } | ||||
| @@ -14,12 +14,6 @@ | |||||
| #include "lolgl.h" | #include "lolgl.h" | ||||
| #if defined _WIN32 && defined USE_D3D9 | |||||
| # define FAR | |||||
| # define NEAR | |||||
| # include <d3d9.h> | |||||
| #endif | |||||
| namespace lol | namespace lol | ||||
| { | { | ||||
| @@ -35,30 +29,8 @@ class VertexBufferData | |||||
| size_t m_size; | size_t m_size; | ||||
| #if defined USE_D3D9 | |||||
| IDirect3DDevice9 *m_dev; | |||||
| IDirect3DVertexBuffer9 *m_vbo; | |||||
| #else | |||||
| GLuint m_vbo; | GLuint m_vbo; | ||||
| uint8_t *m_memory; | uint8_t *m_memory; | ||||
| #endif | |||||
| }; | |||||
| // | |||||
| // The VertexDeclarationData class | |||||
| // ------------------------------- | |||||
| // | |||||
| class VertexDeclarationData | |||||
| { | |||||
| friend class VertexBuffer; | |||||
| friend class VertexDeclaration; | |||||
| #if defined USE_D3D9 | |||||
| IDirect3DDevice9 *m_dev; | |||||
| IDirect3DVertexDeclaration9 *m_vdecl; | |||||
| #else | |||||
| #endif | |||||
| }; | }; | ||||
| // | // | ||||
| @@ -80,8 +52,7 @@ VertexDeclaration::VertexDeclaration(VertexStreamBase const &s1, | |||||
| VertexStreamBase const &s10, | VertexStreamBase const &s10, | ||||
| VertexStreamBase const &s11, | VertexStreamBase const &s11, | ||||
| VertexStreamBase const &s12) | VertexStreamBase const &s12) | ||||
| : m_count(0), | |||||
| m_data(new VertexDeclarationData()) | |||||
| : m_count(0) | |||||
| { | { | ||||
| if (&s1 != &VertexStreamBase::Empty) AddStream(s1); | if (&s1 != &VertexStreamBase::Empty) AddStream(s1); | ||||
| if (&s2 != &VertexStreamBase::Empty) AddStream(s2); | if (&s2 != &VertexStreamBase::Empty) AddStream(s2); | ||||
| @@ -95,29 +66,15 @@ VertexDeclaration::VertexDeclaration(VertexStreamBase const &s1, | |||||
| if (&s10 != &VertexStreamBase::Empty) AddStream(s10); | if (&s10 != &VertexStreamBase::Empty) AddStream(s10); | ||||
| if (&s11 != &VertexStreamBase::Empty) AddStream(s11); | if (&s11 != &VertexStreamBase::Empty) AddStream(s11); | ||||
| if (&s12 != &VertexStreamBase::Empty) AddStream(s12); | if (&s12 != &VertexStreamBase::Empty) AddStream(s12); | ||||
| Initialize(); | |||||
| } | } | ||||
| VertexDeclaration::~VertexDeclaration() | VertexDeclaration::~VertexDeclaration() | ||||
| { | { | ||||
| #if defined USE_D3D9 | |||||
| if (FAILED(m_data->m_vdecl->Release())) | |||||
| Abort(); | |||||
| #else | |||||
| #endif | |||||
| delete m_data; | |||||
| } | } | ||||
| void VertexDeclaration::Bind() | void VertexDeclaration::Bind() | ||||
| { | { | ||||
| #if defined USE_D3D9 | |||||
| if (FAILED(m_data->m_dev->SetVertexDeclaration(m_data->m_vdecl))) | |||||
| Abort(); | |||||
| #else | |||||
| /* FIXME: Nothing to do? */ | /* FIXME: Nothing to do? */ | ||||
| #endif | |||||
| } | } | ||||
| void VertexDeclaration::DrawElements(MeshPrimitive type, int skip, int count) | void VertexDeclaration::DrawElements(MeshPrimitive type, int skip, int count) | ||||
| @@ -125,36 +82,6 @@ void VertexDeclaration::DrawElements(MeshPrimitive type, int skip, int count) | |||||
| if (count <= 0) | if (count <= 0) | ||||
| return; | return; | ||||
| #if defined USE_D3D9 | |||||
| switch (type.ToScalar()) | |||||
| { | |||||
| case MeshPrimitive::Triangles: | |||||
| if (FAILED(m_data->m_dev->DrawPrimitive(D3DPT_TRIANGLELIST, | |||||
| skip, count))) | |||||
| Abort(); | |||||
| break; | |||||
| case MeshPrimitive::TriangleStrips: | |||||
| if (FAILED(m_data->m_dev->DrawPrimitive(D3DPT_TRIANGLESTRIP, | |||||
| skip, count))) | |||||
| Abort(); | |||||
| break; | |||||
| case MeshPrimitive::TriangleFans: | |||||
| if (FAILED(m_data->m_dev->DrawPrimitive(D3DPT_TRIANGLEFAN, | |||||
| skip, count))) | |||||
| Abort(); | |||||
| break; | |||||
| case MeshPrimitive::Points: | |||||
| if (FAILED(m_data->m_dev->DrawPrimitive(D3DPT_POINTLIST, | |||||
| skip, count))) | |||||
| Abort(); | |||||
| break; | |||||
| case MeshPrimitive::Lines: | |||||
| if (FAILED(m_data->m_dev->DrawPrimitive(D3DPT_LINELIST, | |||||
| skip, count))) | |||||
| Abort(); | |||||
| break; | |||||
| } | |||||
| #else | |||||
| /* FIXME: this has nothing to do here! */ | /* FIXME: this has nothing to do here! */ | ||||
| switch (type.ToScalar()) | switch (type.ToScalar()) | ||||
| { | { | ||||
| @@ -174,7 +101,6 @@ void VertexDeclaration::DrawElements(MeshPrimitive type, int skip, int count) | |||||
| glDrawArrays(GL_LINES, skip, count); | glDrawArrays(GL_LINES, skip, count); | ||||
| break; | break; | ||||
| } | } | ||||
| #endif | |||||
| } | } | ||||
| void VertexDeclaration::DrawIndexedElements(MeshPrimitive type, int vbase, | void VertexDeclaration::DrawIndexedElements(MeshPrimitive type, int vbase, | ||||
| @@ -184,39 +110,6 @@ void VertexDeclaration::DrawIndexedElements(MeshPrimitive type, int vbase, | |||||
| if (count <= 0) | if (count <= 0) | ||||
| return; | return; | ||||
| #if defined USE_D3D9 | |||||
| switch (type.ToScalar()) | |||||
| { | |||||
| case MeshPrimitive::Triangles: | |||||
| count = count / 3; | |||||
| if (FAILED(m_data->m_dev->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, | |||||
| vbase, vskip, vcount, skip, count))) | |||||
| Abort(); | |||||
| break; | |||||
| case MeshPrimitive::TriangleStrips: | |||||
| count = count - 2; | |||||
| if (FAILED(m_data->m_dev->DrawIndexedPrimitive(D3DPT_TRIANGLESTRIP, | |||||
| vbase, vskip, vcount, skip, count))) | |||||
| Abort(); | |||||
| break; | |||||
| case MeshPrimitive::TriangleFans: | |||||
| count = count - 2; | |||||
| if (FAILED(m_data->m_dev->DrawIndexedPrimitive(D3DPT_TRIANGLEFAN, | |||||
| vbase, vskip, vcount, skip, count))) | |||||
| Abort(); | |||||
| break; | |||||
| case MeshPrimitive::Points: | |||||
| if (FAILED(m_data->m_dev->DrawIndexedPrimitive(D3DPT_POINTLIST, | |||||
| vbase, vskip, vcount, skip, count))) | |||||
| Abort(); | |||||
| break; | |||||
| case MeshPrimitive::Lines: | |||||
| if (FAILED(m_data->m_dev->DrawIndexedPrimitive(D3DPT_LINELIST, | |||||
| vbase, vskip, vcount, skip, count))) | |||||
| Abort(); | |||||
| break; | |||||
| } | |||||
| #else | |||||
| /* FIXME: this has nothing to do here! */ | /* FIXME: this has nothing to do here! */ | ||||
| switch (type.ToScalar()) | switch (type.ToScalar()) | ||||
| { | { | ||||
| @@ -246,23 +139,10 @@ void VertexDeclaration::DrawIndexedElements(MeshPrimitive type, int vbase, | |||||
| glDrawElements(GL_LINES, count, GL_UNSIGNED_SHORT, 0); | glDrawElements(GL_LINES, count, GL_UNSIGNED_SHORT, 0); | ||||
| break; | break; | ||||
| } | } | ||||
| #endif | |||||
| } | } | ||||
| void VertexDeclaration::Unbind() | void VertexDeclaration::Unbind() | ||||
| { | { | ||||
| #if defined USE_D3D9 | |||||
| int stream = -1; | |||||
| for (int i = 0; i < m_count; i++) | |||||
| if (m_streams[i].index != stream) | |||||
| { | |||||
| stream = m_streams[i].index; | |||||
| if (FAILED(m_data->m_dev->SetStreamSource(stream, 0, 0, 0))) | |||||
| Abort(); | |||||
| } | |||||
| /* "NULL is an invalid input to SetVertexDeclaration" (DX9 guide), so | |||||
| * we just don't touch the current vertex declaration. */ | |||||
| #else | |||||
| for (int i = 0; i < m_count; i++) | for (int i = 0; i < m_count; i++) | ||||
| { | { | ||||
| if (m_streams[i].reg >= 0) | if (m_streams[i].reg >= 0) | ||||
| @@ -275,7 +155,6 @@ void VertexDeclaration::Unbind() | |||||
| } | } | ||||
| } | } | ||||
| glBindBuffer(GL_ARRAY_BUFFER, 0); | glBindBuffer(GL_ARRAY_BUFFER, 0); | ||||
| #endif | |||||
| } | } | ||||
| void VertexDeclaration::SetStream(VertexBuffer *vb, ShaderAttrib attr1, | void VertexDeclaration::SetStream(VertexBuffer *vb, ShaderAttrib attr1, | ||||
| @@ -291,15 +170,10 @@ void VertexDeclaration::SetStream(VertexBuffer *vb, ShaderAttrib attr1, | |||||
| ShaderAttrib attr11, | ShaderAttrib attr11, | ||||
| ShaderAttrib attr12) | ShaderAttrib attr12) | ||||
| { | { | ||||
| #if defined USE_D3D9 | |||||
| // Don't bother in DirectX world, shader attributes are not used | |||||
| SetStream(vb, nullptr); | |||||
| #else | |||||
| ShaderAttrib attribs[12] = { attr1, attr2, attr3, attr4, attr5, attr6, | ShaderAttrib attribs[12] = { attr1, attr2, attr3, attr4, attr5, attr6, | ||||
| attr7, attr8, attr9, attr10, attr11, attr12 }; | attr7, attr8, attr9, attr10, attr11, attr12 }; | ||||
| SetStream(vb, attribs); | SetStream(vb, attribs); | ||||
| #endif | |||||
| } | } | ||||
| void VertexDeclaration::SetStream(VertexBuffer *vb, ShaderAttrib attribs[]) | void VertexDeclaration::SetStream(VertexBuffer *vb, ShaderAttrib attribs[]) | ||||
| @@ -307,39 +181,6 @@ void VertexDeclaration::SetStream(VertexBuffer *vb, ShaderAttrib attribs[]) | |||||
| if (!vb->m_data->m_size) | if (!vb->m_data->m_size) | ||||
| return; | return; | ||||
| #if defined USE_D3D9 | |||||
| /* Only the first item is required to know which stream this | |||||
| * is about; the rest of the information is stored in the | |||||
| * vertex declaration already. */ | |||||
| VertexUsage usage = VertexUsage((attr1.m_flags >> 16) & 0xffff); | |||||
| uint32_t index = attr1.m_flags & 0xffff; | |||||
| /* Find the stream number */ | |||||
| uint32_t usage_index = 0; | |||||
| int stream = -1; | |||||
| for (int i = 0; i < m_count; i++) | |||||
| if (m_streams[i].usage == usage) | |||||
| if (usage_index++ == index) | |||||
| { | |||||
| stream = m_streams[i].index; | |||||
| break; | |||||
| } | |||||
| /* Compute this stream's stride */ | |||||
| int stride = 0; | |||||
| for (int i = 0; i < m_count; i++) | |||||
| if (stream == m_streams[i].index) | |||||
| stride += m_streams[i].size; | |||||
| /* Now we know the stream index and the element stride */ | |||||
| /* FIXME: precompute most of the crap above! */ | |||||
| if (stream >= 0) | |||||
| { | |||||
| if (FAILED(m_data->m_dev->SetStreamSource(stream, vb->m_data->m_vbo, | |||||
| 0, stride))) | |||||
| Abort(); | |||||
| } | |||||
| #else | |||||
| glBindBuffer(GL_ARRAY_BUFFER, vb->m_data->m_vbo); | glBindBuffer(GL_ARRAY_BUFFER, vb->m_data->m_vbo); | ||||
| for (int n = 0; n < 12 && attribs[n].m_flags != (uint64_t)0 - 1; n++) | for (int n = 0; n < 12 && attribs[n].m_flags != (uint64_t)0 - 1; n++) | ||||
| { | { | ||||
| @@ -381,9 +222,9 @@ void VertexDeclaration::SetStream(VertexBuffer *vb, ShaderAttrib attribs[]) | |||||
| } | } | ||||
| /* Finally, we need to retrieve the type of the data */ | /* Finally, we need to retrieve the type of the data */ | ||||
| # if !defined GL_DOUBLE | |||||
| # define GL_DOUBLE 0 | |||||
| # endif | |||||
| #if !defined GL_DOUBLE | |||||
| # define GL_DOUBLE 0 | |||||
| #endif | |||||
| static struct { GLint size; GLenum type; } const tlut[] = | static struct { GLint size; GLenum type; } const tlut[] = | ||||
| { | { | ||||
| { 0, 0 }, | { 0, 0 }, | ||||
| @@ -419,10 +260,10 @@ void VertexDeclaration::SetStream(VertexBuffer *vb, ShaderAttrib attribs[]) | |||||
| || tlut[type_index].type == GL_DOUBLE | || tlut[type_index].type == GL_DOUBLE | ||||
| || tlut[type_index].type == GL_BYTE | || tlut[type_index].type == GL_BYTE | ||||
| || tlut[type_index].type == GL_UNSIGNED_BYTE | || tlut[type_index].type == GL_UNSIGNED_BYTE | ||||
| # if defined USE_GLEW && !defined __APPLE__ | |||||
| #if defined USE_GLEW && !defined __APPLE__ | |||||
| /* If this is not available, don't use it */ | /* If this is not available, don't use it */ | ||||
| || !glVertexAttribIPointer | || !glVertexAttribIPointer | ||||
| # endif | |||||
| #endif | |||||
| || false) | || false) | ||||
| { | { | ||||
| /* Normalize unsigned bytes by default, because it's usually | /* Normalize unsigned bytes by default, because it's usually | ||||
| @@ -433,97 +274,16 @@ void VertexDeclaration::SetStream(VertexBuffer *vb, ShaderAttrib attribs[]) | |||||
| tlut[type_index].type, normalize, | tlut[type_index].type, normalize, | ||||
| stride, (GLvoid const *)(uintptr_t)offset); | stride, (GLvoid const *)(uintptr_t)offset); | ||||
| } | } | ||||
| # if defined GL_VERSION_3_0 | |||||
| #if defined GL_VERSION_3_0 | |||||
| else | else | ||||
| { | { | ||||
| glVertexAttribIPointer((GLint)reg, tlut[type_index].size, | glVertexAttribIPointer((GLint)reg, tlut[type_index].size, | ||||
| tlut[type_index].type, | tlut[type_index].type, | ||||
| stride, (GLvoid const *)(uintptr_t)offset); | stride, (GLvoid const *)(uintptr_t)offset); | ||||
| } | } | ||||
| # endif | |||||
| } | |||||
| } | |||||
| #endif | #endif | ||||
| } | |||||
| void VertexDeclaration::Initialize() | |||||
| { | |||||
| #if defined USE_D3D9 | |||||
| static D3DVERTEXELEMENT9 const end_element[] = { D3DDECL_END() }; | |||||
| static D3DDECLTYPE const X = D3DDECLTYPE_UNUSED; | |||||
| static D3DDECLTYPE const tlut[] = | |||||
| { | |||||
| D3DDECLTYPE_UNUSED, | |||||
| #if LOL_FEATURE_CXX11_UNRESTRICTED_UNIONS | |||||
| X, D3DDECLTYPE_FLOAT16_2, X, D3DDECLTYPE_FLOAT16_4, /* half */ | |||||
| #endif | |||||
| D3DDECLTYPE_FLOAT1, D3DDECLTYPE_FLOAT2, D3DDECLTYPE_FLOAT3, | |||||
| D3DDECLTYPE_FLOAT4, /* float */ | |||||
| X, X, X, X, /* double */ | |||||
| X, X, X, X, /* int8_t */ | |||||
| X, X, X, D3DDECLTYPE_UBYTE4N, /* uint8_t */ | |||||
| X, D3DDECLTYPE_SHORT2N, X, D3DDECLTYPE_SHORT4N, /* int16_t */ | |||||
| X, D3DDECLTYPE_USHORT2N, X, D3DDECLTYPE_USHORT4N, /* uint16_t */ | |||||
| X, X, X, X, /* int32_t */ | |||||
| X, X, X, X, /* uint32_t */ | |||||
| }; | |||||
| static D3DDECLUSAGE const ulut[] = | |||||
| { | |||||
| D3DDECLUSAGE_POSITION, | |||||
| D3DDECLUSAGE_BLENDWEIGHT, | |||||
| D3DDECLUSAGE_BLENDINDICES, | |||||
| D3DDECLUSAGE_NORMAL, | |||||
| D3DDECLUSAGE_PSIZE, | |||||
| D3DDECLUSAGE_TEXCOORD, | |||||
| D3DDECLUSAGE_TANGENT, | |||||
| D3DDECLUSAGE_BINORMAL, | |||||
| D3DDECLUSAGE_TESSFACTOR, | |||||
| D3DDECLUSAGE_POSITIONT, | |||||
| D3DDECLUSAGE_COLOR, | |||||
| D3DDECLUSAGE_FOG, | |||||
| D3DDECLUSAGE_DEPTH, | |||||
| D3DDECLUSAGE_SAMPLE, | |||||
| }; | |||||
| D3DVERTEXELEMENT9 elements[12 + 1]; | |||||
| for (int n = 0; n < m_count; n++) | |||||
| { | |||||
| elements[n].Stream = m_streams[n].index; | |||||
| elements[n].Offset = 0; | |||||
| for (int i = 0; i < n; i++) | |||||
| if (m_streams[i].index == m_streams[n].index) | |||||
| elements[n].Offset += m_streams[i].size; | |||||
| if (m_streams[n].stream_type >= 0 | |||||
| && m_streams[n].stream_type < sizeof(tlut) / sizeof(*tlut)) | |||||
| elements[n].Type = tlut[m_streams[n].stream_type]; | |||||
| else | |||||
| elements[n].Type = D3DDECLTYPE_UNUSED; | |||||
| elements[n].Method = D3DDECLMETHOD_DEFAULT; | |||||
| if (m_streams[n].usage >= 0 | |||||
| && m_streams[n].usage < sizeof(ulut) / sizeof(*ulut)) | |||||
| elements[n].Usage = ulut[m_streams[n].usage]; | |||||
| else | |||||
| elements[n].Usage = D3DDECLUSAGE_POSITION; | |||||
| elements[n].UsageIndex = 0; | |||||
| for (int i = 0; i < n; i++) | |||||
| if (elements[i].Stream == elements[n].Stream | |||||
| && elements[i].Usage == elements[n].Usage) | |||||
| elements[n].UsageIndex++; | |||||
| } | |||||
| } | } | ||||
| elements[m_count] = end_element[0]; | |||||
| m_data->m_dev = (IDirect3DDevice9 *)Renderer::Get()->GetDevice(); | |||||
| if (FAILED(m_data->m_dev->CreateVertexDeclaration(elements, | |||||
| &m_data->m_vdecl))) | |||||
| Abort(); | |||||
| #else | |||||
| #endif | |||||
| } | } | ||||
| void VertexDeclaration::AddStream(VertexStreamBase const &s) | void VertexDeclaration::AddStream(VertexStreamBase const &s) | ||||
| @@ -596,28 +356,17 @@ VertexBuffer::VertexBuffer(size_t size) | |||||
| m_data->m_size = size; | m_data->m_size = size; | ||||
| if (!size) | if (!size) | ||||
| return; | return; | ||||
| #if defined USE_D3D9 | |||||
| m_data->m_dev = (IDirect3DDevice9 *)Renderer::Get()->GetDevice(); | |||||
| if (FAILED(m_data->m_dev->CreateVertexBuffer(size, D3DUSAGE_WRITEONLY, nullptr, | |||||
| D3DPOOL_MANAGED, &m_data->m_vbo, nullptr))) | |||||
| Abort(); | |||||
| #else | |||||
| glGenBuffers(1, &m_data->m_vbo); | glGenBuffers(1, &m_data->m_vbo); | ||||
| m_data->m_memory = new uint8_t[size]; | m_data->m_memory = new uint8_t[size]; | ||||
| #endif | |||||
| } | } | ||||
| VertexBuffer::~VertexBuffer() | VertexBuffer::~VertexBuffer() | ||||
| { | { | ||||
| if (m_data->m_size) | if (m_data->m_size) | ||||
| { | { | ||||
| #if defined USE_D3D9 | |||||
| if (FAILED(m_data->m_vbo->Release())) | |||||
| Abort(); | |||||
| #else | |||||
| glDeleteBuffers(1, &m_data->m_vbo); | glDeleteBuffers(1, &m_data->m_vbo); | ||||
| delete[] m_data->m_memory; | delete[] m_data->m_memory; | ||||
| #endif | |||||
| } | } | ||||
| delete m_data; | delete m_data; | ||||
| } | } | ||||
| @@ -631,31 +380,21 @@ void *VertexBuffer::Lock(size_t offset, size_t size) | |||||
| { | { | ||||
| if (!m_data->m_size) | if (!m_data->m_size) | ||||
| return nullptr; | return nullptr; | ||||
| #if defined USE_D3D9 | |||||
| void *ret; | |||||
| if (FAILED(m_data->m_vbo->Lock(offset, size, (void **)&ret, 0))) | |||||
| Abort(); | |||||
| return ret; | |||||
| #else | |||||
| /* FIXME: is there a way to use "size"? */ | /* FIXME: is there a way to use "size"? */ | ||||
| UNUSED(size); | UNUSED(size); | ||||
| return m_data->m_memory + offset; | return m_data->m_memory + offset; | ||||
| #endif | |||||
| } | } | ||||
| void VertexBuffer::Unlock() | void VertexBuffer::Unlock() | ||||
| { | { | ||||
| if (!m_data->m_size) | if (!m_data->m_size) | ||||
| return; | return; | ||||
| #if defined USE_D3D9 | |||||
| if (FAILED(m_data->m_vbo->Unlock())) | |||||
| Abort(); | |||||
| #else | |||||
| glBindBuffer(GL_ARRAY_BUFFER, m_data->m_vbo); | glBindBuffer(GL_ARRAY_BUFFER, m_data->m_vbo); | ||||
| glBufferData(GL_ARRAY_BUFFER, m_data->m_size, m_data->m_memory, | glBufferData(GL_ARRAY_BUFFER, m_data->m_size, m_data->m_memory, | ||||
| GL_STATIC_DRAW); | GL_STATIC_DRAW); | ||||
| glBindBuffer(GL_ARRAY_BUFFER, 0); | glBindBuffer(GL_ARRAY_BUFFER, 0); | ||||
| #endif | |||||
| } | } | ||||
| } /* namespace lol */ | } /* namespace lol */ | ||||
| @@ -135,8 +135,6 @@ private: | |||||
| public: | public: | ||||
| void Clear(ClearMask mask); | void Clear(ClearMask mask); | ||||
| void *GetDevice(); | |||||
| static void AddNew(ivec2 size); | static void AddNew(ivec2 size); | ||||
| static int GetCount(); | static int GetCount(); | ||||
| static Renderer* Get(int index = 0); | static Renderer* Get(int index = 0); | ||||
| @@ -304,9 +304,6 @@ public: | |||||
| private: | private: | ||||
| uint64_t m_flags; | uint64_t m_flags; | ||||
| #if defined USE_D3D9 | |||||
| uint32_t m_attrib; | |||||
| #endif | |||||
| }; | }; | ||||
| class ShaderData; | class ShaderData; | ||||
| @@ -236,7 +236,6 @@ public: | |||||
| VertexStreamBase GetStream(int index) const; | VertexStreamBase GetStream(int index) const; | ||||
| private: | private: | ||||
| void Initialize(); | |||||
| void AddStream(VertexStreamBase const &); | void AddStream(VertexStreamBase const &); | ||||
| struct | struct | ||||
| @@ -247,9 +246,6 @@ private: | |||||
| } m_streams[12 + 1]; | } m_streams[12 + 1]; | ||||
| int m_count; | int m_count; | ||||
| private: | |||||
| class VertexDeclarationData *m_data; | |||||
| }; | }; | ||||
| } /* namespace lol */ | } /* namespace lol */ | ||||
| @@ -20,10 +20,6 @@ | |||||
| # else | # else | ||||
| # include <SDL.h> | # include <SDL.h> | ||||
| # endif | # endif | ||||
| # if USE_D3D9 | |||||
| # include <d3d9.h> | |||||
| # include <SDL_syswm.h> | |||||
| # endif | |||||
| #endif | #endif | ||||
| #include "lolgl.h" | #include "lolgl.h" | ||||
| @@ -33,10 +29,6 @@ | |||||
| # include "platform/d3d9/d3d9input.h" | # include "platform/d3d9/d3d9input.h" | ||||
| #endif | #endif | ||||
| #if (USE_SDL || USE_OLD_SDL) && USE_D3D9 | |||||
| HWND g_hwnd = nullptr; | |||||
| #endif | |||||
| namespace lol | namespace lol | ||||
| { | { | ||||
| @@ -100,13 +92,6 @@ SdlAppDisplay::SdlAppDisplay(char const *title, ivec2 res) | |||||
| SDL_WM_SetCaption(title, nullptr); | SDL_WM_SetCaption(title, nullptr); | ||||
| # if USE_D3D9 | |||||
| SDL_Surface *video = SDL_SetVideoMode(res.x, res.y, 16, 0); | |||||
| SDL_SysWMinfo wminfo; | |||||
| SDL_VERSION(&wminfo.version); | |||||
| SDL_GetWMInfo(&wminfo); | |||||
| g_hwnd = wminfo.window; | |||||
| # else | |||||
| SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); | SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); | ||||
| SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16); | SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16); | ||||
| @@ -114,7 +99,6 @@ SdlAppDisplay::SdlAppDisplay(char const *title, ivec2 res) | |||||
| // and screen_h with the value of vidinfo after the call to | // and screen_h with the value of vidinfo after the call to | ||||
| // SDL_SetVideoMode. | // SDL_SetVideoMode. | ||||
| data->m_window = SDL_SetVideoMode(res.x, res.y, 0, SDL_OPENGL); | data->m_window = SDL_SetVideoMode(res.x, res.y, 0, SDL_OPENGL); | ||||
| # endif | |||||
| if (!data->m_window) | if (!data->m_window) | ||||
| { | { | ||||
| @@ -151,8 +135,6 @@ void SdlAppDisplay::SetResolution(ivec2 resolution) | |||||
| { | { | ||||
| #if USE_SDL | #if USE_SDL | ||||
| SDL_SetWindowSize(data->m_window, resolution.x, resolution.y); | SDL_SetWindowSize(data->m_window, resolution.x, resolution.y); | ||||
| #elif USE_OLD_SDL && USE_D3D9 | |||||
| //Not implemented | |||||
| #elif USE_OLD_SDL | #elif USE_OLD_SDL | ||||
| //Not implemented | //Not implemented | ||||
| #endif | #endif | ||||
| @@ -161,8 +143,6 @@ void SdlAppDisplay::SetPosition(ivec2 position) | |||||
| { | { | ||||
| #if USE_SDL | #if USE_SDL | ||||
| SDL_SetWindowPosition(data->m_window, position.x, position.y); | SDL_SetWindowPosition(data->m_window, position.x, position.y); | ||||
| #elif USE_OLD_SDL && USE_D3D9 | |||||
| //Not implemented | |||||
| #elif USE_OLD_SDL | #elif USE_OLD_SDL | ||||
| //Not implemented | //Not implemented | ||||
| #endif | #endif | ||||
| @@ -174,29 +154,15 @@ void SdlAppDisplay::Enable() | |||||
| //TODO: Should we do that: ? | //TODO: Should we do that: ? | ||||
| SDL_GL_MakeCurrent(data->m_window, data->m_glcontext); | SDL_GL_MakeCurrent(data->m_window, data->m_glcontext); | ||||
| #endif | #endif | ||||
| #if (USE_SDL || USE_OLD_SDL) && defined USE_D3D9 | |||||
| IDirect3DDevice9 *d3d_dev = (IDirect3DDevice9 *)Renderer::Get()->GetDevice(); | |||||
| HRESULT hr; | |||||
| hr = d3d_dev->BeginScene(); | |||||
| if (FAILED(hr)) | |||||
| Abort(); | |||||
| #endif | |||||
| } | } | ||||
| void SdlAppDisplay::Disable() | void SdlAppDisplay::Disable() | ||||
| { | { | ||||
| #if USE_SDL | |||||
| #if USE_SDL | |||||
| SDL_GL_SwapWindow(data->m_window); | SDL_GL_SwapWindow(data->m_window); | ||||
| #elif USE_OLD_SDL && USE_D3D9 | |||||
| hr = d3d_dev->EndScene(); | |||||
| if (FAILED(hr)) | |||||
| Abort(); | |||||
| hr = d3d_dev->Present(nullptr, nullptr, nullptr, nullptr); | |||||
| if (FAILED(hr)) | |||||
| Abort(); | |||||
| #elif USE_OLD_SDL | |||||
| #elif USE_OLD_SDL | |||||
| SDL_GL_SwapBuffers(); | SDL_GL_SwapBuffers(); | ||||
| #endif | |||||
| #endif | |||||
| } | } | ||||
| #if USE_SDL | #if USE_SDL | ||||
| @@ -209,8 +175,6 @@ const char* SceneDisplay::GetPhysicalName(int index) | |||||
| { | { | ||||
| return SDL_GetDisplayName(index); | return SDL_GetDisplayName(index); | ||||
| } | } | ||||
| #elif USE_OLD_SDL && USE_D3D9 | |||||
| // Not implemented | |||||
| #elif USE_OLD_SDL | #elif USE_OLD_SDL | ||||
| // Not implemented | // Not implemented | ||||
| #endif | #endif | ||||
| @@ -130,11 +130,16 @@ private: | |||||
| /** Back buffer: where to render to. */ | /** Back buffer: where to render to. */ | ||||
| Framebuffer *m_backbuffer = nullptr; | Framebuffer *m_backbuffer = nullptr; | ||||
| Shader *m_pp_shader = nullptr; | |||||
| VertexDeclaration *m_pp_vdecl; | |||||
| ShaderUniform m_pp_texture; | |||||
| ShaderAttrib m_pp_coord; | |||||
| VertexBuffer *m_pp_vbo; | |||||
| struct postprocess | |||||
| { | |||||
| Shader *m_shader = nullptr; | |||||
| VertexBuffer *m_vbo = nullptr; | |||||
| VertexDeclaration *m_vdecl = nullptr; | |||||
| ShaderUniform m_texture; | |||||
| ShaderAttrib m_coord; | |||||
| } | |||||
| m_pp; | |||||
| /* Sources are shared by all scenes. | /* Sources are shared by all scenes. | ||||
| * Renderers are scene-dependent. They get the primitive in the identical | * Renderers are scene-dependent. They get the primitive in the identical | ||||
| @@ -189,18 +194,18 @@ Scene::Scene(ivec2 size) | |||||
| : data(new SceneData()) | : data(new SceneData()) | ||||
| { | { | ||||
| data->m_backbuffer = new Framebuffer(size); | data->m_backbuffer = new Framebuffer(size); | ||||
| data->m_pp_shader = Shader::Create(LOLFX_RESOURCE_NAME(postprocess)); | |||||
| data->m_pp_coord = data->m_pp_shader->GetAttribLocation(VertexUsage::Position, 0); | |||||
| data->m_pp_vdecl = new VertexDeclaration(VertexStream<vec2>(VertexUsage::Position)); | |||||
| data->m_pp_texture = data->m_pp_shader->GetUniformLocation("u_texture"); | |||||
| data->m_pp.m_shader = Shader::Create(LOLFX_RESOURCE_NAME(postprocess)); | |||||
| data->m_pp.m_coord = data->m_pp.m_shader->GetAttribLocation(VertexUsage::Position, 0); | |||||
| data->m_pp.m_vdecl = new VertexDeclaration(VertexStream<vec2>(VertexUsage::Position)); | |||||
| data->m_pp.m_texture = data->m_pp.m_shader->GetUniformLocation("u_texture"); | |||||
| array<vec2> quad { vec2( 1.0, 1.0), vec2(-1.0, -1.0), vec2( 1.0, -1.0), | array<vec2> quad { vec2( 1.0, 1.0), vec2(-1.0, -1.0), vec2( 1.0, -1.0), | ||||
| vec2(-1.0, -1.0), vec2( 1.0, 1.0), vec2(-1.0, 1.0), }; | vec2(-1.0, -1.0), vec2( 1.0, 1.0), vec2(-1.0, 1.0), }; | ||||
| data->m_pp_vbo = new VertexBuffer(quad.bytes()); | |||||
| void *vertices = data->m_pp_vbo->Lock(0, 0); | |||||
| memcpy(vertices, &quad[0], quad.bytes()); | |||||
| data->m_pp_vbo->Unlock(); | |||||
| data->m_pp.m_vbo = new VertexBuffer(quad.bytes()); | |||||
| void *vertices = data->m_pp.m_vbo->Lock(0, 0); | |||||
| memcpy(vertices, quad.data(), quad.bytes()); | |||||
| data->m_pp.m_vbo->Unlock(); | |||||
| /* Create a default orthographic camera, in case the user doesn’t. */ | /* Create a default orthographic camera, in case the user doesn’t. */ | ||||
| data->m_default_cam = new Camera(); | data->m_default_cam = new Camera(); | ||||
| @@ -212,7 +217,7 @@ Scene::Scene(ivec2 size) | |||||
| data->m_tile_api.m_shader = 0; | data->m_tile_api.m_shader = 0; | ||||
| data->m_tile_api.m_palette_shader = 0; | data->m_tile_api.m_palette_shader = 0; | ||||
| data->m_tile_api.m_vdecl = new VertexDeclaration(VertexStream<vec3>(VertexUsage::Position), | data->m_tile_api.m_vdecl = new VertexDeclaration(VertexStream<vec3>(VertexUsage::Position), | ||||
| VertexStream<vec2>(VertexUsage::TexCoord)); | |||||
| VertexStream<vec2>(VertexUsage::TexCoord)); | |||||
| data->m_line_api.m_shader = 0; | data->m_line_api.m_shader = 0; | ||||
| data->m_line_api.m_vdecl = new VertexDeclaration(VertexStream<vec4,vec4>(VertexUsage::Position, VertexUsage::Color)); | data->m_line_api.m_vdecl = new VertexDeclaration(VertexStream<vec4,vec4>(VertexUsage::Position, VertexUsage::Color)); | ||||
| @@ -618,13 +623,13 @@ void Scene::render(float seconds) | |||||
| data->m_backbuffer->Unbind(); | data->m_backbuffer->Unbind(); | ||||
| /* Now blit the offline buffer */ | /* Now blit the offline buffer */ | ||||
| data->m_pp_shader->Bind(); | |||||
| data->m_pp_shader->SetUniform(data->m_pp_texture, data->m_backbuffer->GetTextureUniform(), 0); | |||||
| data->m_pp_vdecl->SetStream(data->m_pp_vbo, data->m_pp_coord); | |||||
| data->m_pp_vdecl->Bind(); | |||||
| data->m_pp_vdecl->DrawElements(MeshPrimitive::Triangles, 0, 6); | |||||
| data->m_pp_vdecl->Unbind(); | |||||
| data->m_pp_shader->Unbind(); | |||||
| data->m_pp.m_shader->Bind(); | |||||
| data->m_pp.m_shader->SetUniform(data->m_pp.m_texture, data->m_backbuffer->GetTextureUniform(), 0); | |||||
| data->m_pp.m_vdecl->SetStream(data->m_pp.m_vbo, data->m_pp.m_coord); | |||||
| data->m_pp.m_vdecl->Bind(); | |||||
| data->m_pp.m_vdecl->DrawElements(MeshPrimitive::Triangles, 0, 6); | |||||
| data->m_pp.m_vdecl->Unbind(); | |||||
| data->m_pp.m_shader->Unbind(); | |||||
| } | } | ||||
| //----------------------------------------------------------------------------- | //----------------------------------------------------------------------------- | ||||
| @@ -669,9 +674,7 @@ void Scene::render_tiles() // XXX: rename to Blit() | |||||
| rc.SetBlendEquation(BlendEquation::Add, BlendEquation::Max); | rc.SetBlendEquation(BlendEquation::Add, BlendEquation::Max); | ||||
| rc.SetAlphaFunc(AlphaFunc::GreaterOrEqual, 0.01f); | rc.SetAlphaFunc(AlphaFunc::GreaterOrEqual, 0.01f); | ||||
| #if defined USE_D3D9 | |||||
| /* TODO */ | |||||
| #elif (defined USE_GLEW || defined HAVE_GL_2X) && !defined HAVE_GLES_2X | |||||
| #if (defined USE_GLEW || defined HAVE_GL_2X) && !defined HAVE_GLES_2X | |||||
| glEnable(GL_TEXTURE_2D); | glEnable(GL_TEXTURE_2D); | ||||
| #endif | #endif | ||||
| @@ -766,9 +769,7 @@ void Scene::render_tiles() // XXX: rename to Blit() | |||||
| } | } | ||||
| #if defined USE_D3D9 | |||||
| /* TODO */ | |||||
| #elif (defined USE_GLEW || defined HAVE_GL_2X) && !defined HAVE_GLES_2X | |||||
| #if (defined USE_GLEW || defined HAVE_GL_2X) && !defined HAVE_GLES_2X | |||||
| glDisable(GL_TEXTURE_2D); | glDisable(GL_TEXTURE_2D); | ||||
| #endif | #endif | ||||
| } | } | ||||
| @@ -18,11 +18,6 @@ | |||||
| # define WIN32_LEAN_AND_MEAN | # define WIN32_LEAN_AND_MEAN | ||||
| # include <windows.h> | # include <windows.h> | ||||
| # undef WIN32_LEAN_AND_MEAN | # undef WIN32_LEAN_AND_MEAN | ||||
| # if defined USE_D3D9 | |||||
| # define FAR | |||||
| # define NEAR | |||||
| # include <d3d9.h> | |||||
| # endif | |||||
| #endif | #endif | ||||
| #include "textureimage-private.h" | #include "textureimage-private.h" | ||||
| @@ -20,11 +20,6 @@ | |||||
| # define WIN32_LEAN_AND_MEAN | # define WIN32_LEAN_AND_MEAN | ||||
| # include <windows.h> | # include <windows.h> | ||||
| # undef WIN32_LEAN_AND_MEAN | # undef WIN32_LEAN_AND_MEAN | ||||
| # if defined USE_D3D9 | |||||
| # define FAR | |||||
| # define NEAR | |||||
| # include <d3d9.h> | |||||
| # endif | |||||
| #endif | #endif | ||||
| #include "textureimage-private.h" | #include "textureimage-private.h" | ||||
| @@ -11,9 +11,6 @@ | |||||
| #include <lol/engine-internal.h> | #include <lol/engine-internal.h> | ||||
| #if defined _WIN32 | #if defined _WIN32 | ||||
| # if defined USE_D3D9 | |||||
| # include <d3d9.h> | |||||
| # endif | |||||
| # define WIN32_LEAN_AND_MEAN | # define WIN32_LEAN_AND_MEAN | ||||
| # include <windows.h> | # include <windows.h> | ||||
| # undef WIN32_LEAN_AND_MEAN | # undef WIN32_LEAN_AND_MEAN | ||||
| @@ -61,8 +58,7 @@ void Video::SetDebugRenderMode(DebugRenderMode d) | |||||
| case DebugRenderMode::Normal: | case DebugRenderMode::Normal: | ||||
| case DebugRenderMode::UV: | case DebugRenderMode::UV: | ||||
| { | { | ||||
| #if defined USE_D3D9 | |||||
| #elif defined HAVE_GLES_2X | |||||
| #if defined HAVE_GLES_2X | |||||
| #elif defined USE_GLEW || defined HAVE_GL_2X | #elif defined USE_GLEW || defined HAVE_GL_2X | ||||
| glEnable(GL_CULL_FACE); | glEnable(GL_CULL_FACE); | ||||
| glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); | glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); | ||||
| @@ -71,8 +67,7 @@ void Video::SetDebugRenderMode(DebugRenderMode d) | |||||
| } | } | ||||
| case DebugRenderMode::Wireframe: | case DebugRenderMode::Wireframe: | ||||
| { | { | ||||
| #if defined USE_D3D9 | |||||
| #elif defined HAVE_GLES_2X | |||||
| #if defined HAVE_GLES_2X | |||||
| #elif defined USE_GLEW || defined HAVE_GL_2X | #elif defined USE_GLEW || defined HAVE_GL_2X | ||||
| glDisable(GL_CULL_FACE); | glDisable(GL_CULL_FACE); | ||||
| glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); | glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); | ||||
| @@ -101,9 +96,7 @@ void Video::Destroy() | |||||
| void Video::Capture(uint32_t *buffer) | void Video::Capture(uint32_t *buffer) | ||||
| { | { | ||||
| #if defined USE_D3D9 | |||||
| /* TODO */ | |||||
| #elif defined USE_GLEW || defined HAVE_GL_2X || defined HAVE_GLEX_2X | |||||
| #if defined USE_GLEW || defined HAVE_GL_2X || defined HAVE_GLEX_2X | |||||
| GLint v[4]; | GLint v[4]; | ||||
| glGetIntegerv(GL_VIEWPORT, v); | glGetIntegerv(GL_VIEWPORT, v); | ||||
| int width = v[2], height = v[3]; | int width = v[2], height = v[3]; | ||||