Merge pull request #808 from wesnoth/remove_sdl_gpu
Remove SDL_GPU #idfefs and library
This commit is contained in:
commit
0a4ff56d76
83 changed files with 0 additions and 57981 deletions
|
@ -1,157 +0,0 @@
|
|||
set(SDL_gpu_INSTALL_BY_DEFAULT OFF)
|
||||
|
||||
option(SDL_gpu_INSTALL "Install SDL_gpu libs, includes, and CMake scripts" ${SDL_gpu_INSTALL_BY_DEFAULT})
|
||||
option(SDL_gpu_BUILD_DEBUG "Build with debugging symbols" ON)
|
||||
option(SDL_gpu_BUILD_SHARED "Build SDL_gpu shared libraries" OFF)
|
||||
option(SDL_gpu_BUILD_STATIC "Build SDL_gpu static libraries" ON)
|
||||
option(SDL_gpu_USE_SDL1 "Use SDL 1.2 headers and library instead of SDL 2" ON)
|
||||
option(SDL_gpu_DISABLE_OPENGL "Disable OpenGL renderers. Overrides specific OpenGL renderer flags." OFF)
|
||||
option(SDL_gpu_DISABLE_GLES "Disable OpenGLES renderers. Overrides specific GLES renderer flags." ON)
|
||||
option(SDL_gpu_DISABLE_OPENGL_1_BASE "Disable OpenGL 1 BASE renderer" OFF)
|
||||
option(SDL_gpu_DISABLE_OPENGL_1 "Disable OpenGL 1.X renderer" OFF)
|
||||
option(SDL_gpu_DISABLE_OPENGL_2 "Disable OpenGL 2.X renderer" OFF)
|
||||
option(SDL_gpu_DISABLE_OPENGL_3 "Disable OpenGL 3.X renderer" OFF)
|
||||
option(SDL_gpu_DISABLE_OPENGL_4 "Disable OpenGL 4.X renderer" OFF)
|
||||
option(SDL_gpu_DISABLE_GLES_1 "Disable OpenGLES 1.X renderer" OFF)
|
||||
option(SDL_gpu_DISABLE_GLES_2 "Disable OpenGLES 2.X renderer" OFF)
|
||||
option(SDL_gpu_DISABLE_GLES_3 "Disable OpenGLES 3.X renderer" OFF)
|
||||
|
||||
set(SDL_gpu_VERSION 0.8.1)
|
||||
|
||||
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/CMake_scripts)
|
||||
|
||||
if ( SDL_gpu_BUILD_DEBUG )
|
||||
SET(CMAKE_BUILD_TYPE Debug)
|
||||
else ( SDL_gpu_BUILD_DEBUG )
|
||||
SET(CMAKE_BUILD_TYPE Release)
|
||||
endif ( SDL_gpu_BUILD_DEBUG )
|
||||
|
||||
# Find the package for SDL or SDL2
|
||||
if ( SDL_gpu_USE_SDL1 )
|
||||
find_package(SDL REQUIRED)
|
||||
|
||||
if ( NOT SDL_FOUND )
|
||||
message ( FATAL_ERROR "SDL not found!" )
|
||||
endif ( NOT SDL_FOUND )
|
||||
|
||||
include_directories(${SDL_INCLUDE_DIR})
|
||||
link_libraries(${SDL_LIBRARY})
|
||||
else ( SDL_gpu_USE_SDL1 )
|
||||
find_package(SDL2 REQUIRED)
|
||||
|
||||
if ( NOT SDL2_FOUND )
|
||||
message ( FATAL_ERROR "SDL2 not found!" )
|
||||
endif ( NOT SDL2_FOUND )
|
||||
|
||||
if ( NOT SDL2MAIN_LIBRARY )
|
||||
message ( WARNING "SDL2MAIN_LIBRARY is NOTFOUND" )
|
||||
SET( SDL2MAIN_LIBRARY "" )
|
||||
endif ( NOT SDL2MAIN_LIBRARY )
|
||||
|
||||
include_directories(${SDL2_INCLUDE_DIR})
|
||||
link_libraries(${SDL2MAIN_LIBRARY} ${SDL2_LIBRARY})
|
||||
endif( SDL_gpu_USE_SDL1 )
|
||||
|
||||
# Find the package for OpenGL
|
||||
if (SDL_gpu_DISABLE_OPENGL)
|
||||
add_definitions("-DSDL_GPU_DISABLE_OPENGL")
|
||||
else (SDL_gpu_DISABLE_OPENGL)
|
||||
|
||||
find_package(OpenGL REQUIRED)
|
||||
include_directories(${OPENGL_INCLUDE_DIR})
|
||||
link_libraries (${OPENGL_LIBRARIES})
|
||||
|
||||
if (SDL_gpu_DISABLE_OPENGL_1_BASE)
|
||||
add_definitions("-DSDL_GPU_DISABLE_OPENGL_1_BASE")
|
||||
endif (SDL_gpu_DISABLE_OPENGL_1_BASE)
|
||||
if (SDL_gpu_DISABLE_OPENGL_1)
|
||||
add_definitions("-DSDL_GPU_DISABLE_OPENGL_1")
|
||||
endif (SDL_gpu_DISABLE_OPENGL_1)
|
||||
if (SDL_gpu_DISABLE_OPENGL_2)
|
||||
add_definitions("-DSDL_GPU_DISABLE_OPENGL_2")
|
||||
endif (SDL_gpu_DISABLE_OPENGL_2)
|
||||
if (SDL_gpu_DISABLE_OPENGL_3)
|
||||
add_definitions("-DSDL_GPU_DISABLE_OPENGL_3")
|
||||
endif (SDL_gpu_DISABLE_OPENGL_3)
|
||||
if (SDL_gpu_DISABLE_OPENGL_4)
|
||||
add_definitions("-DSDL_GPU_DISABLE_OPENGL_4")
|
||||
endif (SDL_gpu_DISABLE_OPENGL_4)
|
||||
|
||||
# If glew is not found here, we’ll use the bundled version
|
||||
find_package(GLEW)
|
||||
if(NOT GLEW_FOUND)
|
||||
message(" Using bundled version of GLEW")
|
||||
endif(NOT GLEW_FOUND)
|
||||
|
||||
|
||||
if (NOT SDL_gpu_DISABLE_OPENGL)
|
||||
if(GLEW_FOUND)
|
||||
# Look in the GL subdirectory, too.
|
||||
foreach(GL_DIR ${GLEW_INCLUDE_DIRS})
|
||||
set(GLEW_GL_DIRS ${GLEW_GL_DIRS} "${GL_DIR}/GL")
|
||||
endforeach(GL_DIR ${GLEW_INCLUDE_DIRS})
|
||||
|
||||
include_directories(${GLEW_INCLUDE_DIRS} ${GLEW_GL_DIRS})
|
||||
link_libraries (${GLEW_LIBRARIES})
|
||||
else(GLEW_FOUND)
|
||||
SET(SDL_gpu_SRCS ${SDL_gpu_SRCS} externals/glew/glew.c)
|
||||
SET(SDL_gpu_HDRS ${SDL_gpu_HDRS} externals/glew/glew.h externals/glew/glxew.h externals/glew/wglew.h)
|
||||
endif(GLEW_FOUND)
|
||||
endif(NOT SDL_gpu_DISABLE_OPENGL)
|
||||
|
||||
endif (SDL_gpu_DISABLE_OPENGL)
|
||||
|
||||
# Find the package for OpenGLES
|
||||
if (SDL_gpu_DISABLE_GLES)
|
||||
add_definitions("-DSDL_GPU_DISABLE_GLES")
|
||||
else (SDL_gpu_DISABLE_GLES)
|
||||
|
||||
find_package(OpenGLES REQUIRED)
|
||||
include_directories(${OPENGLES_INCLUDE_DIR})
|
||||
link_libraries (${OPENGLES_LIBRARIES})
|
||||
|
||||
if (SDL_gpu_DISABLE_GLES_1)
|
||||
add_definitions("-DSDL_GPU_DISABLE_GLES_1")
|
||||
endif (SDL_gpu_DISABLE_GLES_1)
|
||||
if (SDL_gpu_DISABLE_GLES_2)
|
||||
add_definitions("-DSDL_GPU_DISABLE_GLES_2")
|
||||
endif (SDL_gpu_DISABLE_GLES_2)
|
||||
if (SDL_gpu_DISABLE_GLES_3)
|
||||
add_definitions("-DSDL_GPU_DISABLE_GLES_3")
|
||||
endif (SDL_gpu_DISABLE_GLES_3)
|
||||
|
||||
endif (SDL_gpu_DISABLE_GLES)
|
||||
|
||||
# If stb-image is not found here, we’ll use the bundled version
|
||||
find_package(STBI)
|
||||
if(NOT STBI_FOUND)
|
||||
message(" Using bundled version of stb-image")
|
||||
endif(NOT STBI_FOUND)
|
||||
|
||||
find_package(STBI_write)
|
||||
if(NOT STBI_WRITE_FOUND)
|
||||
message(" Using bundled version of stb-image-write")
|
||||
endif(NOT STBI_WRITE_FOUND)
|
||||
|
||||
if(NOT WIN32)
|
||||
find_library(M_LIB m)
|
||||
link_libraries(${M_LIB})
|
||||
endif (NOT WIN32)
|
||||
|
||||
# Make local includes look in the right places
|
||||
include_directories(SDL_gpu)
|
||||
include_directories(SDL_gpu/GL_common)
|
||||
include_directories(SDL_gpu/OpenGL_1_BASE)
|
||||
include_directories(SDL_gpu/OpenGL_1)
|
||||
include_directories(SDL_gpu/OpenGL_2)
|
||||
include_directories(SDL_gpu/OpenGL_3)
|
||||
include_directories(SDL_gpu/GLES_1)
|
||||
include_directories(SDL_gpu/GLES_2)
|
||||
include_directories(SDL_gpu/externals/glew)
|
||||
include_directories(SDL_gpu/externals/stb_image)
|
||||
|
||||
|
||||
add_definitions("-Wall -std=c99 -pedantic -DSTBI_FAILURE_USERMSG")
|
||||
|
||||
# Build the SDL_gpu library.
|
||||
add_subdirectory(SDL_gpu)
|
|
@ -1,88 +0,0 @@
|
|||
# - Try to find ffmpeg libraries (libavcodec, libavformat and libavutil)
|
||||
# Once done this will define
|
||||
#
|
||||
# FFMPEG_FOUND - system has ffmpeg or libav
|
||||
# FFMPEG_INCLUDE_DIR - the ffmpeg include directory
|
||||
# FFMPEG_LIBRARIES - Link these to use ffmpeg
|
||||
# FFMPEG_LIBAVCODEC
|
||||
# FFMPEG_LIBAVFORMAT
|
||||
# FFMPEG_LIBAVUTIL
|
||||
# FFMPEG_LIBSWSCALE
|
||||
#
|
||||
# Copyright (c) 2008 Andreas Schneider <mail@cynapses.org>
|
||||
# Modified for other libraries by Lasse Kärkkäinen <tronic>
|
||||
# Modified for Hedgewars by Stepik777
|
||||
# Modified for SDL_gpu by Jonathan Dearborn
|
||||
#
|
||||
# Redistribution and use is allowed according to the terms of the New
|
||||
# BSD license.
|
||||
#
|
||||
|
||||
if (FFMPEG_LIBRARIES AND FFMPEG_INCLUDE_DIR)
|
||||
# in cache already
|
||||
set(FFMPEG_FOUND TRUE)
|
||||
else (FFMPEG_LIBRARIES AND FFMPEG_INCLUDE_DIR)
|
||||
# use pkg-config to get the directories and then use these values
|
||||
# in the FIND_PATH() and FIND_LIBRARY() calls
|
||||
find_package(PkgConfig)
|
||||
if (PKG_CONFIG_FOUND)
|
||||
pkg_check_modules(_FFMPEG_AVCODEC libavcodec)
|
||||
pkg_check_modules(_FFMPEG_AVFORMAT libavformat)
|
||||
pkg_check_modules(_FFMPEG_AVUTIL libavutil)
|
||||
pkg_check_modules(_FFMPEG_SWSCALE libswscale)
|
||||
endif (PKG_CONFIG_FOUND)
|
||||
|
||||
find_path(FFMPEG_AVCODEC_INCLUDE_DIR
|
||||
NAMES libavcodec/avcodec.h
|
||||
PATHS ${_FFMPEG_AVCODEC_INCLUDE_DIRS} /usr/include /usr/local/include /opt/local/include /sw/include
|
||||
PATH_SUFFIXES ffmpeg libav
|
||||
)
|
||||
|
||||
find_library(FFMPEG_LIBAVCODEC
|
||||
NAMES avcodec
|
||||
PATHS ${_FFMPEG_AVCODEC_LIBRARY_DIRS} /usr/lib /usr/local/lib /opt/local/lib /sw/lib
|
||||
)
|
||||
|
||||
find_library(FFMPEG_LIBAVFORMAT
|
||||
NAMES avformat
|
||||
PATHS ${_FFMPEG_AVFORMAT_LIBRARY_DIRS} /usr/lib /usr/local/lib /opt/local/lib /sw/lib
|
||||
)
|
||||
|
||||
find_library(FFMPEG_LIBAVUTIL
|
||||
NAMES avutil
|
||||
PATHS ${_FFMPEG_AVUTIL_LIBRARY_DIRS} /usr/lib /usr/local/lib /opt/local/lib /sw/lib
|
||||
)
|
||||
|
||||
find_library(FFMPEG_LIBSWSCALE
|
||||
NAMES swscale
|
||||
PATHS ${_FFMPEG_SWSCALE_LIBRARY_DIRS} /usr/lib /usr/local/lib /opt/local/lib /sw/lib
|
||||
)
|
||||
|
||||
if (FFMPEG_LIBAVCODEC AND FFMPEG_LIBAVFORMAT)
|
||||
set(FFMPEG_FOUND TRUE)
|
||||
endif()
|
||||
|
||||
if (FFMPEG_FOUND)
|
||||
set(FFMPEG_INCLUDE_DIR ${FFMPEG_AVCODEC_INCLUDE_DIR})
|
||||
|
||||
set(FFMPEG_LIBRARIES
|
||||
${FFMPEG_LIBAVCODEC}
|
||||
${FFMPEG_LIBAVFORMAT}
|
||||
${FFMPEG_LIBAVUTIL}
|
||||
${FFMPEG_LIBSWSCALE}
|
||||
)
|
||||
|
||||
endif (FFMPEG_FOUND)
|
||||
|
||||
if (FFMPEG_FOUND)
|
||||
if (NOT FFMPEG_FIND_QUIETLY)
|
||||
message(STATUS "Found FFMPEG or Libav: ${FFMPEG_LIBRARIES}, ${FFMPEG_INCLUDE_DIR}")
|
||||
endif (NOT FFMPEG_FIND_QUIETLY)
|
||||
else (FFMPEG_FOUND)
|
||||
if (FFMPEG_FIND_REQUIRED)
|
||||
message(FATAL_ERROR "Could not find libavcodec or libavformat or libavutil")
|
||||
endif (FFMPEG_FIND_REQUIRED)
|
||||
endif (FFMPEG_FOUND)
|
||||
|
||||
endif (FFMPEG_LIBRARIES AND FFMPEG_INCLUDE_DIR)
|
||||
|
|
@ -1,100 +0,0 @@
|
|||
#-------------------------------------------------------------------
|
||||
# This file is part of the CMake build system for OGRE
|
||||
# (Object-oriented Graphics Rendering Engine)
|
||||
# For the latest info, see http://www.ogre3d.org/
|
||||
#
|
||||
# The contents of this file are placed in the public domain. Feel
|
||||
# free to make use of it in any way you like.
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
# - Try to find OpenGLES
|
||||
# Once done this will define
|
||||
#
|
||||
# OPENGLES_FOUND - system has OpenGLES
|
||||
# OPENGLES_INCLUDE_DIR - the GL include directory
|
||||
# OPENGLES_LIBRARIES - Link these to use OpenGLES
|
||||
|
||||
include(FindPkgMacros)
|
||||
|
||||
IF (WIN32)
|
||||
|
||||
IF(0) # Disabled, untill further testing
|
||||
IF (CYGWIN)
|
||||
|
||||
FIND_PATH(OPENGLES_INCLUDE_DIR GLES/gl.h )
|
||||
|
||||
FIND_LIBRARY(OPENGLES_gl_LIBRARY libgles_cm )
|
||||
|
||||
ELSE (CYGWIN)
|
||||
|
||||
IF(BORLAND)
|
||||
SET (OPENGLES_gl_LIBRARY import32 CACHE STRING "OpenGL library for win32")
|
||||
ELSE(BORLAND)
|
||||
#MS compiler - todo - fix the following line:
|
||||
SET (OPENGLES_gl_LIBRARY ${OGRE_SOURCE_DIR}/Dependencies/lib/release/libgles_cm.lib CACHE STRING "OpenGL library for win32")
|
||||
ENDIF(BORLAND)
|
||||
|
||||
ENDIF (CYGWIN)
|
||||
ENDIF()
|
||||
|
||||
ELSE (WIN32)
|
||||
|
||||
IF (APPLE)
|
||||
|
||||
create_search_paths(/Developer/Platforms)
|
||||
findpkg_framework(OpenGLES)
|
||||
set(OPENGLES_gl_LIBRARY "-framework OpenGLES")
|
||||
|
||||
ELSE(APPLE)
|
||||
|
||||
IF(0) # Disabled, untill further testing
|
||||
|
||||
|
||||
FIND_PATH(OPENGLES_INCLUDE_DIR GLES/gl.h
|
||||
/usr/openwin/share/include
|
||||
/opt/graphics/OpenGL/include /usr/X11R6/include
|
||||
/usr/include
|
||||
)
|
||||
|
||||
|
||||
FIND_LIBRARY(OPENGLES_gl_LIBRARY
|
||||
NAMES GLES_CM
|
||||
PATHS /opt/graphics/OpenGL/lib
|
||||
/usr/openwin/lib
|
||||
/usr/shlib /usr/X11R6/lib
|
||||
/usr/lib
|
||||
)
|
||||
|
||||
# On Unix OpenGL most certainly always requires X11.
|
||||
# Feel free to tighten up these conditions if you don't
|
||||
# think this is always true.
|
||||
# It's not true on OSX.
|
||||
|
||||
IF (OPENGLES_gl_LIBRARY)
|
||||
IF(NOT X11_FOUND)
|
||||
INCLUDE(FindX11)
|
||||
ENDIF(NOT X11_FOUND)
|
||||
IF (X11_FOUND)
|
||||
IF (NOT APPLE)
|
||||
SET (OPENGLES_LIBRARIES ${X11_LIBRARIES})
|
||||
ENDIF (NOT APPLE)
|
||||
ENDIF (X11_FOUND)
|
||||
ENDIF (OPENGLES_gl_LIBRARY)
|
||||
ENDIF()
|
||||
|
||||
ENDIF(APPLE)
|
||||
ENDIF (WIN32)
|
||||
|
||||
SET( OPENGLES_FOUND "NO" )
|
||||
IF(OPENGLES_gl_LIBRARY)
|
||||
|
||||
SET( OPENGLES_LIBRARIES ${OPENGLES_gl_LIBRARY} ${OPENGLES_LIBRARIES})
|
||||
|
||||
SET( OPENGLES_FOUND "YES" )
|
||||
|
||||
ENDIF(OPENGLES_gl_LIBRARY)
|
||||
|
||||
MARK_AS_ADVANCED(
|
||||
OPENGLES_INCLUDE_DIR
|
||||
OPENGLES_gl_LIBRARY
|
||||
)
|
|
@ -1,142 +0,0 @@
|
|||
#-------------------------------------------------------------------
|
||||
# This file is part of the CMake build system for OGRE
|
||||
# (Object-oriented Graphics Rendering Engine)
|
||||
# For the latest info, see http://www.ogre3d.org/
|
||||
#
|
||||
# The contents of this file are placed in the public domain. Feel
|
||||
# free to make use of it in any way you like.
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
##################################################################
|
||||
# Provides some common functionality for the FindPackage modules
|
||||
##################################################################
|
||||
|
||||
# Begin processing of package
|
||||
macro(findpkg_begin PREFIX)
|
||||
if (NOT ${PREFIX}_FIND_QUIETLY)
|
||||
message(STATUS "Looking for ${PREFIX}...")
|
||||
endif ()
|
||||
endmacro(findpkg_begin)
|
||||
|
||||
# Display a status message unless FIND_QUIETLY is set
|
||||
macro(pkg_message PREFIX)
|
||||
if (NOT ${PREFIX}_FIND_QUIETLY)
|
||||
message(STATUS ${ARGN})
|
||||
endif ()
|
||||
endmacro(pkg_message)
|
||||
|
||||
# Get environment variable, define it as ENV_$var and make sure backslashes are converted to forward slashes
|
||||
macro(getenv_path VAR)
|
||||
set(ENV_${VAR} $ENV{${VAR}})
|
||||
# replace won't work if var is blank
|
||||
if (ENV_${VAR})
|
||||
string( REGEX REPLACE "\\\\" "/" ENV_${VAR} ${ENV_${VAR}} )
|
||||
endif ()
|
||||
endmacro(getenv_path)
|
||||
|
||||
# Construct search paths for includes and libraries from a PREFIX_PATH
|
||||
macro(create_search_paths PREFIX)
|
||||
foreach(dir ${${PREFIX}_PREFIX_PATH})
|
||||
set(${PREFIX}_INC_SEARCH_PATH ${${PREFIX}_INC_SEARCH_PATH}
|
||||
${dir}/include ${dir}/include/${PREFIX} ${dir}/Headers)
|
||||
set(${PREFIX}_LIB_SEARCH_PATH ${${PREFIX}_LIB_SEARCH_PATH}
|
||||
${dir}/lib ${dir}/lib/${PREFIX} ${dir}/Libs)
|
||||
endforeach(dir)
|
||||
set(${PREFIX}_FRAMEWORK_SEARCH_PATH ${${PREFIX}_PREFIX_PATH})
|
||||
endmacro(create_search_paths)
|
||||
|
||||
# clear cache variables if a certain variable changed
|
||||
macro(clear_if_changed TESTVAR)
|
||||
# test against internal check variable
|
||||
if (NOT "${${TESTVAR}}" STREQUAL "${${TESTVAR}_INT_CHECK}")
|
||||
message(STATUS "${TESTVAR} changed.")
|
||||
foreach(var ${ARGN})
|
||||
set(${var} "NOTFOUND" CACHE STRING "x" FORCE)
|
||||
endforeach(var)
|
||||
endif ()
|
||||
set(${TESTVAR}_INT_CHECK ${${TESTVAR}} CACHE INTERNAL "x" FORCE)
|
||||
endmacro(clear_if_changed)
|
||||
|
||||
# Try to get some hints from pkg-config, if available
|
||||
macro(use_pkgconfig PREFIX PKGNAME)
|
||||
find_package(PkgConfig)
|
||||
if (PKG_CONFIG_FOUND)
|
||||
pkg_check_modules(${PREFIX} ${PKGNAME})
|
||||
endif ()
|
||||
endmacro (use_pkgconfig)
|
||||
|
||||
# Couple a set of release AND debug libraries (or frameworks)
|
||||
macro(make_library_set PREFIX)
|
||||
if (${PREFIX}_FWK)
|
||||
set(${PREFIX} ${${PREFIX}_FWK})
|
||||
elseif (${PREFIX}_REL AND ${PREFIX}_DBG)
|
||||
set(${PREFIX} optimized ${${PREFIX}_REL} debug ${${PREFIX}_DBG})
|
||||
elseif (${PREFIX}_REL)
|
||||
set(${PREFIX} ${${PREFIX}_REL})
|
||||
elseif (${PREFIX}_DBG)
|
||||
set(${PREFIX} ${${PREFIX}_DBG})
|
||||
endif ()
|
||||
endmacro(make_library_set)
|
||||
|
||||
# Generate debug names from given release names
|
||||
macro(get_debug_names PREFIX)
|
||||
foreach(i ${${PREFIX}})
|
||||
set(${PREFIX}_DBG ${${PREFIX}_DBG} ${i}d ${i}D ${i}_d ${i}_D ${i}_debug ${i})
|
||||
endforeach(i)
|
||||
endmacro(get_debug_names)
|
||||
|
||||
# Add the parent dir from DIR to VAR
|
||||
macro(add_parent_dir VAR DIR)
|
||||
get_filename_component(${DIR}_TEMP "${${DIR}}/.." ABSOLUTE)
|
||||
set(${VAR} ${${VAR}} ${${DIR}_TEMP})
|
||||
endmacro(add_parent_dir)
|
||||
|
||||
# Do the final processing for the package find.
|
||||
macro(findpkg_finish PREFIX)
|
||||
# skip if already processed during this run
|
||||
if (NOT ${PREFIX}_FOUND)
|
||||
if (${PREFIX}_INCLUDE_DIR AND ${PREFIX}_LIBRARY)
|
||||
set(${PREFIX}_FOUND TRUE)
|
||||
set(${PREFIX}_INCLUDE_DIRS ${${PREFIX}_INCLUDE_DIR})
|
||||
set(${PREFIX}_LIBRARIES ${${PREFIX}_LIBRARY})
|
||||
if (NOT ${PREFIX}_FIND_QUIETLY)
|
||||
message(STATUS "Found ${PREFIX}: ${${PREFIX}_LIBRARIES}")
|
||||
endif ()
|
||||
else ()
|
||||
if (NOT ${PREFIX}_FIND_QUIETLY)
|
||||
message(STATUS "Could not locate ${PREFIX}")
|
||||
endif ()
|
||||
if (${PREFIX}_FIND_REQUIRED)
|
||||
message(FATAL_ERROR "Required library ${PREFIX} not found! Install the library (including dev packages) and try again. If the library is already installed, set the missing variables manually in cmake.")
|
||||
endif ()
|
||||
endif ()
|
||||
|
||||
mark_as_advanced(${PREFIX}_INCLUDE_DIR ${PREFIX}_LIBRARY ${PREFIX}_LIBRARY_REL ${PREFIX}_LIBRARY_DBG ${PREFIX}_LIBRARY_FWK)
|
||||
endif ()
|
||||
endmacro(findpkg_finish)
|
||||
|
||||
|
||||
# Slightly customised framework finder
|
||||
MACRO(findpkg_framework fwk)
|
||||
IF(APPLE)
|
||||
SET(${fwk}_FRAMEWORK_PATH
|
||||
${${fwk}_FRAMEWORK_SEARCH_PATH}
|
||||
${CMAKE_FRAMEWORK_PATH}
|
||||
~/Library/Frameworks
|
||||
/Library/Frameworks
|
||||
/System/Library/Frameworks
|
||||
/Network/Library/Frameworks
|
||||
/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS3.0.sdk/System/Library/Frameworks/
|
||||
)
|
||||
FOREACH(dir ${${fwk}_FRAMEWORK_PATH})
|
||||
SET(fwkpath ${dir}/${fwk}.framework)
|
||||
IF(EXISTS ${fwkpath})
|
||||
SET(${fwk}_FRAMEWORK_INCLUDES ${${fwk}_FRAMEWORK_INCLUDES}
|
||||
${fwkpath}/Headers ${fwkpath}/PrivateHeaders)
|
||||
if (NOT ${fwk}_LIBRARY_FWK)
|
||||
SET(${fwk}_LIBRARY_FWK "-framework ${fwk}")
|
||||
endif ()
|
||||
ENDIF(EXISTS ${fwkpath})
|
||||
ENDFOREACH(dir)
|
||||
ENDIF(APPLE)
|
||||
ENDMACRO(findpkg_framework)
|
|
@ -1,180 +0,0 @@
|
|||
# Locate SDL2 library
|
||||
# This module defines
|
||||
# SDL2_LIBRARY, the name of the library to link against
|
||||
# SDL2_FOUND, if false, do not try to link to SDL2
|
||||
# SDL2_INCLUDE_DIR, where to find SDL.h
|
||||
#
|
||||
# This module responds to the the flag:
|
||||
# SDL2_BUILDING_LIBRARY
|
||||
# If this is defined, then no SDL2_main will be linked in because
|
||||
# only applications need main().
|
||||
# Otherwise, it is assumed you are building an application and this
|
||||
# module will attempt to locate and set the the proper link flags
|
||||
# as part of the returned SDL2_LIBRARY variable.
|
||||
#
|
||||
# Don't forget to include SDL2main.h and SDL2main.m your project for the
|
||||
# OS X framework based version. (Other versions link to -lSDL2main which
|
||||
# this module will try to find on your behalf.) Also for OS X, this
|
||||
# module will automatically add the -framework Cocoa on your behalf.
|
||||
#
|
||||
#
|
||||
# Additional Note: If you see an empty SDL2_LIBRARY_TEMP in your configuration
|
||||
# and no SDL2_LIBRARY, it means CMake did not find your SDL2 library
|
||||
# (SDL2.dll, libsdl2.so, SDL2.framework, etc).
|
||||
# Set SDL2_LIBRARY_TEMP to point to your SDL2 library, and configure again.
|
||||
# Similarly, if you see an empty SDL2MAIN_LIBRARY, you should set this value
|
||||
# as appropriate. These values are used to generate the final SDL2_LIBRARY
|
||||
# variable, but when these values are unset, SDL2_LIBRARY does not get created.
|
||||
#
|
||||
#
|
||||
# $SDL2DIR is an environment variable that would
|
||||
# correspond to the ./configure --prefix=$SDL2DIR
|
||||
# used in building SDL2.
|
||||
# l.e.galup 9-20-02
|
||||
#
|
||||
# Modified by Eric Wing.
|
||||
# Added code to assist with automated building by using environmental variables
|
||||
# and providing a more controlled/consistent search behavior.
|
||||
# Added new modifications to recognize OS X frameworks and
|
||||
# additional Unix paths (FreeBSD, etc).
|
||||
# Also corrected the header search path to follow "proper" SDL2 guidelines.
|
||||
# Added a search for SDL2main which is needed by some platforms.
|
||||
# Added a search for threads which is needed by some platforms.
|
||||
# Added needed compile switches for MinGW.
|
||||
#
|
||||
# On OSX, this will prefer the Framework version (if found) over others.
|
||||
# People will have to manually change the cache values of
|
||||
# SDL2_LIBRARY to override this selection or set the CMake environment
|
||||
# CMAKE_INCLUDE_PATH to modify the search paths.
|
||||
#
|
||||
# Note that the header path has changed from SDL2/SDL.h to just SDL.h
|
||||
# This needed to change because "proper" SDL2 convention
|
||||
# is #include "SDL.h", not <SDL2/SDL.h>. This is done for portability
|
||||
# reasons because not all systems place things in SDL2/ (see FreeBSD).
|
||||
#
|
||||
# Ported by Johnny Patterson. This is a literal port for SDL2 of the FindSDL.cmake
|
||||
# module with the minor edit of changing "SDL" to "SDL2" where necessary. This
|
||||
# was not created for redistribution, and exists temporarily pending official
|
||||
# SDL2 CMake modules.
|
||||
|
||||
#=============================================================================
|
||||
# Copyright 2003-2009 Kitware, Inc.
|
||||
#
|
||||
# Distributed under the OSI-approved BSD License (the "License");
|
||||
# see accompanying file Copyright.txt for details.
|
||||
#
|
||||
# This software is distributed WITHOUT ANY WARRANTY; without even the
|
||||
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
# See the License for more information.
|
||||
#=============================================================================
|
||||
# (To distribute this file outside of CMake, substitute the full
|
||||
# License text for the above reference.)
|
||||
|
||||
FIND_PATH(SDL2_INCLUDE_DIR SDL.h
|
||||
HINTS
|
||||
$ENV{SDL2DIR}
|
||||
PATH_SUFFIXES include/SDL2 include
|
||||
PATHS
|
||||
~/Library/Frameworks
|
||||
/Library/Frameworks
|
||||
/usr/local/include/SDL2
|
||||
/usr/include/SDL2
|
||||
/sw # Fink
|
||||
/opt/local # DarwinPorts
|
||||
/opt/csw # Blastwave
|
||||
/opt
|
||||
)
|
||||
#MESSAGE("SDL2_INCLUDE_DIR is ${SDL2_INCLUDE_DIR}")
|
||||
|
||||
FIND_LIBRARY(SDL2_LIBRARY_TEMP
|
||||
NAMES SDL2
|
||||
HINTS
|
||||
$ENV{SDL2DIR}
|
||||
PATH_SUFFIXES lib64 lib
|
||||
PATHS
|
||||
/sw
|
||||
/opt/local
|
||||
/opt/csw
|
||||
/opt
|
||||
)
|
||||
|
||||
#MESSAGE("SDL2_LIBRARY_TEMP is ${SDL2_LIBRARY_TEMP}")
|
||||
|
||||
IF(NOT SDL2_BUILDING_LIBRARY)
|
||||
IF(NOT ${SDL2_INCLUDE_DIR} MATCHES ".framework")
|
||||
# Non-OS X framework versions expect you to also dynamically link to
|
||||
# SDL2main. This is mainly for Windows and OS X. Other (Unix) platforms
|
||||
# seem to provide SDL2main for compatibility even though they don't
|
||||
# necessarily need it.
|
||||
FIND_LIBRARY(SDL2MAIN_LIBRARY
|
||||
NAMES SDL2main
|
||||
HINTS
|
||||
$ENV{SDL2DIR}
|
||||
PATH_SUFFIXES lib64 lib
|
||||
PATHS
|
||||
/sw
|
||||
/opt/local
|
||||
/opt/csw
|
||||
/opt
|
||||
)
|
||||
ENDIF(NOT ${SDL2_INCLUDE_DIR} MATCHES ".framework")
|
||||
ENDIF(NOT SDL2_BUILDING_LIBRARY)
|
||||
|
||||
# SDL2 may require threads on your system.
|
||||
# The Apple build may not need an explicit flag because one of the
|
||||
# frameworks may already provide it.
|
||||
# But for non-OSX systems, I will use the CMake Threads package.
|
||||
IF(NOT APPLE)
|
||||
FIND_PACKAGE(Threads)
|
||||
ENDIF(NOT APPLE)
|
||||
|
||||
# MinGW needs an additional library, mwindows
|
||||
# It's total link flags should look like -lmingw32 -lSDL2main -lSDL2 -lmwindows
|
||||
# (Actually on second look, I think it only needs one of the m* libraries.)
|
||||
IF(MINGW)
|
||||
SET(MINGW32_LIBRARY mingw32 CACHE STRING "mwindows for MinGW")
|
||||
ENDIF(MINGW)
|
||||
|
||||
SET(SDL2_FOUND "NO")
|
||||
IF(SDL2_LIBRARY_TEMP)
|
||||
# For SDL2main
|
||||
IF(NOT SDL2_BUILDING_LIBRARY)
|
||||
IF(SDL2MAIN_LIBRARY)
|
||||
SET(SDL2_LIBRARY_TEMP ${SDL2MAIN_LIBRARY} ${SDL2_LIBRARY_TEMP})
|
||||
ENDIF(SDL2MAIN_LIBRARY)
|
||||
ENDIF(NOT SDL2_BUILDING_LIBRARY)
|
||||
|
||||
# For OS X, SDL2 uses Cocoa as a backend so it must link to Cocoa.
|
||||
# CMake doesn't display the -framework Cocoa string in the UI even
|
||||
# though it actually is there if I modify a pre-used variable.
|
||||
# I think it has something to do with the CACHE STRING.
|
||||
# So I use a temporary variable until the end so I can set the
|
||||
# "real" variable in one-shot.
|
||||
IF(APPLE)
|
||||
SET(SDL2_LIBRARY_TEMP ${SDL2_LIBRARY_TEMP} "-framework Cocoa")
|
||||
ENDIF(APPLE)
|
||||
|
||||
# For threads, as mentioned Apple doesn't need this.
|
||||
# In fact, there seems to be a problem if I used the Threads package
|
||||
# and try using this line, so I'm just skipping it entirely for OS X.
|
||||
IF(NOT APPLE)
|
||||
SET(SDL2_LIBRARY_TEMP ${SDL2_LIBRARY_TEMP} ${CMAKE_THREAD_LIBS_INIT})
|
||||
ENDIF(NOT APPLE)
|
||||
|
||||
# For MinGW library
|
||||
IF(MINGW)
|
||||
SET(SDL2_LIBRARY_TEMP ${MINGW32_LIBRARY} ${SDL2_LIBRARY_TEMP})
|
||||
ENDIF(MINGW)
|
||||
|
||||
# Set the final string here so the GUI reflects the final state.
|
||||
SET(SDL2_LIBRARY ${SDL2_LIBRARY_TEMP} CACHE STRING "Where the SDL2 Library can be found")
|
||||
# Set the temp variable to INTERNAL so it is not seen in the CMake GUI
|
||||
SET(SDL2_LIBRARY_TEMP "${SDL2_LIBRARY_TEMP}" CACHE INTERNAL "")
|
||||
|
||||
SET(SDL2_FOUND "YES")
|
||||
ENDIF(SDL2_LIBRARY_TEMP)
|
||||
|
||||
INCLUDE(FindPackageHandleStandardArgs)
|
||||
|
||||
FIND_PACKAGE_HANDLE_STANDARD_ARGS(SDL2
|
||||
REQUIRED_VARS SDL2_LIBRARY SDL2_INCLUDE_DIR)
|
1781
src/SDL_gpu/Doxyfile
1781
src/SDL_gpu/Doxyfile
File diff suppressed because it is too large
Load diff
|
@ -1 +0,0 @@
|
|||
This directory includes the source code of the SDL_gpu library. It doesn't include the sources for the demos or the tools found in the original source tree. The CMake recipe in the top directory (where this file is located) was modified, when updating the SDL_gpu sources make sure not to overwrite it.
|
|
@ -1,65 +0,0 @@
|
|||
SDL_gpu, a library for making hardware-accelerated 2D graphics easy.
|
||||
by Jonathan Dearborn
|
||||
|
||||
SDL_gpu is licensed under the terms of the MIT License.
|
||||
See LICENSE.txt for details of the usage license granted to you for this code.
|
||||
|
||||
|
||||
=============
|
||||
LATEST SOURCE
|
||||
=============
|
||||
|
||||
SDL_gpu is hosted on Google Code (http://code.google.com/p/sdl-gpu). You can check out the latest version of the source code with Subversion:
|
||||
svn checkout http://sdl-gpu.googlecode.com/svn/trunk/ sdl-gpu
|
||||
|
||||
To check out everything, including the pre-generated documentation:
|
||||
svn checkout http://sdl-gpu.googlecode.com/svn/ sdl-gpu
|
||||
|
||||
For just the current library code, use:
|
||||
svn checkout http://sdl-gpu.googlecode.com/svn/trunk/ sdl-gpu
|
||||
|
||||
|
||||
============
|
||||
DEPENDENCIES
|
||||
============
|
||||
|
||||
SDL 1.2 or SDL 2.0 (www.libsdl.org)
|
||||
A rendering backend
|
||||
Currently implemented: OpenGL 1.1, OpenGL 2.0, OpenGL 3.0, OpenGL ES 1.1, OpenGL ES 2.0
|
||||
|
||||
|
||||
========
|
||||
BUILDING
|
||||
========
|
||||
|
||||
SDL_gpu uses CMake (www.cmake.org) to coordinate the library build process. CMake is available as a GUI program or on the command line.
|
||||
|
||||
For Linux/UNIX systems, run CMake in the base directory:
|
||||
cmake -G "Unix Makefiles"
|
||||
make
|
||||
sudo make install
|
||||
|
||||
For Linux/UNIX systems, changing the default installation directory can be done like so:
|
||||
cmake -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX=/usr
|
||||
|
||||
For Windows systems, you can use cmake-gui and select appropriate options in there (warning: cmake-gui is messy!).
|
||||
|
||||
|
||||
===================
|
||||
INCLUDING / LINKING
|
||||
===================
|
||||
|
||||
Add the include for SDL_gpu.h to your sources. Link to SDL_gpu (libSDL_gpu.a) or SDL2_gpu (if you use SDL2).
|
||||
|
||||
|
||||
=============
|
||||
DOCUMENTATION
|
||||
=============
|
||||
|
||||
Documentation is automatically generated with Doxygen (http://sourceforge.net/projects/doxygen).
|
||||
Pre-generated documentation can be found in the repository's base documentation directory.
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -1,28 +0,0 @@
|
|||
LOCAL_PATH := $(call my-dir)
|
||||
|
||||
include $(CLEAR_VARS)
|
||||
|
||||
LOCAL_MODULE := SDL2_gpu
|
||||
|
||||
SDL_GPU_DIR := ./
|
||||
STB_IMAGE_DIR := $(SDL_GPU_DIR)/externals/stb_image
|
||||
|
||||
LOCAL_CFLAGS := -I$(LOCAL_PATH)/../SDL/include -I$(LOCAL_PATH)/$(SDL_GPU_DIR) -I$(LOCAL_PATH)/$(RENDERER_DIR) -I$(LOCAL_PATH)/$(STB_IMAGE_DIR)
|
||||
|
||||
LOCAL_SRC_FILES := $(SDL_GPU_DIR)/SDL_gpu.c \
|
||||
$(SDL_GPU_DIR)/SDL_gpu_Renderer.c \
|
||||
$(SDL_GPU_DIR)/SDL_gpuShapes.c \
|
||||
$(SDL_GPU_DIR)/GL_common/SDL_gpu_GL_matrix.c \
|
||||
$(SDL_GPU_DIR)/GLES_1/SDL_gpu_GLES_1.c \
|
||||
$(SDL_GPU_DIR)/GLES_2/SDL_gpu_GLES_2.c \
|
||||
$(STB_IMAGE_DIR)/stb_image.c \
|
||||
$(STB_IMAGE_DIR)/stb_image_write.c
|
||||
|
||||
|
||||
LOCAL_CFLAGS += -DSDL_GPU_DISABLE_OPENGL -DSTBI_FAILURE_USERMSG -O3
|
||||
#LOCAL_LDLIBS += -llog -lGLESv1_CM
|
||||
LOCAL_LDLIBS += -llog -lGLESv2 -lGLESv1_CM
|
||||
|
||||
LOCAL_SHARED_LIBRARIES := SDL2
|
||||
|
||||
include $(BUILD_SHARED_LIBRARY)
|
|
@ -1,109 +0,0 @@
|
|||
set(SDL_gpu_SRCS
|
||||
SDL_gpu.c
|
||||
SDL_gpuShapes.c
|
||||
SDL_gpu_Renderer.c
|
||||
GL_common/SDL_gpu_GL_matrix.c
|
||||
OpenGL_1_BASE/SDL_gpu_OpenGL_1_BASE.c
|
||||
OpenGL_1/SDL_gpu_OpenGL_1.c
|
||||
OpenGL_2/SDL_gpu_OpenGL_2.c
|
||||
OpenGL_3/SDL_gpu_OpenGL_3.c
|
||||
GLES_1/SDL_gpu_GLES_1.c
|
||||
GLES_2/SDL_gpu_GLES_2.c
|
||||
)
|
||||
|
||||
set(SDL_gpu_HDRS
|
||||
SDL_gpu.h
|
||||
GL_common/SDL_gpu_GL_matrix.h
|
||||
GL_common/SDL_gpu_GL_common.inl
|
||||
GL_common/SDL_gpuShapes_GL_common.inl
|
||||
OpenGL_1_BASE/SDL_gpu_OpenGL_1_BASE.h
|
||||
OpenGL_1/SDL_gpu_OpenGL_1.h
|
||||
OpenGL_2/SDL_gpu_OpenGL_2.h
|
||||
OpenGL_3/SDL_gpu_OpenGL_3.h
|
||||
GLES_1/SDL_gpu_GLES_1.h
|
||||
GLES_2/SDL_gpu_GLES_2.h
|
||||
)
|
||||
|
||||
if(STBI_FOUND)
|
||||
include_directories(${STBI_INCLUDE_DIR})
|
||||
link_libraries (${STBI_LIBRARY})
|
||||
else(STBI_FOUND)
|
||||
SET(SDL_gpu_SRCS ${SDL_gpu_SRCS} externals/stb_image/stb_image.c)
|
||||
SET(SDL_gpu_HDRS ${SDL_gpu_HDRS} externals/stb_image/stb_image.h)
|
||||
endif(STBI_FOUND)
|
||||
|
||||
if(STBI_WRITE_FOUND)
|
||||
include_directories(${STBI_WRITE_INCLUDE_DIR})
|
||||
link_libraries (${STBI_WRITE_LIBRARY})
|
||||
else(STBI_WRITE_FOUND)
|
||||
SET(SDL_gpu_SRCS ${SDL_gpu_SRCS} externals/stb_image/stb_image_write.c)
|
||||
SET(SDL_gpu_HDRS ${SDL_gpu_HDRS} externals/stb_image/stb_image_write.h)
|
||||
endif(STBI_WRITE_FOUND)
|
||||
|
||||
|
||||
set(SDL_gpu_install_HDRS
|
||||
SDL_gpu.h
|
||||
GL_common/SDL_gpu_GL_matrix.h
|
||||
OpenGL_1_BASE/SDL_gpu_OpenGL_1_BASE.h
|
||||
OpenGL_1/SDL_gpu_OpenGL_1.h
|
||||
OpenGL_2/SDL_gpu_OpenGL_2.h
|
||||
OpenGL_3/SDL_gpu_OpenGL_3.h
|
||||
GLES_1/SDL_gpu_GLES_1.h
|
||||
GLES_2/SDL_gpu_GLES_2.h
|
||||
)
|
||||
|
||||
# Set the appropriate library name so SDL_gpu and SDL2_gpu can co-exist.
|
||||
if ( SDL_gpu_USE_SDL1)
|
||||
set (SDL_gpu_OUTPUT_NAME "SDL_gpu")
|
||||
else ( SDL_gpu_USE_SDL1)
|
||||
set (SDL_gpu_OUTPUT_NAME "SDL2_gpu")
|
||||
endif ( SDL_gpu_USE_SDL1)
|
||||
|
||||
# Build the shared library (.so or .dll)
|
||||
if(SDL_gpu_BUILD_SHARED)
|
||||
add_library(SDL_gpu_shared SHARED
|
||||
${SDL_gpu_HDRS}
|
||||
${SDL_gpu_SRCS}
|
||||
)
|
||||
set_target_properties(SDL_gpu_shared PROPERTIES
|
||||
OUTPUT_NAME ${SDL_gpu_OUTPUT_NAME}
|
||||
CLEAN_DIRECT_OUTPUT 1
|
||||
VERSION ${SDL_gpu_VERSION}
|
||||
)
|
||||
set_target_properties(SDL_gpu_shared PROPERTIES LINKER_LANGUAGE C)
|
||||
endif()
|
||||
|
||||
# Build the static library (.a)
|
||||
if(SDL_gpu_BUILD_STATIC)
|
||||
add_library(SDL_gpu STATIC
|
||||
${SDL_gpu_HDRS}
|
||||
${SDL_gpu_SRCS}
|
||||
)
|
||||
set_target_properties(SDL_gpu PROPERTIES
|
||||
OUTPUT_NAME ${SDL_gpu_OUTPUT_NAME}
|
||||
CLEAN_DIRECT_OUTPUT 1
|
||||
VERSION ${SDL_gpu_VERSION}
|
||||
)
|
||||
set_target_properties(SDL_gpu PROPERTIES LINKER_LANGUAGE C)
|
||||
endif()
|
||||
|
||||
# These are used to create visual studio folders.
|
||||
source_group(Common FILES ${SDL_gpu_SRCS} ${SDL_gpu_HDRS})
|
||||
|
||||
# Install the library
|
||||
if(SDL_gpu_INSTALL)
|
||||
# install headers
|
||||
install(FILES ${SDL_gpu_install_HDRS} DESTINATION include/SDL)
|
||||
|
||||
# install libraries
|
||||
if(SDL_gpu_BUILD_SHARED)
|
||||
install(TARGETS SDL_gpu_shared EXPORT SDL_gpu-targets DESTINATION lib)
|
||||
endif()
|
||||
if(SDL_gpu_BUILD_STATIC)
|
||||
install(TARGETS SDL_gpu EXPORT SDL_gpu-targets DESTINATION lib)
|
||||
endif()
|
||||
|
||||
# install build system hooks for third-party apps
|
||||
#install(EXPORT SDL_gpu-targets DESTINATION ./SDL_gpu)
|
||||
#install(FILES SDL_gpuConfig.cmake DESTINATION ./SDL_gpu)
|
||||
endif(SDL_gpu_INSTALL)
|
|
@ -1,52 +0,0 @@
|
|||
#include "SDL_gpu_GLES_1.h"
|
||||
|
||||
#if defined(SDL_GPU_DISABLE_GLES) || defined(SDL_GPU_DISABLE_GLES_1)
|
||||
|
||||
// Dummy implementations
|
||||
GPU_Renderer* GPU_CreateRenderer_GLES_1(GPU_RendererID request) {return NULL;}
|
||||
void GPU_FreeRenderer_GLES_1(GPU_Renderer* renderer) {}
|
||||
|
||||
#else
|
||||
|
||||
|
||||
// Most of the code pulled in from here...
|
||||
#define SDL_GPU_USE_GLES
|
||||
#define SDL_GPU_USE_GL_TIER2
|
||||
#define SDL_GPU_GL_TIER 2
|
||||
#define SDL_GPU_GLES_MAJOR_VERSION 1
|
||||
#define SDL_GPU_DISABLE_SHADERS
|
||||
#define SDL_GPU_APPLY_TRANSFORMS_TO_GL_STACK
|
||||
#define SDL_GPU_NO_VAO
|
||||
#include "../GL_common/SDL_gpu_GL_common.inl"
|
||||
#include "../GL_common/SDL_gpuShapes_GL_common.inl"
|
||||
|
||||
|
||||
GPU_Renderer* GPU_CreateRenderer_GLES_1(GPU_RendererID request)
|
||||
{
|
||||
GPU_Renderer* renderer = (GPU_Renderer*)malloc(sizeof(GPU_Renderer));
|
||||
if(renderer == NULL)
|
||||
return NULL;
|
||||
|
||||
memset(renderer, 0, sizeof(GPU_Renderer));
|
||||
|
||||
renderer->id = request;
|
||||
renderer->id.id = GPU_RENDERER_GLES_1;
|
||||
renderer->shader_language = GPU_LANGUAGE_NONE;
|
||||
renderer->shader_version = 0;
|
||||
|
||||
renderer->current_context_target = NULL;
|
||||
|
||||
SET_COMMON_FUNCTIONS(renderer);
|
||||
|
||||
return renderer;
|
||||
}
|
||||
|
||||
void GPU_FreeRenderer_GLES_1(GPU_Renderer* renderer)
|
||||
{
|
||||
if(renderer == NULL)
|
||||
return;
|
||||
|
||||
free(renderer);
|
||||
}
|
||||
|
||||
#endif
|
|
@ -1,86 +0,0 @@
|
|||
#ifndef _SDL_GPU_GLES_1_H__
|
||||
#define _SDL_GPU_GLES_1_H__
|
||||
|
||||
#include "SDL_gpu.h"
|
||||
#include "SDL_platform.h"
|
||||
|
||||
#if !defined(SDL_GPU_DISABLE_GLES) && !defined(SDL_GPU_DISABLE_GLES_1)
|
||||
|
||||
#ifdef __IPHONEOS__
|
||||
#include <OpenGLES/ES1/gl.h>
|
||||
#include <OpenGLES/ES1/glext.h>
|
||||
#else
|
||||
#include "GLES/gl.h"
|
||||
#include "GLES/glext.h"
|
||||
#endif
|
||||
|
||||
#define glFrustum glFrustumf
|
||||
#define glOrtho glOrthof
|
||||
#define glGenerateMipmap glGenerateMipmapOES
|
||||
#define glDeleteFramebuffers glDeleteFramebuffersOES
|
||||
#define glGenFramebuffers glGenFramebuffersOES
|
||||
#define glFramebufferTexture2D glFramebufferTexture2DOES
|
||||
#define glCheckFramebufferStatus glCheckFramebufferStatusOES
|
||||
#define glBindFramebuffer glBindFramebufferOES
|
||||
#define GL_FRAMEBUFFER GL_FRAMEBUFFER_OES
|
||||
#define GL_FRAMEBUFFER_BINDING GL_FRAMEBUFFER_BINDING_OES
|
||||
#define GL_COLOR_ATTACHMENT0 GL_COLOR_ATTACHMENT0_OES
|
||||
#define GL_FRAMEBUFFER_COMPLETE GL_FRAMEBUFFER_COMPLETE_OES
|
||||
|
||||
#define glBlendEquation glBlendEquationOES
|
||||
#define glBlendEquationSeparate glBlendEquationSeparateOES
|
||||
#define glBlendFuncSeparate glBlendFuncSeparateOES
|
||||
|
||||
#define GL_FUNC_ADD GL_FUNC_ADD_OES
|
||||
#define GL_FUNC_SUBTRACT GL_FUNC_SUBTRACT_OES
|
||||
#define GL_FUNC_REVERSE_SUBTRACT GL_FUNC_REVERSE_SUBTRACT_OES
|
||||
|
||||
#define GL_MIRRORED_REPEAT GL_MIRRORED_REPEAT_OES
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#define GPU_CONTEXT_DATA ContextData_GLES_1
|
||||
#define GPU_IMAGE_DATA ImageData_GLES_1
|
||||
#define GPU_TARGET_DATA TargetData_GLES_1
|
||||
|
||||
|
||||
|
||||
typedef struct ContextData_GLES_1
|
||||
{
|
||||
SDL_Color last_color;
|
||||
Uint8 last_use_texturing;
|
||||
unsigned int last_shape;
|
||||
Uint8 last_use_blending;
|
||||
GPU_BlendMode last_blend_mode;
|
||||
GPU_Rect last_viewport;
|
||||
GPU_Camera last_camera;
|
||||
Uint8 last_camera_inverted;
|
||||
|
||||
GPU_Image* last_image;
|
||||
GPU_Target* last_target;
|
||||
float* blit_buffer; // Holds sets of 4 vertices and 4 tex coords interleaved (e.g. [x0, y0, z0, s0, t0, ...]).
|
||||
unsigned short blit_buffer_num_vertices;
|
||||
unsigned short blit_buffer_max_num_vertices;
|
||||
unsigned short* index_buffer; // Indexes into the blit buffer so we can use 4 vertices for every 2 triangles (1 quad)
|
||||
unsigned int index_buffer_num_vertices;
|
||||
unsigned int index_buffer_max_num_vertices;
|
||||
} ContextData_GLES_1;
|
||||
|
||||
typedef struct ImageData_GLES_1
|
||||
{
|
||||
int refcount;
|
||||
Uint32 handle;
|
||||
Uint32 format;
|
||||
} ImageData_GLES_1;
|
||||
|
||||
typedef struct TargetData_GLES_1
|
||||
{
|
||||
int refcount;
|
||||
Uint32 handle;
|
||||
Uint32 format;
|
||||
} TargetData_GLES_1;
|
||||
|
||||
|
||||
|
||||
#endif
|
|
@ -1,53 +0,0 @@
|
|||
#include "SDL_gpu_GLES_2.h"
|
||||
|
||||
|
||||
#if defined(SDL_GPU_DISABLE_GLES) || defined(SDL_GPU_DISABLE_GLES_2)
|
||||
|
||||
// Dummy implementations
|
||||
GPU_Renderer* GPU_CreateRenderer_GLES_2(GPU_RendererID request) {return NULL;}
|
||||
void GPU_FreeRenderer_GLES_2(GPU_Renderer* renderer) {}
|
||||
|
||||
#else
|
||||
|
||||
|
||||
// Most of the code pulled in from here...
|
||||
#define SDL_GPU_USE_GLES
|
||||
#define SDL_GPU_USE_GL_TIER3
|
||||
#define SDL_GPU_GL_TIER 3
|
||||
#define SDL_GPU_GLSL_VERSION 100
|
||||
#define SDL_GPU_GLES_MAJOR_VERSION 2
|
||||
#define SDL_GPU_NO_VAO
|
||||
#include "../GL_common/SDL_gpu_GL_common.inl"
|
||||
#include "../GL_common/SDL_gpuShapes_GL_common.inl"
|
||||
|
||||
|
||||
GPU_Renderer* GPU_CreateRenderer_GLES_2(GPU_RendererID request)
|
||||
{
|
||||
GPU_Renderer* renderer = (GPU_Renderer*)malloc(sizeof(GPU_Renderer));
|
||||
if(renderer == NULL)
|
||||
return NULL;
|
||||
|
||||
memset(renderer, 0, sizeof(GPU_Renderer));
|
||||
|
||||
renderer->id = request;
|
||||
renderer->id.id = GPU_RENDERER_GLES_2;
|
||||
renderer->shader_language = GPU_LANGUAGE_GLSLES;
|
||||
renderer->shader_version = SDL_GPU_GLSL_VERSION;
|
||||
|
||||
renderer->current_context_target = NULL;
|
||||
|
||||
SET_COMMON_FUNCTIONS(renderer);
|
||||
|
||||
return renderer;
|
||||
}
|
||||
|
||||
void GPU_FreeRenderer_GLES_2(GPU_Renderer* renderer)
|
||||
{
|
||||
if(renderer == NULL)
|
||||
return;
|
||||
|
||||
free(renderer);
|
||||
}
|
||||
|
||||
|
||||
#endif
|
|
@ -1,149 +0,0 @@
|
|||
#ifndef _SDL_GPU_GLES_2_H__
|
||||
#define _SDL_GPU_GLES_2_H__
|
||||
|
||||
#include "SDL_gpu.h"
|
||||
#include "SDL_platform.h"
|
||||
|
||||
#if !defined(SDL_GPU_DISABLE_GLES) && !defined(SDL_GPU_DISABLE_GLES_2)
|
||||
|
||||
#ifdef __IPHONEOS__
|
||||
#include <OpenGLES/ES2/gl.h>
|
||||
#include <OpenGLES/ES2/glext.h>
|
||||
#else
|
||||
#include "GLES2/gl2.h"
|
||||
#include "GLES2/gl2ext.h"
|
||||
#endif
|
||||
|
||||
#define glVertexAttribI1i glVertexAttrib1f
|
||||
#define glVertexAttribI2i glVertexAttrib2f
|
||||
#define glVertexAttribI3i glVertexAttrib3f
|
||||
#define glVertexAttribI4i glVertexAttrib4f
|
||||
#define glVertexAttribI1ui glVertexAttrib1f
|
||||
#define glVertexAttribI2ui glVertexAttrib2f
|
||||
#define glVertexAttribI3ui glVertexAttrib3f
|
||||
#define glVertexAttribI4ui glVertexAttrib4f
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#define GPU_CONTEXT_DATA ContextData_GLES_2
|
||||
#define GPU_IMAGE_DATA ImageData_GLES_2
|
||||
#define GPU_TARGET_DATA TargetData_GLES_2
|
||||
|
||||
|
||||
#define GPU_DEFAULT_TEXTURED_VERTEX_SHADER_SOURCE \
|
||||
"#version 100\n\
|
||||
precision mediump float;\n\
|
||||
precision mediump int;\n\
|
||||
\
|
||||
attribute vec2 gpu_Vertex;\n\
|
||||
attribute vec2 gpu_TexCoord;\n\
|
||||
attribute vec4 gpu_Color;\n\
|
||||
uniform mat4 gpu_ModelViewProjectionMatrix;\n\
|
||||
\
|
||||
varying vec4 color;\n\
|
||||
varying vec2 texCoord;\n\
|
||||
\
|
||||
void main(void)\n\
|
||||
{\n\
|
||||
color = gpu_Color;\n\
|
||||
texCoord = vec2(gpu_TexCoord);\n\
|
||||
gl_Position = gpu_ModelViewProjectionMatrix * vec4(gpu_Vertex, 0.0, 1.0);\n\
|
||||
}"
|
||||
|
||||
// Tier 3 uses shader attributes to send position, texcoord, and color data for each vertex.
|
||||
#define GPU_DEFAULT_UNTEXTURED_VERTEX_SHADER_SOURCE \
|
||||
"#version 100\n\
|
||||
precision mediump float;\n\
|
||||
precision mediump int;\n\
|
||||
\
|
||||
attribute vec2 gpu_Vertex;\n\
|
||||
attribute vec4 gpu_Color;\n\
|
||||
uniform mat4 gpu_ModelViewProjectionMatrix;\n\
|
||||
\
|
||||
varying vec4 color;\n\
|
||||
\
|
||||
void main(void)\n\
|
||||
{\n\
|
||||
color = gpu_Color;\n\
|
||||
gl_Position = gpu_ModelViewProjectionMatrix * vec4(gpu_Vertex, 0.0, 1.0);\n\
|
||||
}"
|
||||
|
||||
|
||||
#define GPU_DEFAULT_TEXTURED_FRAGMENT_SHADER_SOURCE \
|
||||
"#version 100\n\
|
||||
precision mediump float;\n\
|
||||
precision mediump int;\n\
|
||||
\
|
||||
varying vec4 color;\n\
|
||||
varying vec2 texCoord;\n\
|
||||
\
|
||||
uniform sampler2D tex;\n\
|
||||
\
|
||||
void main(void)\n\
|
||||
{\n\
|
||||
gl_FragColor = texture2D(tex, texCoord) * color;\n\
|
||||
}"
|
||||
|
||||
#define GPU_DEFAULT_UNTEXTURED_FRAGMENT_SHADER_SOURCE \
|
||||
"#version 100\n\
|
||||
precision mediump float;\n\
|
||||
precision mediump int;\n\
|
||||
\
|
||||
varying vec4 color;\n\
|
||||
\
|
||||
void main(void)\n\
|
||||
{\n\
|
||||
gl_FragColor = color;\n\
|
||||
}"
|
||||
|
||||
|
||||
|
||||
|
||||
typedef struct ContextData_GLES_2
|
||||
{
|
||||
SDL_Color last_color;
|
||||
Uint8 last_use_texturing;
|
||||
unsigned int last_shape;
|
||||
Uint8 last_use_blending;
|
||||
GPU_BlendMode last_blend_mode;
|
||||
GPU_Rect last_viewport;
|
||||
GPU_Camera last_camera;
|
||||
Uint8 last_camera_inverted;
|
||||
|
||||
GPU_Image* last_image;
|
||||
GPU_Target* last_target;
|
||||
float* blit_buffer; // Holds sets of 4 vertices, each with interleaved position, tex coords, and colors (e.g. [x0, y0, z0, s0, t0, r0, g0, b0, a0, ...]).
|
||||
unsigned short blit_buffer_num_vertices;
|
||||
unsigned short blit_buffer_max_num_vertices;
|
||||
unsigned short* index_buffer; // Indexes into the blit buffer so we can use 4 vertices for every 2 triangles (1 quad)
|
||||
unsigned int index_buffer_num_vertices;
|
||||
unsigned int index_buffer_max_num_vertices;
|
||||
|
||||
// Tier 3 rendering
|
||||
unsigned int blit_VBO[2]; // For double-buffering
|
||||
Uint8 blit_VBO_flop;
|
||||
GPU_ShaderBlock shader_block[2];
|
||||
GPU_ShaderBlock current_shader_block;
|
||||
|
||||
GPU_AttributeSource shader_attributes[16];
|
||||
unsigned int attribute_VBO[16];
|
||||
} ContextData_GLES_2;
|
||||
|
||||
typedef struct ImageData_GLES_2
|
||||
{
|
||||
int refcount;
|
||||
Uint32 handle;
|
||||
Uint32 format;
|
||||
} ImageData_GLES_2;
|
||||
|
||||
typedef struct TargetData_GLES_2
|
||||
{
|
||||
int refcount;
|
||||
Uint32 handle;
|
||||
Uint32 format;
|
||||
} TargetData_GLES_2;
|
||||
|
||||
|
||||
|
||||
#endif
|
|
@ -1,848 +0,0 @@
|
|||
/* This is an implementation file to be included after certain #defines have been set.
|
||||
See a particular renderer's *.c file for specifics. */
|
||||
|
||||
#ifndef DEGPERRAD
|
||||
#define DEGPERRAD 57.2957795f
|
||||
#endif
|
||||
|
||||
#ifndef RADPERDEG
|
||||
#define RADPERDEG 0.0174532925f
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// All shapes start this way for setup and so they can access the blit buffer properly
|
||||
#define BEGIN_UNTEXTURED(function_name, shape, num_additional_vertices, num_additional_indices) \
|
||||
GPU_CONTEXT_DATA* cdata; \
|
||||
float* blit_buffer; \
|
||||
unsigned short* index_buffer; \
|
||||
int vert_index; \
|
||||
int color_index; \
|
||||
float r, g, b, a; \
|
||||
unsigned short blit_buffer_starting_index; \
|
||||
if(target == NULL) \
|
||||
{ \
|
||||
GPU_PushErrorCode(function_name, GPU_ERROR_NULL_ARGUMENT, "target"); \
|
||||
return; \
|
||||
} \
|
||||
if(renderer != target->renderer) \
|
||||
{ \
|
||||
GPU_PushErrorCode(function_name, GPU_ERROR_USER_ERROR, "Mismatched renderer"); \
|
||||
return; \
|
||||
} \
|
||||
\
|
||||
makeContextCurrent(renderer, target); \
|
||||
if(renderer->current_context_target == NULL) \
|
||||
{ \
|
||||
GPU_PushErrorCode(function_name, GPU_ERROR_USER_ERROR, "NULL context"); \
|
||||
return; \
|
||||
} \
|
||||
\
|
||||
if(!bindFramebuffer(renderer, target)) \
|
||||
{ \
|
||||
GPU_PushErrorCode(function_name, GPU_ERROR_BACKEND_ERROR, "Failed to bind framebuffer."); \
|
||||
return; \
|
||||
} \
|
||||
\
|
||||
prepareToRenderToTarget(renderer, target); \
|
||||
prepareToRenderShapes(renderer, shape); \
|
||||
\
|
||||
cdata = (GPU_CONTEXT_DATA*)renderer->current_context_target->context->data; \
|
||||
\
|
||||
if(cdata->blit_buffer_num_vertices + (num_additional_vertices) >= cdata->blit_buffer_max_num_vertices) \
|
||||
{ \
|
||||
if(!growBlitBuffer(cdata, cdata->blit_buffer_num_vertices + (num_additional_vertices))) \
|
||||
renderer->FlushBlitBuffer(renderer); \
|
||||
} \
|
||||
if(cdata->index_buffer_num_vertices + (num_additional_indices) >= cdata->index_buffer_max_num_vertices) \
|
||||
{ \
|
||||
if(!growIndexBuffer(cdata, cdata->index_buffer_num_vertices + (num_additional_indices))) \
|
||||
renderer->FlushBlitBuffer(renderer); \
|
||||
} \
|
||||
\
|
||||
blit_buffer = cdata->blit_buffer; \
|
||||
index_buffer = cdata->index_buffer; \
|
||||
\
|
||||
vert_index = GPU_BLIT_BUFFER_VERTEX_OFFSET + cdata->blit_buffer_num_vertices*GPU_BLIT_BUFFER_FLOATS_PER_VERTEX; \
|
||||
color_index = GPU_BLIT_BUFFER_COLOR_OFFSET + cdata->blit_buffer_num_vertices*GPU_BLIT_BUFFER_FLOATS_PER_VERTEX; \
|
||||
\
|
||||
if(target->use_color) \
|
||||
{ \
|
||||
r = MIX_COLOR_COMPONENT_NORMALIZED_RESULT(target->color.r, color.r); \
|
||||
g = MIX_COLOR_COMPONENT_NORMALIZED_RESULT(target->color.g, color.g); \
|
||||
b = MIX_COLOR_COMPONENT_NORMALIZED_RESULT(target->color.b, color.b); \
|
||||
a = MIX_COLOR_COMPONENT_NORMALIZED_RESULT(GET_ALPHA(target->color), GET_ALPHA(color)); \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
r = color.r/255.0f; \
|
||||
g = color.g/255.0f; \
|
||||
b = color.b/255.0f; \
|
||||
a = GET_ALPHA(color)/255.0f; \
|
||||
} \
|
||||
blit_buffer_starting_index = cdata->blit_buffer_num_vertices; \
|
||||
(void)blit_buffer_starting_index;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
static float SetLineThickness(GPU_Renderer* renderer, float thickness)
|
||||
{
|
||||
float old;
|
||||
|
||||
if(renderer->current_context_target == NULL)
|
||||
return 1.0f;
|
||||
|
||||
old = renderer->current_context_target->context->line_thickness;
|
||||
if(old != thickness)
|
||||
renderer->FlushBlitBuffer(renderer);
|
||||
|
||||
renderer->current_context_target->context->line_thickness = thickness;
|
||||
glLineWidth(thickness);
|
||||
return old;
|
||||
}
|
||||
|
||||
static float GetLineThickness(GPU_Renderer* renderer)
|
||||
{
|
||||
return renderer->current_context_target->context->line_thickness;
|
||||
}
|
||||
|
||||
static void Pixel(GPU_Renderer* renderer, GPU_Target* target, float x, float y, SDL_Color color)
|
||||
{
|
||||
BEGIN_UNTEXTURED("GPU_Pixel", GL_POINTS, 1, 1);
|
||||
|
||||
SET_UNTEXTURED_VERTEX(x, y, r, g, b, a);
|
||||
}
|
||||
|
||||
static void Line(GPU_Renderer* renderer, GPU_Target* target, float x1, float y1, float x2, float y2, SDL_Color color)
|
||||
{
|
||||
float thickness = renderer->GetLineThickness(renderer);
|
||||
|
||||
float t = thickness/2;
|
||||
float line_angle = atan2f(y2 - y1, x2 - x1);
|
||||
float tc = t*cosf(line_angle);
|
||||
float ts = t*sinf(line_angle);
|
||||
|
||||
BEGIN_UNTEXTURED("GPU_Line", GL_TRIANGLES, 4, 6);
|
||||
|
||||
SET_UNTEXTURED_VERTEX(x1 + ts, y1 - tc, r, g, b, a);
|
||||
SET_UNTEXTURED_VERTEX(x1 - ts, y1 + tc, r, g, b, a);
|
||||
SET_UNTEXTURED_VERTEX(x2 + ts, y2 - tc, r, g, b, a);
|
||||
|
||||
SET_INDEXED_VERTEX(1);
|
||||
SET_INDEXED_VERTEX(2);
|
||||
SET_UNTEXTURED_VERTEX(x2 - ts, y2 + tc, r, g, b, a);
|
||||
}
|
||||
|
||||
// Arc() might call Circle()
|
||||
static void Circle(GPU_Renderer* renderer, GPU_Target* target, float x, float y, float radius, SDL_Color color);
|
||||
|
||||
static void Arc(GPU_Renderer* renderer, GPU_Target* target, float x, float y, float radius, float start_angle, float end_angle, SDL_Color color)
|
||||
{
|
||||
float t;
|
||||
float dt;
|
||||
float dx, dy;
|
||||
|
||||
int numSegments;
|
||||
|
||||
if(start_angle > end_angle)
|
||||
{
|
||||
float swapa = end_angle;
|
||||
end_angle = start_angle;
|
||||
start_angle = swapa;
|
||||
}
|
||||
if(start_angle == end_angle)
|
||||
return;
|
||||
|
||||
// Big angle
|
||||
if(end_angle - start_angle >= 360)
|
||||
{
|
||||
Circle(renderer, target, x, y, radius, color);
|
||||
return;
|
||||
}
|
||||
|
||||
// Shift together
|
||||
while(start_angle < 0 && end_angle < 0)
|
||||
{
|
||||
start_angle += 360;
|
||||
end_angle += 360;
|
||||
}
|
||||
while(start_angle > 360 && end_angle > 360)
|
||||
{
|
||||
start_angle -= 360;
|
||||
end_angle -= 360;
|
||||
}
|
||||
|
||||
|
||||
t = start_angle;
|
||||
dt = ((end_angle - start_angle)/360)*(1.25f/sqrtf(radius)) * DEGPERRAD; // s = rA, so dA = ds/r. ds of 1.25*sqrt(radius) is good, use A in degrees.
|
||||
|
||||
numSegments = fabs(end_angle - start_angle)/dt;
|
||||
if(numSegments == 0)
|
||||
return;
|
||||
|
||||
{
|
||||
int i;
|
||||
BEGIN_UNTEXTURED("GPU_Arc", GL_LINES, 1 + (numSegments - 1) + 1, 1 + (numSegments - 1) * 2 + 1);
|
||||
|
||||
dx = radius*cos(t*RADPERDEG);
|
||||
dy = radius*sin(t*RADPERDEG);
|
||||
SET_UNTEXTURED_VERTEX(x + dx, y + dy, r, g, b, a); // first point
|
||||
t += dt;
|
||||
|
||||
for (i = 1; i < numSegments; i++)
|
||||
{
|
||||
dx = radius*cos(t*RADPERDEG);
|
||||
dy = radius*sin(t*RADPERDEG);
|
||||
SET_UNTEXTURED_VERTEX(x + dx, y + dy, r, g, b, a);
|
||||
SET_INDEXED_VERTEX(i); // Double that vertex
|
||||
t += dt;
|
||||
}
|
||||
|
||||
// Last point
|
||||
dx = radius*cos(end_angle*RADPERDEG);
|
||||
dy = radius*sin(end_angle*RADPERDEG);
|
||||
SET_UNTEXTURED_VERTEX(x + dx, y + dy, r, g, b, a);
|
||||
}
|
||||
}
|
||||
|
||||
// ArcFilled() might call CircleFilled()
|
||||
static void CircleFilled(GPU_Renderer* renderer, GPU_Target* target, float x, float y, float radius, SDL_Color color);
|
||||
|
||||
static void ArcFilled(GPU_Renderer* renderer, GPU_Target* target, float x, float y, float radius, float start_angle, float end_angle, SDL_Color color)
|
||||
{
|
||||
float t;
|
||||
float dt;
|
||||
float dx, dy;
|
||||
|
||||
int numSegments;
|
||||
|
||||
if(start_angle > end_angle)
|
||||
{
|
||||
float swapa = end_angle;
|
||||
end_angle = start_angle;
|
||||
start_angle = swapa;
|
||||
}
|
||||
if(start_angle == end_angle)
|
||||
return;
|
||||
|
||||
// Big angle
|
||||
if(end_angle - start_angle >= 360)
|
||||
{
|
||||
CircleFilled(renderer, target, x, y, radius, color);
|
||||
return;
|
||||
}
|
||||
|
||||
// Shift together
|
||||
while(start_angle < 0 && end_angle < 0)
|
||||
{
|
||||
start_angle += 360;
|
||||
end_angle += 360;
|
||||
}
|
||||
while(start_angle > 360 && end_angle > 360)
|
||||
{
|
||||
start_angle -= 360;
|
||||
end_angle -= 360;
|
||||
}
|
||||
|
||||
t = start_angle;
|
||||
dt = ((end_angle - start_angle)/360)*(1.25f/sqrtf(radius)) * DEGPERRAD; // s = rA, so dA = ds/r. ds of 1.25*sqrt(radius) is good, use A in degrees.
|
||||
|
||||
numSegments = fabs(end_angle - start_angle)/dt;
|
||||
if(numSegments == 0)
|
||||
return;
|
||||
|
||||
{
|
||||
int i;
|
||||
BEGIN_UNTEXTURED("GPU_ArcFilled", GL_TRIANGLES, 3 + (numSegments - 1) + 1, 3 + (numSegments - 1) * 3 + 3);
|
||||
|
||||
// First triangle
|
||||
SET_UNTEXTURED_VERTEX(x, y, r, g, b, a);
|
||||
dx = radius*cos(t*RADPERDEG);
|
||||
dy = radius*sin(t*RADPERDEG);
|
||||
SET_UNTEXTURED_VERTEX(x + dx, y + dy, r, g, b, a); // first point
|
||||
t += dt;
|
||||
dx = radius*cos(t*RADPERDEG);
|
||||
dy = radius*sin(t*RADPERDEG);
|
||||
SET_UNTEXTURED_VERTEX(x + dx, y + dy, r, g, b, a); // new point
|
||||
t += dt;
|
||||
|
||||
for (i = 2; i < numSegments + 1; i++)
|
||||
{
|
||||
dx = radius*cos(t*RADPERDEG);
|
||||
dy = radius*sin(t*RADPERDEG);
|
||||
SET_INDEXED_VERTEX(0); // center
|
||||
SET_INDEXED_VERTEX(i); // last point
|
||||
SET_UNTEXTURED_VERTEX(x + dx, y + dy, r, g, b, a); // new point
|
||||
t += dt;
|
||||
}
|
||||
|
||||
// Last triangle
|
||||
dx = radius*cos(end_angle*RADPERDEG);
|
||||
dy = radius*sin(end_angle*RADPERDEG);
|
||||
SET_INDEXED_VERTEX(0); // center
|
||||
SET_INDEXED_VERTEX(i); // last point
|
||||
SET_UNTEXTURED_VERTEX(x + dx, y + dy, r, g, b, a); // new point
|
||||
}
|
||||
}
|
||||
|
||||
static void Circle(GPU_Renderer* renderer, GPU_Target* target, float x, float y, float radius, SDL_Color color)
|
||||
{
|
||||
float t = 0;
|
||||
float dt = (1.25f/sqrtf(radius)) * DEGPERRAD; // s = rA, so dA = ds/r. ds of 1.25*sqrt(radius) is good, use A in degrees.
|
||||
float dx, dy;
|
||||
int numSegments = 360/dt+1;
|
||||
int i;
|
||||
|
||||
BEGIN_UNTEXTURED("GPU_Circle", GL_LINES, 1 + (numSegments-1), 1 + (numSegments-1)*2 + 1);
|
||||
|
||||
dx = radius;
|
||||
dy = 0.0f;
|
||||
SET_UNTEXTURED_VERTEX(x+dx, y+dy, r, g, b, a); // first point
|
||||
|
||||
for(i = 1; i < numSegments; i++)
|
||||
{
|
||||
dx = radius*cos(t*RADPERDEG);
|
||||
dy = radius*sin(t*RADPERDEG);
|
||||
SET_UNTEXTURED_VERTEX(x+dx, y+dy, r, g, b, a);
|
||||
SET_INDEXED_VERTEX(i); // Double that vertex
|
||||
t += dt;
|
||||
}
|
||||
|
||||
SET_INDEXED_VERTEX(0); // back to the beginning
|
||||
}
|
||||
|
||||
static void CircleFilled(GPU_Renderer* renderer, GPU_Target* target, float x, float y, float radius, SDL_Color color)
|
||||
{
|
||||
float t = 0;
|
||||
float dt = (1.25f/sqrtf(radius)) * DEGPERRAD; // s = rA, so dA = ds/r. ds of 1.25*sqrt(radius) is good, use A in degrees.
|
||||
float dx, dy;
|
||||
|
||||
int numSegments = 360/dt+1;
|
||||
int i;
|
||||
|
||||
BEGIN_UNTEXTURED("GPU_CircleFilled", GL_TRIANGLES, 3 + (numSegments-2), 3 + (numSegments-2)*3 + 3);
|
||||
|
||||
// First triangle
|
||||
SET_UNTEXTURED_VERTEX(x, y, r, g, b, a);
|
||||
dx = radius;
|
||||
dy = 0.0f;
|
||||
SET_UNTEXTURED_VERTEX(x+dx, y+dy, r, g, b, a); // first point
|
||||
t += dt;
|
||||
dx = radius*cos(t*RADPERDEG);
|
||||
dy = radius*sin(t*RADPERDEG);
|
||||
SET_UNTEXTURED_VERTEX(x+dx, y+dy, r, g, b, a); // new point
|
||||
t += dt;
|
||||
|
||||
for(i = 2; i < numSegments; i++)
|
||||
{
|
||||
dx = radius*cos(t*RADPERDEG);
|
||||
dy = radius*sin(t*RADPERDEG);
|
||||
SET_INDEXED_VERTEX(0); // center
|
||||
SET_INDEXED_VERTEX(i); // last point
|
||||
SET_UNTEXTURED_VERTEX(x+dx, y+dy, r, g, b, a); // new point
|
||||
t += dt;
|
||||
}
|
||||
|
||||
SET_INDEXED_VERTEX(0); // center
|
||||
SET_INDEXED_VERTEX(i); // last point
|
||||
SET_INDEXED_VERTEX(1); // first point
|
||||
}
|
||||
|
||||
static void Sector(GPU_Renderer* renderer, GPU_Target* target, float x, float y, float inner_radius, float outer_radius, float start_angle, float end_angle, SDL_Color color)
|
||||
{
|
||||
Uint8 circled;
|
||||
float dx1, dy1, dx2, dy2, dx3, dy3, dx4, dy4;
|
||||
|
||||
if(inner_radius < 0.0f)
|
||||
inner_radius = 0.0f;
|
||||
if(outer_radius < 0.0f)
|
||||
outer_radius = 0.0f;
|
||||
|
||||
if(inner_radius > outer_radius)
|
||||
{
|
||||
float s = inner_radius;
|
||||
inner_radius = outer_radius;
|
||||
outer_radius = s;
|
||||
}
|
||||
|
||||
if(start_angle > end_angle)
|
||||
{
|
||||
float swapa = end_angle;
|
||||
end_angle = start_angle;
|
||||
start_angle = swapa;
|
||||
}
|
||||
if(start_angle == end_angle)
|
||||
return;
|
||||
|
||||
if(inner_radius == outer_radius)
|
||||
{
|
||||
Arc(renderer, target, x, y, inner_radius, start_angle, end_angle, color);
|
||||
return;
|
||||
}
|
||||
|
||||
circled = (end_angle - start_angle >= 360);
|
||||
// Composited shape... But that means error codes may be confusing. :-/
|
||||
Arc(renderer, target, x, y, inner_radius, start_angle, end_angle, color);
|
||||
|
||||
if(!circled)
|
||||
{
|
||||
dx1 = inner_radius*cos(end_angle*RADPERDEG);
|
||||
dy1 = inner_radius*sin(end_angle*RADPERDEG);
|
||||
dx2 = outer_radius*cos(end_angle*RADPERDEG);
|
||||
dy2 = outer_radius*sin(end_angle*RADPERDEG);
|
||||
Line(renderer, target, x+dx1, y+dy1, x+dx2, y+dy2, color);
|
||||
}
|
||||
|
||||
Arc(renderer, target, x, y, outer_radius, start_angle, end_angle, color);
|
||||
|
||||
if(!circled)
|
||||
{
|
||||
dx3 = inner_radius*cos(start_angle*RADPERDEG);
|
||||
dy3 = inner_radius*sin(start_angle*RADPERDEG);
|
||||
dx4 = outer_radius*cos(start_angle*RADPERDEG);
|
||||
dy4 = outer_radius*sin(start_angle*RADPERDEG);
|
||||
Line(renderer, target, x+dx3, y+dy3, x+dx4, y+dy4, color);
|
||||
}
|
||||
}
|
||||
|
||||
static void SectorFilled(GPU_Renderer* renderer, GPU_Target* target, float x, float y, float inner_radius, float outer_radius, float start_angle, float end_angle, SDL_Color color)
|
||||
{
|
||||
float t;
|
||||
float dt;
|
||||
float dx, dy;
|
||||
|
||||
int numSegments;
|
||||
|
||||
if(inner_radius < 0.0f)
|
||||
inner_radius = 0.0f;
|
||||
if(outer_radius < 0.0f)
|
||||
outer_radius = 0.0f;
|
||||
|
||||
if(inner_radius > outer_radius)
|
||||
{
|
||||
float s = inner_radius;
|
||||
inner_radius = outer_radius;
|
||||
outer_radius = s;
|
||||
}
|
||||
|
||||
if(inner_radius == outer_radius)
|
||||
{
|
||||
Arc(renderer, target, x, y, inner_radius, start_angle, end_angle, color);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if(start_angle > end_angle)
|
||||
{
|
||||
float swapa = end_angle;
|
||||
end_angle = start_angle;
|
||||
start_angle = swapa;
|
||||
}
|
||||
if(start_angle == end_angle)
|
||||
return;
|
||||
|
||||
if(end_angle - start_angle >= 360)
|
||||
end_angle = start_angle + 360;
|
||||
|
||||
|
||||
t = start_angle;
|
||||
dt = ((end_angle - start_angle)/360)*(1.25f/sqrtf(outer_radius)) * DEGPERRAD; // s = rA, so dA = ds/r. ds of 1.25*sqrt(radius) is good, use A in degrees.
|
||||
|
||||
numSegments = fabs(end_angle - start_angle)/dt;
|
||||
if(numSegments == 0)
|
||||
return;
|
||||
|
||||
{
|
||||
int i;
|
||||
Uint8 use_inner;
|
||||
BEGIN_UNTEXTURED("GPU_SectorFilled", GL_TRIANGLES, 3 + (numSegments - 1) + 1, 3 + (numSegments - 1) * 3 + 3);
|
||||
|
||||
use_inner = 0; // Switches between the radii for the next point
|
||||
|
||||
// First triangle
|
||||
dx = inner_radius*cos(t*RADPERDEG);
|
||||
dy = inner_radius*sin(t*RADPERDEG);
|
||||
SET_UNTEXTURED_VERTEX(x + dx, y + dy, r, g, b, a);
|
||||
|
||||
dx = outer_radius*cos(t*RADPERDEG);
|
||||
dy = outer_radius*sin(t*RADPERDEG);
|
||||
SET_UNTEXTURED_VERTEX(x + dx, y + dy, r, g, b, a);
|
||||
t += dt;
|
||||
dx = inner_radius*cos(t*RADPERDEG);
|
||||
dy = inner_radius*sin(t*RADPERDEG);
|
||||
SET_UNTEXTURED_VERTEX(x + dx, y + dy, r, g, b, a);
|
||||
t += dt;
|
||||
|
||||
for (i = 2; i < numSegments + 1; i++)
|
||||
{
|
||||
SET_INDEXED_VERTEX(i - 1);
|
||||
SET_INDEXED_VERTEX(i);
|
||||
if (use_inner)
|
||||
{
|
||||
dx = inner_radius*cos(t*RADPERDEG);
|
||||
dy = inner_radius*sin(t*RADPERDEG);
|
||||
}
|
||||
else
|
||||
{
|
||||
dx = outer_radius*cos(t*RADPERDEG);
|
||||
dy = outer_radius*sin(t*RADPERDEG);
|
||||
}
|
||||
SET_UNTEXTURED_VERTEX(x + dx, y + dy, r, g, b, a); // new point
|
||||
t += dt;
|
||||
use_inner = !use_inner;
|
||||
}
|
||||
|
||||
// Last quad
|
||||
t = end_angle;
|
||||
if (use_inner)
|
||||
{
|
||||
dx = inner_radius*cos(t*RADPERDEG);
|
||||
dy = inner_radius*sin(t*RADPERDEG);
|
||||
}
|
||||
else
|
||||
{
|
||||
dx = outer_radius*cos(t*RADPERDEG);
|
||||
dy = outer_radius*sin(t*RADPERDEG);
|
||||
}
|
||||
SET_INDEXED_VERTEX(i - 1);
|
||||
SET_INDEXED_VERTEX(i);
|
||||
SET_UNTEXTURED_VERTEX(x + dx, y + dy, r, g, b, a); // new point
|
||||
use_inner = !use_inner;
|
||||
i++;
|
||||
|
||||
if (use_inner)
|
||||
{
|
||||
dx = inner_radius*cos(t*RADPERDEG);
|
||||
dy = inner_radius*sin(t*RADPERDEG);
|
||||
}
|
||||
else
|
||||
{
|
||||
dx = outer_radius*cos(t*RADPERDEG);
|
||||
dy = outer_radius*sin(t*RADPERDEG);
|
||||
}
|
||||
SET_INDEXED_VERTEX(i - 1);
|
||||
SET_INDEXED_VERTEX(i);
|
||||
SET_UNTEXTURED_VERTEX(x + dx, y + dy, r, g, b, a); // new point
|
||||
}
|
||||
}
|
||||
|
||||
static void Tri(GPU_Renderer* renderer, GPU_Target* target, float x1, float y1, float x2, float y2, float x3, float y3, SDL_Color color)
|
||||
{
|
||||
BEGIN_UNTEXTURED("GPU_Tri", GL_LINES, 3, 6);
|
||||
|
||||
SET_UNTEXTURED_VERTEX(x1, y1, r, g, b, a);
|
||||
SET_UNTEXTURED_VERTEX(x2, y2, r, g, b, a);
|
||||
|
||||
SET_INDEXED_VERTEX(1);
|
||||
SET_UNTEXTURED_VERTEX(x3, y3, r, g, b, a);
|
||||
|
||||
SET_INDEXED_VERTEX(2);
|
||||
SET_INDEXED_VERTEX(0);
|
||||
}
|
||||
|
||||
static void TriFilled(GPU_Renderer* renderer, GPU_Target* target, float x1, float y1, float x2, float y2, float x3, float y3, SDL_Color color)
|
||||
{
|
||||
BEGIN_UNTEXTURED("GPU_TriFilled", GL_TRIANGLES, 3, 3);
|
||||
|
||||
SET_UNTEXTURED_VERTEX(x1, y1, r, g, b, a);
|
||||
SET_UNTEXTURED_VERTEX(x2, y2, r, g, b, a);
|
||||
SET_UNTEXTURED_VERTEX(x3, y3, r, g, b, a);
|
||||
}
|
||||
|
||||
static void Rectangle(GPU_Renderer* renderer, GPU_Target* target, float x1, float y1, float x2, float y2, SDL_Color color)
|
||||
{
|
||||
if(y2 < y1)
|
||||
{
|
||||
float y = y1;
|
||||
y1 = y2;
|
||||
y2 = y;
|
||||
}
|
||||
if(x2 < x1)
|
||||
{
|
||||
float x = x1;
|
||||
x1 = x2;
|
||||
x2 = x;
|
||||
}
|
||||
|
||||
{
|
||||
float thickness = renderer->GetLineThickness(renderer);
|
||||
|
||||
float t = thickness / 2;
|
||||
|
||||
// Thick lines via filled triangles
|
||||
|
||||
BEGIN_UNTEXTURED("GPU_Rectangle", GL_TRIANGLES, 10, 24);
|
||||
|
||||
// First triangle
|
||||
SET_UNTEXTURED_VERTEX(x1 - t, y1 - t, r, g, b, a);
|
||||
SET_UNTEXTURED_VERTEX(x1 + t, y1 + t, r, g, b, a);
|
||||
SET_UNTEXTURED_VERTEX(x2 + t, y1 - t, r, g, b, a);
|
||||
|
||||
SET_INDEXED_VERTEX(1);
|
||||
SET_INDEXED_VERTEX(2);
|
||||
SET_UNTEXTURED_VERTEX(x2 - t, y1 + t, r, g, b, a);
|
||||
|
||||
SET_INDEXED_VERTEX(2);
|
||||
SET_INDEXED_VERTEX(3);
|
||||
SET_UNTEXTURED_VERTEX(x2 + t, y2 + t, r, g, b, a);
|
||||
|
||||
SET_INDEXED_VERTEX(3);
|
||||
SET_INDEXED_VERTEX(4);
|
||||
SET_UNTEXTURED_VERTEX(x2 - t, y2 - t, r, g, b, a);
|
||||
|
||||
SET_INDEXED_VERTEX(4);
|
||||
SET_INDEXED_VERTEX(5);
|
||||
SET_UNTEXTURED_VERTEX(x1 - t, y2 + t, r, g, b, a);
|
||||
|
||||
SET_INDEXED_VERTEX(5);
|
||||
SET_INDEXED_VERTEX(6);
|
||||
SET_UNTEXTURED_VERTEX(x1 + t, y2 - t, r, g, b, a);
|
||||
|
||||
SET_INDEXED_VERTEX(6);
|
||||
SET_INDEXED_VERTEX(7);
|
||||
SET_UNTEXTURED_VERTEX(x1 - t, y1 - t, r, g, b, a);
|
||||
|
||||
SET_INDEXED_VERTEX(7);
|
||||
SET_INDEXED_VERTEX(8);
|
||||
SET_UNTEXTURED_VERTEX(x1 + t, y1 + t, r, g, b, a);
|
||||
}
|
||||
}
|
||||
|
||||
static void RectangleFilled(GPU_Renderer* renderer, GPU_Target* target, float x1, float y1, float x2, float y2, SDL_Color color)
|
||||
{
|
||||
BEGIN_UNTEXTURED("GPU_RectangleFilled", GL_TRIANGLES, 4, 6);
|
||||
|
||||
SET_UNTEXTURED_VERTEX(x1, y1, r, g, b, a);
|
||||
SET_UNTEXTURED_VERTEX(x1, y2, r, g, b, a);
|
||||
SET_UNTEXTURED_VERTEX(x2, y1, r, g, b, a);
|
||||
|
||||
SET_INDEXED_VERTEX(1);
|
||||
SET_INDEXED_VERTEX(2);
|
||||
SET_UNTEXTURED_VERTEX(x2, y2, r, g, b, a);
|
||||
}
|
||||
|
||||
static void RectangleRound(GPU_Renderer* renderer, GPU_Target* target, float x1, float y1, float x2, float y2, float radius, SDL_Color color)
|
||||
{
|
||||
if(y2 < y1)
|
||||
{
|
||||
float temp = y2;
|
||||
y2 = y1;
|
||||
y1 = temp;
|
||||
}
|
||||
if(x2 < x1)
|
||||
{
|
||||
float temp = x2;
|
||||
x2 = x1;
|
||||
x1 = temp;
|
||||
}
|
||||
|
||||
if(radius > (x2-x1)/2)
|
||||
radius = (x2-x1)/2;
|
||||
if(radius > (y2-y1)/2)
|
||||
radius = (y2 - y1) / 2;
|
||||
|
||||
{
|
||||
float tau = 2 * M_PI;
|
||||
|
||||
int verts_per_corner = 7;
|
||||
float corner_angle_increment = (tau / 4) / (verts_per_corner - 1); // 0, 15, 30, 45, 60, 75, 90
|
||||
// Starting angle
|
||||
float angle = tau*0.75f;
|
||||
int last_index = 1;
|
||||
int i;
|
||||
|
||||
BEGIN_UNTEXTURED("GPU_RectangleRound", GL_LINES, 4 + 4 * (verts_per_corner - 1), 8 + 4 * (verts_per_corner - 1) * 2);
|
||||
|
||||
|
||||
// First point
|
||||
SET_UNTEXTURED_VERTEX(x2 - radius + cos(angle)*radius, y1 + radius + sin(angle)*radius, r, g, b, a);
|
||||
|
||||
for (i = 1; i < verts_per_corner; i++)
|
||||
{
|
||||
SET_UNTEXTURED_VERTEX(x2 - radius + cos(angle)*radius, y1 + radius + sin(angle)*radius, r, g, b, a);
|
||||
SET_INDEXED_VERTEX(last_index++);
|
||||
angle += corner_angle_increment;
|
||||
}
|
||||
|
||||
SET_UNTEXTURED_VERTEX(x2 - radius + cos(angle)*radius, y2 - radius + sin(angle)*radius, r, g, b, a);
|
||||
SET_INDEXED_VERTEX(last_index++);
|
||||
for (i = 1; i < verts_per_corner; i++)
|
||||
{
|
||||
SET_UNTEXTURED_VERTEX(x2 - radius + cos(angle)*radius, y2 - radius + sin(angle)*radius, r, g, b, a);
|
||||
SET_INDEXED_VERTEX(last_index++);
|
||||
angle += corner_angle_increment;
|
||||
}
|
||||
|
||||
SET_UNTEXTURED_VERTEX(x1 + radius + cos(angle)*radius, y2 - radius + sin(angle)*radius, r, g, b, a);
|
||||
SET_INDEXED_VERTEX(last_index++);
|
||||
for (i = 1; i < verts_per_corner; i++)
|
||||
{
|
||||
SET_UNTEXTURED_VERTEX(x1 + radius + cos(angle)*radius, y2 - radius + sin(angle)*radius, r, g, b, a);
|
||||
SET_INDEXED_VERTEX(last_index++);
|
||||
angle += corner_angle_increment;
|
||||
}
|
||||
|
||||
SET_UNTEXTURED_VERTEX(x1 + radius + cos(angle)*radius, y1 + radius + sin(angle)*radius, r, g, b, a);
|
||||
SET_INDEXED_VERTEX(last_index++);
|
||||
for (i = 1; i < verts_per_corner; i++)
|
||||
{
|
||||
SET_UNTEXTURED_VERTEX(x1 + radius + cos(angle)*radius, y1 + radius + sin(angle)*radius, r, g, b, a);
|
||||
SET_INDEXED_VERTEX(last_index++);
|
||||
angle += corner_angle_increment;
|
||||
}
|
||||
|
||||
// Last point
|
||||
SET_INDEXED_VERTEX(0);
|
||||
}
|
||||
}
|
||||
|
||||
static void RectangleRoundFilled(GPU_Renderer* renderer, GPU_Target* target, float x1, float y1, float x2, float y2, float radius, SDL_Color color)
|
||||
{
|
||||
if(y2 < y1)
|
||||
{
|
||||
float temp = y2;
|
||||
y2 = y1;
|
||||
y1 = temp;
|
||||
}
|
||||
if(x2 < x1)
|
||||
{
|
||||
float temp = x2;
|
||||
x2 = x1;
|
||||
x1 = temp;
|
||||
}
|
||||
|
||||
if(radius > (x2-x1)/2)
|
||||
radius = (x2-x1)/2;
|
||||
if(radius > (y2-y1)/2)
|
||||
radius = (y2 - y1) / 2;
|
||||
|
||||
{
|
||||
float tau = 2 * M_PI;
|
||||
|
||||
int verts_per_corner = 7;
|
||||
float corner_angle_increment = (tau / 4) / (verts_per_corner - 1); // 0, 15, 30, 45, 60, 75, 90
|
||||
|
||||
// Starting angle
|
||||
float angle = tau*0.75f;
|
||||
int last_index = 2;
|
||||
int i;
|
||||
|
||||
BEGIN_UNTEXTURED("GPU_RectangleRoundFilled", GL_TRIANGLES, 6 + 4 * (verts_per_corner - 1) - 1, 15 + 4 * (verts_per_corner - 1) * 3 - 3);
|
||||
|
||||
|
||||
// First triangle
|
||||
SET_UNTEXTURED_VERTEX((x2 + x1) / 2, (y2 + y1) / 2, r, g, b, a); // Center
|
||||
SET_UNTEXTURED_VERTEX(x2 - radius + cos(angle)*radius, y1 + radius + sin(angle)*radius, r, g, b, a);
|
||||
angle += corner_angle_increment;
|
||||
SET_UNTEXTURED_VERTEX(x2 - radius + cos(angle)*radius, y1 + radius + sin(angle)*radius, r, g, b, a);
|
||||
angle += corner_angle_increment;
|
||||
|
||||
for (i = 2; i < verts_per_corner; i++)
|
||||
{
|
||||
SET_INDEXED_VERTEX(0);
|
||||
SET_INDEXED_VERTEX(last_index++);
|
||||
SET_UNTEXTURED_VERTEX(x2 - radius + cos(angle)*radius, y1 + radius + sin(angle)*radius, r, g, b, a);
|
||||
angle += corner_angle_increment;
|
||||
}
|
||||
|
||||
SET_INDEXED_VERTEX(0);
|
||||
SET_INDEXED_VERTEX(last_index++);
|
||||
SET_UNTEXTURED_VERTEX(x2 - radius + cos(angle)*radius, y2 - radius + sin(angle)*radius, r, g, b, a);
|
||||
for (i = 1; i < verts_per_corner; i++)
|
||||
{
|
||||
SET_INDEXED_VERTEX(0);
|
||||
SET_INDEXED_VERTEX(last_index++);
|
||||
SET_UNTEXTURED_VERTEX(x2 - radius + cos(angle)*radius, y2 - radius + sin(angle)*radius, r, g, b, a);
|
||||
angle += corner_angle_increment;
|
||||
}
|
||||
|
||||
SET_INDEXED_VERTEX(0);
|
||||
SET_INDEXED_VERTEX(last_index++);
|
||||
SET_UNTEXTURED_VERTEX(x1 + radius + cos(angle)*radius, y2 - radius + sin(angle)*radius, r, g, b, a);
|
||||
for (i = 1; i < verts_per_corner; i++)
|
||||
{
|
||||
SET_INDEXED_VERTEX(0);
|
||||
SET_INDEXED_VERTEX(last_index++);
|
||||
SET_UNTEXTURED_VERTEX(x1 + radius + cos(angle)*radius, y2 - radius + sin(angle)*radius, r, g, b, a);
|
||||
angle += corner_angle_increment;
|
||||
}
|
||||
|
||||
SET_INDEXED_VERTEX(0);
|
||||
SET_INDEXED_VERTEX(last_index++);
|
||||
SET_UNTEXTURED_VERTEX(x1 + radius + cos(angle)*radius, y1 + radius + sin(angle)*radius, r, g, b, a);
|
||||
for (i = 1; i < verts_per_corner; i++)
|
||||
{
|
||||
SET_INDEXED_VERTEX(0);
|
||||
SET_INDEXED_VERTEX(last_index++);
|
||||
SET_UNTEXTURED_VERTEX(x1 + radius + cos(angle)*radius, y1 + radius + sin(angle)*radius, r, g, b, a);
|
||||
angle += corner_angle_increment;
|
||||
}
|
||||
|
||||
// Last triangle
|
||||
SET_INDEXED_VERTEX(0);
|
||||
SET_INDEXED_VERTEX(last_index++);
|
||||
SET_INDEXED_VERTEX(1);
|
||||
}
|
||||
}
|
||||
|
||||
static void Polygon(GPU_Renderer* renderer, GPU_Target* target, unsigned int num_vertices, float* vertices, SDL_Color color)
|
||||
{
|
||||
if(num_vertices < 3)
|
||||
return;
|
||||
|
||||
{
|
||||
int numSegments = 2 * num_vertices;
|
||||
int last_index = 0;
|
||||
int i;
|
||||
|
||||
BEGIN_UNTEXTURED("GPU_Polygon", GL_LINES, num_vertices, numSegments);
|
||||
|
||||
SET_UNTEXTURED_VERTEX(vertices[0], vertices[1], r, g, b, a);
|
||||
for (i = 2; i < numSegments; i += 2)
|
||||
{
|
||||
SET_UNTEXTURED_VERTEX(vertices[i], vertices[i + 1], r, g, b, a);
|
||||
last_index++;
|
||||
SET_INDEXED_VERTEX(last_index); // Double the last one for the next line
|
||||
}
|
||||
SET_INDEXED_VERTEX(0);
|
||||
}
|
||||
}
|
||||
|
||||
static void PolygonFilled(GPU_Renderer* renderer, GPU_Target* target, unsigned int num_vertices, float* vertices, SDL_Color color)
|
||||
{
|
||||
if(num_vertices < 3)
|
||||
return;
|
||||
|
||||
{
|
||||
int numSegments = 2 * num_vertices;
|
||||
|
||||
// Using a fan of triangles assumes that the polygon is convex
|
||||
BEGIN_UNTEXTURED("GPU_PolygonFilled", GL_TRIANGLES, num_vertices, 3 + (num_vertices - 3) * 3);
|
||||
|
||||
// First triangle
|
||||
SET_UNTEXTURED_VERTEX(vertices[0], vertices[1], r, g, b, a);
|
||||
SET_UNTEXTURED_VERTEX(vertices[2], vertices[3], r, g, b, a);
|
||||
SET_UNTEXTURED_VERTEX(vertices[4], vertices[5], r, g, b, a);
|
||||
|
||||
if (num_vertices > 3)
|
||||
{
|
||||
int last_index = 2;
|
||||
|
||||
int i;
|
||||
for (i = 6; i < numSegments; i += 2)
|
||||
{
|
||||
SET_INDEXED_VERTEX(0); // Start from the first vertex
|
||||
SET_INDEXED_VERTEX(last_index); // Double the last one
|
||||
SET_UNTEXTURED_VERTEX(vertices[i], vertices[i + 1], r, g, b, a);
|
||||
last_index++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load diff
|
@ -1,357 +0,0 @@
|
|||
#include "SDL_gpu.h"
|
||||
#include "SDL_gpu_GL_matrix.h"
|
||||
#include <math.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#define __func__ __FUNCTION__
|
||||
#endif
|
||||
|
||||
#ifndef M_PI
|
||||
#define M_PI 3.1415926f
|
||||
#endif
|
||||
|
||||
|
||||
// static inline only supported in Visual C++ from version 2015 but can use static __inline instead for older versions
|
||||
#ifndef static_inline
|
||||
#ifdef _MSC_VER
|
||||
#if _MSC_VER < 1900
|
||||
#define static_inline static __inline
|
||||
#else
|
||||
#define static_inline static inline
|
||||
#endif
|
||||
#else
|
||||
#define static_inline static inline
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// Visual C does not support C99 (which includes a safe snprintf)
|
||||
#ifdef _MSC_VER
|
||||
#define snprintf c99_snprintf
|
||||
// From Valentin Milea: http://stackoverflow.com/questions/2915672/snprintf-and-visual-studio-2010
|
||||
static_inline int c99_vsnprintf(char* str, size_t size, const char* format, va_list ap)
|
||||
{
|
||||
int count = -1;
|
||||
|
||||
if (size != 0)
|
||||
count = _vsnprintf_s(str, size, _TRUNCATE, format, ap);
|
||||
if (count == -1)
|
||||
count = _vscprintf(format, ap);
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
static_inline int c99_snprintf(char* str, size_t size, const char* format, ...)
|
||||
{
|
||||
int count;
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, format);
|
||||
count = c99_vsnprintf(str, size, format, ap);
|
||||
va_end(ap);
|
||||
|
||||
return count;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
// Implementations based on Wayne Cochran's (wcochran) matrix.c
|
||||
|
||||
// Column-major
|
||||
#define INDEX(row,col) ((col)*4 + (row))
|
||||
|
||||
void GPU_MatrixCopy(float* result, const float* A)
|
||||
{
|
||||
memcpy(result, A, 16*sizeof(float));
|
||||
}
|
||||
|
||||
void GPU_MatrixIdentity(float* result)
|
||||
{
|
||||
memset(result, 0, 16*sizeof(float));
|
||||
result[0] = result[5] = result[10] = result[15] = 1;
|
||||
}
|
||||
|
||||
// Matrix multiply: result = A * B
|
||||
void GPU_Multiply4x4(float* result, float* A, float* B)
|
||||
{
|
||||
int r, c, i;
|
||||
float s;
|
||||
for(r = 0; r < 4; r++)
|
||||
{
|
||||
for(c = 0; c < 4; c++)
|
||||
{
|
||||
s = 0;
|
||||
for(i = 0; i < 4; i++)
|
||||
s += A[INDEX(r,i)]*B[INDEX(i,c)];
|
||||
|
||||
result[INDEX(r,c)] = s;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GPU_MultiplyAndAssign(float* result, float* A)
|
||||
{
|
||||
float temp[16];
|
||||
GPU_Multiply4x4(temp, result, A);
|
||||
GPU_MatrixCopy(result, temp);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// Can be used up to two times per line evaluation...
|
||||
const char* GPU_GetMatrixString(float* A)
|
||||
{
|
||||
static char buffer[512];
|
||||
static char buffer2[512];
|
||||
static char flip = 0;
|
||||
|
||||
char* b = (flip? buffer : buffer2);
|
||||
flip = !flip;
|
||||
|
||||
snprintf(b, 512, "%.1f %.1f %.1f %.1f\n"
|
||||
"%.1f %.1f %.1f %.1f\n"
|
||||
"%.1f %.1f %.1f %.1f\n"
|
||||
"%.1f %.1f %.1f %.1f",
|
||||
A[0], A[1], A[2], A[3],
|
||||
A[4], A[5], A[6], A[7],
|
||||
A[8], A[9], A[10], A[11],
|
||||
A[12], A[13], A[14], A[15]);
|
||||
return b;
|
||||
}
|
||||
|
||||
void GPU_MatrixMode(int matrix_mode)
|
||||
{
|
||||
GPU_Target* target = GPU_GetContextTarget();
|
||||
if(target == NULL || target->context == NULL)
|
||||
return;
|
||||
|
||||
target->context->matrix_mode = matrix_mode;
|
||||
}
|
||||
|
||||
float* GPU_GetModelView(void)
|
||||
{
|
||||
GPU_Target* target = GPU_GetContextTarget();
|
||||
GPU_MatrixStack* stack;
|
||||
|
||||
if(target == NULL || target->context == NULL)
|
||||
return NULL;
|
||||
stack = &target->context->modelview_matrix;
|
||||
if(stack->size == 0)
|
||||
return NULL;
|
||||
return stack->matrix[stack->size-1];
|
||||
}
|
||||
|
||||
float* GPU_GetProjection(void)
|
||||
{
|
||||
GPU_Target* target = GPU_GetContextTarget();
|
||||
GPU_MatrixStack* stack;
|
||||
|
||||
if(target == NULL || target->context == NULL)
|
||||
return NULL;
|
||||
stack = &target->context->projection_matrix;
|
||||
if(stack->size == 0)
|
||||
return NULL;
|
||||
return stack->matrix[stack->size-1];
|
||||
}
|
||||
|
||||
float* GPU_GetCurrentMatrix(void)
|
||||
{
|
||||
GPU_Target* target = GPU_GetContextTarget();
|
||||
GPU_MatrixStack* stack;
|
||||
|
||||
if(target == NULL || target->context == NULL)
|
||||
return NULL;
|
||||
if(target->context->matrix_mode == GPU_MODELVIEW)
|
||||
stack = &target->context->modelview_matrix;
|
||||
else
|
||||
stack = &target->context->projection_matrix;
|
||||
|
||||
if(stack->size == 0)
|
||||
return NULL;
|
||||
return stack->matrix[stack->size-1];
|
||||
}
|
||||
|
||||
void GPU_PushMatrix()
|
||||
{
|
||||
GPU_Target* target = GPU_GetContextTarget();
|
||||
GPU_MatrixStack* stack;
|
||||
|
||||
if(target == NULL || target->context == NULL)
|
||||
return;
|
||||
|
||||
stack = (target->context->matrix_mode == GPU_MODELVIEW? &target->context->modelview_matrix : &target->context->projection_matrix);
|
||||
if(stack->size + 1 >= GPU_MATRIX_STACK_MAX)
|
||||
{
|
||||
GPU_PushErrorCode(__func__, GPU_ERROR_USER_ERROR, "Matrix stack is full (%d)", GPU_MATRIX_STACK_MAX);
|
||||
return;
|
||||
}
|
||||
GPU_MatrixCopy(stack->matrix[stack->size], stack->matrix[stack->size-1]);
|
||||
stack->size++;
|
||||
}
|
||||
|
||||
void GPU_PopMatrix()
|
||||
{
|
||||
GPU_Target* target = GPU_GetContextTarget();
|
||||
GPU_MatrixStack* stack;
|
||||
|
||||
if(target == NULL || target->context == NULL)
|
||||
return;
|
||||
|
||||
stack = (target->context->matrix_mode == GPU_MODELVIEW? &target->context->modelview_matrix : &target->context->projection_matrix);
|
||||
if(stack->size == 0)
|
||||
{
|
||||
GPU_PushErrorCode(__func__, GPU_ERROR_USER_ERROR, "Matrix stack is empty.");
|
||||
return;
|
||||
}
|
||||
stack->size--;
|
||||
}
|
||||
|
||||
void GPU_LoadIdentity(void)
|
||||
{
|
||||
float* result = GPU_GetCurrentMatrix();
|
||||
if(result == NULL)
|
||||
return;
|
||||
GPU_MatrixIdentity(result);
|
||||
}
|
||||
|
||||
void GPU_Ortho(float left, float right, float bottom, float top, float near, float far)
|
||||
{
|
||||
float* result = GPU_GetCurrentMatrix();
|
||||
if(result == NULL)
|
||||
return;
|
||||
|
||||
{
|
||||
#ifdef ROW_MAJOR
|
||||
float A[16] = {2/(right - left), 0, 0, -(right + left)/(right - left),
|
||||
0, 2/(top - bottom), 0, -(top + bottom)/(top - bottom),
|
||||
0, 0, -2/(far - near), -(far + near)/(far - near),
|
||||
0, 0, 0, 1};
|
||||
#else
|
||||
float A[16] = { 2 / (right - left), 0, 0, 0,
|
||||
0, 2 / (top - bottom), 0, 0,
|
||||
0, 0, -2 / (far - near), 0,
|
||||
-(right + left) / (right - left), -(top + bottom) / (top - bottom), -(far + near) / (far - near), 1 };
|
||||
#endif
|
||||
|
||||
GPU_MultiplyAndAssign(result, A);
|
||||
}
|
||||
}
|
||||
|
||||
void GPU_Frustum(float right, float left, float bottom, float top, float near, float far)
|
||||
{
|
||||
float* result = GPU_GetCurrentMatrix();
|
||||
if(result == NULL)
|
||||
return;
|
||||
|
||||
{
|
||||
#ifdef ROW_MAJOR
|
||||
float A[16] = {2 * near / (right - left), 0, 0, 0,
|
||||
0, 2 * near / (top - bottom), 0, 0,
|
||||
(right + left) / (right - left), (top + bottom) / (top - bottom), -(far + near) / (far - near), -1,
|
||||
0, 0, -(2 * far * near) / (far - near), 0};
|
||||
#else
|
||||
float A[16] = { 2 * near / (right - left), 0, (right + left) / (right - left), 0,
|
||||
0, 2 * near / (top - bottom), (top + bottom) / (top - bottom), 0,
|
||||
0, 0, -(far + near) / (far - near), -(2 * far * near) / (far - near),
|
||||
0, 0, -1, 0 };
|
||||
#endif
|
||||
|
||||
GPU_MultiplyAndAssign(result, A);
|
||||
}
|
||||
}
|
||||
|
||||
void GPU_Translate(float x, float y, float z)
|
||||
{
|
||||
float* result = GPU_GetCurrentMatrix();
|
||||
if(result == NULL)
|
||||
return;
|
||||
|
||||
{
|
||||
#ifdef ROW_MAJOR
|
||||
float A[16] = {1, 0, 0, x,
|
||||
0, 1, 0, y,
|
||||
0, 0, 1, z,
|
||||
0, 0, 0, 1};
|
||||
#else
|
||||
float A[16] = { 1, 0, 0, 0,
|
||||
0, 1, 0, 0,
|
||||
0, 0, 1, 0,
|
||||
x, y, z, 1 };
|
||||
#endif
|
||||
|
||||
GPU_MultiplyAndAssign(result, A);
|
||||
}
|
||||
}
|
||||
|
||||
void GPU_Scale(float sx, float sy, float sz)
|
||||
{
|
||||
float* result = GPU_GetCurrentMatrix();
|
||||
if(result == NULL)
|
||||
return;
|
||||
|
||||
{
|
||||
float A[16] = { sx, 0, 0, 0,
|
||||
0, sy, 0, 0,
|
||||
0, 0, sz, 0,
|
||||
0, 0, 0, 1 };
|
||||
|
||||
GPU_MultiplyAndAssign(result, A);
|
||||
}
|
||||
}
|
||||
|
||||
void GPU_Rotate(float degrees, float x, float y, float z)
|
||||
{
|
||||
float p, radians, c, s, c_, zc_, yc_, xzc_, xyc_, yzc_, xs, ys, zs;
|
||||
float* result;
|
||||
|
||||
p = 1/sqrtf(x*x + y*y + z*z);
|
||||
x *= p; y *= p; z *= p;
|
||||
radians = degrees * (M_PI/180);
|
||||
c = cosf(radians);
|
||||
s = sinf(radians);
|
||||
c_ = 1 - c;
|
||||
zc_ = z*c_;
|
||||
yc_ = y*c_;
|
||||
xzc_ = x*zc_;
|
||||
xyc_ = x*y*c_;
|
||||
yzc_ = y*zc_;
|
||||
xs = x*s;
|
||||
ys = y*s;
|
||||
zs = z*s;
|
||||
|
||||
result = GPU_GetCurrentMatrix();
|
||||
if(result == NULL)
|
||||
return;
|
||||
|
||||
{
|
||||
#ifdef ROW_MAJOR
|
||||
float A[16] = {x*x*c_ + c, xyc_ - zs, xzc_ + ys, 0,
|
||||
xyc_ + zs, y*yc_ + c, yzc_ - xs, 0,
|
||||
xzc_ - ys, yzc_ + xs, z*zc_ + c, 0,
|
||||
0, 0, 0, 1};
|
||||
#else
|
||||
float A[16] = { x*x*c_ + c, xyc_ + zs, xzc_ - ys, 0,
|
||||
xyc_ - zs, y*yc_ + c, yzc_ + xs, 0,
|
||||
xzc_ + ys, yzc_ - xs, z*zc_ + c, 0,
|
||||
0, 0, 0, 1 };
|
||||
#endif
|
||||
|
||||
GPU_MultiplyAndAssign(result, A);
|
||||
}
|
||||
}
|
||||
|
||||
void GPU_MultMatrix(float* A)
|
||||
{
|
||||
float* result = GPU_GetCurrentMatrix();
|
||||
if(result == NULL)
|
||||
return;
|
||||
GPU_MultiplyAndAssign(result, A);
|
||||
}
|
||||
|
||||
void GPU_GetModelViewProjection(float* result)
|
||||
{
|
||||
// MVP = P * MV
|
||||
GPU_Multiply4x4(result, GPU_GetProjection(), GPU_GetModelView());
|
||||
}
|
|
@ -1,39 +0,0 @@
|
|||
#ifndef _SDL_GPU_GL_MATRIX_H__
|
||||
#define _SDL_GPU_GL_MATRIX_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// Basic matrix operations
|
||||
void GPU_MatrixCopy(float* result, const float* A);
|
||||
void GPU_MatrixIdentity(float* result);
|
||||
void GPU_Multiply4x4(float* result, float* A, float* B);
|
||||
void GPU_MultiplyAndAssign(float* result, float* A);
|
||||
|
||||
|
||||
// State-specific operations
|
||||
#define GPU_MODELVIEW 0
|
||||
#define GPU_PROJECTION 1
|
||||
|
||||
const char* GPU_GetMatrixString(float* A);
|
||||
void GPU_MatrixMode(int matrix_mode);
|
||||
float* GPU_GetCurrentMatrix(void);
|
||||
float* GPU_GetModelView(void);
|
||||
float* GPU_GetProjection(void);
|
||||
void GPU_GetModelViewProjection(float* result);
|
||||
void GPU_PushMatrix(void);
|
||||
void GPU_PopMatrix(void);
|
||||
void GPU_LoadIdentity(void);
|
||||
void GPU_Ortho(float left, float right, float bottom, float top, float near, float far);
|
||||
void GPU_Frustum(float right, float left, float bottom, float top, float near, float far);
|
||||
void GPU_Translate(float x, float y, float z);
|
||||
void GPU_Scale(float sx, float sy, float sz);
|
||||
void GPU_Rotate(float degrees, float x, float y, float z);
|
||||
void GPU_MultMatrix(float* matrix4x4);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -1,51 +0,0 @@
|
|||
#include "SDL_gpu_OpenGL_1.h"
|
||||
|
||||
|
||||
#if defined(SDL_GPU_DISABLE_OPENGL) || defined(SDL_GPU_DISABLE_OPENGL_1)
|
||||
|
||||
// Dummy implementations
|
||||
GPU_Renderer* GPU_CreateRenderer_OpenGL_1(GPU_RendererID request) {return NULL;}
|
||||
void GPU_FreeRenderer_OpenGL_1(GPU_Renderer* renderer) {}
|
||||
|
||||
#else
|
||||
|
||||
// Most of the code pulled in from here...
|
||||
#define SDL_GPU_USE_OPENGL
|
||||
#define SDL_GPU_USE_GL_TIER3
|
||||
#define SDL_GPU_GL_TIER 3
|
||||
#define SDL_GPU_GLSL_VERSION 110
|
||||
#define SDL_GPU_GL_MAJOR_VERSION 1
|
||||
#define SDL_GPU_NO_VAO
|
||||
#include "../GL_common/SDL_gpu_GL_common.inl"
|
||||
#include "../GL_common/SDL_gpuShapes_GL_common.inl"
|
||||
|
||||
|
||||
GPU_Renderer* GPU_CreateRenderer_OpenGL_1(GPU_RendererID request)
|
||||
{
|
||||
GPU_Renderer* renderer = (GPU_Renderer*)malloc(sizeof(GPU_Renderer));
|
||||
if(renderer == NULL)
|
||||
return NULL;
|
||||
|
||||
memset(renderer, 0, sizeof(GPU_Renderer));
|
||||
|
||||
renderer->id = request;
|
||||
renderer->id.id = GPU_RENDERER_OPENGL_1;
|
||||
renderer->shader_language = GPU_LANGUAGE_GLSL;
|
||||
renderer->shader_version = SDL_GPU_GLSL_VERSION;
|
||||
|
||||
renderer->current_context_target = NULL;
|
||||
|
||||
SET_COMMON_FUNCTIONS(renderer);
|
||||
|
||||
return renderer;
|
||||
}
|
||||
|
||||
void GPU_FreeRenderer_OpenGL_1(GPU_Renderer* renderer)
|
||||
{
|
||||
if(renderer == NULL)
|
||||
return;
|
||||
|
||||
free(renderer);
|
||||
}
|
||||
|
||||
#endif
|
|
@ -1,270 +0,0 @@
|
|||
#ifndef _SDL_GPU_OPENGL_1_H__
|
||||
#define _SDL_GPU_OPENGL_1_H__
|
||||
|
||||
#include "SDL_gpu.h"
|
||||
|
||||
#if !defined(SDL_GPU_DISABLE_OPENGL) && !defined(SDL_GPU_DISABLE_OPENGL_1)
|
||||
|
||||
// Hacks to fix compile errors due to polluted namespace
|
||||
#ifdef _WIN32
|
||||
#define _WINUSER_H
|
||||
#define _WINGDI_H
|
||||
#endif
|
||||
|
||||
#include "glew.h"
|
||||
|
||||
#if defined(GL_EXT_bgr) && !defined(GL_BGR)
|
||||
#define GL_BGR GL_BGR_EXT
|
||||
#endif
|
||||
#if defined(GL_EXT_bgra) && !defined(GL_BGRA)
|
||||
#define GL_BGRA GL_BGRA_EXT
|
||||
#endif
|
||||
#if defined(GL_EXT_abgr) && !defined(GL_ABGR)
|
||||
#define GL_ABGR GL_ABGR_EXT
|
||||
#endif
|
||||
|
||||
#undef glBlendFuncSeparate
|
||||
#define glBlendFuncSeparate glBlendFuncSeparateEXT
|
||||
#undef glBlendEquation
|
||||
#define glBlendEquation glBlendEquationEXT
|
||||
#undef glBlendEquationSeparate
|
||||
#define glBlendEquationSeparate glBlendEquationSeparateEXT
|
||||
|
||||
#undef GL_MIRRORED_REPEAT
|
||||
#define GL_MIRRORED_REPEAT GL_MIRRORED_REPEAT_ARB
|
||||
|
||||
#undef glCreateShader
|
||||
#undef GL_VERTEX_SHADER
|
||||
#undef GL_FRAGMENT_SHADER
|
||||
#undef glShaderSource
|
||||
#undef glCompileShader
|
||||
#undef glGetShaderiv
|
||||
#undef GL_COMPILE_STATUS
|
||||
#undef glGetShaderInfoLog
|
||||
#undef glDeleteShader
|
||||
#undef glActiveTexture
|
||||
#undef GL_TEXTURE0
|
||||
#define glCreateShader glCreateShaderObjectARB
|
||||
#define GL_VERTEX_SHADER GL_VERTEX_SHADER_ARB
|
||||
#define GL_FRAGMENT_SHADER GL_FRAGMENT_SHADER_ARB
|
||||
#define glShaderSource glShaderSourceARB
|
||||
#define glCompileShader glCompileShaderARB
|
||||
#define glGetShaderiv glGetObjectParameterivARB
|
||||
#define GL_COMPILE_STATUS GL_OBJECT_COMPILE_STATUS_ARB
|
||||
#define glGetShaderInfoLog glGetInfoLogARB
|
||||
#define glDeleteShader glDeleteObjectARB
|
||||
#define glActiveTexture glActiveTextureARB
|
||||
#define GL_TEXTURE0 GL_TEXTURE0_ARB
|
||||
|
||||
#undef glCreateProgram
|
||||
#undef glAttachShader
|
||||
#undef glLinkProgram
|
||||
#undef GL_LINK_STATUS
|
||||
#undef glGetProgramiv
|
||||
#undef glGetProgramInfoLog
|
||||
#undef glUseProgram
|
||||
#undef glDeleteProgram
|
||||
#define glCreateProgram glCreateProgramObjectARB
|
||||
#define glAttachShader glAttachObjectARB
|
||||
#define glLinkProgram glLinkProgramARB
|
||||
#define GL_LINK_STATUS GL_OBJECT_LINK_STATUS_ARB
|
||||
#define glGetProgramiv glGetObjectParameterivARB
|
||||
#define glGetProgramInfoLog glGetInfoLogARB
|
||||
#define glUseProgram glUseProgramObjectARB
|
||||
#define glDeleteProgram glDeleteObjectARB
|
||||
|
||||
#undef glGetUniformLocation
|
||||
#undef glGetUniformiv
|
||||
#undef glUniform1i
|
||||
#undef glUniform1iv
|
||||
#undef glUniform2iv
|
||||
#undef glUniform3iv
|
||||
#undef glUniform4iv
|
||||
#undef glUniform1f
|
||||
#undef glUniform1fv
|
||||
#undef glUniform2fv
|
||||
#undef glUniform3fv
|
||||
#undef glUniform4fv
|
||||
#undef glUniformMatrix4fv
|
||||
#define glGetUniformLocation glGetUniformLocationARB
|
||||
#define glGetUniformiv glGetUniformivARB
|
||||
#define glUniform1i glUniform1iARB
|
||||
#define glUniform1iv glUniform1ivARB
|
||||
#define glUniform2iv glUniform2ivARB
|
||||
#define glUniform3iv glUniform3ivARB
|
||||
#define glUniform4iv glUniform4ivARB
|
||||
#define glUniform1f glUniform1fARB
|
||||
#define glUniform1fv glUniform1fvARB
|
||||
#define glUniform2fv glUniform2fvARB
|
||||
#define glUniform3fv glUniform3fvARB
|
||||
#define glUniform4fv glUniform4fvARB
|
||||
#define glUniformMatrix4fv glUniformMatrix4fvARB
|
||||
|
||||
#undef glGetAttribLocation
|
||||
#undef glVertexAttrib1f
|
||||
#undef glVertexAttrib2f
|
||||
#undef glVertexAttrib3f
|
||||
#undef glVertexAttrib4f
|
||||
#undef glVertexAttribI1i
|
||||
#undef glVertexAttribI2i
|
||||
#undef glVertexAttribI3i
|
||||
#undef glVertexAttribI4i
|
||||
#undef glVertexAttribI1ui
|
||||
#undef glVertexAttribI2ui
|
||||
#undef glVertexAttribI3ui
|
||||
#undef glVertexAttribI4ui
|
||||
#define glGetAttribLocation glGetAttribLocationARB
|
||||
#define glVertexAttrib1f glVertexAttrib1fARB
|
||||
#define glVertexAttrib2f glVertexAttrib2fARB
|
||||
#define glVertexAttrib3f glVertexAttrib3fARB
|
||||
#define glVertexAttrib4f glVertexAttrib4fARB
|
||||
#define glVertexAttribI1i glVertexAttrib1sARB
|
||||
#define glVertexAttribI2i glVertexAttrib2sARB
|
||||
#define glVertexAttribI3i glVertexAttrib3sARB
|
||||
#define glVertexAttribI4i glVertexAttrib4sARB
|
||||
#define glVertexAttribI1ui glVertexAttrib1sARB
|
||||
#define glVertexAttribI2ui glVertexAttrib2sARB
|
||||
#define glVertexAttribI3ui glVertexAttrib3sARB
|
||||
#define glVertexAttribI4ui glVertexAttrib4sARB
|
||||
|
||||
#undef glGenBuffers
|
||||
#undef glDeleteBuffers
|
||||
#undef glBindBuffer
|
||||
#undef glBufferData
|
||||
#undef glBufferSubData
|
||||
#undef GL_ARRAY_BUFFER
|
||||
#define glGenBuffers glGenBuffersARB
|
||||
#define glDeleteBuffers glDeleteBuffersARB
|
||||
#define glBindBuffer glBindBufferARB
|
||||
#define glBufferData glBufferDataARB
|
||||
#define glBufferSubData glBufferSubDataARB
|
||||
#define GL_ARRAY_BUFFER GL_ARRAY_BUFFER_ARB
|
||||
|
||||
|
||||
#undef glEnableVertexAttribArray
|
||||
#undef glDisableVertexAttribArray
|
||||
#undef glVertexAttribPointer
|
||||
#define glEnableVertexAttribArray glEnableVertexAttribArrayARB
|
||||
#define glDisableVertexAttribArray glDisableVertexAttribArrayARB
|
||||
#define glVertexAttribPointer glVertexAttribPointerARB
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#define GPU_CONTEXT_DATA ContextData_OpenGL_1
|
||||
#define GPU_IMAGE_DATA ImageData_OpenGL_1
|
||||
#define GPU_TARGET_DATA TargetData_OpenGL_1
|
||||
|
||||
|
||||
|
||||
|
||||
#define GPU_DEFAULT_TEXTURED_VERTEX_SHADER_SOURCE \
|
||||
"#version 110\n\
|
||||
\
|
||||
attribute vec2 gpu_Vertex;\n\
|
||||
attribute vec2 gpu_TexCoord;\n\
|
||||
attribute vec4 gpu_Color;\n\
|
||||
uniform mat4 gpu_ModelViewProjectionMatrix;\n\
|
||||
\
|
||||
varying vec4 color;\n\
|
||||
varying vec2 texCoord;\n\
|
||||
\
|
||||
void main(void)\n\
|
||||
{\n\
|
||||
color = gpu_Color;\n\
|
||||
texCoord = vec2(gpu_TexCoord);\n\
|
||||
gl_Position = gpu_ModelViewProjectionMatrix * vec4(gpu_Vertex, 0.0, 1.0);\n\
|
||||
}"
|
||||
|
||||
// Tier 3 uses shader attributes to send position, texcoord, and color data for each vertex.
|
||||
#define GPU_DEFAULT_UNTEXTURED_VERTEX_SHADER_SOURCE \
|
||||
"#version 110\n\
|
||||
\
|
||||
attribute vec2 gpu_Vertex;\n\
|
||||
attribute vec4 gpu_Color;\n\
|
||||
uniform mat4 gpu_ModelViewProjectionMatrix;\n\
|
||||
\
|
||||
varying vec4 color;\n\
|
||||
\
|
||||
void main(void)\n\
|
||||
{\n\
|
||||
color = gpu_Color;\n\
|
||||
gl_Position = gpu_ModelViewProjectionMatrix * vec4(gpu_Vertex, 0.0, 1.0);\n\
|
||||
}"
|
||||
|
||||
|
||||
#define GPU_DEFAULT_TEXTURED_FRAGMENT_SHADER_SOURCE \
|
||||
"#version 110\n\
|
||||
\
|
||||
varying vec4 color;\n\
|
||||
varying vec2 texCoord;\n\
|
||||
\
|
||||
uniform sampler2D tex;\n\
|
||||
\
|
||||
void main(void)\n\
|
||||
{\n\
|
||||
gl_FragColor = texture2D(tex, texCoord) * color;\n\
|
||||
}"
|
||||
|
||||
#define GPU_DEFAULT_UNTEXTURED_FRAGMENT_SHADER_SOURCE \
|
||||
"#version 110\n\
|
||||
\
|
||||
varying vec4 color;\n\
|
||||
\
|
||||
void main(void)\n\
|
||||
{\n\
|
||||
gl_FragColor = color;\n\
|
||||
}"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
typedef struct ContextData_OpenGL_1
|
||||
{
|
||||
SDL_Color last_color;
|
||||
Uint8 last_use_texturing;
|
||||
unsigned int last_shape;
|
||||
Uint8 last_use_blending;
|
||||
GPU_BlendMode last_blend_mode;
|
||||
GPU_Rect last_viewport;
|
||||
GPU_Camera last_camera;
|
||||
Uint8 last_camera_inverted;
|
||||
|
||||
GPU_Image* last_image;
|
||||
GPU_Target* last_target;
|
||||
float* blit_buffer; // Holds sets of 4 vertices and 4 tex coords interleaved (e.g. [x0, y0, z0, s0, t0, ...]).
|
||||
unsigned short blit_buffer_num_vertices;
|
||||
unsigned short blit_buffer_max_num_vertices;
|
||||
unsigned short* index_buffer; // Indexes into the blit buffer so we can use 4 vertices for every 2 triangles (1 quad)
|
||||
unsigned int index_buffer_num_vertices;
|
||||
unsigned int index_buffer_max_num_vertices;
|
||||
|
||||
|
||||
unsigned int blit_VBO[2]; // For double-buffering
|
||||
Uint8 blit_VBO_flop;
|
||||
GPU_ShaderBlock shader_block[2];
|
||||
GPU_ShaderBlock current_shader_block;
|
||||
|
||||
GPU_AttributeSource shader_attributes[16];
|
||||
unsigned int attribute_VBO[16];
|
||||
} ContextData_OpenGL_1;
|
||||
|
||||
typedef struct ImageData_OpenGL_1
|
||||
{
|
||||
int refcount;
|
||||
Uint32 handle;
|
||||
Uint32 format;
|
||||
} ImageData_OpenGL_1;
|
||||
|
||||
typedef struct TargetData_OpenGL_1
|
||||
{
|
||||
int refcount;
|
||||
Uint32 handle;
|
||||
Uint32 format;
|
||||
} TargetData_OpenGL_1;
|
||||
|
||||
|
||||
|
||||
#endif
|
|
@ -1,52 +0,0 @@
|
|||
#include "SDL_gpu_OpenGL_1_BASE.h"
|
||||
|
||||
|
||||
#if defined(SDL_GPU_DISABLE_OPENGL) || defined(SDL_GPU_DISABLE_OPENGL_1_BASE)
|
||||
|
||||
// Dummy implementations
|
||||
GPU_Renderer* GPU_CreateRenderer_OpenGL_1_BASE(GPU_RendererID request) {return NULL;}
|
||||
void GPU_FreeRenderer_OpenGL_1_BASE(GPU_Renderer* renderer) {}
|
||||
|
||||
#else
|
||||
|
||||
// Most of the code pulled in from here...
|
||||
#define SDL_GPU_USE_OPENGL
|
||||
#define SDL_GPU_DISABLE_SHADERS
|
||||
#define SDL_GPU_USE_GL_TIER1
|
||||
#define SDL_GPU_GL_TIER 1
|
||||
#define SDL_GPU_GL_MAJOR_VERSION 1
|
||||
#define SDL_GPU_APPLY_TRANSFORMS_TO_GL_STACK
|
||||
#define SDL_GPU_NO_VAO
|
||||
#include "../GL_common/SDL_gpu_GL_common.inl"
|
||||
#include "../GL_common/SDL_gpuShapes_GL_common.inl"
|
||||
|
||||
|
||||
GPU_Renderer* GPU_CreateRenderer_OpenGL_1_BASE(GPU_RendererID request)
|
||||
{
|
||||
GPU_Renderer* renderer = (GPU_Renderer*)malloc(sizeof(GPU_Renderer));
|
||||
if(renderer == NULL)
|
||||
return NULL;
|
||||
|
||||
memset(renderer, 0, sizeof(GPU_Renderer));
|
||||
|
||||
renderer->id = request;
|
||||
renderer->id.id = GPU_RENDERER_OPENGL_1_BASE;
|
||||
renderer->shader_language = GPU_LANGUAGE_NONE;
|
||||
renderer->shader_version = 0;
|
||||
|
||||
renderer->current_context_target = NULL;
|
||||
|
||||
SET_COMMON_FUNCTIONS(renderer);
|
||||
|
||||
return renderer;
|
||||
}
|
||||
|
||||
void GPU_FreeRenderer_OpenGL_1_BASE(GPU_Renderer* renderer)
|
||||
{
|
||||
if(renderer == NULL)
|
||||
return;
|
||||
|
||||
free(renderer);
|
||||
}
|
||||
|
||||
#endif
|
|
@ -1,76 +0,0 @@
|
|||
#ifndef _SDL_GPU_OPENGL_1_BASE_H__
|
||||
#define _SDL_GPU_OPENGL_1_BASE_H__
|
||||
|
||||
#include "SDL_gpu.h"
|
||||
|
||||
#if !defined(SDL_GPU_DISABLE_OPENGL) && !defined(SDL_GPU_DISABLE_OPENGL_1_BASE)
|
||||
|
||||
// Hacks to fix compile errors due to polluted namespace
|
||||
#ifdef _WIN32
|
||||
#define _WINUSER_H
|
||||
#define _WINGDI_H
|
||||
#endif
|
||||
|
||||
#include "glew.h"
|
||||
|
||||
#if defined(GL_EXT_bgr) && !defined(GL_BGR)
|
||||
#define GL_BGR GL_BGR_EXT
|
||||
#endif
|
||||
#if defined(GL_EXT_bgra) && !defined(GL_BGRA)
|
||||
#define GL_BGRA GL_BGRA_EXT
|
||||
#endif
|
||||
#if defined(GL_EXT_abgr) && !defined(GL_ABGR)
|
||||
#define GL_ABGR GL_ABGR_EXT
|
||||
#endif
|
||||
|
||||
#undef GL_MIRRORED_REPEAT
|
||||
#define GL_MIRRORED_REPEAT GL_MIRRORED_REPEAT_ARB
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#define GPU_CONTEXT_DATA ContextData_OpenGL_1_BASE
|
||||
#define GPU_IMAGE_DATA ImageData_OpenGL_1_BASE
|
||||
#define GPU_TARGET_DATA TargetData_OpenGL_1_BASE
|
||||
|
||||
|
||||
|
||||
|
||||
typedef struct ContextData_OpenGL_1_BASE
|
||||
{
|
||||
SDL_Color last_color;
|
||||
Uint8 last_use_texturing;
|
||||
unsigned int last_shape;
|
||||
Uint8 last_use_blending;
|
||||
GPU_BlendMode last_blend_mode;
|
||||
GPU_Rect last_viewport;
|
||||
GPU_Camera last_camera;
|
||||
Uint8 last_camera_inverted;
|
||||
|
||||
GPU_Image* last_image;
|
||||
GPU_Target* last_target;
|
||||
float* blit_buffer; // Holds sets of 4 vertices and 4 tex coords interleaved (e.g. [x0, y0, z0, s0, t0, ...]).
|
||||
unsigned short blit_buffer_num_vertices;
|
||||
unsigned short blit_buffer_max_num_vertices;
|
||||
unsigned short* index_buffer; // Indexes into the blit buffer so we can use 4 vertices for every 2 triangles (1 quad)
|
||||
unsigned int index_buffer_num_vertices;
|
||||
unsigned int index_buffer_max_num_vertices;
|
||||
} ContextData_OpenGL_1_BASE;
|
||||
|
||||
typedef struct ImageData_OpenGL_1_BASE
|
||||
{
|
||||
int refcount;
|
||||
Uint32 handle;
|
||||
Uint32 format;
|
||||
} ImageData_OpenGL_1_BASE;
|
||||
|
||||
typedef struct TargetData_OpenGL_1_BASE
|
||||
{
|
||||
int refcount;
|
||||
Uint32 handle;
|
||||
Uint32 format;
|
||||
} TargetData_OpenGL_1_BASE;
|
||||
|
||||
|
||||
|
||||
#endif
|
|
@ -1,52 +0,0 @@
|
|||
#include "SDL_gpu_OpenGL_2.h"
|
||||
|
||||
|
||||
#if defined(SDL_GPU_DISABLE_OPENGL) || defined(SDL_GPU_DISABLE_OPENGL_2)
|
||||
|
||||
// Dummy implementations
|
||||
GPU_Renderer* GPU_CreateRenderer_OpenGL_2(GPU_RendererID request) {return NULL;}
|
||||
void GPU_FreeRenderer_OpenGL_2(GPU_Renderer* renderer) {}
|
||||
|
||||
#else
|
||||
|
||||
// Most of the code pulled in from here...
|
||||
#define SDL_GPU_USE_OPENGL
|
||||
#define SDL_GPU_USE_GL_TIER3
|
||||
#define SDL_GPU_GL_TIER 3
|
||||
#define SDL_GPU_GLSL_VERSION 120
|
||||
#define SDL_GPU_GL_MAJOR_VERSION 2
|
||||
#define SDL_GPU_NO_VAO
|
||||
#include "../GL_common/SDL_gpu_GL_common.inl"
|
||||
#include "../GL_common/SDL_gpuShapes_GL_common.inl"
|
||||
|
||||
|
||||
GPU_Renderer* GPU_CreateRenderer_OpenGL_2(GPU_RendererID request)
|
||||
{
|
||||
GPU_Renderer* renderer = (GPU_Renderer*)malloc(sizeof(GPU_Renderer));
|
||||
if(renderer == NULL)
|
||||
return NULL;
|
||||
|
||||
memset(renderer, 0, sizeof(GPU_Renderer));
|
||||
|
||||
renderer->id = request;
|
||||
renderer->id.id = GPU_RENDERER_OPENGL_2;
|
||||
renderer->shader_language = GPU_LANGUAGE_GLSL;
|
||||
renderer->shader_version = SDL_GPU_GLSL_VERSION;
|
||||
|
||||
renderer->current_context_target = NULL;
|
||||
|
||||
SET_COMMON_FUNCTIONS(renderer);
|
||||
|
||||
return renderer;
|
||||
}
|
||||
|
||||
void GPU_FreeRenderer_OpenGL_2(GPU_Renderer* renderer)
|
||||
{
|
||||
if(renderer == NULL)
|
||||
return;
|
||||
|
||||
free(renderer);
|
||||
}
|
||||
|
||||
|
||||
#endif
|
|
@ -1,141 +0,0 @@
|
|||
#ifndef _SDL_GPU_OPENGL_2_H__
|
||||
#define _SDL_GPU_OPENGL_2_H__
|
||||
|
||||
#include "SDL_gpu.h"
|
||||
|
||||
#if !defined(SDL_GPU_DISABLE_OPENGL) && !defined(SDL_GPU_DISABLE_OPENGL_2)
|
||||
|
||||
// Hacks to fix compile errors due to polluted namespace
|
||||
#ifdef _WIN32
|
||||
#define _WINUSER_H
|
||||
#define _WINGDI_H
|
||||
#endif
|
||||
|
||||
#include "glew.h"
|
||||
|
||||
#if defined(GL_EXT_bgr) && !defined(GL_BGR)
|
||||
#define GL_BGR GL_BGR_EXT
|
||||
#endif
|
||||
#if defined(GL_EXT_bgra) && !defined(GL_BGRA)
|
||||
#define GL_BGRA GL_BGRA_EXT
|
||||
#endif
|
||||
#if defined(GL_EXT_abgr) && !defined(GL_ABGR)
|
||||
#define GL_ABGR GL_ABGR_EXT
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#define GPU_CONTEXT_DATA ContextData_OpenGL_2
|
||||
#define GPU_IMAGE_DATA ImageData_OpenGL_2
|
||||
#define GPU_TARGET_DATA TargetData_OpenGL_2
|
||||
|
||||
|
||||
|
||||
#define GPU_DEFAULT_TEXTURED_VERTEX_SHADER_SOURCE \
|
||||
"#version 120\n\
|
||||
\
|
||||
attribute vec2 gpu_Vertex;\n\
|
||||
attribute vec2 gpu_TexCoord;\n\
|
||||
attribute vec4 gpu_Color;\n\
|
||||
uniform mat4 gpu_ModelViewProjectionMatrix;\n\
|
||||
\
|
||||
varying vec4 color;\n\
|
||||
varying vec2 texCoord;\n\
|
||||
\
|
||||
void main(void)\n\
|
||||
{\n\
|
||||
color = gpu_Color;\n\
|
||||
texCoord = vec2(gpu_TexCoord);\n\
|
||||
gl_Position = gpu_ModelViewProjectionMatrix * vec4(gpu_Vertex, 0.0, 1.0);\n\
|
||||
}"
|
||||
|
||||
// Tier 3 uses shader attributes to send position, texcoord, and color data for each vertex.
|
||||
#define GPU_DEFAULT_UNTEXTURED_VERTEX_SHADER_SOURCE \
|
||||
"#version 120\n\
|
||||
\
|
||||
attribute vec2 gpu_Vertex;\n\
|
||||
attribute vec4 gpu_Color;\n\
|
||||
uniform mat4 gpu_ModelViewProjectionMatrix;\n\
|
||||
\
|
||||
varying vec4 color;\n\
|
||||
\
|
||||
void main(void)\n\
|
||||
{\n\
|
||||
color = gpu_Color;\n\
|
||||
gl_Position = gpu_ModelViewProjectionMatrix * vec4(gpu_Vertex, 0.0, 1.0);\n\
|
||||
}"
|
||||
|
||||
|
||||
#define GPU_DEFAULT_TEXTURED_FRAGMENT_SHADER_SOURCE \
|
||||
"#version 120\n\
|
||||
\
|
||||
varying vec4 color;\n\
|
||||
varying vec2 texCoord;\n\
|
||||
\
|
||||
uniform sampler2D tex;\n\
|
||||
\
|
||||
void main(void)\n\
|
||||
{\n\
|
||||
gl_FragColor = texture2D(tex, texCoord) * color;\n\
|
||||
}"
|
||||
|
||||
#define GPU_DEFAULT_UNTEXTURED_FRAGMENT_SHADER_SOURCE \
|
||||
"#version 120\n\
|
||||
\
|
||||
varying vec4 color;\n\
|
||||
\
|
||||
void main(void)\n\
|
||||
{\n\
|
||||
gl_FragColor = color;\n\
|
||||
}"
|
||||
|
||||
|
||||
|
||||
typedef struct ContextData_OpenGL_2
|
||||
{
|
||||
SDL_Color last_color;
|
||||
Uint8 last_use_texturing;
|
||||
unsigned int last_shape;
|
||||
Uint8 last_use_blending;
|
||||
GPU_BlendMode last_blend_mode;
|
||||
GPU_Rect last_viewport;
|
||||
GPU_Camera last_camera;
|
||||
Uint8 last_camera_inverted;
|
||||
|
||||
GPU_Image* last_image;
|
||||
GPU_Target* last_target;
|
||||
float* blit_buffer; // Holds sets of 4 vertices and 4 tex coords interleaved (e.g. [x0, y0, z0, s0, t0, ...]).
|
||||
unsigned short blit_buffer_num_vertices;
|
||||
unsigned short blit_buffer_max_num_vertices;
|
||||
unsigned short* index_buffer; // Indexes into the blit buffer so we can use 4 vertices for every 2 triangles (1 quad)
|
||||
unsigned int index_buffer_num_vertices;
|
||||
unsigned int index_buffer_max_num_vertices;
|
||||
|
||||
|
||||
unsigned int blit_VBO[2]; // For double-buffering
|
||||
Uint8 blit_VBO_flop;
|
||||
GPU_ShaderBlock shader_block[2];
|
||||
GPU_ShaderBlock current_shader_block;
|
||||
|
||||
GPU_AttributeSource shader_attributes[16];
|
||||
unsigned int attribute_VBO[16];
|
||||
} ContextData_OpenGL_2;
|
||||
|
||||
typedef struct ImageData_OpenGL_2
|
||||
{
|
||||
int refcount;
|
||||
Uint32 handle;
|
||||
Uint32 format;
|
||||
} ImageData_OpenGL_2;
|
||||
|
||||
typedef struct TargetData_OpenGL_2
|
||||
{
|
||||
int refcount;
|
||||
Uint32 handle;
|
||||
Uint32 format;
|
||||
} TargetData_OpenGL_2;
|
||||
|
||||
|
||||
|
||||
#endif
|
|
@ -1,52 +0,0 @@
|
|||
#include "SDL_gpu_OpenGL_3.h"
|
||||
|
||||
|
||||
#if defined(SDL_GPU_DISABLE_OPENGL) || defined(SDL_GPU_DISABLE_OPENGL_3)
|
||||
|
||||
// Dummy implementations
|
||||
GPU_Renderer* GPU_CreateRenderer_OpenGL_3(GPU_RendererID request) {return NULL;}
|
||||
void GPU_FreeRenderer_OpenGL_3(GPU_Renderer* renderer) {}
|
||||
|
||||
#else
|
||||
|
||||
|
||||
// Most of the code pulled in from here...
|
||||
#define SDL_GPU_USE_OPENGL
|
||||
#define SDL_GPU_USE_GL_TIER3
|
||||
#define SDL_GPU_GL_TIER 3
|
||||
#define SDL_GPU_GLSL_VERSION 130
|
||||
#define SDL_GPU_GL_MAJOR_VERSION 3
|
||||
#include "../GL_common/SDL_gpu_GL_common.inl"
|
||||
#include "../GL_common/SDL_gpuShapes_GL_common.inl"
|
||||
|
||||
|
||||
GPU_Renderer* GPU_CreateRenderer_OpenGL_3(GPU_RendererID request)
|
||||
{
|
||||
GPU_Renderer* renderer = (GPU_Renderer*)malloc(sizeof(GPU_Renderer));
|
||||
if(renderer == NULL)
|
||||
return NULL;
|
||||
|
||||
memset(renderer, 0, sizeof(GPU_Renderer));
|
||||
|
||||
renderer->id = request;
|
||||
renderer->id.id = GPU_RENDERER_OPENGL_3;
|
||||
renderer->shader_language = GPU_LANGUAGE_GLSL;
|
||||
renderer->shader_version = SDL_GPU_GLSL_VERSION;
|
||||
|
||||
renderer->current_context_target = NULL;
|
||||
|
||||
SET_COMMON_FUNCTIONS(renderer);
|
||||
|
||||
return renderer;
|
||||
}
|
||||
|
||||
void GPU_FreeRenderer_OpenGL_3(GPU_Renderer* renderer)
|
||||
{
|
||||
if(renderer == NULL)
|
||||
return;
|
||||
|
||||
free(renderer);
|
||||
}
|
||||
|
||||
|
||||
#endif
|
|
@ -1,139 +0,0 @@
|
|||
#ifndef _SDL_GPU_OPENGL_3_H__
|
||||
#define _SDL_GPU_OPENGL_3_H__
|
||||
|
||||
#include "SDL_gpu.h"
|
||||
|
||||
#if !defined(SDL_GPU_DISABLE_OPENGL) && !defined(SDL_GPU_DISABLE_OPENGL_3)
|
||||
|
||||
// Hacks to fix compile errors due to polluted namespace
|
||||
#ifdef _WIN32
|
||||
#define _WINUSER_H
|
||||
#define _WINGDI_H
|
||||
#endif
|
||||
|
||||
#include "glew.h"
|
||||
|
||||
#if defined(GL_EXT_bgr) && !defined(GL_BGR)
|
||||
#define GL_BGR GL_BGR_EXT
|
||||
#endif
|
||||
#if defined(GL_EXT_bgra) && !defined(GL_BGRA)
|
||||
#define GL_BGRA GL_BGRA_EXT
|
||||
#endif
|
||||
#if defined(GL_EXT_abgr) && !defined(GL_ABGR)
|
||||
#define GL_ABGR GL_ABGR_EXT
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
#define GPU_CONTEXT_DATA ContextData_OpenGL_3
|
||||
#define GPU_IMAGE_DATA ImageData_OpenGL_3
|
||||
#define GPU_TARGET_DATA TargetData_OpenGL_3
|
||||
|
||||
|
||||
#define GPU_DEFAULT_TEXTURED_VERTEX_SHADER_SOURCE \
|
||||
"#version 130\n\
|
||||
\
|
||||
in vec2 gpu_Vertex;\n\
|
||||
in vec2 gpu_TexCoord;\n\
|
||||
in vec4 gpu_Color;\n\
|
||||
uniform mat4 gpu_ModelViewProjectionMatrix;\n\
|
||||
\
|
||||
out vec4 color;\n\
|
||||
out vec2 texCoord;\n\
|
||||
\
|
||||
void main(void)\n\
|
||||
{\n\
|
||||
color = gpu_Color;\n\
|
||||
texCoord = vec2(gpu_TexCoord);\n\
|
||||
gl_Position = gpu_ModelViewProjectionMatrix * vec4(gpu_Vertex, 0.0, 1.0);\n\
|
||||
}"
|
||||
|
||||
// Tier 3 uses shader attributes to send position, texcoord, and color data for each vertex.
|
||||
#define GPU_DEFAULT_UNTEXTURED_VERTEX_SHADER_SOURCE \
|
||||
"#version 130\n\
|
||||
\
|
||||
in vec2 gpu_Vertex;\n\
|
||||
in vec4 gpu_Color;\n\
|
||||
uniform mat4 gpu_ModelViewProjectionMatrix;\n\
|
||||
\
|
||||
out vec4 color;\n\
|
||||
\
|
||||
void main(void)\n\
|
||||
{\n\
|
||||
color = gpu_Color;\n\
|
||||
gl_Position = gpu_ModelViewProjectionMatrix * vec4(gpu_Vertex, 0.0, 1.0);\n\
|
||||
}"
|
||||
|
||||
|
||||
#define GPU_DEFAULT_TEXTURED_FRAGMENT_SHADER_SOURCE \
|
||||
"#version 130\n\
|
||||
\
|
||||
in vec4 color;\n\
|
||||
in vec2 texCoord;\n\
|
||||
\
|
||||
uniform sampler2D tex;\n\
|
||||
\
|
||||
void main(void)\n\
|
||||
{\n\
|
||||
gl_FragColor = texture2D(tex, texCoord) * color;\n\
|
||||
}"
|
||||
|
||||
#define GPU_DEFAULT_UNTEXTURED_FRAGMENT_SHADER_SOURCE \
|
||||
"#version 130\n\
|
||||
\
|
||||
in vec4 color;\n\
|
||||
\
|
||||
void main(void)\n\
|
||||
{\n\
|
||||
gl_FragColor = color;\n\
|
||||
}"
|
||||
|
||||
|
||||
typedef struct ContextData_OpenGL_3
|
||||
{
|
||||
SDL_Color last_color;
|
||||
Uint8 last_use_texturing;
|
||||
unsigned int last_shape;
|
||||
Uint8 last_use_blending;
|
||||
GPU_BlendMode last_blend_mode;
|
||||
GPU_Rect last_viewport;
|
||||
GPU_Camera last_camera;
|
||||
Uint8 last_camera_inverted;
|
||||
|
||||
GPU_Image* last_image;
|
||||
GPU_Target* last_target;
|
||||
float* blit_buffer; // Holds sets of 4 vertices, each with interleaved position, tex coords, and colors (e.g. [x0, y0, z0, s0, t0, r0, g0, b0, a0, ...]).
|
||||
unsigned short blit_buffer_num_vertices;
|
||||
unsigned short blit_buffer_max_num_vertices;
|
||||
unsigned short* index_buffer; // Indexes into the blit buffer so we can use 4 vertices for every 2 triangles (1 quad)
|
||||
unsigned int index_buffer_num_vertices;
|
||||
unsigned int index_buffer_max_num_vertices;
|
||||
|
||||
// Tier 3 rendering
|
||||
unsigned int blit_VAO;
|
||||
unsigned int blit_VBO[2]; // For double-buffering
|
||||
Uint8 blit_VBO_flop;
|
||||
GPU_ShaderBlock shader_block[2];
|
||||
GPU_ShaderBlock current_shader_block;
|
||||
|
||||
GPU_AttributeSource shader_attributes[16];
|
||||
unsigned int attribute_VBO[16];
|
||||
} ContextData_OpenGL_3;
|
||||
|
||||
typedef struct ImageData_OpenGL_3
|
||||
{
|
||||
int refcount;
|
||||
Uint32 handle;
|
||||
Uint32 format;
|
||||
} ImageData_OpenGL_3;
|
||||
|
||||
typedef struct TargetData_OpenGL_3
|
||||
{
|
||||
int refcount;
|
||||
Uint32 handle;
|
||||
Uint32 format;
|
||||
} TargetData_OpenGL_3;
|
||||
|
||||
|
||||
|
||||
#endif
|
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
|
@ -1,3 +0,0 @@
|
|||
get_filename_component(SELF_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH)
|
||||
include(${SELF_DIR}/SDL_gpu-targets.cmake)
|
||||
|
|
@ -1,173 +0,0 @@
|
|||
#include "SDL_gpu.h"
|
||||
#include <string.h>
|
||||
|
||||
#define CHECK_RENDERER(ret) \
|
||||
GPU_Renderer* renderer = GPU_GetCurrentRenderer(); \
|
||||
if(renderer == NULL) \
|
||||
return ret;
|
||||
|
||||
|
||||
float GPU_SetLineThickness(float thickness)
|
||||
{
|
||||
CHECK_RENDERER(1.0f);
|
||||
if(renderer->SetLineThickness == NULL)
|
||||
return 1.0f;
|
||||
|
||||
return renderer->SetLineThickness(renderer, thickness);
|
||||
}
|
||||
|
||||
float GPU_GetLineThickness(void)
|
||||
{
|
||||
CHECK_RENDERER(1.0f);
|
||||
if(renderer->GetLineThickness == NULL)
|
||||
return 1.0f;
|
||||
|
||||
return renderer->GetLineThickness(renderer);
|
||||
}
|
||||
|
||||
void GPU_Pixel(GPU_Target* target, float x, float y, SDL_Color color)
|
||||
{
|
||||
CHECK_RENDERER();
|
||||
if(renderer->Pixel == NULL)
|
||||
return;
|
||||
|
||||
renderer->Pixel(renderer, target, x, y, color);
|
||||
}
|
||||
|
||||
void GPU_Line(GPU_Target* target, float x1, float y1, float x2, float y2, SDL_Color color)
|
||||
{
|
||||
CHECK_RENDERER();
|
||||
if(renderer->Line == NULL)
|
||||
return;
|
||||
|
||||
renderer->Line(renderer, target, x1, y1, x2, y2, color);
|
||||
}
|
||||
|
||||
|
||||
void GPU_Arc(GPU_Target* target, float x, float y, float radius, float start_angle, float end_angle, SDL_Color color)
|
||||
{
|
||||
CHECK_RENDERER();
|
||||
if(renderer->Arc == NULL)
|
||||
return;
|
||||
|
||||
renderer->Arc(renderer, target, x, y, radius, start_angle, end_angle, color);
|
||||
}
|
||||
|
||||
|
||||
void GPU_ArcFilled(GPU_Target* target, float x, float y, float radius, float start_angle, float end_angle, SDL_Color color)
|
||||
{
|
||||
CHECK_RENDERER();
|
||||
if(renderer->ArcFilled == NULL)
|
||||
return;
|
||||
|
||||
renderer->ArcFilled(renderer, target, x, y, radius, start_angle, end_angle, color);
|
||||
}
|
||||
|
||||
void GPU_Circle(GPU_Target* target, float x, float y, float radius, SDL_Color color)
|
||||
{
|
||||
CHECK_RENDERER();
|
||||
if(renderer->Circle == NULL)
|
||||
return;
|
||||
|
||||
renderer->Circle(renderer, target, x, y, radius, color);
|
||||
}
|
||||
|
||||
void GPU_CircleFilled(GPU_Target* target, float x, float y, float radius, SDL_Color color)
|
||||
{
|
||||
CHECK_RENDERER();
|
||||
if(renderer->CircleFilled == NULL)
|
||||
return;
|
||||
|
||||
renderer->CircleFilled(renderer, target, x, y, radius, color);
|
||||
}
|
||||
|
||||
void GPU_Sector(GPU_Target* target, float x, float y, float inner_radius, float outer_radius, float start_angle, float end_angle, SDL_Color color)
|
||||
{
|
||||
CHECK_RENDERER();
|
||||
if(renderer->Sector == NULL)
|
||||
return;
|
||||
|
||||
renderer->Sector(renderer, target, x, y, inner_radius, outer_radius, start_angle, end_angle, color);
|
||||
}
|
||||
|
||||
void GPU_SectorFilled(GPU_Target* target, float x, float y, float inner_radius, float outer_radius, float start_angle, float end_angle, SDL_Color color)
|
||||
{
|
||||
CHECK_RENDERER();
|
||||
if(renderer->SectorFilled == NULL)
|
||||
return;
|
||||
|
||||
renderer->SectorFilled(renderer, target, x, y, inner_radius, outer_radius, start_angle, end_angle, color);
|
||||
}
|
||||
|
||||
void GPU_Tri(GPU_Target* target, float x1, float y1, float x2, float y2, float x3, float y3, SDL_Color color)
|
||||
{
|
||||
CHECK_RENDERER();
|
||||
if(renderer->Tri == NULL)
|
||||
return;
|
||||
|
||||
renderer->Tri(renderer, target, x1, y1, x2, y2, x3, y3, color);
|
||||
}
|
||||
|
||||
void GPU_TriFilled(GPU_Target* target, float x1, float y1, float x2, float y2, float x3, float y3, SDL_Color color)
|
||||
{
|
||||
CHECK_RENDERER();
|
||||
if(renderer->TriFilled == NULL)
|
||||
return;
|
||||
|
||||
renderer->TriFilled(renderer, target, x1, y1, x2, y2, x3, y3, color);
|
||||
}
|
||||
|
||||
void GPU_Rectangle(GPU_Target* target, float x1, float y1, float x2, float y2, SDL_Color color)
|
||||
{
|
||||
CHECK_RENDERER();
|
||||
if(renderer->Rectangle == NULL)
|
||||
return;
|
||||
|
||||
renderer->Rectangle(renderer, target, x1, y1, x2, y2, color);
|
||||
}
|
||||
|
||||
void GPU_RectangleFilled(GPU_Target* target, float x1, float y1, float x2, float y2, SDL_Color color)
|
||||
{
|
||||
CHECK_RENDERER();
|
||||
if(renderer->RectangleFilled == NULL)
|
||||
return;
|
||||
|
||||
renderer->RectangleFilled(renderer, target, x1, y1, x2, y2, color);
|
||||
}
|
||||
|
||||
void GPU_RectangleRound(GPU_Target* target, float x1, float y1, float x2, float y2, float radius, SDL_Color color)
|
||||
{
|
||||
CHECK_RENDERER();
|
||||
if(renderer->RectangleRound == NULL)
|
||||
return;
|
||||
|
||||
renderer->RectangleRound(renderer, target, x1, y1, x2, y2, radius, color);
|
||||
}
|
||||
|
||||
void GPU_RectangleRoundFilled(GPU_Target* target, float x1, float y1, float x2, float y2, float radius, SDL_Color color)
|
||||
{
|
||||
CHECK_RENDERER();
|
||||
if(renderer->RectangleRoundFilled == NULL)
|
||||
return;
|
||||
|
||||
renderer->RectangleRoundFilled(renderer, target, x1, y1, x2, y2, radius, color);
|
||||
}
|
||||
|
||||
void GPU_Polygon(GPU_Target* target, unsigned int num_vertices, float* vertices, SDL_Color color)
|
||||
{
|
||||
CHECK_RENDERER();
|
||||
if(renderer->Polygon == NULL)
|
||||
return;
|
||||
|
||||
renderer->Polygon(renderer, target, num_vertices, vertices, color);
|
||||
}
|
||||
|
||||
void GPU_PolygonFilled(GPU_Target* target, unsigned int num_vertices, float* vertices, SDL_Color color)
|
||||
{
|
||||
CHECK_RENDERER();
|
||||
if(renderer->PolygonFilled == NULL)
|
||||
return;
|
||||
|
||||
renderer->PolygonFilled(renderer, target, num_vertices, vertices, color);
|
||||
}
|
||||
|
|
@ -1,422 +0,0 @@
|
|||
#include "SDL_gpu.h"
|
||||
#include "SDL_platform.h"
|
||||
#include <string.h>
|
||||
|
||||
#ifndef _MSC_VER
|
||||
#include <strings.h>
|
||||
#else
|
||||
#define __func__ __FUNCTION__
|
||||
#endif
|
||||
|
||||
#define MAX_ACTIVE_RENDERERS 20
|
||||
#define MAX_REGISTERED_RENDERERS 10
|
||||
|
||||
typedef struct RendererRegistration
|
||||
{
|
||||
GPU_RendererID id;
|
||||
GPU_Renderer* (*createFn)(GPU_RendererID request);
|
||||
void (*freeFn)(GPU_Renderer*);
|
||||
} RendererRegistration;
|
||||
|
||||
static Uint8 initialized = 0;
|
||||
|
||||
static GPU_Renderer* rendererMap[MAX_ACTIVE_RENDERERS];
|
||||
static RendererRegistration rendererRegister[MAX_REGISTERED_RENDERERS];
|
||||
|
||||
|
||||
|
||||
static GPU_RendererID makeRendererID(GPU_RendererEnum id, int major_version, int minor_version, int index)
|
||||
{
|
||||
GPU_RendererID r = {id, major_version, minor_version, index};
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
void GPU_InitRendererRegister(void);
|
||||
|
||||
int GPU_GetNumActiveRenderers(void)
|
||||
{
|
||||
int count;
|
||||
int i;
|
||||
|
||||
GPU_InitRendererRegister();
|
||||
|
||||
count = 0;
|
||||
for(i = 0; i < MAX_ACTIVE_RENDERERS; i++)
|
||||
{
|
||||
if(rendererMap[i] != NULL)
|
||||
count++;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
void GPU_GetActiveRendererList(GPU_RendererID* renderers_array)
|
||||
{
|
||||
int count;
|
||||
int i;
|
||||
|
||||
GPU_InitRendererRegister();
|
||||
|
||||
count = 0;
|
||||
for(i = 0; i < MAX_ACTIVE_RENDERERS; i++)
|
||||
{
|
||||
if(rendererMap[i] != NULL)
|
||||
{
|
||||
renderers_array[count] = rendererMap[i]->id;
|
||||
count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int GPU_GetNumRegisteredRenderers(void)
|
||||
{
|
||||
int count;
|
||||
int i;
|
||||
|
||||
GPU_InitRendererRegister();
|
||||
|
||||
count = 0;
|
||||
for(i = 0; i < MAX_REGISTERED_RENDERERS; i++)
|
||||
{
|
||||
if(rendererRegister[i].id.id != GPU_RENDERER_UNKNOWN)
|
||||
count++;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
void GPU_GetRegisteredRendererList(GPU_RendererID* renderers_array)
|
||||
{
|
||||
int count;
|
||||
int i;
|
||||
|
||||
GPU_InitRendererRegister();
|
||||
|
||||
count = 0;
|
||||
for(i = 0; i < MAX_REGISTERED_RENDERERS; i++)
|
||||
{
|
||||
if(rendererRegister[i].id.id != GPU_RENDERER_UNKNOWN)
|
||||
{
|
||||
renderers_array[count] = rendererRegister[i].id;
|
||||
count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
GPU_RendererID GPU_GetRendererID(unsigned int index)
|
||||
{
|
||||
if(index >= MAX_REGISTERED_RENDERERS)
|
||||
return makeRendererID(GPU_RENDERER_UNKNOWN, 0, 0, -1);
|
||||
|
||||
return rendererRegister[index].id;
|
||||
}
|
||||
|
||||
GPU_Renderer* GPU_CreateRenderer_OpenGL_1_BASE(GPU_RendererID request);
|
||||
void GPU_FreeRenderer_OpenGL_1_BASE(GPU_Renderer* renderer);
|
||||
GPU_Renderer* GPU_CreateRenderer_OpenGL_1(GPU_RendererID request);
|
||||
void GPU_FreeRenderer_OpenGL_1(GPU_Renderer* renderer);
|
||||
GPU_Renderer* GPU_CreateRenderer_OpenGL_2(GPU_RendererID request);
|
||||
void GPU_FreeRenderer_OpenGL_2(GPU_Renderer* renderer);
|
||||
GPU_Renderer* GPU_CreateRenderer_OpenGL_3(GPU_RendererID request);
|
||||
void GPU_FreeRenderer_OpenGL_3(GPU_Renderer* renderer);
|
||||
GPU_Renderer* GPU_CreateRenderer_GLES_1(GPU_RendererID request);
|
||||
void GPU_FreeRenderer_GLES_1(GPU_Renderer* renderer);
|
||||
GPU_Renderer* GPU_CreateRenderer_GLES_2(GPU_RendererID request);
|
||||
void GPU_FreeRenderer_GLES_2(GPU_Renderer* renderer);
|
||||
|
||||
void GPU_RegisterRenderers()
|
||||
{
|
||||
int i = 0;
|
||||
|
||||
if(i >= MAX_REGISTERED_RENDERERS)
|
||||
return;
|
||||
|
||||
#ifndef SDL_GPU_DISABLE_OPENGL
|
||||
#ifndef SDL_GPU_DISABLE_OPENGL_1_BASE
|
||||
rendererRegister[i].id = makeRendererID(GPU_RENDERER_OPENGL_1_BASE, 1, 1, i);
|
||||
rendererRegister[i].createFn = &GPU_CreateRenderer_OpenGL_1_BASE;
|
||||
rendererRegister[i].freeFn = &GPU_FreeRenderer_OpenGL_1_BASE;
|
||||
|
||||
i++;
|
||||
if(i >= MAX_REGISTERED_RENDERERS)
|
||||
return;
|
||||
#endif
|
||||
|
||||
#ifndef SDL_GPU_DISABLE_OPENGL_1
|
||||
rendererRegister[i].id = makeRendererID(GPU_RENDERER_OPENGL_1, 1, 1, i);
|
||||
rendererRegister[i].createFn = &GPU_CreateRenderer_OpenGL_1;
|
||||
rendererRegister[i].freeFn = &GPU_FreeRenderer_OpenGL_1;
|
||||
|
||||
i++;
|
||||
if(i >= MAX_REGISTERED_RENDERERS)
|
||||
return;
|
||||
#endif
|
||||
|
||||
#ifndef SDL_GPU_DISABLE_OPENGL_2
|
||||
rendererRegister[i].id = makeRendererID(GPU_RENDERER_OPENGL_2, 2, 0, i);
|
||||
rendererRegister[i].createFn = &GPU_CreateRenderer_OpenGL_2;
|
||||
rendererRegister[i].freeFn = &GPU_FreeRenderer_OpenGL_2;
|
||||
|
||||
i++;
|
||||
if(i >= MAX_REGISTERED_RENDERERS)
|
||||
return;
|
||||
#endif
|
||||
|
||||
#ifndef SDL_GPU_DISABLE_OPENGL_3
|
||||
rendererRegister[i].id = makeRendererID(GPU_RENDERER_OPENGL_3, 3, 0, i);
|
||||
rendererRegister[i].createFn = &GPU_CreateRenderer_OpenGL_3;
|
||||
rendererRegister[i].freeFn = &GPU_FreeRenderer_OpenGL_3;
|
||||
|
||||
i++;
|
||||
if(i >= MAX_REGISTERED_RENDERERS)
|
||||
return;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef SDL_GPU_DISABLE_GLES
|
||||
#ifndef SDL_GPU_DISABLE_GLES_1
|
||||
rendererRegister[i].id = makeRendererID(GPU_RENDERER_GLES_1, 1, 1, i);
|
||||
rendererRegister[i].createFn = &GPU_CreateRenderer_GLES_1;
|
||||
rendererRegister[i].freeFn = &GPU_FreeRenderer_GLES_1;
|
||||
|
||||
i++;
|
||||
if(i >= MAX_REGISTERED_RENDERERS)
|
||||
return;
|
||||
#endif
|
||||
#ifndef SDL_GPU_DISABLE_GLES_2
|
||||
rendererRegister[i].id = makeRendererID(GPU_RENDERER_GLES_2, 2, 0, i);
|
||||
rendererRegister[i].createFn = &GPU_CreateRenderer_GLES_2;
|
||||
rendererRegister[i].freeFn = &GPU_FreeRenderer_GLES_2;
|
||||
|
||||
i++;
|
||||
if(i >= MAX_REGISTERED_RENDERERS)
|
||||
return;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
|
||||
static int renderer_order_size = 0;
|
||||
static GPU_RendererID renderer_order[GPU_RENDERER_ORDER_MAX];
|
||||
|
||||
void GPU_InitRendererRegister(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
if(initialized)
|
||||
return;
|
||||
|
||||
for(i = 0; i < MAX_REGISTERED_RENDERERS; i++)
|
||||
{
|
||||
rendererRegister[i].id.id = GPU_RENDERER_UNKNOWN;
|
||||
rendererRegister[i].id.index = i;
|
||||
rendererRegister[i].createFn = NULL;
|
||||
rendererRegister[i].freeFn = NULL;
|
||||
}
|
||||
for(i = 0; i < MAX_ACTIVE_RENDERERS; i++)
|
||||
{
|
||||
rendererMap[i] = NULL;
|
||||
}
|
||||
|
||||
GPU_GetDefaultRendererOrder(&renderer_order_size, renderer_order);
|
||||
|
||||
initialized = 1;
|
||||
|
||||
GPU_RegisterRenderers();
|
||||
}
|
||||
|
||||
|
||||
void GPU_GetRendererOrder(int* order_size, GPU_RendererID* order)
|
||||
{
|
||||
if(order_size != NULL)
|
||||
*order_size = renderer_order_size;
|
||||
|
||||
if(order != NULL && renderer_order_size > 0)
|
||||
memcpy(order, renderer_order, renderer_order_size*sizeof(GPU_RendererID));
|
||||
}
|
||||
|
||||
void GPU_SetRendererOrder(int order_size, GPU_RendererID* order)
|
||||
{
|
||||
if(order == NULL)
|
||||
{
|
||||
// Restore the default order
|
||||
int count = 0;
|
||||
GPU_RendererID default_order[GPU_RENDERER_ORDER_MAX];
|
||||
GPU_GetDefaultRendererOrder(&count, default_order);
|
||||
GPU_SetRendererOrder(count, default_order); // Call us again with the default order
|
||||
return;
|
||||
}
|
||||
|
||||
if(order_size <= 0)
|
||||
return;
|
||||
|
||||
if(order_size > GPU_RENDERER_ORDER_MAX)
|
||||
{
|
||||
GPU_PushErrorCode(__func__, GPU_ERROR_USER_ERROR, "Given order_size (%d) is greater than GPU_RENDERER_ORDER_MAX (%d)", order_size, GPU_RENDERER_ORDER_MAX);
|
||||
order_size = GPU_RENDERER_ORDER_MAX;
|
||||
}
|
||||
|
||||
memcpy(renderer_order, order, order_size*sizeof(GPU_RendererID));
|
||||
renderer_order_size = order_size;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void GPU_GetDefaultRendererOrder(int* order_size, GPU_RendererID* order)
|
||||
{
|
||||
int count = 0;
|
||||
GPU_RendererID default_order[GPU_RENDERER_ORDER_MAX];
|
||||
|
||||
#if defined(__ANDROID__) || defined(__IPHONEOS__)
|
||||
default_order[count++] = GPU_MakeRendererID(GPU_RENDERER_GLES_2, 2, 0);
|
||||
default_order[count++] = GPU_MakeRendererID(GPU_RENDERER_GLES_1, 1, 1);
|
||||
#else
|
||||
default_order[count++] = GPU_MakeRendererID(GPU_RENDERER_OPENGL_3, 3, 0);
|
||||
default_order[count++] = GPU_MakeRendererID(GPU_RENDERER_OPENGL_2, 2, 0);
|
||||
default_order[count++] = GPU_MakeRendererID(GPU_RENDERER_OPENGL_1, 1, 1);
|
||||
#endif
|
||||
|
||||
if(order_size != NULL)
|
||||
*order_size = count;
|
||||
|
||||
if(order != NULL && count > 0)
|
||||
memcpy(order, default_order, count*sizeof(GPU_RendererID));
|
||||
}
|
||||
|
||||
const char* GPU_GetRendererEnumString(GPU_RendererEnum id)
|
||||
{
|
||||
if(id == GPU_RENDERER_OPENGL_1_BASE)
|
||||
return "OpenGL 1 BASE";
|
||||
if(id == GPU_RENDERER_OPENGL_1)
|
||||
return "OpenGL 1.x";
|
||||
if(id == GPU_RENDERER_OPENGL_2)
|
||||
return "OpenGL 2.x";
|
||||
if(id == GPU_RENDERER_OPENGL_3)
|
||||
return "OpenGL 3.x";
|
||||
if(id == GPU_RENDERER_OPENGL_4)
|
||||
return "OpenGL 4.x";
|
||||
if(id == GPU_RENDERER_GLES_1)
|
||||
return "OpenGLES 1.x";
|
||||
if(id == GPU_RENDERER_GLES_2)
|
||||
return "OpenGLES 2.x";
|
||||
if(id == GPU_RENDERER_GLES_3)
|
||||
return "OpenGLES 3.x";
|
||||
if(id == GPU_RENDERER_D3D9)
|
||||
return "Direct3D 9";
|
||||
if(id == GPU_RENDERER_D3D10)
|
||||
return "Direct3D 10";
|
||||
if(id == GPU_RENDERER_D3D11)
|
||||
return "Direct3D 11";
|
||||
|
||||
return "Unknown";
|
||||
}
|
||||
|
||||
|
||||
GPU_Renderer* GPU_CreateRenderer(GPU_RendererID id)
|
||||
{
|
||||
GPU_Renderer* result = NULL;
|
||||
int i;
|
||||
for(i = 0; i < MAX_REGISTERED_RENDERERS; i++)
|
||||
{
|
||||
if(rendererRegister[i].id.id == GPU_RENDERER_UNKNOWN)
|
||||
continue;
|
||||
|
||||
if(id.id == rendererRegister[i].id.id)
|
||||
{
|
||||
if(rendererRegister[i].createFn != NULL)
|
||||
{
|
||||
result = rendererRegister[i].createFn(id);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(result == NULL)
|
||||
{
|
||||
GPU_PushErrorCode(__func__, GPU_ERROR_DATA_ERROR, "Renderer was not found in the renderer registry.");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
GPU_Renderer* GPU_GetRenderer(unsigned int index)
|
||||
{
|
||||
if(index >= MAX_ACTIVE_RENDERERS)
|
||||
return NULL;
|
||||
|
||||
return rendererMap[index];
|
||||
}
|
||||
|
||||
// Get a renderer from the map.
|
||||
GPU_Renderer* GPU_GetRendererByID(GPU_RendererID id)
|
||||
{
|
||||
GPU_InitRendererRegister();
|
||||
|
||||
if(id.index < 0)
|
||||
return NULL;
|
||||
|
||||
return GPU_GetRenderer(id.index);
|
||||
}
|
||||
|
||||
// Create a new renderer based on a registered id and store it in the map.
|
||||
GPU_Renderer* GPU_AddRenderer(GPU_RendererID id)
|
||||
{
|
||||
int i;
|
||||
for(i = 0; i < MAX_ACTIVE_RENDERERS; i++)
|
||||
{
|
||||
if(rendererMap[i] == NULL)
|
||||
{
|
||||
// Create
|
||||
GPU_Renderer* renderer = GPU_CreateRenderer(id);
|
||||
if(renderer == NULL)
|
||||
{
|
||||
GPU_PushErrorCode(__func__, GPU_ERROR_BACKEND_ERROR, "Failed to create new renderer.");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Add
|
||||
rendererMap[i] = renderer;
|
||||
renderer->id.index = i;
|
||||
// Return
|
||||
return renderer;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void GPU_FreeRenderer(GPU_Renderer* renderer)
|
||||
{
|
||||
int i;
|
||||
for(i = 0; i < MAX_REGISTERED_RENDERERS; i++)
|
||||
{
|
||||
if(rendererRegister[i].id.id == GPU_RENDERER_UNKNOWN)
|
||||
continue;
|
||||
|
||||
if(renderer->id.id == rendererRegister[i].id.id)
|
||||
{
|
||||
rendererRegister[i].freeFn(renderer);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Remove a renderer from the map and free it.
|
||||
void GPU_RemoveRenderer(GPU_RendererID id)
|
||||
{
|
||||
int i;
|
||||
for(i = 0; i < MAX_ACTIVE_RENDERERS; i++)
|
||||
{
|
||||
if(rendererMap[i] == NULL)
|
||||
continue;
|
||||
|
||||
if(i == id.index && id.id == rendererMap[i]->id.id)
|
||||
{
|
||||
GPU_FreeRenderer(rendererMap[i]);
|
||||
rendererMap[i] = NULL;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
15484
src/SDL_gpu/SDL_gpu/externals/glew/glew.c
vendored
15484
src/SDL_gpu/SDL_gpu/externals/glew/glew.c
vendored
File diff suppressed because it is too large
Load diff
15510
src/SDL_gpu/SDL_gpu/externals/glew/glew.h
vendored
15510
src/SDL_gpu/SDL_gpu/externals/glew/glew.h
vendored
File diff suppressed because it is too large
Load diff
1568
src/SDL_gpu/SDL_gpu/externals/glew/glxew.h
vendored
1568
src/SDL_gpu/SDL_gpu/externals/glew/glxew.h
vendored
File diff suppressed because it is too large
Load diff
1361
src/SDL_gpu/SDL_gpu/externals/glew/wglew.h
vendored
1361
src/SDL_gpu/SDL_gpu/externals/glew/wglew.h
vendored
File diff suppressed because it is too large
Load diff
|
@ -1,3 +0,0 @@
|
|||
|
||||
#define STB_IMAGE_IMPLEMENTATION
|
||||
#include "stb_image.h"
|
4655
src/SDL_gpu/SDL_gpu/externals/stb_image/stb_image.h
vendored
4655
src/SDL_gpu/SDL_gpu/externals/stb_image/stb_image.h
vendored
File diff suppressed because it is too large
Load diff
|
@ -1,3 +0,0 @@
|
|||
|
||||
#define STB_IMAGE_WRITE_IMPLEMENTATION
|
||||
#include "stb_image_write.h"
|
|
@ -1,517 +0,0 @@
|
|||
/* stb_image_write - v0.94 - public domain - http://nothings.org/stb/stb_image_write.h
|
||||
writes out PNG/BMP/TGA images to C stdio - Sean Barrett 2010
|
||||
no warranty implied; use at your own risk
|
||||
|
||||
|
||||
Before including,
|
||||
|
||||
#define STB_IMAGE_WRITE_IMPLEMENTATION
|
||||
|
||||
in the file that you want to have the implementation.
|
||||
|
||||
Will probably not work correctly with strict-aliasing optimizations.
|
||||
|
||||
|
||||
ABOUT:
|
||||
|
||||
This header file is a library for writing images to C stdio. It could be
|
||||
adapted to write to memory or a general streaming interface; let me know.
|
||||
|
||||
The PNG output is not optimal; it is 20-50% larger than the file
|
||||
written by a decent optimizing implementation. This library is designed
|
||||
for source code compactness and simplicitly, not optimal image file size
|
||||
or run-time performance.
|
||||
|
||||
USAGE:
|
||||
|
||||
There are three functions, one for each image file format:
|
||||
|
||||
int stbi_write_png(char const *filename, int w, int h, int comp, const void *data, int stride_in_bytes);
|
||||
int stbi_write_bmp(char const *filename, int w, int h, int comp, const void *data);
|
||||
int stbi_write_tga(char const *filename, int w, int h, int comp, const void *data);
|
||||
|
||||
Each function returns 0 on failure and non-0 on success.
|
||||
|
||||
The functions create an image file defined by the parameters. The image
|
||||
is a rectangle of pixels stored from left-to-right, top-to-bottom.
|
||||
Each pixel contains 'comp' channels of data stored interleaved with 8-bits
|
||||
per channel, in the following order: 1=Y, 2=YA, 3=RGB, 4=RGBA. (Y is
|
||||
monochrome color.) The rectangle is 'w' pixels wide and 'h' pixels tall.
|
||||
The *data pointer points to the first byte of the top-left-most pixel.
|
||||
For PNG, "stride_in_bytes" is the distance in bytes from the first byte of
|
||||
a row of pixels to the first byte of the next row of pixels.
|
||||
|
||||
PNG creates output files with the same number of components as the input.
|
||||
The BMP and TGA formats expand Y to RGB in the file format. BMP does not
|
||||
output alpha.
|
||||
|
||||
PNG supports writing rectangles of data even when the bytes storing rows of
|
||||
data are not consecutive in memory (e.g. sub-rectangles of a larger image),
|
||||
by supplying the stride between the beginning of adjacent rows. The other
|
||||
formats do not. (Thus you cannot write a native-format BMP through the BMP
|
||||
writer, both because it is in BGR order and because it may have padding
|
||||
at the end of the line.)
|
||||
*/
|
||||
|
||||
#ifndef INCLUDE_STB_IMAGE_WRITE_H
|
||||
#define INCLUDE_STB_IMAGE_WRITE_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern int stbi_write_png(char const *filename, int w, int h, int comp, const void *data, int stride_in_bytes);
|
||||
extern int stbi_write_bmp(char const *filename, int w, int h, int comp, const void *data);
|
||||
extern int stbi_write_tga(char const *filename, int w, int h, int comp, const void *data);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif//INCLUDE_STB_IMAGE_WRITE_H
|
||||
|
||||
#ifdef STB_IMAGE_WRITE_IMPLEMENTATION
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
|
||||
typedef unsigned int stbiw_uint32;
|
||||
typedef int stb_image_write_test[sizeof(stbiw_uint32)==4 ? 1 : -1];
|
||||
|
||||
static void writefv(FILE *f, const char *fmt, va_list v)
|
||||
{
|
||||
while (*fmt) {
|
||||
switch (*fmt++) {
|
||||
case ' ': break;
|
||||
case '1': { unsigned char x = (unsigned char) va_arg(v, int); fputc(x,f); break; }
|
||||
case '2': { int x = va_arg(v,int); unsigned char b[2];
|
||||
b[0] = (unsigned char) x; b[1] = (unsigned char) (x>>8);
|
||||
fwrite(b,2,1,f); break; }
|
||||
case '4': { stbiw_uint32 x = va_arg(v,int); unsigned char b[4];
|
||||
b[0]=(unsigned char)x; b[1]=(unsigned char)(x>>8);
|
||||
b[2]=(unsigned char)(x>>16); b[3]=(unsigned char)(x>>24);
|
||||
fwrite(b,4,1,f); break; }
|
||||
default:
|
||||
assert(0);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void write3(FILE *f, unsigned char a, unsigned char b, unsigned char c)
|
||||
{
|
||||
unsigned char arr[3];
|
||||
arr[0] = a, arr[1] = b, arr[2] = c;
|
||||
fwrite(arr, 3, 1, f);
|
||||
}
|
||||
|
||||
static void write_pixels(FILE *f, int rgb_dir, int vdir, int x, int y, int comp, void *data, int write_alpha, int scanline_pad)
|
||||
{
|
||||
unsigned char bg[3] = { 255, 0, 255}, px[3];
|
||||
stbiw_uint32 zero = 0;
|
||||
int i,j,k, j_end;
|
||||
|
||||
if (y <= 0)
|
||||
return;
|
||||
|
||||
if (vdir < 0)
|
||||
j_end = -1, j = y-1;
|
||||
else
|
||||
j_end = y, j = 0;
|
||||
|
||||
for (; j != j_end; j += vdir) {
|
||||
for (i=0; i < x; ++i) {
|
||||
unsigned char *d = (unsigned char *) data + (j*x+i)*comp;
|
||||
if (write_alpha < 0)
|
||||
fwrite(&d[comp-1], 1, 1, f);
|
||||
switch (comp) {
|
||||
case 1:
|
||||
case 2: write3(f, d[0],d[0],d[0]);
|
||||
break;
|
||||
case 4:
|
||||
if (!write_alpha) {
|
||||
// composite against pink background
|
||||
for (k=0; k < 3; ++k)
|
||||
px[k] = bg[k] + ((d[k] - bg[k]) * d[3])/255;
|
||||
write3(f, px[1-rgb_dir],px[1],px[1+rgb_dir]);
|
||||
break;
|
||||
}
|
||||
/* FALLTHROUGH */
|
||||
case 3:
|
||||
write3(f, d[1-rgb_dir],d[1],d[1+rgb_dir]);
|
||||
break;
|
||||
}
|
||||
if (write_alpha > 0)
|
||||
fwrite(&d[comp-1], 1, 1, f);
|
||||
}
|
||||
fwrite(&zero,scanline_pad,1,f);
|
||||
}
|
||||
}
|
||||
|
||||
static int outfile(char const *filename, int rgb_dir, int vdir, int x, int y, int comp, void *data, int alpha, int pad, const char *fmt, ...)
|
||||
{
|
||||
FILE *f;
|
||||
if (y < 0 || x < 0) return 0;
|
||||
f = fopen(filename, "wb");
|
||||
if (f) {
|
||||
va_list v;
|
||||
va_start(v, fmt);
|
||||
writefv(f, fmt, v);
|
||||
va_end(v);
|
||||
write_pixels(f,rgb_dir,vdir,x,y,comp,data,alpha,pad);
|
||||
fclose(f);
|
||||
}
|
||||
return f != NULL;
|
||||
}
|
||||
|
||||
int stbi_write_bmp(char const *filename, int x, int y, int comp, const void *data)
|
||||
{
|
||||
int pad = (-x*3) & 3;
|
||||
return outfile(filename,-1,-1,x,y,comp,(void *) data,0,pad,
|
||||
"11 4 22 4" "4 44 22 444444",
|
||||
'B', 'M', 14+40+(x*3+pad)*y, 0,0, 14+40, // file header
|
||||
40, x,y, 1,24, 0,0,0,0,0,0); // bitmap header
|
||||
}
|
||||
|
||||
int stbi_write_tga(char const *filename, int x, int y, int comp, const void *data)
|
||||
{
|
||||
int has_alpha = !(comp & 1);
|
||||
return outfile(filename, -1,-1, x, y, comp, (void *) data, has_alpha, 0,
|
||||
"111 221 2222 11", 0,0,2, 0,0,0, 0,0,x,y, 24+8*has_alpha, 8*has_alpha);
|
||||
}
|
||||
|
||||
// stretchy buffer; stbiw__sbpush() == vector<>::push_back() -- stbiw__sbcount() == vector<>::size()
|
||||
#define stbiw__sbraw(a) ((int *) (a) - 2)
|
||||
#define stbiw__sbm(a) stbiw__sbraw(a)[0]
|
||||
#define stbiw__sbn(a) stbiw__sbraw(a)[1]
|
||||
|
||||
#define stbiw__sbneedgrow(a,n) ((a)==0 || stbiw__sbn(a)+n >= stbiw__sbm(a))
|
||||
#define stbiw__sbmaybegrow(a,n) (stbiw__sbneedgrow(a,(n)) ? stbiw__sbgrow(a,n) : 0)
|
||||
#define stbiw__sbgrow(a,n) stbiw__sbgrowf((void **) &(a), (n), sizeof(*(a)))
|
||||
|
||||
#define stbiw__sbpush(a, v) (stbiw__sbmaybegrow(a,1), (a)[stbiw__sbn(a)++] = (v))
|
||||
#define stbiw__sbcount(a) ((a) ? stbiw__sbn(a) : 0)
|
||||
#define stbiw__sbfree(a) ((a) ? free(stbiw__sbraw(a)),0 : 0)
|
||||
|
||||
static void *stbiw__sbgrowf(void **arr, int increment, int itemsize)
|
||||
{
|
||||
int m = *arr ? 2*stbiw__sbm(*arr)+increment : increment+1;
|
||||
void *p = realloc(*arr ? stbiw__sbraw(*arr) : 0, itemsize * m + sizeof(int)*2);
|
||||
assert(p);
|
||||
if (p) {
|
||||
if (!*arr) ((int *) p)[1] = 0;
|
||||
*arr = (void *) ((int *) p + 2);
|
||||
stbiw__sbm(*arr) = m;
|
||||
}
|
||||
return *arr;
|
||||
}
|
||||
|
||||
static unsigned char *stbiw__zlib_flushf(unsigned char *data, unsigned int *bitbuffer, int *bitcount)
|
||||
{
|
||||
while (*bitcount >= 8) {
|
||||
stbiw__sbpush(data, (unsigned char) *bitbuffer);
|
||||
*bitbuffer >>= 8;
|
||||
*bitcount -= 8;
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
static int stbiw__zlib_bitrev(int code, int codebits)
|
||||
{
|
||||
int res=0;
|
||||
while (codebits--) {
|
||||
res = (res << 1) | (code & 1);
|
||||
code >>= 1;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
static unsigned int stbiw__zlib_countm(unsigned char *a, unsigned char *b, int limit)
|
||||
{
|
||||
int i;
|
||||
for (i=0; i < limit && i < 258; ++i)
|
||||
if (a[i] != b[i]) break;
|
||||
return i;
|
||||
}
|
||||
|
||||
static unsigned int stbiw__zhash(unsigned char *data)
|
||||
{
|
||||
stbiw_uint32 hash = data[0] + (data[1] << 8) + (data[2] << 16);
|
||||
hash ^= hash << 3;
|
||||
hash += hash >> 5;
|
||||
hash ^= hash << 4;
|
||||
hash += hash >> 17;
|
||||
hash ^= hash << 25;
|
||||
hash += hash >> 6;
|
||||
return hash;
|
||||
}
|
||||
|
||||
#define stbiw__zlib_flush() (out = stbiw__zlib_flushf(out, &bitbuf, &bitcount))
|
||||
#define stbiw__zlib_add(code,codebits) \
|
||||
(bitbuf |= (code) << bitcount, bitcount += (codebits), stbiw__zlib_flush())
|
||||
#define stbiw__zlib_huffa(b,c) stbiw__zlib_add(stbiw__zlib_bitrev(b,c),c)
|
||||
// default huffman tables
|
||||
#define stbiw__zlib_huff1(n) stbiw__zlib_huffa(0x30 + (n), 8)
|
||||
#define stbiw__zlib_huff2(n) stbiw__zlib_huffa(0x190 + (n)-144, 9)
|
||||
#define stbiw__zlib_huff3(n) stbiw__zlib_huffa(0 + (n)-256,7)
|
||||
#define stbiw__zlib_huff4(n) stbiw__zlib_huffa(0xc0 + (n)-280,8)
|
||||
#define stbiw__zlib_huff(n) ((n) <= 143 ? stbiw__zlib_huff1(n) : (n) <= 255 ? stbiw__zlib_huff2(n) : (n) <= 279 ? stbiw__zlib_huff3(n) : stbiw__zlib_huff4(n))
|
||||
#define stbiw__zlib_huffb(n) ((n) <= 143 ? stbiw__zlib_huff1(n) : stbiw__zlib_huff2(n))
|
||||
|
||||
#define stbiw__ZHASH 16384
|
||||
|
||||
unsigned char * stbi_zlib_compress(unsigned char *data, int data_len, int *out_len, int quality)
|
||||
{
|
||||
static unsigned short lengthc[] = { 3,4,5,6,7,8,9,10,11,13,15,17,19,23,27,31,35,43,51,59,67,83,99,115,131,163,195,227,258, 259 };
|
||||
static unsigned char lengtheb[]= { 0,0,0,0,0,0,0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0 };
|
||||
static unsigned short distc[] = { 1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193,257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577, 32768 };
|
||||
static unsigned char disteb[] = { 0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13 };
|
||||
unsigned int bitbuf=0;
|
||||
int i,j, bitcount=0;
|
||||
unsigned char *out = NULL;
|
||||
unsigned char **hash_table[stbiw__ZHASH]; // 64KB on the stack!
|
||||
if (quality < 5) quality = 5;
|
||||
|
||||
stbiw__sbpush(out, 0x78); // DEFLATE 32K window
|
||||
stbiw__sbpush(out, 0x5e); // FLEVEL = 1
|
||||
stbiw__zlib_add(1,1); // BFINAL = 1
|
||||
stbiw__zlib_add(1,2); // BTYPE = 1 -- fixed huffman
|
||||
|
||||
for (i=0; i < stbiw__ZHASH; ++i)
|
||||
hash_table[i] = NULL;
|
||||
|
||||
i=0;
|
||||
while (i < data_len-3) {
|
||||
// hash next 3 bytes of data to be compressed
|
||||
int h = stbiw__zhash(data+i)&(stbiw__ZHASH-1), best=3;
|
||||
unsigned char *bestloc = 0;
|
||||
unsigned char **hlist = hash_table[h];
|
||||
int n = stbiw__sbcount(hlist);
|
||||
for (j=0; j < n; ++j) {
|
||||
if (hlist[j]-data > i-32768) { // if entry lies within window
|
||||
int d = stbiw__zlib_countm(hlist[j], data+i, data_len-i);
|
||||
if (d >= best) best=d,bestloc=hlist[j];
|
||||
}
|
||||
}
|
||||
// when hash table entry is too long, delete half the entries
|
||||
if (hash_table[h] && stbiw__sbn(hash_table[h]) == 2*quality) {
|
||||
memcpy(hash_table[h], hash_table[h]+quality, sizeof(hash_table[h][0])*quality);
|
||||
stbiw__sbn(hash_table[h]) = quality;
|
||||
}
|
||||
stbiw__sbpush(hash_table[h],data+i);
|
||||
|
||||
if (bestloc) {
|
||||
// "lazy matching" - check match at *next* byte, and if it's better, do cur byte as literal
|
||||
h = stbiw__zhash(data+i+1)&(stbiw__ZHASH-1);
|
||||
hlist = hash_table[h];
|
||||
n = stbiw__sbcount(hlist);
|
||||
for (j=0; j < n; ++j) {
|
||||
if (hlist[j]-data > i-32767) {
|
||||
int e = stbiw__zlib_countm(hlist[j], data+i+1, data_len-i-1);
|
||||
if (e > best) { // if next match is better, bail on current match
|
||||
bestloc = NULL;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (bestloc) {
|
||||
int d = (int) (data+i - bestloc); // distance back
|
||||
assert(d <= 32767 && best <= 258);
|
||||
for (j=0; best > lengthc[j+1]-1; ++j);
|
||||
stbiw__zlib_huff(j+257);
|
||||
if (lengtheb[j]) stbiw__zlib_add(best - lengthc[j], lengtheb[j]);
|
||||
for (j=0; d > distc[j+1]-1; ++j);
|
||||
stbiw__zlib_add(stbiw__zlib_bitrev(j,5),5);
|
||||
if (disteb[j]) stbiw__zlib_add(d - distc[j], disteb[j]);
|
||||
i += best;
|
||||
} else {
|
||||
stbiw__zlib_huffb(data[i]);
|
||||
++i;
|
||||
}
|
||||
}
|
||||
// write out final bytes
|
||||
for (;i < data_len; ++i)
|
||||
stbiw__zlib_huffb(data[i]);
|
||||
stbiw__zlib_huff(256); // end of block
|
||||
// pad with 0 bits to byte boundary
|
||||
while (bitcount)
|
||||
stbiw__zlib_add(0,1);
|
||||
|
||||
for (i=0; i < stbiw__ZHASH; ++i)
|
||||
(void) stbiw__sbfree(hash_table[i]);
|
||||
|
||||
{
|
||||
// compute adler32 on input
|
||||
unsigned int i=0, s1=1, s2=0, blocklen = data_len % 5552;
|
||||
int j=0;
|
||||
while (j < data_len) {
|
||||
for (i=0; i < blocklen; ++i) s1 += data[j+i], s2 += s1;
|
||||
s1 %= 65521, s2 %= 65521;
|
||||
j += blocklen;
|
||||
blocklen = 5552;
|
||||
}
|
||||
stbiw__sbpush(out, (unsigned char) (s2 >> 8));
|
||||
stbiw__sbpush(out, (unsigned char) s2);
|
||||
stbiw__sbpush(out, (unsigned char) (s1 >> 8));
|
||||
stbiw__sbpush(out, (unsigned char) s1);
|
||||
}
|
||||
*out_len = stbiw__sbn(out);
|
||||
// make returned pointer freeable
|
||||
memmove(stbiw__sbraw(out), out, *out_len);
|
||||
return (unsigned char *) stbiw__sbraw(out);
|
||||
}
|
||||
|
||||
unsigned int stbiw__crc32(unsigned char *buffer, int len)
|
||||
{
|
||||
static unsigned int crc_table[256];
|
||||
unsigned int crc = ~0u;
|
||||
int i,j;
|
||||
if (crc_table[1] == 0)
|
||||
for(i=0; i < 256; i++)
|
||||
for (crc_table[i]=i, j=0; j < 8; ++j)
|
||||
crc_table[i] = (crc_table[i] >> 1) ^ (crc_table[i] & 1 ? 0xedb88320 : 0);
|
||||
for (i=0; i < len; ++i)
|
||||
crc = (crc >> 8) ^ crc_table[buffer[i] ^ (crc & 0xff)];
|
||||
return ~crc;
|
||||
}
|
||||
|
||||
#define stbiw__wpng4(o,a,b,c,d) ((o)[0]=(unsigned char)(a),(o)[1]=(unsigned char)(b),(o)[2]=(unsigned char)(c),(o)[3]=(unsigned char)(d),(o)+=4)
|
||||
#define stbiw__wp32(data,v) stbiw__wpng4(data, (v)>>24,(v)>>16,(v)>>8,(v));
|
||||
#define stbiw__wptag(data,s) stbiw__wpng4(data, s[0],s[1],s[2],s[3])
|
||||
|
||||
static void stbiw__wpcrc(unsigned char **data, int len)
|
||||
{
|
||||
unsigned int crc = stbiw__crc32(*data - len - 4, len+4);
|
||||
stbiw__wp32(*data, crc);
|
||||
}
|
||||
|
||||
static unsigned char stbiw__paeth(int a, int b, int c)
|
||||
{
|
||||
int p = a + b - c, pa = abs(p-a), pb = abs(p-b), pc = abs(p-c);
|
||||
if (pa <= pb && pa <= pc) return (unsigned char) a;
|
||||
if (pb <= pc) return (unsigned char) b;
|
||||
return (unsigned char) c;
|
||||
}
|
||||
|
||||
unsigned char *stbi_write_png_to_mem(unsigned char *pixels, int stride_bytes, int x, int y, int n, int *out_len)
|
||||
{
|
||||
int ctype[5] = { -1, 0, 4, 2, 6 };
|
||||
unsigned char sig[8] = { 137,80,78,71,13,10,26,10 };
|
||||
unsigned char *out,*o, *filt, *zlib;
|
||||
signed char *line_buffer;
|
||||
int i,j,k,p,zlen;
|
||||
|
||||
if (stride_bytes == 0)
|
||||
stride_bytes = x * n;
|
||||
|
||||
filt = (unsigned char *) malloc((x*n+1) * y); if (!filt) return 0;
|
||||
line_buffer = (signed char *) malloc(x * n); if (!line_buffer) { free(filt); return 0; }
|
||||
for (j=0; j < y; ++j) {
|
||||
static int mapping[] = { 0,1,2,3,4 };
|
||||
static int firstmap[] = { 0,1,0,5,6 };
|
||||
int *mymap = j ? mapping : firstmap;
|
||||
int best = 0, bestval = 0x7fffffff;
|
||||
for (p=0; p < 2; ++p) {
|
||||
for (k= p?best:0; k < 5; ++k) {
|
||||
int type = mymap[k],est=0;
|
||||
unsigned char *z = pixels + stride_bytes*j;
|
||||
for (i=0; i < n; ++i)
|
||||
switch (type) {
|
||||
case 0: line_buffer[i] = z[i]; break;
|
||||
case 1: line_buffer[i] = z[i]; break;
|
||||
case 2: line_buffer[i] = z[i] - z[i-stride_bytes]; break;
|
||||
case 3: line_buffer[i] = z[i] - (z[i-stride_bytes]>>1); break;
|
||||
case 4: line_buffer[i] = (signed char) (z[i] - stbiw__paeth(0,z[i-stride_bytes],0)); break;
|
||||
case 5: line_buffer[i] = z[i]; break;
|
||||
case 6: line_buffer[i] = z[i]; break;
|
||||
}
|
||||
for (i=n; i < x*n; ++i) {
|
||||
switch (type) {
|
||||
case 0: line_buffer[i] = z[i]; break;
|
||||
case 1: line_buffer[i] = z[i] - z[i-n]; break;
|
||||
case 2: line_buffer[i] = z[i] - z[i-stride_bytes]; break;
|
||||
case 3: line_buffer[i] = z[i] - ((z[i-n] + z[i-stride_bytes])>>1); break;
|
||||
case 4: line_buffer[i] = z[i] - stbiw__paeth(z[i-n], z[i-stride_bytes], z[i-stride_bytes-n]); break;
|
||||
case 5: line_buffer[i] = z[i] - (z[i-n]>>1); break;
|
||||
case 6: line_buffer[i] = z[i] - stbiw__paeth(z[i-n], 0,0); break;
|
||||
}
|
||||
}
|
||||
if (p) break;
|
||||
for (i=0; i < x*n; ++i)
|
||||
est += abs((signed char) line_buffer[i]);
|
||||
if (est < bestval) { bestval = est; best = k; }
|
||||
}
|
||||
}
|
||||
// when we get here, best contains the filter type, and line_buffer contains the data
|
||||
filt[j*(x*n+1)] = (unsigned char) best;
|
||||
memcpy(filt+j*(x*n+1)+1, line_buffer, x*n);
|
||||
}
|
||||
free(line_buffer);
|
||||
zlib = stbi_zlib_compress(filt, y*( x*n+1), &zlen, 8); // increase 8 to get smaller but use more memory
|
||||
free(filt);
|
||||
if (!zlib) return 0;
|
||||
|
||||
// each tag requires 12 bytes of overhead
|
||||
out = (unsigned char *) malloc(8 + 12+13 + 12+zlen + 12);
|
||||
if (!out) return 0;
|
||||
*out_len = 8 + 12+13 + 12+zlen + 12;
|
||||
|
||||
o=out;
|
||||
memcpy(o,sig,8); o+= 8;
|
||||
stbiw__wp32(o, 13); // header length
|
||||
stbiw__wptag(o, "IHDR");
|
||||
stbiw__wp32(o, x);
|
||||
stbiw__wp32(o, y);
|
||||
*o++ = 8;
|
||||
*o++ = (unsigned char) ctype[n];
|
||||
*o++ = 0;
|
||||
*o++ = 0;
|
||||
*o++ = 0;
|
||||
stbiw__wpcrc(&o,13);
|
||||
|
||||
stbiw__wp32(o, zlen);
|
||||
stbiw__wptag(o, "IDAT");
|
||||
memcpy(o, zlib, zlen); o += zlen; free(zlib);
|
||||
stbiw__wpcrc(&o, zlen);
|
||||
|
||||
stbiw__wp32(o,0);
|
||||
stbiw__wptag(o, "IEND");
|
||||
stbiw__wpcrc(&o,0);
|
||||
|
||||
assert(o == out + *out_len);
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
int stbi_write_png(char const *filename, int x, int y, int comp, const void *data, int stride_bytes)
|
||||
{
|
||||
FILE *f;
|
||||
int len;
|
||||
unsigned char *png = stbi_write_png_to_mem((unsigned char *) data, stride_bytes, x, y, comp, &len);
|
||||
if (!png) return 0;
|
||||
f = fopen(filename, "wb");
|
||||
if (!f) { free(png); return 0; }
|
||||
fwrite(png, 1, len, f);
|
||||
fclose(f);
|
||||
free(png);
|
||||
return 1;
|
||||
}
|
||||
#endif // STB_IMAGE_WRITE_IMPLEMENTATION
|
||||
|
||||
/* Revision history
|
||||
|
||||
0.94 (2014-05-31)
|
||||
rename private functions to avoid conflicts with stb_image.h
|
||||
0.93 (2014-05-27)
|
||||
warning fixes
|
||||
0.92 (2010-08-01)
|
||||
casts to unsigned char to fix warnings
|
||||
0.91 (2010-07-17)
|
||||
first public release
|
||||
0.90 first internal release
|
||||
*/
|
|
@ -1,58 +0,0 @@
|
|||
/*!
|
||||
\mainpage
|
||||
|
||||
SDL_gpu is a C code library for making hardware-accelerated 2D graphics easy.
|
||||
|
||||
SDL_gpu is licensed under the terms of the MIT License.
|
||||
See LICENSE.txt for details of the usage license granted to you for this code.
|
||||
|
||||
|
||||
\section latest_source LATEST SOURCE
|
||||
|
||||
SDL_gpu is hosted on Google Code (http://code.google.com/p/sdl-gpu). You can check out the latest version of the source code with Subversion:
|
||||
svn checkout http://sdl-gpu.googlecode.com/svn/trunk/ sdl-gpu
|
||||
|
||||
To check out everything, including the pre-generated documentation:
|
||||
svn checkout http://sdl-gpu.googlecode.com/svn/ sdl-gpu
|
||||
|
||||
For just the current library code, use:
|
||||
svn checkout http://sdl-gpu.googlecode.com/svn/trunk/ sdl-gpu
|
||||
|
||||
|
||||
\section dependencies DEPENDENCIES
|
||||
|
||||
SDL 1.2 or SDL 2.0 (www.libsdl.org)
|
||||
A rendering backend
|
||||
Currently implemented: OpenGL 1.1, OpenGL 2.0, OpenGL 3.0, OpenGL ES 1.1, OpenGL ES 2.0
|
||||
|
||||
|
||||
\section building BUILDING
|
||||
|
||||
SDL_gpu uses CMake (www.cmake.org) to coordinate the library build process. CMake is available as a GUI program or on the command line.
|
||||
|
||||
For Linux/UNIX systems, run CMake in the base directory:
|
||||
cmake -G "Unix Makefiles"
|
||||
make
|
||||
sudo make install
|
||||
|
||||
For Linux/UNIX systems, changing the default installation directory can be done like so:
|
||||
cmake -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX=/usr
|
||||
|
||||
For Windows systems, you can use cmake-gui and select appropriate options in there (warning: cmake-gui is messy!).
|
||||
|
||||
|
||||
\section including_linking INCLUDING / LINKING
|
||||
|
||||
Add the include for SDL_gpu.h to your sources. Link to SDL_gpu (libSDL_gpu.a) or SDL2_gpu (if you use SDL2).
|
||||
|
||||
|
||||
\section documentation DOCUMENTATION
|
||||
|
||||
Documentation is automatically generated with Doxygen (http://sourceforge.net/projects/doxygen).
|
||||
Pre-generated documentation can be found in the repository's base documentation directory.
|
||||
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
595
src/display.cpp
595
src/display.cpp
|
@ -179,11 +179,7 @@ display::display(const display_context * dc, CVideo& video, std::weak_ptr<wb::ma
|
|||
complete_redraw_event_("completely_redrawn"),
|
||||
nextDraw_(0),
|
||||
reportRects_(),
|
||||
#ifdef SDL_GPU
|
||||
reportImages_(),
|
||||
#else
|
||||
reportSurfaces_(),
|
||||
#endif
|
||||
reports_(),
|
||||
menu_buttons_(),
|
||||
action_buttons_(),
|
||||
|
@ -220,10 +216,6 @@ display::display(const display_context * dc, CVideo& video, std::weak_ptr<wb::ma
|
|||
arrows_map_(),
|
||||
color_adjust_(),
|
||||
dirty_()
|
||||
#ifdef SDL_GPU
|
||||
, update_panel_image_(true),
|
||||
panel_image_()
|
||||
#endif
|
||||
{
|
||||
//The following assertion fails when starting a campaign
|
||||
assert(singleton_ == nullptr);
|
||||
|
@ -337,27 +329,6 @@ void display::init_flags_for_side_internal(size_t n, const std::string& side_col
|
|||
f.start_animation(rand() % f.get_end_time(), true);
|
||||
}
|
||||
|
||||
#ifdef SDL_GPU
|
||||
sdl::timage display::get_flag(const map_location& loc)
|
||||
{
|
||||
if(!get_map().is_village(loc)) {
|
||||
return surface(nullptr);
|
||||
}
|
||||
|
||||
for(size_t i = 0; i != dc_->teams().size(); ++i) {
|
||||
if(dc_->teams()[i].owns_village(loc) &&
|
||||
(!fogged(loc) || !dc_->teams()[currentTeam_].is_enemy(i+1)))
|
||||
{
|
||||
flags_[i].update_last_draw_time();
|
||||
const image::locator &image_flag = animate_map_ ?
|
||||
flags_[i].get_current_frame() : flags_[i].get_first_frame();
|
||||
return image::get_texture(image_flag, image::TOD_COLORED);
|
||||
}
|
||||
}
|
||||
|
||||
return sdl::timage();
|
||||
}
|
||||
#else
|
||||
surface display::get_flag(const map_location& loc)
|
||||
{
|
||||
if(!get_map().is_village(loc)) {
|
||||
|
@ -377,7 +348,6 @@ surface display::get_flag(const map_location& loc)
|
|||
|
||||
return surface(nullptr);
|
||||
}
|
||||
#endif
|
||||
|
||||
void display::set_team(size_t teamindex, bool show_everything)
|
||||
{
|
||||
|
@ -1016,11 +986,7 @@ static const std::string& get_direction(size_t n)
|
|||
return dirs[n >= sizeof(dirs)/sizeof(*dirs) ? 0 : n];
|
||||
}
|
||||
|
||||
#ifdef SDL_GPU
|
||||
std::vector<sdl::timage> display::get_fog_shroud_images(const map_location& loc, image::TYPE image_type)
|
||||
#else
|
||||
std::vector<surface> display::get_fog_shroud_images(const map_location& loc, image::TYPE image_type)
|
||||
#endif
|
||||
{
|
||||
std::vector<std::string> names;
|
||||
|
||||
|
@ -1098,45 +1064,23 @@ std::vector<surface> display::get_fog_shroud_images(const map_location& loc, ima
|
|||
}
|
||||
|
||||
// now get the surfaces
|
||||
#ifdef SDL_GPU
|
||||
std::vector<sdl::timage> res;
|
||||
#else
|
||||
std::vector<surface> res;
|
||||
#endif
|
||||
|
||||
for (std::string& name : names) {
|
||||
#ifdef SDL_GPU
|
||||
const sdl::timage img(image::get_texture(name, image_type));
|
||||
if (!img.null())
|
||||
res.push_back(img);
|
||||
#else
|
||||
const surface surf(image::get_image(name, image_type));
|
||||
if (surf)
|
||||
res.push_back(surf);
|
||||
#endif
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
#ifdef SDL_GPU
|
||||
std::vector<sdl::timage> display::get_terrain_images(
|
||||
const map_location &loc,
|
||||
const std::string& timeid,
|
||||
image::TYPE image_type,
|
||||
TERRAIN_TYPE terrain_type)
|
||||
#else
|
||||
std::vector<surface> display::get_terrain_images(const map_location &loc,
|
||||
const std::string& timeid,
|
||||
image::TYPE image_type,
|
||||
TERRAIN_TYPE terrain_type)
|
||||
#endif
|
||||
{
|
||||
#ifdef SDL_GPU
|
||||
std::vector<sdl::timage> res;
|
||||
#else
|
||||
std::vector<surface> res;
|
||||
#endif
|
||||
|
||||
terrain_builder::TERRAIN_TYPE builder_terrain_type =
|
||||
(terrain_type == FOREGROUND ?
|
||||
|
@ -1191,21 +1135,6 @@ std::vector<surface> display::get_terrain_images(const map_location &loc,
|
|||
// We need to test for the tile to be rendered and
|
||||
// not the location, since the transitions are rendered
|
||||
// over the offmap-terrain and these need a ToD coloring.
|
||||
#ifdef SDL_GPU
|
||||
sdl::timage img;
|
||||
const bool off_map = image.get_filename() == off_map_name;
|
||||
if(!use_local_light || off_map) {
|
||||
img = image::get_texture(image, off_map ? image::SCALED_TO_HEX : image_type);
|
||||
} else if(lt.empty()) {
|
||||
img = image::get_texture(image, image::SCALED_TO_HEX);
|
||||
} else {
|
||||
img = image::get_lighted_texture(image, lt, image::SCALED_TO_HEX);
|
||||
}
|
||||
|
||||
if (!img.null()) {
|
||||
res.push_back(img);
|
||||
}
|
||||
#else
|
||||
surface surf;
|
||||
const bool off_map = image.get_filename() == off_map_name;
|
||||
if(off_map) {
|
||||
|
@ -1219,28 +1148,12 @@ std::vector<surface> display::get_terrain_images(const map_location &loc,
|
|||
if (!surf.null()) {
|
||||
res.push_back(surf);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
#ifdef SDL_GPU
|
||||
void display::drawing_buffer_add(const tdrawing_layer layer,
|
||||
const map_location& loc, int x, int y,
|
||||
const sdl::timage &img)
|
||||
{
|
||||
drawing_buffer_.push_back(tblit(layer, loc, x, y, img));
|
||||
}
|
||||
|
||||
void display::drawing_buffer_add(const tdrawing_layer layer,
|
||||
const map_location& loc, int x, int y,
|
||||
const std::vector<sdl::timage> &imgs)
|
||||
{
|
||||
drawing_buffer_.push_back(tblit(layer, loc, x, y, imgs));
|
||||
}
|
||||
#else
|
||||
void display::drawing_buffer_add(const tdrawing_layer layer,
|
||||
const map_location& loc, int x, int y, const surface& surf,
|
||||
const SDL_Rect &clip)
|
||||
|
@ -1255,7 +1168,6 @@ void display::drawing_buffer_add(const tdrawing_layer layer,
|
|||
{
|
||||
drawing_buffer_.push_back(tblit(layer, loc, x, y, surf, clip));
|
||||
}
|
||||
#endif
|
||||
|
||||
// FIXME: temporary method. Group splitting should be made
|
||||
// public into the definition of tdrawing_layer
|
||||
|
@ -1329,33 +1241,6 @@ void display::drawing_buffer_commit()
|
|||
// std::list::sort() is a stable sort
|
||||
drawing_buffer_.sort();
|
||||
|
||||
#ifdef SDL_GPU
|
||||
SDL_Rect clip_rect = map_area();
|
||||
GPU_SetClip(get_render_target(), clip_rect.x, clip_rect.y, clip_rect.w, clip_rect.h);
|
||||
|
||||
/*
|
||||
* Info regarding the rendering algorithm.
|
||||
*
|
||||
* In order to render a hex properly it needs to be rendered per row. On
|
||||
* this row several layers need to be drawn at the same time. Mainly the
|
||||
* unit and the background terrain. This is needed since both can spill
|
||||
* in the next hex. The foreground terrain needs to be drawn before to
|
||||
* avoid decapitation a unit.
|
||||
*
|
||||
* This ended in the following priority order:
|
||||
* layergroup > location > layer > 'tblit' > surface
|
||||
*/
|
||||
|
||||
for (tblit &blit : drawing_buffer_) {
|
||||
for (sdl::timage& img : blit.images()) {
|
||||
if (!img.null()) {
|
||||
screen_.draw_texture(img, blit.x(), blit.y());
|
||||
}
|
||||
}
|
||||
}
|
||||
drawing_buffer_clear();
|
||||
GPU_UnsetClip(get_render_target());
|
||||
#else
|
||||
SDL_Rect clip_rect = map_area();
|
||||
surface& screen = get_screen_surface();
|
||||
clip_rect_setter set_clip_rect(screen, &clip_rect);
|
||||
|
@ -1387,7 +1272,6 @@ void display::drawing_buffer_commit()
|
|||
}
|
||||
}
|
||||
drawing_buffer_clear();
|
||||
#endif
|
||||
}
|
||||
|
||||
void display::drawing_buffer_clear()
|
||||
|
@ -1429,21 +1313,13 @@ void display::flip()
|
|||
sdl::fill_rect_alpha(r, color, 1, frameBuffer);
|
||||
update_rect(r);
|
||||
}
|
||||
#ifdef SDL_GPU
|
||||
font::draw_floating_labels(screen_);
|
||||
#else
|
||||
font::draw_floating_labels(frameBuffer);
|
||||
#endif
|
||||
events::raise_volatile_draw_event();
|
||||
|
||||
video().flip();
|
||||
|
||||
events::raise_volatile_undraw_event();
|
||||
#ifdef SDL_GPU
|
||||
font::undraw_floating_labels(screen_);
|
||||
#else
|
||||
font::undraw_floating_labels(frameBuffer);
|
||||
#endif
|
||||
}
|
||||
|
||||
void display::update_display()
|
||||
|
@ -1495,11 +1371,7 @@ void display::update_display()
|
|||
|
||||
flip();
|
||||
}
|
||||
#ifdef SDL_GPU
|
||||
static void draw_panel(surface &target, const theme::panel& panel, std::vector<gui::button>& /*buttons*/)
|
||||
#else
|
||||
static void draw_panel(CVideo &video, const theme::panel& panel, std::vector<std::shared_ptr<gui::button>>& /*buttons*/)
|
||||
#endif
|
||||
{
|
||||
//log_scope("draw panel");
|
||||
DBG_DP << "drawing panel " << panel.get_id() << "\n";
|
||||
|
@ -1516,12 +1388,8 @@ static void draw_panel(CVideo &video, const theme::panel& panel, std::vector<std
|
|||
if(surf->w != loc.w || surf->h != loc.h) {
|
||||
surf.assign(tile_surface(surf,loc.w,loc.h));
|
||||
}
|
||||
#ifdef SDL_GPU
|
||||
blit_surface(surf, nullptr, target, &loc);
|
||||
#else
|
||||
video.blit_surface(loc.x, loc.y, surf);
|
||||
update_rect(loc);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1570,23 +1438,6 @@ static void draw_label(CVideo& video, surface target, const theme::label& label)
|
|||
|
||||
void display::draw_all_panels()
|
||||
{
|
||||
#ifdef SDL_GPU
|
||||
const surface& screen(screen_.getSurface());
|
||||
|
||||
/*
|
||||
* The minimap is also a panel, force it to update its contents.
|
||||
* This is required when the size of the minimap has been modified.
|
||||
*/
|
||||
recalculate_minimap();
|
||||
|
||||
draw_panel_image();
|
||||
|
||||
const std::vector<theme::label>& labels = theme_.labels();
|
||||
for(std::vector<theme::label>::const_iterator i = labels.begin(); i != labels.end(); ++i) {
|
||||
draw_label(video(),screen,*i);
|
||||
}
|
||||
render_buttons();
|
||||
#else
|
||||
surface& screen(screen_.getSurface());
|
||||
|
||||
/*
|
||||
|
@ -1606,47 +1457,9 @@ void display::draw_all_panels()
|
|||
}
|
||||
|
||||
render_buttons();
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef SDL_GPU
|
||||
void display::draw_panel_image(SDL_Rect *clip)
|
||||
{
|
||||
surface screen(video().getSurface());
|
||||
|
||||
if (update_panel_image_) {
|
||||
surface surf = create_neutral_surface(screen->w, screen->h);
|
||||
const std::vector<theme::panel>& panels = theme_.panels();
|
||||
for(std::vector<theme::panel>::const_iterator p = panels.begin(); p != panels.end(); ++p) {
|
||||
draw_panel(surf, *p, menu_buttons_);
|
||||
}
|
||||
|
||||
panel_image_ = sdl::timage(surf);
|
||||
update_panel_image_ = false;
|
||||
}
|
||||
|
||||
if (clip != nullptr)
|
||||
GPU_SetClip(get_render_target(), clip->x, clip->y, clip->w, clip->h);
|
||||
|
||||
video().draw_texture(panel_image_, 0, 0);
|
||||
|
||||
if (clip != nullptr)
|
||||
GPU_UnsetClip(get_render_target());
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef SDL_GPU
|
||||
static void draw_background(CVideo &video, const SDL_Rect& area, const std::string& image)
|
||||
{
|
||||
sdl::timage img(image::get_texture(image));
|
||||
if (img.null()) {
|
||||
return;
|
||||
}
|
||||
img.set_wrap(GPU_WRAP_REPEAT, GPU_WRAP_REPEAT);
|
||||
img.set_clip(sdl::create_rect(0, 0, area.w, area.h));
|
||||
video.draw_texture(img, area.x, area.y);
|
||||
}
|
||||
#else
|
||||
static void draw_background(surface screen, const SDL_Rect& area, const std::string& image)
|
||||
{
|
||||
const surface background(image::get_image(image));
|
||||
|
@ -1666,7 +1479,6 @@ static void draw_background(surface screen, const SDL_Rect& area, const std::str
|
|||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void display::draw_text_in_hex(const map_location& loc,
|
||||
const tdrawing_layer layer, const std::string& text,
|
||||
|
@ -1682,19 +1494,6 @@ void display::draw_text_in_hex(const map_location& loc,
|
|||
+ static_cast<int>(x_in_hex* hex_size());
|
||||
const int y = get_location_y(loc) - text_surf->h/2
|
||||
+ static_cast<int>(y_in_hex* hex_size());
|
||||
#ifdef SDL_GPU
|
||||
sdl::timage text_img(text_surf);
|
||||
sdl::timage back_img(back_surf);
|
||||
|
||||
for (int dy=-1; dy <= 1; ++dy) {
|
||||
for (int dx=-1; dx <= 1; ++dx) {
|
||||
if (dx!=0 || dy!=0) {
|
||||
drawing_buffer_add(layer, loc, x + dx, y + dy, back_img);
|
||||
}
|
||||
}
|
||||
}
|
||||
drawing_buffer_add(layer, loc, x, y, text_img);
|
||||
#else
|
||||
for (int dy=-1; dy <= 1; ++dy) {
|
||||
for (int dx=-1; dx <= 1; ++dx) {
|
||||
if (dx!=0 || dy!=0) {
|
||||
|
@ -1703,27 +1502,9 @@ void display::draw_text_in_hex(const map_location& loc,
|
|||
}
|
||||
}
|
||||
drawing_buffer_add(layer, loc, x, y, text_surf);
|
||||
#endif
|
||||
}
|
||||
|
||||
//TODO: convert this to use sdl::ttexture
|
||||
#ifdef SDL_GPU
|
||||
void display::render_image(int x, int y, const display::tdrawing_layer drawing_layer,
|
||||
const map_location& loc, sdl::timage image,
|
||||
bool hreverse, bool greyscale, fixed_t /*alpha*/,
|
||||
Uint32 /*blendto*/, double /*blend_ratio*/, double submerged, bool vreverse)
|
||||
{
|
||||
int effect_flags = hreverse ? SHADER_EFFECT_FLIP : SHADER_EFFECT_NONE |
|
||||
vreverse ? SHADER_EFFECT_FLOP : SHADER_EFFECT_NONE |
|
||||
greyscale ? SHADER_EFFECT_GRAYSCALE : SHADER_EFFECT_NONE;
|
||||
|
||||
image.set_effects(effect_flags);
|
||||
image.set_submerge(submerged);
|
||||
|
||||
drawing_buffer_add(drawing_layer, loc, x, y, image);
|
||||
}
|
||||
|
||||
#else
|
||||
void display::render_image(int x, int y, const display::tdrawing_layer drawing_layer,
|
||||
const map_location& loc, surface image,
|
||||
bool hreverse, bool greyscale, fixed_t alpha,
|
||||
|
@ -1793,7 +1574,6 @@ void display::render_image(int x, int y, const display::tdrawing_layer drawing_l
|
|||
drawing_buffer_add(drawing_layer, loc, x, y, surf);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
void display::select_hex(map_location hex)
|
||||
{
|
||||
invalidate(selectedHex_);
|
||||
|
@ -1845,13 +1625,9 @@ void display::draw_init()
|
|||
if(redraw_background_) {
|
||||
// Full redraw of the background
|
||||
const SDL_Rect clip_rect = map_outside_area();
|
||||
#ifdef SDL_GPU
|
||||
draw_background(screen_, clip_rect, theme_.border().background_image);
|
||||
#else
|
||||
const surface& screen = get_screen_surface();
|
||||
clip_rect_setter set_clip_rect(screen, &clip_rect);
|
||||
draw_background(screen, clip_rect, theme_.border().background_image);
|
||||
#endif
|
||||
update_rect(clip_rect);
|
||||
|
||||
redraw_background_ = false;
|
||||
|
@ -1967,67 +1743,6 @@ void display::announce(const std::string& message, const SDL_Color& color, int l
|
|||
|
||||
void display::draw_border(const map_location& loc, const int xpos, const int ypos)
|
||||
{
|
||||
#ifdef SDL_GPU
|
||||
/**
|
||||
* at the moment the border must be between 0.0 and 0.5
|
||||
* and the image should always be prepared for a 0.5 border.
|
||||
* This way this code doesn't need modifications for other border sizes.
|
||||
*/
|
||||
|
||||
// First handle the corners :
|
||||
if(loc.x == -1 && loc.y == -1) { // top left corner
|
||||
drawing_buffer_add(LAYER_BORDER, loc, xpos + zoom_/4, ypos,
|
||||
image::get_texture(theme_.border().corner_image_top_left, image::SCALED_TO_ZOOM));
|
||||
} else if(loc.x == get_map().w() && loc.y == -1) { // top right corner
|
||||
// We use the map idea of odd and even, and map coords are internal coords + 1
|
||||
if(loc.x%2 == 0) {
|
||||
drawing_buffer_add(LAYER_BORDER, loc, xpos, ypos + zoom_/2,
|
||||
image::get_texture(theme_.border().corner_image_top_right_odd, image::SCALED_TO_ZOOM));
|
||||
} else {
|
||||
drawing_buffer_add(LAYER_BORDER, loc, xpos, ypos,
|
||||
image::get_texture(theme_.border().corner_image_top_right_even, image::SCALED_TO_ZOOM));
|
||||
}
|
||||
} else if(loc.x == -1 && loc.y == get_map().h()) { // bottom left corner
|
||||
drawing_buffer_add(LAYER_BORDER, loc, xpos + zoom_/4, ypos,
|
||||
image::get_texture(theme_.border().corner_image_bottom_left, image::SCALED_TO_ZOOM));
|
||||
|
||||
} else if(loc.x == get_map().w() && loc.y == get_map().h()) { // bottom right corner
|
||||
// We use the map idea of odd and even, and map coords are internal coords + 1
|
||||
if(loc.x%2 == 1) {
|
||||
drawing_buffer_add(LAYER_BORDER, loc, xpos, ypos,
|
||||
image::get_texture(theme_.border().corner_image_bottom_right_even, image::SCALED_TO_ZOOM));
|
||||
} else {
|
||||
drawing_buffer_add(LAYER_BORDER, loc, xpos, ypos,
|
||||
image::get_texture(theme_.border().corner_image_bottom_right_odd, image::SCALED_TO_ZOOM));
|
||||
}
|
||||
|
||||
// Now handle the sides:
|
||||
} else if(loc.x == -1) { // left side
|
||||
drawing_buffer_add(LAYER_BORDER, loc, xpos + zoom_/4, ypos,
|
||||
image::get_texture(theme_.border().border_image_left, image::SCALED_TO_ZOOM));
|
||||
} else if(loc.x == get_map().w()) { // right side
|
||||
drawing_buffer_add(LAYER_BORDER, loc, xpos + zoom_/4, ypos,
|
||||
image::get_texture(theme_.border().border_image_right, image::SCALED_TO_ZOOM));
|
||||
} else if(loc.y == -1) { // top side
|
||||
// We use the map idea of odd and even, and map coords are internal coords + 1
|
||||
if(loc.x%2 == 1) {
|
||||
drawing_buffer_add(LAYER_BORDER, loc, xpos, ypos,
|
||||
image::get_texture(theme_.border().border_image_top_even, image::SCALED_TO_ZOOM));
|
||||
} else {
|
||||
drawing_buffer_add(LAYER_BORDER, loc, xpos, ypos + zoom_/2,
|
||||
image::get_texture(theme_.border().border_image_top_odd, image::SCALED_TO_ZOOM));
|
||||
}
|
||||
} else if(loc.y == get_map().h()) { // bottom side
|
||||
// We use the map idea of odd and even, and map coords are internal coords + 1
|
||||
if(loc.x%2 == 1) {
|
||||
drawing_buffer_add(LAYER_BORDER, loc, xpos, ypos,
|
||||
image::get_texture(theme_.border().border_image_bottom_even, image::SCALED_TO_ZOOM));
|
||||
} else {
|
||||
drawing_buffer_add(LAYER_BORDER, loc, xpos, ypos + zoom_/2,
|
||||
image::get_texture(theme_.border().border_image_bottom_odd, image::SCALED_TO_ZOOM));
|
||||
}
|
||||
}
|
||||
#else
|
||||
/**
|
||||
* at the moment the border must be between 0.0 and 0.5
|
||||
* and the image should always be prepared for a 0.5 border.
|
||||
|
@ -2087,7 +1802,6 @@ void display::draw_border(const map_location& loc, const int xpos, const int ypo
|
|||
image::get_image(theme_.border().border_image_bottom_odd, image::SCALED_TO_ZOOM));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void display::draw_minimap()
|
||||
|
@ -2098,11 +1812,6 @@ void display::draw_minimap()
|
|||
return;
|
||||
}
|
||||
|
||||
#ifdef SDL_GPU
|
||||
minimap_location_ = image::draw_minimap(screen_, area, get_map(), &dc_->teams()[currentTeam_], nullptr);
|
||||
|
||||
draw_minimap_units();
|
||||
#else
|
||||
if(minimap_ == nullptr || minimap_->w > area.w || minimap_->h > area.h) {
|
||||
minimap_ = image::getMinimap(area.w, area.h, get_map(),
|
||||
dc_->teams().empty() ? nullptr : &dc_->teams()[currentTeam_],
|
||||
|
@ -2150,7 +1859,6 @@ void display::draw_minimap()
|
|||
minimap_location_.y + view_y - 1,
|
||||
view_w + 2, view_h + 2,
|
||||
box_color, screen);
|
||||
#endif
|
||||
}
|
||||
|
||||
void display::draw_minimap_units()
|
||||
|
@ -2201,12 +1909,8 @@ void display::draw_minimap_units()
|
|||
, minimap_location_.y + round_double(u_y)
|
||||
, round_double(u_w)
|
||||
, round_double(u_h));
|
||||
#ifdef SDL_GPU
|
||||
sdl::fill_rect(screen_, r, col);
|
||||
#else
|
||||
const Uint32 mapped_col = SDL_MapRGB(video().getSurface()->format,col.r,col.g,col.b);
|
||||
sdl::fill_rect(video().getSurface(), &r, mapped_col);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2268,12 +1972,7 @@ bool display::scroll(int xmove, int ymove, bool force)
|
|||
invalidate_locations_in_rect(r);
|
||||
}
|
||||
scroll_event_.notify_observers();
|
||||
#ifdef SDL_GPU
|
||||
screen_.clear_overlay();
|
||||
invalidate_all();
|
||||
#else
|
||||
update_rect(map_area());
|
||||
#endif
|
||||
|
||||
redrawMinimap_ = true;
|
||||
return true;
|
||||
|
@ -2662,11 +2361,7 @@ void display::redraw_everything()
|
|||
invalidateGameStatus_ = true;
|
||||
|
||||
reportRects_.clear();
|
||||
#ifdef SDL_GPU
|
||||
reportImages_.clear();
|
||||
#else
|
||||
reportSurfaces_.clear();
|
||||
#endif
|
||||
reports_.clear();
|
||||
|
||||
bounds_check_position();
|
||||
|
@ -2852,7 +2547,6 @@ void display::draw_invalidated() {
|
|||
|
||||
}
|
||||
|
||||
//TODO: proper SDL_gpu implementation
|
||||
void display::draw_hex(const map_location& loc) {
|
||||
int xpos = get_location_x(loc);
|
||||
int ypos = get_location_y(loc);
|
||||
|
@ -2868,19 +2562,6 @@ void display::draw_hex(const map_location& loc) {
|
|||
drawing_buffer_add(LAYER_TERRAIN_FG, loc, xpos, ypos,
|
||||
get_terrain_images(loc,tod.id,image_type, FOREGROUND));
|
||||
|
||||
#ifdef SDL_GPU
|
||||
// Draw the grid, if that's been enabled
|
||||
if(grid_ && on_map && !off_map_tile) {
|
||||
static const image::locator grid_top(game_config::images::grid_top);
|
||||
drawing_buffer_add(LAYER_GRID_TOP, loc, xpos, ypos,
|
||||
image::get_texture(grid_top, image::TOD_COLORED));
|
||||
static const image::locator grid_bottom(game_config::images::grid_bottom);
|
||||
drawing_buffer_add(LAYER_GRID_BOTTOM, loc, xpos, ypos,
|
||||
image::get_texture(grid_bottom, image::TOD_COLORED));
|
||||
}
|
||||
// village-control flags.
|
||||
drawing_buffer_add(LAYER_TERRAIN_BG, loc, xpos, ypos, get_flag(loc));
|
||||
#else
|
||||
// Draw the grid, if that's been enabled
|
||||
if(grid_ && on_map && !off_map_tile) {
|
||||
static const image::locator grid_top(game_config::images::grid_top);
|
||||
|
@ -2892,7 +2573,6 @@ void display::draw_hex(const map_location& loc) {
|
|||
}
|
||||
// village-control flags.
|
||||
drawing_buffer_add(LAYER_TERRAIN_BG, loc, xpos, ypos, get_flag(loc));
|
||||
#endif
|
||||
}
|
||||
|
||||
if(!shrouded(loc)) {
|
||||
|
@ -2921,16 +2601,9 @@ void display::draw_hex(const map_location& loc) {
|
|||
&& !(fogged(loc) && !overlays.first->second.visible_in_fog))
|
||||
{
|
||||
|
||||
#ifdef SDL_GPU
|
||||
const sdl::timage img = use_local_light
|
||||
? image::get_lighted_texture(overlays.first->second.image, lt, image::SCALED_TO_HEX)
|
||||
: image::get_texture(overlays.first->second.image, image_type);
|
||||
drawing_buffer_add(LAYER_TERRAIN_BG, loc, xpos, ypos, img);
|
||||
#else
|
||||
const surface surf =
|
||||
image::get_lighted_image(overlays.first->second.image, lt, image::SCALED_TO_HEX);
|
||||
drawing_buffer_add(LAYER_TERRAIN_BG, loc, xpos, ypos, surf);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2938,15 +2611,6 @@ void display::draw_hex(const map_location& loc) {
|
|||
// Draw the time-of-day mask on top of the terrain in the hex.
|
||||
// tod may differ from tod if hex is illuminated.
|
||||
const std::string& tod_hex_mask = tod.image_mask;
|
||||
#ifdef SDL_GPU
|
||||
if(!tod_hex_mask1.null() || !tod_hex_mask2.null()) {
|
||||
drawing_buffer_add(LAYER_TERRAIN_FG, loc, xpos, ypos, tod_hex_mask1);
|
||||
drawing_buffer_add(LAYER_TERRAIN_FG, loc, xpos, ypos, tod_hex_mask2);
|
||||
} else if(!tod_hex_mask.empty()) {
|
||||
drawing_buffer_add(LAYER_TERRAIN_FG, loc, xpos, ypos,
|
||||
image::get_texture(tod_hex_mask,image::SCALED_TO_HEX));
|
||||
}
|
||||
#else
|
||||
if(tod_hex_mask1 != nullptr || tod_hex_mask2 != nullptr) {
|
||||
drawing_buffer_add(LAYER_TERRAIN_FG, loc, xpos, ypos, tod_hex_mask1);
|
||||
drawing_buffer_add(LAYER_TERRAIN_FG, loc, xpos, ypos, tod_hex_mask2);
|
||||
|
@ -2954,15 +2618,10 @@ void display::draw_hex(const map_location& loc) {
|
|||
drawing_buffer_add(LAYER_TERRAIN_FG, loc, xpos, ypos,
|
||||
image::get_image(tod_hex_mask,image::SCALED_TO_HEX));
|
||||
}
|
||||
#endif
|
||||
|
||||
// Paint mouseover overlays
|
||||
if(loc == mouseoverHex_ && (on_map || (in_editor() && get_map().on_board_with_border(loc)))
|
||||
#ifdef SDL_GPU
|
||||
&& !mouseover_hex_overlay_.null()) {
|
||||
#else
|
||||
&& mouseover_hex_overlay_ != nullptr) {
|
||||
#endif
|
||||
drawing_buffer_add(LAYER_MOUSEOVER_OVERLAY, loc, xpos, ypos, mouseover_hex_overlay_);
|
||||
}
|
||||
|
||||
|
@ -2976,19 +2635,6 @@ void display::draw_hex(const map_location& loc) {
|
|||
|
||||
// Apply shroud, fog and linger overlay
|
||||
|
||||
#ifdef SDL_GPU
|
||||
if(shrouded(loc)) {
|
||||
// We apply void also on off-map tiles
|
||||
// to shroud the half-hexes too
|
||||
const std::string& shroud_image = get_variant(shroud_images_, loc);
|
||||
drawing_buffer_add(LAYER_FOG_SHROUD, loc, xpos, ypos,
|
||||
image::get_texture(shroud_image, image_type));
|
||||
} else if(fogged(loc)) {
|
||||
const std::string& fog_image = get_variant(fog_images_, loc);
|
||||
drawing_buffer_add(LAYER_FOG_SHROUD, loc, xpos, ypos,
|
||||
image::get_texture(fog_image, image_type));
|
||||
}
|
||||
#else
|
||||
if(shrouded(loc)) {
|
||||
// We apply void also on off-map tiles
|
||||
// to shroud the half-hexes too
|
||||
|
@ -3000,7 +2646,6 @@ void display::draw_hex(const map_location& loc) {
|
|||
drawing_buffer_add(LAYER_FOG_SHROUD, loc, xpos, ypos,
|
||||
image::get_image(fog_image, image_type));
|
||||
}
|
||||
#endif
|
||||
|
||||
if(!shrouded(loc)) {
|
||||
drawing_buffer_add(LAYER_FOG_SHROUD, loc, xpos, ypos, get_fog_shroud_images(loc, image_type));
|
||||
|
@ -3020,13 +2665,8 @@ void display::draw_hex(const map_location& loc) {
|
|||
} else {
|
||||
off_y -= text->h / 2;
|
||||
}
|
||||
#ifdef SDL_GPU
|
||||
drawing_buffer_add(LAYER_FOG_SHROUD, loc, off_x, off_y, sdl::timage(bg));
|
||||
drawing_buffer_add(LAYER_FOG_SHROUD, loc, off_x, off_y, sdl::timage(text));
|
||||
#else
|
||||
drawing_buffer_add(LAYER_FOG_SHROUD, loc, off_x, off_y, bg);
|
||||
drawing_buffer_add(LAYER_FOG_SHROUD, loc, off_x, off_y, text);
|
||||
#endif
|
||||
}
|
||||
if (draw_terrain_codes_ && (game_config::debug || !shrouded(loc))) {
|
||||
int off_x = xpos + hex_size()/2;
|
||||
|
@ -3039,24 +2679,14 @@ void display::draw_hex(const map_location& loc) {
|
|||
if (!draw_coordinates_) {
|
||||
off_y -= text->h / 2;
|
||||
}
|
||||
#ifdef SDL_GPU
|
||||
drawing_buffer_add(LAYER_FOG_SHROUD, loc, off_x, off_y, sdl::timage(bg));
|
||||
drawing_buffer_add(LAYER_FOG_SHROUD, loc, off_x, off_y, sdl::timage(text));
|
||||
#else
|
||||
drawing_buffer_add(LAYER_FOG_SHROUD, loc, off_x, off_y, bg);
|
||||
drawing_buffer_add(LAYER_FOG_SHROUD, loc, off_x, off_y, text);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
if(debug_foreground) {
|
||||
#ifdef SDL_GPU
|
||||
drawing_buffer_add(LAYER_UNIT_DEFAULT, loc, xpos, ypos,
|
||||
image::get_texture("terrain/foreground.png", image_type));
|
||||
#else
|
||||
drawing_buffer_add(LAYER_UNIT_DEFAULT, loc, xpos, ypos,
|
||||
image::get_image("terrain/foreground.png", image_type));
|
||||
#endif
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -3069,17 +2699,6 @@ image::TYPE display::get_image_type(const map_location& /*loc*/) {
|
|||
|
||||
}*/
|
||||
|
||||
#ifdef SDL_GPU
|
||||
void display::draw_image_for_report(sdl::timage& img, SDL_Rect& rect)
|
||||
{
|
||||
const float scale_factor = std::min(rect.w / img.base_width(), rect.h / img.base_height());
|
||||
img.set_scale(scale_factor, scale_factor);
|
||||
const int xpos = rect.x + (rect.w - img.width())/2;
|
||||
const int ypos = rect.y + (rect.h - img.height())/2;
|
||||
|
||||
screen_.draw_texture(img, xpos, ypos);
|
||||
}
|
||||
#else
|
||||
void display::draw_image_for_report(surface& img, SDL_Rect& rect)
|
||||
{
|
||||
SDL_Rect visible_area = get_non_transparent_portion(img);
|
||||
|
@ -3112,7 +2731,6 @@ void display::draw_image_for_report(surface& img, SDL_Rect& rect)
|
|||
sdl_blit(img,nullptr,screen_.getSurface(),&target);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Redraws the specified report (if anything has changed).
|
||||
|
@ -3121,218 +2739,6 @@ void display::draw_image_for_report(surface& img, SDL_Rect& rect)
|
|||
*/
|
||||
void display::refresh_report(std::string const &report_name, const config * new_cfg)
|
||||
{
|
||||
#ifdef SDL_GPU
|
||||
const theme::status_item *item = theme_.get_status_item(report_name);
|
||||
if (!item) {
|
||||
reportImages_[report_name] = sdl::timage();
|
||||
return;
|
||||
}
|
||||
|
||||
// Now we will need the config. Generate one if needed.
|
||||
|
||||
boost::optional <events::mouse_handler &> mhb = boost::none;
|
||||
|
||||
if (resources::controller) {
|
||||
mhb = resources::controller->get_mouse_handler_base();
|
||||
}
|
||||
|
||||
reports::context temp_context = reports::context(*dc_, *this, *resources::tod_manager, wb_.lock(), mhb);
|
||||
|
||||
const config generated_cfg = new_cfg ? config() : reports_object_->generate_report(report_name, temp_context);
|
||||
if ( new_cfg == nullptr )
|
||||
new_cfg = &generated_cfg;
|
||||
|
||||
SDL_Rect &rect = reportRects_[report_name];
|
||||
const SDL_Rect &new_rect = item->location(screen_area());
|
||||
sdl::timage &img = reportImages_[report_name];
|
||||
config &report = reports_[report_name];
|
||||
|
||||
// Report and its location is unchanged since last time. Do nothing.
|
||||
if (!img.null() && rect == new_rect && report == *new_cfg) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Update the config in reports_.
|
||||
report = *new_cfg;
|
||||
|
||||
if (!img.null()) {
|
||||
screen_.draw_texture(img, rect.x, rect.y);
|
||||
}
|
||||
|
||||
// If the rectangle has just changed, assign the surface to it
|
||||
if (img.null() || new_rect != rect)
|
||||
{
|
||||
img = sdl::timage();
|
||||
rect = new_rect;
|
||||
|
||||
// If the rectangle is present, and we are blitting text,
|
||||
// then we need to backup the surface.
|
||||
// (Images generally won't need backing up,
|
||||
// unless they are transparent, but that is done later).
|
||||
// TODO: handle this somehow for SDL_gpu
|
||||
/*if (rect.w > 0 && rect.h > 0) {
|
||||
img.assign(get_surface_portion(screen_.getSurface(), rect));
|
||||
if (reportSurfaces_[report_name] == nullptr) {
|
||||
ERR_DP << "Could not backup background for report!" << std::endl;
|
||||
}
|
||||
}
|
||||
update_rect(rect);*/
|
||||
}
|
||||
|
||||
tooltips::clear_tooltips(rect);
|
||||
draw_panel_image(&rect);
|
||||
|
||||
if (report.empty()) return;
|
||||
|
||||
int x = rect.x, y = rect.y;
|
||||
|
||||
// Add prefix, postfix elements.
|
||||
// Make sure that they get the same tooltip
|
||||
// as the guys around them.
|
||||
std::string str = item->prefix();
|
||||
if (!str.empty()) {
|
||||
config &e = report.add_child_at("element", config(), 0);
|
||||
e["text"] = str;
|
||||
e["tooltip"] = report.child("element")["tooltip"];
|
||||
}
|
||||
str = item->postfix();
|
||||
if (!str.empty()) {
|
||||
config &e = report.add_child("element");
|
||||
e["text"] = str;
|
||||
e["tooltip"] = report.child("element", -1)["tooltip"];
|
||||
}
|
||||
|
||||
// Loop through and display each report element.
|
||||
int tallest = 0;
|
||||
int image_count = 0;
|
||||
bool used_ellipsis = false;
|
||||
std::ostringstream ellipsis_tooltip;
|
||||
SDL_Rect ellipsis_area = rect;
|
||||
|
||||
for (config::const_child_itors elements = report.child_range("element");
|
||||
elements.first != elements.second; ++elements.first)
|
||||
{
|
||||
SDL_Rect area = sdl::create_rect(x, y, rect.w + rect.x - x, rect.h + rect.y - y);
|
||||
if (area.h <= 0) break;
|
||||
|
||||
std::string t = (*elements.first)["text"];
|
||||
if (!t.empty())
|
||||
{
|
||||
if (used_ellipsis) goto skip_element;
|
||||
|
||||
// Draw a text element.
|
||||
font::ttext text;
|
||||
if (item->font_rgb_set()) {
|
||||
// font_rgb() has no alpha channel and uses a 0x00RRGGBB
|
||||
// layout instead of 0xRRGGBBAA which is what ttext expects,
|
||||
// so shift the value to the left and add fully-opaque alpha.
|
||||
text.set_foreground_color((item->font_rgb() << 8) + 0xFF);
|
||||
}
|
||||
bool eol = false;
|
||||
if (t[t.size() - 1] == '\n') {
|
||||
eol = true;
|
||||
t = t.substr(0, t.size() - 1);
|
||||
}
|
||||
text.set_font_size(item->font_size());
|
||||
text.set_text(t, true);
|
||||
text.set_maximum_width(area.w);
|
||||
text.set_maximum_height(area.h, false);
|
||||
sdl::timage text_img = text.render_as_texture();
|
||||
|
||||
// check if next element is text with almost no space to show it
|
||||
const int minimal_text = 12; // width in pixels
|
||||
config::const_child_iterator ee = elements.first;
|
||||
if (!eol && rect.w - (x - rect.x + text_img.width()) < minimal_text &&
|
||||
++ee != elements.second && !(*ee)["text"].empty())
|
||||
{
|
||||
// make this element longer to trigger rendering of ellipsis
|
||||
// (to indicate that next elements have not enough space)
|
||||
//NOTE this space should be longer than minimal_text pixels
|
||||
t = t + " ";
|
||||
text.set_text(t, true);
|
||||
text_img = text.render_as_texture();
|
||||
// use the area of this element for next tooltips
|
||||
used_ellipsis = true;
|
||||
ellipsis_area.x = x;
|
||||
ellipsis_area.y = y;
|
||||
ellipsis_area.w = text_img.width();
|
||||
ellipsis_area.h = text_img.height();
|
||||
}
|
||||
|
||||
screen_.draw_texture(text_img, x, y);
|
||||
area.w = text_img.width();
|
||||
area.h = text_img.height();
|
||||
if (area.h > tallest) {
|
||||
tallest = area.h;
|
||||
}
|
||||
if (eol) {
|
||||
x = rect.x;
|
||||
y += tallest;
|
||||
tallest = 0;
|
||||
} else {
|
||||
x += area.w;
|
||||
}
|
||||
}
|
||||
else if (!(t = (*elements.first)["image"].str()).empty())
|
||||
{
|
||||
if (used_ellipsis) goto skip_element;
|
||||
|
||||
// Draw an image element.
|
||||
sdl::timage image(image::get_texture(t));
|
||||
|
||||
if (image.null()) {
|
||||
ERR_DP << "could not find image for report: '" << t << "'" << std::endl;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (area.w < image.width() && image_count) {
|
||||
// We have more than one image, and this one doesn't fit.
|
||||
image = image::get_texture(game_config::images::ellipsis);
|
||||
used_ellipsis = true;
|
||||
}
|
||||
|
||||
if (image.width() < area.w) area.w = image.width();
|
||||
if (image.height() < area.h) area.h = image.height();
|
||||
draw_image_for_report(image, area);
|
||||
|
||||
++image_count;
|
||||
if (area.h > tallest) {
|
||||
tallest = area.h;
|
||||
}
|
||||
|
||||
if (!used_ellipsis) {
|
||||
x += area.w;
|
||||
} else {
|
||||
ellipsis_area = area;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// No text nor image, skip this element
|
||||
continue;
|
||||
}
|
||||
|
||||
skip_element:
|
||||
t = (*elements.first)["tooltip"].t_str().base_str();
|
||||
if (!t.empty()) {
|
||||
if (!used_ellipsis) {
|
||||
tooltips::add_tooltip(area, t, (*elements.first)["help"].t_str().base_str());
|
||||
} else {
|
||||
// Collect all tooltips for the ellipsis.
|
||||
// TODO: need a better separator
|
||||
// TODO: assign an action
|
||||
ellipsis_tooltip << t;
|
||||
config::const_child_iterator ee = elements.first;
|
||||
if (++ee != elements.second)
|
||||
ellipsis_tooltip << "\n _________\n\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (used_ellipsis) {
|
||||
tooltips::add_tooltip(ellipsis_area, ellipsis_tooltip.str());
|
||||
}
|
||||
#else
|
||||
const theme::status_item *item = theme_.get_status_item(report_name);
|
||||
if (!item) {
|
||||
reportSurfaces_[report_name].assign(nullptr);
|
||||
|
@ -3542,7 +2948,6 @@ void display::refresh_report(std::string const &report_name, const config * new_
|
|||
if (used_ellipsis) {
|
||||
tooltips::add_tooltip(ellipsis_area, ellipsis_tooltip.str());
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void display::invalidate_all()
|
||||
|
|
|
@ -438,17 +438,6 @@ public:
|
|||
*/
|
||||
void invalidate_animations_location(const map_location& loc);
|
||||
|
||||
#ifdef SDL_GPU
|
||||
/**
|
||||
* mouseover_hex_overlay_ require a prerendered surface
|
||||
* and is drawn underneath the mouse's location
|
||||
*/
|
||||
void set_mouseover_hex_overlay(const sdl::timage& image)
|
||||
{ mouseover_hex_overlay_ = image; }
|
||||
|
||||
void clear_mouseover_hex_overlay()
|
||||
{ mouseover_hex_overlay_ = sdl::timage(); }
|
||||
#else
|
||||
/**
|
||||
* mouseover_hex_overlay_ require a prerendered surface
|
||||
* and is drawn underneath the mouse's location
|
||||
|
@ -458,7 +447,6 @@ public:
|
|||
|
||||
void clear_mouseover_hex_overlay()
|
||||
{ mouseover_hex_overlay_ = nullptr; }
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Debug function to toggle the "sunset" mode.
|
||||
|
@ -737,16 +725,6 @@ protected:
|
|||
|
||||
enum TERRAIN_TYPE { BACKGROUND, FOREGROUND};
|
||||
|
||||
#ifdef SDL_GPU
|
||||
std::vector<sdl::timage> get_terrain_images(const map_location &loc,
|
||||
const std::string& timeid,
|
||||
image::TYPE type,
|
||||
TERRAIN_TYPE terrain_type);
|
||||
|
||||
std::vector<sdl::timage> get_fog_shroud_images(const map_location& loc, image::TYPE image_type);
|
||||
|
||||
void draw_image_for_report(sdl::timage& img, SDL_Rect& rect);
|
||||
#else
|
||||
std::vector<surface> get_terrain_images(const map_location &loc,
|
||||
const std::string& timeid,
|
||||
image::TYPE type,
|
||||
|
@ -755,7 +733,6 @@ protected:
|
|||
std::vector<surface> get_fog_shroud_images(const map_location& loc, image::TYPE image_type);
|
||||
|
||||
void draw_image_for_report(surface& img, SDL_Rect& rect);
|
||||
#endif
|
||||
|
||||
void scroll_to_xy(int screenxpos, int screenypos, SCROLL_TYPE scroll_type,bool force = true);
|
||||
|
||||
|
@ -805,27 +782,16 @@ protected:
|
|||
|
||||
// Not set by the initializer:
|
||||
std::map<std::string, SDL_Rect> reportRects_;
|
||||
#ifdef SDL_GPU
|
||||
std::map<std::string, sdl::timage> reportImages_;
|
||||
#else
|
||||
std::map<std::string, surface> reportSurfaces_;
|
||||
#endif
|
||||
std::map<std::string, config> reports_;
|
||||
std::vector<std::shared_ptr<gui::button>> menu_buttons_, action_buttons_;
|
||||
std::vector<std::shared_ptr<gui::zoom_slider>> sliders_;
|
||||
std::set<map_location> invalidated_;
|
||||
std::set<map_location> previous_invalidated_;
|
||||
#ifdef SDL_GPU
|
||||
sdl::timage mouseover_hex_overlay_;
|
||||
// If we're transitioning from one time of day to the next,
|
||||
// then we will use these two masks on top of all hexes when we blit.
|
||||
sdl::timage tod_hex_mask1, tod_hex_mask2;
|
||||
#else
|
||||
surface mouseover_hex_overlay_;
|
||||
// If we're transitioning from one time of day to the next,
|
||||
// then we will use these two masks on top of all hexes when we blit.
|
||||
surface tod_hex_mask1, tod_hex_mask2;
|
||||
#endif
|
||||
std::vector<std::string> fog_images_;
|
||||
std::vector<std::string> shroud_images_;
|
||||
|
||||
|
@ -841,13 +807,8 @@ protected:
|
|||
|
||||
private:
|
||||
|
||||
#ifdef SDL_GPU
|
||||
// This surface must be freed by the caller
|
||||
sdl::timage get_flag(const map_location& loc);
|
||||
#else
|
||||
// This surface must be freed by the caller
|
||||
surface get_flag(const map_location& loc);
|
||||
#endif
|
||||
|
||||
/** Animated flags for each team */
|
||||
std::vector<animated<image::locator> > flags_;
|
||||
|
@ -907,24 +868,6 @@ public:
|
|||
*/
|
||||
};
|
||||
|
||||
#ifdef SDL_GPU
|
||||
/**
|
||||
* Draw an image at a certain location.
|
||||
* x,y: pixel location on screen to draw the image
|
||||
* image: the image to draw
|
||||
* reverse: if the image should be flipped across the x axis
|
||||
* greyscale: used for instance to give the petrified appearance to a unit image
|
||||
* alpha: the merging to use with the background
|
||||
* blendto: blend to this color using blend_ratio
|
||||
* submerged: the amount of the unit out of 1.0 that is submerged
|
||||
* (presumably under water) and thus shouldn't be drawn
|
||||
*/
|
||||
void render_image(int x, int y, const display::tdrawing_layer drawing_layer,
|
||||
const map_location& loc, sdl::timage image,
|
||||
bool hreverse=false, bool greyscale=false,
|
||||
fixed_t alpha=ftofxp(1.0), Uint32 blendto=0,
|
||||
double blend_ratio=0, double submerged=0.0,bool vreverse =false);
|
||||
#else
|
||||
/**
|
||||
* Draw an image at a certain location.
|
||||
* x,y: pixel location on screen to draw the image
|
||||
|
@ -941,7 +884,6 @@ public:
|
|||
bool hreverse=false, bool greyscale=false,
|
||||
fixed_t alpha=ftofxp(1.0), Uint32 blendto=0,
|
||||
double blend_ratio=0, double submerged=0.0,bool vreverse =false);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Draw text on a hex. (0.5, 0.5) is the center.
|
||||
|
@ -1001,18 +943,6 @@ protected:
|
|||
class tblit
|
||||
{
|
||||
public:
|
||||
#ifdef SDL_GPU
|
||||
tblit(const tdrawing_layer layer, const map_location& loc,
|
||||
const int x, const int y, const sdl::timage& image)
|
||||
: x_(x), y_(y), images_(1, image), key_(loc, layer)
|
||||
{}
|
||||
|
||||
tblit(const tdrawing_layer layer, const map_location& loc,
|
||||
const int x, const int y,
|
||||
const std::vector<sdl::timage>& images)
|
||||
: x_(x), y_(y), images_(images), key_(loc, layer)
|
||||
{}
|
||||
#else
|
||||
tblit(const tdrawing_layer layer, const map_location& loc,
|
||||
const int x, const int y, const surface& surf,
|
||||
const SDL_Rect& clip)
|
||||
|
@ -1026,31 +956,22 @@ protected:
|
|||
: x_(x), y_(y), surf_(surf), clip_(clip),
|
||||
key_(loc, layer)
|
||||
{}
|
||||
#endif
|
||||
|
||||
int x() const { return x_; }
|
||||
int y() const { return y_; }
|
||||
#ifdef SDL_GPU
|
||||
std::vector<sdl::timage> &images() { return images_; }
|
||||
#else
|
||||
const std::vector<surface> &surf() const { return surf_; }
|
||||
const SDL_Rect &clip() const { return clip_; }
|
||||
#endif
|
||||
|
||||
bool operator<(const tblit &rhs) const { return key_ < rhs.key_; }
|
||||
|
||||
private:
|
||||
int x_; /**< x screen coordinate to render at. */
|
||||
int y_; /**< y screen coordinate to render at. */
|
||||
#ifdef SDL_GPU
|
||||
std::vector<sdl::timage> images_;
|
||||
#else
|
||||
std::vector<surface> surf_; /**< surface(s) to render. */
|
||||
SDL_Rect clip_; /**<
|
||||
* The clipping area of the source if
|
||||
* omitted the entire source is used.
|
||||
*/
|
||||
#endif
|
||||
drawing_buffer_key key_;
|
||||
};
|
||||
|
||||
|
@ -1058,15 +979,6 @@ protected:
|
|||
tdrawing_buffer drawing_buffer_;
|
||||
|
||||
public:
|
||||
#ifdef SDL_GPU
|
||||
void drawing_buffer_add(const tdrawing_layer layer,
|
||||
const map_location& loc, int x, int y,
|
||||
const sdl::timage& img);
|
||||
|
||||
void drawing_buffer_add(const tdrawing_layer layer,
|
||||
const map_location& loc, int x, int y,
|
||||
const std::vector<sdl::timage> &imgs);
|
||||
#else
|
||||
/**
|
||||
* Add an item to the drawing buffer. You need to update screen on affected area
|
||||
*
|
||||
|
@ -1082,7 +994,6 @@ public:
|
|||
const map_location& loc, int x, int y,
|
||||
const std::vector<surface> &surf,
|
||||
const SDL_Rect &clip = SDL_Rect());
|
||||
#endif
|
||||
|
||||
protected:
|
||||
|
||||
|
@ -1095,9 +1006,6 @@ protected:
|
|||
/** redraw all panels associated with the map display */
|
||||
void draw_all_panels();
|
||||
|
||||
#ifdef SDL_GPU
|
||||
void draw_panel_image(SDL_Rect *clip = nullptr);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Initiate a redraw.
|
||||
|
@ -1163,10 +1071,6 @@ private:
|
|||
|
||||
bool dirty_;
|
||||
|
||||
#ifdef SDL_GPU
|
||||
bool update_panel_image_;
|
||||
sdl::timage panel_image_;
|
||||
#endif
|
||||
|
||||
|
||||
public:
|
||||
|
|
|
@ -108,18 +108,6 @@ void editor_display::draw_hex(const map_location& loc)
|
|||
int ypos = get_location_y(loc);
|
||||
display::draw_hex(loc);
|
||||
if (map().on_board_with_border(loc)) {
|
||||
#ifdef SDL_GPU
|
||||
if (map().in_selection(loc)) {
|
||||
drawing_buffer_add(LAYER_FOG_SHROUD, loc, xpos, ypos,
|
||||
image::get_texture("editor/selection-overlay.png", image::TOD_COLORED));
|
||||
}
|
||||
|
||||
if (brush_locations_.find(loc) != brush_locations_.end()) {
|
||||
static const image::locator brush(game_config::images::editor_brush);
|
||||
drawing_buffer_add(LAYER_SELECTED_HEX, loc, xpos, ypos,
|
||||
image::get_texture(brush, image::SCALED_TO_HEX));
|
||||
}
|
||||
#else
|
||||
if (map().in_selection(loc)) {
|
||||
drawing_buffer_add(LAYER_FOG_SHROUD, loc, xpos, ypos,
|
||||
image::get_image("editor/selection-overlay.png", image::TOD_COLORED));
|
||||
|
@ -130,7 +118,6 @@ void editor_display::draw_hex(const map_location& loc)
|
|||
drawing_buffer_add(LAYER_SELECTED_HEX, loc, xpos, ypos,
|
||||
image::get_image(brush, image::SCALED_TO_HEX));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -227,30 +227,6 @@ surface floating_label::create_surface()
|
|||
}
|
||||
#endif
|
||||
|
||||
#ifdef SDL_GPU
|
||||
void floating_label::draw(CVideo &video)
|
||||
{
|
||||
if (!visible_) {
|
||||
return;
|
||||
}
|
||||
#if 0
|
||||
create_image();
|
||||
if (img_.null()) {
|
||||
return;
|
||||
}
|
||||
|
||||
video.draw_texture(img_, xpos(img_.width()), int(ypos_));
|
||||
#else
|
||||
create_surface();
|
||||
if (surf_.null()) {
|
||||
return;
|
||||
}
|
||||
|
||||
video.blit_to_overlay(surf_, xpos(surf_->w), int(ypos_));
|
||||
#endif
|
||||
}
|
||||
|
||||
#else
|
||||
void floating_label::draw(surface screen)
|
||||
{
|
||||
if(!visible_) {
|
||||
|
@ -281,15 +257,7 @@ void floating_label::draw(surface screen)
|
|||
|
||||
update_rect(rect);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef SDL_GPU
|
||||
void floating_label::undraw(CVideo &video)
|
||||
{
|
||||
SDL_Rect r = sdl::create_rect(xpos(surf_->w), ypos_, surf_->w, surf_->h);
|
||||
video.clear_overlay_area(r);
|
||||
}
|
||||
#else
|
||||
void floating_label::undraw(surface screen)
|
||||
{
|
||||
if(screen == nullptr || buf_ == nullptr) {
|
||||
|
@ -311,7 +279,6 @@ void floating_label::undraw(surface screen)
|
|||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
int add_floating_label(const floating_label& flabel)
|
||||
{
|
||||
|
@ -385,14 +352,10 @@ SDL_Rect get_floating_label_rect(int handle)
|
|||
|
||||
floating_label_context::floating_label_context()
|
||||
{
|
||||
#ifdef SDL_GPU
|
||||
|
||||
#else
|
||||
surface const screen = nullptr;
|
||||
if(screen != nullptr) {
|
||||
draw_floating_labels(screen);
|
||||
}
|
||||
#endif
|
||||
|
||||
label_contexts.push(std::set<int>());
|
||||
}
|
||||
|
@ -406,55 +369,12 @@ floating_label_context::~floating_label_context()
|
|||
|
||||
label_contexts.pop();
|
||||
|
||||
#ifdef SDL_GPU
|
||||
//TODO
|
||||
#else
|
||||
surface const screen = nullptr;
|
||||
if(screen != nullptr) {
|
||||
undraw_floating_labels(screen);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef SDL_GPU
|
||||
void draw_floating_labels(CVideo &video)
|
||||
{
|
||||
if(label_contexts.empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
const std::set<int>& context = label_contexts.top();
|
||||
|
||||
//draw the labels in the order they were added, so later added labels (likely to be tooltips)
|
||||
//are displayed over earlier added labels.
|
||||
for(label_map::iterator i = labels.begin(); i != labels.end(); ++i) {
|
||||
if(context.count(i->first) > 0) {
|
||||
i->second.draw(video);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void undraw_floating_labels(CVideo &video)
|
||||
{
|
||||
if(label_contexts.empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
std::set<int>& context = label_contexts.top();
|
||||
|
||||
//remove expired labels
|
||||
for(label_map::iterator j = labels.begin(); j != labels.end(); ) {
|
||||
if(context.count(j->first) > 0 && j->second.expired()) {
|
||||
j->second.undraw(video);
|
||||
context.erase(j->first);
|
||||
labels.erase(j++);
|
||||
} else {
|
||||
++j;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#else
|
||||
void draw_floating_labels(surface screen)
|
||||
{
|
||||
if(label_contexts.empty()) {
|
||||
|
@ -498,6 +418,5 @@ void undraw_floating_labels(surface screen)
|
|||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
|
@ -70,13 +70,8 @@ public:
|
|||
void use_markup(bool b) {use_markup_ = b;}
|
||||
|
||||
void move(double xmove, double ymove);
|
||||
#ifdef SDL_GPU
|
||||
void draw(CVideo &video);
|
||||
void undraw(CVideo &video);
|
||||
#else
|
||||
void draw(surface screen);
|
||||
void undraw(surface screen);
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
sdl::timage create_image();
|
||||
|
@ -134,12 +129,7 @@ void remove_floating_label(int handle);
|
|||
void show_floating_label(int handle, bool show);
|
||||
|
||||
SDL_Rect get_floating_label_rect(int handle);
|
||||
#ifdef SDL_GPU
|
||||
void draw_floating_labels(CVideo &video);
|
||||
void undraw_floating_labels(CVideo &video);
|
||||
#else
|
||||
void draw_floating_labels(surface screen);
|
||||
void undraw_floating_labels(surface screen);
|
||||
#endif
|
||||
|
||||
} // end namespace font
|
||||
|
|
|
@ -60,11 +60,7 @@ std::map<map_location,fixed_t> game_display::debugHighlights_;
|
|||
*
|
||||
* This function is only used internally by game_display so I have moved it out of the header into the compilaton unit.
|
||||
*/
|
||||
#ifdef SDL_GPU
|
||||
std::vector<sdl::timage> footsteps_images(const map_location& loc, const pathfind::marked_route & route_, const display_context * dc_);
|
||||
#else
|
||||
std::vector<surface> footsteps_images(const map_location& loc, const pathfind::marked_route & route_, const display_context * dc_);
|
||||
#endif
|
||||
|
||||
game_display::game_display(game_board& board, CVideo& video, std::weak_ptr<wb::manager> wb,
|
||||
reports & reports_object,
|
||||
|
@ -109,7 +105,6 @@ game_display::~game_display()
|
|||
} catch (...) {}
|
||||
}
|
||||
|
||||
//TODO: proper SDL_gpu implementation
|
||||
void game_display::new_turn()
|
||||
{
|
||||
const time_of_day& tod = tod_manager_->get_time_of_day();
|
||||
|
@ -126,17 +121,6 @@ void game_display::new_turn()
|
|||
const int starting_ticks = SDL_GetTicks();
|
||||
for(int i = 0; i != niterations; ++i) {
|
||||
|
||||
#ifdef SDL_GPU
|
||||
if(old_mask != nullptr) {
|
||||
const fixed_t proportion = ftofxp(1.0) - fxpdiv(i,niterations);
|
||||
tod_hex_mask1 = sdl::timage(adjust_surface_alpha(old_mask,proportion));
|
||||
}
|
||||
|
||||
if(new_mask != nullptr) {
|
||||
const fixed_t proportion = fxpdiv(i,niterations);
|
||||
tod_hex_mask2 = sdl::timage(adjust_surface_alpha(new_mask,proportion));
|
||||
}
|
||||
#else
|
||||
if(old_mask != nullptr) {
|
||||
const fixed_t proportion = ftofxp(1.0) - fxpdiv(i,niterations);
|
||||
adjust_surface_alpha(old_mask, proportion);
|
||||
|
@ -148,7 +132,6 @@ void game_display::new_turn()
|
|||
adjust_surface_alpha(new_mask, proportion);
|
||||
tod_hex_mask2.assign(new_mask);
|
||||
}
|
||||
#endif
|
||||
|
||||
invalidate_all();
|
||||
draw();
|
||||
|
@ -161,13 +144,8 @@ void game_display::new_turn()
|
|||
}
|
||||
}
|
||||
|
||||
#ifdef SDL_GPU
|
||||
tod_hex_mask1 = sdl::timage();
|
||||
tod_hex_mask2 = sdl::timage();
|
||||
#else
|
||||
tod_hex_mask1.assign(nullptr);
|
||||
tod_hex_mask2.assign(nullptr);
|
||||
#endif
|
||||
}
|
||||
|
||||
first_turn_ = false;
|
||||
|
@ -313,29 +291,6 @@ void game_display::draw_hex(const map_location& loc)
|
|||
if( u != nullptr ) {
|
||||
hex_top_layer = LAYER_MOUSEOVER_TOP;
|
||||
}
|
||||
#ifdef SDL_GPU
|
||||
if(u == nullptr) {
|
||||
drawing_buffer_add( hex_top_layer, loc, xpos, ypos,
|
||||
image::get_texture("misc/hover-hex-top.png~RC(magenta>gold)", image::SCALED_TO_HEX));
|
||||
drawing_buffer_add(LAYER_MOUSEOVER_BOTTOM, loc, xpos, ypos,
|
||||
image::get_texture("misc/hover-hex-bottom.png~RC(magenta>gold)", image::SCALED_TO_HEX));
|
||||
} else if(dc_->teams()[currentTeam_].is_enemy(u->side())) {
|
||||
drawing_buffer_add( hex_top_layer, loc, xpos, ypos,
|
||||
image::get_texture("misc/hover-hex-enemy-top.png~RC(magenta>red)", image::SCALED_TO_HEX));
|
||||
drawing_buffer_add(LAYER_MOUSEOVER_BOTTOM, loc, xpos, ypos,
|
||||
image::get_texture("misc/hover-hex-enemy-bottom.png~RC(magenta>red)", image::SCALED_TO_HEX));
|
||||
} else if(dc_->teams()[currentTeam_].side() == u->side()) {
|
||||
drawing_buffer_add( hex_top_layer, loc, xpos, ypos,
|
||||
image::get_texture("misc/hover-hex-top.png~RC(magenta>green)", image::SCALED_TO_HEX));
|
||||
drawing_buffer_add(LAYER_MOUSEOVER_BOTTOM, loc, xpos, ypos,
|
||||
image::get_texture("misc/hover-hex-bottom.png~RC(magenta>green)", image::SCALED_TO_HEX));
|
||||
} else {
|
||||
drawing_buffer_add( hex_top_layer, loc, xpos, ypos,
|
||||
image::get_texture("misc/hover-hex-top.png~RC(magenta>lightblue)", image::SCALED_TO_HEX));
|
||||
drawing_buffer_add(LAYER_MOUSEOVER_BOTTOM, loc, xpos, ypos,
|
||||
image::get_texture("misc/hover-hex-bottom.png~RC(magenta>lightblue)", image::SCALED_TO_HEX));
|
||||
}
|
||||
#else
|
||||
if(u == nullptr) {
|
||||
drawing_buffer_add( hex_top_layer, loc, xpos, ypos,
|
||||
image::get_image("misc/hover-hex-top.png~RC(magenta>gold)", image::SCALED_TO_HEX));
|
||||
|
@ -357,7 +312,6 @@ void game_display::draw_hex(const map_location& loc)
|
|||
drawing_buffer_add(LAYER_MOUSEOVER_BOTTOM, loc, xpos, ypos,
|
||||
image::get_image("misc/hover-hex-bottom.png~RC(magenta>lightblue)", image::SCALED_TO_HEX));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
@ -368,13 +322,8 @@ void game_display::draw_hex(const map_location& loc)
|
|||
if (!is_shrouded && !reach_map_.empty()
|
||||
&& reach_map_.find(loc) == reach_map_.end() && loc != attack_indicator_dst_) {
|
||||
static const image::locator unreachable(game_config::images::unreachable);
|
||||
#ifdef SDL_GPU
|
||||
drawing_buffer_add(LAYER_REACHMAP, loc, xpos, ypos,
|
||||
image::get_texture(unreachable,image::SCALED_TO_HEX));
|
||||
#else
|
||||
drawing_buffer_add(LAYER_REACHMAP, loc, xpos, ypos,
|
||||
image::get_image(unreachable,image::SCALED_TO_HEX));
|
||||
#endif
|
||||
}
|
||||
|
||||
if (std::shared_ptr<wb::manager> w = wb_.lock()) {
|
||||
|
@ -382,40 +331,13 @@ void game_display::draw_hex(const map_location& loc)
|
|||
|
||||
if (!(w->is_active() && w->has_temp_move()))
|
||||
{
|
||||
#ifdef SDL_GPU
|
||||
std::vector<sdl::timage> footstepImages = footsteps_images(loc, route_, dc_);
|
||||
#else
|
||||
std::vector<surface> footstepImages = footsteps_images(loc, route_, dc_);
|
||||
#endif
|
||||
if (!footstepImages.empty()) {
|
||||
drawing_buffer_add(LAYER_FOOTSTEPS, loc, xpos, ypos, footsteps_images(loc, route_, dc_));
|
||||
}
|
||||
}
|
||||
}
|
||||
// Draw the attack direction indicator
|
||||
#ifdef SDL_GPU
|
||||
if(on_map && loc == attack_indicator_src_) {
|
||||
drawing_buffer_add(LAYER_ATTACK_INDICATOR, loc, xpos, ypos,
|
||||
image::get_texture("misc/attack-indicator-src-" + attack_indicator_direction() + ".png", image::SCALED_TO_HEX));
|
||||
} else if (on_map && loc == attack_indicator_dst_) {
|
||||
drawing_buffer_add(LAYER_ATTACK_INDICATOR, loc, xpos, ypos,
|
||||
image::get_texture("misc/attack-indicator-dst-" + attack_indicator_direction() + ".png", image::SCALED_TO_HEX));
|
||||
}
|
||||
|
||||
// Linger overlay unconditionally otherwise it might give glitches
|
||||
// so it's drawn over the shroud and fog.
|
||||
if(game_mode_ != RUNNING) {
|
||||
static const image::locator linger(game_config::images::linger);
|
||||
drawing_buffer_add(LAYER_LINGER_OVERLAY, loc, xpos, ypos,
|
||||
image::get_texture(linger, image::TOD_COLORED));
|
||||
}
|
||||
|
||||
if(on_map && loc == selectedHex_ && !game_config::images::selected.empty()) {
|
||||
static const image::locator selected(game_config::images::selected);
|
||||
drawing_buffer_add(LAYER_SELECTED_HEX, loc, xpos, ypos,
|
||||
image::get_texture(selected, image::SCALED_TO_HEX));
|
||||
}
|
||||
#else
|
||||
if(on_map && loc == attack_indicator_src_) {
|
||||
drawing_buffer_add(LAYER_ATTACK_INDICATOR, loc, xpos, ypos,
|
||||
image::get_image("misc/attack-indicator-src-" + attack_indicator_direction() + ".png", image::SCALED_TO_HEX));
|
||||
|
@ -437,7 +359,6 @@ void game_display::draw_hex(const map_location& loc)
|
|||
drawing_buffer_add(LAYER_SELECTED_HEX, loc, xpos, ypos,
|
||||
image::get_image(selected, image::SCALED_TO_HEX));
|
||||
}
|
||||
#endif
|
||||
|
||||
// Show def% and turn to reach info
|
||||
if(!is_shrouded && on_map) {
|
||||
|
@ -521,22 +442,6 @@ void game_display::draw_movement_info(const map_location& loc)
|
|||
|
||||
int xpos = get_location_x(loc);
|
||||
int ypos = get_location_y(loc);
|
||||
#ifdef SDL_GPU
|
||||
if (w->second.invisible) {
|
||||
drawing_buffer_add(LAYER_MOVE_INFO, loc, xpos, ypos,
|
||||
image::get_texture("misc/hidden.png", image::SCALED_TO_HEX));
|
||||
}
|
||||
|
||||
if (w->second.zoc) {
|
||||
drawing_buffer_add(LAYER_MOVE_INFO, loc, xpos, ypos,
|
||||
image::get_texture("misc/zoc.png", image::SCALED_TO_HEX));
|
||||
}
|
||||
|
||||
if (w->second.capture) {
|
||||
drawing_buffer_add(LAYER_MOVE_INFO, loc, xpos, ypos,
|
||||
image::get_texture("misc/capture.png", image::SCALED_TO_HEX));
|
||||
}
|
||||
#else
|
||||
if (w->second.invisible) {
|
||||
drawing_buffer_add(LAYER_MOVE_INFO, loc, xpos, ypos,
|
||||
image::get_image("misc/hidden.png", image::SCALED_TO_HEX));
|
||||
|
@ -551,7 +456,6 @@ void game_display::draw_movement_info(const map_location& loc)
|
|||
drawing_buffer_add(LAYER_MOVE_INFO, loc, xpos, ypos,
|
||||
image::get_image("misc/capture.png", image::SCALED_TO_HEX));
|
||||
}
|
||||
#endif
|
||||
|
||||
//we display turn info only if different from a simple last "1"
|
||||
if (w->second.turns > 1 || (w->second.turns == 1 && loc != route_.steps.back())) {
|
||||
|
@ -592,17 +496,9 @@ void game_display::draw_movement_info(const map_location& loc)
|
|||
}
|
||||
}
|
||||
|
||||
#ifdef SDL_GPU
|
||||
std::vector<sdl::timage> footsteps_images(const map_location& loc, const pathfind::marked_route & route_, const display_context * dc_)
|
||||
#else
|
||||
std::vector<surface> footsteps_images(const map_location& loc, const pathfind::marked_route & route_, const display_context * dc_)
|
||||
#endif
|
||||
{
|
||||
#ifdef SDL_GPU
|
||||
std::vector<sdl::timage> res;
|
||||
#else
|
||||
std::vector<surface> res;
|
||||
#endif
|
||||
|
||||
if (route_.steps.size() < 2) {
|
||||
return res; // no real "route"
|
||||
|
@ -627,11 +523,7 @@ std::vector<surface> footsteps_images(const map_location& loc, const pathfind::m
|
|||
}
|
||||
const std::string foot_speed_prefix = game_config::foot_speed_prefix[image_number-1];
|
||||
|
||||
#ifdef SDL_GPU
|
||||
sdl::timage teleport;
|
||||
#else
|
||||
surface teleport = nullptr;
|
||||
#endif
|
||||
|
||||
// We draw 2 half-hex (with possibly different directions),
|
||||
// but skip the first for the first step.
|
||||
|
@ -645,11 +537,7 @@ std::vector<surface> footsteps_images(const map_location& loc, const pathfind::m
|
|||
if (!tiles_adjacent(*(i+(h-1)), *(i+h))) {
|
||||
std::string teleport_image =
|
||||
h==0 ? game_config::foot_teleport_enter : game_config::foot_teleport_exit;
|
||||
#ifdef SDL_GPU
|
||||
teleport = image::get_texture(teleport_image, image::SCALED_TO_HEX);
|
||||
#else
|
||||
teleport = image::get_image(teleport_image, image::SCALED_TO_HEX);
|
||||
#endif
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -667,19 +555,11 @@ std::vector<surface> footsteps_images(const map_location& loc, const pathfind::m
|
|||
+ sense + "-" + i->write_direction(dir)
|
||||
+ ".png" + rotate;
|
||||
|
||||
#ifdef SDL_GPU
|
||||
res.push_back(image::get_texture(image, image::SCALED_TO_HEX));
|
||||
#else
|
||||
res.push_back(image::get_image(image, image::SCALED_TO_HEX));
|
||||
#endif
|
||||
}
|
||||
|
||||
// we draw teleport image (if any) in last
|
||||
#ifdef SDL_GPU
|
||||
if (!teleport.null()) res.push_back(teleport);
|
||||
#else
|
||||
if (teleport != nullptr) res.push_back(teleport);
|
||||
#endif
|
||||
|
||||
return res;
|
||||
}
|
||||
|
|
|
@ -676,11 +676,7 @@ int twindow::show(const bool restore, const unsigned auto_close_timeout)
|
|||
SDL_Rect rect = get_rectangle();
|
||||
sdl_blit(restorer_, 0, video_.getSurface(), &rect);
|
||||
update_rect(get_rectangle());
|
||||
#ifdef SDL_GPU
|
||||
font::undraw_floating_labels(video_);
|
||||
#else
|
||||
font::undraw_floating_labels(video_.getSurface());
|
||||
#endif
|
||||
}
|
||||
throw;
|
||||
}
|
||||
|
@ -692,11 +688,7 @@ int twindow::show(const bool restore, const unsigned auto_close_timeout)
|
|||
SDL_Rect rect = get_rectangle();
|
||||
sdl_blit(restorer_, 0, video_.getSurface(), &rect);
|
||||
update_rect(get_rectangle());
|
||||
#ifdef SDL_GPU
|
||||
font::undraw_floating_labels(video_);
|
||||
#else
|
||||
font::undraw_floating_labels(video_.getSurface());
|
||||
#endif
|
||||
}
|
||||
|
||||
return retval_;
|
||||
|
@ -731,11 +723,7 @@ void twindow::draw()
|
|||
SDL_Rect rect = get_rectangle();
|
||||
// We want the labels underneath the window so draw them and use them
|
||||
// as restore point.
|
||||
#ifdef SDL_GPU
|
||||
font::draw_floating_labels(video_);
|
||||
#else
|
||||
font::draw_floating_labels(frame_buffer);
|
||||
#endif
|
||||
if(restore_) {
|
||||
restorer_ = get_surface_portion(frame_buffer, rect);
|
||||
}
|
||||
|
|
116
src/image.cpp
116
src/image.cpp
|
@ -164,11 +164,6 @@ image::image_cache images_,
|
|||
tod_colored_images_,
|
||||
brightened_images_;
|
||||
|
||||
#ifdef SDL_GPU
|
||||
image::texture_cache txt_images_,
|
||||
txt_hexed_images_,
|
||||
txt_brightened_images_;
|
||||
#endif
|
||||
|
||||
// cache storing if each image fit in a hex
|
||||
image::bool_cache in_hex_info_;
|
||||
|
@ -179,9 +174,6 @@ image::bool_cache is_empty_hex_;
|
|||
// caches storing the different lighted cases for each image
|
||||
image::lit_cache lit_images_,
|
||||
lit_scaled_images_;
|
||||
#ifdef SDL_GPU
|
||||
image::lit_texture_cache lit_textures_;
|
||||
#endif
|
||||
// caches storing each lightmap generated
|
||||
image::lit_variants lightmaps_;
|
||||
|
||||
|
@ -649,17 +641,6 @@ surface load_from_disk(const locator &loc)
|
|||
}
|
||||
}
|
||||
|
||||
#ifdef SDL_GPU
|
||||
sdl::timage load_texture(const locator &loc)
|
||||
{
|
||||
surface img = load_from_disk(loc);
|
||||
if (!img.null()) {
|
||||
return sdl::timage(img);
|
||||
} else {
|
||||
return sdl::timage();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
manager::manager() {}
|
||||
|
||||
|
@ -969,104 +950,7 @@ surface get_image(const image::locator& i_locator, TYPE type)
|
|||
return res;
|
||||
}
|
||||
|
||||
#ifdef SDL_GPU
|
||||
sdl::timage get_texture(const locator& loc, TYPE type)
|
||||
{
|
||||
if (loc.is_void()) {
|
||||
return sdl::timage();
|
||||
}
|
||||
|
||||
texture_cache *cache;
|
||||
|
||||
switch (type) {
|
||||
case UNSCALED:
|
||||
case SCALED_TO_ZOOM:
|
||||
cache = &txt_images_;
|
||||
break;
|
||||
case BRIGHTENED:
|
||||
cache = &txt_brightened_images_;
|
||||
break;
|
||||
case HEXED:
|
||||
case SCALED_TO_HEX:
|
||||
case TOD_COLORED:
|
||||
cache = &txt_hexed_images_;
|
||||
break;
|
||||
default:
|
||||
return sdl::timage();
|
||||
}
|
||||
|
||||
if (!loc.in_cache(*cache)) {
|
||||
if (type == UNSCALED || type == SCALED_TO_ZOOM) {
|
||||
sdl::timage txt = load_texture(loc);
|
||||
loc.add_to_cache(*cache, txt);
|
||||
} else if (type == BRIGHTENED) {
|
||||
surface surf = get_brightened(loc);
|
||||
sdl::timage txt(surf);
|
||||
loc.add_to_cache(*cache, txt);
|
||||
} else {
|
||||
surface surf = get_hexed(loc);
|
||||
sdl::timage txt(surf);
|
||||
loc.add_to_cache(*cache, txt);
|
||||
}
|
||||
}
|
||||
|
||||
sdl::timage result = loc.locate_in_cache(*cache);
|
||||
|
||||
switch (type) {
|
||||
case UNSCALED:
|
||||
case HEXED:
|
||||
case BRIGHTENED:
|
||||
break;
|
||||
case TOD_COLORED:
|
||||
result.set_color_mod(red_adjust, green_adjust, blue_adjust);
|
||||
case SCALED_TO_ZOOM:
|
||||
case SCALED_TO_HEX:
|
||||
result.set_scale(zoom / 72.0f, zoom / 72.0f);
|
||||
break;
|
||||
default:
|
||||
return sdl::timage();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef SDL_GPU
|
||||
sdl::timage get_lighted_texture(const locator &i_locator, const light_string &ls, TYPE type)
|
||||
{
|
||||
sdl::timage res;
|
||||
if(i_locator.is_void())
|
||||
return res;
|
||||
|
||||
// if no light variants yet, need to add an empty map
|
||||
if(!i_locator.in_cache(lit_textures_)){
|
||||
i_locator.add_to_cache(lit_textures_, lit_texture_variants());
|
||||
}
|
||||
|
||||
//need access to add it if not found
|
||||
{ // enclose reference pointing to data stored in a changing vector
|
||||
const lit_texture_variants& lvar = i_locator.locate_in_cache(lit_textures_);
|
||||
lit_texture_variants::const_iterator lvi = lvar.find(ls);
|
||||
if(lvi != lvar.end()) {
|
||||
return lvi->second;
|
||||
}
|
||||
}
|
||||
|
||||
// not cached yet, generate it
|
||||
surface surf = get_image(i_locator, HEXED);
|
||||
surf = apply_light(surf, ls);
|
||||
|
||||
res = sdl::timage(surf);
|
||||
|
||||
if (type == SCALED_TO_HEX) {
|
||||
res.set_scale(zoom / 72.0f, zoom / 72.0f);
|
||||
}
|
||||
// record the lighted surface in the corresponding variants cache
|
||||
i_locator.access_in_cache(lit_textures_)[ls] = res;
|
||||
|
||||
return res;
|
||||
}
|
||||
#endif
|
||||
surface get_lighted_image(const image::locator& i_locator, const light_string& ls, TYPE type)
|
||||
{
|
||||
surface res;
|
||||
|
|
|
@ -124,14 +124,8 @@ namespace image {
|
|||
|
||||
surface load_from_disk(const locator &loc);
|
||||
|
||||
#ifdef SDL_GPU
|
||||
sdl::timage load_texture(const locator &loc);
|
||||
#endif
|
||||
|
||||
typedef cache_type<surface> image_cache;
|
||||
#ifdef SDL_GPU
|
||||
typedef cache_type<sdl::timage> texture_cache;
|
||||
#endif
|
||||
typedef cache_type<bool> bool_cache;
|
||||
|
||||
typedef std::map<t_translation::t_terrain, surface> mini_terrain_cache_map;
|
||||
|
@ -151,10 +145,6 @@ namespace image {
|
|||
typedef std::map<light_string, surface> lit_variants;
|
||||
// lighted variants for each locator
|
||||
typedef cache_type<lit_variants> lit_cache;
|
||||
#ifdef SDL_GPU
|
||||
typedef std::map<light_string, sdl::timage> lit_texture_variants;
|
||||
typedef cache_type<lit_texture_variants> lit_texture_cache;
|
||||
#endif
|
||||
|
||||
void flush_cache();
|
||||
|
||||
|
@ -206,16 +196,10 @@ namespace image {
|
|||
|
||||
///function to get the surface corresponding to an image.
|
||||
surface get_image(const locator& i_locator, TYPE type=UNSCALED);
|
||||
#ifdef SDL_GPU
|
||||
sdl::timage get_texture(const locator &loc, TYPE type=UNSCALED);
|
||||
#endif
|
||||
|
||||
///function to get the surface corresponding to an image.
|
||||
///after applying the lightmap encoded in ls
|
||||
///type should be HEXED or SCALED_TO_HEX
|
||||
#ifdef SDL_GPU
|
||||
sdl::timage get_lighted_texture(const image::locator& i_locator, const light_string& ls, TYPE type);
|
||||
#endif
|
||||
surface get_lighted_image(const image::locator& i_locator, const light_string& ls, TYPE type);
|
||||
|
||||
///function to get the standard hex mask
|
||||
|
|
|
@ -562,21 +562,6 @@ SDL_Rect draw_wrapped_text(CVideo* gui, const SDL_Rect& area, int font_size,
|
|||
return font::draw_text(gui, area, font_size, color, wrapped_text, x, y, false);
|
||||
}
|
||||
|
||||
#ifdef SDL_GPU
|
||||
sdl::timage draw_text_to_texture(const SDL_Rect &area, int size, const SDL_Color &color, const std::string &text, bool use_tooltips, int style)
|
||||
{
|
||||
SDL_Rect rect = text_area(text, size, style);
|
||||
surface surf = SDL_CreateRGBSurface(SDL_SWSURFACE, rect.w, rect.h, 32,
|
||||
0xff000000,
|
||||
0x00ff0000,
|
||||
0x0000ff00,
|
||||
0x000000ff);
|
||||
SDL_FillRect(surf, nullptr, 0x000000ff);
|
||||
draw_text(surf, area, size, color, text, 0, 0, use_tooltips, style);
|
||||
|
||||
return sdl::timage(surf);
|
||||
}
|
||||
#endif
|
||||
|
||||
} // end namespace font
|
||||
|
||||
|
|
|
@ -24,9 +24,6 @@ class surface;
|
|||
#include <string>
|
||||
#include "serialization/unicode_types.hpp"
|
||||
|
||||
#ifdef SDL_GPU
|
||||
#include "sdl/image.hpp"
|
||||
#endif
|
||||
|
||||
namespace font {
|
||||
|
||||
|
@ -85,12 +82,6 @@ SDL_Rect draw_text(CVideo* gui, const SDL_Rect& area, int size,
|
|||
const SDL_Color& color, const std::string& text,
|
||||
int x, int y, bool use_tooltips = false, int style = 0);
|
||||
|
||||
#ifdef SDL_GPU
|
||||
sdl::timage draw_text_to_texture(const SDL_Rect& area, int size,
|
||||
const SDL_Color& color,
|
||||
const std::string& text,
|
||||
bool use_tooltips = false, int style = 0);
|
||||
#endif
|
||||
|
||||
/** Calculate the size of a text (in pixels) if it were to be drawn. */
|
||||
SDL_Rect text_area(const std::string& text, int size, int style=0);
|
||||
|
|
151
src/minimap.cpp
151
src/minimap.cpp
|
@ -279,156 +279,5 @@ surface getMinimap(int w, int h, const gamemap &map, const team *vw, const std::
|
|||
return minimap;
|
||||
}
|
||||
|
||||
#ifdef SDL_GPU
|
||||
SDL_Rect draw_minimap(CVideo &video, const SDL_Rect &area, const gamemap &map, const team *vw, const std::map<map_location, unsigned int> *reach_map)
|
||||
{
|
||||
const terrain_type_data & tdata = *map.tdata();
|
||||
|
||||
const float width = map.w() * 72 * 3/4;
|
||||
const float height = map.h() * 72 + 72 * 1/4;
|
||||
const float scale_factor = std::min(area.w / width, area.h / height);
|
||||
const float tile_size = 72 * scale_factor;
|
||||
const int xoff = area.x + (area.w - scale_factor * width) / 2;
|
||||
const int yoff = area.y + (area.h - scale_factor * height) / 2 + 1;
|
||||
|
||||
const bool draw_terrain = preferences::minimap_draw_terrain();
|
||||
const bool terrain_coding = preferences::minimap_terrain_coding();
|
||||
const bool draw_villages = preferences::minimap_draw_villages();
|
||||
|
||||
for(int y = 0; y != map.total_height(); ++y) {
|
||||
for(int x = 0; x != map.total_width(); ++x) {
|
||||
map_location loc(x, y);
|
||||
if(!map.on_board(loc))
|
||||
continue;
|
||||
|
||||
const bool highlighted = reach_map && reach_map->count(loc) != 0;
|
||||
const bool shrouded = (resources::screen != nullptr && resources::screen->is_blindfolded()) || (vw != nullptr && vw->shrouded(loc));
|
||||
// shrouded hex are not considered fogged (no need to fog a black image)
|
||||
const bool fogged = (vw != nullptr && !shrouded && vw->fogged(loc));
|
||||
|
||||
const t_translation::t_terrain terrain = shrouded ?
|
||||
t_translation::VOID_TERRAIN : map[loc];
|
||||
const terrain_type& terrain_info = tdata.get_terrain_info(terrain);
|
||||
|
||||
const int xpos = x * tile_size * 3/4 + xoff;
|
||||
const int ypos = y * tile_size + tile_size / 4 * (is_odd(x) ? 2 : 0) + yoff;
|
||||
|
||||
if (draw_terrain) {
|
||||
if (terrain_coding) {
|
||||
sdl::timage img = image::get_texture("terrain/" + terrain_info.minimap_image() + ".png", image::HEXED);
|
||||
//TODO: proper color mod values once blending is implemented
|
||||
if (fogged) {
|
||||
img.set_color_mod(100, 100, 100);
|
||||
}
|
||||
if (highlighted) {
|
||||
img.set_color_mod(150, 150, 150);
|
||||
}
|
||||
|
||||
img.set_scale(scale_factor, scale_factor);
|
||||
|
||||
video.draw_texture(img, xpos, ypos);
|
||||
|
||||
if (terrain_info.is_combined()) {
|
||||
sdl::timage overlay = image::get_texture("terrain/" + terrain_info.minimap_image_overlay() + ".png", image::HEXED);
|
||||
if (fogged) {
|
||||
overlay.set_color_mod(100, 100, 100);
|
||||
}
|
||||
if (highlighted) {
|
||||
overlay.set_color_mod(150, 150, 150);
|
||||
}
|
||||
|
||||
overlay.set_scale(scale_factor, scale_factor);
|
||||
video.draw_texture(overlay, xpos, ypos);
|
||||
}
|
||||
} else {
|
||||
SDL_Color col;
|
||||
std::map<std::string, color_range>::const_iterator it = game_config::team_rgb_range.find(terrain_info.id());
|
||||
if (it == game_config::team_rgb_range.end()) {
|
||||
col = create_color(0,0,0,SDL_ALPHA_OPAQUE);
|
||||
} else
|
||||
col = int_to_color(it->second.rep());
|
||||
|
||||
bool first = true;
|
||||
const t_translation::t_list& underlying_terrains = tdata.underlying_union_terrain(terrain);
|
||||
for(const t_translation::t_terrain& underlying_terrain : underlying_terrains) {
|
||||
|
||||
const std::string& terrain_id = tdata.get_terrain_info(underlying_terrain).id();
|
||||
std::map<std::string, color_range>::const_iterator it = game_config::team_rgb_range.find(terrain_id);
|
||||
if (it == game_config::team_rgb_range.end())
|
||||
continue;
|
||||
|
||||
SDL_Color tmp = int_to_color(it->second.rep());
|
||||
|
||||
if (fogged) {
|
||||
if (tmp.b < 50) tmp.b = 0;
|
||||
else tmp.b -= 50;
|
||||
if (tmp.g < 50) tmp.g = 0;
|
||||
else tmp.g -= 50;
|
||||
if (tmp.r < 50) tmp.r = 0;
|
||||
else tmp.r -= 50;
|
||||
}
|
||||
|
||||
if (highlighted) {
|
||||
if (tmp.b > 205) tmp.b = 255;
|
||||
else tmp.b += 50;
|
||||
if (tmp.g > 205) tmp.g = 255;
|
||||
else tmp.g += 50;
|
||||
if (tmp.r > 205) tmp.r = 255;
|
||||
else tmp.r += 50;
|
||||
}
|
||||
|
||||
if (first) {
|
||||
first = false;
|
||||
col = tmp;
|
||||
} else {
|
||||
col.r = col.r - (col.r - tmp.r)/2;
|
||||
col.g = col.g - (col.g - tmp.g)/2;
|
||||
col.b = col.b - (col.b - tmp.b)/2;
|
||||
}
|
||||
}
|
||||
SDL_Rect fillrect = sdl::create_rect(xpos, ypos, tile_size * 3/4, tile_size);
|
||||
sdl::fill_rect(video, fillrect, col);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (terrain_info.is_village() && draw_villages) {
|
||||
|
||||
int side = (resources::gameboard ? resources::gameboard->village_owner(loc) : -1); //check needed for mp create dialog
|
||||
|
||||
SDL_Color col = int_to_color(game_config::team_rgb_range.find("white")->second.min());
|
||||
|
||||
if (!fogged) {
|
||||
if (side > -1) {
|
||||
|
||||
if (!preferences::minimap_movement_coding() || !vw ) {
|
||||
col = team::get_minimap_color(side + 1);
|
||||
} else {
|
||||
|
||||
if (vw->owns_village(loc))
|
||||
col = int_to_color(game_config::color_info(preferences::unmoved_color()).rep());
|
||||
else if (vw->is_enemy(side + 1))
|
||||
col = int_to_color(game_config::color_info(preferences::enemy_color()).rep());
|
||||
else
|
||||
col = int_to_color(game_config::color_info(preferences::allied_color()).rep());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SDL_Rect fillrect = sdl::create_rect(
|
||||
xpos
|
||||
, ypos
|
||||
, tile_size * 3/4
|
||||
, tile_size
|
||||
);
|
||||
|
||||
sdl::fill_rect(video, fillrect, col);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return sdl::create_rect(xoff, yoff, width * scale_factor, height * scale_factor);
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
|
|
|
@ -23,17 +23,10 @@ class team;
|
|||
struct map_location;
|
||||
class gamemap;
|
||||
|
||||
#ifdef SDL_GPU
|
||||
class CVideo;
|
||||
struct SDL_Rect;
|
||||
#endif
|
||||
|
||||
namespace image {
|
||||
///function to create the minimap for a given map
|
||||
///the surface returned must be freed by the user
|
||||
#ifdef SDL_GPU
|
||||
SDL_Rect draw_minimap(CVideo &video, const SDL_Rect &area, const gamemap &map, const team *vw = nullptr, const std::map<map_location,unsigned int> *reach_map = nullptr);
|
||||
#endif
|
||||
surface getMinimap(int w, int h, const gamemap &map_, const team *vm = nullptr, const std::map<map_location,unsigned int> *reach_map = nullptr);
|
||||
}
|
||||
|
||||
|
|
|
@ -15,7 +15,6 @@
|
|||
#include "sdl/exception.hpp"
|
||||
|
||||
#include <SDL_error.h>
|
||||
#include "gpu.hpp"
|
||||
|
||||
namespace sdl
|
||||
{
|
||||
|
@ -29,29 +28,11 @@ static std::string create_error(const std::string& operation,
|
|||
return operation;
|
||||
}
|
||||
}
|
||||
#ifdef SDL_GPU
|
||||
static std::string create_gpu_error(const std::string &op,
|
||||
const bool fetch_error_msg)
|
||||
{
|
||||
if (fetch_error_msg) {
|
||||
return op + " Error »" + GPU_PopErrorCode().details + "«.\n";
|
||||
} else {
|
||||
return op;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
texception::texception(const std::string& operation, const bool use_sdl_error)
|
||||
: game::error(create_error(operation, use_sdl_error))
|
||||
{
|
||||
}
|
||||
|
||||
#ifdef SDL_GPU
|
||||
tgpu_exception::tgpu_exception(const std::string &op,
|
||||
const bool fetch_error_msg)
|
||||
: game::error(create_gpu_error(op, fetch_error_msg))
|
||||
{
|
||||
}
|
||||
#endif
|
||||
|
||||
} // namespace sdl
|
||||
|
|
|
@ -39,12 +39,6 @@ struct texception : public game::error
|
|||
texception(const std::string& operation, const bool use_sdl_error);
|
||||
};
|
||||
|
||||
#ifdef SDL_GPU
|
||||
struct tgpu_exception : public game::error
|
||||
{
|
||||
tgpu_exception(const std::string &op, const bool fetch_error_msg);
|
||||
};
|
||||
#endif
|
||||
|
||||
} // namespace sdl
|
||||
|
||||
|
|
|
@ -1,19 +0,0 @@
|
|||
/*
|
||||
Copyright (C) 2014 - 2016 by Lipka Boldizsár <lipkab@zoho.com>
|
||||
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY.
|
||||
|
||||
See the COPYING file for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file Alias for SDL_gpu/SDL_gpu/SDL_gpu.h
|
||||
*/
|
||||
|
||||
#include "../SDL_gpu/SDL_gpu/SDL_gpu.h"
|
|
@ -23,375 +23,3 @@
|
|||
|
||||
#include <cassert>
|
||||
|
||||
#ifdef SDL_GPU
|
||||
#include "rect.hpp"
|
||||
namespace sdl
|
||||
{
|
||||
timage::timage(Uint16 w, Uint16 h)
|
||||
: image_(nullptr)
|
||||
, rotation_(0)
|
||||
, hscale_(1)
|
||||
, vscale_(1)
|
||||
, clip_()
|
||||
, red_mod_(0)
|
||||
, green_mod_(0)
|
||||
, blue_mod_(0)
|
||||
, alpha_mod_(0)
|
||||
, hwrap_(GPU_WRAP_NONE)
|
||||
, vwrap_(GPU_WRAP_NONE)
|
||||
, effects_(0)
|
||||
{
|
||||
clip_ = create_gpu_rect(0, 0, w, h);
|
||||
image_ = GPU_CreateImage(w, h, GPU_FORMAT_RGBA);
|
||||
if (image_ == nullptr) {
|
||||
throw tgpu_exception("Failed to construct timage object.", true);
|
||||
} else {
|
||||
image_->refcount = 1;
|
||||
static SDL_Color black = {0, 0, 0, 0};
|
||||
GPU_SetColor(image_, &black);
|
||||
}
|
||||
}
|
||||
|
||||
timage::timage(const std::string &file)
|
||||
: image_(GPU_LoadImage(file.c_str()))
|
||||
, rotation_(0)
|
||||
, hscale_(1)
|
||||
, vscale_(1)
|
||||
, clip_()
|
||||
, red_mod_(0)
|
||||
, green_mod_(0)
|
||||
, blue_mod_(0)
|
||||
, alpha_mod_(0)
|
||||
, hwrap_(GPU_WRAP_NONE)
|
||||
, vwrap_(GPU_WRAP_NONE)
|
||||
, effects_(0)
|
||||
{
|
||||
if (image_ == nullptr) {
|
||||
throw tgpu_exception("Failed to construct timage object.", true);
|
||||
} else {
|
||||
clip_ = create_gpu_rect(0, 0, image_->w, image_->h);
|
||||
image_->refcount = 1;
|
||||
static SDL_Color black = {0, 0, 0, 0};
|
||||
GPU_SetColor(image_, &black);
|
||||
}
|
||||
}
|
||||
|
||||
timage::timage(const surface &source)
|
||||
: image_(GPU_CopyImageFromSurface(source))
|
||||
, rotation_(0)
|
||||
, hscale_(1)
|
||||
, vscale_(1)
|
||||
, clip_()
|
||||
, red_mod_(0)
|
||||
, green_mod_(0)
|
||||
, blue_mod_(0)
|
||||
, alpha_mod_(0)
|
||||
, hwrap_(GPU_WRAP_NONE)
|
||||
, vwrap_(GPU_WRAP_NONE)
|
||||
, smooth_(false)
|
||||
, submerge_(0)
|
||||
, effects_(0)
|
||||
{
|
||||
if (image_ == nullptr) {
|
||||
if (!source.nullptr()) {
|
||||
throw tgpu_exception("Failed to construct timage object.", true);
|
||||
}
|
||||
} else {
|
||||
clip_ = create_gpu_rect(0, 0, image_->w, image_->h);
|
||||
image_->refcount = 1;
|
||||
static SDL_Color black = {0, 0, 0, 0};
|
||||
GPU_SetColor(image_, &black);
|
||||
}
|
||||
}
|
||||
|
||||
timage::timage(SDL_Surface *source)
|
||||
: image_(GPU_CopyImageFromSurface(source))
|
||||
, rotation_(0)
|
||||
, hscale_(1)
|
||||
, vscale_(1)
|
||||
, clip_()
|
||||
, red_mod_(0)
|
||||
, green_mod_(0)
|
||||
, blue_mod_(0)
|
||||
, alpha_mod_(0)
|
||||
, hwrap_(GPU_WRAP_NONE)
|
||||
, vwrap_(GPU_WRAP_NONE)
|
||||
, smooth_(false)
|
||||
, submerge_(0)
|
||||
, effects_(0)
|
||||
{
|
||||
if (image_ == nullptr) {
|
||||
if (source != nullptr) {
|
||||
throw tgpu_exception("Failed to construct timage object.", true);
|
||||
}
|
||||
} else {
|
||||
clip_ = create_gpu_rect(0, 0, image_->w, image_->h);
|
||||
image_->refcount = 1;
|
||||
static SDL_Color black = {0, 0, 0, 0};
|
||||
GPU_SetColor(image_, &black);
|
||||
}
|
||||
}
|
||||
|
||||
timage::timage()
|
||||
: image_(nullptr)
|
||||
, rotation_(0)
|
||||
, hscale_(1)
|
||||
, vscale_(1)
|
||||
, clip_()
|
||||
, red_mod_(0)
|
||||
, green_mod_(0)
|
||||
, blue_mod_(0)
|
||||
, alpha_mod_(0)
|
||||
, hwrap_(GPU_WRAP_NONE)
|
||||
, vwrap_(GPU_WRAP_NONE)
|
||||
, smooth_(false)
|
||||
, submerge_(0)
|
||||
, effects_(0)
|
||||
{
|
||||
}
|
||||
|
||||
sdl::timage::~timage()
|
||||
{
|
||||
if (image_ != nullptr) {
|
||||
image_->refcount -= 1;
|
||||
if (image_->refcount == 0) {
|
||||
GPU_FreeImage(image_);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
timage::timage(const timage &texture)
|
||||
: image_(texture.image_)
|
||||
, rotation_(texture.rotation_)
|
||||
, hscale_(texture.hscale_)
|
||||
, vscale_(texture.vscale_)
|
||||
, clip_(texture.clip_)
|
||||
, red_mod_(texture.red_mod_)
|
||||
, green_mod_(texture.green_mod_)
|
||||
, blue_mod_(texture.blue_mod_)
|
||||
, alpha_mod_(texture.alpha_mod_)
|
||||
, hwrap_(texture.hwrap_)
|
||||
, vwrap_(texture.vwrap_)
|
||||
, smooth_(texture.smooth_)
|
||||
, submerge_(texture.submerge_)
|
||||
, effects_(texture.effects_)
|
||||
{
|
||||
if (image_ != nullptr) {
|
||||
image_->refcount += 1;
|
||||
}
|
||||
}
|
||||
|
||||
timage &timage::operator =(const timage &texture)
|
||||
{
|
||||
if (&texture != this) {
|
||||
this->~timage();
|
||||
new (this) timage(texture);
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
void timage::draw(CVideo &video, const int x, const int y)
|
||||
{
|
||||
GPU_SetImageFilter(image_, smooth_ ? GPU_FILTER_LINEAR : GPU_FILTER_NEAREST);
|
||||
GPU_SetWrapMode(image_, hwrap_, vwrap_);
|
||||
video.set_texture_color_modulation(red_mod_, green_mod_, blue_mod_, alpha_mod_);
|
||||
video.set_texture_submerge(float(submerge_));
|
||||
video.set_texture_effects(effects_);
|
||||
GPU_BlitTransform(image_, &clip_, video.render_target(), x + width()/2, y + height()/2,
|
||||
rotation_, hscale_, vscale_);
|
||||
}
|
||||
|
||||
void timage::set_rotation(float rotation)
|
||||
{
|
||||
rotation_ = rotation;
|
||||
}
|
||||
|
||||
float timage::rotation() const
|
||||
{
|
||||
return rotation_;
|
||||
}
|
||||
|
||||
void timage::set_hscale(float factor)
|
||||
{
|
||||
hscale_ = factor;
|
||||
}
|
||||
|
||||
void timage::set_vscale(float factor)
|
||||
{
|
||||
vscale_ = factor;
|
||||
}
|
||||
|
||||
void timage::set_scale(float hfactor, float vfactor)
|
||||
{
|
||||
hscale_ = hfactor;
|
||||
vscale_ = vfactor;
|
||||
}
|
||||
|
||||
float timage::hscale() const
|
||||
{
|
||||
return hscale_;
|
||||
}
|
||||
|
||||
float timage::vscale() const
|
||||
{
|
||||
return vscale_;
|
||||
}
|
||||
|
||||
void timage::set_smooth_scaling(bool use_smooth)
|
||||
{
|
||||
smooth_ = use_smooth;
|
||||
}
|
||||
|
||||
bool timage::smooth_scaling() const
|
||||
{
|
||||
return smooth_;
|
||||
}
|
||||
|
||||
int timage::width() const
|
||||
{
|
||||
return clip_.w * hscale_;
|
||||
}
|
||||
|
||||
int timage::height() const
|
||||
{
|
||||
return clip_.h * vscale_;
|
||||
}
|
||||
|
||||
Uint16 timage::base_width() const
|
||||
{
|
||||
return image_->w;
|
||||
}
|
||||
|
||||
Uint16 timage::base_height() const
|
||||
{
|
||||
return image_->h;
|
||||
}
|
||||
|
||||
void timage::set_clip(const SDL_Rect &rect)
|
||||
{
|
||||
clip_.x = rect.x;
|
||||
clip_.y = rect.y;
|
||||
clip_.w = rect.w;
|
||||
clip_.h = rect.h;
|
||||
}
|
||||
|
||||
SDL_Rect timage::clip() const
|
||||
{
|
||||
SDL_Rect result;
|
||||
result.x = clip_.x;
|
||||
result.y = clip_.y;
|
||||
result.w = clip_.w;
|
||||
result.h = clip_.h;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void timage::set_alpha(int alpha)
|
||||
{
|
||||
alpha_mod_ = alpha;
|
||||
}
|
||||
|
||||
int timage::alpha() const
|
||||
{
|
||||
return alpha_mod_;
|
||||
}
|
||||
|
||||
void timage::set_color_mod(int r, int g, int b)
|
||||
{
|
||||
red_mod_ = r;
|
||||
green_mod_ = g;
|
||||
blue_mod_ = b;
|
||||
}
|
||||
|
||||
int timage::red_mod() const
|
||||
{
|
||||
return red_mod_;
|
||||
}
|
||||
|
||||
int timage::green_mod() const
|
||||
{
|
||||
return green_mod_;
|
||||
}
|
||||
|
||||
int timage::blue_mod() const
|
||||
{
|
||||
return blue_mod_;
|
||||
}
|
||||
|
||||
void timage::set_hwrap(GPU_WrapEnum mode)
|
||||
{
|
||||
hwrap_ = mode;
|
||||
}
|
||||
|
||||
void timage::set_vwrap(GPU_WrapEnum mode)
|
||||
{
|
||||
vwrap_ = mode;
|
||||
}
|
||||
|
||||
void timage::set_wrap(GPU_WrapEnum hmode, GPU_WrapEnum vmode)
|
||||
{
|
||||
hwrap_ = hmode;
|
||||
vwrap_ = vmode;
|
||||
}
|
||||
|
||||
GPU_WrapEnum timage::hwrap() const
|
||||
{
|
||||
return hwrap_;
|
||||
}
|
||||
|
||||
GPU_WrapEnum timage::vwrap() const
|
||||
{
|
||||
return vwrap_;
|
||||
}
|
||||
|
||||
void timage::set_submerge(double val)
|
||||
{
|
||||
submerge_ = val;
|
||||
}
|
||||
|
||||
double timage::submerge() const
|
||||
{
|
||||
return submerge_;
|
||||
}
|
||||
|
||||
void timage::set_effects(int effects)
|
||||
{
|
||||
effects_ = effects;
|
||||
}
|
||||
|
||||
int timage::effects() const
|
||||
{
|
||||
return effects_;
|
||||
}
|
||||
|
||||
bool timage::nullptr() const
|
||||
{
|
||||
return image_ == nullptr;
|
||||
}
|
||||
|
||||
timage timage::clone() const
|
||||
{
|
||||
timage res;
|
||||
res.image_ = GPU_CopyImage(image_);
|
||||
res.set_alpha(alpha());
|
||||
res.set_clip(clip());
|
||||
res.set_color_mod(red_mod(), green_mod(), blue_mod());
|
||||
res.set_wrap(hwrap(), vwrap());
|
||||
res.set_rotation(rotation());
|
||||
res.set_scale(hscale(), vscale());
|
||||
res.set_smooth_scaling(smooth_scaling());
|
||||
res.set_submerge(submerge());
|
||||
res.set_effects(effects());
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
GPU_Image *timage::raw() const
|
||||
{
|
||||
return image_;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -20,274 +20,5 @@
|
|||
* Contains a wrapper class for the @ref GPU_Image class.
|
||||
*/
|
||||
|
||||
#ifdef SDL_GPU
|
||||
#include "gpu.hpp"
|
||||
#include <string>
|
||||
|
||||
class surface;
|
||||
class CVideo;
|
||||
|
||||
namespace sdl
|
||||
{
|
||||
|
||||
class timage
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Creates a texture with the given width and height.
|
||||
*
|
||||
* @param w Width.
|
||||
* @param h Height.
|
||||
*/
|
||||
timage(Uint16 w, Uint16 h);
|
||||
|
||||
/**
|
||||
* Loads a texture from an image file.
|
||||
*
|
||||
* @param file Full path of the file.
|
||||
*/
|
||||
timage(const std::string &file);
|
||||
|
||||
/**
|
||||
* Creates a texture from an SDL surface.
|
||||
*
|
||||
* @param source Pointer to the surface.
|
||||
*/
|
||||
timage( SDL_Surface *source);
|
||||
|
||||
/**
|
||||
* Creates a texture from an SDL surface.
|
||||
*
|
||||
* @param source The surface.
|
||||
*/
|
||||
timage(const surface &source);
|
||||
|
||||
timage();
|
||||
|
||||
~timage();
|
||||
|
||||
timage(const timage &texture);
|
||||
|
||||
timage &operator=(const timage &texture);
|
||||
|
||||
/**
|
||||
* Render the texture on a specified target, with respect to the previously
|
||||
* set rotation, coloring etc.
|
||||
*
|
||||
* @param video The target to draw onto.
|
||||
* @param x Where to draw (x coordinate).
|
||||
* @param y Where to draw (y coordinate).
|
||||
*/
|
||||
void draw(CVideo &video, const int x, const int y);
|
||||
|
||||
/**
|
||||
* Rotates the texture by a given angle.
|
||||
*
|
||||
* @param rotation The angle in degrees.
|
||||
*/
|
||||
void set_rotation(float rotation);
|
||||
|
||||
/**
|
||||
* Returns the angle by which the texture is rotated.
|
||||
*/
|
||||
float rotation() const;
|
||||
|
||||
/**
|
||||
* Scales the surface horizontally by a given factor.
|
||||
*
|
||||
* @param factor Scaling ratio.
|
||||
*/
|
||||
void set_hscale(float factor);
|
||||
|
||||
/**
|
||||
* Scales the surface vertically by a given factor.
|
||||
*
|
||||
* @param factor Scaling ratio.
|
||||
*/
|
||||
void set_vscale(float factor);
|
||||
|
||||
/**
|
||||
* Scales the surface by a given factor.
|
||||
*
|
||||
* @param hfactor Horizontal scaling factor.
|
||||
* @param vfactor Vertical scaling factor.
|
||||
*/
|
||||
void set_scale(float hfactor, float vfactor);
|
||||
|
||||
/**
|
||||
* Returns the horizontal scaling factor.
|
||||
*/
|
||||
float hscale() const;
|
||||
|
||||
/**
|
||||
* Returns the vertical scaling factor.
|
||||
*/
|
||||
float vscale() const;
|
||||
|
||||
/**
|
||||
* Tell the renderer which scaling algorithm to use.
|
||||
*
|
||||
* @param use_smooth True to use bilinear scaling.
|
||||
*/
|
||||
void set_smooth_scaling(bool use_smooth);
|
||||
|
||||
/**
|
||||
* Returns true if bilinear scaling is enabled.
|
||||
*/
|
||||
bool smooth_scaling() const;
|
||||
|
||||
/**
|
||||
* Returns the width of the texture after scaling and clipping applied.
|
||||
*/
|
||||
int width() const;
|
||||
|
||||
/**
|
||||
* Returns the height of the texture after scaling and clipping applied.
|
||||
*/
|
||||
int height() const;
|
||||
|
||||
/**
|
||||
* Returns the width of the texture before scaling.
|
||||
*/
|
||||
Uint16 base_width() const;
|
||||
|
||||
/**
|
||||
* Returns the height of the texture before scaling.
|
||||
*/
|
||||
Uint16 base_height() const;
|
||||
|
||||
/**
|
||||
* Set the area of the texture that should be displayed when drawing.
|
||||
* Clipping is performed before drawing. The clip area can be larger than
|
||||
* the texture itself, if this happens, extra pixels will be filled
|
||||
* according the configured wrap mode.
|
||||
*
|
||||
* @param rect The clip area.
|
||||
*/
|
||||
void set_clip(const SDL_Rect &rect);
|
||||
|
||||
/**
|
||||
* Returns the current clip area.
|
||||
*/
|
||||
SDL_Rect clip() const;
|
||||
|
||||
/**
|
||||
* Sets the alpha of the texture.
|
||||
*
|
||||
* @param alpha Alpha value.
|
||||
*/
|
||||
void set_alpha(int alpha);
|
||||
|
||||
/**
|
||||
* Returns the alpha of the texture.
|
||||
*/
|
||||
int alpha() const;
|
||||
|
||||
/**
|
||||
* Set color modulation.
|
||||
*
|
||||
* @param r Red modulation.
|
||||
* @param g Green modulation.
|
||||
* @param b Blue modulation.
|
||||
*/
|
||||
void set_color_mod(int r, int g, int b);
|
||||
|
||||
/**
|
||||
* Returns red modulation.
|
||||
*/
|
||||
int red_mod() const;
|
||||
|
||||
/**
|
||||
* Returns green modulation.
|
||||
*/
|
||||
int green_mod() const;
|
||||
|
||||
/**
|
||||
* Returns blue modulation.
|
||||
*/
|
||||
int blue_mod() const;
|
||||
|
||||
/**
|
||||
* Set horizontal wrap mode.
|
||||
*
|
||||
* @param mode Wrap mode.
|
||||
*/
|
||||
void set_hwrap(GPU_WrapEnum mode);
|
||||
|
||||
/**
|
||||
* Set vertical wrap mode.
|
||||
*
|
||||
* @param mode Wrap mode.
|
||||
*/
|
||||
void set_vwrap(GPU_WrapEnum mode);
|
||||
|
||||
/**
|
||||
* Set wrap mode.
|
||||
*
|
||||
* @param hmode Horizontal wrap mode.
|
||||
* @param vmode Vertical wrap mode.
|
||||
*/
|
||||
void set_wrap(GPU_WrapEnum hmode, GPU_WrapEnum vmode);
|
||||
|
||||
/**
|
||||
* Returns the horizontal wrap policy of the texture.
|
||||
*/
|
||||
GPU_WrapEnum hwrap() const;
|
||||
|
||||
/**
|
||||
* Returns the vertical wrap policy of the texture.
|
||||
*/
|
||||
GPU_WrapEnum vwrap( )const;
|
||||
|
||||
void set_submerge(double val);
|
||||
|
||||
double submerge() const;
|
||||
|
||||
void set_effects(int effects);
|
||||
|
||||
int effects() const;
|
||||
|
||||
/**
|
||||
* Returns true if the managed texture is nullptr.
|
||||
*/
|
||||
bool nullptr() const;
|
||||
|
||||
timage clone() const;
|
||||
|
||||
GPU_Image *raw() const;
|
||||
|
||||
private:
|
||||
/** The texture itself. */
|
||||
GPU_Image *image_;
|
||||
|
||||
/** How much will it be rotated. */
|
||||
float rotation_;
|
||||
|
||||
/** How much will it be scaled horizontally. */
|
||||
float hscale_;
|
||||
|
||||
/** How much will it be scaled vertically. */
|
||||
float vscale_;
|
||||
|
||||
/** Which part of the texture should be displayed. */
|
||||
GPU_Rect clip_;
|
||||
|
||||
/** Color mod. */
|
||||
int red_mod_, green_mod_, blue_mod_, alpha_mod_;
|
||||
|
||||
/** Wrap policy. */
|
||||
GPU_WrapEnum hwrap_, vwrap_;
|
||||
|
||||
/** Smooth scaling. */
|
||||
bool smooth_;
|
||||
|
||||
/** Submerge. */
|
||||
double submerge_;
|
||||
|
||||
/** Shader effects (flip, flop, grayscale). */
|
||||
int effects_;
|
||||
};
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
|
|
@ -15,9 +15,6 @@
|
|||
#include "sdl/rect.hpp"
|
||||
#include "sdl/utils.hpp"
|
||||
|
||||
#ifdef SDL_GPU
|
||||
#include "video.hpp"
|
||||
#endif
|
||||
|
||||
namespace sdl
|
||||
{
|
||||
|
@ -34,14 +31,6 @@ SDL_Rect create_rect(const int x, const int y, const int w, const int h)
|
|||
return rect;
|
||||
}
|
||||
|
||||
#ifdef SDL_GPU
|
||||
GPU_Rect create_gpu_rect(const float x, const float y, const float w, const float h)
|
||||
{
|
||||
GPU_Rect result = {x, y, w, h};
|
||||
|
||||
return result;
|
||||
}
|
||||
#endif
|
||||
|
||||
bool point_in_rect(int x, int y, const SDL_Rect& rect)
|
||||
{
|
||||
|
@ -124,39 +113,6 @@ void draw_solid_tinted_rectangle(int x, int y, int w, int h,
|
|||
fill_rect_alpha(rect,SDL_MapRGB(target->format,r,g,b),Uint8(alpha*255),target);
|
||||
}
|
||||
|
||||
#ifdef SDL_GPU
|
||||
void draw_rect(CVideo &video, const SDL_Rect &rect, Uint8 r, Uint8 g,
|
||||
Uint8 b, Uint8 a)
|
||||
{
|
||||
video.set_texture_color_modulation(0, 0, 0, 0);
|
||||
SDL_Color color = {r, g, b, a};
|
||||
GPU_Rectangle(video.render_target(), rect.x, rect.y, rect.x + rect.w, rect.y + rect.h,
|
||||
color);
|
||||
}
|
||||
|
||||
void draw_rect(CVideo &video, const SDL_Rect &rect, SDL_Color color)
|
||||
{
|
||||
video.set_texture_color_modulation(0, 0, 0, 0);
|
||||
GPU_Rectangle(video.render_target(), rect.x, rect.y, rect.x + rect.w, rect.y + rect.h,
|
||||
color);
|
||||
}
|
||||
|
||||
void fill_rect(CVideo &video, const SDL_Rect &rect, Uint8 r, Uint8 g,
|
||||
Uint8 b, Uint8 a)
|
||||
{
|
||||
video.set_texture_color_modulation(0, 0, 0, 0);
|
||||
SDL_Color color = {r, g, b, a};
|
||||
GPU_RectangleFilled(video.render_target(), rect.x, rect.y, rect.x + rect.w,
|
||||
rect.y + rect.h, color);
|
||||
}
|
||||
|
||||
void fill_rect(CVideo &video, const SDL_Rect &rect, SDL_Color color)
|
||||
{
|
||||
video.set_texture_color_modulation(0, 0, 0, 0);
|
||||
GPU_RectangleFilled(video.render_target(), rect.x, rect.y, rect.x + rect.w,
|
||||
rect.y + rect.h, color);
|
||||
}
|
||||
#endif
|
||||
|
||||
} // namespace sdl
|
||||
|
||||
|
|
|
@ -25,11 +25,6 @@
|
|||
|
||||
#include <SDL_rect.h>
|
||||
|
||||
#ifdef SDL_GPU
|
||||
#include "gpu.hpp"
|
||||
|
||||
class CVideo;
|
||||
#endif
|
||||
|
||||
namespace sdl
|
||||
{
|
||||
|
@ -44,10 +39,6 @@ extern const SDL_Rect empty_rect;
|
|||
*/
|
||||
SDL_Rect create_rect(const int x, const int y, const int w, const int h);
|
||||
|
||||
#ifdef SDL_GPU
|
||||
GPU_Rect create_gpu_rect(const float x, const float y, const float w,
|
||||
const float h);
|
||||
#endif
|
||||
/**
|
||||
* Tests whether a point is inside a rectangle.
|
||||
*
|
||||
|
@ -145,17 +136,6 @@ inline void fill_rect(surface& dst, SDL_Rect* dst_rect, const Uint32 color)
|
|||
SDL_FillRect(dst, dst_rect, color);
|
||||
}
|
||||
|
||||
#ifdef SDL_GPU
|
||||
void fill_rect(CVideo &video, const SDL_Rect &rect, SDL_Color color);
|
||||
|
||||
void fill_rect(CVideo &video, const SDL_Rect &rect, Uint8 r, Uint8 g,
|
||||
Uint8 b, Uint8 a = SDL_ALPHA_OPAQUE);
|
||||
|
||||
void draw_rect(CVideo &video, const SDL_Rect &rect, SDL_Color color);
|
||||
|
||||
void draw_rect(CVideo &video, const SDL_Rect &rect, Uint8 r, Uint8 g,
|
||||
Uint8 b, Uint8 a = SDL_ALPHA_OPAQUE);
|
||||
#endif
|
||||
} // namespace sdl
|
||||
|
||||
bool operator==(const SDL_Rect& a, const SDL_Rect& b);
|
||||
|
|
|
@ -17,149 +17,3 @@
|
|||
#include "image.hpp"
|
||||
#include "../image.hpp" // We want the file in src/
|
||||
|
||||
#ifdef SDL_GPU
|
||||
namespace sdl
|
||||
{
|
||||
|
||||
shader_program::shader_program(const std::string &vsrc, const std::string &fsrc)
|
||||
: program_object_(0)
|
||||
, vertex_object_(0)
|
||||
, fragment_object_(0)
|
||||
, block_()
|
||||
, attr_color_mod_(0)
|
||||
, attr_submerge_(0)
|
||||
, attr_effects_(0)
|
||||
, uni_overlay_(0)
|
||||
, overlay_image_()
|
||||
, refcount_(new unsigned(1))
|
||||
{
|
||||
vertex_object_ = GPU_LoadShader(GPU_VERTEX_SHADER, vsrc.c_str());
|
||||
if (!vertex_object_) {
|
||||
throw shader_error("Failed to compile vertex shader");
|
||||
}
|
||||
|
||||
fragment_object_ = GPU_LoadShader(GPU_FRAGMENT_SHADER, fsrc.c_str());
|
||||
if (!fragment_object_) {
|
||||
throw shader_error("Failed to compile fragment shader");
|
||||
}
|
||||
|
||||
program_object_ = GPU_LinkShaders(vertex_object_, fragment_object_);
|
||||
if (!program_object_) {
|
||||
throw shader_error("Failed to link shader program");
|
||||
}
|
||||
|
||||
attr_color_mod_ = GPU_GetAttributeLocation(program_object_,
|
||||
"vert_color_mod");
|
||||
attr_submerge_ = GPU_GetAttributeLocation(program_object_,
|
||||
"vert_submerge");
|
||||
attr_effects_ = GPU_GetAttributeLocation(program_object_,
|
||||
"vert_effects");
|
||||
uni_overlay_ = GPU_GetUniformLocation(program_object_, "overlay");
|
||||
|
||||
set_color_mod(0, 0, 0, 0);
|
||||
set_submerge(0);
|
||||
set_effects(0);
|
||||
}
|
||||
|
||||
shader_program::shader_program()
|
||||
: program_object_(0)
|
||||
, vertex_object_(0)
|
||||
, fragment_object_(0)
|
||||
, block_()
|
||||
, attr_color_mod_(0)
|
||||
, attr_submerge_(0)
|
||||
, attr_effects_(0)
|
||||
, uni_overlay_(0)
|
||||
, overlay_image_()
|
||||
, refcount_(new unsigned(1))
|
||||
{}
|
||||
|
||||
shader_program::~shader_program()
|
||||
{
|
||||
(*refcount_)--;
|
||||
if (!*refcount_) {
|
||||
deactivate();
|
||||
GPU_FreeShader(vertex_object_);
|
||||
GPU_FreeShader(fragment_object_);
|
||||
GPU_FreeShaderProgram(program_object_);
|
||||
}
|
||||
}
|
||||
|
||||
shader_program::shader_program(const shader_program &prog)
|
||||
: program_object_(prog.program_object_)
|
||||
, vertex_object_(prog.vertex_object_)
|
||||
, fragment_object_(prog.fragment_object_)
|
||||
, block_(prog.block_)
|
||||
, attr_color_mod_(prog.attr_color_mod_)
|
||||
, attr_submerge_(prog.attr_submerge_)
|
||||
, attr_effects_(prog.attr_effects_)
|
||||
, uni_overlay_(prog.uni_overlay_)
|
||||
, overlay_image_(prog.overlay_image_)
|
||||
, refcount_(prog.refcount_)
|
||||
{
|
||||
(*refcount_)++;
|
||||
}
|
||||
|
||||
const shader_program &shader_program::operator =(const shader_program &prog)
|
||||
{
|
||||
if (&prog != this) {
|
||||
this->~shader_program();
|
||||
return *(new(this) shader_program(prog));
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
void shader_program::activate()
|
||||
{
|
||||
block_ = GPU_LoadShaderBlock(program_object_, "vert_vertex",
|
||||
"vert_texture_pos", "vert_draw_color",
|
||||
"model_view_proj");
|
||||
GPU_ActivateShaderProgram(program_object_, &block_);
|
||||
//NOTE: this line can be removed once we made sure that a sane overlay
|
||||
// will be set before rendering anything.
|
||||
set_overlay(image::get_texture("misc/blank.png"));
|
||||
}
|
||||
|
||||
void shader_program::deactivate()
|
||||
{
|
||||
if (GPU_GetCurrentShaderProgram() == program_object_) {
|
||||
GPU_DeactivateShaderProgram();
|
||||
}
|
||||
}
|
||||
|
||||
void shader_program::set_color_mod(int r, int g, int b, int a)
|
||||
{
|
||||
static float color_mod[4];
|
||||
color_mod[0] = float(r) / 255;
|
||||
color_mod[1] = float(g) / 255;
|
||||
color_mod[2] = float(b) / 255;
|
||||
color_mod[3] = float(a) / 255;
|
||||
|
||||
GPU_SetAttributefv(attr_color_mod_, 4, color_mod);
|
||||
}
|
||||
|
||||
void shader_program::set_submerge(float val)
|
||||
{
|
||||
GPU_SetAttributef(attr_submerge_, val);
|
||||
}
|
||||
|
||||
void shader_program::set_effects(int effects)
|
||||
{
|
||||
GPU_SetAttributei(attr_effects_, effects);
|
||||
}
|
||||
|
||||
void shader_program::set_overlay(const timage &img)
|
||||
{
|
||||
overlay_image_ = img;
|
||||
GPU_SetShaderImage(img.raw(), uni_overlay_, 1);
|
||||
}
|
||||
|
||||
shader_error::shader_error(const std::string &op)
|
||||
: game::error(op + "\n" + GPU_GetShaderMessage())
|
||||
{
|
||||
std::cerr << GPU_GetShaderMessage() << std::endl;
|
||||
}
|
||||
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -13,58 +13,3 @@
|
|||
*/
|
||||
|
||||
|
||||
#ifdef SDL_GPU
|
||||
|
||||
#include "gpu.hpp"
|
||||
#include "image.hpp"
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "exceptions.hpp"
|
||||
|
||||
#define SHADER_EFFECT_NONE 0
|
||||
#define SHADER_EFFECT_FLIP 1
|
||||
#define SHADER_EFFECT_FLOP 2
|
||||
#define SHADER_EFFECT_GRAYSCALE 4
|
||||
|
||||
namespace sdl {
|
||||
|
||||
class timage;
|
||||
|
||||
class shader_program
|
||||
{
|
||||
public:
|
||||
shader_program(const std::string &vsrc, const std::string &fsrc);
|
||||
shader_program();
|
||||
~shader_program();
|
||||
|
||||
shader_program(const shader_program &prog);
|
||||
const shader_program& operator =(const shader_program &prog);
|
||||
|
||||
void activate();
|
||||
void deactivate();
|
||||
|
||||
void set_color_mod(int r, int g, int b, int a);
|
||||
void set_submerge(float val);
|
||||
void set_effects(int effects);
|
||||
void set_overlay(const sdl::timage &img);
|
||||
|
||||
private:
|
||||
Uint32 program_object_, vertex_object_, fragment_object_;
|
||||
GPU_ShaderBlock block_;
|
||||
int attr_color_mod_, attr_submerge_, attr_effects_;
|
||||
int uni_overlay_;
|
||||
// we need to retain a copy of the overlay texture to prevent it from
|
||||
// getting deleted
|
||||
sdl::timage overlay_image_;
|
||||
unsigned *refcount_;
|
||||
};
|
||||
|
||||
class shader_error : public game::error
|
||||
{
|
||||
public:
|
||||
shader_error(const std::string &op);
|
||||
};
|
||||
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -67,11 +67,7 @@ SDL_Color int_to_color(const Uint32 rgb)
|
|||
result.r = (0x00FF0000 & rgb )>> 16;
|
||||
result.g = (0x0000FF00 & rgb) >> 8;
|
||||
result.b = (0x000000FF & rgb);
|
||||
#ifdef SDL_GPU
|
||||
result.unused = SDL_ALPHA_OPAQUE;
|
||||
#else
|
||||
result.a = SDL_ALPHA_OPAQUE;
|
||||
#endif
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
@ -90,18 +90,6 @@ dialog_frame::dialog_frame(CVideo& video, const std::string& title,
|
|||
restorer_(nullptr),
|
||||
auto_restore_(auto_restore),
|
||||
dim_(),
|
||||
#ifdef SDL_GPU
|
||||
top_(image::get_texture("dialogs/" + dialog_style_.panel + "-border-top.png")),
|
||||
bot_(image::get_texture("dialogs/" + dialog_style_.panel + "-border-bottom.png")),
|
||||
left_(image::get_texture("dialogs/" + dialog_style_.panel + "-border-left.png")),
|
||||
right_(image::get_texture("dialogs/" + dialog_style_.panel + "-border-right.png")),
|
||||
top_left_(image::get_texture("dialogs/" + dialog_style_.panel + "-border-topleft.png")),
|
||||
bot_left_(image::get_texture("dialogs/" + dialog_style_.panel + "-border-botleft.png")),
|
||||
top_right_(image::get_texture("dialogs/" + dialog_style_.panel + "-border-topright.png")),
|
||||
bot_right_(image::get_texture("dialogs/" + dialog_style_.panel + "-border-botright.png")),
|
||||
bg_(image::get_texture("dialogs/" + dialog_style_.panel + "-background.png")),
|
||||
have_border_(!top_.null() && !bot_.null() && !left_.null() && !right_.null())
|
||||
#else
|
||||
top_(image::get_image("dialogs/" + dialog_style_.panel + "-border-top.png")),
|
||||
bot_(image::get_image("dialogs/" + dialog_style_.panel + "-border-bottom.png")),
|
||||
left_(image::get_image("dialogs/" + dialog_style_.panel + "-border-left.png")),
|
||||
|
@ -113,7 +101,6 @@ dialog_frame::dialog_frame(CVideo& video, const std::string& title,
|
|||
bg_(image::get_image("dialogs/" + dialog_style_.panel + "-background.png")),
|
||||
have_border_(top_ != nullptr && bot_ != nullptr && left_ != nullptr && right_ != nullptr),
|
||||
dirty_(true)
|
||||
#endif
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -133,11 +120,7 @@ dialog_frame::dimension_measurements dialog_frame::layout(SDL_Rect const& rect)
|
|||
int dialog_frame::top_padding() const {
|
||||
int padding = 0;
|
||||
if(have_border_) {
|
||||
#ifdef SDL_GPU
|
||||
padding += top_.height();
|
||||
#else
|
||||
padding += top_->h;
|
||||
#endif
|
||||
}
|
||||
if(!title_.empty()) {
|
||||
padding += font::get_max_height(font::SIZE_TITLE) + 2*dialog_frame::title_border_h;
|
||||
|
@ -187,11 +170,7 @@ int dialog_frame::bottom_padding() const {
|
|||
}
|
||||
}
|
||||
if(have_border_) {
|
||||
#ifdef SDL_GPU
|
||||
padding += bot_.height();
|
||||
#else
|
||||
padding += bot_->h;
|
||||
#endif
|
||||
}
|
||||
return padding;
|
||||
}
|
||||
|
@ -228,17 +207,10 @@ dialog_frame::dimension_measurements dialog_frame::layout(int x, int y, int w, i
|
|||
|
||||
SDL_Rect bounds = screen_area();
|
||||
if(have_border_) {
|
||||
#ifdef SDL_GPU
|
||||
bounds.x += left_.width();
|
||||
bounds.y += top_.height();
|
||||
bounds.w -= left_.width();
|
||||
bounds.h -= top_.height();
|
||||
#else
|
||||
bounds.x += left_->w;
|
||||
bounds.y += top_->h;
|
||||
bounds.w -= left_->w;
|
||||
bounds.h -= top_->h;
|
||||
#endif
|
||||
}
|
||||
if(x < bounds.x) {
|
||||
w += x;
|
||||
|
@ -263,17 +235,10 @@ dialog_frame::dimension_measurements dialog_frame::layout(int x, int y, int w, i
|
|||
dim_.interior.w = w;
|
||||
dim_.interior.h = h;
|
||||
if(have_border_) {
|
||||
#ifdef SDL_GPU
|
||||
dim_.exterior.x = dim_.interior.x - left_.width();
|
||||
dim_.exterior.y = dim_.interior.y - top_.height();
|
||||
dim_.exterior.w = dim_.interior.w + left_.width() + right_.width();
|
||||
dim_.exterior.h = dim_.interior.h + top_.height() + bot_.height();
|
||||
#else
|
||||
dim_.exterior.x = dim_.interior.x - left_->w;
|
||||
dim_.exterior.y = dim_.interior.y - top_->h;
|
||||
dim_.exterior.w = dim_.interior.w + left_->w + right_->w;
|
||||
dim_.exterior.h = dim_.interior.h + top_->h + bot_->h;
|
||||
#endif
|
||||
} else {
|
||||
dim_.exterior = dim_.interior;
|
||||
}
|
||||
|
@ -288,28 +253,6 @@ void dialog_frame::draw_border()
|
|||
return;
|
||||
}
|
||||
|
||||
#ifdef SDL_GPU
|
||||
top_.set_hscale(float(dim_.interior.w )/ top_.base_width());
|
||||
video_.draw_texture(top_, dim_.interior.x, dim_.exterior.y);
|
||||
|
||||
bot_.set_hscale(float(dim_.interior.w) / bot_.base_width());
|
||||
video_.draw_texture(bot_, dim_.interior.x, dim_.interior.y + dim_.interior.h);
|
||||
|
||||
left_.set_vscale(float(dim_.interior.h) / left_.base_height());
|
||||
video_.draw_texture(left_, dim_.exterior.x, dim_.interior.y);
|
||||
|
||||
right_.set_vscale(float(dim_.interior.h) / right_.base_height());
|
||||
video_.draw_texture(right_, dim_.interior.x + dim_.interior.w, dim_.interior.y);
|
||||
|
||||
if(top_left_.null() || bot_left_.null() || top_right_.null() || bot_right_.null()) {
|
||||
return;
|
||||
}
|
||||
|
||||
video_.draw_texture(top_left_, dim_.interior.x - left_.width(), dim_.interior.y - top_.height());
|
||||
video_.draw_texture(bot_left_, dim_.interior.x - left_.width(), dim_.interior.y + dim_.interior.h + bot_.height() - bot_left_.height());
|
||||
video_.draw_texture(top_right_, dim_.interior.x + dim_.interior.w + right_.width() - top_right_.width(), dim_.interior.y - top_.height());
|
||||
video_.draw_texture(bot_right_, dim_.interior.x + dim_.interior.w + right_.width() - bot_right_.width(), dim_.interior.y + dim_.interior.h + bot_.height() - bot_right_.height());
|
||||
#else
|
||||
surface top_image(scale_surface(top_, dim_.interior.w, top_->h));
|
||||
|
||||
if(top_image != nullptr) {
|
||||
|
@ -344,7 +287,6 @@ void dialog_frame::draw_border()
|
|||
video_.blit_surface(dim_.interior.x - left_->w, dim_.interior.y + dim_.interior.h + bot_->h - bot_left_->h, bot_left_);
|
||||
video_.blit_surface(dim_.interior.x + dim_.interior.w + right_->w - top_right_->w, dim_.interior.y - top_->h, top_right_);
|
||||
video_.blit_surface(dim_.interior.x + dim_.interior.w + right_->w - bot_right_->w, dim_.interior.y + dim_.interior.h + bot_->h - bot_right_->h, bot_right_);
|
||||
#endif
|
||||
}
|
||||
|
||||
void dialog_frame::clear_background()
|
||||
|
@ -366,24 +308,6 @@ void dialog_frame::draw_background()
|
|||
sdl_blit(surf, nullptr, video_.getSurface(), &dim_.exterior);
|
||||
}
|
||||
|
||||
#ifdef SDL_GPU
|
||||
if(bg_.null()) {
|
||||
ERR_DP << "could not find dialog background '" << dialog_style_.panel << "'" << std::endl;
|
||||
return;
|
||||
}
|
||||
for(int i = 0; i < dim_.interior.w; i += bg_.width()) {
|
||||
for(int j = 0; j < dim_.interior.h; j += bg_.height()) {
|
||||
SDL_Rect src = {0,0,0,0};
|
||||
src.w = std::min(dim_.interior.w - i, bg_.width());
|
||||
src.h = std::min(dim_.interior.h - j, bg_.height());
|
||||
SDL_Rect dst = src;
|
||||
dst.x = dim_.interior.x + i;
|
||||
dst.y = dim_.interior.y + j;
|
||||
bg_.set_clip(src);
|
||||
video_.draw_texture(bg_, dst.x, dst.y);
|
||||
}
|
||||
}
|
||||
#else
|
||||
if(bg_ == nullptr) {
|
||||
ERR_DP << "could not find dialog background '" << dialog_style_.panel << "'" << std::endl;
|
||||
return;
|
||||
|
@ -399,7 +323,6 @@ void dialog_frame::draw_background()
|
|||
sdl_blit(bg_, &src, video_.getSurface(), &dst);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
SDL_Rect dialog_frame::draw_title(CVideo* video)
|
||||
|
|
|
@ -110,11 +110,7 @@ private:
|
|||
surface_restorer* restorer_;
|
||||
bool auto_restore_;
|
||||
dimension_measurements dim_;
|
||||
#ifdef SDL_GPU
|
||||
sdl::timage top_, bot_, left_, right_, top_left_, bot_left_, top_right_, bot_right_, bg_;
|
||||
#else
|
||||
surface top_, bot_, left_, right_, top_left_, bot_left_, top_right_, bot_right_, bg_;
|
||||
#endif
|
||||
bool have_border_;
|
||||
bool dirty_;
|
||||
};
|
||||
|
|
|
@ -67,29 +67,6 @@ void floating_image::assign(const floating_image& fi)
|
|||
|
||||
floating_image::render_input floating_image::get_render_input(double xscale, double yscale, SDL_Rect& dst_rect) const
|
||||
{
|
||||
#ifdef SDL_GPU
|
||||
render_input ri = {
|
||||
{0,0,0,0},
|
||||
file_.empty() ? sdl::timage() : image::get_texture(file_)
|
||||
};
|
||||
|
||||
if(!ri.image.null()) {
|
||||
if(autoscaled_) {
|
||||
ri.image.set_scale(xscale, yscale);
|
||||
}
|
||||
|
||||
ri.rect.x = static_cast<int>(x_*xscale) + dst_rect.x;
|
||||
ri.rect.y = static_cast<int>(y_*yscale) + dst_rect.y;
|
||||
ri.rect.w = ri.image.width();
|
||||
ri.rect.h = ri.image.height();
|
||||
|
||||
if(centered_) {
|
||||
ri.rect.x -= ri.rect.w / 2;
|
||||
ri.rect.y -= ri.rect.h / 2;
|
||||
}
|
||||
}
|
||||
return ri;
|
||||
#else
|
||||
render_input ri = {
|
||||
{0,0,0,0},
|
||||
file_.empty() ? nullptr : image::get_image(file_)
|
||||
|
@ -115,7 +92,6 @@ floating_image::render_input floating_image::get_render_input(double xscale, dou
|
|||
}
|
||||
}
|
||||
return ri;
|
||||
#endif
|
||||
}
|
||||
|
||||
background_layer::background_layer()
|
||||
|
|
|
@ -43,11 +43,7 @@ public:
|
|||
struct render_input
|
||||
{
|
||||
SDL_Rect rect; /**< Corrected rectangle for rendering surf. */
|
||||
#ifdef SDL_GPU
|
||||
sdl::timage image;
|
||||
#else
|
||||
surface image; /**< Surface, scaled if required. */
|
||||
#endif
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -42,22 +42,14 @@ static lg::log_domain log_engine("engine");
|
|||
|
||||
namespace {
|
||||
int const storybox_padding = 10; // px
|
||||
#ifdef SDL_GPU
|
||||
int const storyshadow_a = 125;
|
||||
#else
|
||||
double const storyshadow_opacity = 0.5;
|
||||
#endif
|
||||
int const storyshadow_r = 0;
|
||||
int const storyshadow_g = 0;
|
||||
int const storyshadow_b = 0;
|
||||
|
||||
int const titlebox_padding = 20; // px
|
||||
int const titleshadow_padding = 5; // px
|
||||
#ifdef SDL_GPU
|
||||
int const titleshadow_a = 125;
|
||||
#else
|
||||
double const titleshadow_opacity = 0.5;
|
||||
#endif
|
||||
int const titleshadow_r = 0;
|
||||
int const titleshadow_g = 0;
|
||||
int const titleshadow_b = 0;
|
||||
|
@ -72,7 +64,6 @@ namespace {
|
|||
// Hard-coded path to a suitable (tileable) pic for the storytxt box border.
|
||||
std::string const storybox_top_border_path = "dialogs/translucent54-border-top.png";
|
||||
std::string const storybox_bottom_border_path = "dialogs/translucent54-border-bottom.png";
|
||||
#ifndef SDL_GPU
|
||||
void blur_area(CVideo& video, int y, int h)
|
||||
{
|
||||
SDL_Rect blur_rect = sdl::create_rect(0, y, screen_area().w, h);
|
||||
|
@ -81,7 +72,6 @@ namespace {
|
|||
video.blit_surface(0, y, blur);
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
namespace storyscreen {
|
||||
|
@ -100,12 +90,7 @@ part_ui::part_ui(part &p, CVideo& video, gui::button &next_button,
|
|||
, x_scale_factor_(1.0)
|
||||
, y_scale_factor_(1.0)
|
||||
, base_rect_()
|
||||
#ifdef SDL_GPU
|
||||
, background_images_()
|
||||
, background_positions_()
|
||||
#else
|
||||
, background_(nullptr)
|
||||
#endif
|
||||
, imgs_()
|
||||
, has_background_(false)
|
||||
, text_x_(200)
|
||||
|
@ -118,74 +103,6 @@ part_ui::part_ui(part &p, CVideo& video, gui::button &next_button,
|
|||
|
||||
void part_ui::prepare_background()
|
||||
{
|
||||
#ifdef SDL_GPU
|
||||
base_rect_.w = video_.getx();
|
||||
base_rect_.h = video_.gety();
|
||||
has_background_ = false;
|
||||
bool no_base_yet = true;
|
||||
|
||||
for (const background_layer& bl : p_.get_background_layers()) {
|
||||
sdl::timage layer;
|
||||
|
||||
if (!bl.file().empty()) {
|
||||
layer = image::get_texture(bl.file());
|
||||
}
|
||||
has_background_ = has_background_ || !layer.null();
|
||||
if(layer.null() || layer.width() * layer.height() == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const double xscale = 1.0 * video_.getx() / layer.base_width();
|
||||
const double yscale = 1.0 * video_.gety() / layer.base_height();
|
||||
const bool scalev = bl.scale_vertically();
|
||||
const bool scaleh = bl.scale_horizontally();
|
||||
const bool keep_ratio = bl.keep_aspect_ratio();
|
||||
const bool tileh = bl.tile_horizontally();
|
||||
const bool tilev = bl.tile_vertically();
|
||||
|
||||
double x_scale_factor = scaleh ? xscale : 1.0;
|
||||
double y_scale_factor = scalev ? yscale : 1.0;
|
||||
|
||||
if (scalev && scaleh && keep_ratio) {
|
||||
x_scale_factor = y_scale_factor = std::min<double>(xscale, yscale);
|
||||
} else if (keep_ratio && scaleh) {
|
||||
x_scale_factor = y_scale_factor = xscale;
|
||||
} else if (keep_ratio && scalev) {
|
||||
x_scale_factor = y_scale_factor = yscale;
|
||||
}
|
||||
|
||||
layer.set_smooth_scaling(true);
|
||||
SDL_Rect clip = sdl::create_rect(0, 0, layer.base_width(), layer.base_height());
|
||||
if (tileh) {
|
||||
clip.x = (layer.base_width() - video_.getx())/2;
|
||||
clip.w = video_.getx();
|
||||
layer.set_hwrap(GPU_WRAP_REPEAT);
|
||||
}
|
||||
if (tilev) {
|
||||
clip.y = (layer.base_height() - video_.gety())/2;
|
||||
clip.h = video_.gety();
|
||||
layer.set_vwrap(GPU_WRAP_REPEAT);
|
||||
}
|
||||
layer.set_clip(clip);
|
||||
layer.set_scale(x_scale_factor, y_scale_factor);
|
||||
|
||||
SDL_Rect base_rect = sdl::create_rect(
|
||||
(video_.getx() - layer.width()) / 2
|
||||
, (video_.gety() - layer.height()) / 2
|
||||
, layer.width()
|
||||
, layer.height());
|
||||
|
||||
background_images_.push_back(layer);
|
||||
background_positions_.push_back(std::pair<int, int>(base_rect.x, base_rect.y));
|
||||
|
||||
if (bl.is_base_layer() || no_base_yet) {
|
||||
x_scale_factor_ = x_scale_factor;
|
||||
y_scale_factor_ = y_scale_factor;
|
||||
base_rect_ = base_rect;
|
||||
no_base_yet = false;
|
||||
}
|
||||
}
|
||||
#else
|
||||
background_.assign( create_neutral_surface(video_.getx(), video_.gety()) );
|
||||
base_rect_.w = video_.getx();
|
||||
base_rect_.h = video_.gety();
|
||||
|
@ -264,7 +181,6 @@ void part_ui::prepare_background()
|
|||
no_base_yet = false;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void part_ui::prepare_geometry()
|
||||
|
@ -320,35 +236,6 @@ void part_ui::render_background()
|
|||
|
||||
bool part_ui::render_floating_images()
|
||||
{
|
||||
#ifdef SDL_GPU
|
||||
skip_ = false;
|
||||
last_key_ = true;
|
||||
|
||||
size_t fi_n = 0;
|
||||
for (floating_image::render_input& ri : imgs_) {
|
||||
const floating_image& fi = p_.get_floating_images()[fi_n];
|
||||
|
||||
if(!ri.image.null()) {
|
||||
ri.image.draw(video_, ri.rect.x, ri.rect.y);
|
||||
video_.flip();
|
||||
}
|
||||
|
||||
if (!skip_)
|
||||
{
|
||||
int delay = fi.display_delay(), delay_step = 20;
|
||||
for (int i = 0; i != (delay + delay_step - 1) / delay_step; ++i)
|
||||
{
|
||||
if (handle_interface()) return false;
|
||||
if (skip_) break;
|
||||
CVideo::delay(std::min<int>(delay_step, delay - i * delay_step));
|
||||
}
|
||||
}
|
||||
|
||||
++fi_n;
|
||||
}
|
||||
|
||||
return true;
|
||||
#else
|
||||
events::raise_draw_event();
|
||||
|
||||
skip_ = false;
|
||||
|
@ -385,75 +272,10 @@ bool part_ui::render_floating_images()
|
|||
++fi_n;
|
||||
}
|
||||
return true;
|
||||
#endif
|
||||
}
|
||||
|
||||
void part_ui::render_title_box()
|
||||
{
|
||||
#ifdef SDL_GPU
|
||||
const std::string& titletxt = p_.title();
|
||||
if(titletxt.empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
int titlebox_x, titlebox_y, titlebox_max_w, titlebox_max_h;
|
||||
// We later correct these according to the storytext box location.
|
||||
// The text box is always aligned according to the base_rect_
|
||||
// (effective background area) at the end.
|
||||
titlebox_x = titlebox_padding;
|
||||
titlebox_max_w = base_rect_.w - 2*titlebox_padding;
|
||||
titlebox_y = titlebox_padding;
|
||||
titlebox_max_h = base_rect_.h - 2*titlebox_padding;
|
||||
|
||||
font::ttext t;
|
||||
if(!t.set_text(titletxt, true)) {
|
||||
ERR_NG << "Text: Invalid markup in '"
|
||||
<< titletxt << "' rendered as is.\n";
|
||||
t.set_text(titletxt, false);
|
||||
}
|
||||
|
||||
t.set_font_style(font::ttext::STYLE_NORMAL)
|
||||
.set_font_size(titlebox_font_size)
|
||||
.set_foreground_color(titlebox_font_color)
|
||||
.set_maximum_width(titlebox_max_w)
|
||||
.set_maximum_height(titlebox_max_h, true);
|
||||
sdl::timage txttxt = t.render_as_texture();
|
||||
|
||||
if(txttxt.null()) {
|
||||
ERR_NG << "storyscreen titlebox rendering resulted in a null surface" << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
const int titlebox_w = txttxt.width();
|
||||
const int titlebox_h = txttxt.height();
|
||||
|
||||
switch(p_.title_text_alignment()) {
|
||||
case part::TEXT_CENTERED:
|
||||
titlebox_x = base_rect_.w / 2 - titlebox_w / 2 - titlebox_padding;
|
||||
break;
|
||||
case part::TEXT_RIGHT:
|
||||
titlebox_x = base_rect_.w - titlebox_padding - titlebox_w;
|
||||
break;
|
||||
default:
|
||||
break; // already set before
|
||||
}
|
||||
|
||||
// Translate to absolute position.
|
||||
titlebox_x += base_rect_.x;
|
||||
titlebox_y += base_rect_.y;
|
||||
|
||||
const SDL_Rect box = sdl::create_rect(
|
||||
titlebox_x - titleshadow_padding,
|
||||
titlebox_y - titleshadow_padding,
|
||||
titlebox_w + 2*titleshadow_padding,
|
||||
titlebox_h + 2*titleshadow_padding
|
||||
);
|
||||
|
||||
sdl::fill_rect(video_, box, titleshadow_r, titleshadow_g, titleshadow_b,
|
||||
titleshadow_a);
|
||||
|
||||
video_.draw_texture(txttxt, titlebox_x, titlebox_y);
|
||||
#else
|
||||
const std::string& titletxt = p_.title();
|
||||
if(titletxt.empty()) {
|
||||
return;
|
||||
|
@ -530,7 +352,6 @@ void part_ui::render_title_box()
|
|||
back_button_.hide(false);
|
||||
play_button_.hide(false);
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef LOW_MEM
|
||||
|
@ -539,45 +360,6 @@ void part_ui::render_story_box_borders(SDL_Rect& /*update_area*/)
|
|||
#else
|
||||
void part_ui::render_story_box_borders(SDL_Rect& update_area)
|
||||
{
|
||||
#ifdef SDL_GPU
|
||||
const part::BLOCK_LOCATION tbl = p_.story_text_location();
|
||||
|
||||
if(has_background_) {
|
||||
sdl::timage border_top;
|
||||
sdl::timage border_bottom;
|
||||
|
||||
if(tbl == part::BLOCK_BOTTOM || tbl == part::BLOCK_MIDDLE) {
|
||||
border_top = image::get_texture(storybox_top_border_path);
|
||||
}
|
||||
|
||||
if(tbl == part::BLOCK_TOP || tbl == part::BLOCK_MIDDLE) {
|
||||
border_bottom = image::get_texture(storybox_bottom_border_path);
|
||||
}
|
||||
|
||||
//
|
||||
// If one of those are null at this point, it means that either we
|
||||
// don't need that border pic, or it is missing (in such case get_image()
|
||||
// would report).
|
||||
//
|
||||
|
||||
if(border_top.null() != true) {
|
||||
const float xscale = float(screen_area().w) / border_top.base_width();
|
||||
border_top.set_hscale(xscale);
|
||||
//TODO: blurring
|
||||
video_.draw_texture(border_top, 0,
|
||||
update_area.y - border_top.base_height());
|
||||
}
|
||||
|
||||
if(border_bottom.null() != true) {
|
||||
const float xscale = float(screen_area().w) / border_bottom.base_width();
|
||||
border_bottom.set_hscale(xscale);
|
||||
//TODO: blurring
|
||||
video_.draw_texture(border_bottom, 0,
|
||||
update_area.y - border_top.base_height());
|
||||
}
|
||||
|
||||
}
|
||||
#else
|
||||
const part::BLOCK_LOCATION tbl = p_.story_text_location();
|
||||
|
||||
if(has_background_) {
|
||||
|
@ -621,123 +403,11 @@ void part_ui::render_story_box_borders(SDL_Rect& update_area)
|
|||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
void part_ui::render_story_box()
|
||||
{
|
||||
#ifdef SDL_GPU
|
||||
LOG_NG << "ENTER part_ui()::render_story_box()\n";
|
||||
|
||||
const std::string& storytxt = p_.text();
|
||||
if(storytxt.empty()) {
|
||||
video_.flip();
|
||||
wait_for_input();
|
||||
return;
|
||||
}
|
||||
|
||||
const part::BLOCK_LOCATION tbl = p_.story_text_location();
|
||||
const int max_width = buttons_x_ - storybox_padding - text_x_;
|
||||
const int max_height = screen_area().h - storybox_padding;
|
||||
|
||||
skip_ = false;
|
||||
last_key_ = true;
|
||||
|
||||
font::ttext t;
|
||||
if(!t.set_text(p_.text(), true)) {
|
||||
ERR_NG << "Text: Invalid markup in '"
|
||||
<< p_.text() << "' rendered as is.\n";
|
||||
t.set_text(p_.text(), false);
|
||||
}
|
||||
t.set_font_style(font::ttext::STYLE_NORMAL)
|
||||
.set_font_size(storybox_font_size)
|
||||
.set_foreground_color(storybox_font_color)
|
||||
.set_maximum_width(max_width)
|
||||
.set_maximum_height(max_height, true);
|
||||
sdl::timage txttxt = t.render_as_texture();
|
||||
|
||||
if(txttxt.null()) {
|
||||
ERR_NG << "storyscreen text area rendering resulted in a null texture" << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
int fix_text_y = text_y_;
|
||||
if(fix_text_y + 2*(storybox_padding+1) + txttxt.height() > screen_area().h && tbl != part::BLOCK_TOP) {
|
||||
fix_text_y =
|
||||
(screen_area().h > txttxt.height() + 1) ?
|
||||
(std::max(0, screen_area().h - txttxt.height() - 2*(storybox_padding+1))) :
|
||||
(0);
|
||||
}
|
||||
int fix_text_h;
|
||||
switch(tbl) {
|
||||
case part::BLOCK_TOP:
|
||||
fix_text_h = std::max(txttxt.height() + 2*storybox_padding, screen_area().h/4);
|
||||
break;
|
||||
case part::BLOCK_MIDDLE:
|
||||
fix_text_h = std::max(txttxt.height() + 2*storybox_padding, screen_area().h/3);
|
||||
break;
|
||||
default:
|
||||
fix_text_h = screen_area().h - fix_text_y;
|
||||
break;
|
||||
}
|
||||
|
||||
SDL_Rect update_area = sdl::create_rect(0
|
||||
, fix_text_y
|
||||
, screen_area().w
|
||||
, fix_text_h);
|
||||
|
||||
/* do */ {
|
||||
// this should kill the tiniest flickering caused
|
||||
// by the buttons being hidden and unhidden in this scope.
|
||||
update_locker locker(video_);
|
||||
|
||||
next_button_.hide();
|
||||
back_button_.hide();
|
||||
play_button_.hide();
|
||||
|
||||
//TODO: blurring
|
||||
|
||||
const SDL_Rect box = sdl::create_rect(0, fix_text_y, screen_area().w,
|
||||
fix_text_h);
|
||||
|
||||
sdl::fill_rect(video_, box, storyshadow_r, storyshadow_g,
|
||||
storyshadow_b, storyshadow_a);
|
||||
|
||||
render_story_box_borders(update_area); // no-op if LOW_MEM is defined
|
||||
|
||||
next_button_.hide(false);
|
||||
back_button_.hide(false);
|
||||
play_button_.hide(false);
|
||||
}
|
||||
|
||||
// Time to do some fucking visual effect.
|
||||
const int scan_height = 1, scan_width = txttxt.width();
|
||||
SDL_Rect scan = sdl::create_rect(0, 0, scan_width, scan_height);
|
||||
SDL_Rect dstrect = sdl::create_rect(text_x_, 0, scan_width, scan_height);
|
||||
bool scan_finished = false;
|
||||
while(true) {
|
||||
scan_finished = scan.y >= txttxt.base_height();
|
||||
if (!scan_finished)
|
||||
{
|
||||
dstrect.y = fix_text_y + scan.y + storybox_padding;
|
||||
txttxt.set_clip(scan);
|
||||
video_.draw_texture(txttxt, dstrect.x, dstrect.y);
|
||||
video_.flip();
|
||||
++scan.y;
|
||||
}
|
||||
else skip_ = true;
|
||||
|
||||
if (handle_interface()) break;
|
||||
|
||||
if (!skip_ || scan_finished) {
|
||||
CVideo::delay(20);
|
||||
}
|
||||
}
|
||||
|
||||
const SDL_Rect rect = sdl::create_rect(0, 0, video_.getx(), video_.gety());
|
||||
sdl::fill_rect(video_, rect, 0, 0, 0, SDL_ALPHA_OPAQUE);
|
||||
#else
|
||||
|
||||
LOG_NG<< "ENTER part_ui()::render_story_box()\n";
|
||||
bool first = true;
|
||||
|
@ -909,7 +579,6 @@ void part_ui::render_story_box()
|
|||
0, 0, video_.getx(), video_.gety(), 0, 0, 0,
|
||||
1.0, video_.getSurface()
|
||||
);
|
||||
#endif
|
||||
}
|
||||
|
||||
void part_ui::wait_for_input()
|
||||
|
|
|
@ -89,12 +89,7 @@ private:
|
|||
// (the background layer we align the images to)
|
||||
SDL_Rect base_rect_;
|
||||
|
||||
#ifdef SDL_GPU
|
||||
std::vector< sdl::timage > background_images_;
|
||||
std::vector< std::pair<int, int> > background_positions_;
|
||||
#else
|
||||
surface background_;
|
||||
#endif
|
||||
std::vector< floating_image::render_input > imgs_;
|
||||
bool has_background_;
|
||||
|
||||
|
|
13
src/text.cpp
13
src/text.cpp
|
@ -98,9 +98,6 @@ ttext::ttext() :
|
|||
layout_(pango_layout_new(context_)),
|
||||
rect_(),
|
||||
surface_(),
|
||||
#ifdef SDL_GPU
|
||||
texture_(),
|
||||
#endif
|
||||
text_(),
|
||||
markedup_text_(false),
|
||||
link_aware_(false),
|
||||
|
@ -162,13 +159,6 @@ surface ttext::render() const
|
|||
return surface_;
|
||||
}
|
||||
|
||||
#ifdef SDL_GPU
|
||||
sdl::timage ttext::render_as_texture() const
|
||||
{
|
||||
rerender();
|
||||
return texture_;
|
||||
}
|
||||
#endif
|
||||
|
||||
int ttext::get_width() const
|
||||
{
|
||||
|
@ -776,9 +766,6 @@ void ttext::rerender(const bool force) const
|
|||
|
||||
surface_.assign(SDL_CreateRGBSurfaceFrom(
|
||||
surface_buffer_, width, height, 32, stride, 0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000));
|
||||
#ifdef SDL_GPU
|
||||
texture_ = sdl::timage(surface_);
|
||||
#endif
|
||||
cairo_destroy(cr);
|
||||
cairo_surface_destroy(cairo_surface);
|
||||
}
|
||||
|
|
16
src/text.hpp
16
src/text.hpp
|
@ -28,10 +28,6 @@
|
|||
|
||||
#include "sdl/image.hpp"
|
||||
|
||||
#ifdef SDL_GPU
|
||||
#include "sdl/gpu.hpp"
|
||||
#include "sdl/image.hpp"
|
||||
#endif
|
||||
|
||||
struct language_def;
|
||||
|
||||
|
@ -80,15 +76,6 @@ public:
|
|||
*/
|
||||
surface render() const;
|
||||
|
||||
#ifdef SDL_GPU
|
||||
/**
|
||||
* Returns the rendered text as a texture.
|
||||
*
|
||||
* Before rendering it tests whether a redraw is needed and if so it first
|
||||
* redraws the texture before returning it.
|
||||
*/
|
||||
sdl::timage render_as_texture() const;
|
||||
#endif
|
||||
|
||||
/** Returns the width needed for the text. */
|
||||
int get_width() const;
|
||||
|
@ -256,9 +243,6 @@ private:
|
|||
/** The surface to render upon used as a cache. */
|
||||
mutable surface surface_;
|
||||
|
||||
#ifdef SDL_GPU
|
||||
mutable sdl::timage texture_;
|
||||
#endif
|
||||
|
||||
/** The text to draw (stored as UTF-8). */
|
||||
std::string text_;
|
||||
|
|
|
@ -177,13 +177,8 @@ void unit_drawer::redraw_unit (const unit & u) const
|
|||
SDL_Rect unit_rect = sdl::create_rect(xsrc, ysrc +adjusted_params.y, hex_size, hex_size);
|
||||
draw_bars = sdl::rects_overlap(unit_rect, disp.map_outside_area());
|
||||
}
|
||||
#ifdef SDL_GPU
|
||||
sdl::timage ellipse_front;
|
||||
sdl::timage ellipse_back;
|
||||
#else
|
||||
surface ellipse_front(nullptr);
|
||||
surface ellipse_back(nullptr);
|
||||
#endif
|
||||
int ellipse_floating = 0;
|
||||
// Always show the ellipse for selected units
|
||||
if(draw_bars && (preferences::show_side_colors() || sel_hex == loc)) {
|
||||
|
@ -209,28 +204,10 @@ void unit_drawer::redraw_unit (const unit & u) const
|
|||
const std::string ellipse_bot = formatter() << ellipse << "-" << leader << nozoc << selected << "bottom.png~RC(ellipse_red>" << tc << ")";
|
||||
|
||||
// Load the ellipse parts recolored to match team color
|
||||
#ifdef SDL_GPU
|
||||
ellipse_back = image::get_texture(image::locator(ellipse_top), image::SCALED_TO_ZOOM);
|
||||
ellipse_front = image::get_texture(image::locator(ellipse_bot), image::SCALED_TO_ZOOM);
|
||||
#else
|
||||
ellipse_back.assign(image::get_image(image::locator(ellipse_top), image::SCALED_TO_ZOOM));
|
||||
ellipse_front.assign(image::get_image(image::locator(ellipse_bot), image::SCALED_TO_ZOOM));
|
||||
#endif
|
||||
}
|
||||
}
|
||||
#ifdef SDL_GPU
|
||||
if (!ellipse_back.null()) {
|
||||
//disp.drawing_buffer_add(display::LAYER_UNIT_BG, loc,
|
||||
disp.drawing_buffer_add(display::LAYER_UNIT_FIRST, loc,
|
||||
xsrc, ysrc +adjusted_params.y-ellipse_floating, ellipse_back);
|
||||
}
|
||||
|
||||
if (!ellipse_front.null()) {
|
||||
//disp.drawing_buffer_add(display::LAYER_UNIT_FG, loc,
|
||||
disp.drawing_buffer_add(display::LAYER_UNIT_FIRST, loc,
|
||||
xsrc, ysrc +adjusted_params.y-ellipse_floating, ellipse_front);
|
||||
}
|
||||
#else
|
||||
if (ellipse_back != nullptr) {
|
||||
//disp.drawing_buffer_add(display::LAYER_UNIT_BG, loc,
|
||||
disp.drawing_buffer_add(display::LAYER_UNIT_FIRST, loc,
|
||||
|
@ -242,7 +219,6 @@ void unit_drawer::redraw_unit (const unit & u) const
|
|||
disp.drawing_buffer_add(display::LAYER_UNIT_FIRST, loc,
|
||||
xsrc, ysrc +adjusted_params.y-ellipse_floating, ellipse_front);
|
||||
}
|
||||
#endif
|
||||
if(draw_bars) {
|
||||
const image::locator* orb_img = nullptr;
|
||||
const surface unit_img = image::get_image(u.default_anim_image(), image::SCALED_TO_ZOOM);
|
||||
|
@ -330,19 +306,11 @@ void unit_drawer::redraw_unit (const unit & u) const
|
|||
}
|
||||
|
||||
for(std::vector<std::string>::const_iterator ov = u.overlays().begin(); ov != u.overlays().end(); ++ov) {
|
||||
#ifdef SDL_GPU
|
||||
const sdl::timage ov_img(image::get_texture(*ov, image::SCALED_TO_ZOOM));
|
||||
if(!ov_img.null()) {
|
||||
disp.drawing_buffer_add(display::LAYER_UNIT_BAR,
|
||||
loc, xsrc, ysrc +adjusted_params.y, ov_img);
|
||||
}
|
||||
#else
|
||||
const surface ov_img(image::get_image(*ov, image::SCALED_TO_ZOOM));
|
||||
if(ov_img != nullptr) {
|
||||
disp.drawing_buffer_add(display::LAYER_UNIT_BAR,
|
||||
loc, xsrc+xoff, ysrc+yoff+adjusted_params.y, ov_img);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -365,7 +333,6 @@ void unit_drawer::redraw_unit (const unit & u) const
|
|||
ac.refreshing_ = false;
|
||||
}
|
||||
|
||||
//TODO: proper SDL_gpu implementation
|
||||
void unit_drawer::draw_bar(const std::string& image, int xpos, int ypos,
|
||||
const map_location& loc, size_t height, double filled,
|
||||
const SDL_Color& col, fixed_t alpha) const
|
||||
|
@ -419,16 +386,8 @@ void unit_drawer::draw_bar(const std::string& image, int xpos, int ypos,
|
|||
SDL_Rect bot = sdl::create_rect(0, bar_loc.y + skip_rows, surf->w, 0);
|
||||
bot.h = surf->w - bot.y;
|
||||
|
||||
#ifdef SDL_GPU
|
||||
sdl::timage img(surf);
|
||||
img.set_clip(top);
|
||||
disp.drawing_buffer_add(display::LAYER_UNIT_BAR, loc, xpos, ypos, surf);
|
||||
img.set_clip(bot);
|
||||
disp.drawing_buffer_add(display::LAYER_UNIT_BAR, loc, xpos, ypos + top.h, surf);
|
||||
#else
|
||||
disp.drawing_buffer_add(display::LAYER_UNIT_BAR, loc, xpos, ypos, surf, top);
|
||||
disp.drawing_buffer_add(display::LAYER_UNIT_BAR, loc, xpos, ypos + top.h, surf, bot);
|
||||
#endif
|
||||
|
||||
size_t unfilled = static_cast<size_t>(height * (1.0 - filled));
|
||||
|
||||
|
@ -437,11 +396,7 @@ void unit_drawer::draw_bar(const std::string& image, int xpos, int ypos,
|
|||
surface filled_surf = create_compatible_surface(bar_surf, bar_loc.w, height - unfilled);
|
||||
SDL_Rect filled_area = sdl::create_rect(0, 0, bar_loc.w, height-unfilled);
|
||||
sdl::fill_rect(filled_surf,&filled_area,SDL_MapRGBA(bar_surf->format,col.r,col.g,col.b, r_alpha));
|
||||
#ifdef SDL_GPU
|
||||
disp.drawing_buffer_add(display::LAYER_UNIT_BAR, loc, xpos + bar_loc.x, ypos + bar_loc.y + unfilled, sdl::timage(filled_surf));
|
||||
#else
|
||||
disp.drawing_buffer_add(display::LAYER_UNIT_BAR, loc, xpos + bar_loc.x, ypos + bar_loc.y + unfilled, filled_surf);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
|
113
src/video.cpp
113
src/video.cpp
|
@ -28,7 +28,6 @@
|
|||
#include "sdl/rect.hpp"
|
||||
#include "sdl/window.hpp"
|
||||
#include "video.hpp"
|
||||
#include "sdl/gpu.hpp"
|
||||
#include "display.hpp"
|
||||
|
||||
#include <vector>
|
||||
|
@ -44,17 +43,11 @@ static lg::log_domain log_display("display");
|
|||
CVideo* CVideo::singleton_ = nullptr;
|
||||
|
||||
namespace {
|
||||
#ifdef SDL_GPU
|
||||
GPU_Target *render_target_;
|
||||
#endif
|
||||
}
|
||||
|
||||
static unsigned int get_flags(unsigned int flags)
|
||||
{
|
||||
/* The wanted flags for the render need to be evaluated for SDL2. */
|
||||
#ifdef SDL_GPU
|
||||
flags |= SDL_OPENGLBLIT;
|
||||
#endif
|
||||
|
||||
flags |= SDL_WINDOW_RESIZABLE;
|
||||
|
||||
|
@ -120,12 +113,6 @@ bool CVideo::non_interactive()
|
|||
}
|
||||
|
||||
|
||||
#ifdef SDL_GPU
|
||||
GPU_Target *get_render_target()
|
||||
{
|
||||
return render_target_;
|
||||
}
|
||||
#endif
|
||||
|
||||
surface& get_video_surface()
|
||||
{
|
||||
|
@ -214,9 +201,6 @@ void CVideo::video_event_handler::handle_window_event(const SDL_Event &event)
|
|||
|
||||
CVideo::CVideo(FAKE_TYPES type) :
|
||||
window(),
|
||||
#ifdef SDL_GPU
|
||||
shader_(),
|
||||
#endif
|
||||
mode_changed_(false),
|
||||
fake_screen_(false),
|
||||
help_string_(0),
|
||||
|
@ -241,43 +225,14 @@ CVideo::CVideo(FAKE_TYPES type) :
|
|||
|
||||
void CVideo::initSDL()
|
||||
{
|
||||
#ifdef SDL_GPU
|
||||
//800x600 is a dummy value, the actual resolution is set in setMode
|
||||
render_target_ = GPU_Init(800, 600, GPU_DEFAULT_INIT_FLAGS);
|
||||
|
||||
if(render_target_ == nullptr) {
|
||||
ERR_DP << "Could not initialize window: " << SDL_GetError() << std::endl;
|
||||
throw CVideo::error();
|
||||
}
|
||||
|
||||
const std::string vertex_src = game_config::path + "/data/shaders/default.vert";
|
||||
const std::string frag_src = game_config::path + "/data/shaders/default.frag";
|
||||
shader_ = sdl::shader_program(vertex_src, frag_src);
|
||||
shader_.activate();
|
||||
#else
|
||||
const int res = SDL_InitSubSystem(SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE);
|
||||
|
||||
if(res < 0) {
|
||||
ERR_DP << "Could not initialize SDL_video: " << SDL_GetError() << std::endl;
|
||||
throw CVideo::error();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef SDL_GPU
|
||||
void CVideo::update_overlay(SDL_Rect *rect)
|
||||
{
|
||||
sdl::timage img(overlay_);
|
||||
shader_.set_overlay(img);
|
||||
|
||||
// Re-render the appropriate screen area so that overlay change is visible
|
||||
static sdl::timage empty(image::get_texture("images/misc/blank.png"));
|
||||
SDL_Rect whole = sdl::create_rect(0, 0, overlay_->w, overlay_->h);
|
||||
SDL_Rect *r = rect == nullptr ? &whole : rect;
|
||||
empty.set_scale(float(r->w) / empty.base_width(), float(r->h) / empty.base_height());
|
||||
draw_texture(empty, r->x, r->y);
|
||||
}
|
||||
#endif
|
||||
|
||||
CVideo::~CVideo()
|
||||
{
|
||||
|
@ -297,61 +252,6 @@ void CVideo::blit_surface(int x, int y, surface surf, SDL_Rect* srcrect, SDL_Rec
|
|||
sdl_blit(surf,srcrect,target,&dst);
|
||||
}
|
||||
|
||||
#ifdef SDL_GPU
|
||||
GPU_Target *CVideo::render_target() const
|
||||
{
|
||||
return render_target_;
|
||||
}
|
||||
|
||||
void CVideo::draw_texture(sdl::timage &texture, int x, int y)
|
||||
{
|
||||
texture.draw(*this, x, y);
|
||||
}
|
||||
|
||||
void CVideo::set_texture_color_modulation(int r, int g, int b, int a)
|
||||
{
|
||||
shader_.set_color_mod(r, g, b, a);
|
||||
}
|
||||
|
||||
void CVideo::set_texture_submerge(float f)
|
||||
{
|
||||
shader_.set_submerge(f);
|
||||
}
|
||||
|
||||
void CVideo::set_texture_effects(int effects)
|
||||
{
|
||||
shader_.set_effects(effects);
|
||||
}
|
||||
|
||||
void CVideo::blit_to_overlay(surface surf, int x, int y)
|
||||
{
|
||||
if (x < 0 || y < 0 || x > overlay_->w || y > overlay_->h) {
|
||||
return;
|
||||
}
|
||||
SDL_Rect r = sdl::create_rect(x, y, surf->w, surf->h);
|
||||
SDL_BlitSurface(surf, nullptr, overlay_, &r);
|
||||
update_overlay(&r);
|
||||
}
|
||||
|
||||
void CVideo::clear_overlay_area(SDL_Rect area)
|
||||
{
|
||||
const Uint32 color = SDL_MapRGBA(overlay_->format, 0, 0, 0, 0);
|
||||
Uint32 *pixels = static_cast<Uint32*>(overlay_->pixels);
|
||||
for (int x = area.x; x<area.x + area.w; ++x) {
|
||||
for (int y = area.y; y<area.y +area.h; ++y) {
|
||||
const int index = y * (area.w + overlay_->pitch) + x;
|
||||
pixels[index] = color;
|
||||
}
|
||||
}
|
||||
update_overlay(&area);
|
||||
}
|
||||
|
||||
void CVideo::clear_overlay()
|
||||
{
|
||||
overlay_ = create_compatible_surface(overlay_, getx(), gety());
|
||||
update_overlay();
|
||||
}
|
||||
#endif
|
||||
|
||||
void CVideo::make_fake()
|
||||
{
|
||||
|
@ -472,20 +372,12 @@ bool CVideo::modeChanged()
|
|||
|
||||
int CVideo::getx() const
|
||||
{
|
||||
#ifdef SDL_GPU
|
||||
return GPU_GetContextTarget()->w;
|
||||
#else
|
||||
return frameBuffer->w;
|
||||
#endif
|
||||
}
|
||||
|
||||
int CVideo::gety() const
|
||||
{
|
||||
#ifdef SDL_GPU
|
||||
return GPU_GetContextTarget()->h;
|
||||
#else
|
||||
return frameBuffer->h;
|
||||
#endif
|
||||
}
|
||||
|
||||
void CVideo::delay(unsigned int milliseconds)
|
||||
|
@ -498,13 +390,8 @@ void CVideo::flip()
|
|||
{
|
||||
if(fake_screen_ || flip_locked_ > 0)
|
||||
return;
|
||||
#ifdef SDL_GPU
|
||||
assert(render_target_);
|
||||
GPU_Flip(render_target_);
|
||||
#else
|
||||
if (window)
|
||||
window->render();
|
||||
#endif
|
||||
}
|
||||
|
||||
void CVideo::lock_updates(bool value)
|
||||
|
|
|
@ -24,25 +24,12 @@
|
|||
#include "sdl/window.hpp"
|
||||
|
||||
class surface;
|
||||
#ifdef SDL_GPU
|
||||
#include "sdl/shader.hpp"
|
||||
#include "sdl/utils.hpp"
|
||||
|
||||
namespace sdl
|
||||
{
|
||||
class timage;
|
||||
}
|
||||
#endif
|
||||
|
||||
//possible flags when setting video modes
|
||||
#define SDL_APPMOUSEFOCUS 0x01 /**< The app has mouse coverage */
|
||||
#define SDL_APPINPUTFOCUS 0x02 /**< The app has input focus */
|
||||
#define SDL_APPACTIVE 0x04 /**< The application is active */
|
||||
|
||||
#ifdef SDL_GPU
|
||||
struct GPU_Target;
|
||||
GPU_Target *get_render_target();
|
||||
#endif
|
||||
|
||||
surface& get_video_surface();
|
||||
|
||||
|
@ -112,18 +99,6 @@ public:
|
|||
|
||||
//blits a surface with black as alpha
|
||||
void blit_surface(int x, int y, surface surf, SDL_Rect* srcrect=nullptr, SDL_Rect* clip_rect=nullptr);
|
||||
#ifdef SDL_GPU
|
||||
GPU_Target *render_target() const;
|
||||
|
||||
void draw_texture(sdl::timage &texture, int x, int y);
|
||||
void set_texture_color_modulation(int r, int g, int b, int a);
|
||||
void set_texture_submerge(float f);
|
||||
void set_texture_effects(int effects);
|
||||
|
||||
void blit_to_overlay(surface surf, int x, int y);
|
||||
void clear_overlay_area(SDL_Rect area);
|
||||
void clear_overlay();
|
||||
#endif
|
||||
void flip();
|
||||
static void delay(unsigned int milliseconds);
|
||||
|
||||
|
@ -225,12 +200,6 @@ private:
|
|||
};
|
||||
|
||||
void initSDL();
|
||||
#ifdef SDL_GPU
|
||||
void update_overlay(SDL_Rect *rect = nullptr);
|
||||
|
||||
sdl::shader_program shader_;
|
||||
surface overlay_;
|
||||
#endif
|
||||
|
||||
bool mode_changed_;
|
||||
|
||||
|
|
|
@ -198,24 +198,6 @@ void attack::draw_hex(const map_location& hex)
|
|||
std::string direction_text = map_location::write_direction(
|
||||
get_dest_hex().get_relative_dir(target_hex_));
|
||||
|
||||
#ifdef SDL_GPU
|
||||
if (hex == get_dest_hex()) //add symbol to attacker hex
|
||||
{
|
||||
int xpos = resources::screen->get_location_x(get_dest_hex());
|
||||
int ypos = resources::screen->get_location_y(get_dest_hex());
|
||||
|
||||
resources::screen->drawing_buffer_add(layer, get_dest_hex(), xpos, ypos,
|
||||
image::get_texture("whiteboard/attack-indicator-src-" + direction_text + ".png", image::SCALED_TO_HEX));
|
||||
}
|
||||
else if (hex == target_hex_) //add symbol to defender hex
|
||||
{
|
||||
int xpos = resources::screen->get_location_x(target_hex_);
|
||||
int ypos = resources::screen->get_location_y(target_hex_);
|
||||
|
||||
resources::screen->drawing_buffer_add(layer, target_hex_, xpos, ypos,
|
||||
image::get_texture("whiteboard/attack-indicator-dst-" + direction_text + ".png", image::SCALED_TO_HEX));
|
||||
}
|
||||
#else
|
||||
if (hex == get_dest_hex()) //add symbol to attacker hex
|
||||
{
|
||||
int xpos = resources::screen->get_location_x(get_dest_hex());
|
||||
|
@ -232,7 +214,6 @@ void attack::draw_hex(const map_location& hex)
|
|||
resources::screen->drawing_buffer_add(layer, target_hex_, xpos, ypos,
|
||||
image::get_image("whiteboard/attack-indicator-dst-" + direction_text + ".png", image::SCALED_TO_HEX));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -142,13 +142,8 @@ void suppose_dead::draw_hex(const map_location& hex)
|
|||
|
||||
int xpos = resources::screen->get_location_x(loc_);
|
||||
int ypos = resources::screen->get_location_y(loc_);
|
||||
#ifdef SDL_GPU
|
||||
resources::screen->drawing_buffer_add(layer, loc_, xpos, ypos,
|
||||
image::get_texture("whiteboard/suppose_dead.png", image::SCALED_TO_HEX));
|
||||
#else
|
||||
resources::screen->drawing_buffer_add(layer, loc_, xpos, ypos,
|
||||
image::get_image("whiteboard/suppose_dead.png", image::SCALED_TO_HEX));
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -48,17 +48,10 @@ button::button(CVideo& video, const std::string& label, button::TYPE type,
|
|||
std::string button_image_name, SPACE_CONSUMPTION spacing,
|
||||
const bool auto_join, std::string overlay_image)
|
||||
: widget(video, auto_join), type_(type),
|
||||
#ifdef SDL_GPU
|
||||
label_text_(label), label_image_(),
|
||||
image_(), pressedImage_(), activeImage_(), pressedActiveImage_(),
|
||||
disabledImage_(), pressedDisabledImage_(),
|
||||
overlayImage_(), overlayPressedImage_(), overlayActiveImage_(),
|
||||
#else
|
||||
label_text_(label),
|
||||
image_(nullptr), pressedImage_(nullptr), activeImage_(nullptr), pressedActiveImage_(nullptr),
|
||||
disabledImage_(nullptr), pressedDisabledImage_(nullptr),
|
||||
overlayImage_(nullptr), overlayPressedImage_(nullptr), overlayActiveImage_(nullptr),
|
||||
#endif
|
||||
state_(NORMAL), pressed_(false),
|
||||
spacing_(spacing), base_height_(0), base_width_(0),
|
||||
button_image_name_(), button_overlay_image_name_(overlay_image),
|
||||
|
@ -107,86 +100,6 @@ void button::load_images() {
|
|||
break;
|
||||
}
|
||||
|
||||
#ifdef SDL_GPU
|
||||
sdl::timage button_image(image::get_texture(button_image_name_ + ".png" + button_image_path_suffix_));
|
||||
sdl::timage pressed_image(image::get_texture(button_image_name_ + "-pressed.png"+ button_image_path_suffix_));
|
||||
sdl::timage active_image(image::get_texture(button_image_name_ + "-active.png"+ button_image_path_suffix_));
|
||||
sdl::timage disabled_image;
|
||||
if (filesystem::file_exists(game_config::path + "/images/" + button_image_name_ + "-disabled.png"))
|
||||
disabled_image = image::get_texture(button_image_name_ + "-disabled.png"+ button_image_path_suffix_);
|
||||
sdl::timage pressed_disabled_image, pressed_active_image, touched_image;
|
||||
|
||||
if (!button_overlay_image_name_.empty()) {
|
||||
overlayImage_ = image::get_texture(button_overlay_image_name_ + size_postfix + ".png"+ button_image_path_suffix_);
|
||||
overlayPressedImage_ = image::get_texture(button_overlay_image_name_ + size_postfix + "-pressed.png"+ button_image_path_suffix_);
|
||||
|
||||
if (filesystem::file_exists(game_config::path + "/images/" + button_overlay_image_name_ + size_postfix + "-active.png"))
|
||||
overlayActiveImage_ = image::get_texture(button_overlay_image_name_ + size_postfix + "-active.png"+ button_image_path_suffix_);
|
||||
|
||||
if (filesystem::file_exists(game_config::path + "/images/" + button_overlay_image_name_ + size_postfix + "-disabled.png"))
|
||||
overlayDisabledImage_ = image::get_texture(button_overlay_image_name_ + size_postfix + "-disabled.png"+ button_image_path_suffix_);
|
||||
if (overlayDisabledImage_.null())
|
||||
overlayDisabledImage_ = image::get_texture(button_overlay_image_name_ + size_postfix + ".png~GS()" + button_image_path_suffix_);
|
||||
|
||||
if (filesystem::file_exists(game_config::path + "/images/" + button_overlay_image_name_ + size_postfix + "-disabled-pressed.png"))
|
||||
overlayPressedDisabledImage_ = image::get_texture(button_overlay_image_name_ + size_postfix + "-disabled-pressed.png");
|
||||
if (overlayPressedDisabledImage_.null())
|
||||
overlayPressedDisabledImage_ = image::get_texture(button_overlay_image_name_ + size_postfix + "-pressed.png~GS()"+ button_image_path_suffix_);
|
||||
} else {
|
||||
overlayImage_ = sdl::timage();
|
||||
}
|
||||
|
||||
if (disabled_image.null()) {
|
||||
disabled_image = image::get_texture(button_image_name_ + ".png~GS()" + button_image_path_suffix_);
|
||||
}
|
||||
|
||||
if (pressed_image.null())
|
||||
pressed_image = button_image;
|
||||
|
||||
if (active_image.null())
|
||||
active_image = button_image;
|
||||
|
||||
if (type_ == TYPE_CHECK || type_ == TYPE_RADIO) {
|
||||
touched_image = image::get_texture(button_image_name_ + "-touched.png"+ button_image_path_suffix_);
|
||||
if (touched_image.null())
|
||||
touched_image = pressed_image;
|
||||
|
||||
pressed_active_image = (image::get_texture(button_image_name_ + "-active-pressed.png"+ button_image_path_suffix_));
|
||||
if (pressed_active_image.null())
|
||||
pressed_active_image = pressed_image;
|
||||
|
||||
if (filesystem::file_exists(game_config::path + "/images/" + button_image_name_ + size_postfix + "-disabled-pressed.png"))
|
||||
pressed_disabled_image = image::get_texture(button_image_name_ + "-disabled-pressed.png"+ button_image_path_suffix_);
|
||||
if (pressed_disabled_image.null())
|
||||
pressed_disabled_image = image::get_texture(button_image_name_ + "-pressed.png~GS()"+ button_image_path_suffix_);
|
||||
}
|
||||
|
||||
if (button_image.null()) {
|
||||
ERR_DP << "error initializing button!" << std::endl;
|
||||
throw error();
|
||||
}
|
||||
|
||||
base_height_ = button_image.height();
|
||||
base_width_ = button_image.width();
|
||||
|
||||
if (type_ != TYPE_IMAGE) {
|
||||
set_label(label_text_);
|
||||
}
|
||||
|
||||
image_ = button_image;
|
||||
pressedImage_ = pressed_image;
|
||||
activeImage_ = active_image;
|
||||
disabledImage_ = disabled_image;
|
||||
if (type_ == TYPE_CHECK || type_ == TYPE_RADIO) {
|
||||
pressedDisabledImage_ = pressed_disabled_image;
|
||||
pressedActiveImage_ = pressed_active_image;
|
||||
touchedImage_ = touched_image;
|
||||
}
|
||||
|
||||
if (type_ == TYPE_IMAGE){
|
||||
calculate_size();
|
||||
}
|
||||
#else
|
||||
surface button_image(image::get_image(button_image_name_ + ".png" + button_image_path_suffix_));
|
||||
surface pressed_image(image::get_image(button_image_name_ + "-pressed.png"+ button_image_path_suffix_));
|
||||
surface active_image(image::get_image(button_image_name_ + "-active.png"+ button_image_path_suffix_));
|
||||
|
@ -281,7 +194,6 @@ void button::load_images() {
|
|||
if (type_ == TYPE_IMAGE){
|
||||
calculate_size();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
button::~button()
|
||||
|
@ -292,13 +204,8 @@ void button::calculate_size()
|
|||
{
|
||||
if (type_ == TYPE_IMAGE){
|
||||
SDL_Rect loc_image = location();
|
||||
#ifdef SDL_GPU
|
||||
loc_image.h = image_.height();
|
||||
loc_image.w = image_.width();
|
||||
#else
|
||||
loc_image.h = image_->h;
|
||||
loc_image.w = image_->w;
|
||||
#endif
|
||||
set_location(loc_image);
|
||||
return;
|
||||
}
|
||||
|
@ -398,92 +305,6 @@ void button::enable(bool new_val)
|
|||
|
||||
void button::draw_contents()
|
||||
{
|
||||
#ifdef SDL_GPU
|
||||
sdl::timage image = image_;
|
||||
const int image_w = image_.width();
|
||||
|
||||
int offset = 0;
|
||||
switch(state_) {
|
||||
case ACTIVE:
|
||||
image = activeImage_;
|
||||
break;
|
||||
case PRESSED:
|
||||
image = pressedImage_;
|
||||
if (type_ == TYPE_PRESS)
|
||||
offset = 1;
|
||||
break;
|
||||
case PRESSED_ACTIVE:
|
||||
image = pressedActiveImage_;
|
||||
break;
|
||||
case TOUCHED_NORMAL:
|
||||
case TOUCHED_PRESSED:
|
||||
image = touchedImage_;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
SDL_Rect const &loc = location();
|
||||
SDL_Rect clipArea = loc;
|
||||
const int texty = loc.y + loc.h / 2 - textRect_.h / 2 + offset;
|
||||
int textx;
|
||||
|
||||
if (type_ != TYPE_CHECK && type_ != TYPE_RADIO && type_ != TYPE_IMAGE)
|
||||
textx = loc.x + image.width() / 2 - textRect_.w / 2 + offset;
|
||||
else {
|
||||
clipArea.w += image_w + checkbox_horizontal_padding;
|
||||
textx = loc.x + image_w + checkbox_horizontal_padding / 2;
|
||||
}
|
||||
|
||||
SDL_Color button_color = font::BUTTON_COLOR;
|
||||
|
||||
if (!enabled()) {
|
||||
|
||||
if (state_ == PRESSED || state_ == PRESSED_ACTIVE)
|
||||
image = pressedDisabledImage_;
|
||||
else image = disabledImage_;
|
||||
|
||||
button_color = font::GRAY_COLOR;
|
||||
}
|
||||
|
||||
sdl::timage overlay;
|
||||
if (!overlayImage_.null()) {
|
||||
|
||||
overlay = enabled() ? overlayImage_ : overlayDisabledImage_;
|
||||
|
||||
if (!overlayPressedImage_.null()) {
|
||||
switch (state_) {
|
||||
case ACTIVE:
|
||||
if (!overlayActiveImage_.null())
|
||||
overlay = overlayActiveImage_;
|
||||
break;
|
||||
case PRESSED:
|
||||
case PRESSED_ACTIVE:
|
||||
case TOUCHED_NORMAL:
|
||||
case TOUCHED_PRESSED:
|
||||
overlay = enabled() ? overlayPressedImage_ : overlayPressedDisabledImage_;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
image.set_scale(float(loc.w) / image.width(), float(loc.h) / image.height());
|
||||
overlay.set_scale(float(loc.w) / overlay.width(), float(loc.h) / image.height());
|
||||
|
||||
video().draw_texture(image, loc.x, loc.y);
|
||||
video().draw_texture(overlay, loc.x, loc.y);
|
||||
if (type_ != TYPE_IMAGE){
|
||||
clipArea.x += offset;
|
||||
clipArea.y += offset;
|
||||
clipArea.w -= 2*offset;
|
||||
clipArea.h -= 2*offset;
|
||||
// label_image_.set_clip(clipArea);
|
||||
video().draw_texture(label_image_, textx, texty);
|
||||
}
|
||||
#else
|
||||
surface image = image_;
|
||||
const int image_w = image_->w;
|
||||
|
||||
|
@ -569,7 +390,6 @@ void button::draw_contents()
|
|||
}
|
||||
|
||||
update_rect(loc);
|
||||
#endif
|
||||
}
|
||||
|
||||
bool button::hit(int x, int y) const
|
||||
|
@ -615,11 +435,6 @@ void button::set_label(const std::string& val)
|
|||
}
|
||||
|
||||
calculate_size();
|
||||
#ifdef SDL_GPU
|
||||
font::ttext text;
|
||||
text.set_text(label_text_, false);
|
||||
label_image_ = text.render_as_texture();
|
||||
#endif
|
||||
|
||||
set_dirty(true);
|
||||
}
|
||||
|
|
|
@ -18,9 +18,6 @@
|
|||
|
||||
#include "exceptions.hpp"
|
||||
|
||||
#ifdef SDL_GPU
|
||||
#include "sdl/image.hpp"
|
||||
#endif
|
||||
|
||||
namespace gui {
|
||||
|
||||
|
@ -75,18 +72,10 @@ private:
|
|||
|
||||
std::string label_text_;
|
||||
|
||||
#ifdef SDL_GPU
|
||||
sdl::timage label_image_;
|
||||
sdl::timage image_, pressedImage_, activeImage_, pressedActiveImage_,
|
||||
touchedImage_, disabledImage_, pressedDisabledImage_,
|
||||
overlayImage_, overlayPressedImage_, overlayPressedDisabledImage_, overlayDisabledImage_,
|
||||
overlayActiveImage_;
|
||||
#else
|
||||
surface image_, pressedImage_, activeImage_, pressedActiveImage_,
|
||||
touchedImage_, disabledImage_, pressedDisabledImage_,
|
||||
overlayImage_, overlayPressedImage_, overlayPressedDisabledImage_, overlayDisabledImage_,
|
||||
overlayActiveImage_;
|
||||
#endif
|
||||
SDL_Rect textRect_;
|
||||
|
||||
enum STATE { UNINIT, NORMAL, ACTIVE, PRESSED, PRESSED_ACTIVE, TOUCHED_NORMAL, TOUCHED_PRESSED };
|
||||
|
|
|
@ -25,11 +25,7 @@ namespace gui {
|
|||
|
||||
label::label(CVideo& video, const std::string& text, int size, const SDL_Color& color, const bool auto_join) : widget(video, auto_join), text_(text), size_(size), color_(color)
|
||||
{
|
||||
#ifdef SDL_GPU
|
||||
render_text();
|
||||
#else
|
||||
update_label_size();
|
||||
#endif
|
||||
}
|
||||
|
||||
const std::string& label::set_text(const std::string& text)
|
||||
|
@ -38,11 +34,7 @@ const std::string& label::set_text(const std::string& text)
|
|||
return text_;
|
||||
|
||||
text_ = text;
|
||||
#ifdef SDL_GPU
|
||||
render_text();
|
||||
#else
|
||||
update_label_size();
|
||||
#endif
|
||||
set_dirty();
|
||||
return text_;
|
||||
}
|
||||
|
@ -55,9 +47,6 @@ const std::string& label::get_text() const
|
|||
const SDL_Color& label::set_color(const SDL_Color& color)
|
||||
{
|
||||
color_ = color;
|
||||
#ifdef SDL_GPU
|
||||
render_text();
|
||||
#endif
|
||||
set_dirty();
|
||||
return get_color();
|
||||
}
|
||||
|
@ -71,11 +60,7 @@ void label::draw_contents()
|
|||
{
|
||||
const SDL_Rect& loc = location();
|
||||
if (!text_.empty() && loc.w > 0 && loc.h > 0)
|
||||
#ifdef SDL_GPU
|
||||
video().draw_texture(text_image_, loc.x, loc.y);
|
||||
#else
|
||||
font::draw_text(&video(), loc, size_, get_color(), text_, loc.x, loc.y);
|
||||
#endif
|
||||
}
|
||||
|
||||
void label::update_label_size()
|
||||
|
@ -84,20 +69,6 @@ void label::update_label_size()
|
|||
set_measurements(area.w, area.h);
|
||||
}
|
||||
|
||||
#ifdef SDL_GPU
|
||||
void label::render_text()
|
||||
{
|
||||
font::ttext txt;
|
||||
|
||||
txt.set_text(text_, true);
|
||||
const Uint32 color = (color_.r << 16) + (color_.g << 16) + (color_.b);
|
||||
txt.set_foreground_color(color);
|
||||
txt.set_font_size(size_);
|
||||
|
||||
text_image_ = txt.render_as_texture();
|
||||
set_measurements(text_image_.width(), text_image_.height());
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -36,11 +36,6 @@ public:
|
|||
virtual void draw_contents();
|
||||
private:
|
||||
void update_label_size();
|
||||
#ifdef SDL_GPU
|
||||
void render_text();
|
||||
|
||||
sdl::timage text_image_;
|
||||
#endif
|
||||
std::string text_;
|
||||
int size_;
|
||||
SDL_Color color_;
|
||||
|
|
|
@ -810,16 +810,6 @@ SDL_Rect menu::style::item_size(const std::string& item) const {
|
|||
res.w += 5;
|
||||
}
|
||||
const std::string str = *it;
|
||||
#ifdef SDL_GPU
|
||||
if (!str.empty() && str[0] == IMAGE_PREFIX) {
|
||||
const std::string image_name(str.begin()+1,str.end());
|
||||
sdl::timage img = get_item_image(image_name);
|
||||
if(!img.null()) {
|
||||
res.w += img.width();
|
||||
res.h = std::max<int>(img.height(), res.h);
|
||||
}
|
||||
}
|
||||
#else
|
||||
if (!str.empty() && str[0] == IMAGE_PREFIX) {
|
||||
const std::string image_name(str.begin()+1,str.end());
|
||||
surface const img = get_item_image(image_name);
|
||||
|
@ -828,7 +818,6 @@ SDL_Rect menu::style::item_size(const std::string& item) const {
|
|||
res.h = std::max<int>(img->h, res.h);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
else {
|
||||
const SDL_Rect area = {0,0,10000,10000};
|
||||
const SDL_Rect font_size =
|
||||
|
@ -862,17 +851,9 @@ void menu::style::draw_row_bg(menu& menu_ref, const size_t /*row_index*/, const
|
|||
break;
|
||||
}
|
||||
|
||||
#ifdef SDL_GPU
|
||||
sdl::draw_solid_tinted_rectangle(rect.x, rect.y, rect.w, rect.h,
|
||||
(rgb&0xff0000) >> 16,(rgb&0xff00) >> 8,rgb&0xff,alpha,
|
||||
menu_ref.video().getSurface());
|
||||
sdl::fill_rect(menu_ref.video(), rect, (rgb&0xff0000) >> 16,
|
||||
(rgb&0xff00) >> 8, rgb&0xff, alpha);
|
||||
#else
|
||||
sdl::draw_solid_tinted_rectangle(rect.x, rect.y, rect.w, rect.h,
|
||||
(rgb&0xff0000) >> 16,(rgb&0xff00) >> 8,rgb&0xff,alpha,
|
||||
menu_ref.video().getSurface());
|
||||
#endif
|
||||
}
|
||||
|
||||
void menu::style::draw_row(menu& menu_ref, const size_t row_index, const SDL_Rect& rect, ROW_TYPE type)
|
||||
|
@ -954,78 +935,6 @@ void menu::draw_row(const size_t row_index, const SDL_Rect& rect, ROW_TYPE type)
|
|||
if(lang_rtl)
|
||||
xpos -= widths[i];
|
||||
if(type == HEADING_ROW) {
|
||||
#ifdef SDL_GPU
|
||||
const SDL_Rect pos = sdl::create_rect(xpos, rect.y, widths[i], rect.h);
|
||||
if(highlight_heading_ == int(i)) {
|
||||
sdl::fill_rect(video(), pos, 255, 255, 255, 75);
|
||||
} else if(sortby_ == int(i)) {
|
||||
sdl::fill_rect(video(), pos, 255, 255, 255, 25);
|
||||
}
|
||||
}
|
||||
|
||||
const int last_x = xpos;
|
||||
column.w = widths[i];
|
||||
std::string str = row[i];
|
||||
std::vector<std::string> img_text_items = utils::split(str, IMG_TEXT_SEPARATOR, utils::REMOVE_EMPTY);
|
||||
for (std::vector<std::string>::const_iterator it = img_text_items.begin();
|
||||
it != img_text_items.end(); ++it) {
|
||||
str = *it;
|
||||
if (!str.empty() && str[0] == IMAGE_PREFIX) {
|
||||
const std::string image_name(str.begin()+1,str.end());
|
||||
sdl::timage img = style_->get_item_image(image_name);
|
||||
const int remaining_width = max_width_ < 0 ? area.w :
|
||||
std::min<int>(max_width_, ((lang_rtl)? xpos - rect.x : rect.x + rect.w - xpos));
|
||||
if(!img.null() && img.width() <= remaining_width
|
||||
&& rect.y + img.height() < area.h) {
|
||||
const size_t y = rect.y + (rect.h - img.height())/2;
|
||||
const size_t w = img.width() + 5;
|
||||
const size_t x = xpos + ((lang_rtl) ? widths[i] - w : 0);
|
||||
video().draw_texture(img, x, y);
|
||||
if(!lang_rtl)
|
||||
xpos += w;
|
||||
column.w -= w;
|
||||
}
|
||||
} else {
|
||||
column.x = xpos;
|
||||
const bool has_wrap = (str.find_first_of("\r\n") != std::string::npos);
|
||||
//prevent ellipsis calculation if there is any line wrapping
|
||||
std::string to_show = str;
|
||||
if (use_ellipsis_ && !has_wrap)
|
||||
{
|
||||
int fs = style_->get_font_size();
|
||||
int style = TTF_STYLE_NORMAL;
|
||||
int w = loc.w - (xpos - rect.x) - 2 * style_->get_thickness();
|
||||
std::string::const_iterator i_beg = to_show.begin(), i_end = to_show.end(),
|
||||
i = font::parse_markup(i_beg, i_end, &fs, nullptr, &style);
|
||||
if (i != i_end) {
|
||||
std::string tmp(i, i_end);
|
||||
to_show.erase(i - i_beg, i_end - i_beg);
|
||||
to_show += font::make_text_ellipsis(tmp, fs, w, style);
|
||||
}
|
||||
}
|
||||
const SDL_Rect& text_size = font::text_area(str,style_->get_font_size());
|
||||
const size_t y = rect.y + (rect.h - text_size.h)/2;
|
||||
const size_t padding = 2;
|
||||
sdl::timage text_img = font::draw_text_to_texture(column,style_->get_font_size(),font::NORMAL_COLOR,to_show);
|
||||
video().draw_texture(text_img, (type == HEADING_ROW ? xpos+padding : xpos), y);
|
||||
if(type == HEADING_ROW && sortby_ == int(i)) {
|
||||
sdl::timage sort_img = image::get_texture("buttons/sliders/slider_arrow_blue.png");
|
||||
sort_img.set_rotation(sortreversed_ ? 0 : 180);
|
||||
if(!sort_img.null() && sort_img.width() <= widths[i] && sort_img.height() <= rect.h) {
|
||||
const size_t sort_x = xpos + widths[i] - sort_img.width() - padding;
|
||||
const size_t sort_y = rect.y + rect.h/2 - sort_img.height()/2;
|
||||
video().draw_texture(sort_img, sort_x, sort_y);
|
||||
}
|
||||
}
|
||||
xpos += dir * (text_size.w + 5);
|
||||
}
|
||||
}
|
||||
if(lang_rtl)
|
||||
xpos = last_x;
|
||||
else
|
||||
xpos = last_x + widths[i];
|
||||
}
|
||||
#else
|
||||
if(highlight_heading_ == int(i)) {
|
||||
sdl::draw_solid_tinted_rectangle(xpos,rect.y,widths[i],rect.h,255,255,255,0.3,video().getSurface());
|
||||
} else if(sortby_ == int(i)) {
|
||||
|
@ -1097,7 +1006,6 @@ void menu::draw_row(const size_t row_index, const SDL_Rect& rect, ROW_TYPE type)
|
|||
else
|
||||
xpos = last_x + widths[i];
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void menu::draw_contents()
|
||||
|
|
|
@ -42,11 +42,7 @@ public:
|
|||
virtual void draw_row_bg(menu& menu_ref, const size_t row_index, const SDL_Rect& rect, ROW_TYPE type);
|
||||
virtual void draw_row(menu& menu_ref, const size_t row_index, const SDL_Rect& rect, ROW_TYPE type);
|
||||
void scale_images(int max_width, int max_height);
|
||||
#ifdef SDL_GPU
|
||||
sdl::timage get_item_image(const image::locator &i_locator) const;
|
||||
#else
|
||||
surface get_item_image(const image::locator &i_locator) const;
|
||||
#endif
|
||||
size_t get_font_size() const;
|
||||
size_t get_cell_padding() const;
|
||||
size_t get_thickness() const;
|
||||
|
@ -57,11 +53,7 @@ public:
|
|||
size_t thickness_; //additional cell padding for style use only
|
||||
|
||||
int normal_rgb_, selected_rgb_, heading_rgb_;
|
||||
#ifdef SDL_GPU
|
||||
int normal_alpha_, selected_alpha_, heading_alpha_;
|
||||
#else
|
||||
double normal_alpha_, selected_alpha_, heading_alpha_;
|
||||
#endif
|
||||
int max_img_w_, max_img_h_;
|
||||
};
|
||||
|
||||
|
@ -83,11 +75,7 @@ public:
|
|||
|
||||
protected:
|
||||
const std::string img_base_;
|
||||
#ifdef SDL_GPU
|
||||
std::map<std::string, sdl::timage> img_map_;
|
||||
#else
|
||||
std::map<std::string,surface> img_map_;
|
||||
#endif
|
||||
|
||||
private:
|
||||
bool load_image(const std::string &img_sub);
|
||||
|
@ -96,9 +84,6 @@ public:
|
|||
bool load_failed_;
|
||||
int normal_rgb2_, selected_rgb2_, heading_rgb2_;
|
||||
double normal_alpha2_, selected_alpha2_, heading_alpha2_;
|
||||
#ifdef SDL_GPU
|
||||
sdl::timage background_image_;
|
||||
#endif
|
||||
//FIXME: why is this better than a plain surface?
|
||||
struct bg_cache
|
||||
{
|
||||
|
|
|
@ -37,11 +37,7 @@ menu::style &menu::default_style = menu::bluebg_style;
|
|||
menu::style::style() : font_size_(font::SIZE_NORMAL),
|
||||
cell_padding_(font::SIZE_NORMAL * 3/5), thickness_(0),
|
||||
normal_rgb_(0x000000), selected_rgb_(0x000099), heading_rgb_(0x333333),
|
||||
#ifdef SDL_GPU
|
||||
normal_alpha_(50), selected_alpha_(150), heading_alpha_(75),
|
||||
#else
|
||||
normal_alpha_(0.2), selected_alpha_(0.6), heading_alpha_(0.3),
|
||||
#endif
|
||||
max_img_w_(-1), max_img_h_(-1)
|
||||
{}
|
||||
|
||||
|
@ -67,28 +63,6 @@ void menu::style::scale_images(int max_width, int max_height)
|
|||
max_img_h_ = max_height;
|
||||
}
|
||||
|
||||
#ifdef SDL_GPU
|
||||
sdl::timage menu::style::get_item_image(const image::locator& img_loc) const
|
||||
{
|
||||
sdl::timage img = image::get_texture(img_loc);
|
||||
if(!img.null())
|
||||
{
|
||||
int scale = 100;
|
||||
if(max_img_w_ > 0 && img.width() > max_img_w_) {
|
||||
scale = (max_img_w_ * 100) / img.width();
|
||||
}
|
||||
if(max_img_h_ > 0 && img.height() > max_img_h_) {
|
||||
scale = std::min<int>(scale, ((max_img_h_ * 100) / img.height()));
|
||||
}
|
||||
if(scale != 100)
|
||||
{
|
||||
img.set_scale(scale, scale);
|
||||
return img;
|
||||
}
|
||||
}
|
||||
return img;
|
||||
}
|
||||
#else
|
||||
surface menu::style::get_item_image(const image::locator& img_loc) const
|
||||
{
|
||||
surface surf = image::get_image(img_loc);
|
||||
|
@ -108,21 +82,13 @@ surface menu::style::get_item_image(const image::locator& img_loc) const
|
|||
}
|
||||
return surf;
|
||||
}
|
||||
#endif
|
||||
|
||||
bool menu::imgsel_style::load_image(const std::string &img_sub)
|
||||
{
|
||||
#ifdef SDL_GPU
|
||||
std::string path = img_base_ + "-" + img_sub + ".png";
|
||||
sdl::timage image = image::get_image(path);
|
||||
img_map_[img_sub] = image;
|
||||
return(!image.null());
|
||||
#else
|
||||
std::string path = img_base_ + "-" + img_sub + ".png";
|
||||
const surface image = image::get_image(path);
|
||||
img_map_[img_sub] = image;
|
||||
return(!image.null());
|
||||
#endif
|
||||
}
|
||||
|
||||
bool menu::imgsel_style::load_images()
|
||||
|
@ -139,15 +105,9 @@ bool menu::imgsel_style::load_images()
|
|||
&& load_image("border-top")
|
||||
&& load_image("border-bottom") )
|
||||
{
|
||||
#ifdef SDL_GPU
|
||||
thickness_ = std::min(
|
||||
img_map_["border-top"].height(),
|
||||
img_map_["border-left"].width());
|
||||
#else
|
||||
thickness_ = std::min(
|
||||
img_map_["border-top"]->h,
|
||||
img_map_["border-left"]->w);
|
||||
#endif
|
||||
|
||||
|
||||
if(has_background_ && !load_image("background"))
|
||||
|
@ -179,13 +139,6 @@ bool menu::imgsel_style::load_images()
|
|||
|
||||
void menu::imgsel_style::draw_row_bg(menu& menu_ref, const size_t row_index, const SDL_Rect& rect, ROW_TYPE type)
|
||||
{
|
||||
#ifdef SDL_GPU
|
||||
if(type == SELECTED_ROW && has_background_ && !load_failed_) {
|
||||
background_image_.set_scale(float(rect.w) / background_image_.width(),
|
||||
float(rect.h) / background_image_.height());
|
||||
menu_ref.video().draw_texture(background_image_, rect.x, rect.y);
|
||||
}
|
||||
#else
|
||||
if(type == SELECTED_ROW && has_background_ && !load_failed_) {
|
||||
if(bg_cache_.width != rect.w || bg_cache_.height != rect.h)
|
||||
{
|
||||
|
@ -198,7 +151,6 @@ void menu::imgsel_style::draw_row_bg(menu& menu_ref, const size_t row_index, con
|
|||
SDL_Rect clip = rect;
|
||||
menu_ref.video().blit_surface(rect.x,rect.y,bg_cache_.surf,nullptr,&clip);
|
||||
}
|
||||
#endif
|
||||
else {
|
||||
style::draw_row_bg(menu_ref, row_index, rect, type);
|
||||
}
|
||||
|
@ -210,72 +162,6 @@ void menu::imgsel_style::draw_row(menu& menu_ref, const size_t row_index, const
|
|||
//draw item inside
|
||||
style::draw_row(menu_ref, row_index, rect, type);
|
||||
|
||||
#ifdef SDL_GPU
|
||||
if(type == SELECTED_ROW) {
|
||||
// draw border
|
||||
sdl::timage image;
|
||||
SDL_Rect area;
|
||||
area.x = rect.x;
|
||||
area.y = rect.y;
|
||||
|
||||
GPU_SetClip(get_render_target(), rect.x, rect.y, rect.w, rect.h);
|
||||
|
||||
image = img_map_["border-top"];
|
||||
area.x = rect.x;
|
||||
area.y = rect.y;
|
||||
do {
|
||||
menu_ref.video().draw_texture(image, area.x, area.y);
|
||||
area.x += image.width();
|
||||
} while( area.x < rect.x + rect.w );
|
||||
|
||||
image = img_map_["border-left"];
|
||||
area.x = rect.x;
|
||||
area.y = rect.y;
|
||||
do {
|
||||
menu_ref.video().draw_texture(image, area.x, area.y);
|
||||
area.y += image.height();
|
||||
} while( area.y < rect.y + rect.h );
|
||||
|
||||
image = img_map_["border-right"];
|
||||
area.x = rect.x + rect.w - thickness_;
|
||||
area.y = rect.y;
|
||||
do {
|
||||
menu_ref.video().draw_texture(image, area.x, area.y);
|
||||
area.y += image.height();
|
||||
} while( area.y < rect.y + rect.h );
|
||||
|
||||
image = img_map_["border-bottom"];
|
||||
area.x = rect.x;
|
||||
area.y = rect.y + rect.h - thickness_;
|
||||
do {
|
||||
menu_ref.video().draw_texture(image, area.x, area.y);
|
||||
area.x += image.width();
|
||||
} while( area.x < rect.x + rect.w );
|
||||
|
||||
image = img_map_["border-topleft"];
|
||||
area.x = rect.x;
|
||||
area.y = rect.y;
|
||||
menu_ref.video().draw_texture(image, area.x, area.y);
|
||||
|
||||
image = img_map_["border-topright"];
|
||||
area.x = rect.x + rect.w - image.width();
|
||||
area.y = rect.y;
|
||||
menu_ref.video().draw_texture(image, area.x, area.y);
|
||||
|
||||
image = img_map_["border-botleft"];
|
||||
area.x = rect.x;
|
||||
area.y = rect.y + rect.h - image.height();
|
||||
menu_ref.video().draw_texture(image, area.x, area.y);
|
||||
|
||||
image = img_map_["border-botright"];
|
||||
area.x = rect.x + rect.w - image.width();
|
||||
area.y = rect.y + rect.h - image.height();
|
||||
menu_ref.video().draw_texture(image, area.x, area.y);
|
||||
|
||||
GPU_UnsetClip(get_render_target());
|
||||
}
|
||||
}
|
||||
#else
|
||||
if(type == SELECTED_ROW) {
|
||||
// draw border
|
||||
surface image;
|
||||
|
@ -337,7 +223,6 @@ void menu::imgsel_style::draw_row(menu& menu_ref, const size_t row_index, const
|
|||
menu_ref.video().blit_surface(area.x,area.y,image);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
else {
|
||||
//default drawing
|
||||
style::draw_row(menu_ref, row_index, rect, type);
|
||||
|
|
Loading…
Add table
Reference in a new issue