Initial commit
This commit is contained in:
BIN
Bin/x86-64/libZNet.a
Normal file
BIN
Bin/x86-64/libZNet.a
Normal file
Binary file not shown.
BIN
Bin/x86-64/libZUtil.a
Normal file
BIN
Bin/x86-64/libZUtil.a
Normal file
Binary file not shown.
BIN
Bin/x86-64/libsst-net.a
Normal file
BIN
Bin/x86-64/libsst-net.a
Normal file
Binary file not shown.
22
BuildConfig/Darwin-Libs.rules
Normal file
22
BuildConfig/Darwin-Libs.rules
Normal file
@@ -0,0 +1,22 @@
|
||||
# BuildConfig/POSIX-Libs.rules
|
||||
# Author: Patrick Baggett <ptbaggett@762studios.com>
|
||||
# Created: 3/19/2012
|
||||
#
|
||||
# Purpose:
|
||||
#
|
||||
# Defines common libraries required for linking on POSIX platforms
|
||||
#
|
||||
# License:
|
||||
#
|
||||
# This program is free software. It comes without any warranty, to
|
||||
# the extent permitted by applicable law. You can redistribute it
|
||||
# and/or modify it under the terms of the Do What The Fuck You Want
|
||||
# To Public License, Version 2, as published by Sam Hocevar. See
|
||||
# http://sam.zoy.org/wtfpl/COPYING for more details.
|
||||
|
||||
# Base libraries (console)
|
||||
export ZENGINE_BASE_LIBS = -lpthread -lm
|
||||
|
||||
# GUI libraries (X Windows)
|
||||
export ZENGINE_GUI_LIBS = -lGL -lX11
|
||||
|
||||
48
BuildConfig/DetectCompiler.rules
Normal file
48
BuildConfig/DetectCompiler.rules
Normal file
@@ -0,0 +1,48 @@
|
||||
# BuildConfig/DetectCompiler.rules
|
||||
# Author: Patrick Baggett <ptbaggett@762studios.com>
|
||||
# Created: 4/3/2012
|
||||
#
|
||||
# Purpose:
|
||||
#
|
||||
# Check for common compilers and sets flags for them
|
||||
#
|
||||
# License:
|
||||
#
|
||||
# This program is free software. It comes without any warranty, to
|
||||
# the extent permitted by applicable law. You can redistribute it
|
||||
# and/or modify it under the terms of the Do What The Fuck You Want
|
||||
# To Public License, Version 2, as published by Sam Hocevar. See
|
||||
# http://sam.zoy.org/wtfpl/COPYING for more details.
|
||||
|
||||
# =================
|
||||
# Detect "gcc"
|
||||
# =================
|
||||
CC := $(shell which $(CC))
|
||||
|
||||
#Check if $CC filename has "gcc" in it, but don't be fooled if path has "gcc"
|
||||
ifeq ($(findstring gcc,$(notdir $(realpath $(CC)))),gcc)
|
||||
IS_GCC := 1
|
||||
else
|
||||
IS_GCC := 0
|
||||
endif
|
||||
|
||||
# =================
|
||||
# Detect "icc"
|
||||
# =================
|
||||
#Check if $CC filename has "icc" in it, but don't be fooled if path has "icc"
|
||||
ifeq ($(findstring icc,$(notdir $(realpath $(CC)))),icc)
|
||||
IS_ICC := 1
|
||||
else
|
||||
IS_ICC := 0
|
||||
endif
|
||||
|
||||
# =================
|
||||
# Detect plain "cc"
|
||||
# =================
|
||||
#Check if $CC filename /is/ "cc", but don't be fooled if path has "cc"
|
||||
ifeq ($(notdir $(realpath $(CC))),cc)
|
||||
IS_CC := 1
|
||||
else
|
||||
IS_CC := 0
|
||||
endif
|
||||
|
||||
36
BuildConfig/DetectLibs.rules
Normal file
36
BuildConfig/DetectLibs.rules
Normal file
@@ -0,0 +1,36 @@
|
||||
# BuildConfig/DetectLibs.rules
|
||||
# Author: Patrick Baggett <ptbaggett@762studios.com>
|
||||
# Created: 4/24/2014
|
||||
#
|
||||
# Purpose:
|
||||
#
|
||||
# Detects presence of libraries
|
||||
#
|
||||
# License:
|
||||
#
|
||||
# This program is free software. It comes without any warranty, to
|
||||
# the extent permitted by applicable law. You can redistribute it
|
||||
# and/or modify it under the terms of the Do What The Fuck You Want
|
||||
# To Public License, Version 2, as published by Sam Hocevar. See
|
||||
# http://sam.zoy.org/wtfpl/COPYING for more details.
|
||||
|
||||
# There is no reason for us to do this here - the reason being is that automatic detection with no alternative is simply a waste of time.
|
||||
# It's better to have individual makefiles that you include for system stacks. Compiler detection and bifurcation is really solid - the auto
|
||||
# detection is best left to full fledged build tools - since that's literally what auto-tools does.
|
||||
#
|
||||
# Use this file as as temp file
|
||||
TEMPFILE := $(shell mktemp 2>/dev/null || mktemp -t 'mytmpdir')
|
||||
|
||||
#Detect a library, called as: $(call detectLib,file.h,HAVE_FILE_H)
|
||||
detectLib = $(shell echo "\#include $(1)" > $(TEMPFILE); $(CC) -E $(TEMPFILE) >/dev/null 2>&1; if [ $$? -eq 0 ]; then echo "-D$(2)"; else echo ""; fi)
|
||||
|
||||
DETECTED_LIBS :=
|
||||
DETECTED_LIBS += $(call detectLib,<X11/Xlib.h>,HAVE_XLIB)
|
||||
DETECTED_LIBS += $(call detectLib,<X11/extensions/XInput2.h>,HAVE_XINPUT2)
|
||||
DETECTED_LIBS += $(call detectLib,<wayland-client.h>,HAVE_WAYLAND)
|
||||
DETECTED_LIBS += $(call detectLib,<EGL/egl.h>,HAVE_EGL)
|
||||
|
||||
FORCE_REMOVE := $(shell rm $(TEMPFILE))
|
||||
|
||||
OS_CXXFLAGS += $(DETECTED_LIBS)
|
||||
OS_CFLAGS += $(DETECTED_LIBS)
|
||||
84
BuildConfig/DetectPlatform.rules
Normal file
84
BuildConfig/DetectPlatform.rules
Normal file
@@ -0,0 +1,84 @@
|
||||
# BuildConfig/DetectPlatform.rules
|
||||
# Author: Patrick Baggett <ptbaggett@762studios.com>
|
||||
# Created: 11/15/2011
|
||||
#
|
||||
# Purpose:
|
||||
#
|
||||
# OS/architecture detection rules. Requires GNU Make
|
||||
#
|
||||
# License:
|
||||
#
|
||||
# This program is free software. It comes without any warranty, to
|
||||
# the extent permitted by applicable law. You can redistribute it
|
||||
# and/or modify it under the terms of the Do What The Fuck You Want
|
||||
# To Public License, Version 2, as published by Sam Hocevar. See
|
||||
# http://sam.zoy.org/wtfpl/COPYING for more details.
|
||||
|
||||
# Allow user overrides of $OS and $ARCH
|
||||
|
||||
#==============================
|
||||
# Detect operating system
|
||||
#==============================
|
||||
ifeq ($(OS),)
|
||||
OS := $(shell uname)
|
||||
ifeq ($(OS),SunOS)
|
||||
OS := Solaris
|
||||
endif
|
||||
ifeq ($(findstring Windows,$(OS)),Windows) # *Windows* -> Windows
|
||||
OS := Windows
|
||||
endif
|
||||
|
||||
ifeq ($(findstring MINGW,$(OS)),MINGW) # *MINGW* -> Windows
|
||||
OS := Windows
|
||||
endif
|
||||
endif
|
||||
|
||||
# Detect when the Win32 environment variable "Windows_NT" is set and normalize it
|
||||
ifeq ($(OS),Windows_NT)
|
||||
OS := Windows
|
||||
endif
|
||||
|
||||
#==============================
|
||||
# Detect processor arch
|
||||
# =============================
|
||||
ifeq ($(ARCH),)
|
||||
ifeq ($(OS),Solaris) #Solaris likes "-p" instead of "-m"
|
||||
ARCH := $(shell uname -p)
|
||||
else
|
||||
ARCH := $(shell uname -m)
|
||||
endif
|
||||
|
||||
#Replace "i<x>86" with "x86", where <x> can be [x, digit]
|
||||
ARCH := $(shell echo $(ARCH) | sed s/i[x0-9]86/x86/)
|
||||
|
||||
#Replace "powerpc" with "ppc"
|
||||
ARCH := $(shell echo $(ARCH) | sed s/powerpc/ppc/)
|
||||
|
||||
ifeq ($(ARCH),sparc64) #Linux on UltraSPARC gives sparc64 when running 64-bit kernel
|
||||
ARCH := sparc
|
||||
endif
|
||||
|
||||
ifeq ($(ARCH),mips64) #Linux/mips64 kernel, but probably don't want 64-bit app
|
||||
ARCH := mips
|
||||
endif
|
||||
|
||||
ifeq ($(ARCH),amd64) # "amd64" -> "x86-64"
|
||||
ARCH := x86-64
|
||||
endif
|
||||
|
||||
ifeq ($(ARCH),x86_64) # "x86_64" -> "x86-64"
|
||||
ARCH := x86-64
|
||||
endif
|
||||
|
||||
ifeq ($(ARCH),armv6l) # "armv6l" -> "arm"
|
||||
ARCH := arm
|
||||
SUBARCH := armv6
|
||||
endif
|
||||
|
||||
ifeq ($(ARCH),armv7l) # "armv7l" -> "arm
|
||||
ARCH := arm
|
||||
SUBARCH := armv7
|
||||
endif
|
||||
|
||||
endif
|
||||
|
||||
44
BuildConfig/DetectWinSys.rules
Normal file
44
BuildConfig/DetectWinSys.rules
Normal file
@@ -0,0 +1,44 @@
|
||||
# BuildConfig/DetectWinSys.rules
|
||||
# Author: Patrick Baggett <ptbaggett@762studios.com>
|
||||
# Created: 1/18/2013
|
||||
#
|
||||
# Purpose:
|
||||
#
|
||||
# Windowing system detection
|
||||
#
|
||||
# License:
|
||||
#
|
||||
# This program is free software. It comes without any warranty, to
|
||||
# the extent permitted by applicable law. You can redistribute it
|
||||
# and/or modify it under the terms of the Do What The Fuck You Want
|
||||
# To Public License, Version 2, as published by Sam Hocevar. See
|
||||
# http://sam.zoy.org/wtfpl/COPYING for more details.
|
||||
|
||||
# This detects a default windowing system (WINSYS) based upon OS. The
|
||||
# user may override it by setting $WINSYS ahead of time, in which case
|
||||
# these rules act as a no-op
|
||||
|
||||
ifeq ($(WINSYS),)
|
||||
|
||||
#Windows uses...Win32 APIs
|
||||
ifeq ($(OS),Windows)
|
||||
WINSYS := Win32
|
||||
endif
|
||||
|
||||
#MacOS X uses...MacOS X APIs
|
||||
ifeq ($(OS),Darwin)
|
||||
WINSYS := MacOSX
|
||||
endif
|
||||
|
||||
#Android uses...Android APIs
|
||||
ifeq ($(OS),Android)
|
||||
WINSYS := Android
|
||||
endif
|
||||
|
||||
#No specific rules, so default to Xlib
|
||||
ifeq ($(WINSYS),)
|
||||
WINSYS := Xlib
|
||||
endif
|
||||
|
||||
endif
|
||||
|
||||
20
BuildConfig/GCC-Flags.rules
Normal file
20
BuildConfig/GCC-Flags.rules
Normal file
@@ -0,0 +1,20 @@
|
||||
# BuildConfig/GCC-Flags.rules
|
||||
# Author: Patrick Baggett <ptbaggett@762studios.com>
|
||||
# Created: 1/11/2012
|
||||
#
|
||||
# Purpose:
|
||||
#
|
||||
# Common flags for GNU "gcc" to reduce redundancy
|
||||
#
|
||||
# License:
|
||||
#
|
||||
# This program is free software. It comes without any warranty, to
|
||||
# the extent permitted by applicable law. You can redistribute it
|
||||
# and/or modify it under the terms of the Do What The Fuck You Want
|
||||
# To Public License, Version 2, as published by Sam Hocevar. See
|
||||
# http://sam.zoy.org/wtfpl/COPYING for more details.
|
||||
|
||||
GCC_COMMON := -fstrict-aliasing -Wall -Wextra
|
||||
|
||||
OS_CFLAGS += $(GCC_COMMON)
|
||||
OS_CXXFLAGS += $(GCC_COMMON)
|
||||
30
BuildConfig/Makefile.Android.arm
Normal file
30
BuildConfig/Makefile.Android.arm
Normal file
@@ -0,0 +1,30 @@
|
||||
# BuildConfig/Makefile.Android.arm
|
||||
# Author: Patrick Baggett <ptbaggett@762studios.com>
|
||||
# Created: 1/16/2013
|
||||
#
|
||||
# Purpose:
|
||||
#
|
||||
# Makefile for Android running on 32-bit ARMv6+ architecture processors
|
||||
#
|
||||
# License:
|
||||
#
|
||||
# This program is free software. It comes without any warranty, to
|
||||
# the extent permitted by applicable law. You can redistribute it
|
||||
# and/or modify it under the terms of the Do What The Fuck You Want
|
||||
# To Public License, Version 2, as published by Sam Hocevar. See
|
||||
# http://sam.zoy.org/wtfpl/COPYING for more details.
|
||||
|
||||
# All C/C++ compiler flags required by this OS platform
|
||||
# TODO: anything required here?
|
||||
OS_CXXFLAGS := -D_UNIX=1
|
||||
OS_CFLAGS := -D_UNIX=1
|
||||
|
||||
include BuildConfig/GCC-Flags.rules
|
||||
include BuildConfig/POSIX-Libs.rules
|
||||
|
||||
ASM ?= as
|
||||
RANLIB ?= ranlib
|
||||
SUBSYSTEM := POSIX
|
||||
|
||||
# All flags/libraries the linker will need
|
||||
OS_LDFLAGS :=
|
||||
30
BuildConfig/Makefile.Darwin.x86
Normal file
30
BuildConfig/Makefile.Darwin.x86
Normal file
@@ -0,0 +1,30 @@
|
||||
# BuildConfig/Makefile.Darwin.x86
|
||||
# Author: Patrick Baggett <ptbaggett@762studios.com>
|
||||
# Created: 12/28/2011
|
||||
#
|
||||
# Purpose:
|
||||
#
|
||||
# Makefile for Mac OS running on 32-bit x86 architecture processors
|
||||
#
|
||||
# License:
|
||||
#
|
||||
# This program is free software. It comes without any warranty, to
|
||||
# the extent permitted by applicable law. You can redistribute it
|
||||
# and/or modify it under the terms of the Do What The Fuck You Want
|
||||
# To Public License, Version 2, as published by Sam Hocevar. See
|
||||
# http://sam.zoy.org/wtfpl/COPYING for more details.
|
||||
|
||||
# All C/C++ compiler flags required by this OS platform
|
||||
# NOTE: This pretty much assumes GCC
|
||||
OS_CXXFLAGS := -m32 -D_UNIX=1 -I/usr/local/include
|
||||
OS_CFLAGS := -m32 -D_UNIX=1 -I/usr/local/include
|
||||
|
||||
include BuildConfig/GCC-Flags.rules
|
||||
include BuildConfig/Darwin-Libs.rules
|
||||
|
||||
ASM := yasm -f macho32 -m x86
|
||||
RANLIB := ranlib
|
||||
SUBSYSTEM := POSIX
|
||||
|
||||
# All flags/libraries the linker will need
|
||||
OS_LDFLAGS := -m32 -L/usr/local/lib -Wl,-rpath,/usr/local/lib
|
||||
30
BuildConfig/Makefile.Darwin.x86-64
Normal file
30
BuildConfig/Makefile.Darwin.x86-64
Normal file
@@ -0,0 +1,30 @@
|
||||
# BuildConfig/Makefile.Darwin.x86-64
|
||||
# Author: Patrick Baggett <ptbaggett@762studios.com>
|
||||
# Created: 11/15/2012
|
||||
#
|
||||
# Purpose:
|
||||
#
|
||||
# Makefile for Mac OS running on 64-bit x86 architecture processors
|
||||
#
|
||||
# License:
|
||||
#
|
||||
# This program is free software. It comes without any warranty, to
|
||||
# the extent permitted by applicable law. You can redistribute it
|
||||
# and/or modify it under the terms of the Do What The Fuck You Want
|
||||
# To Public License, Version 2, as published by Sam Hocevar. See
|
||||
# http://sam.zoy.org/wtfpl/COPYING for more details.
|
||||
|
||||
# All C/C++ compiler flags required by this OS platform
|
||||
# NOTE: This pretty much assumes GCC
|
||||
OS_CXXFLAGS := -m64 -D_UNIX=1 -I/usr/local/include
|
||||
OS_CFLAGS := -m64 -D_UNIX=1 -I/usr/local/include
|
||||
|
||||
include BuildConfig/GCC-Flags.rules
|
||||
include BuildConfig/Darwin-Libs.rules
|
||||
|
||||
ASM := yasm -f macho64 -m amd64
|
||||
RANLIB := ranlib
|
||||
SUBSYSTEM := POSIX
|
||||
|
||||
# All flags/libraries the linker will need
|
||||
OS_LDFLAGS := -m64 -L/usr/local/lib -Wl,-rpath,/usr/local/lib
|
||||
30
BuildConfig/Makefile.Linux.arm
Normal file
30
BuildConfig/Makefile.Linux.arm
Normal file
@@ -0,0 +1,30 @@
|
||||
# BuildConfig/Makefile.Linux.arm
|
||||
# Author: Patrick Baggett <ptbaggett@762studios.com>
|
||||
# Created: 6/21/2012
|
||||
#
|
||||
# Purpose:
|
||||
#
|
||||
# Makefile for Linux running on 32-bit ARMv6+ architecture processors
|
||||
#
|
||||
# License:
|
||||
#
|
||||
# This program is free software. It comes without any warranty, to
|
||||
# the extent permitted by applicable law. You can redistribute it
|
||||
# and/or modify it under the terms of the Do What The Fuck You Want
|
||||
# To Public License, Version 2, as published by Sam Hocevar. See
|
||||
# http://sam.zoy.org/wtfpl/COPYING for more details.
|
||||
|
||||
# All C/C++ compiler flags required by this OS platform
|
||||
# NOTE: This pretty much assumes GCC on Linux
|
||||
OS_CXXFLAGS := -D_UNIX=1 -I/usr/local/include
|
||||
OS_CFLAGS := -D_UNIX=1 -I/usr/local/include
|
||||
|
||||
include BuildConfig/GCC-Flags.rules
|
||||
include BuildConfig/POSIX-Libs.rules
|
||||
|
||||
ASM ?= as
|
||||
RANLIB ?= ranlib
|
||||
SUBSYSTEM := POSIX
|
||||
|
||||
# All flags/libraries the linker will need
|
||||
OS_LDFLAGS := -L/usr/local/lib -Wl,-rpath,/usr/local/lib
|
||||
32
BuildConfig/Makefile.Linux.ia64
Normal file
32
BuildConfig/Makefile.Linux.ia64
Normal file
@@ -0,0 +1,32 @@
|
||||
# BuildConfig/Makefile.Linux.ia64
|
||||
# Author: Patrick Baggett <ptbaggett@762studios.com>
|
||||
# Created: 4/16/20112
|
||||
#
|
||||
# Purpose:
|
||||
#
|
||||
# Makefile for Linux running on Itanium architecture processors
|
||||
#
|
||||
# License:
|
||||
#
|
||||
# This program is free software. It comes without any warranty, to
|
||||
# the extent permitted by applicable law. You can redistribute it
|
||||
# and/or modify it under the terms of the Do What The Fuck You Want
|
||||
# To Public License, Version 2, as published by Sam Hocevar. See
|
||||
# http://sam.zoy.org/wtfpl/COPYING for more details.
|
||||
|
||||
# All C/C++ compiler flags required by this OS platform
|
||||
# NOTE: This pretty much assumes GCC on Linux
|
||||
OS_CXXFLAGS := -D_UNIX=1 -I/usr/local/include
|
||||
OS_CFLAGS := -D_UNIX=1 -I/usr/local/include
|
||||
|
||||
include BuildConfig/GCC-Flags.rules
|
||||
include BuildConfig/POSIX-Libs.rules
|
||||
|
||||
ASM := as -mtune=itanium2
|
||||
RANLIB := ranlib
|
||||
SUBSYSTEM := POSIX
|
||||
|
||||
# All flags/libraries the linker will need
|
||||
OS_LDFLAGS := -L/usr/local/lib -Wl,-rpath,/usr/local/lib
|
||||
|
||||
|
||||
30
BuildConfig/Makefile.Linux.mips
Normal file
30
BuildConfig/Makefile.Linux.mips
Normal file
@@ -0,0 +1,30 @@
|
||||
# BuildConfig/Makefile.Linux.mips
|
||||
# Author: Patrick Baggett <ptbaggett@762studios.com>
|
||||
# Created: 6/28/2013
|
||||
#
|
||||
# Purpose:
|
||||
#
|
||||
# Makefile for Linux running on 32-bit MIPS architecture processors
|
||||
#
|
||||
# License:
|
||||
#
|
||||
# This program is free software. It comes without any warranty, to
|
||||
# the extent permitted by applicable law. You can redistribute it
|
||||
# and/or modify it under the terms of the Do What The Fuck You Want
|
||||
# To Public License, Version 2, as published by Sam Hocevar. See
|
||||
# http://sam.zoy.org/wtfpl/COPYING for more details.
|
||||
|
||||
# All C/C++ compiler flags required by this OS platform
|
||||
# NOTE: This pretty much assumes GCC on Linux
|
||||
OS_CXXFLAGS := -D_UNIX=1 -I/usr/local/include
|
||||
OS_CFLAGS := -D_UNIX=1 -I/usr/local/include
|
||||
|
||||
include BuildConfig/GCC-Flags.rules
|
||||
include BuildConfig/POSIX-Libs.rules
|
||||
|
||||
ASM ?= as -mips32
|
||||
RANLIB ?= ranlib
|
||||
SUBSYSTEM := POSIX
|
||||
|
||||
# All flags/libraries the linker will need
|
||||
OS_LDFLAGS := -L/usr/local/lib -Wl,-rpath,/usr/local/lib
|
||||
30
BuildConfig/Makefile.Linux.mips64
Normal file
30
BuildConfig/Makefile.Linux.mips64
Normal file
@@ -0,0 +1,30 @@
|
||||
# BuildConfig/Makefile.Linux.mips
|
||||
# Author: Patrick Baggett <ptbaggett@762studios.com>
|
||||
# Created: 6/28/2013
|
||||
#
|
||||
# Purpose:
|
||||
#
|
||||
# Makefile for Linux running on 64-bit MIPS architecture processors
|
||||
#
|
||||
# License:
|
||||
#
|
||||
# This program is free software. It comes without any warranty, to
|
||||
# the extent permitted by applicable law. You can redistribute it
|
||||
# and/or modify it under the terms of the Do What The Fuck You Want
|
||||
# To Public License, Version 2, as published by Sam Hocevar. See
|
||||
# http://sam.zoy.org/wtfpl/COPYING for more details.
|
||||
|
||||
# All C/C++ compiler flags required by this OS platform
|
||||
# NOTE: This pretty much assumes GCC on Linux
|
||||
OS_CXXFLAGS := -mabi=64 -D_UNIX=1 -I/usr/local/include
|
||||
OS_CFLAGS := -mabi=64 -D_UNIX=1 -I/usr/local/include
|
||||
|
||||
include BuildConfig/GCC-Flags.rules
|
||||
include BuildConfig/POSIX-Libs.rules
|
||||
|
||||
ASM ?= as -mips64 -mabi=64
|
||||
RANLIB ?= ranlib
|
||||
SUBSYSTEM := POSIX
|
||||
|
||||
# All flags/libraries the linker will need
|
||||
OS_LDFLAGS := -mabi=64 -L/usr/local/lib -Wl,-rpath,/usr/local/lib
|
||||
33
BuildConfig/Makefile.Linux.ppc
Normal file
33
BuildConfig/Makefile.Linux.ppc
Normal file
@@ -0,0 +1,33 @@
|
||||
# BuildConfig/Makefile.Linux.ppc
|
||||
# Author: Patrick Baggett <ptbaggett@762studios.com>
|
||||
# Created: 7/20/2012
|
||||
#
|
||||
# Purpose:
|
||||
#
|
||||
# Makefile for Linux running on Power Arch. processors, 32-bit binary
|
||||
#
|
||||
# License:
|
||||
#
|
||||
# This program is free software. It comes without any warranty, to
|
||||
# the extent permitted by applicable law. You can redistribute it
|
||||
# and/or modify it under the terms of the Do What The Fuck You Want
|
||||
# To Public License, Version 2, as published by Sam Hocevar. See
|
||||
# http://sam.zoy.org/wtfpl/COPYING for more details.
|
||||
|
||||
# All C++ compiler flags required by this OS platform
|
||||
OS_CXXFLAGS := -m32 -D_UNIX=1 -I/usr/local/include
|
||||
OS_CFLAGS := -m32 -D_UNIX=1 -I/usr/local/include
|
||||
|
||||
# Assume GCC here
|
||||
include BuildConfig/GCC-Flags.rules
|
||||
|
||||
# Linux uses POSIX-like libraries
|
||||
include BuildConfig/POSIX-Libs.rules
|
||||
|
||||
ASM := as -mregnames
|
||||
RANLIB := ranlib
|
||||
SUBSYSTEM := POSIX
|
||||
|
||||
# Flags for linker: 32-bit binary, and use "/usr/local/lib" in the path
|
||||
OS_LDFLAGS := -m32 -L/usr/local/lib -Wl,-rpath,/usr/local/lib
|
||||
|
||||
33
BuildConfig/Makefile.Linux.sparc
Normal file
33
BuildConfig/Makefile.Linux.sparc
Normal file
@@ -0,0 +1,33 @@
|
||||
# BuildConfig/Makefile.Linux.sparc
|
||||
# Author: Patrick Baggett <ptbaggett@762studios.com>
|
||||
# Created: 11/15/2011
|
||||
#
|
||||
# Purpose:
|
||||
#
|
||||
# Makefile for Linux running on SPARCv9 processors, 32-bit binary
|
||||
#
|
||||
# License:
|
||||
#
|
||||
# This program is free software. It comes without any warranty, to
|
||||
# the extent permitted by applicable law. You can redistribute it
|
||||
# and/or modify it under the terms of the Do What The Fuck You Want
|
||||
# To Public License, Version 2, as published by Sam Hocevar. See
|
||||
# http://sam.zoy.org/wtfpl/COPYING for more details.
|
||||
|
||||
# All C++ compiler flags required by this OS platform
|
||||
OS_CXXFLAGS := -m32 -D_UNIX=1 -I/usr/local/include
|
||||
OS_CFLAGS := -m32 -D_UNIX=1 -I/usr/local/include
|
||||
|
||||
# Assume GCC here
|
||||
include BuildConfig/GCC-Flags.rules
|
||||
|
||||
# Linux uses POSIX-like libraries
|
||||
include BuildConfig/POSIX-Libs.rules
|
||||
|
||||
ASM := as -xarch=v8plusa
|
||||
RANLIB := ranlib
|
||||
SUBSYSTEM := POSIX
|
||||
|
||||
# Flags for linker: 32-bit binary, and use "/usr/local/lib" in the path
|
||||
OS_LDFLAGS := -m32 -L/usr/local/lib -Wl,-rpath,/usr/local/lib
|
||||
|
||||
33
BuildConfig/Makefile.Linux.sparc64
Normal file
33
BuildConfig/Makefile.Linux.sparc64
Normal file
@@ -0,0 +1,33 @@
|
||||
# BuildConfig/Makefile.Linux.sparc64
|
||||
# Author: Patrick Baggett <ptbaggett@762studios.com>
|
||||
# Created: 7/9/2012
|
||||
#
|
||||
# Purpose:
|
||||
#
|
||||
# Makefile for Linux running on SPARCv9 processors, 64-bit binary
|
||||
#
|
||||
# License:
|
||||
#
|
||||
# This program is free software. It comes without any warranty, to
|
||||
# the extent permitted by applicable law. You can redistribute it
|
||||
# and/or modify it under the terms of the Do What The Fuck You Want
|
||||
# To Public License, Version 2, as published by Sam Hocevar. See
|
||||
# http://sam.zoy.org/wtfpl/COPYING for more details.
|
||||
|
||||
# All C++ compiler flags required by this OS platform
|
||||
OS_CXXFLAGS := -m64 -D_UNIX=1 -I/usr/local/include
|
||||
OS_CFLAGS := -m64 -D_UNIX=1 -I/usr/local/include
|
||||
|
||||
# Assume GCC here
|
||||
include BuildConfig/GCC-Flags.rules
|
||||
|
||||
# Linux uses POSIX-like libraries
|
||||
include BuildConfig/POSIX-Libs.rules
|
||||
|
||||
ASM := as -xarch=v9a
|
||||
RANLIB := ranlib
|
||||
SUBSYSTEM := POSIX
|
||||
|
||||
# Flags for linker: 64-bit binary, and use "/usr/local/lib64" in the path
|
||||
OS_LDFLAGS := -m64 -L/usr/local/lib64 -Wl,-rpath,/usr/local/lib64
|
||||
|
||||
30
BuildConfig/Makefile.Linux.x86
Normal file
30
BuildConfig/Makefile.Linux.x86
Normal file
@@ -0,0 +1,30 @@
|
||||
# BuildConfig/Makefile.Linux.x86
|
||||
# Author: Patrick Baggett <ptbaggett@762studios.com>
|
||||
# Created: 12/28/2011
|
||||
#
|
||||
# Purpose:
|
||||
#
|
||||
# Makefile for Linux running on 32-bit x86 architecture processors
|
||||
#
|
||||
# License:
|
||||
#
|
||||
# This program is free software. It comes without any warranty, to
|
||||
# the extent permitted by applicable law. You can redistribute it
|
||||
# and/or modify it under the terms of the Do What The Fuck You Want
|
||||
# To Public License, Version 2, as published by Sam Hocevar. See
|
||||
# http://sam.zoy.org/wtfpl/COPYING for more details.
|
||||
|
||||
# All C/C++ compiler flags required by this OS platform
|
||||
# NOTE: This pretty much assumes GCC on Linux
|
||||
OS_CXXFLAGS := -m32 -D_UNIX=1 -I/usr/local/include
|
||||
OS_CFLAGS := -m32 -D_UNIX=1 -I/usr/local/include
|
||||
|
||||
include BuildConfig/GCC-Flags.rules
|
||||
include BuildConfig/POSIX-Libs.rules
|
||||
|
||||
ASM := yasm -f elf32 -m x86
|
||||
RANLIB := ranlib
|
||||
SUBSYSTEM := POSIX
|
||||
|
||||
# All flags/libraries the linker will need
|
||||
OS_LDFLAGS := -m32 -L/usr/local/lib -Wl,-rpath,/usr/local/lib
|
||||
30
BuildConfig/Makefile.Linux.x86-64
Normal file
30
BuildConfig/Makefile.Linux.x86-64
Normal file
@@ -0,0 +1,30 @@
|
||||
# BuildConfig/Makefile.Linux.x86-64
|
||||
# Author: Patrick Baggett <ptbaggett@762studios.com>
|
||||
# Created: 7/25/2011
|
||||
#
|
||||
# Purpose:
|
||||
#
|
||||
# Makefile for Linux running on 64-bit x86 architecture processors
|
||||
#
|
||||
# License:
|
||||
#
|
||||
# This program is free software. It comes without any warranty, to
|
||||
# the extent permitted by applicable law. You can redistribute it
|
||||
# and/or modify it under the terms of the Do What The Fuck You Want
|
||||
# To Public License, Version 2, as published by Sam Hocevar. See
|
||||
# http://sam.zoy.org/wtfpl/COPYING for more details.
|
||||
|
||||
# All C/C++ compiler flags required by this OS platform
|
||||
OS_CXXFLAGS := -m64 -D_UNIX=1 -I/usr/local/include
|
||||
OS_CFLAGS := -m64 -D_UNIX=1 -I/usr/local/include
|
||||
|
||||
include BuildConfig/GCC-Flags.rules
|
||||
include BuildConfig/POSIX-Libs.rules
|
||||
|
||||
ASM := yasm -f elf64 -m amd64
|
||||
RANLIB := ranlib
|
||||
SUBSYSTEM := POSIX
|
||||
|
||||
CWD = $(shell pwd)
|
||||
# All flags/libraries the linker will need
|
||||
OS_LDFLAGS := -m64 -L/usr/local/lib64 -Wl,-rpath,/usr/local/lib64
|
||||
56
BuildConfig/Makefile.Solaris.sparc
Normal file
56
BuildConfig/Makefile.Solaris.sparc
Normal file
@@ -0,0 +1,56 @@
|
||||
# BuildConfig/Makefile.Solaris.sparc
|
||||
# Author: Patrick Baggett <ptbaggett@762studios.com>
|
||||
# Created: 12/15/2011
|
||||
#
|
||||
# Purpose:
|
||||
#
|
||||
# Makefile for Solaris 10 running on SPARCv9 processors, 32-bit binary
|
||||
#
|
||||
# License:
|
||||
#
|
||||
# This program is free software. It comes without any warranty, to
|
||||
# the extent permitted by applicable law. You can redistribute it
|
||||
# and/or modify it under the terms of the Do What The Fuck You Want
|
||||
# To Public License, Version 2, as published by Sam Hocevar. See
|
||||
# http://sam.zoy.org/wtfpl/COPYING for more details.
|
||||
|
||||
# All C++ compiler flags required by this OS platform
|
||||
OS_CXXFLAGS := -D_POSIX_PTHREAD_SEMANTICS -m32 -D_UNIX=1 -I/usr/local/include
|
||||
OS_CFLAGS := -D_POSIX_PTHREAD_SEMANTICS -m32 -D_UNIX=1 -I/usr/local/include
|
||||
|
||||
# All flags/libraries the linker will need
|
||||
OS_LDFLAGS := -m32 -L/usr/local/lib -Wl,-R,/usr/local/lib
|
||||
|
||||
ASM := /usr/ccs/bin/as -xarch=v8plusa
|
||||
RANLIB := /usr/ccs/bin/ranlib
|
||||
AR := /usr/ccs/bin/ar
|
||||
SUBSYSTEM := Solaris
|
||||
|
||||
#Default $CC to Sun "cc"
|
||||
ifeq ($(origin CC),default)
|
||||
CC := cc
|
||||
endif
|
||||
|
||||
#Default $CXX to Sun "CC"
|
||||
ifeq ($(origin CXX),default)
|
||||
CXX := CC
|
||||
endif
|
||||
|
||||
include BuildConfig/DetectCompiler.rules
|
||||
include BuildConfig/Solaris-Libs.rules
|
||||
|
||||
ifeq ($(IS_GCC),1)
|
||||
CXX := g++ #Use matching GNU g++
|
||||
include BuildConfig/GCC-Flags.rules
|
||||
|
||||
#These are gcc + sparc specific
|
||||
OS_CFLAGS += -mcpu=ultrasparc -mvis -threads
|
||||
OS_CXXFLAGS += -mcpu=ultrasparc -mvis -threads
|
||||
else ifeq ($(IS_CC),1)
|
||||
CXX := CC #Use matching Sun C++
|
||||
include BuildConfig/SunPro-Flags.rules
|
||||
|
||||
#These are SunPro + sparc specific
|
||||
OS_CFLAGS += -xvis=yes -xarch=sparcvis
|
||||
OS_CXXFLAGS += -xvis=yes -xarch=sparcvis
|
||||
endif
|
||||
56
BuildConfig/Makefile.Solaris.sparc64
Normal file
56
BuildConfig/Makefile.Solaris.sparc64
Normal file
@@ -0,0 +1,56 @@
|
||||
# BuildConfig/Makefile.Solaris.sparc64
|
||||
# Author: Patrick Baggett <ptbaggett@762studios.com>
|
||||
# Created: 4/3/2012
|
||||
#
|
||||
# Purpose:
|
||||
#
|
||||
# Makefile for Solaris 10 running on SPARCv9 processors, 64-bit binary
|
||||
#
|
||||
# License:
|
||||
#
|
||||
# This program is free software. It comes without any warranty, to
|
||||
# the extent permitted by applicable law. You can redistribute it
|
||||
# and/or modify it under the terms of the Do What The Fuck You Want
|
||||
# To Public License, Version 2, as published by Sam Hocevar. See
|
||||
# http://sam.zoy.org/wtfpl/COPYING for more details.
|
||||
|
||||
# All C++ compiler flags required by this OS platform
|
||||
OS_CXXFLAGS := -D_POSIX_PTHREAD_SEMANTICS -m64 -D_UNIX=1 -I/usr/local/include
|
||||
OS_CFLAGS := -D_POSIX_PTHREAD_SEMANTICS -m64 -D_UNIX=1 -I/usr/local/include
|
||||
|
||||
# All flags/libraries the linker will need
|
||||
OS_LDFLAGS := -m64 -L/usr/local/lib/sparcv9 -Wl,-R,/usr/local/lib/sparcv9
|
||||
|
||||
ASM := /usr/ccs/bin/as -xarch=v9a
|
||||
RANLIB := /usr/ccs/bin/ranlib
|
||||
AR := /usr/ccs/bin/ar
|
||||
SUBSYSTEM := Solaris
|
||||
|
||||
#Default $CC to Sun "cc"
|
||||
ifeq ($(origin CC),default)
|
||||
CC := cc
|
||||
endif
|
||||
|
||||
#Default $CXX to Sun "CC"
|
||||
ifeq ($(origin CXX),default)
|
||||
CXX := CC
|
||||
endif
|
||||
|
||||
include BuildConfig/DetectCompiler.rules
|
||||
include BuildConfig/Solaris-Libs.rules
|
||||
|
||||
ifeq ($(IS_GCC),1)
|
||||
CXX := g++ #Use matching GNU g++
|
||||
include BuildConfig/GCC-Flags.rules
|
||||
|
||||
#These are gcc + sparc specific
|
||||
OS_CFLAGS += -mcpu=ultrasparc -mvis -threads
|
||||
OS_CXXFLAGS += -mcpu=ultrasparc -mvis -threads
|
||||
else ifeq ($(IS_CC),1)
|
||||
CXX := CC #Use matching Sun C++
|
||||
include BuildConfig/SunPro-Flags.rules
|
||||
|
||||
#These are SunPro + sparc64 specific
|
||||
OS_CFLAGS += -xvis=yes -xarch=sparcvis
|
||||
OS_CXXFLAGS += -xvis=yes -xarch=sparcvis
|
||||
endif
|
||||
52
BuildConfig/Makefile.Solaris.x86
Normal file
52
BuildConfig/Makefile.Solaris.x86
Normal file
@@ -0,0 +1,52 @@
|
||||
# BuildConfig/Makefile.Solaris.x86
|
||||
# Author: Patrick Baggett <ptbaggett@762studios.com>
|
||||
# Created: 12/15/2011
|
||||
#
|
||||
# Purpose:
|
||||
#
|
||||
# Makefile for Solaris 10 running on x86 processors, 32-bit binary
|
||||
#
|
||||
# License:
|
||||
#
|
||||
# This program is free software. It comes without any warranty, to
|
||||
# the extent permitted by applicable law. You can redistribute it
|
||||
# and/or modify it under the terms of the Do What The Fuck You Want
|
||||
# To Public License, Version 2, as published by Sam Hocevar. See
|
||||
# http://sam.zoy.org/wtfpl/COPYING for more details.
|
||||
|
||||
# All C++ compiler flags required by this OS platform
|
||||
OS_CXXFLAGS := -D_POSIX_PTHREAD_SEMANTICS=1 -m32 -D_UNIX=1 -I/usr/local/include
|
||||
OS_CFLAGS := -D_POSIX_PTHREAD_SEMANTICS=1 -m32 -D_UNIX=1 -I/usr/local/include
|
||||
|
||||
# All flags/libraries the linker will need
|
||||
OS_LDFLAGS := -m32 -L/usr/local/lib -Wl,-R,/usr/local/lib
|
||||
|
||||
ASM := yasm -f elf32
|
||||
RANLIB := /usr/ccs/bin/ranlib
|
||||
AR := /usr/ccs/bin/ar
|
||||
SUBSYSTEM := Solaris
|
||||
|
||||
#Default $CC to Sun "cc"
|
||||
ifeq ($(origin CC),default)
|
||||
CC := cc
|
||||
endif
|
||||
|
||||
#Default $CXX to Sun "CC"
|
||||
ifeq ($(origin CXX),default)
|
||||
CXX := CC
|
||||
endif
|
||||
|
||||
include BuildConfig/DetectCompiler.rules
|
||||
include BuildConfig/Solaris-Libs.rules
|
||||
|
||||
ifeq ($(IS_GCC),1)
|
||||
CXX := g++ #Use matching GNU g++
|
||||
include BuildConfig/GCC-Flags.rules
|
||||
|
||||
#These are gcc + Solaris specific
|
||||
OS_CFLAGS += -threads
|
||||
OS_CXXFLAGS += -threads
|
||||
else ifeq ($(IS_CC),1)
|
||||
CXX := CC #Use matching Sun C++
|
||||
include BuildConfig/SunPro-Flags.rules
|
||||
endif
|
||||
28
BuildConfig/Makefile.Windows.x86
Normal file
28
BuildConfig/Makefile.Windows.x86
Normal file
@@ -0,0 +1,28 @@
|
||||
# BuildConfig/Makefile.Windows.x86
|
||||
# Author: Patrick Baggett <ptbaggett@762studios.com>
|
||||
# Created: 11/09/2012
|
||||
#
|
||||
# Purpose:
|
||||
#
|
||||
# Makefile for Windows running on 32-bit x86 architecture processors
|
||||
#
|
||||
# License:
|
||||
#
|
||||
# This program is free software. It comes without any warranty, to
|
||||
# the extent permitted by applicable law. You can redistribute it
|
||||
# and/or modify it under the terms of the Do What The Fuck You Want
|
||||
# To Public License, Version 2, as published by Sam Hocevar. See
|
||||
# http://sam.zoy.org/wtfpl/COPYING for more details.
|
||||
|
||||
# All C/C++ compiler flags required by this OS platform
|
||||
OS_CXXFLAGS := -m32 -D_WINDOWS=1
|
||||
OS_CFLAGS := -m32 -D_WINDOWS=1
|
||||
|
||||
include BuildConfig/GCC-Flags.rules
|
||||
|
||||
ASM := yasm -f win32 -m x86
|
||||
RANLIB := ranlib
|
||||
SUBSYSTEM := Win32
|
||||
|
||||
# All flags/libraries the linker will need
|
||||
OS_LDFLAGS := -m32 -L/usr/local/lib -Wl,-rpath,/usr/local/lib
|
||||
22
BuildConfig/POSIX-Libs.rules
Normal file
22
BuildConfig/POSIX-Libs.rules
Normal file
@@ -0,0 +1,22 @@
|
||||
# BuildConfig/POSIX-Libs.rules
|
||||
# Author: Patrick Baggett <ptbaggett@762studios.com>
|
||||
# Created: 3/19/2012
|
||||
#
|
||||
# Purpose:
|
||||
#
|
||||
# Defines common libraries required for linking on POSIX platforms
|
||||
#
|
||||
# License:
|
||||
#
|
||||
# This program is free software. It comes without any warranty, to
|
||||
# the extent permitted by applicable law. You can redistribute it
|
||||
# and/or modify it under the terms of the Do What The Fuck You Want
|
||||
# To Public License, Version 2, as published by Sam Hocevar. See
|
||||
# http://sam.zoy.org/wtfpl/COPYING for more details.
|
||||
|
||||
# Base libraries (console)
|
||||
export ZENGINE_BASE_LIBS = -lrt -ldl -lpthread -lm
|
||||
|
||||
# GUI libraries (X Windows)
|
||||
export ZENGINE_GUI_LIBS = -lGL -lX11
|
||||
|
||||
19
BuildConfig/RaspPi-Flags.rules
Normal file
19
BuildConfig/RaspPi-Flags.rules
Normal file
@@ -0,0 +1,19 @@
|
||||
# BuildConfig/RaspPi-Flags.rules
|
||||
# Author: Patrick Baggett <ptbaggett@762studios.com>
|
||||
# Created: 1/4/2013
|
||||
#
|
||||
# Purpose:
|
||||
#
|
||||
# Special flags for the Raspberry Pi running on Linux
|
||||
#
|
||||
# License:
|
||||
#
|
||||
# This program is free software. It comes without any warranty, to
|
||||
# the extent permitted by applicable law. You can redistribute it
|
||||
# and/or modify it under the terms of the Do What The Fuck You Want
|
||||
# To Public License, Version 2, as published by Sam Hocevar. See
|
||||
# http://sam.zoy.org/wtfpl/COPYING for more details.
|
||||
|
||||
OS_CFLAGS += -I/opt/vc/include -I/opt/vc/include/interface/vcos/pthreads
|
||||
OS_LDFLAGS += -L/opt/vc/lib -lbcm_host
|
||||
|
||||
26
BuildConfig/Solaris-Libs.rules
Normal file
26
BuildConfig/Solaris-Libs.rules
Normal file
@@ -0,0 +1,26 @@
|
||||
# BuildConfig/Solaris-Libs.rules
|
||||
# Author: Patrick Baggett <ptbaggett@762studios.com>
|
||||
# Created: 4/11/2012
|
||||
#
|
||||
# Purpose:
|
||||
#
|
||||
# Defines common libraries required for linking on Solaris 10 and later
|
||||
#
|
||||
# License:
|
||||
#
|
||||
# This program is free software. It comes without any warranty, to
|
||||
# the extent permitted by applicable law. You can redistribute it
|
||||
# and/or modify it under the terms of the Do What The Fuck You Want
|
||||
# To Public License, Version 2, as published by Sam Hocevar. See
|
||||
# http://sam.zoy.org/wtfpl/COPYING for more details.
|
||||
|
||||
# The major difference between this file and POSIX-Libs.rules is that Solaris
|
||||
# uses native threads, so linking to libpthread.so just bloats the binary. Also,
|
||||
# Solaris native threads are in libc.so, so no other library is needed.
|
||||
|
||||
# Base libraries (console)
|
||||
export ZENGINE_BASE_LIBS = -lrt -lm
|
||||
|
||||
# GUI libraries (X Windows)
|
||||
export ZENGINE_GUI_LIBS = -lGL -lX11
|
||||
|
||||
30
BuildConfig/SunPro-Flags.rules
Normal file
30
BuildConfig/SunPro-Flags.rules
Normal file
@@ -0,0 +1,30 @@
|
||||
# BuildConfig/SunPro-Flags.rules
|
||||
# Author: Patrick Baggett <ptbaggett@762studios.com>
|
||||
# Created: 4/1/2012
|
||||
#
|
||||
# Purpose:
|
||||
#
|
||||
# Common flags for Sun "cc" to reduce redundancy
|
||||
#
|
||||
# License:
|
||||
#
|
||||
# This program is free software. It comes without any warranty, to
|
||||
# the extent permitted by applicable law. You can redistribute it
|
||||
# and/or modify it under the terms of the Do What The Fuck You Want
|
||||
# To Public License, Version 2, as published by Sam Hocevar. See
|
||||
# http://sam.zoy.org/wtfpl/COPYING for more details.
|
||||
|
||||
SUNPRO_COMMON := -mt -features=extensions
|
||||
|
||||
ifeq ($(findstring sparc,$(ARCH)),sparc)
|
||||
ISSPARC := 1
|
||||
endif
|
||||
|
||||
ifeq ($(ISSPARC),1)
|
||||
SUNPRO_COMMON += -xmemalign=8s
|
||||
endif
|
||||
|
||||
OS_CFLAGS += $(SUNPRO_COMMON) -xalias_level=std
|
||||
OS_CXXFLAGS += $(SUNPRO_COMMON) -xalias_level=simple
|
||||
OS_LDFLAGS += $(SUNPRO_COMMON)
|
||||
|
||||
137
Include/ZBuild.hpp
Normal file
137
Include/ZBuild.hpp
Normal file
@@ -0,0 +1,137 @@
|
||||
/*
|
||||
ZBuild.hpp
|
||||
Author: James Russell <jcrussell@762studios.com>
|
||||
|
||||
Purpose: This is the build file that is used to set overall build configuration
|
||||
when building ZEngine projects. This needs to be on the build path for
|
||||
all ZEngine projects.
|
||||
|
||||
Changelog
|
||||
2011/12/11 - creation (jcrussell)
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef _ZBUILD_HPP
|
||||
#define _ZBUILD_HPP
|
||||
|
||||
//Current version of ZEngine (overall, not individual lib versions)
|
||||
#define ZENGINE_CURRENT_VERSION "0.6.0"
|
||||
|
||||
//These should be modified for the game in question
|
||||
#ifndef COMPANY_NAME
|
||||
#define COMPANY_NAME "762Studios"
|
||||
#endif
|
||||
|
||||
#ifndef GAME_NAME
|
||||
#define GAME_NAME "762Game"
|
||||
#endif
|
||||
|
||||
/*
|
||||
The following flags can be enabled / disabled based off of compile type. Usually enabled as a 1 or 0, but
|
||||
some will have additional options.
|
||||
|
||||
--- ZRendererUtil ---
|
||||
#define ZASSERT_RENDERERUTIL - Enables run-time asserts for renderer util project debugging
|
||||
|
||||
--- ZRenderer ---
|
||||
#define ZASSERT_RENDERER - Enables run-time asserts for renderer project debugging
|
||||
|
||||
#define ZGL_CHECKGL - Enables the CHECKGL function call to check graphics library state after library calls
|
||||
|
||||
--- ZUtil ---
|
||||
#define ZALLOC_CHECK_ALLOC - Indicates that ZAlloc should record allocations
|
||||
#define ZALLOC_EXTRA_SPAMMY - Indicates that ZAlloc should log all allocations
|
||||
|
||||
#define ZASSERT_DISABLE - Disables run-time asserts for debugging purposes
|
||||
#define ZASSERT_UTIL_ENABLE - Enables run-time asserts for util project debugging
|
||||
|
||||
#define ZLOG_LEVEL - Defined as one of ZLOG_LEVEL_NONE, ZLOG_LEVEL_ERROR, ZLOG_LEVEL_WARNING, ZLOG_LEVEL_DETAILED, or ZLOG_LEVEL_EVERYTHING
|
||||
|
||||
#define ZSTL_CHECK_INTEGRITY - Causes ZSTL containers to check integrity after function calls (uses ZASSERT)
|
||||
#define ZSTL_CHECK_NAME - Causes ZName to ensure no hash collision has occurred
|
||||
#define ZSTL_DISABLE_RUNTIME_CHECKS - Causes ZSTL containers to no longer do runtime bounds and error checking (ballsy)
|
||||
*/
|
||||
|
||||
//Engine Debug version engine flags
|
||||
#ifdef _DEBUGENG
|
||||
|
||||
#define ZALLOC_CHECK_ALLOC 1
|
||||
#define ZALLOC_EXTRA_SPAMMY 0
|
||||
|
||||
#define ZASSERT_ENABLE 1
|
||||
#define ZASSERT_UTIL_ENABLE 1
|
||||
#define ZASSERT_RENDERER_ENABLE 1
|
||||
|
||||
#define ZRENDERER_CHECKGL 1
|
||||
|
||||
#define ZLOG_LEVEL ZLOG_LEVEL_SPAM
|
||||
|
||||
#define ZSTL_CHECK_INTEGRITY 1
|
||||
#define ZSTL_CHECK_NAME 1
|
||||
#define ZSTL_DISABLE_RUNTIME_CHECKS 0
|
||||
|
||||
#endif //_DEBUGENG
|
||||
|
||||
//Debug version engine flags
|
||||
#ifdef _DEBUG
|
||||
|
||||
#define ZALLOC_CHECK_ALLOC 1
|
||||
#define ZALLOC_EXTRA_SPAMMY 0
|
||||
|
||||
#define ZASSERT_ENABLE 1
|
||||
#define ZASSERT_UTIL_ENABLE 1
|
||||
#define ZASSERT_RENDERER_ENABLE 0
|
||||
|
||||
#define ZLOG_LEVEL ZLOG_LEVEL_INFO
|
||||
|
||||
#define ZRENDERER_CHECKGL 1
|
||||
|
||||
#define ZSTL_CHECK_INTEGRITY 1
|
||||
#define ZSTL_CHECK_NAME 1
|
||||
#define ZSTL_DISABLE_RUNTIME_CHECKS 0
|
||||
|
||||
#endif //_DEBUG
|
||||
|
||||
//Dev version engine flags
|
||||
#ifdef _DEV
|
||||
|
||||
#define ZALLOC_CHECK_ALLOC 0
|
||||
#define ZALLOC_EXTRA_SPAMMY 0
|
||||
|
||||
#define ZASSERT_ENABLE 1
|
||||
#define ZASSERT_UTIL_ENABLE 0
|
||||
#define ZASSERT_RENDERER_ENABLE 0
|
||||
|
||||
#define ZRENDERER_CHECKGL 0
|
||||
|
||||
#define ZLOG_LEVEL ZLOG_LEVEL_WARNING
|
||||
|
||||
#define ZSTL_CHECK_INTEGRITY 0
|
||||
#define ZSTL_CHECK_NAME 0
|
||||
#define ZSTL_DISABLE_RUNTIME_CHECKS 0
|
||||
|
||||
#endif //_DEV
|
||||
|
||||
//Release version engine flags
|
||||
#ifdef _RELEASE
|
||||
|
||||
#define ZALLOC_CHECK_ALLOC 0
|
||||
#define ZALLOC_EXTRA_SPAMMY 0
|
||||
|
||||
#define ZASSERT_ENABLE 0
|
||||
#define ZASSERT_UTIL_ENABLE 0
|
||||
#define ZASSERT_RENDERER_ENABLE 0
|
||||
|
||||
#define ZRENDERER_CHECKGL 0
|
||||
|
||||
#define ZLOG_LEVEL ZLOG_LEVEL_WARNING
|
||||
|
||||
#define ZSTL_CHECK_INTEGRITY 0
|
||||
#define ZSTL_CHECK_NAME 0
|
||||
#define ZSTL_DISABLE_RUNTIME_CHECKS 1
|
||||
|
||||
#endif //_RELEASE
|
||||
|
||||
#endif
|
||||
|
||||
29
Include/ZNet/ZNet.hpp
Normal file
29
Include/ZNet/ZNet.hpp
Normal file
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
ZNet.hpp
|
||||
Author: Patrick Baggett <ptbaggett@762studios.com>
|
||||
Created: 6/4/2013
|
||||
|
||||
Purpose:
|
||||
|
||||
ZNet main include
|
||||
|
||||
License:
|
||||
|
||||
Copyright 2013, 762 Studios
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef _ZNET_HPP
|
||||
#define _ZNET_HPP
|
||||
|
||||
|
||||
#include <ZNet/ZNetConsts.hpp>
|
||||
#include <ZNet/ZNetHost.hpp>
|
||||
#include <ZNet/ZNetServer.hpp>
|
||||
#include <ZNet/ZNetClient.hpp>
|
||||
#include <ZNet/ZNetPacket.hpp>
|
||||
#include <ZNet/ZNetPeer.hpp>
|
||||
|
||||
#endif
|
||||
|
||||
57
Include/ZNet/ZNetBandwidthMeter.hpp
Normal file
57
Include/ZNet/ZNetBandwidthMeter.hpp
Normal file
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
ZNetBandwidthMeter.hpp
|
||||
Author: Patrick Baggett <ptbaggett@762studios.com>
|
||||
Created: 7/10/2013
|
||||
|
||||
Purpose:
|
||||
|
||||
** NOT PART OF PUBLIC SDK **
|
||||
This class is not part of the public SDK; its fields and methods are not present
|
||||
in the documentation and cannot be guaranteed in future revisions.
|
||||
** NOT PART OF PUBLIC SDK **
|
||||
|
||||
Bandwidth metering using a simple token bucket algorithm. A single value is
|
||||
metered, so a incoming / outgoing each need an instance.
|
||||
|
||||
License:
|
||||
|
||||
Copyright 2013, 762 Studios
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef _ZNETBANDWIDTHMETER_HPP
|
||||
#define _ZNETBANDWIDTHMETER_HPP
|
||||
|
||||
|
||||
#include <pstdint.h>
|
||||
|
||||
class ZNetBandwidthMeter
|
||||
{
|
||||
public:
|
||||
/* Sets the new bandwidth limit */
|
||||
void SetLimit(uint32_t newLimit);
|
||||
|
||||
/* Resets the meter for reuse. Takes the current time */
|
||||
void Reset(uint64_t newStartTime);
|
||||
|
||||
/* Try to allocate a given number of bytes */
|
||||
bool TryAllocate(uint32_t bytes);
|
||||
|
||||
/* Update the token bucket */
|
||||
void Update(uint64_t newTime);
|
||||
|
||||
/* Get the bandwidth limit */
|
||||
uint32_t GetLimit() const { return limit; }
|
||||
|
||||
/* Get the available instantaneous bandwidth */
|
||||
uint32_t GetAvailable() const { return tokens; }
|
||||
|
||||
private: //Should be POD basically
|
||||
uint64_t lastTime; //The last time this was updated
|
||||
uint32_t limit; //The bandwidth limit, in bytes per second
|
||||
uint32_t tokens; //The available bandwidth within this 1 second timeframe
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
98
Include/ZNet/ZNetClient.hpp
Normal file
98
Include/ZNet/ZNetClient.hpp
Normal file
@@ -0,0 +1,98 @@
|
||||
/*
|
||||
ZNetClient.hpp
|
||||
Author: Patrick Baggett <ptbaggett@762studios.com>
|
||||
Created: 7/11/2013
|
||||
|
||||
Purpose:
|
||||
|
||||
ZNetClient -- extends ZNetHost to provide a client
|
||||
|
||||
License:
|
||||
|
||||
Copyright 2013, 762 Studios
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef _ZNETCLIENT_HPP
|
||||
#define _ZNETCLIENT_HPP
|
||||
|
||||
#include <ZNet/ZNetHost.hpp>
|
||||
#include <ZNet/ZNetPeer.hpp>
|
||||
|
||||
class ZNetClient : public ZNetHost
|
||||
{
|
||||
public:
|
||||
ZNetClient();
|
||||
~ZNetClient();
|
||||
|
||||
/*
|
||||
ZNetClient::Update()
|
||||
|
||||
Implements ZNetHost::Update().
|
||||
|
||||
This should be called to read incoming network data and send outgoing traffic. Events
|
||||
are only generated by calling Update().
|
||||
|
||||
@return (int) - Less than 0: error. 0: OK
|
||||
*/
|
||||
int Update();
|
||||
|
||||
/*
|
||||
ZNetClient::Connect()
|
||||
|
||||
Initiates a connection to the given host. This method is asynchronous, so an event is
|
||||
generated. However, if this returns false, then no events will be generated because
|
||||
an error has occurred locally.
|
||||
*/
|
||||
bool Connect(SST_Socket socket, SST_NetAddress* addr, uint32_t nrChannels, uint32_t userData);
|
||||
|
||||
/*
|
||||
ZNetClient::SendPacket()
|
||||
|
||||
Sends a packet to the server via a certain channel. Use ZNetPacket::Release()
|
||||
when the packet is no longer needed.
|
||||
|
||||
@param packet - The packet to broadcast
|
||||
@param channelId - The channel ID
|
||||
*/
|
||||
void SendPacket(ZNetPacket* packet, uint32_t channelId);
|
||||
|
||||
|
||||
/*
|
||||
ZNetClient::Disconnect()
|
||||
|
||||
Begins a graceful disconnect. Update() should be called until an event of type DISCONNECT occurs,
|
||||
or a timeout happens. If a timeout is reached, Reset() should be used.
|
||||
|
||||
*/
|
||||
void Disconnect();
|
||||
|
||||
/*
|
||||
ZNetClient::Reset()
|
||||
|
||||
Disconnects from the server, but does not inform him/her that the disconnect has occurred.
|
||||
This should only be used when a graceful disconnect does not work or when aborting
|
||||
the client. No local event is generated, so any cleanup must be done immediately.
|
||||
*/
|
||||
void Reset();
|
||||
|
||||
/*
|
||||
ZNetClient::GetServer()
|
||||
|
||||
Gets the ZNetPeer object that represents the server. If the client is
|
||||
not connected, then this returns NULL.
|
||||
*/
|
||||
ZNetPeer* GetServer() const;
|
||||
|
||||
bool IsConnected() const { return connectedFlag; }
|
||||
|
||||
private:
|
||||
ZNetPeer server;
|
||||
bool connectedFlag;
|
||||
|
||||
/* Handle a raw packet sent by the server */
|
||||
void HandlePacket(const uint8_t* data, uint32_t dataSize);
|
||||
};
|
||||
|
||||
#endif
|
||||
44
Include/ZNet/ZNetConsts.hpp
Normal file
44
Include/ZNet/ZNetConsts.hpp
Normal file
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
ZNetConsts.hpp
|
||||
Author: Patrick Baggett <ptbaggett@762studios.com>
|
||||
Created: 6/5/2013
|
||||
|
||||
Purpose:
|
||||
|
||||
ZNet symbolic constants
|
||||
|
||||
License:
|
||||
|
||||
Copyright 2013, 762 Studios
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef _ZNETCONSTS_HPP
|
||||
#define _ZNETCONSTS_HPP
|
||||
|
||||
#define ZNET_MTU_IPV4SAFE 512 //Like ZNET_MTU_IPV4, but with slightly less space, allowing for 64 bytes of IP overhead via optional sections
|
||||
#define ZNET_MTU_IPV4 548 //Minimum maximum reassembly buffer size of 576 minus 28 bytes of overhead for UDPv4
|
||||
#define ZNET_MTU_ETHERNET 1500
|
||||
#define ZNET_MTU_IPV6 1280
|
||||
#define ZNET_MTU_IPV6SAFE 1232 //IPv6 required 1280 minus 48 for UDPv6+IPv6 header
|
||||
|
||||
#define ZNET_MAX_SERVER_SOCKETS 4 //Maximum number of sockets a server may listen on
|
||||
|
||||
//Flags for ZNetPacket::Initialize()
|
||||
#define ZNET_TRANSIENT 0x00000000u //< Default value. The packet is unreliable, but transient, so the newest copy is presented and older version discarded.
|
||||
#define ZNET_RELIABLE 0x00000001u //< This packet will be reliable.
|
||||
|
||||
|
||||
|
||||
//Peer state
|
||||
enum ZNetConnectionState
|
||||
{
|
||||
STATE_UNCONNECTED, //No connection(s) established
|
||||
STATE_HANDSHAKE, //Machine has attempted connection, awaiting handshake
|
||||
STATE_CONNECTED, //Machine is connected actively to a remote machine
|
||||
STATE_SERVING //Clients connected, actively serving them
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
45
Include/ZNet/ZNetEvent.hpp
Normal file
45
Include/ZNet/ZNetEvent.hpp
Normal file
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
ZNetEvent.hpp
|
||||
Author: Patrick Baggett <ptbaggett@762studios.com>
|
||||
Created: 6/5/2013
|
||||
|
||||
Purpose:
|
||||
|
||||
ZNet event structure
|
||||
|
||||
License:
|
||||
|
||||
Copyright 2013, 762 Studios
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef _ZNETEVENT_HPP
|
||||
#define _ZNETEVENT_HPP
|
||||
|
||||
class ZNetPeer;
|
||||
struct ZNetPacket;
|
||||
|
||||
enum ZNetEventType
|
||||
{
|
||||
ZNETEVENT_NONE, //No event
|
||||
ZNETEVENT_CONNECT, //A new incoming connection was made
|
||||
ZNETEVENT_DISCONNECT, //A graceful disconnection occurred
|
||||
ZNETEVENT_TIMEOUT, //A timeout occurred
|
||||
ZNETEVENT_DATA //Data was received
|
||||
};
|
||||
|
||||
//Event when connected
|
||||
struct ZNetEvent
|
||||
{
|
||||
ZNetPeer* remote; //The remote host
|
||||
ZNetPacket* packet; //The packet data
|
||||
uint32_t userdata; //The user data (if applicable)
|
||||
ZNetEventType type; //The type
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
184
Include/ZNet/ZNetHost.hpp
Normal file
184
Include/ZNet/ZNetHost.hpp
Normal file
@@ -0,0 +1,184 @@
|
||||
/*
|
||||
ZNetHost.hpp
|
||||
Author: Patrick Baggett <ptbaggett@762studios.com>
|
||||
Created: 7/10/2013
|
||||
|
||||
Purpose:
|
||||
|
||||
ZNet base class for shared client/server data
|
||||
|
||||
License:
|
||||
|
||||
Copyright 2013, 762 Studios
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef _ZNETHOST_HPP
|
||||
#define _ZNETHOST_HPP
|
||||
|
||||
#include <ZNet/ZNetBandwidthMeter.hpp>
|
||||
#include <ZNet/ZNetEvent.hpp>
|
||||
#include <ZSTL/ZList.hpp>
|
||||
|
||||
struct ZNetPacket;
|
||||
|
||||
class ZNetHost
|
||||
{
|
||||
public:
|
||||
ZNetHost();
|
||||
virtual ~ZNetHost() { }
|
||||
|
||||
/*
|
||||
ZNetHost::Update()
|
||||
|
||||
Fetches and sends data as necessary to perform the given role. See the
|
||||
documentation for the specific class. Generally, you need to call this
|
||||
each frame.
|
||||
|
||||
@return (int) - Less than 0: error. 0: OK
|
||||
*/
|
||||
virtual int Update() = 0;
|
||||
|
||||
/*
|
||||
ZNetHost::CreatePacket()
|
||||
|
||||
Creates a packet and copies the given initialization data (if any).
|
||||
|
||||
@param initData - Data to copy to the new packet, or NULL for uninitialized packet.
|
||||
@param dataSize - The size of the packet's payload
|
||||
@param flags - The flags. No flags defined, so must be 0
|
||||
*/
|
||||
ZNetPacket* CreatePacket(const void* initData, uint32_t dataSize, uint32_t flags);
|
||||
|
||||
/*
|
||||
ZNetHost::HasEvent()
|
||||
|
||||
Returns true if there are queued events. The next call to GetNextEvent()
|
||||
is guaranteed to succeed.
|
||||
|
||||
@return (bool) - True if at least one event is pending
|
||||
*/
|
||||
bool HasEvent() { return events.Size() > 0; }
|
||||
|
||||
/*
|
||||
ZNetHost::GetNextEvent()
|
||||
|
||||
Attempt to fetch the next event form the queue and returns
|
||||
whether one was fetched or not.
|
||||
|
||||
@param eventReturn - Pointer to ZNetEvent structure to receive event data
|
||||
@return (bool) - True if an event was returned, false if none was available (and eventReturn is not modified)
|
||||
*/
|
||||
bool GetNextEvent(ZNetEvent* eventReturn);
|
||||
|
||||
//======================================================================
|
||||
// TRIVIAL GETTER / SETTER
|
||||
//======================================================================
|
||||
|
||||
/*
|
||||
ZNetHost::SetIncomingBandwidth()
|
||||
|
||||
Sets the desired incoming bandwidth cap.
|
||||
|
||||
Note that this is a request made of the remote host; malicious hosts can still
|
||||
attempt DoS attacks by sending far above this limit.
|
||||
|
||||
@param bwIn - The target incoming bandwidth, measured in bytes per second.
|
||||
*/
|
||||
void SetIncomingBandwidth(uint32_t bwIn) { inBW.SetLimit(bwIn); }
|
||||
|
||||
/*
|
||||
ZNetHost::SetOutgoingBandwidth()
|
||||
|
||||
Sets the desired outgoing bandwidth cap.
|
||||
|
||||
@param bwOut - The target outgoing bandwidth, measured in bytes per second.
|
||||
*/
|
||||
void SetOutgoingBandwidth(uint32_t bwOut) { outBW.SetLimit(bwOut); }
|
||||
|
||||
/*
|
||||
ZNetHost::SetDropChance()
|
||||
|
||||
** DEBUG ONLY **
|
||||
|
||||
Sets the chance that a packet will be intentionally dropped. This is used to
|
||||
simulate high packet loss networks; it should not be used in production. As
|
||||
such, the percent chance defaults to 0. Values over 100 are treated as 100%.
|
||||
|
||||
@param _dropChance - The percent chance to drop. The value should be 0-99.
|
||||
*/
|
||||
void SetDropChance(uint32_t _dropChance) { dropChance = _dropChance; }
|
||||
|
||||
/*
|
||||
ZNetHost::SetMTU()
|
||||
|
||||
Sets the MTU used by ZNet. ZNet will not send raw packets larger than this;
|
||||
they will be fragmented into multiple calls into libsst-net. This typically less
|
||||
the MTU on the adapter, since the "path MTU" is minimum of all nodes between the
|
||||
two endpoints. The minimum MTU is clamped to 256 bytes.
|
||||
*/
|
||||
void SetMTU(uint32_t _mtu) { mtu = _mtu; if(mtu<256) mtu = 256; }
|
||||
|
||||
/*
|
||||
ZNetHost::GetIncomingBandwidth()
|
||||
|
||||
Gets the incoming bandwidth, in bytes per second.
|
||||
|
||||
@return (uint32_t) - The incoming bandwidth
|
||||
*/
|
||||
uint32_t GetIncomingBandwidth() const { return inBW.GetLimit(); }
|
||||
|
||||
/*
|
||||
ZNetHost::GetOutgoingBandwidth()
|
||||
|
||||
Gets the outgoing bandwidth, in bytes per second.
|
||||
|
||||
@return (uint32_t) - The outgoing bandwidth
|
||||
*/
|
||||
uint32_t GetOutgoingBandwidth() const { return outBW.GetLimit(); }
|
||||
|
||||
/*
|
||||
ZNetHost::GetDropChance()
|
||||
|
||||
** DEBUG ONLY **
|
||||
|
||||
Gets the chance to drop intentionally drop a packet. This should
|
||||
be zero unless testing network code.
|
||||
|
||||
@return (uint32_t) - The chance to drop a packet.
|
||||
*/
|
||||
uint32_t GetDropChance() const { return dropChance; }
|
||||
|
||||
/*
|
||||
ZNetHost::GetMTU()
|
||||
|
||||
Gets the ZNet maximum transmission unit.
|
||||
*/
|
||||
uint32_t GetMTU() const { return mtu; }
|
||||
|
||||
|
||||
protected: //These are used by ZNetServer/ZNetClient
|
||||
|
||||
void Reset(uint64_t time);
|
||||
|
||||
void AddEvent(const ZNetEvent* newEvent) { events.PushBack(*newEvent); }
|
||||
|
||||
//Send all channel data to peer
|
||||
bool SendToPeer(ZNetPeer* peer);
|
||||
|
||||
void TrySendPing(bool isReply, uint32_t givenToken, ZNetPeer* peer);
|
||||
void TrySendConnResp(uint32_t flags, uint32_t code);
|
||||
|
||||
ZNetBandwidthMeter inBW;
|
||||
ZNetBandwidthMeter outBW;
|
||||
|
||||
private:
|
||||
ZList<ZNetEvent> events;
|
||||
uint32_t mtu; //< Maximum (wire) size packet
|
||||
uint32_t dropChance; //< Chance to drop a packet
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
46
Include/ZNet/ZNetPacket.hpp
Normal file
46
Include/ZNet/ZNetPacket.hpp
Normal file
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
ZNetPacket.hpp
|
||||
Author: Patrick Baggett <ptbaggett@762studios.com>
|
||||
Created: 6/4/2013
|
||||
|
||||
Purpose:
|
||||
|
||||
ZNet packet class, represents a packet
|
||||
|
||||
License:
|
||||
|
||||
Copyright 2013, 762 Studios
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef _ZNETPACKET_HPP
|
||||
#define _ZNETPACKET_HPP
|
||||
|
||||
#include <pstdint.h>
|
||||
|
||||
/*
|
||||
ZNetPacket defines a logical packet that is to be sent or has been received. The data is appended
|
||||
at the end of the structure, so getting the address requires pointer manipulation. It does
|
||||
not represent the wire format of what is sent, since packets may be merged.
|
||||
*/
|
||||
|
||||
struct ZNetPacket
|
||||
{
|
||||
uint32_t dataSize; //< Size of the packet (logically)
|
||||
uint32_t flags; //< The flags. ZNET_TRANSIENT, ZNET_RELIABLE, etc.
|
||||
int32_t refCount; //< Reference count
|
||||
|
||||
uint8_t* GetData() { return (uint8_t*) ((uintptr_t)this + sizeof(ZNetPacket)); }
|
||||
void AddReference() { refCount++; }
|
||||
void ReleaseReference()
|
||||
{
|
||||
refCount--;
|
||||
if(refCount == 0)
|
||||
free(this);
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
165
Include/ZNet/ZNetPacketChannel.hpp
Normal file
165
Include/ZNet/ZNetPacketChannel.hpp
Normal file
@@ -0,0 +1,165 @@
|
||||
/*
|
||||
ZNetPacketChannel.hpp
|
||||
Author: Patrick Baggett <ptbaggett@762studios.com>
|
||||
Created: 6/14/2013
|
||||
|
||||
Purpose:
|
||||
|
||||
** NOT PART OF PUBLIC SDK **
|
||||
This class is not part of the public SDK; its fields and methods are not present
|
||||
in the documentation and cannot be guaranteed in future revisions.
|
||||
** NOT PART OF PUBLIC SDK **
|
||||
|
||||
Queue of incoming and outgoing packets.
|
||||
|
||||
License:
|
||||
|
||||
Copyright 2013, 762 Studios
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef _ZNETPACKETCHANNEL_HPP
|
||||
#define _ZNETPACKETCHANNEL_HPP
|
||||
|
||||
#include <ZSTL/ZList.hpp>
|
||||
#include <ZNet/ZNetConsts.hpp>
|
||||
|
||||
struct ZNetPacket;
|
||||
class ZNetHost;
|
||||
|
||||
namespace ZNetPrivate { struct ZNetMessageContainer; } //urgh
|
||||
|
||||
class ZNetPacketChannel
|
||||
{
|
||||
public:
|
||||
struct ZNetQueuedPacket
|
||||
{
|
||||
uint64_t timeSent; //< Time this packet was sent (or 0 for never)
|
||||
ZNetPacket* packet; //< Logical packet data (payload)
|
||||
uint32_t subsequence; //< For data packets, this is the number of bytes successfully acked on the remote end
|
||||
uint32_t command; //< Logical packet command such as ZNETCMD_CONNECT, ZNETCMD_DATA, ...
|
||||
uint16_t sequence; //< Logical packet sequence
|
||||
};
|
||||
|
||||
ZNetPacketChannel() :
|
||||
packetCount(0), overflowLimit(1024), localAck(0), remoteAck(0), nextSequenceNumber(1), critical(false)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void SetOverflowThreshold(uint32_t _overflowLimit) { overflowLimit = _overflowLimit; }
|
||||
|
||||
|
||||
/*
|
||||
ZNetPacketChannel::QueueForSending()
|
||||
|
||||
Attempts to queue a new packet to the channel. If the overflow limit is reached,
|
||||
this returns false and the client should be disconnected.
|
||||
*/
|
||||
bool QueueForSending(ZNetPacket* packet, uint32_t command);
|
||||
|
||||
bool QueueForReceiving();
|
||||
|
||||
|
||||
/*
|
||||
ZNetPacketChannel::SetChannelId()
|
||||
|
||||
Sets the channel's ID value for use in outgoing packets.
|
||||
*/
|
||||
void SetChannelId(uint32_t chId) { channelId = chId; }
|
||||
|
||||
/*
|
||||
ZNetPacketChannel::FillBuffer()
|
||||
|
||||
Fills a buffer with as many packets as the buffer can hold. If all packets
|
||||
have been added, this returns true. If there was not enough space to hold
|
||||
all of the packets, this returns false and the index to resume at is provided.
|
||||
|
||||
@param buffer - Input buffer pointer
|
||||
@param bufferSize - The size of the buffer pointed to by buffer[]
|
||||
@param packetStartIndex - The starting index. Should start at 0, and use the value returned in restartIndexReturn to resume
|
||||
@param restartIndexReturn - The index to resume packet storage.
|
||||
@param bytesWritten - The number of bytes written
|
||||
*/
|
||||
bool FillBuffer(uint8_t* buffer, uint32_t bufferSize, uint32_t packetStartIndex, uint32_t* restartIndexReturn, uint32_t* bytesWritten);
|
||||
|
||||
/*
|
||||
ZNetPacketChannel::Deinitialize()
|
||||
*/
|
||||
void Deinitialize();
|
||||
|
||||
|
||||
/*
|
||||
ZNetPacketChannel::UpdateRemoteAck()
|
||||
|
||||
Updates the remote ack counter and dequeues packets as necessary.
|
||||
|
||||
@param newHighest - The new highest sequence number
|
||||
@param pingAdjust - Set to the current ping value, this value is adjusted by the RTT on a per-packet basis
|
||||
*/
|
||||
void UpdateRemoteAck(uint16_t newHighest, int32_t* pingAdjust);
|
||||
|
||||
/*
|
||||
ZNetPacketChannel::UpdateLocalAck()
|
||||
|
||||
Updates the local sequence counter for this time period.
|
||||
*/
|
||||
void UpdateLocalAck(uint16_t seq);
|
||||
|
||||
/*
|
||||
ZNetPacketChannel::QueueLocally()
|
||||
|
||||
Queue a received packet for local consumption. Since packets have an ordering and they may be received out of
|
||||
order (e.g. send 1, 2, 3 may be processed as 2, 1, 3), this allows ZNet to reorder them and generate the
|
||||
appropriate sequence of events.
|
||||
*/
|
||||
bool QueueLocally(const ZNetPacketChannel::ZNetQueuedPacket* container);
|
||||
|
||||
/*
|
||||
ZNetPacketChannel::QueueData()
|
||||
|
||||
Queue a received data packet. This has one of three effects:
|
||||
1) Full data packet received (e.g. short packet), so it just acts like QueueLocally()
|
||||
2) Fragmented data packet, did not exist before now -- creates a reassembly buffer.
|
||||
3) Fragmented data packet, did exist -- adds to reassembly and check if reassembly is complete. If it is, QueueLocally().
|
||||
*/
|
||||
bool QueueData(ZNetPrivate::ZNetMessageContainer* data);
|
||||
|
||||
void ProcessLocalAcks();
|
||||
|
||||
void SetHost(ZNetHost* _host) { host = _host; }
|
||||
|
||||
ZNetHost* GetHost() const { return host; }
|
||||
|
||||
uint16_t GetLocalAck() { return localAck; }
|
||||
|
||||
//Return the highest sequence number for this channel. This is one less than the "next", intuitively.
|
||||
uint16_t GetHighestSent() { return nextSequenceNumber == 0 ? UINT16_MAX : nextSequenceNumber; }
|
||||
private:
|
||||
|
||||
struct ZNetDataReassemblyPacket
|
||||
{
|
||||
ZNetPacket* packet; //< Logical packet data (not yet fully assembled)
|
||||
uint32_t subsequence; //< Highest contiguous amount of data received
|
||||
uint16_t sequence; //< The sequence number of this packet
|
||||
};
|
||||
|
||||
ZList<ZNetQueuedPacket> packets; //List of packets we've sent (or will send) but have not yet been acknowledged
|
||||
ZList<ZNetDataReassemblyPacket> reassembly;
|
||||
ZList<ZNetQueuedPacket> assembled;
|
||||
ZList<uint16_t> sequencesFound; //The sequence numbers found this time around (sorted)
|
||||
ZNetHost* host; //Owner (used for memory allocations)
|
||||
uint32_t packetCount; //ZList::Size() is O(n), keep track manually
|
||||
uint32_t overflowLimit; //When this many outgoing packets are unacknowledged,
|
||||
uint32_t channelId; //This channel's ID value for outgoing packets
|
||||
uint16_t localAck; //Local acknowledge counter (i.e. highest number of incoming packets we've confirmed)
|
||||
uint16_t remoteAck; //Remote acknowledge counter (i.e. highest number the remote host has told us it has confirmed)
|
||||
uint16_t nextSequenceNumber; //Next outgoing sequence number
|
||||
|
||||
bool critical; //Is the remote host in a critical state?
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
143
Include/ZNet/ZNetPeer.hpp
Normal file
143
Include/ZNet/ZNetPeer.hpp
Normal file
@@ -0,0 +1,143 @@
|
||||
/*
|
||||
ZNetPeer.hpp
|
||||
Author: Patrick Baggett <ptbaggett@762studios.com>
|
||||
Created: 6/5/2013
|
||||
|
||||
Purpose:
|
||||
|
||||
ZNet peer class, representing a remote host
|
||||
|
||||
License:
|
||||
|
||||
Copyright 2013, 762 Studios
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef _ZNETPEER_HPP
|
||||
#define _ZNETPEER_HPP
|
||||
|
||||
#include <SST/SST_Net.h>
|
||||
#include <ZNet/ZNetConsts.hpp>
|
||||
#include <ZNet/ZNetPacketChannel.hpp>
|
||||
|
||||
class ZNetPeer;
|
||||
class ZNetServer;
|
||||
|
||||
class ZNetPeer
|
||||
{
|
||||
public:
|
||||
ZNetPeer();
|
||||
~ZNetPeer() { Deinitialize(); }
|
||||
|
||||
/*
|
||||
ZNetPeer::SetUserData()
|
||||
|
||||
Sets the user data for this peer. This value is not
|
||||
modified or inspected by ZNet. It defaults to NULL.
|
||||
|
||||
@param ud - The user data
|
||||
*/
|
||||
void SetUserData(void* ud) { userdata = ud; }
|
||||
|
||||
/*
|
||||
ZNetPeer:GetUserData()
|
||||
|
||||
Gets the user data for this peer.
|
||||
|
||||
@return (void*) - The user data
|
||||
*/
|
||||
void* GetUserData() { return userdata; }
|
||||
|
||||
/*
|
||||
ZNetPeer::GetNetAddress()
|
||||
|
||||
Gets the network address that this remote host uses.
|
||||
|
||||
@return (const SST_NetAddress*) - The remote host's network address
|
||||
*/
|
||||
const SST_NetAddress* GetNetAddress() const { return &addr; }
|
||||
|
||||
|
||||
/*
|
||||
ZNetPeer::GetState()
|
||||
|
||||
Gets the remote host's state. TODO: Is this necessary for public API?
|
||||
|
||||
@return (ZNetConnectionState) - The connection state
|
||||
*/
|
||||
ZNetConnectionState GetState() const { return state; }
|
||||
|
||||
/*
|
||||
ZNetPeer::GetSocket()
|
||||
|
||||
Gets the socket that was is used to send/receive from the remote host.
|
||||
*/
|
||||
SST_Socket GetSocket() const { return socketCopy; }
|
||||
|
||||
/*
|
||||
ZNetPeer::GetPing()
|
||||
|
||||
Gets the approximate ping. Note that the ping value is only updated
|
||||
when a packet is received, so during a disconnect event, this would not
|
||||
be accurate. Use GetLastReceived() to find the time since the last packet.
|
||||
|
||||
@return (int32_t) - The last known ping value. If < 0, then the ping is unknown.
|
||||
*/
|
||||
int32_t GetPing() { return ping; }
|
||||
|
||||
/*
|
||||
Gets the timestamp at which the last valid packet was received. Applications
|
||||
can use this as a sort of "health" meter for the link and decide how to change
|
||||
things such as client predictions during times of high latency. A value of 0
|
||||
indicates that no valid packet has yet been received. To compare timestamps,
|
||||
use SST_OS_GetMilliTime(). Note that only *valid* packets are considered; so
|
||||
hosts sending incompatible data are not considered.
|
||||
|
||||
@return (uint64_t) - The timestamp of the last valid packet.
|
||||
*/
|
||||
uint64_t GetLastReceived() { return lastValidIncoming; }
|
||||
|
||||
private:
|
||||
|
||||
/* Initialize the peer */
|
||||
bool Initialize(ZNetHost* _host, const SST_NetAddress* newAddr, SST_Socket s, uint32_t nrChannels);
|
||||
|
||||
void Deinitialize();
|
||||
|
||||
void SetState(ZNetConnectionState s) { state = s; }
|
||||
void SetLastReceived(uint64_t ts) { lastValidIncoming = ts; }
|
||||
void SetPing(int32_t _ping) { ping = _ping; }
|
||||
|
||||
|
||||
uint32_t GetNumberChannels() const { return nrChannels; }
|
||||
|
||||
ZNetPacketChannel* GetPacketChannel(uint32_t chId);
|
||||
|
||||
|
||||
//Process all received packets' sequence number to come up with a
|
||||
//new sequence number to tell the remote server that we've received.
|
||||
void ProcessLocalAcks();
|
||||
|
||||
void SendAcksForAllChannels();
|
||||
|
||||
friend class ZNetHost;
|
||||
friend class ZNetClient;
|
||||
friend class ZNetServer;
|
||||
|
||||
SST_NetAddress addr; //Remote address
|
||||
uint64_t lastValidIncoming; //Last time a valid packet was received
|
||||
uint64_t lastOutgoingAck; //Last time an outgoing ACK was sent, or 0 for never.
|
||||
SST_Socket socketCopy; //Copy of the socket that was used connect to this peer
|
||||
ZNetPacketChannel* channels; //The packet channels
|
||||
void* userdata; //User data
|
||||
uint32_t nrChannels; //Size of channels[] array
|
||||
int32_t ping; //Estimated ping
|
||||
ZNetConnectionState state; //Connection state
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
240
Include/ZNet/ZNetServer.hpp
Normal file
240
Include/ZNet/ZNetServer.hpp
Normal file
@@ -0,0 +1,240 @@
|
||||
/*
|
||||
ZNetServer.hpp
|
||||
Author: Patrick Baggett <ptbaggett@762studios.com>
|
||||
Created: 7/10/2013
|
||||
|
||||
Purpose:
|
||||
|
||||
ZNetServer -- extends ZNetHost to provide a server
|
||||
|
||||
License:
|
||||
|
||||
Copyright 2013, 762 Studios
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef _ZNETSERVER_HPP
|
||||
#define _ZNETSERVER_HPP
|
||||
|
||||
#include <ZNet/ZNetHost.hpp>
|
||||
#include <ZNet/ZNetConsts.hpp>
|
||||
#include <ZSTL/ZHashMap.hpp>
|
||||
#include <SST/SST_Net.h>
|
||||
|
||||
typedef uint32_t (*ZNetConnectCallback)(const SST_NetAddress* addr, uint32_t userdata, void* callbackParam);
|
||||
|
||||
|
||||
class ZNetServer : public ZNetHost
|
||||
{
|
||||
public:
|
||||
|
||||
ZNetServer();
|
||||
~ZNetServer();
|
||||
|
||||
/*
|
||||
ZNetServer::Initialize()
|
||||
|
||||
Initializes the ZNetServer instance.
|
||||
|
||||
*/
|
||||
bool Initialize(uint32_t peerCount, uint32_t channelCount);
|
||||
|
||||
/*
|
||||
ZNetServer::AddSocket()
|
||||
|
||||
Adds a socket for ZNet to listen on. ZNet may listen on multiple
|
||||
sockets, but once a socket is added, it cannot be removed. This
|
||||
limit may be lifted. Only up to ZNET_MAX_SERVER_SOCKETS can be
|
||||
added.
|
||||
|
||||
@param s - The socket to listen on.
|
||||
@return (bool) - True if successful, false otherwise
|
||||
*/
|
||||
bool AddSocket(SST_Socket s);
|
||||
|
||||
/*
|
||||
ZNetServer::Update()
|
||||
|
||||
Checks sockets and packet queues for incoming/outgoing traffic. Use GetEvent() to
|
||||
fetch events generated.
|
||||
|
||||
@return (int) - Less than 0: error. 0: OK
|
||||
*/
|
||||
int Update();
|
||||
|
||||
/*
|
||||
ZNetServer::SendPacket()
|
||||
|
||||
Sends a packet to a peer via a certain channel. Use ZNetPacket::Release()
|
||||
when the packet is no longer needed.
|
||||
|
||||
@param packet - The packet to broadcast
|
||||
@param peer - The remote host to send to
|
||||
@param channelId - The channel ID
|
||||
*/
|
||||
void SendPacket(ZNetPacket* packet, ZNetPeer* peer, uint8_t channelId);
|
||||
|
||||
/*
|
||||
ZNetServer::BroadcastPacket()
|
||||
|
||||
Sends a packet to all peers via a certain channel. Use ZNetPacket::Release()
|
||||
when the packet is no longer needed.
|
||||
|
||||
@param packet - The packet to broadcast
|
||||
@param channelId - The channel ID
|
||||
*/
|
||||
void BroadcastPacket(ZNetPacket* packet, uint8_t channelId);
|
||||
|
||||
/*
|
||||
ZNetServer::DisconnectPeer()
|
||||
|
||||
Gracefully disconnects a peer. The peer is sent a message letting him/her
|
||||
that he/she has been disconnected and awaiting confirmation. The reason code
|
||||
parameter is sent to the peer.
|
||||
|
||||
@param peer - The peer to signal a disconnect to
|
||||
@param reasonCode - The application-specific reason code. This is not interpreted by ZNet in any way.
|
||||
*/
|
||||
void DisconnectPeer(ZNetPeer* peer, uint32_t reasonCode);
|
||||
|
||||
/*
|
||||
ZNetServer::ResetPeer()
|
||||
|
||||
Disconnects the peer, but does not inform him/her that the disconnect has occurred.
|
||||
This should only be used when a graceful disconnect does not work or when aborting
|
||||
the server. No local event is generated, so any cleanup of the peer must be done
|
||||
immediately.
|
||||
|
||||
@param packet - The packet to broadcast
|
||||
@param channelId - The channel ID
|
||||
*/
|
||||
void ResetPeer(ZNetPeer* peer);
|
||||
|
||||
/*
|
||||
ZNetServer::NextPeer()
|
||||
|
||||
Gets the next peer in list of peers. The ordering is completely arbitrary and should not be
|
||||
relied on, thus you should only pass NULL or the return value from an earlier NextPeer() call.
|
||||
|
||||
This can be used to iterate through the list of peers:
|
||||
|
||||
ZNetPeer* p = Server->NextPeer(NULL);
|
||||
while(p)
|
||||
{
|
||||
DoSomethingWithPeer(p);
|
||||
p = Server->NextPeer(p);
|
||||
}
|
||||
|
||||
@param thisPeer - The peer to get the next of, or NULL to start.
|
||||
@return (ZNetPeer*) - The next peer, or NULL if reached the end.
|
||||
*/
|
||||
ZNetPeer* NextPeer(ZNetPeer* thisPeer);
|
||||
|
||||
//======================================================================
|
||||
// TRIVIAL GETTER / SETTER
|
||||
//======================================================================
|
||||
|
||||
/*
|
||||
ZNetServer::SetListenFlag()
|
||||
|
||||
Sets the listen flag. When true, the server reports incoming connections
|
||||
for normal processing. When false, the server does not report incoming connections
|
||||
and automatically rejects them.
|
||||
|
||||
@param _listenFlag - The new value for the listen flag
|
||||
*/
|
||||
void SetListenFlag(bool _listenFlag) { listenFlag = _listenFlag; }
|
||||
|
||||
/*
|
||||
ZNetServer::SetConnectCallback()
|
||||
|
||||
Sets the connection callback. When non-NULL, the server calls this function when
|
||||
a connection attempt is made. Returning 0 indicates the client should be accepted,
|
||||
while any other value indicates that the client should be rejected. If no function
|
||||
is present, the server automatically accepts the client. This should be used to
|
||||
implement ban lists.
|
||||
|
||||
@param fn - The new callback function, or NULL to disable it
|
||||
*/
|
||||
void SetConnectCallback(ZNetConnectCallback fn) { connectCallback = fn; }
|
||||
|
||||
/*
|
||||
ZNetServer::SetCallbackParam()
|
||||
|
||||
Sets the parameter that is passed to the callback. It defaults to NULL.
|
||||
|
||||
@param param - The callback parameter
|
||||
*/
|
||||
void SetCallbackParam(void* param) { callbackParam = param; }
|
||||
|
||||
/*
|
||||
ZNetServer::GetListenFlag()
|
||||
|
||||
Gets the listen flag. See ZNetServer::SetListenFlag() for a description of the
|
||||
listen flag.
|
||||
|
||||
@return (bool) - The value of the listen flag
|
||||
*/
|
||||
bool GetListenFlag() const { return listenFlag; }
|
||||
|
||||
/*
|
||||
ZNetServer::GetMaximumClientCount()
|
||||
|
||||
Gets the maximum number of clients that may be simultaneously connected.
|
||||
|
||||
@return (uint32_t) - The maximum number of clients
|
||||
*/
|
||||
uint32_t GetMaximumClientCount() const { return maxClients; }
|
||||
|
||||
/*
|
||||
ZNetServer::GetClientCount()
|
||||
|
||||
Gets the number of clients who are currently connected.
|
||||
|
||||
@return (uint32_t) - The number of clients who are connected.
|
||||
*/
|
||||
uint32_t GetClientCount() const { return clientCount; }
|
||||
|
||||
/*
|
||||
ZNetServer::GetConnectCallback()
|
||||
|
||||
Gets the currently installed callback function, or NULL if none is
|
||||
present.
|
||||
|
||||
@return (ZNetConnectCallback) - The connect callback
|
||||
*/
|
||||
ZNetConnectCallback GetConnectCallback() { return connectCallback; }
|
||||
|
||||
/*
|
||||
ZNetServer::GetCallbackParam()
|
||||
|
||||
Gets the parameter that is passed to the callback function. This
|
||||
defaults to NULL.
|
||||
|
||||
@return (void*) - The callback parameter
|
||||
*/
|
||||
void* GetCallbackParam() { return callbackParam; }
|
||||
private:
|
||||
ZNetPeer* peers; //< The number of peers
|
||||
SST_Socket sockets[ZNET_MAX_SERVER_SOCKETS]; //< The sockets that ZNet can listen on
|
||||
ZNetConnectCallback connectCallback;
|
||||
void* callbackParam;
|
||||
uint32_t channelCount; //< The number of channels
|
||||
uint32_t maxClients; //< The maximum number of clients
|
||||
uint32_t clientCount; //< The current number of clients
|
||||
bool listenFlag; //< The listen flag
|
||||
|
||||
|
||||
|
||||
void HandlePacket(SST_Socket s, const SST_NetAddress* addr, const uint8_t* data, uint32_t length);
|
||||
|
||||
void TrySendConnResp(SST_Socket s, const SST_NetAddress* addr, uint32_t reasonCode, uint32_t flags);
|
||||
|
||||
ZNetPeer* PeerForAddress(const SST_NetAddress* addr) const;
|
||||
|
||||
ZNetPeer* FindEmptyPeerSlot();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
49
Include/ZNet/ZNetUtil.hpp
Normal file
49
Include/ZNet/ZNetUtil.hpp
Normal file
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
ZNetUtil.hpp
|
||||
Author: Patrick Baggett <ptbaggett@762studios.com>
|
||||
Created: 6/5/2013
|
||||
|
||||
Purpose:
|
||||
|
||||
ZNet utility functions
|
||||
|
||||
License:
|
||||
|
||||
Copyright 2013, 762 Studios
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef _ZNETUTIL_HPP
|
||||
#define _ZNETUTIL_HPP
|
||||
|
||||
#include <ZUtil/ZBinaryBufferReader.hpp>
|
||||
#include <ZUtil/ZBinaryBufferWriter.hpp>
|
||||
#include <ZNet/ZNetPacket.hpp>
|
||||
|
||||
namespace ZNetUtil
|
||||
{
|
||||
/*
|
||||
ZNetUtil::ReaderForPacket
|
||||
|
||||
Constructs a ZBinaryBufferReader for the given packet to read it.
|
||||
|
||||
@param packet - The packet to read
|
||||
@return (ZBinaryBufferReader) - The reader class
|
||||
*/
|
||||
inline ZBinaryBufferReader ReaderForPacket(ZNetPacket* packet) { return ZBinaryBufferReader(packet->data, packet->dataSize, ZNET_BYTEORDER); }
|
||||
|
||||
/*
|
||||
ZNetUtil::WriterForPacket
|
||||
|
||||
Constructs a ZBinaryBufferWriter for the given packet to read it.
|
||||
|
||||
@param packet - The packet to read
|
||||
@return (ZBinaryBufferWriter) - The writer class
|
||||
*/
|
||||
inline ZBinaryBufferWriter WriterForPacket(ZNetPacket* packet) { return ZBinaryBufferWriter(packet->data, packet->dataSize, ZNET_BYTEORDER); }
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
288
Include/ZRenderer/ZDataBuffer.hpp
Normal file
288
Include/ZRenderer/ZDataBuffer.hpp
Normal file
@@ -0,0 +1,288 @@
|
||||
/*
|
||||
ZDataBuffer.hpp
|
||||
Author: James Russell <jcrussell@762studios.com>
|
||||
Created: 3/20/2011
|
||||
|
||||
Purpose:
|
||||
|
||||
Interface for graphics device buffered memory, used for uniform buffers, vertex buffers, and
|
||||
index buffers.
|
||||
|
||||
Note that ZDataBuffer is a ZRendererResource, and should be used as such.
|
||||
|
||||
License:
|
||||
|
||||
TODO
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef _ZDATABUFFER_HPP
|
||||
#define _ZDATABUFFER_HPP
|
||||
|
||||
#include <ZRenderer/ZRendererResource.hpp>
|
||||
|
||||
#include <ZSTL/ZArray.hpp>
|
||||
|
||||
//Forward Declarations
|
||||
class ZDataBuffer;
|
||||
|
||||
//The type of data buffer
|
||||
enum ZDataBufferType
|
||||
{
|
||||
ZDBT_VERTEX, //Contains Vertex Data
|
||||
ZDBT_INDEX, //Contains Index Data
|
||||
ZDBT_UNIFORM, //Contains Uniform (Constant) Data
|
||||
ZDBT_SIZE
|
||||
};
|
||||
|
||||
//The usage type of the data buffer
|
||||
enum ZDataBufferUsage
|
||||
{
|
||||
ZDBU_STATIC, //Static Buffer (never or rarely updated)
|
||||
ZDBU_DYNAMIC, //Dynamic Buffer (updated frequently)
|
||||
ZDBU_STREAMING, //Streaming Buffer (updated every frame)
|
||||
ZDBU_SIZE
|
||||
};
|
||||
|
||||
//The data type in a stream
|
||||
enum ZDataBufferStreamType
|
||||
{
|
||||
ZDBST_FLOAT32, //32-bit floating point
|
||||
ZDBST_FLOAT64, //64-bit floating point
|
||||
ZDBST_INT8, //8-bit integer, signed
|
||||
ZDBST_INT16, //16-bit integer, signed
|
||||
ZDBST_INT32, //32-bit integer, signed
|
||||
ZDBST_UINT8, //8-bit integer, unsigned
|
||||
ZDBST_UINT16, //16-bit integer, unsigned
|
||||
ZDBST_UINT32, //32-bit integer, unsigned
|
||||
ZDBST_SIZE
|
||||
};
|
||||
|
||||
//The data type in a block
|
||||
enum ZDataBufferBlockType
|
||||
{
|
||||
ZDBBT_UNIFORM, //Uniform Data
|
||||
ZDBBT_INDEX8, //8-bit index data
|
||||
ZDBBT_INDEX16, //16-bit index data
|
||||
ZDBBT_INDEX32, //32-bit index data
|
||||
ZDBBT_SIZE
|
||||
};
|
||||
|
||||
//Struct for stream definitions
|
||||
struct ZDataBufferStream
|
||||
{
|
||||
ZDataBuffer* Buffer; //Parent buffer that contains this stream
|
||||
size_t ElementSize; //Size of an element in terms of data type (e.g., 2 for vec2, 3 for vec3, etc.)
|
||||
size_t Offset; //Offset (in bytes) that this stream starts from beginning of data buffer
|
||||
size_t Stride; //Distance (in bytes) between elements of this stream
|
||||
ZDataBufferStreamType Type; //Type of data in each element of this stream (this gives us size of each unit of data)
|
||||
bool Normalize; //true: fixed point value converted to [0,1] or [-1,1] range; false: typecasted.
|
||||
};
|
||||
|
||||
//Struct for block definitions
|
||||
struct ZDataBufferBlock
|
||||
{
|
||||
ZDataBufferBlockType Type; //Type of data contained by this block
|
||||
|
||||
size_t Offset; //Offset (in bytes) into the buffer where this block begins
|
||||
size_t Size; //Size (in bytes) of the block
|
||||
|
||||
ZDataBuffer* Buffer; //Parent buffer that contains this block data
|
||||
};
|
||||
|
||||
//Wrapper class for data buffers
|
||||
class ZDataBuffer : public ZRendererResource
|
||||
{
|
||||
private:
|
||||
DISABLE_COPY_AND_ASSIGN(ZDataBuffer);
|
||||
|
||||
public:
|
||||
//Default Constructor
|
||||
ZDataBuffer() : ZRendererResource() { }
|
||||
|
||||
//Virtual Destructor
|
||||
virtual ~ZDataBuffer() { }
|
||||
|
||||
/*
|
||||
virtual public ZDataBuffer::DefineBlock
|
||||
|
||||
Defines a block of data present in the buffer. Examples of blocks include
|
||||
index blocks and uniform buffer storage blocks.
|
||||
|
||||
@param _type - the type of block (index or uniform)
|
||||
@param _size - the size of the block (in bytes)
|
||||
@return (const ZDataBufferBlock*) - the data buffer block created
|
||||
@context (all)
|
||||
*/
|
||||
virtual const ZDataBufferBlock* DefineBlock(ZDataBufferBlockType _type,
|
||||
size_t _size
|
||||
) = 0;
|
||||
/*
|
||||
virtual public ZDataBuffer::DefineStream
|
||||
|
||||
Defines a stream that is present in this buffer. Examples of streams include
|
||||
the position stream (vertex coordinates), the color stream, the normal stream,
|
||||
and uv coordinate streams. Other streams can be defined so as to be usable by
|
||||
shader programs.
|
||||
|
||||
@param _type - The type of stream.
|
||||
@param _elemCount - The number of elements in the stream, e.g., 3D position has an element
|
||||
count of 3, 2D position has an element count of 2, etc...
|
||||
@param _offset - The offset into the buffer (in bytes) where this stream begins
|
||||
@param _stride - The stride between beginnings of consecutive elements (in bytes), or 0 for packed elements
|
||||
@param _normalize - If true, fixed point data should be normalized (i.e. changed to [0,1] or [-1,1] if unsigned/signed), otherwise
|
||||
it is converted similar to a C typecast, i.e. 'float value = (float)fixedValue'
|
||||
@return (const ZDataBufferStream*) - the data buffer stream created
|
||||
@context (all)
|
||||
*/
|
||||
virtual const ZDataBufferStream* DefineStream(ZDataBufferStreamType _type,
|
||||
size_t _elemCount,
|
||||
size_t _offset,
|
||||
size_t _stride,
|
||||
bool _normalize
|
||||
) = 0;
|
||||
|
||||
/*
|
||||
virtual public ZDataBuffer::Fill
|
||||
|
||||
Fills the buffer with data, as specified. This is equivalent to calling
|
||||
'MapBuffer', filling the buffer, and calling 'UnmapBuffer'.
|
||||
|
||||
@param _data - the data to fill the buffer with
|
||||
@param _offset - offset into the buffer to start copying to
|
||||
@param _byteCount - number of bytes to copy from _data
|
||||
@return (bool) - true if this update was successful, false if the buffer is 'locked' or 'contended'
|
||||
@context (all)
|
||||
*/
|
||||
virtual bool Fill(const void* _data,
|
||||
size_t _offset,
|
||||
size_t _byteCount
|
||||
) = 0;
|
||||
|
||||
/*
|
||||
virtual public ZDataBuffer::GetBlock
|
||||
|
||||
Gets the pointer to a block previously defined using DefineBlock().
|
||||
|
||||
@param index - The block's index. The first block created with DefineBlock() is 0, the second is 1, and so on.
|
||||
@return ( const ZDataBufferBlock*) - block definition
|
||||
@context (all)
|
||||
*/
|
||||
virtual const ZDataBufferBlock* GetBlock(size_t index) = 0;
|
||||
|
||||
/*
|
||||
virtual public ZDataBuffer::GetStream
|
||||
|
||||
Gets the pointer to a stream previously defined using DefineStream().
|
||||
|
||||
@param index - The stream's index. The first stream created with DefineStream() is 0, the second is 1, and so on.
|
||||
@return (const ZDataBufferStream*) - stream definition
|
||||
@context (all)
|
||||
*/
|
||||
virtual const ZDataBufferStream* GetStream(size_t index) = 0;
|
||||
|
||||
/*
|
||||
virtual public ZDataBuffer::GetBlockCount
|
||||
|
||||
Gets the number of blocks that have been defined so far.
|
||||
|
||||
@return (size_t) - The number of blocks defined with DefineBlock()
|
||||
@context (all)
|
||||
*/
|
||||
virtual size_t GetBlockCount() const = 0;
|
||||
|
||||
/*
|
||||
virtual public ZDataBuffer::GetStreamCount
|
||||
|
||||
Gets the number of streams that have been defined so far.
|
||||
|
||||
@return (size_t) - The number of blocks defined with DefineStream()
|
||||
@context (all)
|
||||
*/
|
||||
virtual size_t GetStreamCount() const = 0;
|
||||
|
||||
|
||||
/*
|
||||
virtual public ZDataBuffer::GetSize
|
||||
|
||||
Gets the size of this data buffer.
|
||||
|
||||
@return (size_t) - the size (in bytes) of this buffer
|
||||
@context (all)
|
||||
*/
|
||||
virtual size_t GetSize() = 0;
|
||||
|
||||
/*
|
||||
virtual public ZDataBuffer::GetType
|
||||
|
||||
Gets the type of this data buffer.
|
||||
|
||||
@return (ZDataBufferType) - the buffer type
|
||||
@context (all)
|
||||
*/
|
||||
virtual ZDataBufferType GetType() = 0;
|
||||
|
||||
/*
|
||||
virtual public ZDataBuffer::GetUsage
|
||||
|
||||
Gets the usage of this data buffer.
|
||||
|
||||
@return (ZDataBufferUsage) - the usage type
|
||||
@context (all)
|
||||
*/
|
||||
virtual ZDataBufferUsage GetUsage() = 0;
|
||||
|
||||
/*
|
||||
virtual public ZDataBuffer::Map
|
||||
|
||||
Maps the data buffer into user memory and marks this resource as locked until 'UnmapBuffer' is called.
|
||||
|
||||
If the discard parameter is set to true, this tells the implementation that the data
|
||||
that is currently present in the buffer is not required, and this may result in a faster
|
||||
return, especially in the case of static usage buffers. If the current data is needed
|
||||
(discard is false), static usage buffers must wait for the render thread to get the data
|
||||
from the graphics memory. Dynamic and streaming usage buffers typically suffer no
|
||||
performance penalty regardless of the value of the discard parameter, though this may
|
||||
vary based on implementation.
|
||||
|
||||
@param _discard - hint to the implementation that the data in the buffer can be discarded
|
||||
@return (void*) - pointer to the buffer in mapped memory, NULL if this buffer is 'locked' or 'contended'
|
||||
@context (all)
|
||||
*/
|
||||
virtual void* Map(bool _discard = false) = 0;
|
||||
|
||||
/*
|
||||
virtual public ZDataBuffer::UndefBlocks
|
||||
|
||||
Undefines all currently set blocks. This will invalidate existing block
|
||||
definition structures returned from DefineBlock.
|
||||
|
||||
@return (void)
|
||||
@context (all)
|
||||
*/
|
||||
virtual void UndefBlocks() = 0;
|
||||
|
||||
/*
|
||||
virtual public ZDataBuffer::UndefStreams
|
||||
|
||||
Undefines all currently set streams. This will invalidate existing stream
|
||||
definition structures returned from DefineStream.
|
||||
|
||||
@return (void)
|
||||
@context (all)
|
||||
*/
|
||||
virtual void UndefStreams() = 0;
|
||||
|
||||
/*
|
||||
virtual public ZDataBuffer::Unmap
|
||||
|
||||
Unmaps a previously mapped data buffer and unlocks the data buffer.
|
||||
|
||||
@return (void)
|
||||
@context (all)
|
||||
*/
|
||||
virtual void Unmap() = 0;
|
||||
};
|
||||
|
||||
#endif
|
||||
130
Include/ZRenderer/ZDataBufferBase.hpp
Normal file
130
Include/ZRenderer/ZDataBufferBase.hpp
Normal file
@@ -0,0 +1,130 @@
|
||||
/*
|
||||
ZDataBufferBase.hpp
|
||||
Author: James Russell <jcrussell@762studios.com>
|
||||
Created: 3/20/2011
|
||||
|
||||
Purpose:
|
||||
|
||||
The ZDataBufferBase class is meant to be used by implementations that are
|
||||
required to handle threading and concurrency problems that are not solved by
|
||||
the graphics library.
|
||||
|
||||
License:
|
||||
|
||||
TODO
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef _ZDATABUFFERBASE_HPP
|
||||
#define _ZDATABUFFERBASE_HPP
|
||||
|
||||
#include <ZRenderer/ZDataBuffer.hpp>
|
||||
|
||||
/*
|
||||
Base class implementation for the Data Buffer.
|
||||
*/
|
||||
class ZDataBufferBase : public ZDataBuffer
|
||||
{
|
||||
protected:
|
||||
//Default Constructor
|
||||
ZDataBufferBase(ZDataBufferType _type, ZDataBufferUsage _usage, size_t _size);
|
||||
|
||||
//Type of the Data Buffer
|
||||
ZDataBufferType Type;
|
||||
|
||||
//Usage setting for the Data Buffer
|
||||
ZDataBufferUsage Usage;
|
||||
|
||||
//Size (in bytes) of the Data Buffer
|
||||
size_t Size;
|
||||
|
||||
//Array of DataBufferBlocks held by this DataBuffer
|
||||
ZArray<ZDataBufferBlock*> Blocks;
|
||||
|
||||
//Array of DataBufferStreams held by this DataBuffer
|
||||
ZArray<ZDataBufferStream*> Streams;
|
||||
|
||||
//Backing buffer, used to double-buffer the graphics device buffer
|
||||
void* MemBuffer;
|
||||
|
||||
//Flag indicating this buffer was mapped or filled
|
||||
bool bIsDirty;
|
||||
|
||||
//Gets the buffer data from graphics memory
|
||||
virtual void GetDeviceData(void* _buffer) = 0;
|
||||
|
||||
//Gets the next block offset we should use from the subclass
|
||||
virtual size_t GetNextBlockOffset(size_t _size) = 0;
|
||||
|
||||
//Resets the block offset to zero
|
||||
virtual void ResetBlockOffset() = 0;
|
||||
|
||||
public:
|
||||
//Destructor
|
||||
virtual ~ZDataBufferBase();
|
||||
|
||||
/*
|
||||
public ZDataBufferBase::GetMemBufferResetDirty
|
||||
|
||||
Gets the backing memory buffer for this device. This will return
|
||||
NULL if the buffer has not been modified since the last call to
|
||||
this function, and in the case it has been modified, a call to this
|
||||
resets the 'dirty' flag for the buffer.
|
||||
|
||||
@return (void*) - the backing memory buffer, NULL if not modified
|
||||
@context (renderer)
|
||||
*/
|
||||
void* GetMemBufferResetDirty();
|
||||
|
||||
//Subclass Implementation
|
||||
virtual const ZDataBufferBlock* DefineBlock(ZDataBufferBlockType _type,
|
||||
size_t _size
|
||||
);
|
||||
|
||||
//Subclass Implementation
|
||||
virtual const ZDataBufferStream* DefineStream(ZDataBufferStreamType _type,
|
||||
size_t _elemCount,
|
||||
size_t _offset,
|
||||
size_t _stride,
|
||||
bool _normalize
|
||||
);
|
||||
//Subclass Implementation
|
||||
virtual bool Fill(const void* _data, size_t _offset, size_t _byteCount);
|
||||
|
||||
//Subclass Implementation
|
||||
virtual const ZDataBufferBlock* GetBlock(size_t index) { return Blocks[index]; }
|
||||
|
||||
//Subclass Implementation
|
||||
virtual const ZDataBufferStream* GetStream(size_t index) { return Streams[index]; }
|
||||
|
||||
//Subclass Implementation
|
||||
virtual size_t GetBlockCount() const { return Blocks.Size(); }
|
||||
|
||||
//Subclass Implementation
|
||||
virtual size_t GetStreamCount() const { return Streams.Size(); }
|
||||
|
||||
//Subclass Implementation
|
||||
virtual size_t GetSize();
|
||||
|
||||
//Subclass Implementation
|
||||
virtual ZDataBufferType GetType();
|
||||
|
||||
//Subclass Implementation
|
||||
virtual ZDataBufferUsage GetUsage();
|
||||
|
||||
//Subclass Implementation
|
||||
virtual void* Map( bool _discard = false );
|
||||
|
||||
//Subclass Implementation
|
||||
virtual void UndefBlocks();
|
||||
|
||||
//Subclass Implementation
|
||||
virtual void UndefStreams();
|
||||
|
||||
//Subclass Implementation
|
||||
virtual void Unmap();
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
91
Include/ZRenderer/ZDimensionTexture.hpp
Normal file
91
Include/ZRenderer/ZDimensionTexture.hpp
Normal file
@@ -0,0 +1,91 @@
|
||||
/*
|
||||
ZDimensionTexture.hpp
|
||||
Author: James Russell <jcrussell@762studios.com>
|
||||
Created: 7/1/2012
|
||||
|
||||
Purpose:
|
||||
|
||||
'Dimension' (1D, 2D, 3D) Texture Interface.
|
||||
|
||||
License:
|
||||
|
||||
TODO
|
||||
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef _ZDIMENSIONTEXTURE_HPP
|
||||
#define _ZDIMENSIONTEXTURE_HPP
|
||||
|
||||
#include <ZUtil/ZBitmap.hpp>
|
||||
|
||||
#include <ZRenderer/ZTexture.hpp>
|
||||
|
||||
//Two dimensional texture interface class
|
||||
class ZDimensionTexture : public ZTexture
|
||||
{
|
||||
public:
|
||||
//Virtual Destructor
|
||||
virtual ~ZDimensionTexture() { }
|
||||
|
||||
/*
|
||||
virtual public ZDimensionTexture::Fill
|
||||
|
||||
Fills this texture with the data given in the bitmap data structure.
|
||||
|
||||
@param _data - the bitmap data
|
||||
@return (bool) - true if able to fill the texture, false if unable (contested or locked)
|
||||
@context (all)
|
||||
*/
|
||||
virtual bool Fill(const void* _data) = 0;
|
||||
|
||||
/*
|
||||
virtual public ZDimensionTexture::GetBitmap
|
||||
|
||||
Function to get the image metadata for a texture as a ZBitmap. Does not get the
|
||||
bitmap data field in the ZBitmap instance, which is set to NULL.
|
||||
|
||||
@return (const ZBitmapFormat) - bitmap format
|
||||
@context (all)
|
||||
*/
|
||||
virtual const ZBitmapFormat GetBitmapFormat() = 0;
|
||||
|
||||
/*
|
||||
virtual public ZDimensionTexture::Map
|
||||
|
||||
Maps this texture into memory and locks this texture until 'UnmapTexture' is called.
|
||||
|
||||
The bitmap parameter is a description of how the data is laid out in memory.
|
||||
|
||||
If the discard parameter is set to true, this tells the implementation that the data
|
||||
that is currently present in the texture is not required, and this may result in a faster
|
||||
return.
|
||||
|
||||
@param _discard - hint to the implementation that the data in the texture can be discarded
|
||||
@return (void*) - pointer to the mapped buffer
|
||||
@context (all)
|
||||
*/
|
||||
virtual void* Map( bool _discard) = 0;
|
||||
|
||||
/*
|
||||
virtual public ZDimensionTexture::Unmap
|
||||
|
||||
Unmaps a previously mapped texture and unlocks the texture.
|
||||
|
||||
@return (void)
|
||||
@context (all)
|
||||
*/
|
||||
virtual void Unmap() = 0;
|
||||
|
||||
//Not Implemented
|
||||
virtual ZTextureType GetType() = 0;
|
||||
|
||||
//Not Implemented
|
||||
virtual ZTextureUsage GetUsage() = 0;
|
||||
|
||||
//Not Implemented
|
||||
virtual bool IsMipmapped() = 0;
|
||||
};
|
||||
|
||||
#endif
|
||||
110
Include/ZRenderer/ZDimensionTextureBase.hpp
Normal file
110
Include/ZRenderer/ZDimensionTextureBase.hpp
Normal file
@@ -0,0 +1,110 @@
|
||||
/*
|
||||
ZDimensionTextureBase.hpp
|
||||
Author: James Russell <jcrussell@762studios.com>
|
||||
Created: 7/1/2012
|
||||
|
||||
Purpose:
|
||||
|
||||
Base implementation of a dimension (1D, 2D, 3D) texture.
|
||||
|
||||
License:
|
||||
|
||||
TODO
|
||||
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef _ZDIMENSIONTEXTUREBASE_HPP
|
||||
#define _ZDIMENSIONTEXTUREBASE_HPP
|
||||
|
||||
#include <ZRenderer/ZDimensionTexture.hpp>
|
||||
|
||||
class ZDimensionTextureBase : public ZDimensionTexture
|
||||
{
|
||||
protected:
|
||||
//Type of texture
|
||||
ZTextureType Type;
|
||||
|
||||
//Format of texture
|
||||
ZTextureFormat Format;
|
||||
|
||||
//Usage type of texture
|
||||
ZTextureUsage Usage;
|
||||
|
||||
//Bitmap format (including memory buffer, if needed)
|
||||
ZBitmap Bitmap;
|
||||
|
||||
//Flag indicating this is a mipmapped texture
|
||||
bool bIsMipmapped;
|
||||
|
||||
//Flag indicating the texture data has been modified
|
||||
bool bIsDirty;
|
||||
|
||||
//Gets the texture data from graphics memory
|
||||
virtual void GetDeviceData(void* _buffer) = 0;
|
||||
|
||||
/*
|
||||
Parameterized Constructor.
|
||||
|
||||
@param _type - the texture type
|
||||
@param _format - the texture internal storage format
|
||||
@param _usage - the texture usage hint
|
||||
@param _bitmap - the bitmap for this texture (or side of texture, in case of cube map)
|
||||
@param _generateMipmaps - flag indicating we should generate mipmaps for this texture
|
||||
*/
|
||||
ZDimensionTextureBase(ZTextureType _type, ZTextureFormat _format, ZTextureUsage _usage, const ZBitmap& _bitmap, bool _generateMipmaps);
|
||||
|
||||
public:
|
||||
//Virtual Destructor
|
||||
virtual ~ZDimensionTextureBase();
|
||||
|
||||
/*
|
||||
public ZDimensionTextureBase::GetBitmapResetDirty
|
||||
|
||||
Gets the bitmap data for this dimension texture. This will return
|
||||
NULL if the texture has not been modified since the last call to
|
||||
this function, and in the case it has been modified, a call to this
|
||||
resets the 'dirty' flag for the render target.
|
||||
|
||||
@return (ZBitmap*) - bitmap data, NULL if not dirty
|
||||
@context (all)
|
||||
*/
|
||||
ZBitmap* GetBitmapResetDirty();
|
||||
|
||||
uint32_t GetWidth() { return Bitmap.GetWidth(); }
|
||||
uint32_t GetHeight() { return Bitmap.GetHeight(); }
|
||||
uint32_t GetDepth() { return Bitmap.GetDepth(); }
|
||||
|
||||
/*****************************/
|
||||
/* ZDimensionTexture Methods */
|
||||
/*****************************/
|
||||
|
||||
//Subclass Implementation
|
||||
virtual bool Fill(const void* _data);
|
||||
|
||||
//Subclass Implementation
|
||||
virtual const ZBitmapFormat GetBitmapFormat();
|
||||
|
||||
//Subclass Implementation
|
||||
virtual void* Map(bool _discard);
|
||||
|
||||
//Subclass Implementation
|
||||
virtual void Unmap();
|
||||
|
||||
/********************/
|
||||
/* ZTexture Methods */
|
||||
/********************/
|
||||
|
||||
//Subclass Implementation
|
||||
virtual ZTextureType GetType();
|
||||
|
||||
//Subclass Implementation
|
||||
virtual ZTextureUsage GetUsage();
|
||||
|
||||
//Subclass Implementation
|
||||
virtual bool IsMipmapped();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
62
Include/ZRenderer/ZDrawParams.hpp
Normal file
62
Include/ZRenderer/ZDrawParams.hpp
Normal file
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
ZDrawParams.hpp
|
||||
Author: James Russell <jcrussell@762studios.com>
|
||||
Created: 7/17/2012
|
||||
|
||||
Purpose:
|
||||
|
||||
TODO
|
||||
|
||||
License:
|
||||
|
||||
TODO
|
||||
|
||||
*/
|
||||
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef _ZDRAWPARAMS_HPP
|
||||
#define _ZDRAWPARAMS_HPP
|
||||
|
||||
#include <ZRenderer/ZRendererBuild.hpp>
|
||||
|
||||
//Draw Parameters Types
|
||||
enum ZDrawParamsType
|
||||
{
|
||||
ZDPT_SHADER, //Shader Parameter Binding Structure
|
||||
ZDPT_VERTEX, //Vertex Parameter Binding Structure
|
||||
ZDPT_INDEX, //Index Parameter Binding Structure
|
||||
ZDPT_SIZE
|
||||
};
|
||||
|
||||
class ZDrawParams
|
||||
{
|
||||
public:
|
||||
//Virtual Destructor
|
||||
virtual ~ZDrawParams() { }
|
||||
|
||||
/*
|
||||
virtual public ZDrawParams::MarkResourcesContended
|
||||
|
||||
Marks all resources bound in this draw parameters structure to be
|
||||
contended by the renderer.
|
||||
|
||||
@return (void)
|
||||
@context (renderer)
|
||||
*/
|
||||
virtual void MarkResourcesContended() = 0;
|
||||
|
||||
/*
|
||||
virtual public ZDrawParams::ReleaseResourceContention
|
||||
|
||||
Releases resource contention from the renderer.
|
||||
|
||||
@return (void)
|
||||
@context (renderer)
|
||||
*/
|
||||
virtual void ReleaseResourceContention() = 0;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
138
Include/ZRenderer/ZFrameBufferRenderTarget.hpp
Normal file
138
Include/ZRenderer/ZFrameBufferRenderTarget.hpp
Normal file
@@ -0,0 +1,138 @@
|
||||
/*
|
||||
ZFramebufferRenderTarget.h
|
||||
Author: James Russell <jcrussell@762studios.com>
|
||||
|
||||
Purpose: Interface which defines a FrameBuffer, which is a render target that contains
|
||||
a set of Textures or RenderBuffers which can be used for off-screen rendering.
|
||||
|
||||
Changelog
|
||||
2011/04/03 - creation (jcrussell)
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef _ZFRAMEBUFFERRENDERTARGET_HPP
|
||||
#define _ZFRAMEBUFFERRENDERTARGET_HPP
|
||||
|
||||
#include <ZUtil/ZUtil.hpp>
|
||||
|
||||
#include <ZRenderer/ZRenderTarget.hpp>
|
||||
#include <ZRenderer/ZTexture.hpp>
|
||||
#include <ZRenderer/ZRenderBuffer.hpp>
|
||||
|
||||
//The maximum number of color buffers supported on a single frame buffer render target
|
||||
#ifndef ZFBRT_MAX_COLOR_BUFFERS
|
||||
#define ZFBRT_MAX_COLOR_BUFFERS (16)
|
||||
#endif
|
||||
|
||||
//Frame Buffer Render Target, used for off-screen rendering
|
||||
class ZFramebufferRenderTarget : public ZRenderTarget
|
||||
{
|
||||
public:
|
||||
/*
|
||||
public ZFramebufferRenderTarget::AttachColorBuffer
|
||||
|
||||
Attach a texture to this frame buffer render target as a color buffer. All textures
|
||||
set as color buffers must be of the same dimension, and their dimensions must match
|
||||
that of GetWidth() and GetHeight().
|
||||
|
||||
@param _buffer - the texture to bind to this render target
|
||||
@param _index - the index to bind this color buffer to
|
||||
@return (bool) - true if able to attach buffer, false if resource contended
|
||||
@context (all)
|
||||
*/
|
||||
virtual bool AttachColorTexture(ZPtr<ZTexture> _texture, size_t _index) = 0;
|
||||
|
||||
/*
|
||||
virtual public ZFramebufferRenderTarget::AttachDepthTexture
|
||||
|
||||
Attaches a texture to this frame buffer render target as a depth buffer. The texture
|
||||
set as the depth buffer must be of the same dimension as the color buffers, and it's
|
||||
dimension must match that of GetWidth() and GetHeight().
|
||||
|
||||
A frame buffer render target cannot have a texture attached as a depth buffer as well
|
||||
as a render buffer attached for the same purpose.
|
||||
|
||||
@param _texture - the texture to bind
|
||||
@return (bool) - true if able to attach, false otherwise
|
||||
@context (all)
|
||||
*/
|
||||
virtual bool AttachDepthTexture(ZPtr<ZTexture> _texture) = 0;
|
||||
|
||||
/*
|
||||
virtual public ZFramebufferRenderTarget::AttachRenderBuffer
|
||||
|
||||
Attaches a render buffer to this frame buffer render target. The type of attachment
|
||||
is determined by render buffer type.
|
||||
|
||||
A render buffer cannot be attached if another buffer is already attached that would
|
||||
perform it's function, i.e., it is not possible to attach a depth buffer when a
|
||||
depth texture is in place, and it is not possible to attach a stencil buffer
|
||||
when a depth buffer is acting as depth and stencil buffer.
|
||||
|
||||
@param _buffer - the render buffer to attach
|
||||
@return (bool) - true if able to attach buffer, false if resource contended
|
||||
@context (all)
|
||||
*/
|
||||
virtual bool AttachRenderBuffer(ZPtr<ZRenderBuffer> _buffer) = 0;
|
||||
|
||||
/*
|
||||
virtual public ZFramebufferRenderTarget::IsComplete
|
||||
|
||||
Checks to see if this FrameBuffer is in a 'complete' status and can be used. A
|
||||
'complete' frame buffer requires at least one color buffer (bound at index 0) and
|
||||
one depth buffer, and the buffers should be bound by the graphics library to the
|
||||
frame buffer object.
|
||||
|
||||
@return (bool) - true if complete, false otherwise
|
||||
@context (all)
|
||||
*/
|
||||
virtual bool IsComplete() = 0;
|
||||
|
||||
/*
|
||||
virtual public ZFramebufferRenderTarget::RemoveColorBuffers
|
||||
|
||||
Removes the current set of color buffers attached to this frame buffer render target.
|
||||
|
||||
@return (bool) - true if able to remove buffers, false if resource contended
|
||||
@context (all)
|
||||
*/
|
||||
virtual bool RemoveColorBuffers() = 0;
|
||||
|
||||
/*
|
||||
virtual public ZFramebufferRenderTarget::RemoveDepthBuffer
|
||||
|
||||
Removes the current set depth buffers attached to this frame buffer render target.
|
||||
|
||||
@return (bool) - true if able to remove buffer, false if resource contended
|
||||
@context (all)
|
||||
*/
|
||||
virtual bool RemoveDepthBuffer() = 0;
|
||||
|
||||
/*
|
||||
virtual public ZFramebufferRenderTarget::RemoveStencilBuffer
|
||||
|
||||
Removes the current set stencil buffer attached to this frame buffer render target.
|
||||
|
||||
@return (bool) - true if able to remove buffer, false if resource contended
|
||||
@context (all)
|
||||
*/
|
||||
virtual bool RemoveStencilBuffer() = 0;
|
||||
|
||||
//Not Implemented
|
||||
virtual const ZRenderTargetClearFlags& GetClearFlags() = 0;
|
||||
|
||||
//Not Implemented
|
||||
virtual size_t GetHeight() = 0;
|
||||
|
||||
//Not Implemented
|
||||
virtual ZRenderTargetType GetType() = 0;
|
||||
|
||||
//Not Implemented
|
||||
virtual size_t GetWidth() = 0;
|
||||
|
||||
//Not Implemented
|
||||
virtual bool SetClearFlags(const ZRenderTargetClearFlags& _flags) = 0;
|
||||
};
|
||||
|
||||
#endif
|
||||
150
Include/ZRenderer/ZFrameBufferRenderTargetBase.hpp
Normal file
150
Include/ZRenderer/ZFrameBufferRenderTargetBase.hpp
Normal file
@@ -0,0 +1,150 @@
|
||||
/*
|
||||
ZFramebufferRenderTargetBase.hpp
|
||||
Author: James Russell <jcrussell@762studios.com>
|
||||
Created: 08/07/2011
|
||||
|
||||
Purpose:
|
||||
|
||||
Base class implementation of the ZFramebufferRenderTarget interface.
|
||||
|
||||
License:
|
||||
|
||||
TODO
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef _ZFRAMEBUFFERRENDERTARGETBASE_HPP
|
||||
#define _ZFRAMEBUFFERRENDERTARGETBASE_HPP
|
||||
|
||||
#include <ZRenderer/ZFramebufferRenderTarget.hpp>
|
||||
#include <ZRenderer/ZTexture.hpp>
|
||||
#include <ZRenderer/ZRenderBuffer.hpp>
|
||||
|
||||
//Buffer Data Struct, used to indicate buffer state
|
||||
struct ZFramebufferRenderTargetBufferState
|
||||
{
|
||||
//Our set of attached Color Buffers
|
||||
ZPtr<ZTexture> ColorBuffers[ZFBRT_MAX_COLOR_BUFFERS];
|
||||
|
||||
//Our attached depth texture
|
||||
ZPtr<ZTexture> DepthTexture;
|
||||
|
||||
//Our attached depth buffer
|
||||
ZPtr<ZRenderBuffer> DepthBuffer;
|
||||
|
||||
//Our attached stencil buffer
|
||||
ZPtr<ZRenderBuffer> StencilBuffer;
|
||||
|
||||
//Indicates we are in a usable state
|
||||
bool bIsComplete;
|
||||
|
||||
ZFramebufferRenderTargetBufferState()
|
||||
: bIsComplete(false) { }
|
||||
};
|
||||
|
||||
//Base class implementation of a frame buffer render target
|
||||
class ZFramebufferRenderTargetBase : public ZFramebufferRenderTarget
|
||||
{
|
||||
private:
|
||||
DISABLE_COPY_AND_ASSIGN(ZFramebufferRenderTargetBase);
|
||||
|
||||
protected:
|
||||
//The 'clear' flags
|
||||
ZRenderTargetClearFlags Flags;
|
||||
|
||||
//Width of the FBRT
|
||||
size_t Width;
|
||||
|
||||
//Height of the FBRT
|
||||
size_t Height;
|
||||
|
||||
//Flag indicating state has changed
|
||||
bool bIsDirty;
|
||||
|
||||
//Buffer State for this frame buffer render target
|
||||
ZFramebufferRenderTargetBufferState BufferState;
|
||||
|
||||
/*
|
||||
Constructor.
|
||||
|
||||
@param _width - the width (in pixels / texels) of the FBRT
|
||||
@param _height - the height (in pixels / texels) of the FBRT
|
||||
*/
|
||||
ZFramebufferRenderTargetBase(size_t _width, size_t _height);
|
||||
|
||||
public:
|
||||
//Virtual Destructor
|
||||
virtual ~ZFramebufferRenderTargetBase() { }
|
||||
|
||||
/*
|
||||
public ZFramebufferRenderTargetBase::GetBufferState
|
||||
|
||||
Gets the buffer state for this frame buffer render target.
|
||||
|
||||
@return (ZFramebufferRenderTargetBufferState*) - the buffer state
|
||||
@context (all)
|
||||
*/
|
||||
ZFramebufferRenderTargetBufferState* GetBufferState();
|
||||
|
||||
/*
|
||||
public ZFramebufferRenderTargetBase::GetBufferStateResetDirty
|
||||
|
||||
Gets the backing buffer state for this render target. This will return
|
||||
NULL if the buffer state has not been modified since the last call to
|
||||
this function, and in the case it has been modified, a call to this
|
||||
resets the 'dirty' flag for the render target.
|
||||
|
||||
@return (ZFramebufferRenderTargetBufferState*) - buffer state, NULL if not modified
|
||||
@context (all)
|
||||
*/
|
||||
ZFramebufferRenderTargetBufferState* GetBufferStateResetDirty();
|
||||
|
||||
/*************************/
|
||||
/* ZRenderTarget Methods */
|
||||
/*************************/
|
||||
|
||||
//Subclass Implementation
|
||||
virtual const ZRenderTargetClearFlags& GetClearFlags();
|
||||
|
||||
//Subclass Implementation
|
||||
virtual size_t GetHeight();
|
||||
|
||||
//Subclass Implementation
|
||||
virtual ZRenderTargetType GetType();
|
||||
|
||||
//Subclass Implementation
|
||||
virtual size_t GetWidth();
|
||||
|
||||
//Subclass Implementation
|
||||
virtual bool SetClearFlags(const ZRenderTargetClearFlags& _flags);
|
||||
|
||||
/************************************/
|
||||
/* ZFramebufferRenderTarget Methods */
|
||||
/************************************/
|
||||
|
||||
//Subclass Implementation
|
||||
virtual bool AttachColorTexture(ZPtr<ZTexture> _texture, size_t _index);
|
||||
|
||||
//Subclass Implementation
|
||||
virtual bool AttachDepthTexture(ZPtr<ZTexture> _texture);
|
||||
|
||||
//Subclass Implementation
|
||||
virtual bool AttachRenderBuffer(ZPtr<ZRenderBuffer> _buffer);
|
||||
|
||||
//Subclass Implementation
|
||||
virtual bool IsComplete();
|
||||
|
||||
//Subclass Implementation
|
||||
virtual bool RemoveColorBuffers();
|
||||
|
||||
//Subclass Implementation
|
||||
virtual bool RemoveDepthBuffer();
|
||||
|
||||
//Subclass Implementation
|
||||
virtual bool RemoveStencilBuffer();
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
163
Include/ZRenderer/ZIndexParams.hpp
Normal file
163
Include/ZRenderer/ZIndexParams.hpp
Normal file
@@ -0,0 +1,163 @@
|
||||
/*
|
||||
ZIndexParams.hpp
|
||||
Author: James Russell <jcrussell@762studios.com>
|
||||
Created: 7/1/2012
|
||||
|
||||
Purpose:
|
||||
|
||||
TODO
|
||||
|
||||
License:
|
||||
|
||||
TODO
|
||||
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef _ZINDEXPARAMS_HPP
|
||||
#define _ZINDEXPARAMS_HPP
|
||||
|
||||
#include <ZRenderer/ZDrawParams.hpp>
|
||||
|
||||
#include <ZSTL/ZSTL.hpp>
|
||||
|
||||
#include <ZUtil/ZUtil.hpp>
|
||||
|
||||
#include <ZRenderer/ZDataBuffer.hpp>
|
||||
|
||||
typedef enum ZIndexPrimitiveType {
|
||||
ZIPT_TRIANGLES, //Unrelated triangles, n/3 primitives are drawn
|
||||
ZIPT_TRISTRIP, //Triangle Strip, n-2 primitives are drawn
|
||||
ZIPT_LINES, //Unrelated lines, n/2 primitives are drawn
|
||||
ZIPT_LINESTRIP, //Line Strip, n-1 primitives are drawn
|
||||
ZIPT_POINTS, //Point list, n primitives are drawn
|
||||
} ZIndexPrimitiveType;
|
||||
|
||||
class ZIndexParams : public ZDrawParams
|
||||
{
|
||||
private:
|
||||
//This is the bound index buffer and block
|
||||
ZPtr<ZDataBuffer> IndexBuffer;
|
||||
ZPair<ZDataBuffer*, const ZDataBufferBlock*> Binding;
|
||||
|
||||
ZIndexPrimitiveType primType;
|
||||
size_t nrPrims;
|
||||
size_t offset;
|
||||
|
||||
public:
|
||||
/*
|
||||
Default Constructor.
|
||||
*/
|
||||
ZIndexParams();
|
||||
|
||||
/*
|
||||
public ZIndexParams::ClearBlock
|
||||
|
||||
Clears the current block definition and index buffer.
|
||||
|
||||
@return (void)
|
||||
@context (all)
|
||||
*/
|
||||
void ClearIndexBlock();
|
||||
|
||||
/*
|
||||
public ZIndexParams::SetBlock
|
||||
|
||||
Sets the index buffer and index block that will be being used.
|
||||
|
||||
@param _indexBuffer - data buffer containing index data
|
||||
@param _block - the index block
|
||||
@return (void)
|
||||
@context (all)
|
||||
*/
|
||||
void SetIndexBlock(ZPtr<ZDataBuffer> _indexBuffer, const ZDataBufferBlock* _block);
|
||||
|
||||
/*
|
||||
public ZIndexParams::SetPrimitiveDrawCount
|
||||
|
||||
Sets the number of primitives that will be drawn. This is not the number
|
||||
of indices used in total. For example, 300 indices with triangles will draw
|
||||
100 triangles, so the primitive draw count should be 100.
|
||||
|
||||
The special value of '0' is interpreted as "draw as many as possible".
|
||||
|
||||
@param count - The number of primitives
|
||||
@return (void)
|
||||
@context (all)
|
||||
*/
|
||||
void SetPrimitiveDrawCount(size_t _count) { nrPrims = _count; }
|
||||
|
||||
/*
|
||||
public ZIndexParams::GetPrimitiveDrawCount
|
||||
|
||||
Gets the number of primitives that will be drawn.
|
||||
|
||||
@return (size_t) - The number of primitives
|
||||
@context (all)
|
||||
*/
|
||||
size_t GetPrimitiveDrawCount() const { return nrPrims; }
|
||||
|
||||
/*
|
||||
public ZIndexParams::SetDrawOffset
|
||||
|
||||
Sets starting point for drawing, measured in whole indices (not bytes). For example,
|
||||
if you had a stream that contained { 1, 3, 5, 7 } and you wanted to draw
|
||||
starting at '3', then you would use an offset of 1 -- regardless of the
|
||||
type of index (8, 16, 32-bit).
|
||||
|
||||
@param _offset - The offset measured in whole indices
|
||||
@return (void)
|
||||
@context (all)
|
||||
*/
|
||||
void SetDrawOffset(size_t _offset) { offset = _offset; }
|
||||
|
||||
/*
|
||||
public ZIndexParams::GetDrawOffset
|
||||
|
||||
Gets starting point for drawing, measured in whole indices (not bytes)
|
||||
|
||||
@return (size_t) - The offset
|
||||
@context (all)
|
||||
*/
|
||||
|
||||
size_t GetDrawOffset() const { return offset; }
|
||||
|
||||
/*
|
||||
public ZIndexParams::SetPrimitiveType
|
||||
|
||||
Sets primitive type to draw.
|
||||
|
||||
@param _type - The primitive type
|
||||
@return (void)
|
||||
@context (all)
|
||||
*/
|
||||
|
||||
void SetPrimitiveType(ZIndexPrimitiveType _type) { primType = _type; }
|
||||
|
||||
/*
|
||||
public ZIndexParams::GetPrimitiveType
|
||||
|
||||
Gets the type of primitive being rendered
|
||||
|
||||
@return (ZIndexPrimitiveType) - The primitive type
|
||||
@context (all)
|
||||
*/
|
||||
ZIndexPrimitiveType GetPrimitiveType() { return primType; }
|
||||
|
||||
/*
|
||||
The following methods are used by the renderer to get the values needed when
|
||||
binding shader parameter values to pass to the shader program, to mark
|
||||
all bound resources as contended, and release contention.
|
||||
*/
|
||||
const ZPair<ZDataBuffer*, const ZDataBufferBlock*>* GetIndexBlock();
|
||||
ZDataBuffer* GetIndexBuffer();
|
||||
|
||||
//Subclass Override
|
||||
virtual void MarkResourcesContended();
|
||||
|
||||
//Subclass Override
|
||||
virtual void ReleaseResourceContention();
|
||||
};
|
||||
|
||||
#endif
|
||||
98
Include/ZRenderer/ZOpenGLDataBuffer.hpp
Normal file
98
Include/ZRenderer/ZOpenGLDataBuffer.hpp
Normal file
@@ -0,0 +1,98 @@
|
||||
/*
|
||||
ZOpenGLDataBuffer.hpp
|
||||
Author: James Russell <jcrussell@762studios.com>
|
||||
Created: 3/20/2011
|
||||
|
||||
Purpose:
|
||||
|
||||
OpenGL implementation of the ZDataBuffer interfaces.
|
||||
|
||||
License:
|
||||
|
||||
TODO
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef _ZOPENGLDATABUFFER_HPP
|
||||
#define _ZOPENGLDATABUFFER_HPP
|
||||
|
||||
#include <ZUtil/ZUtil.hpp>
|
||||
|
||||
#include <ZRenderer/ZDataBufferBase.hpp>
|
||||
|
||||
//Forward Declarations
|
||||
class ZOpenGLRenderer;
|
||||
|
||||
/*
|
||||
OpenGL Data Buffer.
|
||||
*/
|
||||
class ZOpenGLDataBuffer : public ZDataBufferBase
|
||||
{
|
||||
protected:
|
||||
//Renderer associated with this buffer
|
||||
ZOpenGLRenderer *Renderer;
|
||||
|
||||
//The current offset to use
|
||||
size_t NextOffset;
|
||||
|
||||
//Offset Alignment Requirement
|
||||
static int OffsetAlignment;
|
||||
|
||||
//Gets the buffer data from the graphics device as part of a thread request
|
||||
static void GetDeviceData_( ZThread *_renderThread, void *_dataBuffer );
|
||||
|
||||
//Subclass Override
|
||||
virtual void GetDeviceData(void* _buffer);
|
||||
|
||||
//Subclass Override
|
||||
virtual size_t GetNextBlockOffset(size_t _size);
|
||||
|
||||
//Subclass Override
|
||||
virtual void ResetBlockOffset();
|
||||
|
||||
public:
|
||||
//OpenGL Handle to the Buffer
|
||||
GLuint GLHandle;
|
||||
|
||||
//Gets a GLenum based off of type
|
||||
GLenum GetGLType()
|
||||
{
|
||||
switch (Type)
|
||||
{
|
||||
case ZDBT_UNIFORM: return GL_UNIFORM_BUFFER;
|
||||
case ZDBT_VERTEX: return GL_ARRAY_BUFFER;
|
||||
case ZDBT_INDEX: return GL_ELEMENT_ARRAY_BUFFER;
|
||||
default: return GL_INVALID_ENUM;
|
||||
}
|
||||
}
|
||||
|
||||
//Gets a GLenum based off of usage
|
||||
GLenum GetGLUsage()
|
||||
{
|
||||
switch(Usage)
|
||||
{
|
||||
case ZDBU_STATIC: return GL_STATIC_DRAW;
|
||||
case ZDBU_DYNAMIC: return GL_DYNAMIC_DRAW;
|
||||
case ZDBU_STREAMING: return GL_STREAM_DRAW;
|
||||
default: return GL_INVALID_ENUM;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Constructor.
|
||||
|
||||
@param _renderer - the current renderer
|
||||
@param _type - the type of buffer this is
|
||||
@param _usage - the usage type of this buffer
|
||||
@param _size - the size (in bytes) of the data buffer
|
||||
*/
|
||||
ZOpenGLDataBuffer(ZOpenGLRenderer *_renderer, ZDataBufferType _type, ZDataBufferUsage _usage, size_t _size);
|
||||
|
||||
/*
|
||||
Destructor.
|
||||
*/
|
||||
virtual ~ZOpenGLDataBuffer();
|
||||
};
|
||||
|
||||
#endif
|
||||
262
Include/ZRenderer/ZOpenGLDimensionTexture.hpp
Normal file
262
Include/ZRenderer/ZOpenGLDimensionTexture.hpp
Normal file
@@ -0,0 +1,262 @@
|
||||
/*
|
||||
ZOpenGLDimensionTexture.hpp
|
||||
Author: James Russell <jcrussell@762studios.com>
|
||||
Created: 7/1/2012
|
||||
|
||||
Purpose:
|
||||
|
||||
OpenGL implementation of a 'dimensional' (1D, 2D, 3D) texture.
|
||||
|
||||
License:
|
||||
|
||||
TODO
|
||||
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef _ZOPENGLDIMENSIONTEXTURE_HPP
|
||||
#define _ZOPENGLDIMENSIONTEXTURE_HPP
|
||||
|
||||
#include <SST/SST_GLAPI.h>
|
||||
|
||||
#include <ZRenderer/ZDimensionTextureBase.hpp>
|
||||
|
||||
//Forward Declarations
|
||||
class ZOpenGLRenderer;
|
||||
|
||||
//OpenGL implementation of the two dimensional texture interface
|
||||
class ZOpenGLDimensionTexture : public ZDimensionTextureBase
|
||||
{
|
||||
private:
|
||||
DISABLE_COPY_AND_ASSIGN(ZOpenGLDimensionTexture);
|
||||
|
||||
protected:
|
||||
//Gets the texture data from the graphics device as part of a thread request
|
||||
static void GetDeviceData_( ZThread *_renderThread, void *_dataBuffer );
|
||||
|
||||
//Subclass Implementation
|
||||
virtual void GetDeviceData(void* _buffer);
|
||||
|
||||
public:
|
||||
//Renderer associated with this texture
|
||||
ZOpenGLRenderer *Renderer;
|
||||
|
||||
//The OpenGL handle to the loaded texture
|
||||
GLuint GLHandle;
|
||||
|
||||
//Gets the OpenGL 'target' parameter for this texture type
|
||||
GLenum GetGLTarget()
|
||||
{
|
||||
switch(Type)
|
||||
{
|
||||
case ZTT_TEXTURE1D: return GL_TEXTURE_1D;
|
||||
case ZTT_TEXTURE2D: return GL_TEXTURE_2D;
|
||||
case ZTT_TEXTURE3D: return GL_TEXTURE_3D;
|
||||
case ZTT_TEXTURE_CUBE: /* Invalid Here */
|
||||
default: return GL_INVALID_ENUM;
|
||||
}
|
||||
}
|
||||
|
||||
//Gets the OpenGL 'internalFormat' parameter for this texture format (used for glTexImage*D)
|
||||
GLenum GetGLInternalFormat()
|
||||
{
|
||||
switch (Format)
|
||||
{
|
||||
case ZTF_R8: return GL_R8;
|
||||
case ZTF_R8_SNORM: return GL_R8_SNORM;
|
||||
case ZTF_R8I: return GL_R8I;
|
||||
case ZTF_R8UI: return GL_R8UI;
|
||||
case ZTF_R16: return GL_R16;
|
||||
case ZTF_R16_SNORM: return GL_R16_SNORM;
|
||||
case ZTF_R16I: return GL_R16I;
|
||||
case ZTF_R16UI: return GL_R16UI;
|
||||
case ZTF_R16F: return GL_R16F;
|
||||
case ZTF_R32I: return GL_R32I;
|
||||
case ZTF_R32UI: return GL_R32UI;
|
||||
case ZTF_R32F: return GL_R32F;
|
||||
|
||||
case ZTF_RG8: return GL_RG8;
|
||||
case ZTF_RG8_SNORM: return GL_RG8_SNORM;
|
||||
case ZTF_RG8I: return GL_RG8I;
|
||||
case ZTF_RG8UI: return GL_RG8UI;
|
||||
case ZTF_RG16: return GL_RG16;
|
||||
case ZTF_RG16_SNORM: return GL_RG16_SNORM;
|
||||
case ZTF_RG16I: return GL_RG16I;
|
||||
case ZTF_RG16UI: return GL_RG16UI;
|
||||
case ZTF_RG16F: return GL_RG16F;
|
||||
case ZTF_RG32I: return GL_RG32I;
|
||||
case ZTF_RG32UI: return GL_RG32UI;
|
||||
case ZTF_RG32F: return GL_RG32F;
|
||||
|
||||
case ZTF_RGB8: return GL_RGB8;
|
||||
case ZTF_RGB8_SNORM: return GL_RGB8_SNORM;
|
||||
case ZTF_RGB8I: return GL_RGB8I;
|
||||
case ZTF_RGB8UI: return GL_RGB8UI;
|
||||
case ZTF_RGB16: return GL_RGB16;
|
||||
case ZTF_RGB16_SNORM: return GL_RGB16_SNORM;
|
||||
case ZTF_RGB16I: return GL_RGB16I;
|
||||
case ZTF_RGB16UI: return GL_RGB16UI;
|
||||
case ZTF_RGB16F: return GL_RGB16F;
|
||||
case ZTF_RGB32I: return GL_RGB32I;
|
||||
case ZTF_RGB32UI: return GL_RGB32UI;
|
||||
case ZTF_RGB32F: return GL_RGB32F;
|
||||
|
||||
case ZTF_RGBA8: return GL_RGBA8;
|
||||
case ZTF_RGBA8_SNORM: return GL_RGBA8_SNORM;
|
||||
case ZTF_RGBA8I: return GL_RGBA8I;
|
||||
case ZTF_RGBA8UI: return GL_RGBA8UI;
|
||||
case ZTF_RGBA16: return GL_RGBA16;
|
||||
case ZTF_RGBA16_SNORM: return GL_RGBA16_SNORM;
|
||||
case ZTF_RGBA16I: return GL_RGBA16I;
|
||||
case ZTF_RGBA16UI: return GL_RGBA16UI;
|
||||
case ZTF_RGBA16F: return GL_RGBA16F;
|
||||
case ZTF_RGBA32I: return GL_RGBA32I;
|
||||
case ZTF_RGBA32UI: return GL_RGBA32UI;
|
||||
case ZTF_RGBA32F: return GL_RGBA32F;
|
||||
|
||||
case ZTF_DEPTH16: return GL_DEPTH_COMPONENT16;
|
||||
case ZTF_DEPTH24: return GL_DEPTH_COMPONENT24;
|
||||
case ZTF_DEPTH32: return GL_DEPTH_COMPONENT32;
|
||||
case ZTF_DEPTH24_STENCIL8: return GL_DEPTH24_STENCIL8;
|
||||
|
||||
default: return GL_INVALID_ENUM;
|
||||
}
|
||||
}
|
||||
|
||||
//Gets the OpenGL 'format' parameter for this texture's bitmap format (used for glTexImage*D)
|
||||
GLenum GetGLFormat()
|
||||
{
|
||||
switch (Bitmap.GetFormat())
|
||||
{
|
||||
case ZBF_R8:
|
||||
case ZBF_R8I:
|
||||
case ZBF_R16:
|
||||
case ZBF_R16I:
|
||||
case ZBF_R32:
|
||||
case ZBF_R32I:
|
||||
case ZBF_R32F: return GL_RED;
|
||||
|
||||
case ZBF_RG8:
|
||||
case ZBF_RG8I:
|
||||
case ZBF_RG16:
|
||||
case ZBF_RG16I:
|
||||
case ZBF_RG32:
|
||||
case ZBF_RG32I:
|
||||
case ZBF_RG32F: return GL_RG;
|
||||
|
||||
case ZBF_RGB8:
|
||||
case ZBF_RGB8I:
|
||||
case ZBF_RGB16:
|
||||
case ZBF_RGB16I:
|
||||
case ZBF_RGB32:
|
||||
case ZBF_RGB32I:
|
||||
case ZBF_RGB32F: return GL_RGB;
|
||||
|
||||
case ZBF_RGBA8:
|
||||
case ZBF_RGBA8I:
|
||||
case ZBF_RGBA16:
|
||||
case ZBF_RGBA16I:
|
||||
case ZBF_RGBA32:
|
||||
case ZBF_RGBA32I:
|
||||
case ZBF_RGBA32F: return GL_RGBA;
|
||||
|
||||
case ZBF_BGR8:
|
||||
case ZBF_BGR8I:
|
||||
case ZBF_BGR16:
|
||||
case ZBF_BGR16I:
|
||||
case ZBF_BGR32:
|
||||
case ZBF_BGR32I:
|
||||
case ZBF_BGR32F: return GL_BGR;
|
||||
|
||||
case ZBF_BGRA8:
|
||||
case ZBF_BGRA8I:
|
||||
case ZBF_BGRA16:
|
||||
case ZBF_BGRA16I:
|
||||
case ZBF_BGRA32:
|
||||
case ZBF_BGRA32I:
|
||||
case ZBF_BGRA32F: return GL_BGRA;
|
||||
|
||||
case ZBF_DEPTH32: return GL_DEPTH_COMPONENT;
|
||||
|
||||
default: return GL_INVALID_ENUM;
|
||||
}
|
||||
}
|
||||
|
||||
//Gets the OpenGL 'type' parameter for this texture's bitmap format (used for glTexImage*D calls)
|
||||
GLenum GetGLType()
|
||||
{
|
||||
switch (Bitmap.GetFormat())
|
||||
{
|
||||
case ZBF_R8:
|
||||
case ZBF_RG8:
|
||||
case ZBF_RGB8:
|
||||
case ZBF_RGBA8:
|
||||
case ZBF_BGR8:
|
||||
case ZBF_BGRA8: return GL_UNSIGNED_BYTE;
|
||||
|
||||
case ZBF_R8I:
|
||||
case ZBF_RG8I:
|
||||
case ZBF_RGB8I:
|
||||
case ZBF_RGBA8I:
|
||||
case ZBF_BGR8I:
|
||||
case ZBF_BGRA8I: return GL_BYTE;
|
||||
|
||||
case ZBF_R16:
|
||||
case ZBF_RG16:
|
||||
case ZBF_RGB16:
|
||||
case ZBF_RGBA16:
|
||||
case ZBF_BGR16:
|
||||
case ZBF_BGRA16: return GL_UNSIGNED_SHORT;
|
||||
|
||||
case ZBF_R16I:
|
||||
case ZBF_RG16I:
|
||||
case ZBF_RGB16I:
|
||||
case ZBF_RGBA16I:
|
||||
case ZBF_BGR16I:
|
||||
case ZBF_BGRA16I: return GL_SHORT;
|
||||
|
||||
case ZBF_R32:
|
||||
case ZBF_RG32:
|
||||
case ZBF_RGB32:
|
||||
case ZBF_RGBA32:
|
||||
case ZBF_BGR32:
|
||||
case ZBF_BGRA32: return GL_UNSIGNED_INT;
|
||||
|
||||
case ZBF_R32I:
|
||||
case ZBF_RG32I:
|
||||
case ZBF_RGB32I:
|
||||
case ZBF_RGBA32I:
|
||||
case ZBF_BGR32I:
|
||||
case ZBF_BGRA32I: return GL_INT;
|
||||
|
||||
case ZBF_R32F:
|
||||
case ZBF_RG32F:
|
||||
case ZBF_RGB32F:
|
||||
case ZBF_RGBA32F:
|
||||
case ZBF_BGR32F:
|
||||
case ZBF_BGRA32F: return GL_FLOAT;
|
||||
|
||||
case ZBF_DEPTH32: return GL_UNSIGNED_INT;
|
||||
|
||||
default: return GL_INVALID_ENUM;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Constructor.
|
||||
|
||||
@param _renderer - the current renderer instance
|
||||
@param _type - the type of texture
|
||||
@param _format - the format of the texture
|
||||
@param _usage - the usage type of texture
|
||||
@param _bitmap - the bitmap for this texture (or side, in case of cube map)
|
||||
@param _generateMipmaps - flag indicating we should generate mipmaps
|
||||
*/
|
||||
ZOpenGLDimensionTexture(ZOpenGLRenderer* _renderer, ZTextureType _type, ZTextureFormat _format, ZTextureUsage _usage, const ZBitmap& _bitmap, bool _generateMipmaps);
|
||||
|
||||
//Virtual destructor
|
||||
virtual ~ZOpenGLDimensionTexture();
|
||||
};
|
||||
|
||||
#endif
|
||||
53
Include/ZRenderer/ZOpenGLFrameBufferRenderTarget.hpp
Normal file
53
Include/ZRenderer/ZOpenGLFrameBufferRenderTarget.hpp
Normal file
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
ZOpenGLFrameBufferRenderTarget.hpp
|
||||
Author: James Russell <jcrussell@762studios.com>
|
||||
Created: 07/24/2011
|
||||
|
||||
Purpose:
|
||||
|
||||
OpenGL implementation of the ZFramebufferRenderTargetBase class.
|
||||
|
||||
License:
|
||||
|
||||
TODO
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef _ZOPENGLFRAMEBUFFERRENDERTARGET_HPP
|
||||
#define _ZOPENGLFRAMEBUFFERRENDERTARGET_HPP
|
||||
|
||||
//Forward Declarations
|
||||
class ZOpenGLRenderer;
|
||||
|
||||
#include <ZRenderer/ZFramebufferRenderTargetBase.hpp>
|
||||
|
||||
#include <SST/SST_GLAPI.h>
|
||||
|
||||
class ZOpenGLFramebufferRenderTarget : public ZFramebufferRenderTargetBase
|
||||
{
|
||||
protected:
|
||||
//Renderer Instance
|
||||
ZOpenGLRenderer* Renderer;
|
||||
|
||||
public:
|
||||
//The OpenGL handle to the FBO
|
||||
GLuint GLHandle;
|
||||
|
||||
/*
|
||||
Constructor.
|
||||
|
||||
@param _renderer - the current renderer
|
||||
@param _width - the width this frame buffer render target be be
|
||||
@param _height - the height this frame buffer render target will be
|
||||
*/
|
||||
ZOpenGLFramebufferRenderTarget(ZOpenGLRenderer *_renderer, size_t _width, size_t _height);
|
||||
|
||||
/*
|
||||
Destructor.
|
||||
*/
|
||||
~ZOpenGLFramebufferRenderTarget();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
84
Include/ZRenderer/ZOpenGLRenderBuffer.hpp
Normal file
84
Include/ZRenderer/ZOpenGLRenderBuffer.hpp
Normal file
@@ -0,0 +1,84 @@
|
||||
/*
|
||||
ZOpenGLRenderBuffer.hpp
|
||||
Author: Chris Ertel <crertel@762studios.com>,
|
||||
James Russell <jcrussell@762studios.com>
|
||||
|
||||
Purpose:
|
||||
|
||||
Implementation of the render buffer interface for OpenGL renderers.
|
||||
|
||||
License:
|
||||
|
||||
TODO
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef _ZOPENGLRENDERBUFFER_HPP
|
||||
#define _ZOPENGLRENDERBUFFER_HPP
|
||||
|
||||
//Forward Declaration
|
||||
class ZOpenGLRenderer;
|
||||
|
||||
#include <SST/SST_GLAPI.h>
|
||||
|
||||
#include <ZRenderer/ZRenderBuffer.hpp>
|
||||
|
||||
class ZOpenGLRenderBuffer : public ZRenderBuffer
|
||||
{
|
||||
protected:
|
||||
//Renderer Instance
|
||||
ZOpenGLRenderer* Renderer;
|
||||
|
||||
//The type of render buffer
|
||||
ZRenderBufferType Type;
|
||||
|
||||
//Width of the render buffer
|
||||
size_t Width;
|
||||
|
||||
//Height of the render buffer
|
||||
size_t Height;
|
||||
|
||||
|
||||
public:
|
||||
//Gets the GL storage type
|
||||
inline GLenum GetGLType()
|
||||
{
|
||||
switch(Type)
|
||||
{
|
||||
case ZRBT_DEPTH16: return GL_DEPTH_COMPONENT16;
|
||||
case ZRBT_DEPTH24: return GL_DEPTH_COMPONENT24;
|
||||
case ZRBT_DEPTH32: return GL_DEPTH_COMPONENT32;
|
||||
case ZRBT_STENCIL8: return GL_STENCIL_INDEX8;
|
||||
case ZRBT_DEPTH24_STENCIL8: return GL_DEPTH24_STENCIL8;
|
||||
default: return GL_INVALID_ENUM;
|
||||
}
|
||||
}
|
||||
|
||||
//The OpenGL handle to the render buffer
|
||||
GLuint GLHandle;
|
||||
|
||||
/*
|
||||
Constructor.
|
||||
|
||||
@param _renderer - the current renderer instance
|
||||
@param _type - the type of render buffer this will be
|
||||
@param _width - with of the render buffer
|
||||
@param _height - height of the render buffer
|
||||
*/
|
||||
ZOpenGLRenderBuffer( ZOpenGLRenderer *_renderer, ZRenderBufferType _type, size_t _width, size_t _height);
|
||||
|
||||
//Destructor
|
||||
virtual ~ZOpenGLRenderBuffer();
|
||||
|
||||
//Subclass Implementation
|
||||
virtual size_t GetHeight();
|
||||
|
||||
//Subclass Implementation
|
||||
virtual ZRenderBufferType GetType();
|
||||
|
||||
//Subclass Implementation
|
||||
virtual size_t GetWidth();
|
||||
};
|
||||
|
||||
#endif
|
||||
197
Include/ZRenderer/ZOpenGLRenderer.hpp
Normal file
197
Include/ZRenderer/ZOpenGLRenderer.hpp
Normal file
@@ -0,0 +1,197 @@
|
||||
/*
|
||||
ZOpenGLRenderer.hpp
|
||||
Author: James Russell <jcrussell@762studios.com>
|
||||
Created: 3/27/2011
|
||||
|
||||
Purpose:
|
||||
|
||||
OpenGL implementation of the Renderer. Currently requires OpenGL 3.3.
|
||||
|
||||
License:
|
||||
|
||||
TODO
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef _ZOPENGLRENDERER_HPP
|
||||
#define _ZOPENGLRENDERER_HPP
|
||||
|
||||
#include <SST/SST_GLAPI.h>
|
||||
#include <SST/SST_WMOpenGL.h>
|
||||
|
||||
#include <ZRenderer/ZRendererBase.hpp>
|
||||
#include <ZRenderer/ZOpenGLDataBuffer.hpp>
|
||||
#include <ZRenderer/ZOpenGLShader.hpp>
|
||||
#include <ZRenderer/ZOpenGLShaderProgram.hpp>
|
||||
#include <ZRenderer/ZOpenGLDimensionTexture.hpp>
|
||||
#include <ZRenderer/ZOpenGLSampler.hpp>
|
||||
#include <ZRenderer/ZOpenGLFrameBufferRenderTarget.hpp>
|
||||
#include <ZRenderer/ZOpenGLRenderBuffer.hpp>
|
||||
#include <ZRenderer/ZOpenGLWindowRenderTarget.hpp>
|
||||
#include <ZRenderer/ZOpenGLVertexParams.hpp>
|
||||
|
||||
//CHECKGL function, which checks for OpenGL Error conditions and asserts when they are found
|
||||
void CheckGL();
|
||||
|
||||
//CHECKGL macro for debug mode
|
||||
#if ZRENDERER_CHECKGL
|
||||
#define CHECKGL() (CheckGL())
|
||||
#else
|
||||
#define CHECKGL()
|
||||
#endif
|
||||
|
||||
//Enumeration for various OpenGL resource types
|
||||
enum ZOpenGLResourceType
|
||||
{
|
||||
ZOGLRT_BUFFER, //OpenGL Buffer Object
|
||||
ZOGLRT_SHADER, //OpenGL Shader Object
|
||||
ZOGLRT_SHADER_PROGRAM, //OpenGL Shader Program Object
|
||||
ZOGLRT_TEXTURE, //OpenGL Texture Object
|
||||
ZOGLRT_SAMPLER, //OpenGL Sampler Object
|
||||
ZOGLRT_FRAME_BUFFER, //OpenGL Frame Buffer Object
|
||||
ZOGLRT_RENDER_BUFFER, //OpenGL Render Buffer Object
|
||||
ZOGLRT_VERTEX_ARRAY, //OpenGL Vertex Array Object
|
||||
ZOGLRT_SIZE
|
||||
};
|
||||
|
||||
/*
|
||||
OpenGL Renderer implementation class.
|
||||
*/
|
||||
class ZOpenGLRenderer : public ZRendererBase
|
||||
{
|
||||
private:
|
||||
DISABLE_COPY_AND_ASSIGN(ZOpenGLRenderer);
|
||||
|
||||
//Resource Generation Thread Request
|
||||
class ResourceGenerationThreadRequest : public ZThreadRequest
|
||||
{
|
||||
public:
|
||||
//Default Constructor
|
||||
ResourceGenerationThreadRequest() : ZThreadRequest(true) { }
|
||||
|
||||
//Concurrency control lock for resource generation and cleanup
|
||||
ZMutex ResourceMutex;
|
||||
|
||||
//Indicator that we have a pending resource request
|
||||
bool bPendingResourceRequest;
|
||||
|
||||
//Resource Generation Requests
|
||||
ZArray< ZPtr<ZOpenGLDataBuffer> > DataBufferGenerateRequests;
|
||||
ZArray< ZPtr<ZOpenGLShader> > ShaderGenerateRequests;
|
||||
ZArray< ZPtr<ZOpenGLShaderProgram> > ShaderProgramGenerateRequests;
|
||||
ZArray< ZPtr<ZOpenGLDimensionTexture> > DimensionTextureGenerateRequests;
|
||||
ZArray<ZPtr<ZOpenGLSampler> > SamplerGenerateRequests;
|
||||
ZArray< ZPtr<ZOpenGLFramebufferRenderTarget> > FrameBufferGenerateRequests;
|
||||
ZArray< ZPtr<ZOpenGLRenderBuffer> > RenderBufferGenerateRequests;
|
||||
ZArray< ZPtr<ZOpenGLVertexParams> > VertexParamsGenerateRequests;
|
||||
|
||||
//Resource Delete Requests
|
||||
ZArray< ZPair<ZOpenGLResourceType, GLuint> > ResourceDeleteRequests;
|
||||
|
||||
//Subclass Implementation
|
||||
virtual void Execute( ZThread *_threadObj );
|
||||
};
|
||||
|
||||
protected:
|
||||
//The initialization window
|
||||
SST_Window InitializationWindow;
|
||||
|
||||
//The OpenGL Context for this renderer
|
||||
SST_OpenGLContext GLContext;
|
||||
|
||||
//Indicates we own the GLContext
|
||||
bool bOwnsContext;
|
||||
|
||||
//The Current Render State
|
||||
ZRenderState *CurrentRenderState;
|
||||
|
||||
//Resource Request Object
|
||||
ZPtr<ResourceGenerationThreadRequest> ResourceThreadRequest;
|
||||
|
||||
//Subclass Override
|
||||
virtual bool init();
|
||||
|
||||
//Subclass Override
|
||||
virtual void initThread();
|
||||
|
||||
//Subclass Override
|
||||
virtual void shutdown();
|
||||
|
||||
//Subclass Override
|
||||
virtual void shutdownThread();
|
||||
|
||||
//Subclass Override
|
||||
virtual void Draw(ZArray<ZDrawData*,
|
||||
ZArrayAllocator< ZDrawData*, ZRB_DEFAULT_DRAWDATA_BUFFER_SIZE> >& _renderList,
|
||||
ZRenderTarget* _renderTarget);
|
||||
|
||||
public:
|
||||
/*
|
||||
Constructor.
|
||||
|
||||
Initializes this renderer with the given OpenGL context.
|
||||
|
||||
The provided window handle is only used for binding to a window so that OpenGL values can be obtained. In order
|
||||
to render to the provided window, a ZWindowRenderTarget will need to be created using that window handle after
|
||||
the renderer has finished initializing.
|
||||
|
||||
@param _glContext - the OpenGL context to initialize this renderer with
|
||||
@param _window - window to initialize this renderer with
|
||||
@param _ownContext - indicates whether this renderer 'owns' the context and should clean up when destructed
|
||||
*/
|
||||
ZOpenGLRenderer(SST_OpenGLContext _glContext, SST_Window _window, bool _ownContext);
|
||||
|
||||
/*
|
||||
Destructor.
|
||||
*/
|
||||
~ZOpenGLRenderer();
|
||||
|
||||
/*
|
||||
public ZOpenGLRenderer::DeleteResource
|
||||
|
||||
This will ask the renderer thread to clean up a previously generated OpenGL resource.
|
||||
|
||||
@param _type - the type of resource
|
||||
@param _handle - the handle to the resource
|
||||
@return (void)
|
||||
@context (all)
|
||||
*/
|
||||
void DeleteResource(ZOpenGLResourceType _type, GLuint _handle);
|
||||
|
||||
//////////////////////////
|
||||
/* Logistics Operations */
|
||||
//////////////////////////
|
||||
|
||||
//Subclass Override
|
||||
virtual ZPtr<ZDataBuffer> CreateDataBuffer(ZDataBufferType _type,
|
||||
ZDataBufferUsage _usage,
|
||||
size_t _size);
|
||||
|
||||
//Subclass Override
|
||||
virtual ZPtr<ZDrawParams> CreateDrawParams(ZDrawParamsType _type);
|
||||
|
||||
//Subclass Override
|
||||
virtual ZPtr<ZFramebufferRenderTarget> CreateFrameBufferRenderTarget(size_t _width, size_t _height);
|
||||
|
||||
//Subclass Override
|
||||
virtual ZPtr<ZRenderBuffer> CreateRenderBuffer(ZRenderBufferType _type, size_t _width, size_t _height);
|
||||
|
||||
//Subclass Override
|
||||
virtual ZPtr<ZSampler> CreateSampler();
|
||||
|
||||
//Subclass Override
|
||||
virtual ZPtr<ZShader> CreateShader(ZShaderType _type);
|
||||
|
||||
//Subclass Override
|
||||
virtual ZPtr<ZShaderProgram> CreateShaderProgram();
|
||||
|
||||
//Subclass Override
|
||||
virtual ZPtr<ZTexture> CreateTexture(ZTextureType _type, ZTextureFormat _format, ZTextureUsage _usage, const ZBitmap& _bitmap, bool _generateMipmaps);
|
||||
|
||||
//Subclass Override
|
||||
virtual ZPtr<ZRenderTarget> CreateWindowRenderTarget(SST_Window _window,
|
||||
size_t _screenIndex);
|
||||
};
|
||||
|
||||
#endif
|
||||
162
Include/ZRenderer/ZOpenGLSampler.hpp
Normal file
162
Include/ZRenderer/ZOpenGLSampler.hpp
Normal file
@@ -0,0 +1,162 @@
|
||||
/*
|
||||
ZOpenGLSampler.hpp
|
||||
Author: James Russell <jcrussell@762studios.com>,
|
||||
Chris Ertel <crertel@762studios.com>
|
||||
Created: 7/1/2012
|
||||
|
||||
Purpose:
|
||||
|
||||
OpenGL implementation of the ZSampler interface class.
|
||||
|
||||
License:
|
||||
|
||||
TODO
|
||||
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef _ZOPENGLSAMPLER_HPP
|
||||
#define _ZOPENGLSAMPLER_HPP
|
||||
|
||||
#include <ZUtil/ZUtil.hpp>
|
||||
|
||||
#include <ZRenderer/ZSamplerBase.hpp>
|
||||
|
||||
#include <SST/SST_GLAPI.h>
|
||||
|
||||
//Forward Declarations
|
||||
class ZOpenGLRenderer;
|
||||
|
||||
struct ZOpenGLSamplerState
|
||||
{
|
||||
GLenum SWrapMode; //Wrapping mode for S
|
||||
GLenum TWrapMode; //Wrapping mode for T (unused for 1D)
|
||||
GLenum RWrapMode; //Wrapping mode for R (unused for 1D, 2D)
|
||||
|
||||
GLenum MinFilter; //Minification Filter (including mip filter)
|
||||
GLenum MagFilter; //Magnification Filter
|
||||
|
||||
float MaxAnisotropy; //Maximum Anisotropy (< 2.0 has no effect)
|
||||
float MinLOD; //Minimum LOD
|
||||
float MaxLOD; //Maximum LOD
|
||||
float LODBias; //LOD Bias
|
||||
|
||||
float BorderColor[4]; //RGBA Border Color
|
||||
|
||||
GLenum CompareMode; //Sampler Comparison Mode
|
||||
GLenum CompareFunc; //Sampler Comparison Function
|
||||
};
|
||||
|
||||
//OpenGL implementation of the ZSampler interface class
|
||||
class ZOpenGLSampler : public ZSamplerBase
|
||||
{
|
||||
private:
|
||||
DISABLE_COPY_AND_ASSIGN(ZOpenGLSampler);
|
||||
|
||||
protected:
|
||||
//The current renderer
|
||||
ZOpenGLRenderer* Renderer;
|
||||
|
||||
//Sampler State
|
||||
ZOpenGLSamplerState OpenGLSamplerState;
|
||||
|
||||
public:
|
||||
//OpenGL Handle for the Sampler object
|
||||
GLuint GLHandle;
|
||||
|
||||
//Gets the OpenGL Sampler State
|
||||
const ZOpenGLSamplerState& GetGLSamplerState()
|
||||
{
|
||||
switch (State.SWrapMode)
|
||||
{
|
||||
case ZSWM_CLAMP_EDGE: OpenGLSamplerState.SWrapMode = GL_CLAMP_TO_EDGE; break;
|
||||
case ZSWM_CLAMP_BORDER: OpenGLSamplerState.SWrapMode = GL_CLAMP_TO_BORDER; break;
|
||||
case ZSWM_MIRROR_REPEAT: OpenGLSamplerState.SWrapMode = GL_MIRRORED_REPEAT; break;
|
||||
case ZSWM_REPEAT: OpenGLSamplerState.SWrapMode = GL_REPEAT; break;
|
||||
default: OpenGLSamplerState.SWrapMode = GL_INVALID_ENUM; break;
|
||||
}
|
||||
|
||||
switch (State.TWrapMode)
|
||||
{
|
||||
case ZSWM_CLAMP_EDGE: OpenGLSamplerState.TWrapMode = GL_CLAMP_TO_EDGE; break;
|
||||
case ZSWM_CLAMP_BORDER: OpenGLSamplerState.TWrapMode = GL_CLAMP_TO_BORDER; break;
|
||||
case ZSWM_MIRROR_REPEAT: OpenGLSamplerState.TWrapMode = GL_MIRRORED_REPEAT; break;
|
||||
case ZSWM_REPEAT: OpenGLSamplerState.TWrapMode = GL_REPEAT; break;
|
||||
default: OpenGLSamplerState.TWrapMode = GL_INVALID_ENUM; break;
|
||||
}
|
||||
|
||||
switch (State.RWrapMode)
|
||||
{
|
||||
case ZSWM_CLAMP_EDGE: OpenGLSamplerState.RWrapMode = GL_CLAMP_TO_EDGE; break;
|
||||
case ZSWM_CLAMP_BORDER: OpenGLSamplerState.RWrapMode = GL_CLAMP_TO_BORDER; break;
|
||||
case ZSWM_MIRROR_REPEAT: OpenGLSamplerState.RWrapMode = GL_MIRRORED_REPEAT; break;
|
||||
case ZSWM_REPEAT: OpenGLSamplerState.RWrapMode = GL_REPEAT; break;
|
||||
default: OpenGLSamplerState.RWrapMode = GL_INVALID_ENUM; break;
|
||||
}
|
||||
|
||||
switch(State.MagFilter)
|
||||
{
|
||||
case ZSMAGF_NEAREST: OpenGLSamplerState.MagFilter = GL_NEAREST; break;
|
||||
case ZSMAGF_LINEAR: OpenGLSamplerState.MagFilter = GL_LINEAR; break;
|
||||
default: OpenGLSamplerState.MagFilter = GL_INVALID_ENUM; break;
|
||||
}
|
||||
|
||||
switch(State.MinFilter)
|
||||
{
|
||||
case ZSMINF_NEAREST: OpenGLSamplerState.MinFilter = GL_NEAREST; break;
|
||||
case ZSMINF_NEAREST_MIP_NEAREST: OpenGLSamplerState.MinFilter = GL_NEAREST_MIPMAP_NEAREST; break;
|
||||
case ZSMINF_NEAREST_MIP_LINEAR: OpenGLSamplerState.MinFilter = GL_NEAREST_MIPMAP_LINEAR; break;
|
||||
case ZSMINF_LINEAR: OpenGLSamplerState.MinFilter = GL_LINEAR; break;
|
||||
case ZSMINF_LINEAR_MIP_NEAREST: OpenGLSamplerState.MinFilter = GL_LINEAR_MIPMAP_NEAREST; break;
|
||||
case ZSMINF_LINEAR_MIP_LINEAR: OpenGLSamplerState.MinFilter = GL_LINEAR_MIPMAP_LINEAR; break;
|
||||
default: OpenGLSamplerState.MinFilter = GL_INVALID_ENUM; break;
|
||||
}
|
||||
|
||||
OpenGLSamplerState.MaxAnisotropy = State.MaxAnisotropy;
|
||||
OpenGLSamplerState.MinLOD = State.MinLOD;
|
||||
OpenGLSamplerState.MaxLOD = State.MaxLOD;
|
||||
OpenGLSamplerState.LODBias = State.LODBias;
|
||||
|
||||
OpenGLSamplerState.BorderColor[0] = State.BorderColor[0];
|
||||
OpenGLSamplerState.BorderColor[1] = State.BorderColor[1];
|
||||
OpenGLSamplerState.BorderColor[2] = State.BorderColor[2];
|
||||
OpenGLSamplerState.BorderColor[3] = State.BorderColor[3];
|
||||
|
||||
switch(State.CompareMode)
|
||||
{
|
||||
case ZSCM_NONE: OpenGLSamplerState.CompareMode = GL_NONE; break;
|
||||
case ZSCM_COMPARE_REF_TO_TEXTURE: OpenGLSamplerState.CompareMode = GL_COMPARE_REF_TO_TEXTURE; break;
|
||||
default: OpenGLSamplerState.CompareMode = GL_INVALID_ENUM; break;
|
||||
}
|
||||
|
||||
switch(State.CompareFunc)
|
||||
{
|
||||
case ZSCF_NEVER: OpenGLSamplerState.CompareFunc = GL_NEVER; break;
|
||||
case ZSCF_ALWAYS: OpenGLSamplerState.CompareFunc = GL_ALWAYS; break;
|
||||
case ZSCF_EQUAL: OpenGLSamplerState.CompareFunc = GL_EQUAL; break;
|
||||
case ZSCF_NOT_EQUAL: OpenGLSamplerState.CompareFunc = GL_NOTEQUAL; break;
|
||||
case ZSCF_LESS: OpenGLSamplerState.CompareFunc = GL_LESS; break;
|
||||
case ZSCF_LESS_EQUAL: OpenGLSamplerState.CompareFunc = GL_LEQUAL; break;
|
||||
case ZSCF_GREATER: OpenGLSamplerState.CompareFunc = GL_GREATER; break;
|
||||
case ZSCF_GREATER_EQUAL: OpenGLSamplerState.CompareFunc = GL_GEQUAL; break;
|
||||
default: OpenGLSamplerState.CompareFunc = GL_INVALID_ENUM; break;
|
||||
}
|
||||
|
||||
return OpenGLSamplerState;
|
||||
}
|
||||
|
||||
/*
|
||||
Default Constructor.
|
||||
*/
|
||||
ZOpenGLSampler(ZOpenGLRenderer* _renderer);
|
||||
|
||||
/*
|
||||
Destructor.
|
||||
*/
|
||||
~ZOpenGLSampler();
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
66
Include/ZRenderer/ZOpenGLShader.hpp
Normal file
66
Include/ZRenderer/ZOpenGLShader.hpp
Normal file
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
ZOpenGLShader.hpp
|
||||
Author: Chris Ertel <crertel@762studios.com>,
|
||||
James Russell <jcrussell@762studios.com>
|
||||
Created: 04/20/2011
|
||||
|
||||
Purpose:
|
||||
|
||||
OpenGL implementation of the shader interface.
|
||||
|
||||
License:
|
||||
|
||||
TODO
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef _ZOPENGLSHADER_HPP
|
||||
#define _ZOPENGLSHADER_HPP
|
||||
|
||||
#include <ZRenderer/ZShaderBase.hpp>
|
||||
|
||||
#include <ZUtil/ZUtil.hpp>
|
||||
|
||||
#include <SST/SST_GLAPI.h>
|
||||
|
||||
//Forward Declarations
|
||||
class ZOpenGLRenderer;
|
||||
|
||||
/*
|
||||
OpenGL Shader Implementation.
|
||||
*/
|
||||
class ZOpenGLShader : public ZShaderBase
|
||||
{
|
||||
private:
|
||||
DISABLE_COPY_AND_ASSIGN(ZOpenGLShader);
|
||||
|
||||
protected:
|
||||
//The renderer that created us
|
||||
ZOpenGLRenderer* Renderer;
|
||||
|
||||
//Method used to compile the shader
|
||||
static void Compile_(ZThread* _thread, void* _shader);
|
||||
|
||||
public:
|
||||
//OpenGL Shader Handle
|
||||
GLuint GLHandle;
|
||||
|
||||
/*
|
||||
Constructor.
|
||||
|
||||
@param _renderer - the current renderer instance
|
||||
@param _type - the type of shader
|
||||
*/
|
||||
ZOpenGLShader(ZOpenGLRenderer* _renderer, ZShaderType _type);
|
||||
|
||||
/*
|
||||
Destructor.
|
||||
*/
|
||||
virtual ~ZOpenGLShader();
|
||||
|
||||
//Subclass Override
|
||||
virtual bool Compile();
|
||||
};
|
||||
|
||||
#endif
|
||||
69
Include/ZRenderer/ZOpenGLShaderProgram.hpp
Normal file
69
Include/ZRenderer/ZOpenGLShaderProgram.hpp
Normal file
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
ZOpenGLShaderProgram.h
|
||||
Author: Chris Ertel <crertel@762studios.com>,
|
||||
James Russell <jcrussell@762studios.com>
|
||||
Created: 04/03/2011
|
||||
|
||||
Purpose:
|
||||
|
||||
TODO
|
||||
|
||||
License:
|
||||
|
||||
TODO
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef _ZOPENGLSHADERPROGRAM_HPP
|
||||
#define _ZOPENGLSHADERPROGRAM_HPP
|
||||
|
||||
#include <ZRenderer/ZShaderProgramBase.hpp>
|
||||
#include <ZRenderer/ZOpenGLShader.hpp>
|
||||
|
||||
#include <SST/SST_GLAPI.h>
|
||||
|
||||
//Forward Declarations
|
||||
class ZOpenGLRenderer;
|
||||
|
||||
//Struct we use to track opengl handles for uniform blocks and block members
|
||||
struct ZOpenGLUniformBlockData
|
||||
{
|
||||
GLuint BlockIndex; //OpenGL Index for UniformBlocks[i]
|
||||
ZArray<GLuint> MemberIndices; //OpenGL Index for UniformBlocks[i].Members[i]
|
||||
};
|
||||
|
||||
//OpenGL Implementation of ZShaderProgram
|
||||
class ZOpenGLShaderProgram : public ZShaderProgramBase
|
||||
{
|
||||
protected:
|
||||
//Parent renderer
|
||||
ZOpenGLRenderer* Renderer;
|
||||
|
||||
//Static method used to link a shader program
|
||||
static void Link_(ZThread* _thread, void* _shaderProgram);
|
||||
|
||||
public:
|
||||
//Handle to the program in OpenGL
|
||||
GLuint GLHandle;
|
||||
|
||||
//Our set of uniform indices, sampler indices, and stream indices
|
||||
ZArray<ZOpenGLUniformBlockData> OpenGLUniformBlockData;
|
||||
ZArray<GLuint> OpenGLSamplerData;
|
||||
ZArray<GLuint> OpenGLStreamData;
|
||||
|
||||
/*
|
||||
Constructor.
|
||||
|
||||
@param _renderer - the current renderer
|
||||
*/
|
||||
ZOpenGLShaderProgram(ZOpenGLRenderer* _renderer);
|
||||
|
||||
//Virtual destructor
|
||||
virtual ~ZOpenGLShaderProgram();
|
||||
|
||||
//Subclass Implementation
|
||||
virtual bool Link();
|
||||
};
|
||||
|
||||
#endif
|
||||
92
Include/ZRenderer/ZOpenGLTextureRenderTarget.h
Normal file
92
Include/ZRenderer/ZOpenGLTextureRenderTarget.h
Normal file
@@ -0,0 +1,92 @@
|
||||
/*
|
||||
ZOpenGLTextureRenderTarget.h
|
||||
Author: Chris Ertel (cre1)
|
||||
|
||||
Purpose: TODO
|
||||
|
||||
Changelog
|
||||
2011/05/22 - creation (cre1)
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef _ZOPENGLTEXTURERENDERTARGET_H
|
||||
#define _ZOPENGLTEXTURERENDERTARGET_H
|
||||
|
||||
#include <ZRendering/ZTextureRenderTarget.h>
|
||||
#include <ZRendering/ZOpenGLRenderer.h>
|
||||
#include <GLee/GLee.h>
|
||||
|
||||
class ZOpenGLTexture;
|
||||
class ZOpenGLTextureRenderTarget;
|
||||
|
||||
class ZOpenGLTextureRenderTargetLoadRequest : public ZThreadRequest
|
||||
{
|
||||
private:
|
||||
ZOpenGLTextureRenderTarget *Target;
|
||||
|
||||
public:
|
||||
ZOpenGLTextureRenderTargetLoadRequest(ZOpenGLTextureRenderTarget *_target);
|
||||
|
||||
void Execute(ZThread *_renderer);
|
||||
};
|
||||
|
||||
class ZOpenGLTextureRenderTarget : public ZTextureRenderTarget
|
||||
{
|
||||
friend class ZOpenGLTextureRenderTargetLoadRequest;
|
||||
protected:
|
||||
//The OpenGL Texture
|
||||
// ZOpenGLTexture Tex;
|
||||
|
||||
//The glhandle to the FrameBuffer
|
||||
GLuint FrameBufferHandle;
|
||||
|
||||
//The glhandle to the RenderBuffer
|
||||
GLuint RenderBufferHandle;
|
||||
float ClearColor[4];
|
||||
|
||||
int Width;
|
||||
int Height;
|
||||
int BPP;
|
||||
|
||||
public:
|
||||
//Default Constructor
|
||||
ZOpenGLTextureRenderTarget(ZOpenGLRenderer *_renderer, int _width, int _height, int _bpp, int _rgbaSize, float *_clearColor = NULL);
|
||||
|
||||
//Subclass Implementation
|
||||
bool Activate();
|
||||
|
||||
//Subclass Implementation
|
||||
void Deactivate();
|
||||
|
||||
void SetClearColor(float r, float g, float b, float a);
|
||||
|
||||
void SetClearColor(float* _in);
|
||||
|
||||
//Subclass Implementation (Currently Non-Functional)
|
||||
void SetDimensions(int _width, int _height)
|
||||
{
|
||||
URFP(_width);
|
||||
URFP(_height);
|
||||
}
|
||||
|
||||
//Subclass Implementation (Currently Non-Functional)
|
||||
void SetBitsPerPixel(int _bbp)
|
||||
{
|
||||
URFP(_bbp);
|
||||
}
|
||||
|
||||
//Subclass Implementation (Currently Non-Functional)
|
||||
void SetRGBASize(int _rgbaSize)
|
||||
{
|
||||
URFP(_rgbaSize);
|
||||
}
|
||||
|
||||
//Gets the render target as a texture
|
||||
ZTexture* GetTexture();
|
||||
|
||||
//Gets the texture as a render target
|
||||
ZRenderTarget* GetRenderTarget();
|
||||
};
|
||||
|
||||
#endif
|
||||
46
Include/ZRenderer/ZOpenGLVertexParams.hpp
Normal file
46
Include/ZRenderer/ZOpenGLVertexParams.hpp
Normal file
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
ZOpenGLVertexParams.hpp
|
||||
Author: Patrick Baggett <ptbaggett@762studios.com>
|
||||
Created: 12/13/2012
|
||||
|
||||
Purpose:
|
||||
|
||||
OpenGL specific version of ZVertexParams that implements VAOs.
|
||||
|
||||
License:
|
||||
|
||||
TODO
|
||||
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef _ZOPENGLVERTEXPARAMS_HPP
|
||||
#define _ZOPENGLVERTEXPARAMS_HPP
|
||||
|
||||
#include <ZRenderer/ZVertexParams.hpp>
|
||||
#include <ZRenderer/ZOpenGLShaderProgram.hpp>
|
||||
#include <SST/SST_GLAPI.h>
|
||||
|
||||
|
||||
class ZOpenGLRenderer;
|
||||
|
||||
class ZOpenGLVertexParams : public ZVertexParams
|
||||
{
|
||||
public:
|
||||
ZOpenGLVertexParams(ZOpenGLRenderer* renderer) :
|
||||
Renderer(renderer), vaoHandle(0), arrayBufferBound(0), elementBufferBound(0)
|
||||
{
|
||||
}
|
||||
|
||||
~ZOpenGLVertexParams();
|
||||
|
||||
void UpdateDirty(ZOpenGLShaderProgram* prgm);
|
||||
|
||||
ZOpenGLRenderer* Renderer;
|
||||
GLuint vaoHandle; //Vertex Array Object (VAO) handle
|
||||
GLuint arrayBufferBound; //VBO (GL_ARRAY_BUFFER) that was bound
|
||||
GLuint elementBufferBound; //VBO (GL_ELEMENT_BUFFER) that was bound
|
||||
};
|
||||
|
||||
#endif
|
||||
60
Include/ZRenderer/ZOpenGLWindowRenderTarget.hpp
Normal file
60
Include/ZRenderer/ZOpenGLWindowRenderTarget.hpp
Normal file
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
ZOpenGLWindowRenderTarget.hpp
|
||||
Author: James Russell <jcrussell@762studios.com>
|
||||
Created: 04/01/2011
|
||||
|
||||
Purpose:
|
||||
|
||||
Initializes and manages an OpenGL window.
|
||||
|
||||
License:
|
||||
|
||||
TODO
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef _ZOPENGLWINDOWRENDERTARGET_HPP
|
||||
#define _ZOPENGLWINDOWRENDERTARGET_HPP
|
||||
|
||||
#include <ZRenderer/ZWindowRenderTargetBase.hpp>
|
||||
|
||||
//Forward Declarations
|
||||
class ZOpenGLRenderer;
|
||||
|
||||
/*
|
||||
Screen Render Target for the OpenGL library.
|
||||
*/
|
||||
class ZOpenGLWindowRenderTarget : public ZWindowRenderTargetBase
|
||||
{
|
||||
private:
|
||||
DISABLE_COPY_AND_ASSIGN(ZOpenGLWindowRenderTarget);
|
||||
|
||||
protected:
|
||||
//Renderer Instance
|
||||
ZOpenGLRenderer *Renderer;
|
||||
|
||||
public:
|
||||
//OpenGL Context
|
||||
SST_OpenGLContext GLContext;
|
||||
|
||||
/*
|
||||
Parameterized Constructor.
|
||||
|
||||
@param _renderer - the renderer instance
|
||||
@param _glContext - the OpenGL context to bind to this window
|
||||
@param _window - the window instance (created with libsst-wm)
|
||||
@param _screen - the screen index chosen
|
||||
*/
|
||||
ZOpenGLWindowRenderTarget(ZOpenGLRenderer* _renderer, SST_OpenGLContext _glContext, SST_Window _window, size_t _screenIndex);
|
||||
|
||||
/*
|
||||
Destructor.
|
||||
*/
|
||||
~ZOpenGLWindowRenderTarget();
|
||||
|
||||
//Subclass Override
|
||||
virtual bool SwapBuffers();
|
||||
};
|
||||
|
||||
#endif
|
||||
71
Include/ZRenderer/ZRenderBuffer.hpp
Normal file
71
Include/ZRenderer/ZRenderBuffer.hpp
Normal file
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
ZRenderBuffer.hpp
|
||||
Author: James Russell <jcrussell@762studios.com>
|
||||
Created: 04/03/2011
|
||||
|
||||
Purpose:
|
||||
|
||||
Buffer that can be used for depth and stencil buffers in frame buffer render targets
|
||||
for off-screen rendering.
|
||||
|
||||
License:
|
||||
|
||||
TODO
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef _ZRENDERBUFFER_HPP
|
||||
#define _ZRENDERBUFFER_HPP
|
||||
|
||||
#include <ZRenderer/ZRendererBuild.hpp>
|
||||
|
||||
//Enumeration of render buffer type
|
||||
enum ZRenderBufferType
|
||||
{
|
||||
ZRBT_DEPTH16, //16-bit Depth Storage
|
||||
ZRBT_DEPTH24, //24-bit Depth Storage
|
||||
ZRBT_DEPTH32, //32-bit Depth Storage
|
||||
ZRBT_STENCIL8, //8-bit Stencil Storage
|
||||
ZRBT_DEPTH24_STENCIL8, //24-bit Depth and 8-bit Stencil
|
||||
ZRBT_SIZE
|
||||
};
|
||||
|
||||
class ZRenderBuffer
|
||||
{
|
||||
public:
|
||||
//Virtual Destructor
|
||||
virtual ~ZRenderBuffer() { }
|
||||
|
||||
/*
|
||||
public ZRenderBuffer::GetHeight
|
||||
|
||||
Gets the height value for the render buffer (in pixels).
|
||||
|
||||
@return (size_t) - height value
|
||||
@context (all)
|
||||
*/
|
||||
virtual size_t GetHeight() = 0;
|
||||
|
||||
/*
|
||||
virtual public ZRenderBuffer::GetType
|
||||
|
||||
Gets the type of render buffer this is set up to be (depth or stencil).
|
||||
|
||||
@return (ZRenderBufferType) - the type of render buffer
|
||||
@context (all)
|
||||
*/
|
||||
virtual ZRenderBufferType GetType() = 0;
|
||||
|
||||
/*
|
||||
public ZRenderBuffer::GetWidth
|
||||
|
||||
Gets the width value for the render buffer (in pixels).
|
||||
|
||||
@return (size_t) - width value
|
||||
@context (all)
|
||||
*/
|
||||
virtual size_t GetWidth() = 0;
|
||||
};
|
||||
|
||||
#endif
|
||||
114
Include/ZRenderer/ZRenderTarget.hpp
Normal file
114
Include/ZRenderer/ZRenderTarget.hpp
Normal file
@@ -0,0 +1,114 @@
|
||||
/*
|
||||
ZRenderTarget.hpp
|
||||
Author: James Russell <jcrussell@762studios.com>
|
||||
Created: 03/20/2011
|
||||
|
||||
Purpose:
|
||||
|
||||
Defines an interface for a rendering surface.
|
||||
|
||||
License:
|
||||
|
||||
TODO
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef _ZRENDERTARGET_HPP
|
||||
#define _ZRENDERTARGET_HPP
|
||||
|
||||
#include <ZRenderer/ZRendererBuild.hpp>
|
||||
#include <ZRenderer/ZRendererResource.hpp>
|
||||
|
||||
//Enumeration of possible render target types
|
||||
enum ZRenderTargetType
|
||||
{
|
||||
ZRTT_WINDOW, //Used for window render targets
|
||||
ZRTT_FRAMEBUFFER, //Used for frame buffer render targets
|
||||
ZRTT_SIZE
|
||||
};
|
||||
|
||||
//Used to flag which buffers should be cleared, and to what value
|
||||
struct ZRenderTargetClearFlags
|
||||
{
|
||||
bool AutoClear; //Indicates that the renderer should 'clear' the toggled buffers before rendering to this target
|
||||
|
||||
bool ClearColorBuffer; //Indicates we should clear the color buffer
|
||||
bool ClearDepthBuffer; //Indicates we should clear the depth buffer
|
||||
bool ClearStencilBuffer; //Indicates we should clear the stencil buffer
|
||||
|
||||
float ClearColor[4]; //RGBA clear color to use
|
||||
|
||||
//Default Constructor
|
||||
ZRenderTargetClearFlags()
|
||||
: AutoClear(true), ClearColorBuffer(true), ClearDepthBuffer(true), ClearStencilBuffer(false)
|
||||
{
|
||||
ClearColor[0] = 0.0f;
|
||||
ClearColor[1] = 0.0f;
|
||||
ClearColor[2] = 0.0f;
|
||||
ClearColor[3] = 1.0f;
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
RenderTarget Interface.
|
||||
*/
|
||||
class ZRenderTarget : public ZRendererResource
|
||||
{
|
||||
public:
|
||||
//Virtual Destructor
|
||||
virtual ~ZRenderTarget() { }
|
||||
|
||||
/*
|
||||
public ZRenderTarget::GetClearFlags
|
||||
|
||||
Gets the current set of clear flags for this render target.
|
||||
|
||||
@return (const ZRenderTargetClearFlags&) - clearing flags for this render target
|
||||
@context (all)
|
||||
*/
|
||||
virtual const ZRenderTargetClearFlags& GetClearFlags() = 0;
|
||||
|
||||
/*
|
||||
public ZRenderTarget::GetHeight
|
||||
|
||||
Gets the height value for the render target (in pixels).
|
||||
|
||||
@return (size_t)
|
||||
@context (all)
|
||||
*/
|
||||
virtual size_t GetHeight() = 0;
|
||||
|
||||
/*
|
||||
public ZRenderTarget::GetType
|
||||
|
||||
Gets the type of render target.
|
||||
|
||||
@return (ZRenderTargetType) - the type of render target
|
||||
@context (all)
|
||||
*/
|
||||
virtual ZRenderTargetType GetType() = 0;
|
||||
|
||||
/*
|
||||
public ZRenderTarget::GetWidth
|
||||
|
||||
Gets the width value for the render target (in pixels).
|
||||
|
||||
@return (size_t)
|
||||
@context (all)
|
||||
*/
|
||||
virtual size_t GetWidth() = 0;
|
||||
|
||||
/*
|
||||
public ZRenderTarget::SetClearFlags
|
||||
|
||||
Sets the clear flags for this render target.
|
||||
|
||||
@param _flags - flags structure which has our clear settings
|
||||
@return (bool) - true if able to set flags, false if resource contended
|
||||
@context (all)
|
||||
*/
|
||||
virtual bool SetClearFlags(const ZRenderTargetClearFlags& _flags) = 0;
|
||||
};
|
||||
|
||||
#endif
|
||||
559
Include/ZRenderer/ZRenderer.hpp
Normal file
559
Include/ZRenderer/ZRenderer.hpp
Normal file
@@ -0,0 +1,559 @@
|
||||
/*
|
||||
ZRenderer.hpp
|
||||
Authors: Patrick Baggett <ptbaggett@762studios.com>,
|
||||
Chris Ertel <crertel@762studios.com>,
|
||||
James Russell <jcrussell@762studios.com>
|
||||
Created: 3/20/2011
|
||||
|
||||
Purpose:
|
||||
|
||||
Defines an interface for rendering to screen in graphics-library agnostic fashion.
|
||||
|
||||
License:
|
||||
|
||||
TODO
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef _ZRENDERER_HPP
|
||||
#define _ZRENDERER_HPP
|
||||
|
||||
#include <ZRenderer/ZRendererBuild.hpp>
|
||||
|
||||
#include <SST/SST_WM.h>
|
||||
|
||||
#include <ZUtil/ZUtil.hpp>
|
||||
|
||||
#include <ZRenderer/ZDataBuffer.hpp>
|
||||
#include <ZRenderer/ZRenderTarget.hpp>
|
||||
#include <ZRenderer/ZFramebufferRenderTarget.hpp>
|
||||
#include <ZRenderer/ZWindowRenderTarget.hpp>
|
||||
#include <ZRenderer/ZTexture.hpp>
|
||||
#include <ZRenderer/ZSampler.hpp>
|
||||
#include <ZRenderer/ZShader.hpp>
|
||||
#include <ZRenderer/ZShaderProgram.hpp>
|
||||
#include <ZRenderer/ZShaderParams.hpp>
|
||||
#include <ZRenderer/ZVertexParams.hpp>
|
||||
#include <ZRenderer/ZIndexParams.hpp>
|
||||
|
||||
//Forward Declarations
|
||||
class ZRenderer;
|
||||
|
||||
//Typedef for a frame context (opaque handle)
|
||||
typedef void* ZFrameContext;
|
||||
|
||||
//Rendering phases the ZRenderer can exist in
|
||||
enum ZRenderPhase
|
||||
{
|
||||
ZRP_UNINITIALIZED, //Renderer has yet to be initialized
|
||||
ZRP_IDLE, //Renderer is idle (no frame contexts currently created)
|
||||
ZRP_FRAME_ACCEPTING, //Renderer is accepting SubmitDrawData calls (frame contexts have been created)
|
||||
ZRP_FRAME_RENDERING, //Renderer is rendering Geometry (a frame context is rendering)
|
||||
ZRP_SIZE
|
||||
};
|
||||
|
||||
//Render State Structure, used to set up a render state for SubmitDrawData calls
|
||||
struct ZRenderState
|
||||
{
|
||||
public:
|
||||
//The default constructor for render state initializes to a sane configuration
|
||||
ZRenderState()
|
||||
: EnableStencilTest(false),
|
||||
EnableBlend(true),
|
||||
SourceBlendFunc(SBFV_SRC_ALPHA),
|
||||
DestBlendFunc(DBFV_ONE_MINUS_SRC_ALPHA),
|
||||
blendR(0), blendG(0), blendB(0), blendA(0),
|
||||
EnableCullTest(false),
|
||||
EnableDepthTest(true),
|
||||
DepthFunc(DFV_LESS_THAN),
|
||||
EnableDepthWrite(true) { }
|
||||
|
||||
/////////////////////////////////
|
||||
/* Draw Sort Relevant Settings */
|
||||
/////////////////////////////////
|
||||
|
||||
// BLENDING
|
||||
uint32_t EnableBlend:1; //Enables Blending
|
||||
uint32_t SourceBlendFunc:4; //Specifies Source Blending Function
|
||||
uint32_t DestBlendFunc:3; //Specifies Destination Blending Function
|
||||
|
||||
enum SourceBlendFuncValue //Values for the Source Blend Function
|
||||
{
|
||||
SBFV_ZERO,
|
||||
SBFV_ONE,
|
||||
SBFV_SRC_COLOR,
|
||||
SBFV_ONE_MINUS_SRC_COLOR,
|
||||
SBFV_DST_COLOR,
|
||||
SBFV_ONE_MINUS_DST_COLOR,
|
||||
SBFV_SRC_ALPHA,
|
||||
SBFV_ONE_MINUS_SRC_ALPHA,
|
||||
SBFV_DST_ALPHA,
|
||||
SBFV_ONE_MINUS_DST_ALPHA,
|
||||
SBFV_CONSTANT_COLOR,
|
||||
SBFV_ONE_MINUS_CONSTANT_COLOR,
|
||||
SBFV_CONSTANT_ALPHA,
|
||||
SBFV_ONE_MINUS_CONSTANT_ALPHA,
|
||||
SBFV_SRC_ALPHA_SATURATE,
|
||||
SBFV_SIZE
|
||||
};
|
||||
|
||||
enum DestBlendFuncValue //Values for the Destination Blend Function
|
||||
{
|
||||
DBFV_ZERO,
|
||||
DBFV_ONE,
|
||||
DBFV_SRC_COLOR,
|
||||
DBFV_ONE_MINUS_SRC_COLOR,
|
||||
DBFV_DST_COLOR,
|
||||
DBFV_ONE_MINUS_DST_COLOR,
|
||||
DBFV_SRC_ALPHA,
|
||||
DBFV_ONE_MINUS_SRC_ALPHA,
|
||||
DBFV_DST_ALPHA,
|
||||
DBFV_ONE_MINUS_DST_ALPHA,
|
||||
DBFV_CONSTANT_COLOR,
|
||||
DBFV_ONE_MINUS_CONSTANT_COLOR,
|
||||
DBFV_CONSTANT_ALPHA,
|
||||
DBFV_ONE_MINUS_CONSTANT_ALPHA,
|
||||
DBFV_SIZE
|
||||
};
|
||||
|
||||
float blendR; //Red value used when blending needs a constant color
|
||||
float blendG; //Green value used when blending needs a constant color
|
||||
float blendB; //Blue value used when blending needs a constant color
|
||||
float blendA; //Alpha value used when blending needs a constant color
|
||||
|
||||
// DEPTH
|
||||
uint32_t EnableDepthTest:1; //Bit Enables Depth Testing
|
||||
uint32_t EnableDepthWrite:1; //Sets Depth Buffer to Read Only (Depth Values are not written)
|
||||
uint32_t DepthFunc:3; //Specifies Depth Function
|
||||
|
||||
enum DepthFuncValue //Values for the Depth Function
|
||||
{
|
||||
DFV_NEVER,
|
||||
DFV_LESS_THAN,
|
||||
DFV_EQUAL,
|
||||
DFV_LESS_THAN_EQUAL,
|
||||
DFV_GREATER_THAN,
|
||||
DFV_NOT_EQUAL,
|
||||
DFV_GREATER_THAN_EQUAL,
|
||||
DFV_ALWAYS,
|
||||
DFV_SIZE
|
||||
};
|
||||
|
||||
// CULLING
|
||||
uint32_t EnableCullTest:1; //Enable or disable face culling.
|
||||
uint32_t CullMode:2; //Sets up front/back/both culling
|
||||
|
||||
enum CullModeValue
|
||||
{
|
||||
CMV_FRONT,
|
||||
CMV_BACK,
|
||||
CMV_FRONT_AND_BACK,
|
||||
CMV_SIZE
|
||||
};
|
||||
|
||||
uint32_t CullWinding:1; //Sets winding for culling
|
||||
|
||||
enum CullWindingValue
|
||||
{
|
||||
CWV_CW,
|
||||
CWV_CCW,
|
||||
CWV_SIZE
|
||||
};
|
||||
|
||||
// STENCIL
|
||||
uint32_t EnableStencilTest:1; //Bit Enables Stencil Testing
|
||||
uint32_t StencilTestFuncFront:4; //Specifies the stencil comparisons
|
||||
uint32_t StencilTestMaskFront:8; //Mask for front facing stencil post-op
|
||||
uint32_t StencilTestReferenceFront:8; //Reference value for front facing stencil post-op
|
||||
uint32_t StencilTestFuncBack:4; //Specifies the stencil comparisons
|
||||
uint32_t StencilTestMaskBack:8; //Mask for back facing stencil post-op
|
||||
uint32_t StencilTestReferenceBack:8; //Reference value for back facing stencil post-op
|
||||
|
||||
enum StencilComparisonsValue //Values for the stencil comparisons
|
||||
{
|
||||
SCV_NEVER,
|
||||
SCV_ALWAYS,
|
||||
SCV_LESS,
|
||||
SCV_LEQUAL,
|
||||
SCV_EQUAL,
|
||||
SCV_GEQUAL,
|
||||
SCV_GREATER,
|
||||
SCV_NOTEQUAL,
|
||||
SCV_SIZE
|
||||
};
|
||||
|
||||
uint32_t StencilOpStencilFailFront:3; //Specifies the stencil operation when stencil test fails for front-facing polys
|
||||
uint32_t StencilOpStencilPassDepthFailFront:3; //Specifies the stencil operation when stencil test succeeds and depth test fails fails for front-facing polys
|
||||
uint32_t StencilOpStencilPassDepthPassFront:3; //Specifies the stencil operation when stencil and depth tests pass fails for front-facing polys
|
||||
uint32_t StencilOpStencilFailBack:3; //Specifies the stencil operation when stencil test fails for back-facing polys
|
||||
uint32_t StencilOpStencilPassDepthFailBack:3; //Specifies the stencil operation when stencil test succeeds and depth test fails for back-facing polys
|
||||
uint32_t StencilOpStencilPassDepthPassBack:3; //Specifies the stencil operation when stencil and depth tests pass for back-facing polys
|
||||
|
||||
enum StencilOperationValue //Values for the stencil operations
|
||||
{
|
||||
SOV_KEEP,
|
||||
SOV_ZERO,
|
||||
SOV_REPLACE,
|
||||
SOV_INCR,
|
||||
SOV_INCR_WRAP,
|
||||
SOV_DECR,
|
||||
SOV_DECR_WRAP,
|
||||
SOV_INVERT,
|
||||
SOV_SIZE
|
||||
};
|
||||
};
|
||||
|
||||
class ZRenderer : public ZThread
|
||||
{
|
||||
protected:
|
||||
//Default Constructor
|
||||
ZRenderer() : ZThread("ZRenderer Thread") { }
|
||||
|
||||
public:
|
||||
//Virtual Destructor
|
||||
virtual ~ZRenderer() { }
|
||||
|
||||
//////////////////////////
|
||||
/* Lifecycle Operations */
|
||||
//////////////////////////
|
||||
|
||||
/*
|
||||
virtual public ZRenderer::Init
|
||||
|
||||
Initializes the Renderer for use as a long running subsystem. After this call, the
|
||||
render thread will be running.
|
||||
|
||||
@return (bool)
|
||||
@context (all)
|
||||
*/
|
||||
virtual bool Init() = 0;
|
||||
|
||||
/*
|
||||
virtual public ZRenderer::Shutdown
|
||||
|
||||
Shuts down the system and stops the render thread.
|
||||
|
||||
@return (void)
|
||||
@context (all)
|
||||
*/
|
||||
virtual void Shutdown() = 0;
|
||||
|
||||
///////////////////////////
|
||||
/* Renderer Data Getters */
|
||||
///////////////////////////
|
||||
|
||||
/*
|
||||
virtual public ZRenderer::GetCapabilities
|
||||
|
||||
Returns a map describing the capabilities and configuration of this renderer. All
|
||||
renderer implementations must map the following keys:
|
||||
|
||||
gl { directx, opengl }
|
||||
gl.version { 9.0c, 10.0, 10.1, 11.0, 11.1, 2.1, 3.1, 3.2, 3.3 ... }
|
||||
: version number should always have major.minor format and should be the highest version required
|
||||
gl.shaderlang { hlsl_40, hlsl_30, hlsl, glsl_14, glsl_13, glsl_12, glsl_11, glsl, ... }
|
||||
: shading languages accepted should be listed in a comma separated list in order of preference
|
||||
|
||||
data_buffer.block_alignment { integer }
|
||||
: alignment requirement for buffer blocks
|
||||
|
||||
frame_buffer_render_target.max_color_attachments { integer }
|
||||
: maximum number of color buffer attachments
|
||||
|
||||
Other keys may be supported depending upon the implementation.
|
||||
|
||||
@return (const ZHashMap<ZString, ZString>&) - map of capabilities
|
||||
@context (all)
|
||||
*/
|
||||
virtual const ZHashMap<ZString, ZString>& GetCapabilities() = 0;
|
||||
|
||||
/*
|
||||
virtual public ZRenderer::GetRenderPhase
|
||||
|
||||
Gets the current rendering phase.
|
||||
|
||||
@return (ZRenderPhase) - current rendering phase
|
||||
@context (all)
|
||||
*/
|
||||
virtual ZRenderPhase GetRenderPhase() = 0;
|
||||
|
||||
//////////////////////////
|
||||
/* Logistics Operations */
|
||||
//////////////////////////
|
||||
|
||||
/*
|
||||
virtual public ZRenderer::CreateDataBuffer
|
||||
|
||||
Creates a data buffer which contains data stored in graphics memory. The data
|
||||
buffer is created but not initialized with values (use FillBuffer or MapBuffer).
|
||||
|
||||
Keep in mind when allocating a buffer that defines block data that determining the
|
||||
required size to fit all blocks includes taking into account alignment requirements.
|
||||
The alignment requirement for block data for this renderer can be determined through
|
||||
the capabilities map with key 'buffer.block_alignment'.
|
||||
|
||||
@param _type - the type of buffer to allocate
|
||||
@param _usage - the usage pattern the buffer will follow
|
||||
@param _size - the size (in bytes) to allocate
|
||||
@return (ZDataBuffer) - new data buffer object, NULL if not successful
|
||||
@context (all)
|
||||
*/
|
||||
virtual ZPtr<ZDataBuffer> CreateDataBuffer(ZDataBufferType _type,
|
||||
ZDataBufferUsage _usage,
|
||||
size_t _size
|
||||
) = 0;
|
||||
|
||||
/*
|
||||
virtual public ZRenderer::CreateDrawParams
|
||||
|
||||
Creates a draw parameters binding class, which is provided to the draw calls and
|
||||
is used to bind data to shader variables.
|
||||
|
||||
@param _type - the type of draw parameters binding
|
||||
@return (ZPtr<ZDrawParams>) - new draw parameters object, NULL if not successful
|
||||
@context (all)
|
||||
*/
|
||||
virtual ZPtr<ZDrawParams> CreateDrawParams(ZDrawParamsType _type) = 0;
|
||||
|
||||
/*
|
||||
virtual public ZRenderer::CreateFrameBufferRenderTarget
|
||||
|
||||
Function to create a framebuffer-backed render target.
|
||||
|
||||
@param _width - number of pixels wide to make the frame buffer
|
||||
@param _height - number of pixels tall to make the frame buffer
|
||||
@return (ZPtr<ZFramebufferRenderTarget>) - new frame buffer render target, NULL if not successful
|
||||
@context (all)
|
||||
*/
|
||||
virtual ZPtr<ZFramebufferRenderTarget> CreateFrameBufferRenderTarget(size_t _width, size_t _height) = 0;
|
||||
|
||||
/*
|
||||
virtual public ZRenderer::CreateRenderBuffer
|
||||
|
||||
Function to create a render buffer for use in a frame buffer render target.
|
||||
|
||||
@param _type - the type of render buffer this will be
|
||||
@param _width - number of pixels wide to make the render buffer
|
||||
@param _height - number of pixels tall to make the render buffer
|
||||
@return (ZPtr<ZRenderBuffer>) - new render buffer, NULL if not successful
|
||||
@context (all)
|
||||
*/
|
||||
virtual ZPtr<ZRenderBuffer> CreateRenderBuffer(ZRenderBufferType _type, size_t _width, size_t _height) = 0;
|
||||
|
||||
/*
|
||||
virtual public ZRenderer::CreateSampler
|
||||
|
||||
Creates a sampler object to use as a view onto a texture.
|
||||
|
||||
@return (ZPtr<ZSampler>) - new sampler object, NULL if unsuccessful
|
||||
@context (all)
|
||||
*/
|
||||
virtual ZPtr<ZSampler> CreateSampler() = 0;
|
||||
|
||||
/*
|
||||
virtual public ZRenderer::CreateShader
|
||||
|
||||
Function to create a shader object for the renderer.
|
||||
|
||||
@param _type - type of shader to create:
|
||||
ZST_SOFT : Soft shaders
|
||||
ZST_VERTEX : Vertex shaders
|
||||
ZST_HULL : Hull shaders
|
||||
ZST_DOMAIN : Domain shaders
|
||||
ZST_GEOMETRY: Geometry shaders
|
||||
ZST_FRAGMENT: Fragment (pixel) shaders
|
||||
|
||||
@return (ZPtr<ZShader>) - the created shader, NULL if not successful
|
||||
@context (all)
|
||||
*/
|
||||
virtual ZPtr<ZShader> CreateShader(ZShaderType _type) = 0;
|
||||
|
||||
/*
|
||||
virtual public ZRenderer::CreateShaderProgram
|
||||
|
||||
Function to create a shader program.
|
||||
|
||||
@return (ZPtr<ZShaderProgram>) - new shader program, NULL if not successful
|
||||
@context (all)
|
||||
*/
|
||||
virtual ZPtr<ZShaderProgram> CreateShaderProgram() = 0;
|
||||
|
||||
/*
|
||||
virtual public ZRenderer::CreateTexture
|
||||
|
||||
Creates a texture object.
|
||||
|
||||
In the case of cube map textures, the bitmap format describes a single 'side'
|
||||
of the cube map texture.
|
||||
|
||||
If the bitmap provided has NULL for data, then the texture storage is initialized
|
||||
but no data is copied.
|
||||
|
||||
@param _type - the type of texture
|
||||
@param _format - the texture internal storage format
|
||||
@param _usage - the usage type of the texture
|
||||
@param _bitmap - bitmap structure containing image format and size, as well as data (can be NULL)
|
||||
@param _generateMipmaps - indicating whether or not we should generate mipmaps
|
||||
@return (ZPtr<ZTexture>) - new texture object, NULL if not successful
|
||||
@context (all)
|
||||
*/
|
||||
virtual ZPtr<ZTexture> CreateTexture(ZTextureType _type,
|
||||
ZTextureFormat _format,
|
||||
ZTextureUsage _usage,
|
||||
const ZBitmap& _bitmap,
|
||||
bool _generateMipmaps) = 0;
|
||||
|
||||
/*
|
||||
virtual public ZRenderer::CreateWindowRenderTarget
|
||||
|
||||
Creates a window render target.
|
||||
|
||||
@param _window - the window handle (created using libsst-wm)
|
||||
@param _screenIndex - the screen index bound to the window
|
||||
@return (ZPtr<ZRenderTarget>) - new window render target, NULL if not successful
|
||||
@context (all)
|
||||
*/
|
||||
virtual ZPtr<ZRenderTarget> CreateWindowRenderTarget(SST_Window _window,
|
||||
size_t _screenIndex
|
||||
) = 0;
|
||||
|
||||
////////////////////////
|
||||
/* Frame Data Getters */
|
||||
////////////////////////
|
||||
|
||||
/*
|
||||
virtual public ZRenderer::GetFrameRenderTarget
|
||||
|
||||
Gets the render target set for the given frame context.
|
||||
|
||||
@param _frameContext - frame context
|
||||
@return (ZRenderTarget*) - the render target for the given context
|
||||
@context (all)
|
||||
*/
|
||||
virtual ZRenderTarget* GetFrameRenderTarget(ZFrameContext _frameContext) = 0;
|
||||
|
||||
//////////////////////////
|
||||
/* Rendering Operations */
|
||||
//////////////////////////
|
||||
|
||||
/*
|
||||
The renderer can maintain a few different states, each of which is described by an enumeration. The various
|
||||
rendering operations affect this state, and thread synchronization calls such as WaitFrameStart and WaitFrameEnd
|
||||
will wait until events are triggered after state changes, as follows.
|
||||
|
||||
BeginFrame()
|
||||
| SubmitDrawData()
|
||||
| | RenderFrame()
|
||||
| +-------+-------+ |
|
||||
| | | | |
|
||||
---------------+---+-------+-------+---+-----------------------+---------------
|
||||
===============|///////////////////////|///////////////////////|===============
|
||||
ZRP_IDLE ... =|/ ZRP_FRAME_ACCEPTING /|/ ZRP_FRAME_RENDERING /|= ZRP_IDLE ...
|
||||
===============|///////////////////////|///////////////////////|===============
|
||||
| |
|
||||
+-> WaitFrameStart() +-> WaitFrameEnd()
|
||||
^ |
|
||||
| Frame to Render? |
|
||||
+<----------------------+
|
||||
|
||||
Because of the multi threaded nature of ZRenderer, multiple threads can call SubmitDrawData to populate
|
||||
the render lists full of buffered data to draw. A single call should be placed to BeginFrame for each
|
||||
frame context that is desired, and a single call to RenderFrame should occur for each frame context that has
|
||||
been created.
|
||||
|
||||
It is guaranteed that order will be maintained between calls to RenderFrame, meaning if RenderFrame is called
|
||||
for frame context 0, and then afterwards RenderFrame is called for frame context 1, frame context 0 is guaranteed
|
||||
to render in its entirety before frame context 0 is rendered.
|
||||
*/
|
||||
|
||||
/*
|
||||
virtual public ZRenderer::BeginFrame
|
||||
|
||||
Tells the renderer that threads will begin providing draw data for a frame of rendering. The value returned
|
||||
is later used as a frame context for render calls.
|
||||
|
||||
BeginFrame can be called multiple times, each time returning a new frame context that can be provided
|
||||
for draw calls.
|
||||
|
||||
BeginFrame should be called once for as many frame contexts there will be before beginning render calls
|
||||
for any of them. Calling BeginFrame after other frames have begun rendering results in undefined
|
||||
behavior. Frame contexts should never be re-used across multiple render cycles - always ask for a new one.
|
||||
|
||||
@param _canvas - the canvas to render to
|
||||
@return (ZFrameContext) - the frame context that has been created
|
||||
@context (all)
|
||||
*/
|
||||
virtual ZFrameContext BeginFrame(ZPtr<ZRenderTarget> _canvas) = 0;
|
||||
|
||||
/*
|
||||
virtual public ZRenderer::EndFrame
|
||||
|
||||
TODO
|
||||
|
||||
@param _frameContext - the frame context we are done submitting draw data to
|
||||
@return (void)
|
||||
@context (all)
|
||||
*/
|
||||
virtual void EndFrame(ZFrameContext _frameContext) = 0;
|
||||
|
||||
/*
|
||||
virtual public ZRenderer::SubmitDrawData
|
||||
|
||||
Draws geometry defined in a DataBuffer (Queues them up for rendering).
|
||||
|
||||
@param _frameContext - the frame context to provide data for
|
||||
@param _shaderProgram - the shader program to draw with
|
||||
@param _shaderParams - the shader parameters binding
|
||||
@param _vertexParams - the vertex parameters binding
|
||||
@param _indexParams - the index parameters binding
|
||||
@param _renderState - the render state to render the geometry with
|
||||
@param _drawGroup - the draw group to render this call with; objects with lower draw group
|
||||
are rendered before objects with higher draw group
|
||||
@return (void)
|
||||
@context (all)
|
||||
*/
|
||||
virtual void SubmitDrawData(ZFrameContext _frameContext,
|
||||
ZPtr<ZShaderProgram> _shaderProgram,
|
||||
ZPtr<ZShaderParams> _shaderParams,
|
||||
ZPtr<ZVertexParams> _vertexParams,
|
||||
ZPtr<ZIndexParams> _indexParams,
|
||||
const ZRenderState& _renderState,
|
||||
int _drawGroup = 0
|
||||
) = 0;
|
||||
|
||||
/*
|
||||
virtual public ZRenderer::RenderFrame
|
||||
|
||||
Renders the frame context.
|
||||
|
||||
@param _frameContext - the frame context to render
|
||||
@return (void)
|
||||
@context (all)
|
||||
*/
|
||||
virtual void RenderFrame(ZFrameContext _frameContext) = 0;
|
||||
|
||||
/*
|
||||
virtual public ZRenderer::WaitFrameStart
|
||||
|
||||
Calling thread waits until RenderFrame is called for the given frame context.
|
||||
|
||||
@param _frameContext - the frame context to wait for
|
||||
@return (void)
|
||||
@context (all)
|
||||
*/
|
||||
virtual void WaitFrameStart(ZFrameContext _frameContext) = 0;
|
||||
|
||||
/*
|
||||
virtual public ZRenderer::WaitFrameEnd
|
||||
|
||||
Calling thread waits until after the render thread has finished rendering a frame.
|
||||
|
||||
@param _frameContext - the frame context to wait for
|
||||
@return (void)
|
||||
@context (all)
|
||||
*/
|
||||
virtual void WaitFrameEnd(ZFrameContext _frameContext) = 0;
|
||||
};
|
||||
|
||||
#endif
|
||||
259
Include/ZRenderer/ZRendererBase.hpp
Normal file
259
Include/ZRenderer/ZRendererBase.hpp
Normal file
@@ -0,0 +1,259 @@
|
||||
/*
|
||||
ZRendererBase.hpp
|
||||
Author: James Russell <jcrussell@762studios.com>
|
||||
Created: 3/23/2011
|
||||
|
||||
Purpose:
|
||||
|
||||
Base implementation of the ZRenderer class, which handles many of the details that
|
||||
are common to multi threaded renderers.
|
||||
|
||||
License:
|
||||
|
||||
TODO
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef _ZRENDERERBASE_HPP
|
||||
#define _ZRENDERERBASE_HPP
|
||||
|
||||
#include <ZRenderer/ZRenderer.hpp>
|
||||
#include <ZRenderer/ZDataBufferBase.hpp>
|
||||
|
||||
//Forward Declarations
|
||||
struct ZFrameData;
|
||||
|
||||
//Maximum number of concurrent frame contexts
|
||||
#ifndef ZRB_MAX_FRAME_CONTEXT_COUNT
|
||||
#define ZRB_MAX_FRAME_CONTEXT_COUNT (4)
|
||||
#endif
|
||||
|
||||
//Default slab allocation of Draw Objects, will auto correct at runtime if exceeded
|
||||
#ifndef ZRB_DEFAULT_DRAWDATA_COUNT
|
||||
#define ZRB_DEFAULT_DRAWDATA_COUNT (128)
|
||||
#endif
|
||||
|
||||
//Default buffer size for a draw list
|
||||
#ifndef ZRB_DEFAULT_DRAWDATA_BUFFER_SIZE
|
||||
#define ZRB_DEFAULT_DRAWDATA_BUFFER_SIZE (128)
|
||||
#endif
|
||||
|
||||
/*
|
||||
Used to contain only the minimum data necessary to draw geometry
|
||||
and hold no ownership (in smart pointer terms) over the parameters.
|
||||
*/
|
||||
struct ZDrawData
|
||||
{
|
||||
ZShaderProgram* ShaderProgram; //The shader program we will be drawing with
|
||||
ZShaderParams* ShaderParams; //The shader parameters we will be using
|
||||
ZVertexParams* VertexParams; //The vertex parameters we will be using
|
||||
ZIndexParams* IndexParams; //The index parameters we will be using
|
||||
ZRenderState RenderState; //The renderer state we will be using
|
||||
int DrawGroup; //The draw group for drawing data
|
||||
|
||||
ZFrameData* Parent; //The parent ZFrameData struct that holds ownership
|
||||
|
||||
//Default Constructor
|
||||
ZDrawData()
|
||||
: ShaderProgram(NULL),
|
||||
ShaderParams(NULL), VertexParams(NULL), IndexParams(NULL),
|
||||
RenderState(), DrawGroup(-1),
|
||||
Parent(NULL)
|
||||
{ }
|
||||
};
|
||||
|
||||
/*
|
||||
Used to contain references to the data necessary to draw geometry per frame. Holds
|
||||
strong references long enough to ensure parameters do not get deleted.
|
||||
*/
|
||||
struct ZFrameData
|
||||
{
|
||||
ZArray< ZPtr<ZShaderProgram> > ShaderPrograms; //The shader programs we will be using
|
||||
ZArray< ZPtr<ZShaderParams> > ShaderParams; //The shader parameters we will be using
|
||||
ZArray< ZPtr<ZVertexParams> > VertexParams; //The vertex parameters we will be using
|
||||
ZArray< ZPtr<ZIndexParams> > IndexParams; //The index parameters we will be using
|
||||
|
||||
ZPtr<ZRenderTarget> RenderTarget; //The render target for this frame
|
||||
|
||||
ZArray<ZDrawData*,
|
||||
ZArrayAllocator<ZDrawData*, ZRB_DEFAULT_DRAWDATA_BUFFER_SIZE> > DrawData; //Our set of draw data
|
||||
|
||||
//Concurrency Control Variables
|
||||
ZMutex FrameLock;
|
||||
ZEvent FrameEndSignal;
|
||||
ZEvent FrameStartSignal;
|
||||
};
|
||||
|
||||
/*
|
||||
ZRendererBase class, which can be extended by GL-specific renderers.
|
||||
*/
|
||||
class ZRendererBase : public ZRenderer
|
||||
{
|
||||
private:
|
||||
//The renderer lock
|
||||
ZMutex RendererLock;
|
||||
|
||||
//Current Render Phase
|
||||
volatile ZRenderPhase Phase;
|
||||
|
||||
//Slab allocator for ZFrameData
|
||||
ZSlabAllocator<ZDrawData, ZRB_DEFAULT_DRAWDATA_COUNT> DrawDataAllocator;
|
||||
|
||||
//Slab allocator for ZFrameData
|
||||
ZSlabAllocator<ZFrameData, ZRB_MAX_FRAME_CONTEXT_COUNT> FrameDataAllocator;
|
||||
|
||||
//The frame data available queue (available for use)
|
||||
ZRingBuffer<ZFrameData*,
|
||||
ZRingBuffer_OverflowUnsafe,
|
||||
ZArrayAllocator<ZFrameData*, ZRB_MAX_FRAME_CONTEXT_COUNT> > FrameAvailableQueue;
|
||||
|
||||
//The frame data render queue (pending renders)
|
||||
ZRingBuffer<ZFrameData*,
|
||||
ZRingBuffer_OverflowUnsafe,
|
||||
ZArrayAllocator<ZFrameData*, ZRB_MAX_FRAME_CONTEXT_COUNT> > FrameRenderQueue;
|
||||
|
||||
//The frame data we are rendering
|
||||
ZFrameData* CurrentFrame;
|
||||
|
||||
protected:
|
||||
//Capabilities mapping
|
||||
ZHashMap<ZString, ZString> Capabilities;
|
||||
|
||||
//Protected Constructor
|
||||
ZRendererBase();
|
||||
|
||||
/*
|
||||
virtual protected ZRendererBase::init
|
||||
|
||||
This will be called by ZRendererBase::Init and should handle subclass
|
||||
initialization.
|
||||
|
||||
@return (bool) - true if successful, false otherwise
|
||||
*/
|
||||
virtual bool init() = 0;
|
||||
|
||||
/*
|
||||
virtual protected ZRendererBase::shutdown
|
||||
|
||||
This will be called by ZRendererBase::Shutdown and should handle subclass
|
||||
shutdown.
|
||||
|
||||
@return (void)
|
||||
*/
|
||||
virtual void shutdown() = 0;
|
||||
|
||||
/*
|
||||
virtual protected ZRendererBase::Draw
|
||||
|
||||
Method which should, given a list of render data, draw it to the provided render target.
|
||||
|
||||
@param _renderList - the sorted list of draw data objects to draw
|
||||
@param _renderTarget - the render target to draw to
|
||||
@return (void)
|
||||
*/
|
||||
virtual void Draw(ZArray<ZDrawData*,
|
||||
ZArrayAllocator<ZDrawData*, ZRB_DEFAULT_DRAWDATA_BUFFER_SIZE> >& _renderList,
|
||||
ZRenderTarget* _renderTarget) = 0;
|
||||
|
||||
|
||||
public:
|
||||
/*
|
||||
Destructor.
|
||||
*/
|
||||
virtual ~ZRendererBase();
|
||||
|
||||
//////////////////////////
|
||||
/* Lifecycle Operations */
|
||||
//////////////////////////
|
||||
|
||||
//Subclass Implementation
|
||||
virtual bool Init();
|
||||
|
||||
//Subclass Implementation
|
||||
virtual void Shutdown();
|
||||
|
||||
///////////////////////////
|
||||
/* Renderer Data Getters */
|
||||
///////////////////////////
|
||||
|
||||
//Subclass Override
|
||||
virtual const ZHashMap<ZString, ZString>& GetCapabilities();
|
||||
|
||||
//Subclass Override
|
||||
virtual ZRenderPhase GetRenderPhase();
|
||||
|
||||
//////////////////////////
|
||||
/* Logistics Operations */
|
||||
//////////////////////////
|
||||
|
||||
//Subclass Implementation
|
||||
virtual ZPtr<ZDrawParams> CreateDrawParams(ZDrawParamsType _type);
|
||||
|
||||
//Not Implemented
|
||||
virtual ZPtr<ZDataBuffer> CreateDataBuffer(ZDataBufferType _type,
|
||||
ZDataBufferUsage _usage,
|
||||
size_t _size
|
||||
) = 0;
|
||||
|
||||
//Not Implemented
|
||||
virtual ZPtr<ZFramebufferRenderTarget> CreateFrameBufferRenderTarget(size_t _width, size_t _height) = 0;
|
||||
|
||||
//Not Implemented
|
||||
virtual ZPtr<ZRenderBuffer> CreateRenderBuffer(ZRenderBufferType _type, size_t _width, size_t _height) = 0;
|
||||
|
||||
//Not Implemented
|
||||
virtual ZPtr<ZSampler> CreateSampler() = 0;
|
||||
|
||||
//Not Implemented
|
||||
virtual ZPtr<ZShader> CreateShader(ZShaderType _type) = 0;
|
||||
|
||||
//Not Implemented
|
||||
virtual ZPtr<ZShaderProgram> CreateShaderProgram() = 0;
|
||||
|
||||
//Not Implemented
|
||||
virtual ZPtr<ZTexture> CreateTexture(ZTextureType _type, ZTextureFormat _format, ZTextureUsage _usage, const ZBitmap& _bitmap, bool _generateMipmaps) = 0;
|
||||
|
||||
//Not Implemented
|
||||
virtual ZPtr<ZRenderTarget> CreateWindowRenderTarget(SST_Window _window, size_t _screenIndex) = 0;
|
||||
|
||||
////////////////////////
|
||||
/* Frame Data Getters */
|
||||
////////////////////////
|
||||
|
||||
//Subclass Implementation
|
||||
virtual ZRenderTarget* GetFrameRenderTarget(ZFrameContext _frameContext);
|
||||
|
||||
//////////////////////////
|
||||
/* Rendering Operations */
|
||||
//////////////////////////
|
||||
|
||||
//Subclass Implementation
|
||||
virtual ZFrameContext BeginFrame(ZPtr<ZRenderTarget> _canvas);
|
||||
|
||||
virtual void EndFrame(ZFrameContext _frameContext);
|
||||
|
||||
//Subclass Implementation
|
||||
virtual void SubmitDrawData(ZFrameContext _frameContext,
|
||||
ZPtr<ZShaderProgram> _shaderProgram,
|
||||
ZPtr<ZShaderParams> _shaderParams,
|
||||
ZPtr<ZVertexParams> _vertexParams,
|
||||
ZPtr<ZIndexParams> _indexParams,
|
||||
const ZRenderState& _renderState,
|
||||
int _drawGroup = 0
|
||||
);
|
||||
|
||||
//Subclass Implementation
|
||||
virtual void RenderFrame(ZFrameContext _frameContext);
|
||||
|
||||
//Subclass Implementation
|
||||
virtual void WaitFrameStart(ZFrameContext _frameContext);
|
||||
|
||||
//Subclass Implementation
|
||||
virtual void WaitFrameEnd(ZFrameContext _frameContext);
|
||||
|
||||
//Implementation of the render thread
|
||||
virtual ZThreadReturn run(uint64_t _dt);
|
||||
};
|
||||
|
||||
#endif
|
||||
49
Include/ZRenderer/ZRendererBuild.hpp
Normal file
49
Include/ZRenderer/ZRendererBuild.hpp
Normal file
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
ZRendererBuild.hpp
|
||||
Author: James Russell <jcrussell@762studios.com>
|
||||
Created: 5/21/2012
|
||||
|
||||
Purpose:
|
||||
|
||||
Used to generate definitions for the preprocessor using only compiler-set variables
|
||||
and include headers necessary to ensure previous project build files are included
|
||||
in the correct order.
|
||||
|
||||
License:
|
||||
|
||||
TODO
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef _ZRENDERERBUILD_HPP
|
||||
#define _ZRENDERERBUILD_HPP
|
||||
|
||||
#include "ZBuild.hpp"
|
||||
|
||||
#include <ZUtil/ZUtilBuild.hpp>
|
||||
|
||||
//Version number constants for ZRenderer
|
||||
#define ZRENDERER_VERSION_MAJOR 0x01
|
||||
#define ZRENDERER_VERSION_MINOR 0x00
|
||||
#define ZRENDERER_VERSION_PATCH 0x0000
|
||||
#define ZRENDERER_VERSION (ZRENDERER_VERSION_MAJOR << 24) | (ZRENDERER_VERSION_MINOR << 16) | (ZRENDERER_VERSION_PATCH)
|
||||
|
||||
#define ZRENDERER_VERSION_STRING "1.0.0"
|
||||
|
||||
#if ZASSERT_RENDERER_ENABLE
|
||||
|
||||
//ZASSERT_RENDERER macro, which will trigger a breakpoint if the condition is not met
|
||||
//ZASSERT_RENDERER is meant to be used within the ZRenderer project for internal assertion debugging
|
||||
//ZASSERT should be used when the error condition can be caused by user actions
|
||||
#define ZASSERT_RENDERER(_condition, _message) SST_OS_DebugAssert(_condition, _message)
|
||||
|
||||
#else
|
||||
|
||||
//ZASSERT_RENDERER is disabled
|
||||
#define ZASSERT_RENDERER(_condition, _message) ((void)sizeof(_condition), sizeof(_message))
|
||||
|
||||
#endif //ZASSERT_RENDERER_ENABLE
|
||||
|
||||
#endif
|
||||
|
||||
153
Include/ZRenderer/ZRendererResource.hpp
Normal file
153
Include/ZRenderer/ZRendererResource.hpp
Normal file
@@ -0,0 +1,153 @@
|
||||
/*
|
||||
ZRendererResource.hpp
|
||||
Author: James Russell <jcrussell@762studios.com>
|
||||
Created: 7/8/2012
|
||||
|
||||
Purpose:
|
||||
|
||||
A renderer resource is anything that is created by the renderer and is used as part of
|
||||
the rendering process. Generally, renderer resources are objects that act as an interface
|
||||
to graphics device state, such as buffers, textures, etc.
|
||||
|
||||
It should be noted that resources are not safe to be used across multiple threads, even though
|
||||
the renderer is multi thread capable. A resource should only be used within the context of a
|
||||
single thread, and draw calls using that resource should also remain within the same thread
|
||||
(this is done to avoid costly concurrent operations).
|
||||
|
||||
Different resources are free to be used across different threads.
|
||||
|
||||
Usage:
|
||||
|
||||
A renderer resource can be 'available', 'locked', or 'contended'. When a resource is available,
|
||||
all calls to methods that modify the underlying data (or make the underlying data available for
|
||||
modification) succeed and this will be indicated by the return value. If the resource is locked
|
||||
or contended, the return value of the method will indicate failure to modify the resource.
|
||||
|
||||
If a resource is 'locked', then the resource is currently in the midst of modification. This
|
||||
means that some modification methods will be unavailable. As an example, 'MapBuffer' cannot
|
||||
be called while the buffer is already mapped, and 'FillBuffer' will fail if a buffer has
|
||||
been mapped. A locked resource can be unlocked and returned to 'available' state before
|
||||
rendering.
|
||||
|
||||
If a resource is contended, this means that the renderer is relying on the data that is currently
|
||||
present in graphics memory, as a draw call has been placed using the data at the time of contention.
|
||||
This means that any calls that would allow the user to modify the underlying data will fail. A
|
||||
contended buffer becomes available when the renderer has finished reading the data needed from
|
||||
the resource, which will occur at frame end.
|
||||
|
||||
Note that this means that the following set of actions (using an example of ZDataBuffer):
|
||||
|
||||
buffer = dataBuffer->MapBuffer(true);
|
||||
... //Update Buffer
|
||||
dataBuffer->UnmapBuffer();
|
||||
|
||||
renderer->SubmitDrawData(...); //Draw using this buffer
|
||||
|
||||
buffer = dataBuffer->MapBuffer(true);
|
||||
... //Update Buffer
|
||||
dataBuffer->UnmapBuffer();
|
||||
|
||||
renderer->SubmitDrawData(...); //Draw using the updated buffer
|
||||
|
||||
renderer->RenderFrame(...); //Render this frame
|
||||
|
||||
Will not work. The second call to 'MapBuffer' will fail because the buffer became contended
|
||||
as soon as the buffer was used as an argument to 'SubmitDrawData'. The renderer's 'WaitFameEnd'
|
||||
method will enable you to wait until the resource is no longer contended.
|
||||
|
||||
License:
|
||||
|
||||
TODO
|
||||
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef _ZRENDERERRESOURCE_HPP
|
||||
#define _ZRENDERERRESOURCE_HPP
|
||||
|
||||
#include <ZRenderer/ZRendererBuild.hpp>
|
||||
|
||||
class ZRendererResource
|
||||
{
|
||||
private:
|
||||
DISABLE_COPY_AND_ASSIGN(ZRendererResource);
|
||||
|
||||
protected:
|
||||
//Counter of 'owners' claiming contention
|
||||
int ContentionCount;
|
||||
|
||||
//Flag indicating that this resource has been 'locked'
|
||||
bool bIsLocked;
|
||||
|
||||
public:
|
||||
//Default Constructor
|
||||
ZRendererResource();
|
||||
|
||||
//Virtual Destructor
|
||||
virtual ~ZRendererResource() { }
|
||||
|
||||
/*
|
||||
public ZRendererResource::Available
|
||||
|
||||
Returns whether or not this resource is currently available (able to be modified).
|
||||
If a resource is locked or contended, then it is not available for modification.
|
||||
|
||||
@return (bool) - true if available, false otherwise
|
||||
@context (all)
|
||||
*/
|
||||
bool IsAvailable();
|
||||
|
||||
/*
|
||||
public ZRendererResource::Lock
|
||||
|
||||
Locks this resource, making it unavailable for modification.
|
||||
|
||||
@return (void)
|
||||
@context (all)
|
||||
*/
|
||||
void Lock();
|
||||
|
||||
/*
|
||||
public ZRendererResource::MarkContended
|
||||
|
||||
Marks this resource as contended. Resources should, from this point out,
|
||||
understand that modification of the underlying resource should not happen
|
||||
until after the frame is drawn that would release this resource from
|
||||
contention. From this point out, the caller 'owns' the resource.
|
||||
|
||||
Resources can be marked as contended by multiple sources, and the resource
|
||||
will not be available until all owners who have marked contended have
|
||||
released their claim.
|
||||
|
||||
Generally, this should only be called by the renderer.
|
||||
|
||||
@return (void)
|
||||
@context (renderer)
|
||||
*/
|
||||
void MarkContended();
|
||||
|
||||
/*
|
||||
public ZRendererResource::ReleaseContended
|
||||
|
||||
Removes a previous claim of contention. If all previous owners have
|
||||
released their contention, then the resource is available.
|
||||
|
||||
@return (void)
|
||||
@context (all)
|
||||
*/
|
||||
void ReleaseContention();
|
||||
|
||||
/*
|
||||
public ZRendererResource::Unlock
|
||||
|
||||
Unlocks a resource, making it available for modification.
|
||||
|
||||
@return (void)
|
||||
@context (all)
|
||||
*/
|
||||
void Unlock();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
192
Include/ZRenderer/ZSampler.hpp
Normal file
192
Include/ZRenderer/ZSampler.hpp
Normal file
@@ -0,0 +1,192 @@
|
||||
/*
|
||||
ZSampler.hpp
|
||||
Author: James Russell <jcrussell@762studios.com>
|
||||
Created: 7/1/2012
|
||||
|
||||
Purpose:
|
||||
|
||||
Samplers act as a view onto a texture object, encapsulating all the filtering, mipmapping,
|
||||
and addressing settings for shaders to access a texture.
|
||||
|
||||
TODO - A writeup here on the various settings and how they interact, or at least a link to
|
||||
some place that does
|
||||
|
||||
License:
|
||||
|
||||
TODO
|
||||
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef _ZSAMPLER_HPP
|
||||
#define _ZSAMPLER_HPP
|
||||
|
||||
#include <ZRenderer/ZRendererBuild.hpp>
|
||||
#include <ZRenderer/ZRendererResource.hpp>
|
||||
|
||||
//This should be ~log2 of ZT_MAX_TEXTURE_DIMENSION
|
||||
#ifndef ZS_DEFAULT_MAX_LOD
|
||||
#define ZS_DEFAULT_MAX_LOD (13.0f)
|
||||
#endif
|
||||
|
||||
//Enumeration of sampler wrapping modes
|
||||
enum ZSamplerWrapMode
|
||||
{
|
||||
ZSWM_CLAMP_EDGE, //Sampling beyond the edge results in the last pixel value
|
||||
ZSWM_CLAMP_BORDER, //Sampling beyond the edge results in the specified border value
|
||||
ZSWM_MIRROR_REPEAT, //Sampling beyond the edge wraps back in on itself
|
||||
ZSWM_REPEAT, //Sampling beyond the edge wraps around to the other side
|
||||
ZSWM_SIZE
|
||||
};
|
||||
|
||||
//Enumeration of magnification sampler filtering modes
|
||||
enum ZSamplerMagFilter
|
||||
{
|
||||
ZSMAGF_NEAREST, //Nearest mode filter
|
||||
ZSMAGF_LINEAR, //Linear mode filter
|
||||
ZSMAGF_SIZE
|
||||
};
|
||||
|
||||
//Enumeration of minification sampler filtering modes
|
||||
enum ZSamplerMinFilter
|
||||
{
|
||||
ZSMINF_NEAREST, //Nearest-neighbor pixel, no mip levels
|
||||
ZSMINF_NEAREST_MIP_NEAREST, //Nearest-neighbor sampling on nearest mip level
|
||||
ZSMINF_NEAREST_MIP_LINEAR, //Nearest-neighbor sampling on lerped mip level
|
||||
ZSMINF_LINEAR, //Linear interpolation, no mip levels
|
||||
ZSMINF_LINEAR_MIP_NEAREST, //Lerped sampling on nearest mip level
|
||||
ZSMINF_LINEAR_MIP_LINEAR, //Lerped sampling on lerped mip level
|
||||
ZSMINF_SIZE
|
||||
};
|
||||
|
||||
//Enumeration of sampler comparison modes
|
||||
enum ZSamplerCompareMode
|
||||
{
|
||||
ZSCM_COMPARE_REF_TO_TEXTURE, //Compares reference to texture
|
||||
ZSCM_NONE, //No comparison
|
||||
ZSCM_SIZE
|
||||
};
|
||||
|
||||
//Enumeration of sampler comparison functions
|
||||
enum ZSamplerCompareFunc
|
||||
{
|
||||
ZSCF_LESS_EQUAL, //Less than or equal
|
||||
ZSCF_GREATER_EQUAL, //Greater than or equal
|
||||
ZSCF_LESS, //Less than
|
||||
ZSCF_GREATER, //Greater than
|
||||
ZSCF_EQUAL, //Equal
|
||||
ZSCF_NOT_EQUAL, //Not Equal
|
||||
ZSCF_ALWAYS, //Always
|
||||
ZSCF_NEVER, //Never
|
||||
ZSCF_SIZE
|
||||
};
|
||||
|
||||
//Struct that encapsulates the sampler state
|
||||
struct ZSamplerState
|
||||
{
|
||||
ZSamplerWrapMode SWrapMode; //Wrapping mode for S
|
||||
ZSamplerWrapMode TWrapMode; //Wrapping mode for T (unused for 1D)
|
||||
ZSamplerWrapMode RWrapMode; //Wrapping mode for R (unused for 1D, 2D)
|
||||
|
||||
ZSamplerMinFilter MinFilter; //Minification Filter
|
||||
ZSamplerMagFilter MagFilter; //Magnification Filter
|
||||
|
||||
float MaxAnisotropy; //Maximum Anisotropy (< 2.0 has no effect)
|
||||
float MinLOD; //Minimum LOD
|
||||
float MaxLOD; //Maximum LOD
|
||||
float LODBias; //LOD Bias
|
||||
|
||||
float BorderColor[4]; //RGBA Border Color
|
||||
|
||||
ZSamplerCompareMode CompareMode; //Sampler Comparison Mode
|
||||
ZSamplerCompareFunc CompareFunc; //Sampler Comparison Function
|
||||
|
||||
//Default Configuration
|
||||
ZSamplerState()
|
||||
: SWrapMode(ZSWM_REPEAT), TWrapMode(ZSWM_REPEAT), RWrapMode(ZSWM_REPEAT),
|
||||
MinFilter(ZSMINF_LINEAR), MagFilter(ZSMAGF_LINEAR),
|
||||
MaxAnisotropy(1.0), MinLOD(0), MaxLOD(ZS_DEFAULT_MAX_LOD), LODBias(0),
|
||||
CompareMode(ZSCM_NONE), CompareFunc(ZSCF_ALWAYS)
|
||||
{ }
|
||||
};
|
||||
|
||||
/*
|
||||
Sampler interface class.
|
||||
*/
|
||||
class ZSampler : public ZRendererResource
|
||||
{
|
||||
public:
|
||||
//Virtual Destructor
|
||||
virtual ~ZSampler() { }
|
||||
|
||||
/*
|
||||
ZSampler::Get*
|
||||
|
||||
The following methods are getters for the various ZSampler settings
|
||||
that can be set on a given sampler. For a greater explanation of each
|
||||
setting and what it does, see above.
|
||||
*/
|
||||
|
||||
//Getters for the S, T, and R Wrap Mode set on this sampler
|
||||
virtual ZSamplerWrapMode GetSWrapMode() = 0;
|
||||
virtual ZSamplerWrapMode GetTWrapMode() = 0;
|
||||
virtual ZSamplerWrapMode GetRWrapMode() = 0;
|
||||
|
||||
//Getters for the minification filter and magnification filter
|
||||
virtual ZSamplerMagFilter GetMagFilter() = 0;
|
||||
virtual ZSamplerMinFilter GetMinFilter() = 0;
|
||||
|
||||
//Getters for the maximum anisotropy, minimum LOD, maximum LOD, and LOD bias
|
||||
virtual float GetMaxAnisotropy() = 0;
|
||||
virtual float GetMinLOD() = 0;
|
||||
virtual float GetMaxLOD() = 0;
|
||||
virtual float GetLODBias() = 0;
|
||||
|
||||
//Getter for the border color setting (four-element array, RGBA)
|
||||
virtual const float* GetBorderColor() = 0;
|
||||
|
||||
//Getter for the comparison mode and comparison function
|
||||
virtual ZSamplerCompareMode GetCompareMode() = 0;
|
||||
virtual ZSamplerCompareFunc GetCompareFunc() = 0;
|
||||
|
||||
//Getter for the entire sampler state
|
||||
virtual const ZSamplerState& GetSamplerState() = 0;
|
||||
|
||||
/*
|
||||
ZSampler::Set*
|
||||
|
||||
The following methods are setters for the various ZSampler settings than
|
||||
can be set on a given sampler. For a greater explanation of each setting and what it
|
||||
does, see above.
|
||||
|
||||
If any of the setters returns false, it is because the resource is contended.
|
||||
*/
|
||||
|
||||
//Setters for the S, T, and R wrapping modes
|
||||
virtual bool SetSWrapMode(ZSamplerWrapMode _mode) = 0;
|
||||
virtual bool SetTWrapMode(ZSamplerWrapMode _mode) = 0;
|
||||
virtual bool SetRWrapMode(ZSamplerWrapMode _mode) = 0;
|
||||
|
||||
//Setters for the minification and magnification filter
|
||||
virtual bool SetMagFilter(ZSamplerMagFilter _filter) = 0;
|
||||
virtual bool SetMinFilter(ZSamplerMinFilter _filter) = 0;
|
||||
|
||||
//Setters for maximum anisotropy, minimum LOD, maximum LOD, and LOD bias
|
||||
virtual bool SetMaxAnisotropy(float _max) = 0;
|
||||
virtual bool SetMinLOD(float _min) = 0;
|
||||
virtual bool SetMaxLOD(float _max) = 0;
|
||||
virtual bool SetLODBias(float _bias) = 0;
|
||||
|
||||
//Setter for border color
|
||||
virtual bool SetBorderColor(float _r, float _g, float _b, float _a) = 0;
|
||||
|
||||
//Setter for comparison mode and comparison function
|
||||
virtual bool SetCompareMode(ZSamplerCompareMode _mode) = 0;
|
||||
virtual bool SetCompareFunc(ZSamplerCompareFunc _func) = 0;
|
||||
|
||||
//Setter for entire sampler state
|
||||
virtual bool SetSamplerState(const ZSamplerState& _state) = 0;
|
||||
};
|
||||
|
||||
#endif
|
||||
98
Include/ZRenderer/ZSamplerBase.hpp
Normal file
98
Include/ZRenderer/ZSamplerBase.hpp
Normal file
@@ -0,0 +1,98 @@
|
||||
/*
|
||||
ZSamplerBase.hpp
|
||||
Author: James Russell <jcrussell@762studios.com>
|
||||
Created: 7/1/2012
|
||||
|
||||
Purpose:
|
||||
|
||||
TODO
|
||||
|
||||
License:
|
||||
|
||||
TODO
|
||||
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef _ZSAMPLERBASE_HPP
|
||||
#define _ZSAMPLERBASE_HPP
|
||||
|
||||
#include <ZRenderer/ZSampler.hpp>
|
||||
|
||||
//Base implementation of ZSampler Interface
|
||||
class ZSamplerBase : public ZSampler
|
||||
{
|
||||
private:
|
||||
DISABLE_COPY_AND_ASSIGN(ZSamplerBase);
|
||||
|
||||
protected:
|
||||
//Current sampler state
|
||||
ZSamplerState State;
|
||||
|
||||
//Flag indicating values have changed
|
||||
bool bIsDirty;
|
||||
|
||||
//Default Constructor, which initializes with some sane default settings
|
||||
ZSamplerBase();
|
||||
|
||||
public:
|
||||
//Virtual Destructor
|
||||
virtual ~ZSamplerBase() { }
|
||||
|
||||
/*
|
||||
public ZSamplerBase::GetSamplerStateResetDirty
|
||||
|
||||
Gets the sampler state for this device. This will return
|
||||
NULL if the sampler has not been modified since the last call to
|
||||
this function, and in the case it has been modified, a call to this
|
||||
resets the 'dirty' flag for the buffer.
|
||||
|
||||
@return (ZSamplerState*)
|
||||
@context (all)
|
||||
*/
|
||||
ZSamplerState* GetSamplerStateResetDirty();
|
||||
|
||||
//Subclass Getter Implementations
|
||||
virtual ZSamplerWrapMode GetSWrapMode();
|
||||
virtual ZSamplerWrapMode GetTWrapMode();
|
||||
virtual ZSamplerWrapMode GetRWrapMode();
|
||||
|
||||
virtual ZSamplerMinFilter GetMinFilter();
|
||||
virtual ZSamplerMagFilter GetMagFilter();
|
||||
|
||||
virtual float GetMaxAnisotropy();
|
||||
virtual float GetMinLOD();
|
||||
virtual float GetMaxLOD();
|
||||
virtual float GetLODBias();
|
||||
|
||||
virtual const float* GetBorderColor();
|
||||
|
||||
virtual ZSamplerCompareMode GetCompareMode();
|
||||
virtual ZSamplerCompareFunc GetCompareFunc();
|
||||
|
||||
virtual const ZSamplerState& GetSamplerState();
|
||||
|
||||
//Subclass Setter Implementations
|
||||
virtual bool SetSWrapMode( ZSamplerWrapMode _mode );
|
||||
virtual bool SetTWrapMode( ZSamplerWrapMode _mode );
|
||||
virtual bool SetRWrapMode( ZSamplerWrapMode _mode );
|
||||
|
||||
virtual bool SetMinFilter( ZSamplerMinFilter _filter );
|
||||
virtual bool SetMagFilter( ZSamplerMagFilter _filter );
|
||||
|
||||
virtual bool SetMaxAnisotropy( float _max );
|
||||
virtual bool SetMinLOD( float _min );
|
||||
virtual bool SetMaxLOD( float _max );
|
||||
virtual bool SetLODBias( float _bias );
|
||||
|
||||
virtual bool SetBorderColor( float _r, float _g, float _b, float _a );
|
||||
|
||||
virtual bool SetCompareMode(ZSamplerCompareMode _mode);
|
||||
virtual bool SetCompareFunc(ZSamplerCompareFunc _func);
|
||||
|
||||
virtual bool SetSamplerState(const ZSamplerState& _state);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
122
Include/ZRenderer/ZShader.hpp
Normal file
122
Include/ZRenderer/ZShader.hpp
Normal file
@@ -0,0 +1,122 @@
|
||||
/*
|
||||
ZShader.hpp
|
||||
Author: Chris Ertel <crertel@762studios.com>,
|
||||
James Russell <jcrussell@762studios.com>
|
||||
Created: 4/20/2011
|
||||
|
||||
Purpose:
|
||||
|
||||
TODO
|
||||
|
||||
License:
|
||||
|
||||
TODO
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef _ZSHADER_HPP
|
||||
#define _ZSHADER_HPP
|
||||
|
||||
#include <ZRenderer/ZRendererBuild.hpp>
|
||||
#include <ZRenderer/ZRendererResource.hpp>
|
||||
|
||||
#include <ZSTL/ZString.hpp>
|
||||
|
||||
//Shader Type
|
||||
enum ZShaderType
|
||||
{
|
||||
ZST_SOFT, //Software Shader (unsupported)
|
||||
ZST_VERTEX, //Vertex Shader
|
||||
ZST_FRAGMENT, //Fragment/Pixel Shader
|
||||
ZST_GEOMETRY, //Geometry Shader (unsupported)
|
||||
ZST_HULL, //Hull Shader (unsupported)
|
||||
ZST_DOMAIN, //Domain Shader (unsupported)
|
||||
ZST_SIZE
|
||||
};
|
||||
|
||||
//For you non OpenGL types
|
||||
#define ZST_PIXEL (ZST_FRAGMENT)
|
||||
|
||||
class ZShader : public ZRendererResource
|
||||
{
|
||||
public:
|
||||
/*
|
||||
virtual public ZShader::ClearLog
|
||||
|
||||
Function to clear the log of a shader.
|
||||
|
||||
@return (void)
|
||||
@context (all)
|
||||
*/
|
||||
virtual void ClearCompileLog() = 0;
|
||||
|
||||
/*
|
||||
virtual public ZShdaer::Compile
|
||||
|
||||
Function to compile a shader.
|
||||
|
||||
@return (bool) - true if successfully compiled, false otherwise.
|
||||
@context (all)
|
||||
*/
|
||||
virtual bool Compile() = 0;
|
||||
|
||||
/*
|
||||
virtual public ZShdaer::IsUsable
|
||||
|
||||
Function to compile a shader.
|
||||
|
||||
@return (bool) - true if successfully compiled, false otherwise.
|
||||
@context (all)
|
||||
*/
|
||||
virtual bool IsUsable() = 0;
|
||||
|
||||
/*
|
||||
virtual public ZShader::GetLog
|
||||
|
||||
Function to get the log of a shader.
|
||||
|
||||
@return (ZString) - the log of the shader.
|
||||
@context (all)
|
||||
*/
|
||||
virtual const ZString& GetCompileLog() = 0;
|
||||
|
||||
/*
|
||||
virtual public ZShader::GetSource
|
||||
|
||||
Function to get the source of a shader.
|
||||
|
||||
@return (ZString) - the source of the shader.
|
||||
@context (all)
|
||||
*/
|
||||
virtual const ZString& GetSource() = 0;
|
||||
|
||||
/*
|
||||
virtual public ZShader::GetType
|
||||
|
||||
Function to get the type of a shader.
|
||||
|
||||
ZST_SOFT : Soft shaders
|
||||
ZST_VERTEX : Vertex shaders
|
||||
ZST_HULL : Hull shaders
|
||||
ZST_DOMAIN : Domain shaders
|
||||
ZST_GEOMETRY: Geometry shaders
|
||||
ZST_FRAGMENT: Fragment (pixel) shaders
|
||||
|
||||
@return (ZShaderType) - type of shader.
|
||||
@context (all)
|
||||
*/
|
||||
virtual ZShaderType GetType() = 0;
|
||||
|
||||
/*
|
||||
virtual public ZShader::SetSource
|
||||
|
||||
Function to set the source of a shader.
|
||||
|
||||
@param _source - shader source, as a string
|
||||
@return (void)
|
||||
@context (all)
|
||||
*/
|
||||
virtual void SetSource(const ZString& _source) = 0;
|
||||
};
|
||||
#endif
|
||||
74
Include/ZRenderer/ZShaderBase.hpp
Normal file
74
Include/ZRenderer/ZShaderBase.hpp
Normal file
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
ZShaderBase.hpp
|
||||
Author: Chris Ertel <crertel@762studios.com>,
|
||||
James Russell <jcrussell@762studios.com>
|
||||
Created: 4/20/2011
|
||||
|
||||
Purpose:
|
||||
|
||||
Base implementation of the ZShader interface.
|
||||
|
||||
License:
|
||||
|
||||
TODO
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef _ZSHADERBASE_HPP
|
||||
#define _ZSHADERBASE_HPP
|
||||
|
||||
#include <ZRenderer/ZShader.hpp>
|
||||
|
||||
/*
|
||||
Shader base class implementation.
|
||||
*/
|
||||
class ZShaderBase : public ZShader
|
||||
{
|
||||
protected:
|
||||
//The type of shader
|
||||
ZShaderType Type;
|
||||
|
||||
//The shader source
|
||||
ZString Source;
|
||||
|
||||
//The shader compilation log
|
||||
ZString Log;
|
||||
|
||||
//Boolean set to true indicates this is a usable shader
|
||||
bool bIsUsable;
|
||||
|
||||
public:
|
||||
/*
|
||||
Constructor.
|
||||
|
||||
@param _type - the type of shader this is
|
||||
*/
|
||||
ZShaderBase(ZShaderType _type);
|
||||
|
||||
//Virtual Destructor
|
||||
virtual ~ZShaderBase();
|
||||
|
||||
//Subclass Implementation
|
||||
virtual void ClearCompileLog();
|
||||
|
||||
//Subclass Implementation
|
||||
virtual const ZString& GetCompileLog();
|
||||
|
||||
//Subclass Implementation
|
||||
virtual const ZString& GetSource();
|
||||
|
||||
//Subclass Implementation
|
||||
virtual ZShaderType GetType();
|
||||
|
||||
//Subclass Implementation
|
||||
virtual bool IsUsable();
|
||||
|
||||
//Subclass Implementation
|
||||
virtual void SetSource( const ZString& _source );
|
||||
|
||||
//Not Implemented
|
||||
virtual bool Compile() = 0;
|
||||
};
|
||||
|
||||
#endif
|
||||
147
Include/ZRenderer/ZShaderParams.hpp
Normal file
147
Include/ZRenderer/ZShaderParams.hpp
Normal file
@@ -0,0 +1,147 @@
|
||||
/*
|
||||
ZShaderParams.hpp
|
||||
Author: James Russell <jcrussell@762studios.com>
|
||||
Created: 7/1/2012
|
||||
|
||||
Purpose:
|
||||
|
||||
Shader parameters class, to which uniform buffers and samplers are bound
|
||||
and passed to draw calls. The attached buffers and samplers will be used
|
||||
to provide data to the shader.
|
||||
|
||||
License:
|
||||
|
||||
TODO
|
||||
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef _ZSHADERPARAMS_HPP
|
||||
#define _ZSHADERPARAMS_HPP
|
||||
|
||||
#include <ZRenderer/ZDrawParams.hpp>
|
||||
|
||||
#include <ZSTL/ZSTL.hpp>
|
||||
|
||||
#include <ZUtil/ZUtil.hpp>
|
||||
|
||||
#include <ZRenderer/ZDataBuffer.hpp>
|
||||
#include <ZRenderer/ZTexture.hpp>
|
||||
#include <ZRenderer/ZSampler.hpp>
|
||||
|
||||
#ifndef ZSP_MAX_UNIFORM_BLOCKS
|
||||
#define ZSP_MAX_UNIFORM_BLOCKS (128)
|
||||
#endif
|
||||
|
||||
#ifndef ZSP_MAX_SAMPLERS
|
||||
#define ZSP_MAX_SAMPLERS (32)
|
||||
#endif
|
||||
|
||||
//Shader Parameters Structure, used to hold shader parameters
|
||||
class ZShaderParams : public ZDrawParams
|
||||
{
|
||||
private:
|
||||
DISABLE_COPY_AND_ASSIGN(ZShaderParams);
|
||||
|
||||
protected:
|
||||
//A uniform block binding
|
||||
struct UniformBlockBinding
|
||||
{
|
||||
ZName Name; //Name of the uniform block binding
|
||||
ZPtr<ZDataBuffer> Buffer; //Parent buffer
|
||||
|
||||
ZPair<ZDataBuffer*, const ZDataBufferBlock*> Binding; //Pair Binding
|
||||
};
|
||||
|
||||
//A sampler binding
|
||||
struct SamplerBinding
|
||||
{
|
||||
ZName Name; //Name of the sampler binding
|
||||
ZPtr<ZSampler> Sampler; //Sampler
|
||||
ZPtr<ZTexture> Texture; //Texture
|
||||
|
||||
ZPair<ZSampler*, ZTexture*> Binding; //Pair binding
|
||||
};
|
||||
|
||||
//These are the buffer bindings and samplers that are provided to the shader program
|
||||
UniformBlockBinding UniformBlockBindings[ZSP_MAX_UNIFORM_BLOCKS];
|
||||
SamplerBinding SamplerBindings[ZSP_MAX_SAMPLERS];
|
||||
|
||||
//Our current uniform block count and sampler count
|
||||
size_t UniformBlockBindingCount;
|
||||
size_t SamplerBindingCount;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
/*
|
||||
Default Constructor.
|
||||
*/
|
||||
ZShaderParams();
|
||||
|
||||
virtual ~ZShaderParams() { }
|
||||
|
||||
/*
|
||||
public ZShaderParams::ClearUniformBufferBlocks
|
||||
|
||||
Clears the current set of uniform buffer blocks.
|
||||
|
||||
@return (void)
|
||||
@context (all)
|
||||
*/
|
||||
void ClearUniformBufferBlocks();
|
||||
|
||||
/*
|
||||
public ZShaderParams::ClearSamplers
|
||||
|
||||
Clears the current set of sampler bindings.
|
||||
|
||||
@return (void)
|
||||
@context (all)
|
||||
*/
|
||||
void ClearSamplers();
|
||||
|
||||
/*
|
||||
public ZShaderParams::SetUniformBufferBlock
|
||||
|
||||
Sets the value of a uniform buffer block for a shader. Set to NULL using overload
|
||||
to remove binding.
|
||||
|
||||
@param _name - the name of the uniform block in the shader
|
||||
@param _buffer - the buffer containing the values
|
||||
@param _block - the block definition for the buffer block
|
||||
@return (void)
|
||||
@context (all)
|
||||
*/
|
||||
void SetUniformBufferBlock(const ZName& _name, ZPtr<ZDataBuffer> _buffer, const ZDataBufferBlock* _block);
|
||||
|
||||
/*
|
||||
public ZShaderParams::SetSampler
|
||||
|
||||
Sets the value of a sampler for a shader.
|
||||
|
||||
@param _name - the name of the sampler in the shader
|
||||
@param _sampler - the sampler object to use
|
||||
@param _texture - the texture the sampler object is a view onto
|
||||
@return (void)
|
||||
@context (all)
|
||||
*/
|
||||
void SetSampler(const ZName& _name, ZPtr<ZSampler> _sampler, ZPtr<ZTexture> _texture);
|
||||
|
||||
/*
|
||||
The following methods are used by the renderer to get the values needed when
|
||||
binding shader parameter values to pass to the shader program, to mark
|
||||
all bound resources as contended, and release contention.
|
||||
*/
|
||||
const ZPair<ZDataBuffer*, const ZDataBufferBlock*>* GetUniformBlockByName(const ZName& _name);
|
||||
const ZPair<ZSampler*, ZTexture*>* GetSamplerByName(const ZName& _name);
|
||||
|
||||
//Subclass Override
|
||||
virtual void MarkResourcesContended();
|
||||
|
||||
//Subclass Override
|
||||
virtual void ReleaseResourceContention();
|
||||
};
|
||||
|
||||
#endif
|
||||
315
Include/ZRenderer/ZShaderProgram.hpp
Normal file
315
Include/ZRenderer/ZShaderProgram.hpp
Normal file
@@ -0,0 +1,315 @@
|
||||
/*
|
||||
ZShaderProgram.hpp
|
||||
Author: Chris Ertel <crertel@762studios.com>,
|
||||
James Russell <jcrussell@762studios.com>
|
||||
Created: 04/03/2011
|
||||
|
||||
Purpose:
|
||||
|
||||
TODO
|
||||
|
||||
License:
|
||||
|
||||
TODO
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef _ZSHADERPROGRAM_HPP
|
||||
#define _ZSHADERPROGRAM_HPP
|
||||
|
||||
#include <ZRenderer/ZRendererBuild.hpp>
|
||||
#include <ZRenderer/ZRendererResource.hpp>
|
||||
#include <ZRenderer/ZShader.hpp>
|
||||
#include <ZRenderer/ZSampler.hpp>
|
||||
|
||||
#include <ZSTL/ZString.hpp>
|
||||
|
||||
#include <ZUtil/ZUtil.hpp>
|
||||
|
||||
//Enumeration for shader stream attribute types
|
||||
enum ZShaderStreamAttributeType
|
||||
{
|
||||
// VECTOR TYPE
|
||||
ZSSAT_VECTOR_MIN,
|
||||
|
||||
// Single-precision float
|
||||
ZSSAT_FLOAT,
|
||||
ZSSAT_FLOAT_VEC2,
|
||||
ZSSAT_FLOAT_VEC3,
|
||||
ZSSAT_FLOAT_VEC4,
|
||||
|
||||
ZSSAT_VECTOR_MAX,
|
||||
|
||||
// MATRIX TYPE
|
||||
ZSSAT_MATRIX_MIN,
|
||||
|
||||
// Single-precision float matrix
|
||||
ZSSAT_MAT_22,
|
||||
ZSSAT_MAT_23,
|
||||
ZSSAT_MAT_24,
|
||||
ZSSAT_MAT_32,
|
||||
ZSSAT_MAT_33,
|
||||
ZSSAT_MAT_34,
|
||||
ZSSAT_MAT_42,
|
||||
ZSSAT_MAT_43,
|
||||
ZSSAT_MAT_44,
|
||||
|
||||
ZSSAT_MATRIX_MAX,
|
||||
|
||||
ZSSAT_SIZE,
|
||||
ZSSAT_UNKNOWN
|
||||
};
|
||||
|
||||
//Enumeration for types of shader uniform block member types
|
||||
enum ZShaderUniformBlockMemberType
|
||||
{
|
||||
//VECTOR TYPE
|
||||
ZSUBMT_VECTOR_MIN,
|
||||
|
||||
//Signed integer
|
||||
ZSUBMT_INT,
|
||||
ZSUBMT_INT_VEC2,
|
||||
ZSUBMT_INT_VEC3,
|
||||
ZSUBMT_INT_VEC4,
|
||||
|
||||
//Unsigned integer
|
||||
ZSUBMT_UINT,
|
||||
ZSUBMT_UINT_VEC2,
|
||||
ZSUBMT_UINT_VEC3,
|
||||
ZSUBMT_UINT_VEC4,
|
||||
|
||||
//Single-precision float
|
||||
ZSUBMT_FLOAT,
|
||||
ZSUBMT_FLOAT_VEC2,
|
||||
ZSUBMT_FLOAT_VEC3,
|
||||
ZSUBMT_FLOAT_VEC4,
|
||||
|
||||
//Half-precision float
|
||||
ZSUBMT_HALF,
|
||||
ZSUBMT_HALF_VEC2,
|
||||
ZSUBMT_HALF_VEC3,
|
||||
ZSUBMT_HALF_VEC4,
|
||||
|
||||
//Boolean
|
||||
ZSUBMT_BOOL,
|
||||
ZSUBMT_BOOL_VEC2,
|
||||
ZSUBMT_BOOL_VEC3,
|
||||
ZSUBMT_BOOL_VEC4,
|
||||
|
||||
ZSUBMT_VECTOR_MAX,
|
||||
|
||||
//MATRIX
|
||||
ZSUBMT_MATRIX_MIN,
|
||||
|
||||
//Single-precision float matrix
|
||||
ZSUBMT_MAT_22,
|
||||
ZSUBMT_MAT_23,
|
||||
ZSUBMT_MAT_24,
|
||||
ZSUBMT_MAT_32,
|
||||
ZSUBMT_MAT_33,
|
||||
ZSUBMT_MAT_34,
|
||||
ZSUBMT_MAT_42,
|
||||
ZSUBMT_MAT_43,
|
||||
ZSUBMT_MAT_44,
|
||||
|
||||
ZSUBMT_MATRIX_MAX,
|
||||
|
||||
ZSUBMT_SIZE
|
||||
};
|
||||
|
||||
//Enumeration of sampler types
|
||||
enum ZShaderSamplerType
|
||||
{
|
||||
ZSST_SAMPLER_1D, //1D texture map
|
||||
ZSST_SAMPLER_2D, //2D texture map
|
||||
ZSST_SAMPLER_3D, //3D texture map
|
||||
ZSST_SAMPLER_CUBE, //Cubic texture map (unsupported)
|
||||
ZSST_SAMPLER_1D_SHADOW, //1D shadow map (unsupported)
|
||||
ZSST_SAMPLER_2D_SHADOW, //2D shadow map (unsupported)
|
||||
ZSST_SIZE
|
||||
};
|
||||
|
||||
//Struct defining a shader stream attribute
|
||||
struct ZShaderStreamAttribute
|
||||
{
|
||||
ZName Name; //The name of the attribute
|
||||
size_t Size; //The size of the attribute in terms of elements (arrays have Size > 1)
|
||||
size_t Index; //Index of this attribute in the attributes array
|
||||
|
||||
ZShaderStreamAttributeType Type; //The type of the attribute
|
||||
};
|
||||
|
||||
//Struct defining a uniform block member
|
||||
struct ZShaderUniformBlockMember
|
||||
{
|
||||
ZName Name; //Name of the member
|
||||
size_t Offset; //Offset (within the block) to the member
|
||||
size_t Size; //Size of the member in terms of elements (arrays have Size > 1)
|
||||
size_t Index; //Index of this member in the member array
|
||||
|
||||
size_t ArrayStride; //Stride between elements in an array (0 if not array)
|
||||
|
||||
size_t MatrixStride; //Stride between columns (or rows) of a matrix type (0 if not matrix type)
|
||||
enum { ROW_MAJOR, COLUMN_MAJOR } MatrixOrder; //Order of a matrix type (row or column)
|
||||
|
||||
ZShaderUniformBlockMemberType Type; //Type of the member
|
||||
};
|
||||
|
||||
//Struct defining a uniform block layout
|
||||
struct ZShaderUniformBlock
|
||||
{
|
||||
ZName Name; //Name of the block
|
||||
size_t Size; //Size of the block (in bytes)
|
||||
size_t Index; //Index of this block in the blocks array
|
||||
|
||||
ZArray<ZShaderUniformBlockMember> Members; //Members contained in the block
|
||||
|
||||
/*
|
||||
public ZShaderUniformBlock::GetMemberByName
|
||||
|
||||
This lookup method is used to get a pointer to a member by name, or NULL if not found.
|
||||
Bear in mind that the name is qualified by the block name.
|
||||
|
||||
@param _name - the qualified name of the parameter
|
||||
@return (const ZShaderUniformBlockMember*) - pointer to member if found, NULL if not found
|
||||
*/
|
||||
inline const ZShaderUniformBlockMember* GetMemberByName(const ZName& _name) const
|
||||
{
|
||||
for (size_t i = 0; i < Members.Size(); i++) {
|
||||
if (Members.Data()[i].Name == _name) {
|
||||
return &Members.Data()[i];
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
};
|
||||
|
||||
//Struct defining a shader sampler
|
||||
struct ZShaderSampler
|
||||
{
|
||||
ZName Name; //Name of the sampler
|
||||
size_t Index; //Index of this sampler in the samplers array
|
||||
|
||||
ZShaderSamplerType Type; //Type of the sampler
|
||||
};
|
||||
|
||||
/*
|
||||
Interface for a shader program.
|
||||
*/
|
||||
class ZShaderProgram : public ZRendererResource
|
||||
{
|
||||
public:
|
||||
//Virtual Destructor
|
||||
virtual ~ZShaderProgram() { }
|
||||
|
||||
/*
|
||||
virtual public ZShaderProgram::AttachShader
|
||||
|
||||
Function to attach a shader. This will compile the shader.
|
||||
|
||||
@param _shader - The shader to attach to this shader program.
|
||||
@return (bool) - true if able to compile and attach the shader
|
||||
@context (all)
|
||||
*/
|
||||
virtual bool AttachShader(ZPtr<ZShader> _shader) = 0;
|
||||
|
||||
/*
|
||||
virtual public ZShaderProgram::ClearLog
|
||||
|
||||
Function to clear the log of a shader program.
|
||||
|
||||
@return (void)
|
||||
@context (all)
|
||||
*/
|
||||
virtual void ClearLog() = 0;
|
||||
|
||||
/*
|
||||
virtual public ZShaderProgram::DetachShaders
|
||||
|
||||
Function to get the remove all attached shaders.
|
||||
|
||||
@return (void)
|
||||
@context (all)
|
||||
*/
|
||||
virtual void DetachShaders() = 0;
|
||||
|
||||
/*
|
||||
virtual public ZShaderProgram::GetLinkLog
|
||||
|
||||
Function to get the link log of a shader program.
|
||||
|
||||
@return (ZString) The log of the shader.
|
||||
@context (all)
|
||||
*/
|
||||
virtual const ZString& GetLinkLog() = 0;
|
||||
|
||||
/*
|
||||
virtual public ZShaderProgram::GetShaders
|
||||
|
||||
Function to get the an array of the currently attached shaders.
|
||||
|
||||
@return (ZArray< ZPtr<ZShader> >)
|
||||
@context (all)
|
||||
*/
|
||||
virtual const ZArray< ZPtr<ZShader> >& GetShaders() = 0;
|
||||
|
||||
/*
|
||||
virtual public ZShaderProgram::GetStreamAttributes
|
||||
|
||||
Function to get the stream shader attributes declarations for a linked shader program.
|
||||
|
||||
This returns an empty array until after linking.
|
||||
|
||||
@return (const ZArray<ZShaderStreamAttribute>&) List of shader attributes.
|
||||
@context (all)
|
||||
*/
|
||||
virtual const ZArray<ZShaderStreamAttribute>& GetStreamDeclarations() = 0;
|
||||
|
||||
/*
|
||||
virtual public ZShaderProgram::GetUniformBlockDeclarations
|
||||
|
||||
Function to get the shader uniform block declarations for a linked shader program.
|
||||
|
||||
This returns an empty array until after linking.
|
||||
|
||||
@return (const ZArray<ZShaderUniformBlock>&)
|
||||
@context (all)
|
||||
*/
|
||||
virtual const ZArray<ZShaderUniformBlock>& GetUniformBlockDeclarations() = 0;
|
||||
|
||||
/*
|
||||
virtual public ZShaderProgram::GetShaderSamplerDeclarations
|
||||
|
||||
Function to get teh shader sampler declarations for a linked shader program.
|
||||
|
||||
This returns an empty array until after linking.
|
||||
|
||||
@return (const ZArray<ZShaderSampler>&)
|
||||
@context (all)
|
||||
*/
|
||||
virtual const ZArray<ZShaderSampler>& GetShaderSamplerDeclarations() = 0;
|
||||
|
||||
/*
|
||||
virtual public ZShaderProgram::Link
|
||||
|
||||
Function to link the attached shaders into a usable shader program object.
|
||||
|
||||
@return (bool) True if successfully linked, false otherwise.
|
||||
@context (all)
|
||||
*/
|
||||
virtual bool Link() = 0;
|
||||
|
||||
/*
|
||||
virtual public ZShaderProgram::IsUsable
|
||||
|
||||
Function to see if shader program is usable.
|
||||
|
||||
@return (bool) True if shader program is usable, false otherwise.
|
||||
@context (all)
|
||||
*/
|
||||
virtual bool IsUsable() = 0;
|
||||
};
|
||||
|
||||
#endif
|
||||
85
Include/ZRenderer/ZShaderProgramBase.hpp
Normal file
85
Include/ZRenderer/ZShaderProgramBase.hpp
Normal file
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
ZShaderProgramBase.hpp
|
||||
Author: Chris Ertel <crertel@762studios.com>,
|
||||
James Russell <jcrussell@762studios.com>
|
||||
Created: 04/03/2011
|
||||
|
||||
Purpose:
|
||||
|
||||
ZShaderProgramBase handles the simple logistics for shader programs (e.g., log access, check usability). It
|
||||
is intended to be extended by subclasses to handle implementation-specific issues.
|
||||
|
||||
License:
|
||||
|
||||
TODO
|
||||
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef _ZSHADERPROGRAMBASE_HPP
|
||||
#define _ZSHADERPROGRAMBASE_HPP
|
||||
|
||||
#include <ZRenderer/ZShaderProgram.hpp>
|
||||
|
||||
#include <ZUtil/ZUtil.hpp>
|
||||
|
||||
class ZShaderProgramBase : public ZShaderProgram
|
||||
{
|
||||
protected:
|
||||
//Default Constructor
|
||||
ZShaderProgramBase();
|
||||
|
||||
//Our attached shaders (currently only support vertex and fragment)
|
||||
ZPtr<ZShader> VertexShader;
|
||||
ZPtr<ZShader> FragmentShader;
|
||||
|
||||
ZArray< ZPtr<ZShader> > Shaders;
|
||||
|
||||
//Our cached set of uniform blocks, samplers, and vertex streams
|
||||
ZArray<ZShaderUniformBlock> UniformBlocks;
|
||||
ZArray<ZShaderSampler> Samplers;
|
||||
ZArray<ZShaderStreamAttribute> Streams;
|
||||
|
||||
//Link log for shader program
|
||||
ZString Log;
|
||||
|
||||
//Flag for shader in usable state
|
||||
bool bIsUsable;
|
||||
|
||||
public:
|
||||
//Virtual destructor
|
||||
virtual ~ZShaderProgramBase();
|
||||
|
||||
//Subclass Implementation
|
||||
virtual bool AttachShader(ZPtr<ZShader> _shader);
|
||||
|
||||
//Subclass Implementation
|
||||
virtual void ClearLog();
|
||||
|
||||
//Subclass Implementation
|
||||
virtual void DetachShaders();
|
||||
|
||||
//Subclass Implementation
|
||||
virtual const ZString& GetLinkLog();
|
||||
|
||||
//Subclass Implementation
|
||||
virtual const ZArray<ZShaderStreamAttribute>& GetStreamDeclarations();
|
||||
|
||||
//Subclass Implementation
|
||||
virtual const ZArray<ZShaderUniformBlock>& GetUniformBlockDeclarations();
|
||||
|
||||
//Subclass Implementation
|
||||
virtual const ZArray<ZShaderSampler>& GetShaderSamplerDeclarations();
|
||||
|
||||
//Subclass Implementation
|
||||
virtual const ZArray< ZPtr<ZShader> >& GetShaders();
|
||||
|
||||
//Subclass Implementation
|
||||
virtual bool IsUsable();
|
||||
|
||||
//Not Implemented
|
||||
virtual bool Link() = 0;
|
||||
};
|
||||
|
||||
#endif
|
||||
162
Include/ZRenderer/ZTexture.hpp
Normal file
162
Include/ZRenderer/ZTexture.hpp
Normal file
@@ -0,0 +1,162 @@
|
||||
/*
|
||||
ZTexture.hpp
|
||||
Author: James Russell <jcrussell@762studios.com>
|
||||
Created: 04/06/2011
|
||||
|
||||
Purpose:
|
||||
|
||||
Texture interface for the ZEngine. Texture instances are loaded and created by the
|
||||
renderer, which acts as a factory for the correct type of texture.
|
||||
|
||||
License:
|
||||
|
||||
TODO
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef _ZTEXTURE_HPP
|
||||
#define _ZTEXTURE_HPP
|
||||
|
||||
#include <ZRenderer/ZRendererBuild.hpp>
|
||||
#include <ZRenderer/ZRendererResource.hpp>
|
||||
|
||||
#include <ZUtil/ZUtil.hpp>
|
||||
#include <ZUtil/ZBitmap.hpp>
|
||||
|
||||
//Our maximum size for a texture
|
||||
#ifndef ZT_MAX_TEXTURE_DIMENSION
|
||||
#define ZT_MAX_TEXTURE_DIMENSION (8096)
|
||||
#endif
|
||||
|
||||
/*
|
||||
Enumeration of texture types. Not all are currently supported.
|
||||
*/
|
||||
enum ZTextureType
|
||||
{
|
||||
ZTT_TEXTURE1D, //1D texture map
|
||||
ZTT_TEXTURE2D, //2D texture map
|
||||
ZTT_TEXTURE3D, //3D texture map (unsupported)
|
||||
ZTT_TEXTURE_CUBE, //Cubic texture map (unsupported)
|
||||
ZTT_SIZE
|
||||
};
|
||||
|
||||
/*
|
||||
Enumeration of internal storage format for texture types.
|
||||
*/
|
||||
enum ZTextureFormat
|
||||
{
|
||||
ZTF_R8, //8-bit Unsigned Red (Normalized)
|
||||
ZTF_R8_SNORM, //8-bit Signed Red (Normalized)
|
||||
ZTF_R8I, //8-bit Signed Red
|
||||
ZTF_R8UI, //8-bit Unsigned Red
|
||||
ZTF_R16, //16-bit Unsigned Red (Normalized)
|
||||
ZTF_R16_SNORM, //16-bit Signed Red (Normalized)
|
||||
ZTF_R16I, //16-bit Signed Red
|
||||
ZTF_R16UI, //16-bit Unsigned Red
|
||||
ZTF_R16F, //16-bit Floating Point Red
|
||||
ZTF_R32I, //32-bit Signed Red
|
||||
ZTF_R32UI, //32-bit Unsigned Red
|
||||
ZTF_R32F, //32-bit Floating Point Red
|
||||
|
||||
ZTF_RG8, //8-bit Unsigned Red, Green (Normalized)
|
||||
ZTF_RG8_SNORM, //8-bit Signed Red, Green (Normalized)
|
||||
ZTF_RG8I, //8-bit Signed Red, Green
|
||||
ZTF_RG8UI, //8-bit Unsigned Red, Green
|
||||
ZTF_RG16, //16-bit Unsigned Red, Green (Normalized)
|
||||
ZTF_RG16_SNORM, //16-bit Signed Red, Green (Normalized)
|
||||
ZTF_RG16I, //16-bit Signed Red, Green
|
||||
ZTF_RG16UI, //16-bit Unsigned Red, Green
|
||||
ZTF_RG16F, //16-bit Floating Point Red, Green
|
||||
ZTF_RG32, //32-bit Unsigned Red, Green (Normalized)
|
||||
ZTF_RG32_SNORM, //32-bit Signed Red, Green (Normalized)
|
||||
ZTF_RG32I, //32-bit Signed Red, Green
|
||||
ZTF_RG32UI, //32-bit Unsigned Red, Green
|
||||
ZTF_RG32F, //32-bit Floating Point Red, Green
|
||||
|
||||
ZTF_RGB8, //8-bit Unsigned Red, Green, Blue (Normalized)
|
||||
ZTF_RGB8_SNORM, //8-bit Signed Red, Green, Blue (Normalized)
|
||||
ZTF_RGB8I, //8-bit Signed Red, Green, Blue
|
||||
ZTF_RGB8UI, //8-bit Unsigned Red, Green, Blue
|
||||
ZTF_RGB16, //16-bit Unsigned Red, Green, Blue (Normalized)
|
||||
ZTF_RGB16_SNORM, //16-bit Signed Red, Green, Blue (Normalized)
|
||||
ZTF_RGB16I, //16-bit Signed Red, Green, Blue
|
||||
ZTF_RGB16UI, //16-bit Unsigned Red, Green, Blue
|
||||
ZTF_RGB16F, //16-bit Floating Point Red, Green, Blue
|
||||
ZTF_RGB32, //32-bit Unsigned Red, Green, Blue (Normalized)
|
||||
ZTF_RGB32_SNORM, //32-bit Signed Red, Green, Blue (Normalized)
|
||||
ZTF_RGB32I, //32-bit Signed Red, Green, Blue
|
||||
ZTF_RGB32UI, //32-bit Unsigned Red, Green, Blue
|
||||
ZTF_RGB32F, //32-bit Floating Point Red, Green, Blue
|
||||
|
||||
ZTF_RGBA8, //8-bit Unsigned Red, Green, Blue, Alpha (Normalized)
|
||||
ZTF_RGBA8_SNORM, //8-bit Signed Red, Green, Blue, Alpha (Normalized)
|
||||
ZTF_RGBA8I, //8-bit Signed Red, Green, Blue, Alpha
|
||||
ZTF_RGBA8UI, //8-bit Unsigned Red, Green, Blue, Alpha
|
||||
ZTF_RGBA16, //16-bit Unsigned Red, Green, Blue, Alpha (Normalized)
|
||||
ZTF_RGBA16_SNORM, //16-bit Signed Red, Green, Blue, Alpha (Normalized)
|
||||
ZTF_RGBA16I, //16-bit Signed Red, Green, Blue, Alpha
|
||||
ZTF_RGBA16UI, //16-bit Unsigned Red, Green, Blue, Alpha
|
||||
ZTF_RGBA16F, //16-bit Floating Point Red, Green, Blue, Alpha
|
||||
ZTF_RGBA32, //32-bit Unsigned Red, Green, Blue, Alpha (Normalized)
|
||||
ZTF_RGBA32_SNORM, //32-bit Signed Red, Green, Blue, Alpha (Normalized)
|
||||
ZTF_RGBA32I, //32-bit Signed Red, Green, Blue, Alpha
|
||||
ZTF_RGBA32UI, //32-bit Unsigned Red, Green, Blue, Alpha
|
||||
ZTF_RGBA32F, //32-bit Floating Point Red, Green, Blue, Alpha
|
||||
|
||||
ZTF_DEPTH16, //16-bit Depth Texture
|
||||
ZTF_DEPTH24, //24-bit Depth Texture
|
||||
ZTF_DEPTH32, //32-bit Depth Texture
|
||||
ZTF_DEPTH24_STENCIL8, //32-bit Depth, 8-bit Stencil
|
||||
|
||||
ZTF_SIZE
|
||||
};
|
||||
|
||||
/*
|
||||
Enumeration of texture usage types.
|
||||
*/
|
||||
enum ZTextureUsage
|
||||
{
|
||||
ZTU_STATIC, //Static Texture (never or rarely updated)
|
||||
ZTU_DYNAMIC, //Dynamic Texture (updated frequently)
|
||||
ZTU_STREAMING, //Streaming Texture (updated every frame)
|
||||
ZTU_SIZE
|
||||
};
|
||||
|
||||
class ZTexture : public ZRendererResource
|
||||
{
|
||||
public:
|
||||
//Virtual Destructor
|
||||
virtual ~ZTexture() { }
|
||||
|
||||
/*
|
||||
virtual public ZTexture::GetType
|
||||
|
||||
Gets the type of this texture.
|
||||
|
||||
@return (ZTextureType) - the type of texture
|
||||
*/
|
||||
virtual ZTextureType GetType() = 0;
|
||||
|
||||
/*
|
||||
virtual public ZTexture::GetUsage
|
||||
|
||||
Gets the usage type of this texture.
|
||||
|
||||
@return (ZTextureUsage)
|
||||
@context (all)
|
||||
*/
|
||||
virtual ZTextureUsage GetUsage() = 0;
|
||||
|
||||
/*
|
||||
public ZTexture::IsMipmapped
|
||||
|
||||
Tells you whether or not this texture has been mipmapped.
|
||||
|
||||
@return (bool) - true if mipmapped, false otherwise
|
||||
@context (all)
|
||||
*/
|
||||
virtual bool IsMipmapped() = 0;
|
||||
};
|
||||
|
||||
#endif
|
||||
106
Include/ZRenderer/ZVertexParams.hpp
Normal file
106
Include/ZRenderer/ZVertexParams.hpp
Normal file
@@ -0,0 +1,106 @@
|
||||
/*
|
||||
ZVertexParams.hpp
|
||||
Author: James Russell <jcrussell@762studios.com>
|
||||
Created: 7/1/2012
|
||||
|
||||
Purpose:
|
||||
|
||||
TODO
|
||||
|
||||
License:
|
||||
|
||||
TODO
|
||||
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef _ZVERTEXPARAMS_HPP
|
||||
#define _ZVERTEXPARAMS_HPP
|
||||
|
||||
#include <ZRenderer/ZDrawParams.hpp>
|
||||
|
||||
#include <ZSTL/ZSTL.hpp>
|
||||
|
||||
#include <ZUtil/ZUtil.hpp>
|
||||
|
||||
#include <ZRenderer/ZDataBuffer.hpp>
|
||||
|
||||
#ifndef ZVP_MAX_STREAMS
|
||||
#define ZVP_MAX_STREAMS (128)
|
||||
#endif
|
||||
|
||||
class ZVertexParams : public ZDrawParams
|
||||
{
|
||||
private:
|
||||
//A binding for a vertex stream
|
||||
struct VertexStreamBinding
|
||||
{
|
||||
ZName Name; //Name of the stream attribute
|
||||
ZPair<ZDataBuffer*, const ZDataBufferStream*> Binding; //Pair Binding
|
||||
};
|
||||
|
||||
//This is the bound vertex buffer and streams
|
||||
ZPtr<ZDataBuffer> VertexBuffer;
|
||||
VertexStreamBinding VertexStreams[ZVP_MAX_STREAMS];
|
||||
|
||||
//Our current set number of streams
|
||||
size_t CurrentStreamCount;
|
||||
|
||||
protected:
|
||||
//Does this vertex parameter object need to be updated before rendered with?
|
||||
bool Dirty;
|
||||
|
||||
public:
|
||||
/*
|
||||
Default Constructor.
|
||||
*/
|
||||
ZVertexParams();
|
||||
|
||||
/*
|
||||
public ZVertexParams::ClearStreams
|
||||
|
||||
Clears the list of currently set streams.
|
||||
|
||||
@return (void)
|
||||
@context (all)
|
||||
*/
|
||||
void ClearVertexStreams();
|
||||
|
||||
/*
|
||||
public ZVertexParams::SetStream
|
||||
|
||||
Sets a vertex buffer stream. The vertex buffer provided to each call
|
||||
of 'SetVertexStream' must be the same.
|
||||
|
||||
@param _name - the name of the stream binding
|
||||
@param _vertexBuffer - the vertex buffer to bind streams from
|
||||
@param _stream - the stream definition
|
||||
@return (void)
|
||||
@context (all)
|
||||
*/
|
||||
void SetVertexStream(const ZName& _name, ZPtr<ZDataBuffer> _vertexBuffer, const ZDataBufferStream* _stream);
|
||||
|
||||
/*
|
||||
The following methods are used by the renderer to get the values needed when
|
||||
binding shader parameter values to pass to the shader program, to mark
|
||||
all bound resources as contended, and release contention.
|
||||
*/
|
||||
const ZPair<ZDataBuffer*, const ZDataBufferStream*>* GetStreamByName(const ZName& _name);
|
||||
|
||||
|
||||
ZDataBuffer* GetVertexBuffer();
|
||||
|
||||
bool IsDirty() const { return Dirty; }
|
||||
|
||||
size_t GetStreamCount() const { return CurrentStreamCount; }
|
||||
|
||||
//Subclass Override
|
||||
virtual void MarkResourcesContended();
|
||||
|
||||
//Subclass Override
|
||||
virtual void ReleaseResourceContention();
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
106
Include/ZRenderer/ZWindowRenderTarget.hpp
Normal file
106
Include/ZRenderer/ZWindowRenderTarget.hpp
Normal file
@@ -0,0 +1,106 @@
|
||||
/*
|
||||
ZWindowRenderTarget.hpp
|
||||
Author: James Russell <jcrussell@762studios.com>
|
||||
Created: 04/01/2011
|
||||
|
||||
Purpose:
|
||||
|
||||
Interface class for a window render target. This interface requires that windows
|
||||
be created and manipulated using libsst-wm.
|
||||
|
||||
License:
|
||||
|
||||
TODO
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef _ZWINDOWRENDERTARGET_HPP
|
||||
#define _ZWINDOWRENDERTARGET_HPP
|
||||
|
||||
#include <ZRenderer/ZRendererBuild.hpp>
|
||||
|
||||
#include <SST/SST_WM.h>
|
||||
|
||||
#include <ZUtil/ZUtil.hpp>
|
||||
|
||||
#include <ZRenderer/ZRenderTarget.hpp>
|
||||
|
||||
class ZWindowRenderTarget : public ZRenderTarget
|
||||
{
|
||||
public:
|
||||
//Virtual destructor
|
||||
virtual ~ZWindowRenderTarget() { }
|
||||
|
||||
/*
|
||||
virtual public ZWindowRenderTarget::GetAutoSwapBuffers
|
||||
|
||||
Gets the flag indicating whether or not this target will auto-swap buffers by the
|
||||
renderer when used as a render target.
|
||||
|
||||
@return (bool)
|
||||
@context (all)
|
||||
*/
|
||||
virtual bool GetAutoSwapBuffers() = 0;
|
||||
|
||||
/*
|
||||
virtual public ZWindowRenderTarget::GetScreenIndex
|
||||
|
||||
Gets the screen index held by this window render target. Used to interface with libsst-wm
|
||||
functionality.
|
||||
|
||||
@return (size_t) - the screen index
|
||||
@context (all)
|
||||
*/
|
||||
virtual size_t GetScreenIndex() = 0;
|
||||
|
||||
/*
|
||||
virtual public ZWindowRenderTarget::GetWindowHandle
|
||||
|
||||
Gets the window handle held by this window render target. Used to interface with
|
||||
libsst-wm functionality.
|
||||
|
||||
@return (SST_Window) - the window handle
|
||||
*/
|
||||
virtual SST_Window GetWindowHandle() = 0;
|
||||
|
||||
/*
|
||||
virtual public ZWindowRenderTarget::SetAutoSwapBuffers
|
||||
|
||||
Indicates that the renderer should automatically swap buffers after a render is
|
||||
complete with this render target.
|
||||
|
||||
@param _value - true if we can, false if not
|
||||
@return (bool) - true if able to set flag, false if resource contended
|
||||
@context (all)
|
||||
*/
|
||||
virtual bool SetAutoSwapBuffers(bool _value) = 0;
|
||||
|
||||
/*
|
||||
virtual public ZWindowRenderTarget::SwapBuffers
|
||||
|
||||
Swaps the buffers on the screen, bringing the back buffer to the front buffer. This should be called
|
||||
every frame, and signals the end of the frame. This is only safe to call from within the render thread.
|
||||
|
||||
@return (bool) - true if able to swapbuffers, false if resource contended
|
||||
@context (renderer)
|
||||
*/
|
||||
virtual bool SwapBuffers() = 0;
|
||||
|
||||
//Not Implemented
|
||||
virtual const ZRenderTargetClearFlags& GetClearFlags() = 0;
|
||||
|
||||
//Not Implemented
|
||||
virtual size_t GetHeight() = 0;
|
||||
|
||||
//Not Implemented
|
||||
virtual ZRenderTargetType GetType() = 0;
|
||||
|
||||
//Not Implemented
|
||||
virtual size_t GetWidth() = 0;
|
||||
|
||||
//Not Implemented
|
||||
virtual bool SetClearFlags(const ZRenderTargetClearFlags& _flags) = 0;
|
||||
};
|
||||
|
||||
#endif
|
||||
88
Include/ZRenderer/ZWindowRenderTargetBase.hpp
Normal file
88
Include/ZRenderer/ZWindowRenderTargetBase.hpp
Normal file
@@ -0,0 +1,88 @@
|
||||
/*
|
||||
ZWindowRenderTargetBase.hpp
|
||||
Author: James Russell <jcrussell@762studios.com>
|
||||
Created: 04/03/2011
|
||||
|
||||
Purpose:
|
||||
|
||||
Base class for a window render target.
|
||||
|
||||
License:
|
||||
|
||||
TODO
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef _ZWINDOWRENDERTARGETBASE_HPP
|
||||
#define _ZWINDOWRENDERTARGETBASE_HPP
|
||||
|
||||
#include <ZRenderer/ZWindowRenderTarget.hpp>
|
||||
|
||||
class ZWindowRenderTargetBase : public ZWindowRenderTarget
|
||||
{
|
||||
protected:
|
||||
//The Window Handle
|
||||
SST_Window WindowHandle;
|
||||
|
||||
//The Screen Index
|
||||
size_t ScreenIndex;
|
||||
|
||||
//Our current clear flags
|
||||
ZRenderTargetClearFlags ClearFlags;
|
||||
|
||||
//Whether or not we should auto-swap buffers
|
||||
bool bAutoSwapBuffers;
|
||||
|
||||
/*
|
||||
Parameterized Constructor.
|
||||
|
||||
@param _window - the libsst-wm window handle to this render target
|
||||
@param _screenIndex - the libsst-wm index of this screen
|
||||
*/
|
||||
ZWindowRenderTargetBase(SST_Window _window, size_t _screenIndex);
|
||||
|
||||
public:
|
||||
//Virtual Destructor
|
||||
virtual ~ZWindowRenderTargetBase() { }
|
||||
|
||||
/*************************/
|
||||
/* ZRenderTarget Methods */
|
||||
/*************************/
|
||||
|
||||
//Subclass Implementation
|
||||
virtual const ZRenderTargetClearFlags& GetClearFlags();
|
||||
|
||||
//Subclass Implementation
|
||||
virtual size_t GetHeight();
|
||||
|
||||
//Subclass Implementation
|
||||
virtual ZRenderTargetType GetType();
|
||||
|
||||
//Subclass Implementation
|
||||
virtual size_t GetWidth();
|
||||
|
||||
//Subclass Implementation
|
||||
virtual bool SetClearFlags(const ZRenderTargetClearFlags& _flags);
|
||||
|
||||
/***********************************/
|
||||
/* ZWindowRenderTargetBase Methods */
|
||||
/***********************************/
|
||||
|
||||
//Subclass Implementation
|
||||
virtual bool GetAutoSwapBuffers();
|
||||
|
||||
//Subclass Implementation
|
||||
virtual size_t GetScreenIndex();
|
||||
|
||||
//Subclass Implementation
|
||||
virtual SST_Window GetWindowHandle();
|
||||
|
||||
//Subclass Implementation
|
||||
virtual bool SetAutoSwapBuffers(bool _value);
|
||||
|
||||
//Not Implemented
|
||||
virtual bool SwapBuffers() = 0;
|
||||
};
|
||||
|
||||
#endif
|
||||
164
Include/ZRendererUtil/ZFontRenderer.hpp
Normal file
164
Include/ZRendererUtil/ZFontRenderer.hpp
Normal file
@@ -0,0 +1,164 @@
|
||||
/*
|
||||
ZFontRenderer.h
|
||||
Author: Patrick Baggett <ptbaggett@762studios.com>
|
||||
|
||||
Purpose: TODO
|
||||
|
||||
Changelog
|
||||
2011/09/18 - creation (ptbaggett)
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef _ZFONTRENDERER_HPP
|
||||
#define _ZFONTRENDERER_HPP
|
||||
|
||||
#include <SST/SST_Mat44.h>
|
||||
|
||||
#include <ZRenderer/ZRenderer.hpp>
|
||||
|
||||
//Font Face
|
||||
typedef void* ZFontFace;
|
||||
|
||||
//ZFontBounds struct, used as such
|
||||
// top --- right
|
||||
// | |
|
||||
// left --- bottom
|
||||
struct ZFontBounds
|
||||
{
|
||||
//ZFontBounds of a rectangle (lower-left orientation)
|
||||
int left, bottom, right, top;
|
||||
};
|
||||
|
||||
class ZFontRenderer
|
||||
{
|
||||
protected:
|
||||
//Protected Constructor
|
||||
ZFontRenderer() { }
|
||||
|
||||
public:
|
||||
//Virtual Destructor
|
||||
virtual ~ZFontRenderer() { }
|
||||
|
||||
/*
|
||||
virtual public ZFontRenderer::createFontFace
|
||||
|
||||
Creates a font face from a memory image of a font file.
|
||||
|
||||
@param _pixelSize - The pixel size of a character. To use point size (ala MS Word), use (point size / 72.0) * DPI.
|
||||
@param _fontData - The font file's data
|
||||
@param _dataSize - The size in bytes of the file data.
|
||||
@return (ZFontFace)
|
||||
@context (all)
|
||||
*/
|
||||
virtual ZFontFace CreateFontFace(int _pixelSize, const void* _fontData, unsigned int _dataSize) = 0;
|
||||
|
||||
/*
|
||||
virtual public ZFontRenderer::deleteFontFace
|
||||
|
||||
Deletes a font face. If this face is the currently active face, then the active face is set to NULL.
|
||||
|
||||
@param face - The font face to delete.
|
||||
@return (void)
|
||||
@context (all)
|
||||
*/
|
||||
virtual void DeleteFontFace(ZFontFace face) = 0;
|
||||
|
||||
/*
|
||||
virtual public ZFontRenderer::beginText
|
||||
|
||||
Sets up render state to begin drawing text. The only legal functions to call between beginText(),
|
||||
and endText() are renderText(), computeBounds(), and setColor().
|
||||
|
||||
@param _ctx - The ZFrameContext for this frame
|
||||
@param _xform - The transformation
|
||||
@return (void)
|
||||
@context (all)
|
||||
*/
|
||||
virtual void BeginText(ZFrameContext _ctx, const SST_Mat44f& _xform) = 0;
|
||||
|
||||
/*
|
||||
virtual public ZFontRenderer::endText
|
||||
|
||||
Restores render state when done drawing text, flushes any buffered text.
|
||||
|
||||
@return (void)
|
||||
@context (all)
|
||||
*/
|
||||
virtual void EndText() = 0;
|
||||
|
||||
/*
|
||||
virtual public ZFontRenderer::renderText
|
||||
|
||||
Renders text at the given XY location
|
||||
|
||||
@param x - The left edge of the text
|
||||
@param y - The bottom edge of the text
|
||||
@param text - Some letters render below this line (e.g. the letter g's "tail").
|
||||
@return (void)
|
||||
@context (all)
|
||||
*/
|
||||
virtual void RenderText(int x, int y, const char* text) = 0;
|
||||
|
||||
/*
|
||||
virtual public ZFontRenderer::computeBounds
|
||||
|
||||
Computes the bounding box for text, as if it was placed at the origin.
|
||||
|
||||
@param text - The text to compute a bounding box for.
|
||||
@param bounds - Pointer to where the computed boundaries are stored.
|
||||
@return (void)
|
||||
@context (all)
|
||||
*/
|
||||
virtual void ComputeBounds(const char* text, ZFontBounds* bounds) = 0;
|
||||
|
||||
/*
|
||||
virtual public ZFontRenderer::setColor
|
||||
|
||||
Sets the color of the text. Requires that there is a current font face, set with setFontFace().
|
||||
|
||||
@param r - The red component in the range of [0,1]
|
||||
@param g - The green component in the range of [0,1]
|
||||
@param b - The blue component in the range of [0,1]
|
||||
@param a - The alpha (transparency) component in the range of [0,1]
|
||||
@return (void)
|
||||
@context (all)
|
||||
*/
|
||||
virtual void SetColor(float r, float g, float b, float a) = 0;
|
||||
|
||||
/*
|
||||
virtual public ZFontRenderer::setColor
|
||||
|
||||
Sets a color with a packed 32-bit integer, converting to 4x32-bit floats first. Due to
|
||||
endian-ness differences, don't typecast an char[4] to int* and then dereference it!
|
||||
|
||||
@param rgba - The RGBA color stored as (hex) 0xRRGGBBAA
|
||||
@return (void)
|
||||
@context (all)
|
||||
*/
|
||||
virtual void SetColor(unsigned int rgba) = 0;
|
||||
|
||||
/*
|
||||
public ZFontRenderer::setFontFace
|
||||
|
||||
Sets the current font face.
|
||||
|
||||
@param face - The face to make current
|
||||
@return (void)
|
||||
@context (all)
|
||||
*/
|
||||
virtual void SetFontFace(ZFontFace face) = 0;
|
||||
|
||||
/*
|
||||
public ZFontRenderer::getFontFace
|
||||
|
||||
Gets the current font face.
|
||||
|
||||
@return (ZFontFace) - Handle to the current font face. It is not reference counted.
|
||||
@context (all)
|
||||
*/
|
||||
virtual ZFontFace GetFontFace() = 0;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
67
Include/ZRendererUtil/ZFontRendererBase.hpp
Normal file
67
Include/ZRendererUtil/ZFontRendererBase.hpp
Normal file
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
ZFontRendererBase.h
|
||||
Author: James Russell <jcrussell@762studios.com>
|
||||
|
||||
Purpose: TODO
|
||||
|
||||
Changelog
|
||||
2011/09/18 - creation (jcrussell)
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef _ZFONTRENDERERBASE_HPP
|
||||
#define _ZFONTRENDERERBASE_HPP
|
||||
|
||||
#include <ZRendererUtil/ZFontRenderer.hpp>
|
||||
|
||||
class ZFontRendererBase : public ZFontRenderer
|
||||
{
|
||||
protected:
|
||||
//Our current font face
|
||||
ZFontFace currentFace;
|
||||
|
||||
public:
|
||||
/*
|
||||
Default Constructor.
|
||||
*/
|
||||
ZFontRendererBase();
|
||||
|
||||
/*
|
||||
Destructor.
|
||||
*/
|
||||
virtual ~ZFontRendererBase();
|
||||
|
||||
//Subclass Implementation
|
||||
virtual ZFontFace GetFontFace();
|
||||
|
||||
//Subclass Implementation
|
||||
virtual void SetColor(unsigned int rgba);
|
||||
|
||||
//Subclass Implementation
|
||||
virtual void SetFontFace(ZFontFace face);
|
||||
|
||||
//Not Implemented
|
||||
virtual ZFontFace CreateFontFace( int PixelSize, const void* fontData, unsigned int dataSize ) = 0;
|
||||
|
||||
//Not Implemented
|
||||
virtual void DeleteFontFace( ZFontFace face ) = 0;
|
||||
|
||||
//Not Implemented
|
||||
virtual void BeginText( ZFrameContext _ctx, const SST_Mat44f& _xform ) = 0;
|
||||
|
||||
//Not Implemented
|
||||
virtual void EndText() = 0;
|
||||
|
||||
//Not Implemented
|
||||
virtual void RenderText( int x, int y, const char* text ) = 0;
|
||||
|
||||
//Not Implemented
|
||||
virtual void ComputeBounds( const char* text, ZFontBounds* bounds ) = 0;
|
||||
|
||||
//Not Implemented
|
||||
virtual void SetColor( float r, float g, float b, float a ) = 0;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
126
Include/ZRendererUtil/ZOutlineEvaluator.hpp
Normal file
126
Include/ZRendererUtil/ZOutlineEvaluator.hpp
Normal file
@@ -0,0 +1,126 @@
|
||||
/*
|
||||
ZOutlineEvaluator.h
|
||||
Author: Patrick Baggett <ptbaggett@762studios.com>
|
||||
|
||||
Purpose: TODO
|
||||
|
||||
Changelog
|
||||
2011/09/18 - creation (ptbaggett)
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef _ZOUTLINEEVALUATOR_H
|
||||
#define _ZOUTLINEEVALUATOR_H
|
||||
|
||||
#include <ZUtil/ZUtil.hpp>
|
||||
#include <SST/SST_Vec2.h>
|
||||
|
||||
#include <vector>
|
||||
#include <ft2build.h>
|
||||
#include FT_FREETYPE_H
|
||||
|
||||
class ZOutlineEvaluator
|
||||
{
|
||||
private:
|
||||
FT_Outline* outline;
|
||||
int detail;
|
||||
int curContour;
|
||||
int* bounds;
|
||||
std::vector<SST_Vec2f> pts;
|
||||
|
||||
//Process a curve
|
||||
int processCurve(int contour, int curveStart);
|
||||
|
||||
//Evaluate a line segment
|
||||
void evalLinear(FT_Vector* p0, FT_Vector* p1);
|
||||
|
||||
//Evaluate a quadric path (called conic)
|
||||
void evalQuadratic(FT_Vector* p0, FT_Vector* p1, FT_Vector* p2);
|
||||
|
||||
//Evaluate a cubic path
|
||||
void evalCubic(FT_Vector* p0, FT_Vector* p1, FT_Vector* p2, FT_Vector* p3);
|
||||
|
||||
//Adds a point
|
||||
void addPoint(const FT_Vector* pt);
|
||||
|
||||
public:
|
||||
/*
|
||||
Constructor.
|
||||
|
||||
@param _outline -
|
||||
@param _detail -
|
||||
*/
|
||||
ZOutlineEvaluator(FT_Outline* _outline, int _detail);
|
||||
|
||||
/*
|
||||
Destructor.
|
||||
*/
|
||||
~ZOutlineEvaluator();
|
||||
|
||||
/*
|
||||
public ZOutlineEvaluator::evaluate
|
||||
|
||||
TODO
|
||||
|
||||
@return (void)
|
||||
@context (all)
|
||||
*/
|
||||
void evaluate();
|
||||
|
||||
/*
|
||||
public ZOutlineEvaluator::getContourCount
|
||||
|
||||
TODO
|
||||
|
||||
@return (int)
|
||||
@context (all)
|
||||
*/
|
||||
int getContourCount() const;
|
||||
|
||||
/*
|
||||
public ZOutlineEvaluator::getContourStart
|
||||
|
||||
TODO
|
||||
|
||||
@param contour -
|
||||
@return (int)
|
||||
@context (all)
|
||||
*/
|
||||
int getContourStart(int contour) const;
|
||||
|
||||
/*
|
||||
public ZOutlineEvaluator::getContourEnd
|
||||
|
||||
TODO
|
||||
|
||||
@param contour -
|
||||
@return (int)
|
||||
@context (all)
|
||||
*/
|
||||
int getContourEnd(int contour) const;
|
||||
|
||||
/*
|
||||
public ZOutlineEvaluator::getPoint
|
||||
|
||||
TODO
|
||||
|
||||
@param pt -
|
||||
@return (const SST_Vec2f*)
|
||||
@context (all)
|
||||
*/
|
||||
const SST_Vec2f* getPoint(int pt) const;
|
||||
|
||||
/*
|
||||
public ZOutlineEvaluator::printContourPoints
|
||||
|
||||
TODO
|
||||
|
||||
@param contour -
|
||||
@return (void)
|
||||
@context (all)
|
||||
*/
|
||||
void printContourPoints(int contour);
|
||||
};
|
||||
|
||||
#endif
|
||||
140
Include/ZRendererUtil/ZParticleEffect.h
Normal file
140
Include/ZRendererUtil/ZParticleEffect.h
Normal file
@@ -0,0 +1,140 @@
|
||||
/*
|
||||
ZParticleEffect.h
|
||||
Author: James Russell <jcrussell@762studios.com>
|
||||
|
||||
Purpose: A particle effect class which maintains a set of particle emitters.
|
||||
|
||||
Changelog
|
||||
2011/08/28 - creation (jcrussell)
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef _ZPARTICLEEFFECT_H
|
||||
#define _ZPARTICLEEFFECT_H
|
||||
|
||||
#include <ZRenderer/ZRenderer.hpp>
|
||||
#include <ZRendererUtil/ZParticleEmitter.h>
|
||||
|
||||
class ZParticleEffect
|
||||
{
|
||||
private:
|
||||
//The name of this particle effect
|
||||
ZString Name;
|
||||
|
||||
//Boolean indicating this particle effect has completed
|
||||
bool bIsFinished;
|
||||
|
||||
//The emitters attached to this particle effect
|
||||
ZArray< ZSmartPointer<ZParticleEmitter> > Emitters;
|
||||
|
||||
public:
|
||||
/*
|
||||
Default Constructor.
|
||||
*/
|
||||
ZParticleEffect();
|
||||
|
||||
/*
|
||||
Parameterized Constructor.
|
||||
|
||||
@param _name - the name of this particle effect
|
||||
*/
|
||||
ZParticleEffect(const ZString& _name);
|
||||
|
||||
/*
|
||||
Destructor.
|
||||
*/
|
||||
~ZParticleEffect();
|
||||
|
||||
/*
|
||||
public ZParticleEffect::AddEmitter
|
||||
|
||||
Adds an emitter to this particle effect. The emitter will be updated and rendered when the
|
||||
effect is.
|
||||
|
||||
@param _emitter - the emitter to add
|
||||
@return (void)
|
||||
@context (all)
|
||||
*/
|
||||
void AddEmitter(ZPtr<ZParticleEmitter> _emitter);
|
||||
|
||||
/*
|
||||
public ZParticleEffect::GetName
|
||||
|
||||
Gets the name of this particle effect.
|
||||
|
||||
@return (ZString) - the name of this effect
|
||||
@context (all)
|
||||
*/
|
||||
ZString GetName();
|
||||
|
||||
/*
|
||||
public ZParticleEffect::IsFinished
|
||||
|
||||
Returns true if this particle effect is finished.
|
||||
|
||||
@return (bool) - true if completed, false otherwise
|
||||
@context (all)
|
||||
*/
|
||||
bool IsFinished();
|
||||
|
||||
/*
|
||||
public ZParticleEffect::RemoveEmitter
|
||||
|
||||
Removes an emitter from this particle effect.
|
||||
|
||||
@param _emitter - the particle effect
|
||||
@return (bool) - true if the emitter was contained, false otherwise
|
||||
@context (all)
|
||||
*/
|
||||
bool RemoveEmitter(ZPtr<ZParticleEmitter> _emitter);
|
||||
|
||||
/*
|
||||
public ZParticleEffect::Render
|
||||
|
||||
Renders this particle effect using the provided renderer.
|
||||
|
||||
@param _renderer - the renderer to use
|
||||
@param _frameContext - the frame context to render with
|
||||
@param _drawGroup - the draw group to render in
|
||||
@return (void)
|
||||
@context (all)
|
||||
*/
|
||||
void Render(ZRenderer* _renderer, ZFrameContext _frameContext, int _drawGroup = 0);
|
||||
|
||||
/*
|
||||
public ZParticleEffect::SetFinished
|
||||
|
||||
Sets completion status of this effect to the provided value.
|
||||
|
||||
@param _status - completion status (true if finished, false otherwise)
|
||||
@return (void)
|
||||
@context (all)
|
||||
*/
|
||||
void SetFinished(bool _status);
|
||||
|
||||
/*
|
||||
public ZParticleEffect::SetName
|
||||
|
||||
Sets the name of this particle effect.
|
||||
|
||||
@param _name - the name of this particle effect
|
||||
@return (void)
|
||||
@context (all)
|
||||
*/
|
||||
void SetName(const ZString& _name);
|
||||
|
||||
/*
|
||||
public ZParticleEffect::Update
|
||||
|
||||
Updates this particle effect with the provided delta time since last call to update.
|
||||
|
||||
@param _dt - the time (in milliseconds) since the last call to Update
|
||||
@return (void)
|
||||
@context (all)
|
||||
*/
|
||||
void Update(size_t _dt);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
200
Include/ZRendererUtil/ZParticleEmitter.h
Normal file
200
Include/ZRendererUtil/ZParticleEmitter.h
Normal file
@@ -0,0 +1,200 @@
|
||||
/*
|
||||
ZParticleEmitter.h
|
||||
Author: James Russell <jcrussell@762studios.com>
|
||||
|
||||
Purpose: Particle emitter class, which maintains a set of strategies used to store, create, update, and render
|
||||
particles.
|
||||
|
||||
Changelog
|
||||
2011/08/28 - creation (jcrussell)
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef _ZPARTICLEEMITTER_H
|
||||
#define _ZPARTICLEEMITTER_H
|
||||
|
||||
#include <ZRenderer/ZRenderer.hpp>
|
||||
#include <ZRendererUtil/ZParticleStorageAllocator.h>
|
||||
#include <ZRendererUtil/ZParticleSpawnStrategy.h>
|
||||
#include <ZRendererUtil/ZParticleUpdateStrategy.h>
|
||||
#include <ZRendererUtil/ZParticleRenderStrategy.h>
|
||||
|
||||
//Forward Declaration
|
||||
class ZParticleEffect;
|
||||
|
||||
class ZParticleEmitter
|
||||
{
|
||||
protected:
|
||||
//Number of particles at a time this emitter supports
|
||||
size_t MaxParticles;
|
||||
|
||||
//Boolean indicating this emitter is complete (no longer emits particles)
|
||||
bool bIsFinished;
|
||||
|
||||
//The transform for the particle emitter
|
||||
ZMatrix44f Transform;
|
||||
|
||||
//Particle Generator
|
||||
ZPtr<ZParticleStorageAllocator> StorageAllocator;
|
||||
|
||||
//Particle Spawn Strategy
|
||||
ZPtr<ZParticleSpawnStrategy> SpawnStrategy;
|
||||
|
||||
//Particle Update Strategy
|
||||
ZPtr<ZParticleUpdateStrategy> UpdateStrategy;
|
||||
|
||||
//Particle Render Strategy
|
||||
ZPtr<ZParticleRenderStrategy> RenderStrategy;
|
||||
|
||||
public:
|
||||
/*
|
||||
Default Constructor.
|
||||
*/
|
||||
ZParticleEmitter();
|
||||
|
||||
/*
|
||||
Destructor.
|
||||
*/
|
||||
~ZParticleEmitter();
|
||||
|
||||
/*
|
||||
public ZParticleEmitter::GetMaxParticles
|
||||
|
||||
Returns the current amount of max particles this particle emitter supports.
|
||||
|
||||
@return (size_t)
|
||||
@context (all)
|
||||
*/
|
||||
size_t GetMaxParticles();
|
||||
|
||||
/*
|
||||
public ZParticleEmitter::GetTransform
|
||||
|
||||
Gets the local transform for this particle emitter.
|
||||
|
||||
@return (ZMatrix44f) - local transform for this emitter
|
||||
@context (all)
|
||||
*/
|
||||
ZMatrix44f GetTransform();
|
||||
|
||||
/*
|
||||
public ZParticleEmitter::IsFinished
|
||||
|
||||
Returns true if this particle emitter will no longer emit particles.
|
||||
|
||||
@return (bool) - true if finished, false otherwise
|
||||
@context (all)
|
||||
*/
|
||||
bool IsFinished();
|
||||
|
||||
/*
|
||||
public ZParticleEmitter::Render
|
||||
|
||||
Renders the contained particles using the provided render strategy.
|
||||
|
||||
@param _particleEffect - the parent particle effect
|
||||
@param _renderer - the renderer to use
|
||||
@param _context - frame context to render with
|
||||
@param _drawGroup - the draw group to render with
|
||||
@return (void)
|
||||
@context (all)
|
||||
*/
|
||||
void Render(ZParticleEffect* _particleEffect, ZRenderer* _renderer, ZFrameContext _context, int _drawGroup);
|
||||
|
||||
/*
|
||||
public ZParticleEmitter::SetMaxParticles
|
||||
|
||||
Sets the maximum number of particles this emitter supports.
|
||||
|
||||
@param _maxParticles - the maximum particle count
|
||||
@return (void)
|
||||
@context (all)
|
||||
*/
|
||||
void SetMaxParticles(size_t _maxParticles);
|
||||
|
||||
/*
|
||||
public ZParticleEmitter::SetFinished
|
||||
|
||||
Sets completion status of this emitter to the provided value.
|
||||
|
||||
@param _status - completion status (true if finished, false otherwise)
|
||||
@return (void)
|
||||
@context (all)
|
||||
*/
|
||||
void SetFinished(bool _status);
|
||||
|
||||
/*
|
||||
public ZParticleEmitter::SetParticleStorageAllocator
|
||||
|
||||
Sets the particle storage allocator for this particle emitter. This will call
|
||||
ZParticleStorageAllocator::AllocateParticleStorage.
|
||||
|
||||
@param _allocator - the allocator to use
|
||||
@param _maxParticles - the number of particles to allocate storage for
|
||||
@return (ZPtr<ZParticleStorageAllocator>) - the storage allocator that was previously attached
|
||||
@context (all)
|
||||
*/
|
||||
ZPtr<ZParticleStorageAllocator> SetParticleStorageAllocator(ZPtr<ZParticleStorageAllocator> _allocator, size_t _maxParticles);
|
||||
|
||||
/*
|
||||
public ZParticleEmitter::SetParticleSpawnStrategy
|
||||
|
||||
Sets the particle span strategy for this particle emitter.
|
||||
|
||||
@param _spawnStrategy - the spawn strategy to use
|
||||
@return (ZPtr<ZParticleSpawnStrategy>) - the spawn strategy that was previously attached
|
||||
@context (all)
|
||||
*/
|
||||
ZPtr<ZParticleSpawnStrategy> SetParticleSpawnStrategy(ZPtr<ZParticleSpawnStrategy> _spawnStrategy);
|
||||
|
||||
/*
|
||||
public ZParticleEmitter::SetParticleUpdateStrategy
|
||||
|
||||
Sets the particle update strategy for this particle emitter.
|
||||
|
||||
@param _updateStrategy - the particle update strategy to use
|
||||
@return (ZPtr<ZParticleUpdateStrategy>) - the update strategy that was previously attached
|
||||
@context (all)
|
||||
*/
|
||||
ZPtr<ZParticleUpdateStrategy> SetParticleUpdateStrategy(ZPtr<ZParticleUpdateStrategy> _updateStrategy);
|
||||
|
||||
/*
|
||||
public ZParticleEmitter::SetParticleRenderStrategy
|
||||
|
||||
Sets the render strategy for this particle emitter. This will call AllocateBuffers on the render strategy.
|
||||
|
||||
@param _renderStrategy - the render strategy to use
|
||||
@param _renderer - the renderer to allocate buffers from
|
||||
@return (ZPtr<ZParticleRenderStrategy>) - the render strategy that was previously attached
|
||||
@context (all)
|
||||
*/
|
||||
ZPtr<ZParticleRenderStrategy> SetParticleRenderStrategy(ZPtr<ZParticleRenderStrategy> _renderStrategy, ZRenderer *_renderer);
|
||||
|
||||
/*
|
||||
public ZParticleEmitter::SetTransform
|
||||
|
||||
Sets the transform for this particle emitter.
|
||||
|
||||
@param _transform - the transform to use
|
||||
@return (void)
|
||||
@context (all)
|
||||
*/
|
||||
void SetTransform(ZMatrix44f _transform);
|
||||
|
||||
/*
|
||||
public ZParticleEmitter::Update
|
||||
|
||||
Runs through the various installed strategies, which can will both create new particles (as dictated by strategy)
|
||||
and update existing ones.
|
||||
|
||||
@param _particleEffect - the parent particle effect
|
||||
@param _dt - the time (in milliseconds) since last update
|
||||
@return (void)
|
||||
@context (all)
|
||||
*/
|
||||
void Update(ZParticleEffect* _particleEffect, size_t _dt);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
80
Include/ZRendererUtil/ZParticleRenderStrategy.h
Normal file
80
Include/ZRendererUtil/ZParticleRenderStrategy.h
Normal file
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
ZParticleRenderStrategy.h
|
||||
Author: James Russell <jcrussell@762studios.com>
|
||||
|
||||
Purpose: TODO
|
||||
|
||||
Changelog
|
||||
2011/08/28 - creation (jcrussell)
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef _ZPARTICLERENDERSTRATEGY_H
|
||||
#define _ZPARTICLERENDERSTRATEGY_H
|
||||
|
||||
#include <ZUtil/ZUtil.hpp>
|
||||
#include <ZRenderer/ZRenderer.hpp>
|
||||
#include <ZRendererUtil/ZParticleStorageAllocator.h>
|
||||
|
||||
//Forward Declarations
|
||||
class ZParticleEffect;
|
||||
class ZParticleEmitter;
|
||||
class ZParticleStorageAllocator;
|
||||
|
||||
class ZParticleRenderStrategy
|
||||
{
|
||||
public:
|
||||
//Virtual Destructor
|
||||
~ZParticleRenderStrategy() { }
|
||||
|
||||
/*
|
||||
public ZParticleRenderStrategy::AllocateBuffers
|
||||
|
||||
Called when the particle render strategy needs to allocate buffers from the renderer
|
||||
for particle data.
|
||||
|
||||
@param _maxParticles - the number of particles to allocate buffer space for
|
||||
@param _renderer - the renderer to allocate buffers from
|
||||
@return (void)
|
||||
@context (all)
|
||||
*/
|
||||
virtual void AllocateBuffers(size_t _maxParticles, ZRenderer *_renderer) = 0;
|
||||
|
||||
/*
|
||||
virtual public ZParticleRenderStrategy::CheckParticleFormat
|
||||
|
||||
Checks to see if this render strategy can render the provided particle format.
|
||||
|
||||
@param _format - string description of the particle format
|
||||
@return (bool) - true if this render strategy can handle it, false otherwise
|
||||
@context (all)
|
||||
*/
|
||||
virtual bool CheckParticleFormat(const ZString& _format) = 0;
|
||||
|
||||
/*
|
||||
virtual public ZParticleUpdateStrategy::RenderParticles
|
||||
|
||||
Renders the particle data present in particle storage.
|
||||
|
||||
@param _particleEffect - the emitter's parent particle effect
|
||||
@param _particleEmitter - the parent emitter
|
||||
@param _storageAllocator - the particle data storage
|
||||
@param _renderer - the renderer to render to
|
||||
@param _frameContext - the frame context to render with
|
||||
@return (void)
|
||||
@context (all)
|
||||
*/
|
||||
virtual void RenderParticles(ZParticleEffect* _particleEffect,
|
||||
ZParticleEmitter* _particleEmitter,
|
||||
ZParticleStorageAllocator* _storageAllocator,
|
||||
ZRenderer* _renderer,
|
||||
ZFrameContext _frameContext,
|
||||
const ZMatrix44f& _transform,
|
||||
int _drawGroup
|
||||
) = 0;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
61
Include/ZRendererUtil/ZParticleSpawnStrategy.h
Normal file
61
Include/ZRendererUtil/ZParticleSpawnStrategy.h
Normal file
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
ZParticleSpawnStrategy.h
|
||||
Author: James Russell <jcrussell@762studios.com>
|
||||
|
||||
Purpose: TODO
|
||||
|
||||
Changelog
|
||||
2011/08/28 - creation (jcrussell)
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef _ZPARTICLESPAWNSTRATEGY_H
|
||||
#define _ZPARTICLESPAWNSTRATEGY_H
|
||||
|
||||
#include <ZUtil/ZUtil.hpp>
|
||||
|
||||
//Forward Declarations
|
||||
class ZParticleEffect;
|
||||
class ZParticleEmitter;
|
||||
class ZParticleStorageAllocator;
|
||||
|
||||
class ZParticleSpawnStrategy
|
||||
{
|
||||
public:
|
||||
//Virtual Destructor
|
||||
~ZParticleSpawnStrategy() { }
|
||||
|
||||
/*
|
||||
virtual public ZParticleSpawnStrategy::CheckParticleFormat
|
||||
|
||||
Checks to see if this spawn strategy can spawn the provided particle format.
|
||||
|
||||
@param _format - string description of the particle format
|
||||
@return (bool) - true if this spawn strategy can handle it, false otherwise
|
||||
@context (all)
|
||||
*/
|
||||
virtual bool CheckParticleFormat(const ZString& _format) = 0;
|
||||
|
||||
/*
|
||||
virtual public ZParticleSpawnStrategy::UpdateSpawn
|
||||
|
||||
An update call to the spawn strategy that determines if more particles should be created. If so, the new particle data
|
||||
can be placed directly into particle storage.
|
||||
|
||||
@param _particleEffect - the emitter's parent particle effect
|
||||
@param _particleEmitter - the parent emitter
|
||||
@param _storageAllocator - particle storage used by this particle effect
|
||||
@param _dt - the time (in milliseconds) since last update
|
||||
@return (void)
|
||||
@context (all)
|
||||
*/
|
||||
virtual void UpdateSpawn(ZParticleEffect* _particleEffect,
|
||||
ZParticleEmitter* _particleEmitter,
|
||||
ZParticleStorageAllocator* _storageAllocator,
|
||||
size_t _dt
|
||||
) = 0;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
82
Include/ZRendererUtil/ZParticleStorageAllocator.h
Normal file
82
Include/ZRendererUtil/ZParticleStorageAllocator.h
Normal file
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
ZParticleGenerator.h
|
||||
Author: James Russell <jcrussell@762studios.com>
|
||||
|
||||
Purpose: The particle generator is responsible for generating / allocating the particle data
|
||||
and storing it for the duration the particle emitter is alive.
|
||||
|
||||
Also responsible for cleanup.
|
||||
|
||||
Changelog
|
||||
2011/08/28 - creation (jcrussell)
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef _ZPARTICLESTORAGEALLOCATOR_H
|
||||
#define _ZPARTICLESTORAGEALLOCATOR_H
|
||||
|
||||
#include <ZUtil/ZUtil.hpp>
|
||||
|
||||
//Forward Declaration
|
||||
class ZParticleEffect;
|
||||
class ZParticleEmitter;
|
||||
|
||||
class ZParticleStorageAllocator
|
||||
{
|
||||
public:
|
||||
//Virtual Destructor
|
||||
virtual ~ZParticleStorageAllocator() { }
|
||||
|
||||
/*
|
||||
virtual public ZParticleGenerator::AllocateParticleStorage
|
||||
|
||||
Allocates particle storage for this particle emitter.
|
||||
|
||||
@param _emitter - the emitter we are creating storage for
|
||||
@param _maxParticles - the number of particles we allocate storage for
|
||||
@return (void)
|
||||
@context (all)
|
||||
*/
|
||||
virtual void AllocateParticleStorage(ZParticleEmitter* _emitter, size_t _maxParticles) = 0;
|
||||
|
||||
/*
|
||||
virtual public ZParticleGenerator::DeallocateParticleStorage
|
||||
|
||||
Deallocates storage previously allocated with AllocateParticleStorage.
|
||||
|
||||
@return (void)
|
||||
@context (all)
|
||||
*/
|
||||
virtual void DeallocateParticleStorage() = 0;
|
||||
|
||||
/*
|
||||
virtual public ZParticleStorageAllocator::GetParticleFormat
|
||||
|
||||
Returns a string 'type' indicating the type of particle storage used by this allocator. Checked
|
||||
against the other strategies to ensure compatibility.
|
||||
|
||||
@return (ZString)
|
||||
@context (all)
|
||||
*/
|
||||
virtual ZString GetParticleFormat() = 0;
|
||||
|
||||
/*
|
||||
virtual public ZParticleStorageAllocator::Update
|
||||
|
||||
Updates the storage allocator, indicating another frame has passed.
|
||||
|
||||
@param _effect - the particle effect
|
||||
@param _emitter - the particle emitter
|
||||
@param _dt - amount of time passed (in ms)
|
||||
@return (void)
|
||||
@context (all)
|
||||
*/
|
||||
virtual void Update(ZParticleEffect *_effect,
|
||||
ZParticleEmitter *_emitter,
|
||||
size_t _dt
|
||||
) = 0;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
60
Include/ZRendererUtil/ZParticleUpdateStrategy.h
Normal file
60
Include/ZRendererUtil/ZParticleUpdateStrategy.h
Normal file
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
ZParticleUpdateStrategy.h
|
||||
Author: James Russell <jcrussell@762studios.com>
|
||||
|
||||
Purpose: TODO
|
||||
|
||||
Changelog
|
||||
2011/08/28 - creation (jcrussell)
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef _ZPARTICLEUPDATESTRATEGY_H
|
||||
#define _ZPARTICLEUPDATESTRATEGY_H
|
||||
|
||||
#include <ZUtil/ZUtil.hpp>
|
||||
|
||||
//Forward Declarations
|
||||
class ZParticleEffect;
|
||||
class ZParticleEmitter;
|
||||
class ZParticleStorageAllocator;
|
||||
|
||||
class ZParticleUpdateStrategy
|
||||
{
|
||||
public:
|
||||
//Virtual Destructor
|
||||
~ZParticleUpdateStrategy() { }
|
||||
|
||||
/*
|
||||
virtual public ZParticleUpdateStrategy::CheckParticleFormat
|
||||
|
||||
Checks to see if this update strategy can update the provided particle format.
|
||||
|
||||
@param _format - string description of the particle format
|
||||
@return (bool) - true if this udpate strategy can handle it, false otherwise
|
||||
@context (all)
|
||||
*/
|
||||
virtual bool CheckParticleFormat(const ZString& _format) = 0;
|
||||
|
||||
/*
|
||||
virtual public ZParticleUpdateStrategy::UpdateParticles
|
||||
|
||||
Updates the particle data present in particle storage.
|
||||
|
||||
@param _particleEffect - the emitter's parent particle effect
|
||||
@param _particleEmitter - the parent emitter
|
||||
@param _storageAllocator - the particle data storage
|
||||
@param _dt - the time (in millisecond) since last update
|
||||
@return (void)
|
||||
@context (all)
|
||||
*/
|
||||
virtual void UpdateParticles(ZParticleEffect* _particleEffect,
|
||||
ZParticleEmitter* _particleEmitter,
|
||||
ZParticleStorageAllocator* _storageAllocator,
|
||||
size_t _dt
|
||||
) = 0;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
145
Include/ZRendererUtil/ZPerspectiveCamera.hpp
Normal file
145
Include/ZRendererUtil/ZPerspectiveCamera.hpp
Normal file
@@ -0,0 +1,145 @@
|
||||
#include <SST/SST_Math.h>
|
||||
|
||||
//Perspective Camera Class, Used to compute camera transforms
|
||||
class ZPerspectiveCamera
|
||||
{
|
||||
protected:
|
||||
bool transformDirty; //Dirty flag for computing camera transform
|
||||
|
||||
SST_Mat44f CameraTransform;
|
||||
|
||||
SST_Vec3f EyePoint;
|
||||
SST_Vec3f ForwardVec;
|
||||
SST_Vec3f UpVec;
|
||||
SST_Vec3f RightVec;
|
||||
|
||||
float NearClip;
|
||||
float FarClip;
|
||||
float XFov;
|
||||
float AspectRatio;
|
||||
|
||||
void ComputeCameraTransform()
|
||||
{
|
||||
SST_Mat44f perspectiveMatrix;
|
||||
SST_Mat44f viewMatrix;
|
||||
SST_Vec3f target = {ForwardVec.x + EyePoint.x,
|
||||
ForwardVec.y + EyePoint.y,
|
||||
ForwardVec.z + EyePoint.z};
|
||||
|
||||
SST_Math_Mat44fCreatePerspective(&perspectiveMatrix, this->XFov, this->AspectRatio, this->NearClip, this->FarClip);
|
||||
SST_Math_Mat44fCreateLookAt(&viewMatrix, &this->EyePoint, &target, &this->UpVec);
|
||||
SST_Math_Mat44fMultiplyMatrix(&perspectiveMatrix, &viewMatrix, &this->CameraTransform);
|
||||
|
||||
this->transformDirty = false;
|
||||
}
|
||||
|
||||
//Flags the transform as 'dirty'
|
||||
void FlagTransforms()
|
||||
{
|
||||
this->transformDirty = true;
|
||||
}
|
||||
|
||||
public:
|
||||
ZPerspectiveCamera()
|
||||
{
|
||||
SST_Vec3f eye = { 0, 0, 0 };
|
||||
SST_Vec3f forward = { 0, 1, 0 };
|
||||
SST_Vec3f up = { 0, 0, 1 };
|
||||
SST_Vec3f right = { 1, 0, 1 };
|
||||
|
||||
SetEyePoint(&eye);
|
||||
SetForwardVec(&forward);
|
||||
SetUpVec(&up);
|
||||
SetRightVec(&right);
|
||||
|
||||
NearClip = 1.0f;
|
||||
FarClip = 10000.0f;
|
||||
XFov = 90.0f;
|
||||
AspectRatio = 1.0f;
|
||||
|
||||
this->transformDirty = true;
|
||||
}
|
||||
|
||||
//Getters for camera data
|
||||
const SST_Vec3f* GetEyePoint() { return &EyePoint; }
|
||||
const SST_Vec3f* GetForwardVec() { return &ForwardVec; }
|
||||
const SST_Vec3f* GetUpVec() { return &UpVec; }
|
||||
const SST_Vec3f* GetRightVec() { return &RightVec; }
|
||||
float GetNearClip() { return NearClip; }
|
||||
float GetFarClip() { return FarClip; }
|
||||
float GetXFov() { return XFov; }
|
||||
float GetAspectRatio() { return AspectRatio; }
|
||||
|
||||
//Setters for camera data. Will flag the transform as 'dirty'
|
||||
void SetEyePoint(const SST_Vec3f* _eye) { EyePoint = *_eye; FlagTransforms(); }
|
||||
void SetForwardVec(const SST_Vec3f* _forward) { ForwardVec = *_forward; FlagTransforms(); }
|
||||
void SetUpVec(const SST_Vec3f* _up) { UpVec = *_up; FlagTransforms(); }
|
||||
void SetRightVec(const SST_Vec3f* _right) { RightVec = *_right; FlagTransforms(); }
|
||||
|
||||
void SetNearClip(float _nearClip) { NearClip = _nearClip; FlagTransforms(); }
|
||||
void SetFarClip(float _farClip) { FarClip = _farClip; FlagTransforms(); }
|
||||
void SetXFov(float _xFov) { XFov = _xFov; FlagTransforms(); }
|
||||
void SetAspectRatio(float _ratio) { AspectRatio = _ratio; FlagTransforms(); }
|
||||
|
||||
//Movement methods, which move the camera in the direction if it's basis vectors by a factor
|
||||
void MoveForward(float t)
|
||||
{
|
||||
SST_Vec3f tmp;
|
||||
|
||||
SST_Math_Vec3fScale(&ForwardVec, t, &tmp);
|
||||
SST_Math_Vec3fAddLocal(&EyePoint, &tmp);
|
||||
|
||||
FlagTransforms();
|
||||
}
|
||||
|
||||
void MoveUp(float t)
|
||||
{
|
||||
SST_Vec3f tmp;
|
||||
|
||||
SST_Math_Vec3fScale(&UpVec, t, &tmp);
|
||||
SST_Math_Vec3fAddLocal(&EyePoint, &tmp);
|
||||
|
||||
FlagTransforms();
|
||||
}
|
||||
|
||||
void MoveRight(float t)
|
||||
{
|
||||
SST_Vec3f tmp;
|
||||
|
||||
SST_Math_Vec3fScale(&RightVec, t, &tmp);
|
||||
SST_Math_Vec3fAddLocal(&EyePoint, &tmp);
|
||||
FlagTransforms();
|
||||
}
|
||||
|
||||
//Rotation Methods, which rotate the camera about it's basis vectors
|
||||
void RotateUp(float t)
|
||||
{
|
||||
SST_Math_Vec3fRotateAboutLocal(&this->ForwardVec, &this->RightVec, t);
|
||||
SST_Math_Vec3fRotateAboutLocal(&this->UpVec, &this->RightVec, t);
|
||||
FlagTransforms();
|
||||
}
|
||||
|
||||
void RotateRight(float t)
|
||||
{
|
||||
SST_Math_Vec3fRotateAboutLocal(&this->ForwardVec, &this->UpVec, t);
|
||||
SST_Math_Vec3fRotateAboutLocal(&this->RightVec, &this->UpVec, t);
|
||||
FlagTransforms();
|
||||
}
|
||||
|
||||
void RotateClockwise(float t)
|
||||
{
|
||||
SST_Math_Vec3fRotateAboutLocal(&this->UpVec, &this->ForwardVec, t);
|
||||
SST_Math_Vec3fRotateAboutLocal(&this->RightVec, &this->ForwardVec, t);
|
||||
FlagTransforms();
|
||||
}
|
||||
|
||||
//Camera transform getters, which will trigger a recompute of the transform matrix if need be
|
||||
const SST_Mat44f* GetCameraTransform()
|
||||
{
|
||||
if (this->transformDirty)
|
||||
{
|
||||
this->ComputeCameraTransform();
|
||||
}
|
||||
return &this->CameraTransform;
|
||||
}
|
||||
};
|
||||
84
Include/ZRendererUtil/ZSolidFontFace.hpp
Normal file
84
Include/ZRendererUtil/ZSolidFontFace.hpp
Normal file
@@ -0,0 +1,84 @@
|
||||
/*
|
||||
ZSolidFontFace.hpp
|
||||
Author: Patrick Baggett <ptbaggett@762studios.com>
|
||||
|
||||
Purpose: TODO
|
||||
|
||||
Changelog
|
||||
2011/09/18 - creation (ptbaggett)
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef _ZSOLIDFONTFACE_HPP
|
||||
#define _ZSOLIDFONTFACE_HPP
|
||||
|
||||
#include <SST/SST_Vec2.h>
|
||||
|
||||
#include <ZRendererUtil/ZFontRenderer.hpp> //Need ZFontBounds structure
|
||||
|
||||
//#include <vector>
|
||||
#include <ft2build.h>
|
||||
#include FT_FREETYPE_H
|
||||
#include FT_GLYPH_H
|
||||
|
||||
//Needed for friend class definition
|
||||
class ZSolidFontRenderer;
|
||||
|
||||
// Structure representing glyph information for use in solid font rendering
|
||||
struct ZSolidGlyphInfo
|
||||
{
|
||||
FT_UInt glyphId; // Glyph ID, as read from the font
|
||||
ZArray<SST_Vec2f> verts; // Vertex data, every 3 vertices makes a triangle
|
||||
int advancex; // Amount along X axis to advance pen by, in pixels
|
||||
int advancey; // Amount along Y axis to advance pen by, in pixels
|
||||
ZFontBounds bbox; // Bounding box of this glyph, in pixels
|
||||
};
|
||||
|
||||
//Class representing a font face created by a SolidFontRenderer
|
||||
class ZSolidFontFace
|
||||
{
|
||||
friend class ZSolidFontRenderer;
|
||||
private:
|
||||
FT_Face face;
|
||||
char* fontData;
|
||||
int hasKerning;
|
||||
|
||||
ZHashMap<unsigned int, ZSolidGlyphInfo> glyphCache;
|
||||
|
||||
public:
|
||||
|
||||
/*
|
||||
Default Constructor.
|
||||
*/
|
||||
ZSolidFontFace();
|
||||
|
||||
/*
|
||||
Destructor.
|
||||
*/
|
||||
~ZSolidFontFace();
|
||||
|
||||
/*
|
||||
public ZSolidFontFace::cacheGlyph
|
||||
|
||||
Caches a glyph, given a UTF-32 character code. The glyph must not already be loaded.
|
||||
|
||||
@param charCode - The UTF-32 character code for this glyph
|
||||
@return (const ZSolidGlyphInfo&) - Reference to the glyph information.
|
||||
@context (all)
|
||||
*/
|
||||
const ZSolidGlyphInfo& CacheGlyph(unsigned int charCode);
|
||||
|
||||
/*
|
||||
public ZSolidFontFace::getGlyph
|
||||
|
||||
Gets a glyph from the cache, or loads it if necessary.
|
||||
|
||||
@param charCode -
|
||||
@return (const ZSolidGlyphInfo*)
|
||||
@context (all)
|
||||
*/
|
||||
const ZSolidGlyphInfo* GetGlyph(unsigned int charCode);
|
||||
};
|
||||
|
||||
#endif
|
||||
101
Include/ZRendererUtil/ZSolidFontRenderer.hpp
Normal file
101
Include/ZRendererUtil/ZSolidFontRenderer.hpp
Normal file
@@ -0,0 +1,101 @@
|
||||
/*
|
||||
ZSolidFontRenderer.hpp
|
||||
Author: Patrick Baggett <ptbaggett@762studios.com>
|
||||
|
||||
Purpose: TODO
|
||||
|
||||
Changelog
|
||||
2011/09/18 - creation (ptbaggett)
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef _ZSOLIDFONTRENDERER_H
|
||||
#define _ZSOLIDFONTRENDERER_H
|
||||
|
||||
#include <SST/SST_Mat44.h>
|
||||
|
||||
#include <ZRenderer/ZRenderer.hpp>
|
||||
#include <ZRenderer/ZDataBuffer.hpp>
|
||||
#include <ZRendererUtil/ZFontRendererBase.hpp>
|
||||
#include <ZRendererUtil/ZSolidFontFace.hpp>
|
||||
|
||||
#include <ft2build.h>
|
||||
#include FT_FREETYPE_H
|
||||
|
||||
#define TRICACHE_SIZE (8*1024) //Cache up to 8K polygons before drawing
|
||||
|
||||
class ZSolidFontRenderer : public ZFontRendererBase
|
||||
{
|
||||
protected:
|
||||
ZRenderer* renderer;
|
||||
ZPtr<ZDataBuffer> tricache;
|
||||
|
||||
const ZDataBufferStream* posstream;
|
||||
const ZDataBufferStream* colorstream;
|
||||
const ZDataBufferBlock* matrixBlock;
|
||||
const ZDataBufferBlock* indexBlock;
|
||||
|
||||
ZPtr<ZShaderProgram> shaderprogram;
|
||||
ZPtr<ZShaderParams> shaderparams;
|
||||
ZPtr<ZIndexParams> indexparams;
|
||||
ZPtr<ZVertexParams> vertexparams;
|
||||
|
||||
ZPtr<ZDataBuffer> uniforms;
|
||||
ZPtr<ZDataBuffer> indexes;
|
||||
|
||||
ZFrameContext ctx;
|
||||
SST_Mat44f xform;
|
||||
|
||||
//Internal used struct for vertex / color pairing
|
||||
struct SolidVertex
|
||||
{
|
||||
float x, y;
|
||||
float rgba[4];
|
||||
};
|
||||
|
||||
SolidVertex* vtx_dma;
|
||||
FT_Library library;
|
||||
float color[4];
|
||||
size_t nrTrisWritten;
|
||||
bool inRendering;
|
||||
|
||||
void flushTriCache();
|
||||
|
||||
public:
|
||||
|
||||
/*
|
||||
Constructor.
|
||||
|
||||
@param _renderer - the current renderer instance.
|
||||
*/
|
||||
ZSolidFontRenderer(ZRenderer* _renderer);
|
||||
|
||||
/*
|
||||
Destructor.
|
||||
*/
|
||||
virtual ~ZSolidFontRenderer();
|
||||
|
||||
//Subclass Implementation
|
||||
virtual ZFontFace CreateFontFace(int pixelSize, const void* fontData, unsigned int dataSize);
|
||||
|
||||
//Subclass Implementation
|
||||
virtual void DeleteFontFace(ZFontFace face);
|
||||
|
||||
//Subclass Implementation
|
||||
virtual void BeginText(ZFrameContext _ctx, const SST_Mat44f& _xform);
|
||||
|
||||
//Subclass Implementation
|
||||
virtual void EndText();
|
||||
|
||||
//Subclass Implementation
|
||||
virtual void RenderText(int x, int y, const char* text);
|
||||
|
||||
//Subclass Implementation
|
||||
virtual void ComputeBounds(const char* text, ZFontBounds* bounds);
|
||||
|
||||
//Subclass Implementation
|
||||
virtual void SetColor(float r, float g, float b, float a);
|
||||
};
|
||||
|
||||
#endif
|
||||
105
Include/ZRendererUtil/ZStandardParticleRenderStrategy.h
Normal file
105
Include/ZRendererUtil/ZStandardParticleRenderStrategy.h
Normal file
@@ -0,0 +1,105 @@
|
||||
/*
|
||||
ZStandardParticleRenderStrategy.h
|
||||
Author: James Russell <jcrussell@762studios.com>
|
||||
|
||||
Purpose: TODO
|
||||
|
||||
Changelog
|
||||
2011/09/11 - creation (jcrussell)
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef _ZSTANDARDPARTICLERENDERSTRATEGY_H
|
||||
#define _ZSTANDARDPARTICLERENDERSTRATEGY_H
|
||||
|
||||
#include <ZRendererUtil/ZParticleRenderStrategy.h>
|
||||
#include <ZRendererUtil/ZStandardParticleStorageAllocator.h>
|
||||
|
||||
class ZStandardParticleRenderStrategy : public ZParticleRenderStrategy
|
||||
{
|
||||
protected:
|
||||
//Vertex buffer
|
||||
ZPtr<ZDataBuffer> VertexBuffer;
|
||||
|
||||
//Index buffer
|
||||
ZPtr<ZDataBuffer> IndexBuffer;
|
||||
|
||||
//Material we use
|
||||
ZPtr<ZMaterialSurface> ParticleMaterial;
|
||||
|
||||
//Texture we'll be using
|
||||
ZPtr<ZTexture2D> ParticleTexture;
|
||||
|
||||
//Our render state
|
||||
ZRenderState RenderState;
|
||||
|
||||
//Our UV coordinates (per vertex)
|
||||
float UVs[8];
|
||||
|
||||
public:
|
||||
/*
|
||||
Constructor.
|
||||
|
||||
@param _maxParticles - maximum number of particles we will use
|
||||
@param _renderer - the renderer instance
|
||||
*/
|
||||
ZStandardParticleRenderStrategy();
|
||||
|
||||
/*
|
||||
Destructor.
|
||||
*/
|
||||
~ZStandardParticleRenderStrategy();
|
||||
|
||||
/*
|
||||
public ZStandardParticleRenderStrategy::SetParticleTexture
|
||||
|
||||
TODO
|
||||
|
||||
@param _texture -
|
||||
@return (void)
|
||||
@context (all)
|
||||
*/
|
||||
void SetParticleTexture(ZPtr<ZTexture2D> _texture);
|
||||
|
||||
/*
|
||||
public ZStandardParticleRenderStrategy::SetParticleTextureUVs
|
||||
|
||||
TODO
|
||||
|
||||
@param _uvs - uv coordinate array (size 8)
|
||||
@return (void)
|
||||
@context (all)
|
||||
*/
|
||||
void SetParticleTextureUVs(float *_uvs);
|
||||
|
||||
/*
|
||||
public ZStandardParticleRenderStrategy::SetRenderState
|
||||
|
||||
TODO
|
||||
|
||||
@param _state -
|
||||
@return (void)
|
||||
@context (all)
|
||||
*/
|
||||
void SetRenderState(ZRenderState _state);
|
||||
|
||||
//Subclass Override
|
||||
void AllocateBuffers(size_t _maxParticles, ZRenderer *_renderer);
|
||||
|
||||
//Subclass Override
|
||||
virtual bool CheckParticleFormat( const ZString& _format );
|
||||
|
||||
//Subclass Override
|
||||
virtual void RenderParticles(ZParticleEffect* _particleEffect,
|
||||
ZParticleEmitter* _particleEmitter,
|
||||
ZParticleStorageAllocator* _storageAllocator,
|
||||
ZRenderer* _renderer,
|
||||
ZFrameContext _frameContext,
|
||||
const ZMatrix44f& _transform,
|
||||
int _drawGroup );
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
218
Include/ZRendererUtil/ZStandardParticleSpawnStrategy.h
Normal file
218
Include/ZRendererUtil/ZStandardParticleSpawnStrategy.h
Normal file
@@ -0,0 +1,218 @@
|
||||
/*
|
||||
ZStandardParticleSpawnStrategy.h
|
||||
Author: James Russell <jcrussell@762studios.com>
|
||||
|
||||
Purpose: TODO
|
||||
|
||||
Changelog
|
||||
2011/09/11 - creation (jcrussell)
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef _ZSTANDARDPARTICLESPAWNSTRATEGY_H
|
||||
#define _ZSTANDARDPARTICLESPAWNSTRATEGY_H
|
||||
|
||||
#define ZSP_DEFAULT_SPAWN_MASS (1)
|
||||
|
||||
#define ZSP_DEFAULT_SPAWN_ENERGY (1000)
|
||||
|
||||
#define ZSP_DEFAULT_SPAWN_VELOCITY_X (0.0f)
|
||||
#define ZSP_DEFAULT_SPAWN_VELOCITY_Y (0.0f)
|
||||
#define ZSP_DEFAULT_SPAWN_VELOCITY_Z (0.0f)
|
||||
|
||||
#define ZSP_DEFAULT_SPAWN_FACING_X (0.0f)
|
||||
#define ZSP_DEFAULT_SPAWN_FACING_Y (0.0f)
|
||||
#define ZSP_DEFAULT_SPAWN_FACING_Z (1.0f)
|
||||
|
||||
#define ZSP_DEFAULT_SPAWN_SCALE_X (1.0f)
|
||||
#define ZSP_DEFAULT_SPAWN_SCALE_Y (1.0f)
|
||||
|
||||
#define ZSP_DEFAULT_SPAWN_COLOR_R (1.0f)
|
||||
#define ZSP_DEFAULT_SPAWN_COLOR_G (1.0f)
|
||||
#define ZSP_DEFAULT_SPAWN_COLOR_B (1.0f)
|
||||
#define ZSP_DEFAULT_SPAWN_COLOR_A (1.0f)
|
||||
|
||||
#define ZSP_DEFAULT_TEXTURE_U (0.0f)
|
||||
#define ZSP_DEFAULT_TEXTURE_V (0.0f)
|
||||
#define ZSP_DEFAULT_TEXTURE_OFFSET (1.0f)
|
||||
|
||||
#define ZSP_DEFAULT_SPAWN_INTERVAL (100)
|
||||
#define ZSP_DEFAULT_SPAWN_ANGLE (0.0f)
|
||||
#define ZSP_DEFAULT_SPAWN_COUNT_MIN (0)
|
||||
#define ZSP_DEFAULT_SPAWN_COUNT_MAX (1)
|
||||
|
||||
#include <ZRendererUtil/ZStandardParticleStorageAllocator.h>
|
||||
#include <ZRendererUtil/ZParticleSpawnStrategy.h>
|
||||
|
||||
class ZStandardParticleSpawnStrategy : public ZParticleSpawnStrategy
|
||||
{
|
||||
private:
|
||||
//The time until our next spawn
|
||||
int NextSpawn;
|
||||
|
||||
//Our current spawn group
|
||||
size_t CurrentSpawnGroup;
|
||||
|
||||
protected:
|
||||
//Template for the particle we will be spawning with
|
||||
ZStandardParticle TemplateParticle;
|
||||
|
||||
//The span between particle spawns
|
||||
size_t SpawnInterval;
|
||||
|
||||
//The half-angle we deviate within when spawning a particle [0.0 - pi]
|
||||
float SpawnAngle;
|
||||
|
||||
//The particle count spawn range (lower, upper)
|
||||
ZPair<size_t, size_t> SpawnCountRange;
|
||||
|
||||
public:
|
||||
/*
|
||||
Default Constructor.
|
||||
*/
|
||||
ZStandardParticleSpawnStrategy();
|
||||
|
||||
/*
|
||||
Destructor.
|
||||
*/
|
||||
virtual ~ZStandardParticleSpawnStrategy();
|
||||
|
||||
//Subclass Override
|
||||
virtual bool CheckParticleFormat( const ZString& _format );
|
||||
|
||||
//Subclass Override
|
||||
virtual void UpdateSpawn(ZParticleEffect* _particleEffect,
|
||||
ZParticleEmitter* _particleEmitter,
|
||||
ZParticleStorageAllocator* _storageAllocator,
|
||||
size_t _dt );
|
||||
|
||||
/*
|
||||
public ZStandardParticleSpawnStrategy::GetSpawnAngle
|
||||
|
||||
TODO
|
||||
|
||||
@return (float)
|
||||
@context (all)
|
||||
*/
|
||||
float GetSpawnAngle();
|
||||
|
||||
/*
|
||||
public ZStandardParticleSpawnStrategy::GetSpawnColor
|
||||
|
||||
TODO
|
||||
|
||||
@return (const ZVector4f&)
|
||||
@context (all)
|
||||
*/
|
||||
const ZVector4f& GetSpawnColor();
|
||||
|
||||
/*
|
||||
public ZStandardParticleSpawnStrategy::GetSpawnEnergy
|
||||
|
||||
TODO
|
||||
|
||||
@return (size_t)
|
||||
@context (all)
|
||||
*/
|
||||
size_t GetSpawnEnergy();
|
||||
|
||||
/*
|
||||
public ZStandardParticleSpawnStrategy::GetSpawnInterval
|
||||
|
||||
TODO
|
||||
|
||||
@return (size_t)
|
||||
@context (all)
|
||||
*/
|
||||
size_t GetSpawnInterval();
|
||||
|
||||
/*
|
||||
public ZStandardParticleSpawnStrategy::GetSpawnScale
|
||||
|
||||
TODO
|
||||
|
||||
@return (const ZVector2f&)
|
||||
@context (all)
|
||||
*/
|
||||
const ZVector2f& GetSpawnScale();
|
||||
|
||||
/*
|
||||
public ZStandardParticleSpawnStrategy::GetSpawnVelocity
|
||||
|
||||
TODO
|
||||
|
||||
@return (const ZVector3f&)
|
||||
@context (all)
|
||||
*/
|
||||
const ZVector3f& GetSpawnVelocity();
|
||||
|
||||
/*
|
||||
public ZStandardParticleSpawnStrategy::SetSpawnAngle
|
||||
|
||||
TODO
|
||||
|
||||
@param _angle -
|
||||
@return (void)
|
||||
@context (all)
|
||||
*/
|
||||
void SetSpawnAngle(float _angle);
|
||||
|
||||
/*
|
||||
public ZStandardParticleSpawnStrategy::SetSpawnColor
|
||||
|
||||
TODO
|
||||
|
||||
@param _color -
|
||||
@return (void)
|
||||
@context (all)
|
||||
*/
|
||||
void SetSpawnColor(const ZVector4f& _color);
|
||||
|
||||
/*
|
||||
public ZStandardParticleSpawnStrategy::SetSpawnEnergy
|
||||
|
||||
TODO
|
||||
|
||||
@param _energy -
|
||||
@return (void)
|
||||
@context (all)
|
||||
*/
|
||||
void SetSpawnEnergy(size_t _energy);
|
||||
|
||||
/*
|
||||
public ZStandardParticleSpawnStrategy::SetSpawnInterval
|
||||
|
||||
TODO
|
||||
|
||||
@param _interval -
|
||||
@return (void)
|
||||
@context (all)
|
||||
*/
|
||||
void SetSpawnInterval(size_t _interval);
|
||||
|
||||
/*
|
||||
public ZStandardParticleSpawnStrategy::SetSpawnScale
|
||||
|
||||
TODO
|
||||
|
||||
@param _scale -
|
||||
@return (void)
|
||||
@context (all)
|
||||
*/
|
||||
void SetSpawnScale(const ZVector2f& _scale);
|
||||
|
||||
/*
|
||||
public ZStandardParticleSpawnStrategy::SetDirection
|
||||
|
||||
TODO
|
||||
|
||||
@param _direction -
|
||||
@return (void)
|
||||
@context (all)
|
||||
*/
|
||||
void SetSpawnVelocity(const ZVector3f& _velocity);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
167
Include/ZRendererUtil/ZStandardParticleStorageAllocator.h
Normal file
167
Include/ZRendererUtil/ZStandardParticleStorageAllocator.h
Normal file
@@ -0,0 +1,167 @@
|
||||
/*
|
||||
ZStandardParticleStorageAllocator.h
|
||||
Author: James Russell <jcrussell@762studios.com>
|
||||
|
||||
Purpose: Standard particle type allocator. Stores particle data as an array of structs containing particle data.
|
||||
|
||||
Changelog
|
||||
2011/09/11 - creation (jcrussell)
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef _ZSTANDARDPARTICLESTORAGEALLOCATOR_H
|
||||
#define _ZSTANDARDPARTICLESTORAGEALLOCATOR_H
|
||||
|
||||
#include <ZRendererUtil/ZParticleStorageAllocator.h>
|
||||
|
||||
//Struct containing our per-particle data
|
||||
struct ZStandardParticle
|
||||
{
|
||||
//Particle mass (sign indicates charge)
|
||||
int Mass;
|
||||
|
||||
//Particle Energy (when zero or less, dead)
|
||||
int Energy;
|
||||
|
||||
//Particle Position (offset from emitter transform)
|
||||
ZVector3f Position;
|
||||
|
||||
//Particle Facing (only matters if not billboarding)
|
||||
ZVector3f Facing;
|
||||
|
||||
//Particle Velocity
|
||||
ZVector3f Velocity;
|
||||
|
||||
//Particle Scaling
|
||||
ZVector2f Scale;
|
||||
|
||||
//Particle Color (per vertex, includes alpha)
|
||||
// 3 --- 2
|
||||
// | |
|
||||
// 0 --- 1
|
||||
ZVector4f Color[4];
|
||||
|
||||
//Texture data (U, V, texture width and height)
|
||||
ZVector3f TextureData;
|
||||
|
||||
//Particle Id
|
||||
size_t Id;
|
||||
|
||||
//Default Constructor
|
||||
ZStandardParticle()
|
||||
: Mass(1), Energy(0),
|
||||
Position(0, 0, 0), Facing(0, 0, 0),
|
||||
Velocity(0, 0, 0), Scale(0, 0),
|
||||
TextureData(0, 0, 0), Id(0)
|
||||
{
|
||||
for (int i = 0; i < 4; ++i)
|
||||
{
|
||||
Color[i].Data[0] = 0;
|
||||
Color[i].Data[1] = 0;
|
||||
Color[i].Data[2] = 0;
|
||||
Color[i].Data[3] = 0;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
class ZStandardParticleStorageAllocator : public ZParticleStorageAllocator
|
||||
{
|
||||
protected:
|
||||
//The next inactive particle
|
||||
int NextInactive;
|
||||
|
||||
//The current particle group
|
||||
size_t CurrentGroup;
|
||||
|
||||
//The current particle within the current group
|
||||
size_t CurrentParticle;
|
||||
|
||||
//Array containing particle storage
|
||||
ZArray<ZStandardParticle> ParticleData;
|
||||
|
||||
//Array containing indices for particles that have been activated (must be cleared manually)
|
||||
ZArray<int> NewParticles;
|
||||
|
||||
public:
|
||||
/*
|
||||
Constructor.
|
||||
*/
|
||||
ZStandardParticleStorageAllocator();
|
||||
|
||||
/*
|
||||
Destructor.
|
||||
*/
|
||||
virtual ~ZStandardParticleStorageAllocator();
|
||||
|
||||
/*
|
||||
public ZStandardParticleStorageAllocator::ActivateParticle
|
||||
|
||||
Activates a particle contained in storage and returns the index of the activated particle. This
|
||||
sets the particle id.
|
||||
|
||||
@param _group - the group number this particle is being activated with
|
||||
@return (int) - index to the activated particle
|
||||
@context (all)
|
||||
*/
|
||||
int ActivateParticle(size_t _group);
|
||||
|
||||
/*
|
||||
public ZStandardParticleStorageAllocator::DeactivateParticle
|
||||
|
||||
Deactivates a particle given the index to the particle in storage.
|
||||
|
||||
@param _index - index to the particle in storage
|
||||
@return (void)
|
||||
@context (all)
|
||||
*/
|
||||
void DeactivateParticle(size_t _index);
|
||||
|
||||
/*
|
||||
public ZStandardParticleStorageAllocator::GetActiveParticleCount
|
||||
|
||||
Gets the number of currently active particles. So long as only the methods
|
||||
ActivateParticle and DeactivateParticle have been used, they are guaranteed
|
||||
to be sequential in the ParticleData array and starting at index 0.
|
||||
|
||||
@return (int) - number of active particles
|
||||
@context (all)
|
||||
*/
|
||||
int GetActiveParticleCount();
|
||||
|
||||
/*
|
||||
public ZStandardParticleStorageAllocator::GetParticleData
|
||||
|
||||
Gets a reference to the array containing particle data.
|
||||
|
||||
@return (ZArray<ZStandardParticle>&) - the particle data array
|
||||
@context (all)
|
||||
*/
|
||||
ZArray<ZStandardParticle>& GetParticleData();
|
||||
|
||||
/*
|
||||
public ZStandardParticleStorageAllocator::GetNewParticles
|
||||
|
||||
Gets an array containing indices that correspond to newly activated particles. Should be
|
||||
cleared by the spawn strategy when updated.
|
||||
|
||||
@return (ZArray<int>&) - list of indices to particles that have been activated
|
||||
@context (all)
|
||||
*/
|
||||
ZArray<int>& GetNewParticles();
|
||||
|
||||
//Subclass Override
|
||||
virtual void AllocateParticleStorage( ZParticleEmitter* _emitter, size_t _maxParticles );
|
||||
|
||||
//Subclass Override
|
||||
virtual void DeallocateParticleStorage();
|
||||
|
||||
//Subclass Override
|
||||
virtual ZString GetParticleFormat();
|
||||
|
||||
//Subclass Override
|
||||
virtual void Update(ZParticleEffect *_effect, ZParticleEmitter *_emitter, size_t _dt);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
97
Include/ZRendererUtil/ZStandardParticleUpdateStrategy.h
Normal file
97
Include/ZRendererUtil/ZStandardParticleUpdateStrategy.h
Normal file
@@ -0,0 +1,97 @@
|
||||
/*
|
||||
ZStandardParticleUpdateStrategy.h
|
||||
Author: James Russell <jcrussell@762studios.com>
|
||||
|
||||
Purpose: TODO
|
||||
|
||||
Changelog
|
||||
2011/09/11 - creation (jcrussell)
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef _ZSTANDARDPARTICLEUPDATESTRATEGY_H
|
||||
#define _ZSTANDARDPARTICLEUPDATESTRATEGY_H
|
||||
|
||||
#include <ZRendererUtil/ZParticleUpdateStrategy.h>
|
||||
|
||||
#define ZSP_DEFAULT_ENERGY_BLEED (1)
|
||||
#define ZSP_DEFAULT_ACCELERATION_X (0.0f)
|
||||
#define ZSP_DEFAULT_ACCELERATION_Y (0.0f)
|
||||
#define ZSP_DEFAULT_ACCELERATION_Z (0.5f)
|
||||
|
||||
class ZStandardParticleUpdateStrategy : public ZParticleUpdateStrategy
|
||||
{
|
||||
protected:
|
||||
//Acceleration Vector
|
||||
ZVector3f ParticleAcceleration;
|
||||
|
||||
//Energy drop per ms
|
||||
size_t EnergyBleed;
|
||||
|
||||
public:
|
||||
/*
|
||||
Default Constructor.
|
||||
*/
|
||||
ZStandardParticleUpdateStrategy();
|
||||
|
||||
/*
|
||||
Destructor.
|
||||
*/
|
||||
~ZStandardParticleUpdateStrategy();
|
||||
|
||||
/*
|
||||
public ZStandardParticleUpdateStrategy::GetEnergyBleed
|
||||
|
||||
TODO
|
||||
|
||||
@return (const size_t)
|
||||
@context (all)
|
||||
*/
|
||||
const size_t GetEnergyBleed();
|
||||
|
||||
/*
|
||||
public ZStandardParticleUpdateStrategy::GetParticleAcceleration
|
||||
|
||||
TODO
|
||||
|
||||
@return (const ZVector3f)
|
||||
@context (all)
|
||||
*/
|
||||
const ZVector3f GetParticleAcceleration();
|
||||
|
||||
/*
|
||||
public ZStandardParticleUpdateStrategy::SetEnergyBleed
|
||||
|
||||
TODO
|
||||
|
||||
@param _bleedRate -
|
||||
@return (void)
|
||||
@context (all)
|
||||
*/
|
||||
void SetEnergyBleed(size_t _bleedRate);
|
||||
|
||||
/*
|
||||
public ZStandardParticleUpdateStrategy::SetParticleAcceleration
|
||||
|
||||
TODO
|
||||
|
||||
@param _accel -
|
||||
@return (void)
|
||||
@context (all)
|
||||
*/
|
||||
void SetParticleAcceleration(const ZVector3f& _accel);
|
||||
|
||||
//Subclass Implementation
|
||||
virtual bool CheckParticleFormat( const ZString& _format );
|
||||
|
||||
//Subclass Implementation
|
||||
virtual void UpdateParticles(ZParticleEffect* _particleEffect,
|
||||
ZParticleEmitter* _particleEmitter,
|
||||
ZParticleStorageAllocator* _storageAllocator,
|
||||
size_t _dt );
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
134
Include/ZRendererUtil/ZStaticMesh.hpp
Normal file
134
Include/ZRendererUtil/ZStaticMesh.hpp
Normal file
@@ -0,0 +1,134 @@
|
||||
/*
|
||||
ZStaticMesh.h
|
||||
Author: Chris Ertel <crertel@762studios.com>
|
||||
|
||||
Purpose: Classes for holding static mesh data.
|
||||
|
||||
Changelog
|
||||
2011/09/18 - creation (crertel)
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef _ZSTATICMESH_H
|
||||
#define _ZSTATICMESH_H
|
||||
|
||||
#include <ZUtil/ZSmartPointer.hpp>
|
||||
#include <ZSTL/ZArray.hpp>
|
||||
#include <ZSTL/ZString.hpp>
|
||||
|
||||
typedef uint32_t ZSMFaceIndex;
|
||||
|
||||
typedef enum ZSMChannelType
|
||||
{
|
||||
ZSMCT_UNKNOWN = 0,
|
||||
|
||||
ZSMCT_BOOL = 0x11,
|
||||
ZSMCT_BOOL_VEC2 = 0x12,
|
||||
ZSMCT_BOOL_VEC3 = 0x13,
|
||||
ZSMCT_BOOL_VEC4 = 0x14,
|
||||
|
||||
ZSMCT_INT = 0x21,
|
||||
ZSMCT_INT_VEC2 = 0x22,
|
||||
ZSMCT_INT_VEC3 = 0x23,
|
||||
ZSMCT_INT_VEC4 = 0x24,
|
||||
|
||||
ZSMCT_UINT = 0x31,
|
||||
ZSMCT_UINT_VEC2 = 0x32,
|
||||
ZSMCT_UINT_VEC3 = 0x33,
|
||||
ZSMCT_UINT_VEC4 = 0x34,
|
||||
|
||||
ZSMCT_FLOAT = 0x41,
|
||||
ZSMCT_FLOAT_VEC2 = 0x42,
|
||||
ZSMCT_FLOAT_VEC3 = 0x43,
|
||||
ZSMCT_FLOAT_VEC4 = 0x44
|
||||
};
|
||||
|
||||
class ZSMChannelDefinition
|
||||
{
|
||||
protected:
|
||||
ZString Name;
|
||||
ZSMChannelType Datatype;
|
||||
uint32_t StartOffset;
|
||||
uint32_t Stride;
|
||||
|
||||
public:
|
||||
ZSMChannelDefinition( ZString _name, ZSMChannelType _datatype, uint32_t _offset, uint32_t _stride)
|
||||
: Name(_name), Datatype(_datatype), StartOffset(_offset), Stride(_stride)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
class ZStaticMeshMaterial
|
||||
{
|
||||
protected:
|
||||
ZString Name;
|
||||
ZArray< ZSMFaceIndex > FaceIndices;
|
||||
ZArray< ZPtr<ZSMChannelDefinition> > ChannelDefinitions;
|
||||
|
||||
public:
|
||||
ZStaticMeshMaterial(ZString _name, ZArray< ZSMFaceIndex> _faceIndices, ZArray< ZPtr<ZSMChannelDefinition> > _channelDefinitions)
|
||||
: Name(_name), FaceIndices(_faceIndices), ChannelDefinitions(_channelDefinitions)
|
||||
{
|
||||
}
|
||||
|
||||
/*
|
||||
public ZStaticMeshMaterial::GetName
|
||||
|
||||
Function to get the name of the material.
|
||||
|
||||
@return (ZString) - Name of the material.
|
||||
*/
|
||||
inline ZString GetName() { return this->Name; }
|
||||
|
||||
/*
|
||||
public ZStaticMeshMaterial::GetFaceIndices
|
||||
|
||||
Function to get the face indices for a material.
|
||||
|
||||
@return (ZArray<ZSMFaceIndex>) - Array of the face indices.
|
||||
*/
|
||||
inline ZArray<ZSMFaceIndex> GetFaceIndices() { return this->FaceIndices; }
|
||||
|
||||
/*
|
||||
public ZStaticMeshMaterial::GetChannelDefinitions
|
||||
|
||||
Function to get the vertex channel definiitions for this material.
|
||||
|
||||
@return (ZArray<ZSMChannelDefinition>) - Array of vertex channel definitions.
|
||||
*/
|
||||
inline ZArray< ZPtr<ZSMChannelDefinition> > GetChannelDefinitions() { return this->ChannelDefinitions; }
|
||||
};
|
||||
|
||||
class ZStaticMesh
|
||||
{
|
||||
protected:
|
||||
ZArray< ZPtr<ZStaticMeshMaterial> > MaterialGroups;
|
||||
ZPtr< ZArray< char > > VertexData;
|
||||
|
||||
public:
|
||||
ZStaticMesh(ZArray< ZPtr<ZStaticMeshMaterial> > _groups, ZPtr< ZArray< char > > _vertexData)
|
||||
: MaterialGroups(_groups), VertexData(_vertexData)
|
||||
{
|
||||
}
|
||||
|
||||
/*
|
||||
public ZStaticMesh::GetMaterialGroups
|
||||
|
||||
Function to get the material groups.
|
||||
|
||||
@return (ZArray<ZStaticMeshMaterialGroup>) - Material groups that make up the mesh.
|
||||
*/
|
||||
inline ZArray< ZPtr<ZStaticMeshMaterial> > GetMaterialGroups() { return this->MaterialGroups; }
|
||||
|
||||
/*
|
||||
public ZStaticMesh::GetVertexData
|
||||
|
||||
Function to get the vertex data.
|
||||
|
||||
@return (ZPtr< ZArray< char > >) - Vertex data for the mesh.
|
||||
*/
|
||||
inline ZPtr< ZArray< char > > GetVertexData() { return this->VertexData; }
|
||||
};
|
||||
|
||||
#endif
|
||||
27
Include/ZRendererUtil/ZStaticMeshLoader.hpp
Normal file
27
Include/ZRendererUtil/ZStaticMeshLoader.hpp
Normal file
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
ZStaticMeshLoader.h
|
||||
Author: Chris Ertel <crertel@762studios.com>
|
||||
|
||||
Purpose: File for loading ZStaticMeshes
|
||||
|
||||
Changelog
|
||||
2013/02/24 - Removed dependency on renderer.
|
||||
2011/09/25 - creation (crertel)
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef _ZSTATICMESHLOADER_H
|
||||
#define _ZSTATICMESHLOADER_H
|
||||
|
||||
#include <ZUtil/ZSmartPointer.hpp>
|
||||
#define ZSM_CURRENT_VERSION (4)
|
||||
|
||||
class ZStaticMesh;
|
||||
class ZStaticMeshLoader
|
||||
{
|
||||
public:
|
||||
static ZPtr<ZStaticMesh> loadFromMemory(const void* _memory, size_t _sizeInMemory);
|
||||
};
|
||||
|
||||
#endif
|
||||
100
Include/ZRendererUtil/ZTessellator.hpp
Normal file
100
Include/ZRendererUtil/ZTessellator.hpp
Normal file
@@ -0,0 +1,100 @@
|
||||
/*
|
||||
ZTessellator.h
|
||||
Author: Patrick Baggett <ptbaggett@762studios.com>
|
||||
|
||||
Purpose: Header for tessellator interface. (currently requires GLU)
|
||||
|
||||
Changelog
|
||||
2011/09/18 - creation (ptbaggett)
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef _ZTESSELLATOR_HPP
|
||||
#define _ZTESSELLATOR_HPP
|
||||
|
||||
#include <ZRendererUtil/ZOutlineEvaluator.hpp>
|
||||
|
||||
//Types of tessellations we can handle
|
||||
enum ZTesselatorPolyType
|
||||
{
|
||||
ZTPT_POLY_TRIANGLES,
|
||||
ZTPT_POLY_TRIFAN,
|
||||
ZTPT_POLY_TRISTRIP
|
||||
};
|
||||
|
||||
class ZTessellator
|
||||
{
|
||||
protected:
|
||||
//Protected Constructor
|
||||
ZTessellator() { }
|
||||
|
||||
public:
|
||||
//Virtual Destructor
|
||||
virtual ~ZTessellator() { }
|
||||
|
||||
/*
|
||||
virtual public ZTessellator::BeginPoly
|
||||
|
||||
TODO
|
||||
|
||||
@param type -
|
||||
@return (void)
|
||||
@context (all)
|
||||
*/
|
||||
virtual void BeginPoly(ZTesselatorPolyType type) = 0;
|
||||
|
||||
/*
|
||||
virtual public ZTessellator::BeginTessellate
|
||||
|
||||
TODO
|
||||
|
||||
@return (void)
|
||||
@context (all)
|
||||
*/
|
||||
virtual void BeginTessellate() = 0;
|
||||
|
||||
/*
|
||||
virtual public ZTessellator::EndPoly
|
||||
|
||||
TODO
|
||||
|
||||
@return (void)
|
||||
@context (all)
|
||||
*/
|
||||
virtual void EndPoly() = 0;
|
||||
|
||||
/*
|
||||
virtual public ZTessellator::EndTessellate
|
||||
|
||||
TODO
|
||||
|
||||
@return (void)
|
||||
@context (all)
|
||||
*/
|
||||
virtual void EndTessellate() = 0;
|
||||
|
||||
/*
|
||||
virtual public ZTessellator::Tessellate
|
||||
|
||||
TODO
|
||||
|
||||
@return (void)
|
||||
@context (all)
|
||||
*/
|
||||
virtual void Tesselate() = 0;
|
||||
|
||||
/*
|
||||
virtual public ZTessellator::Vertex
|
||||
|
||||
TODO
|
||||
|
||||
@param p -
|
||||
@return (void)
|
||||
@context (all)
|
||||
*/
|
||||
virtual void Vertex(SST_Vec2f* p) = 0;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
64
Include/ZRendererUtil/ZTessellatorBase.hpp
Normal file
64
Include/ZRendererUtil/ZTessellatorBase.hpp
Normal file
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
ZTessellatorBase.h
|
||||
Author: James Russell <jcrussell@762studios.com>
|
||||
|
||||
Purpose: TODO
|
||||
|
||||
Changelog
|
||||
2011/09/18 - creation (jcrussell)
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef _ZTESSELLATORBASE_HPP
|
||||
#define _ZTESSELLATORBASE_HPP
|
||||
|
||||
#include <ZRendererUtil/ZTessellator.hpp>
|
||||
|
||||
//#if WINDOWS
|
||||
#include <windows.h>
|
||||
//#endif
|
||||
|
||||
#include <GL/glu.h> //TODO: remove dependency on GLU for tessellation
|
||||
|
||||
class ZTessellatorBase : public ZTessellator
|
||||
{
|
||||
protected:
|
||||
//Outline Evaluator to use
|
||||
ZOutlineEvaluator* Evaluator;
|
||||
|
||||
//Tessellator (TODO: remove dependency on GLU)
|
||||
GLUtesselator *Tessellator;
|
||||
|
||||
public:
|
||||
/*
|
||||
Default Constructor.
|
||||
*/
|
||||
ZTessellatorBase(ZOutlineEvaluator* _eval);
|
||||
|
||||
/*
|
||||
Destructor.
|
||||
*/
|
||||
virtual ~ZTessellatorBase();
|
||||
|
||||
//Subclass Implementation
|
||||
virtual void Tesselate();
|
||||
|
||||
//Not Implemented
|
||||
virtual void BeginTessellate() = 0;
|
||||
|
||||
//Not Implemented
|
||||
virtual void EndTessellate() = 0;
|
||||
|
||||
//Not Implemented
|
||||
virtual void BeginPoly( ZTesselatorPolyType type ) = 0;
|
||||
|
||||
//Not Implemented
|
||||
virtual void EndPoly() = 0;
|
||||
|
||||
//Not Implemented
|
||||
virtual void Vertex( SST_Vec2f* p ) = 0;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
37
Include/ZRendererUtil/ZTransformHierarchy.hpp
Normal file
37
Include/ZRendererUtil/ZTransformHierarchy.hpp
Normal file
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
ZTransformHierarchy.h
|
||||
Author: Chris Ertel <crertel@762studios.com>
|
||||
|
||||
Purpose: Helper classes to setup a simple transform hierarchy.
|
||||
|
||||
Changelog
|
||||
2011/09/20 - creation (crertel)
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef _ZTRANSFORMHIERARCHY_H
|
||||
#define _ZTRANSFORMHIERARCHY_H
|
||||
|
||||
#include <ZUtil/ZSmartPointer.hpp>
|
||||
#include <ZSTL/ZArray.hpp>
|
||||
#include <ZUtil/ZMath.h>
|
||||
|
||||
class ZTransformHierarchy
|
||||
{
|
||||
protected:
|
||||
ZMatrix44f Transform;
|
||||
ZString Name;
|
||||
|
||||
ZArray Children;
|
||||
|
||||
public:
|
||||
ZTransformHierarchy();
|
||||
~ZTransformHierarchy();
|
||||
|
||||
|
||||
void Render(ZPtr<ZRenderer> _renderer, ZFrameContext _context, int _drawgroup, ZMatrix44f _transform, ZRenderState _renderState);
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
55
Include/ZRendererUtil/ZTriTessellator.hpp
Normal file
55
Include/ZRendererUtil/ZTriTessellator.hpp
Normal file
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
ZTriTessellator.h
|
||||
Author: Patrick Baggett <ptbaggett@762studios.com>
|
||||
Chris Ertel <crertel@762studios.com>
|
||||
|
||||
Purpose: Implementation of tessellator interface that tessellates into lists of triangles (unindexed)
|
||||
|
||||
Changelog
|
||||
2011/09/18 - creation (ptbaggett)
|
||||
2012/08/05 - Updated to use new SST functions.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef _ZTRITESSELLATOR_HPP
|
||||
#define _ZTRITESSELLATOR_HPP
|
||||
|
||||
#include <SST/SST_Vec2.h>
|
||||
|
||||
#include <ZRendererUtil/ZTessellatorBase.hpp>
|
||||
|
||||
class ZTriTessellator : public ZTessellatorBase
|
||||
{
|
||||
protected:
|
||||
//Our set of vertices
|
||||
ZArray<SST_Vec2f>& Vertices;
|
||||
|
||||
//Temporary use array
|
||||
ZArray<SST_Vec2f> Temp;
|
||||
|
||||
//Tessellation poly type
|
||||
ZTesselatorPolyType PolyType;
|
||||
|
||||
public:
|
||||
//Dumps a list of vertices into 'verts' when complete
|
||||
ZTriTessellator(ZOutlineEvaluator* _eval, ZArray<SST_Vec2f>& _verts);
|
||||
|
||||
//Subclass Implementation
|
||||
virtual void BeginTessellate();
|
||||
|
||||
//Subclass Implementation
|
||||
virtual void EndTessellate();
|
||||
|
||||
//Subclass Implementation
|
||||
virtual void BeginPoly(ZTesselatorPolyType _type);
|
||||
|
||||
//Subclass Implementation
|
||||
virtual void EndPoly();
|
||||
|
||||
//Subclass Implementation
|
||||
virtual void Vertex(SST_Vec2f* _p);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
379
Include/ZSimulation/ZEntity.hpp
Normal file
379
Include/ZSimulation/ZEntity.hpp
Normal file
@@ -0,0 +1,379 @@
|
||||
/*
|
||||
ZEntity.hpp
|
||||
Author: James Russell <jcrussell@762studios.com>
|
||||
Created: 2/5/2013
|
||||
|
||||
Purpose:
|
||||
|
||||
Entity class for the ZSimulation framework.
|
||||
|
||||
All objects affecting the simulation will exist as an entity. Entities can either
|
||||
be created with state or without state. Entities with and without state can
|
||||
be messaged by other entities within the simulation. Entities with state
|
||||
have their state function called once per tick, and this state function
|
||||
can modify the entity state, making the entity an autonomous state machine.
|
||||
|
||||
// ENTITY MESSAGING //
|
||||
|
||||
Entities are created in order to be processed in a threaded fashion. When
|
||||
entities have their current state function called, they should be expected to be
|
||||
able to process this in a thread-safe manner, able to call their own non-const methods
|
||||
but only able to affect other entities via messaging.
|
||||
|
||||
After the state functions are called, remaining messages are delivered to the entity
|
||||
'mailbox'. Any action that could mutate an entity that is not done from within the
|
||||
call to the state function must be handled via a message.
|
||||
|
||||
These delivered messages are then processed in a multi threaded manner, but each entity
|
||||
has it's messages processed serially, meaning that modifications can take place as per
|
||||
normal.
|
||||
|
||||
Entity messages are processed by deferring to the handler installed for a particular
|
||||
message type on an entity. If no message handler is installed for that message type
|
||||
on an entity, the message handler installed for that type on the simulation message
|
||||
stream will be called. If no message handler is installed there, the message is
|
||||
dropped.
|
||||
|
||||
// ENTITY PROPERTIES //
|
||||
|
||||
Entities hold their state via allocation into the simulation 'property buffer', which
|
||||
allows for contiguous space allocation for properties to be stored. The property
|
||||
buffer is a raw memory allocator and does not care what the underlying data actually
|
||||
is.
|
||||
|
||||
Entity properties can be allocated as 'local' or 'synchronized'. Data stored locally
|
||||
is not updated to other simulation instances. Data stored in a 'synchronized' state is
|
||||
mirrored to other simulation instances.
|
||||
|
||||
License:
|
||||
|
||||
Copyright 2013, 762 Studios
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef ZENTITY_HPP
|
||||
#define ZENTITY_HPP
|
||||
|
||||
#include <ZUtil/ZRandomGenerator.hpp>
|
||||
#include <ZUtil/ZName.hpp>
|
||||
|
||||
#include "ZSimulationDefs.hpp"
|
||||
#include "ZPropertyBuffer.hpp"
|
||||
#include "ZStringBuffer.hpp"
|
||||
|
||||
// forward decl
|
||||
class ZSimulation;
|
||||
struct ZMessage;
|
||||
|
||||
/*
|
||||
Entity class.
|
||||
*/
|
||||
class ZEntity
|
||||
{
|
||||
public:
|
||||
/*
|
||||
This is the entity state typedef, which corresponds to 'AI State'. The current think state
|
||||
is called once per simulation tick.
|
||||
|
||||
@param entity - the entity who is thinking
|
||||
@param sim - the running simulation
|
||||
@param dt - the time (expressed in seconds) since last call of this function
|
||||
*/
|
||||
typedef void (*StateFunc)(ZEntity& entity, const ZSimulation& sim, double dt);
|
||||
|
||||
/*
|
||||
This is the entity message handler typedef, which corresponds to 'Behavior'. If there is no message
|
||||
handler installed for a given message type, the default handler installed in the message queue
|
||||
is used.
|
||||
|
||||
@param entity - the entity receiving the message
|
||||
@param sim - the running simulation
|
||||
@param sender - the sending entity
|
||||
@param payload - the payload of the message
|
||||
*/
|
||||
typedef void (*MessageFunc)(ZEntity& entity, const ZSimulation& sim, eID sender, void* payload);
|
||||
|
||||
/*
|
||||
This is the entity initialization function typedef, which can be passed to the simulation to initialize
|
||||
the entity upon creation.
|
||||
|
||||
@param entity - the entity to initialize
|
||||
@param sim - the running simulation
|
||||
*/
|
||||
typedef void (*InitFunc)(ZEntity& entity, const ZSimulation& sim);
|
||||
|
||||
/*
|
||||
Entity property class. An ease of access class for reading and writing
|
||||
property data.
|
||||
|
||||
This class does not handle type coercion on read. Types will change when
|
||||
values are set.
|
||||
*/
|
||||
struct Property {
|
||||
|
||||
// we'll be using this a lot
|
||||
typedef ZStringBuffer::StringKey StringKey;
|
||||
|
||||
enum {
|
||||
BOOL, // boolean type
|
||||
INT, // integer type
|
||||
FLOAT, // floating point type
|
||||
DOUBLE, // double precision floating point type
|
||||
STRING, // string type (stored in string buffer or dynamic, limited size)
|
||||
VECTOR, // vector type (4 floating point values)
|
||||
MATRIX, // matrix type (16 floating point values)
|
||||
|
||||
NONE // untyped data
|
||||
|
||||
} Type; // the type of property
|
||||
|
||||
ZString LocalString; // local storage for strings
|
||||
uint8_t Local[64]; // local storage for simple types
|
||||
void* Data; // data for more complex types
|
||||
size_t Size; // size of data (in bytes)
|
||||
|
||||
// default constructor, which initializes an empty string
|
||||
Property();
|
||||
|
||||
// generic and array constructor, which takes data and size
|
||||
Property(void* data, size_t size);
|
||||
|
||||
// value constructors
|
||||
Property(const Property& other);
|
||||
Property(const bool val);
|
||||
Property(const int val);
|
||||
Property(const float val);
|
||||
Property(const double val);
|
||||
Property(const char* val); // checks to see if this string has a string key, if not makes a dynamic string
|
||||
Property(const StringKey val); // quicker method of directly creating a static string type
|
||||
Property(const SST_Vec4f& val);
|
||||
Property(const SST_Vec3f& val); // convenience for SST_Vec4f(x, y, z, 0.0)
|
||||
Property(const SST_Vec2f& val); // convenience for SST_Vec4f(x, y, 0.0, 0.0)
|
||||
Property(const SST_Mat44f& val);
|
||||
|
||||
// assignment operators
|
||||
Property& operator = (const Property& other);
|
||||
Property& operator = (const bool& val);
|
||||
Property& operator = (const int& val);
|
||||
Property& operator = (const float& val);
|
||||
Property& operator = (const double& al);
|
||||
Property& operator = (const char* val);
|
||||
Property& operator = (const StringKey val); // quicker method of using a static string type
|
||||
Property& operator = (const SST_Vec4f& val);
|
||||
Property& operator = (const SST_Vec3f& val); // convenience for SST_Vec4f(x, y, z, 0.0)
|
||||
Property& operator = (const SST_Vec2f& val); // convenience for SST_Vec4f(x, y, 0.0, 0.0)
|
||||
Property& operator = (const SST_Mat44f& val);
|
||||
|
||||
// cast operators
|
||||
operator bool () const;
|
||||
operator int () const;
|
||||
operator float () const;
|
||||
operator double () const;
|
||||
operator char* () const;
|
||||
operator bool* () const;
|
||||
operator int* () const;
|
||||
operator float* () const;
|
||||
operator double* () const;
|
||||
operator SST_Vec4f () const;
|
||||
operator SST_Vec3f () const; // gets [x, y, z] only
|
||||
operator SST_Vec2f () const; // gets [x, y] only
|
||||
operator SST_Mat44f () const;
|
||||
};
|
||||
|
||||
// c'tor
|
||||
ZEntity(eID entityId, ZSimulation& sim);
|
||||
|
||||
// parameterized c'tor (creates an actor)
|
||||
ZEntity(eID entityId, ZSimulation& sim, StateFunc startState);
|
||||
|
||||
// d'tor
|
||||
~ZEntity();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// Member Data Getter Functions
|
||||
|
||||
eID GetId() const;
|
||||
ZRandomGenerator& GetPRNG();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// Property Manipulation Functions
|
||||
|
||||
/*
|
||||
Property access functions. Used to create, remove, read, and write properties
|
||||
and their values.
|
||||
|
||||
The 'HasProperty' function will return true if the named property exists on
|
||||
this entity.
|
||||
|
||||
The 'CreateSyncProperty' functions is used to declare a synchronized property
|
||||
on this entity. Synchronized properties are automatically mirrored across
|
||||
the network system whenever a change is made. If the 'owner' boolean is
|
||||
set to true, modifications to the entity on this simulation are synchronized
|
||||
to other simulations. If the owner boolean is set to false, modifications
|
||||
are not synchronized, and the property will be updated periodically from
|
||||
other simulations. Only one simulation should be the owner of an entity,
|
||||
or they will update over each other.
|
||||
|
||||
The 'GetProperty' function will fill out a Property instance that references
|
||||
the read value of the named property. If the named property does not exist
|
||||
on this entity, the function will return false.
|
||||
|
||||
The 'SetProperty' function will set the write value of the property to be
|
||||
the value provided. If the named property does not exist, it will be created
|
||||
as a non-synchronized property. Note that the read value is not updated until
|
||||
the next simulation tick.
|
||||
|
||||
The 'EraseProperty' function will queue the property for removal at the end
|
||||
of this tick, which allows 'get' operations to function as normal until the
|
||||
next tick.
|
||||
|
||||
The template 'Get' function is a shortcut to directly get the value of
|
||||
a specific property. Note that if the property does not exist, this will
|
||||
return a default constructed property value.
|
||||
*/
|
||||
|
||||
bool HasProperty(const ZName& name) const;
|
||||
void CreateSyncProperty(const ZName& name, const Property& prop, bool owner);
|
||||
bool GetProperty(const ZName& name, Property& val) const;
|
||||
void SetProperty(const ZName& name, const Property& val);
|
||||
void EraseProperty(const ZName& name);
|
||||
|
||||
template <typename T>
|
||||
T Get(const ZName& name) const
|
||||
{ Property prop; GetProperty(name, prop); return (T)prop; }
|
||||
|
||||
template <typename T>
|
||||
void Set(const ZName& name, const T val)
|
||||
{ Property prop(val); SetProperty(name, prop); }
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/* State Management Functions */
|
||||
|
||||
/*
|
||||
State functions. Used to get information about the current state and
|
||||
manipulate the state stack, as well as call the current state function.
|
||||
|
||||
Push and Pop operate as you would expect for a state stack. The maximum
|
||||
number of states is defined by ZENT_STACK_SIZE.
|
||||
|
||||
SetState sets the current state to the given state, replacing it.
|
||||
|
||||
ResetState clears the state stack and sets the current state to be the
|
||||
provided one.
|
||||
*/
|
||||
|
||||
StateFunc GetCurrentState() const;
|
||||
double GetTimeInCurrentState() const;
|
||||
void PushState(StateFunc state);
|
||||
void PopState();
|
||||
void SetState(StateFunc state);
|
||||
void ResetState(StateFunc state);
|
||||
|
||||
/*
|
||||
State property stack manipulation functions. Used to read and write information
|
||||
to the state property stack, which can be used to pass transient information from
|
||||
one state function to another.
|
||||
*/
|
||||
|
||||
size_t GetStatePropertyCount() const;
|
||||
Property PopStateProperty();
|
||||
void PushStateProperty(const Property& prop);
|
||||
void ClearStatePropertyStack();
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/* Messaging Management Functions */
|
||||
|
||||
/*
|
||||
Messages, once posted to the message queue, can be 'delivered' to entities for
|
||||
sorting purposes to be later processed in a convenient fashion.
|
||||
|
||||
When processing delivered messages, order of delivery is maintained. Any
|
||||
messages that do not have a corresponding handler type installed will be
|
||||
handled by the handler installed in the message stream. If no corresponding
|
||||
handler is installed there, the message is dropped, and the simulation is
|
||||
notified.
|
||||
*/
|
||||
|
||||
void DeliverMessage(ZMessage* msg);
|
||||
void ProcessMessages();
|
||||
void PushMessageHandler(mID type, MessageFunc handler);
|
||||
void PopMessageHandler(mID type);
|
||||
void ClearMessageHandlers();
|
||||
|
||||
protected:
|
||||
/*
|
||||
Typedef for the property map used by ZEntity. It has a bucket size of 32, local
|
||||
storage for the buckets of 32, 10 local nodes for each hash-chain, 10 local storage
|
||||
for each property array, and will not resize based on load factor. Uses a 64-bit
|
||||
hash value.
|
||||
*/
|
||||
typedef ZHashMap<ZName, ZPropertyBuffer::Property, int64_t, ZHasher<ZName, int64_t>, 0> PropMap;
|
||||
|
||||
/*
|
||||
Stack used to indicate which properties have been modified since last swap of properties.
|
||||
*/
|
||||
typedef ZArray<ZPair<ZName, ZPropertyBuffer::Property>> PropModifiedStack;
|
||||
|
||||
/*
|
||||
Stack used to indicate which properties have been deleted since last swap of properties.
|
||||
*/
|
||||
typedef ZArray<ZName> PropDeletedStack;
|
||||
|
||||
/*
|
||||
Stack used for state properties, which can be used to send data from one state to another.
|
||||
*/
|
||||
typedef ZArray<Property> StatePropStack;
|
||||
|
||||
/*
|
||||
Buffer used as an entity mailbox - targeted messages are delivered here.
|
||||
*/
|
||||
typedef ZRingBuffer<ZMessage*> Mailbox;
|
||||
|
||||
/*
|
||||
Typedef for the handler map used by ZEntity, which maps message type to a
|
||||
stack of handlers. Only keeps two local nodes in the allocator, and will not
|
||||
resize based on load factor.
|
||||
*/
|
||||
typedef ZHashMap<mID, ZArray<MessageFunc>, int64_t, ZHasher<ZName, int64_t>, 0,
|
||||
ZListPooledAllocator<ZHashNode<mID, ZArray<MessageFunc>, int64_t>, 2 >> HandlerMap;
|
||||
|
||||
/* Member Data */
|
||||
ZSimulation& Sim; // the simulation running this thing
|
||||
const eID Id; // the id of the entity
|
||||
ZRandomGenerator PRNG; // entity PRNG, kept so there are no thread conflicts with PRNG access
|
||||
|
||||
/* Property Management */
|
||||
PropMap PropertyMap; // entity properties map
|
||||
PropModifiedStack PropertyModifiedStack; // properties that need to be mirrored into the read properties map
|
||||
PropDeletedStack PropertyDeletedStack; // properties have been deleted
|
||||
|
||||
/* State Management */
|
||||
int StateIndex; // index to our current state (-1 indicates no state)
|
||||
StateFunc StateStack[ZSIM_ENT_STATE_STACK_SIZE]; // stack of states (StateStack[StateIndex] is our current)
|
||||
StatePropStack StatePropertyStack; // stack of properties so that states can pass data to each other
|
||||
double StateTime; // amount of time we have spent in our current state
|
||||
|
||||
/* Message Management */
|
||||
Mailbox MessageMailbox; // entity 'Mailbox', which is where messages get delivered to
|
||||
HandlerMap MessageHandlers; // entity handlers, used to process received messages
|
||||
|
||||
private:
|
||||
friend class ZSimulation;
|
||||
friend class ActorTickTask;
|
||||
DISABLE_COPY_AND_ASSIGN(ZEntity);
|
||||
|
||||
// allocates a new property
|
||||
// TODO
|
||||
|
||||
// called by the simulation to tick the current state
|
||||
void StateTick(double dt);
|
||||
|
||||
// called by the simulation to dealloc properties
|
||||
void HandlePropertyDelete();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user