Merge remote-tracking branch 'origin/master' into cmake

This commit is contained in:
rdb 2016-12-07 23:05:40 +01:00
commit 8d305273dd
31 changed files with 497 additions and 319 deletions

View File

@ -38,7 +38,6 @@ import os
import sys
import random
import time
import importlib
__report_indent = 3
@ -61,6 +60,42 @@ def Functor(function, *args, **kArgs):
return functor
"""
try:
import importlib
except ImportError:
# Backward compatibility for Python 2.6.
def _resolve_name(name, package, level):
if not hasattr(package, 'rindex'):
raise ValueError("'package' not set to a string")
dot = len(package)
for x in xrange(level, 1, -1):
try:
dot = package.rindex('.', 0, dot)
except ValueError:
raise ValueError("attempted relative import beyond top-level "
"package")
return "%s.%s" % (package[:dot], name)
def import_module(name, package=None):
if name.startswith('.'):
if not package:
raise TypeError("relative imports require the 'package' argument")
level = 0
for character in name:
if character != '.':
break
level += 1
name = _resolve_name(name[level:], package, level)
__import__(name)
return sys.modules[name]
imp = import_module('imp')
importlib = imp.new_module("importlib")
importlib._resolve_name = _resolve_name
importlib.import_module = import_module
sys.modules['importlib'] = importlib
class Functor:
def __init__(self, function, *args, **kargs):
assert callable(function), "function should be a callable obj"

View File

@ -48,6 +48,8 @@ This issue fixes several bugs that were still found in 1.9.2.
* Fix exception when trying to pickle NodePathCollection objects
* Fix error when trying to raise vectors to a power
* GLSL: fix error when legacy matrix generator inputs are mat3
* Now tries to preserve refresh rate when switching fullscreen on Windows
* Fix back-to-front sorting when gl-coordinate-system is changed
------------------------ RELEASE 1.9.2 ------------------------

View File

@ -326,14 +326,17 @@ as_function_type() {
* This is similar to is_equal(), except it is more forgiving: it considers
* the functions to be equivalent only if the return type and the types of all
* parameters match.
*
* Note that this isn't symmetric to account for covariant return types.
*/
bool CPPFunctionType::
is_equivalent_function(const CPPFunctionType &other) const {
if (!_return_type->is_equivalent(*other._return_type)) {
match_virtual_override(const CPPFunctionType &other) const {
if (!_return_type->is_equivalent(*other._return_type) &&
!_return_type->is_convertible_to(other._return_type)) {
return false;
}
if (_flags != other._flags) {
if (((_flags ^ other._flags) & ~(F_override | F_final)) != 0) {
return false;
}

View File

@ -84,7 +84,7 @@ public:
virtual CPPFunctionType *as_function_type();
bool is_equivalent_function(const CPPFunctionType &other) const;
bool match_virtual_override(const CPPFunctionType &other) const;
CPPIdentifier *_class_owner;

View File

@ -1461,7 +1461,6 @@ handle_define_directive(const string &args, const YYLTYPE &loc) {
CPPManifest *other = result.first->second;
warning("redefinition of macro '" + manifest->_name + "'", loc);
warning("previous definition is here", other->_loc);
delete other;
result.first->second = manifest;
}
}
@ -1679,6 +1678,38 @@ handle_pragma_directive(const string &args, const YYLTYPE &loc) {
assert(it != _parsed_files.end());
it->_pragma_once = true;
}
char macro[64];
if (sscanf(args.c_str(), "push_macro ( \"%63[^\"]\" )", macro) == 1) {
// We just mark it as pushed for now, so that the next time someone tries
// to override it, we save the old value.
Manifests::iterator mi = _manifests.find(macro);
if (mi != _manifests.end()) {
_manifest_stack[macro].push_back(mi->second);
} else {
_manifest_stack[macro].push_back(NULL);
}
} else if (sscanf(args.c_str(), "pop_macro ( \"%63[^\"]\" )", macro) == 1) {
ManifestStack &stack = _manifest_stack[macro];
if (stack.size() > 0) {
CPPManifest *manifest = stack.back();
stack.pop_back();
Manifests::iterator mi = _manifests.find(macro);
if (manifest == NULL) {
// It was undefined when it was pushed, so make it undefined again.
if (mi != _manifests.end()) {
_manifests.erase(mi);
}
} else if (mi != _manifests.end()) {
mi->second = manifest;
} else {
_manifests.insert(Manifests::value_type(macro, manifest));
}
} else {
warning("pop_macro without matching push_macro", loc);
}
}
}
/**

View File

@ -72,6 +72,9 @@ public:
typedef map<string, CPPManifest *> Manifests;
Manifests _manifests;
typedef pvector<CPPManifest *> ManifestStack;
map<string, ManifestStack> _manifest_stack;
pvector<CPPFile::Source> _quote_include_kind;
DSearchPath _quote_include_path;
DSearchPath _angle_include_path;

View File

@ -378,6 +378,10 @@ is_constructible(const CPPType *given_type) const {
}
}
if (is_abstract()) {
return false;
}
// Check for a different constructor.
CPPFunctionGroup *fgroup = get_constructor();
if (fgroup != (CPPFunctionGroup *)NULL) {
@ -444,6 +448,10 @@ is_destructible() const {
*/
bool CPPStructType::
is_default_constructible(CPPVisibility min_vis) const {
if (is_abstract()) {
return false;
}
CPPInstance *constructor = get_default_constructor();
if (constructor != (CPPInstance *)NULL) {
// It has a default constructor.
@ -498,24 +506,6 @@ is_default_constructible(CPPVisibility min_vis) const {
}
}
// Check that we don't have pure virtual methods.
CPPScope::Functions::const_iterator fi;
for (fi = _scope->_functions.begin();
fi != _scope->_functions.end();
++fi) {
CPPFunctionGroup *fgroup = (*fi).second;
CPPFunctionGroup::Instances::const_iterator ii;
for (ii = fgroup->_instances.begin();
ii != fgroup->_instances.end();
++ii) {
CPPInstance *inst = (*ii);
if (inst->_storage_class & CPPInstance::SC_pure_virtual) {
// Here's a pure virtual function.
return false;
}
}
}
return true;
}
@ -524,6 +514,10 @@ is_default_constructible(CPPVisibility min_vis) const {
*/
bool CPPStructType::
is_copy_constructible(CPPVisibility min_vis) const {
if (is_abstract()) {
return false;
}
CPPInstance *constructor = get_copy_constructor();
if (constructor != (CPPInstance *)NULL) {
// It has a copy constructor.
@ -581,24 +575,6 @@ is_copy_constructible(CPPVisibility min_vis) const {
}
}
// Check that we don't have pure virtual methods.
CPPScope::Functions::const_iterator fi;
for (fi = _scope->_functions.begin();
fi != _scope->_functions.end();
++fi) {
CPPFunctionGroup *fgroup = (*fi).second;
CPPFunctionGroup::Instances::const_iterator ii;
for (ii = fgroup->_instances.begin();
ii != fgroup->_instances.end();
++ii) {
CPPInstance *inst = (*ii);
if (inst->_storage_class & CPPInstance::SC_pure_virtual) {
// Here's a pure virtual function.
return false;
}
}
}
return true;
}
@ -620,6 +596,10 @@ is_move_constructible(CPPVisibility min_vis) const {
return false;
}
if (is_abstract()) {
return false;
}
return true;
}
@ -1214,7 +1194,7 @@ get_virtual_funcs(VFunctions &funcs) const {
CPPFunctionType *new_ftype = new_inst->_type->as_function_type();
assert(new_ftype != (CPPFunctionType *)NULL);
if (new_ftype->is_equivalent_function(*base_ftype)) {
if (new_ftype->match_virtual_override(*base_ftype)) {
// It's a match! We now know it's virtual. Erase this function
// from the list, so we can add it back in below.
funcs.erase(vfi);

View File

@ -38,7 +38,6 @@ Filename(const char *filename) {
(*this) = filename;
}
/**
*
*/
@ -84,6 +83,20 @@ Filename(Filename &&from) NOEXCEPT :
}
#endif // USE_MOVE_SEMANTICS
/**
* Creates an empty Filename.
*/
INLINE Filename::
Filename() :
_dirname_end(0),
_basename_start(0),
_basename_end(string::npos),
_extension_start(string::npos),
_hash_start(string::npos),
_hash_end(string::npos),
_flags(0) {
}
/**
*
*/
@ -155,14 +168,6 @@ pattern_filename(const string &filename) {
return result;
}
/**
*
*/
INLINE Filename::
~Filename() {
}
/**
*
*/
@ -233,7 +238,7 @@ operator = (string &&filename) NOEXCEPT {
*/
INLINE Filename &Filename::
operator = (Filename &&from) NOEXCEPT {
_filename = MOVE(from._filename);
_filename = move(from._filename);
_dirname_end = from._dirname_end;
_basename_start = from._basename_start;
_basename_end = from._basename_end;

View File

@ -55,20 +55,22 @@ public:
};
INLINE Filename(const char *filename);
PUBLISHED:
INLINE Filename(const string &filename = "");
INLINE Filename(const string &filename);
INLINE Filename(const wstring &filename);
INLINE Filename(const Filename &copy);
Filename(const Filename &dirname, const Filename &basename);
INLINE ~Filename();
#ifdef USE_MOVE_SEMANTICS
INLINE Filename(string &&filename) NOEXCEPT;
INLINE Filename(Filename &&from) NOEXCEPT;
#endif
PUBLISHED:
INLINE Filename();
Filename(const Filename &dirname, const Filename &basename);
#ifdef HAVE_PYTHON
EXTENSION(Filename(PyObject *path));
EXTENSION(PyObject *__reduce__(PyObject *self) const);
#endif
@ -118,6 +120,7 @@ PUBLISHED:
INLINE char operator [] (size_t n) const;
EXTENSION(PyObject *__repr__() const);
EXTENSION(PyObject *__fspath__() const);
INLINE string substr(size_t begin) const;
INLINE string substr(size_t begin, size_t end) const;

View File

@ -6142,7 +6142,7 @@ pack_return_value(ostream &out, int indent_level, FunctionRemap *remap,
write_python_instance(out, indent_level, return_expr, owns_memory, itype, is_const);
}
} else if (TypeManager::is_struct(orig_type->as_pointer_type()->_pointing_at)) {
} else if (TypeManager::is_struct(orig_type->remove_pointer())) {
TypeIndex type_index = builder.get_type(TypeManager::unwrap(TypeManager::resolve_type(orig_type)),false);
const InterrogateType &itype = idb->get_type(type_index);
@ -6749,6 +6749,8 @@ is_cpp_type_legal(CPPType *in_ctype) {
return true;
} else if (TypeManager::is_pointer_to_simple(type)) {
return true;
} else if (builder.in_forcetype(type->get_local_name(&parser))) {
return true;
} else if (TypeManager::is_exported(type)) {
return true;
} else if (TypeManager::is_pointer_to_PyObject(in_ctype)) {

View File

@ -94,7 +94,6 @@ PkgListSet(["PYTHON", "DIRECT", # Python support
"PANDAPARTICLESYSTEM", # Built in particle system
"CONTRIB", # Experimental
"SSE2", "NEON", # Compiler features
"TOUCHINPUT", # Touchinput interface (requires Windows 7)
])
CheckPandaSourceTree()
@ -170,7 +169,8 @@ def parseopts(args):
"version=","lzma","no-python","threads=","outputdir=","override=",
"static","host=","debversion=","rpmrelease=","p3dsuffix=","rtdist-version=",
"directx-sdk=", "windows-sdk=", "msvc-version=", "clean", "use-icl",
"universal", "target=", "arch=", "git-commit="]
"universal", "target=", "arch=", "git-commit=",
"use-touchinput", "no-touchinput"]
anything = 0
optimize = ""
target = None
@ -316,18 +316,6 @@ def parseopts(args):
print("No Windows SDK version specified. Defaulting to '7.1'.")
WINDOWS_SDK = '7.1'
is_win7 = False
if sys.platform == 'win32':
# Note: not available in cygwin.
winver = sys.getwindowsversion()
if winver[0] >= 6 and winver[1] >= 1:
is_win7 = True
if RUNTIME or not is_win7:
PkgDisable("TOUCHINPUT")
else:
PkgDisable("TOUCHINPUT")
if clean_build and os.path.isdir(GetOutputDir()):
print("Deleting %s" % (GetOutputDir()))
shutil.rmtree(GetOutputDir())
@ -1055,14 +1043,11 @@ def CompileCxx(obj,src,opts):
cmd += "/favor:blend "
cmd += "/wd4996 /wd4275 /wd4273 "
# Enable Windows 7 interfaces if we need Touchinput.
if PkgSkip("TOUCHINPUT") == 0:
cmd += "/DWINVER=0x601 "
else:
cmd += "/DWINVER=0x501 "
# Work around a WinXP/2003 bug when using VS 2015+.
if SDK.get("VISUALSTUDIO_VERSION") == '14.0':
cmd += "/Zc:threadSafeInit- "
# We still target Windows XP.
cmd += "/DWINVER=0x501 "
# Work around a WinXP/2003 bug when using VS 2015+.
if SDK.get("VISUALSTUDIO_VERSION") == '14.0':
cmd += "/Zc:threadSafeInit- "
cmd += "/Fo" + obj + " /nologo /c"
if GetTargetArch() != 'x64' and (not PkgSkip("SSE2") or 'SSE2' in opts):
@ -1113,12 +1098,7 @@ def CompileCxx(obj,src,opts):
if GetTargetArch() == 'x64':
cmd += "/favor:blend "
cmd += "/wd4996 /wd4275 /wd4267 /wd4101 /wd4273 "
# Enable Windows 7 interfaces if we need Touchinput.
if PkgSkip("TOUCHINPUT") == 0:
cmd += "/DWINVER=0x601 "
else:
cmd += "/DWINVER=0x501 "
cmd += "/DWINVER=0x501 "
cmd += "/Fo" + obj + " /c"
for x in ipath: cmd += " /I" + x
for (opt,dir) in INCDIRECTORIES:
@ -1686,11 +1666,7 @@ def CompileLink(dll, obj, opts):
if 'NOARCH:' + arch.upper() not in opts:
cmd += " -arch %s" % arch
if "SYSROOT" in SDK:
cmd += " --sysroot=%s -no-canonical-prefixes" % (SDK["SYSROOT"])
# Android-specific flags.
if GetTarget() == 'android':
elif GetTarget() == 'android':
cmd += " -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now"
if GetTargetArch() == 'armv7a':
cmd += " -march=armv7-a -Wl,--fix-cortex-a8"
@ -1698,6 +1674,9 @@ def CompileLink(dll, obj, opts):
else:
cmd += " -pthread"
if "SYSROOT" in SDK:
cmd += " --sysroot=%s -no-canonical-prefixes" % (SDK["SYSROOT"])
if LDFLAGS != "":
cmd += " " + LDFLAGS
@ -2130,7 +2109,6 @@ DTOOL_CONFIG=[
("REPORT_OPENSSL_ERRORS", '1', '1'),
("USE_PANDAFILESTREAM", '1', '1'),
("USE_DELETED_CHAIN", '1', '1'),
("HAVE_WIN_TOUCHINPUT", 'UNDEF', 'UNDEF'),
("HAVE_GLX", 'UNDEF', '1'),
("HAVE_WGL", '1', 'UNDEF'),
("HAVE_DX9", 'UNDEF', 'UNDEF'),
@ -2237,11 +2215,7 @@ DTOOL_CONFIG=[
("HAVE_CG", 'UNDEF', 'UNDEF'),
("HAVE_CGGL", 'UNDEF', 'UNDEF'),
("HAVE_CGDX9", 'UNDEF', 'UNDEF'),
("HAVE_FFMPEG", 'UNDEF', 'UNDEF'),
("HAVE_SWSCALE", 'UNDEF', 'UNDEF'),
("HAVE_SWRESAMPLE", 'UNDEF', 'UNDEF'),
("HAVE_ARTOOLKIT", 'UNDEF', 'UNDEF'),
("HAVE_OPENCV", 'UNDEF', 'UNDEF'),
("HAVE_DIRECTCAM", 'UNDEF', 'UNDEF'),
("HAVE_SQUISH", 'UNDEF', 'UNDEF'),
("HAVE_CARBON", 'UNDEF', 'UNDEF'),
@ -2296,9 +2270,6 @@ def WriteConfigSettings():
else:
dtool_config["HAVE_"+x] = 'UNDEF'
if not PkgSkip("OPENCV"):
dtool_config["OPENCV_VER_23"] = '1' if OPENCV_VER_23 else 'UNDEF'
dtool_config["HAVE_NET"] = '1'
if (PkgSkip("NVIDIACG")==0):
@ -2355,9 +2326,6 @@ def WriteConfigSettings():
if (PkgSkip("PYTHON") != 0):
dtool_config["HAVE_ROCKET_PYTHON"] = 'UNDEF'
if (PkgSkip("TOUCHINPUT") == 0 and GetTarget() == "windows"):
dtool_config["HAVE_WIN_TOUCHINPUT"] = '1'
if (GetOptimize() <= 3):
dtool_config["HAVE_ROCKET_DEBUGGER"] = '1'
@ -4129,8 +4097,20 @@ if (not RUNTIME):
#
if (PkgSkip("VISION") == 0) and (not RUNTIME):
# We want to know whether we have ffmpeg so that we can override the .avi association.
if not PkgSkip("FFMPEG"):
DefSymbol("OPENCV", "HAVE_FFMPEG")
if not PkgSkip("OPENCV"):
DefSymbol("OPENCV", "HAVE_OPENCV")
if OPENCV_VER_23:
DefSymbol("OPENCV", "OPENCV_VER_23")
OPTS=['DIR:panda/src/vision', 'BUILDING:VISION', 'ARTOOLKIT', 'OPENCV', 'DX9', 'DIRECTCAM', 'JPEG', 'EXCEPTIONS']
TargetAdd('p3vision_composite1.obj', opts=OPTS, input='p3vision_composite1.cxx')
TargetAdd('p3vision_composite1.obj', opts=OPTS, input='p3vision_composite1.cxx', dep=[
'dtool_have_ffmpeg.dat',
'dtool_have_opencv.dat',
'dtool_have_directcam.dat',
])
TargetAdd('libp3vision.dll', input='p3vision_composite1.obj')
TargetAdd('libp3vision.dll', input=COMMON_PANDA_LIBS)
@ -4319,8 +4299,15 @@ if (PkgSkip("VRPN")==0 and not RUNTIME):
# DIRECTORY: panda/src/ffmpeg
#
if PkgSkip("FFMPEG") == 0 and not RUNTIME:
if not PkgSkip("SWSCALE"):
DefSymbol("FFMPEG", "HAVE_SWSCALE")
if not PkgSkip("SWRESAMPLE"):
DefSymbol("FFMPEG", "HAVE_SWRESAMPLE")
OPTS=['DIR:panda/src/ffmpeg', 'BUILDING:FFMPEG', 'FFMPEG', 'SWSCALE', 'SWRESAMPLE']
TargetAdd('p3ffmpeg_composite1.obj', opts=OPTS, input='p3ffmpeg_composite1.cxx')
TargetAdd('p3ffmpeg_composite1.obj', opts=OPTS, input='p3ffmpeg_composite1.cxx', dep=[
'dtool_have_swscale.dat', 'dtool_have_swresample.dat'])
TargetAdd('libp3ffmpeg.dll', input='p3ffmpeg_composite1.obj')
TargetAdd('libp3ffmpeg.dll', input=COMMON_PANDA_LIBS)
TargetAdd('libp3ffmpeg.dll', opts=OPTS)
@ -4600,7 +4587,7 @@ if (GetTarget() == 'darwin' and PkgSkip("COCOA")==0 and PkgSkip("GL")==0 and not
if (PkgSkip('PANDAFX')==0):
TargetAdd('libpandagl.dll', input='libpandafx.dll')
TargetAdd('libpandagl.dll', input=COMMON_PANDA_LIBS)
TargetAdd('libpandagl.dll', opts=['MODULE', 'GL', 'NVIDIACG', 'CGGL', 'COCOA'])
TargetAdd('libpandagl.dll', opts=['MODULE', 'GL', 'NVIDIACG', 'CGGL', 'COCOA', 'CARBON'])
#
# DIRECTORY: panda/src/osxdisplay/

View File

@ -396,10 +396,16 @@ def CrossCompiling():
return GetTarget() != GetHost()
def GetCC():
return os.environ.get('CC', TOOLCHAIN_PREFIX + 'gcc')
if TARGET == 'darwin':
return os.environ.get('CC', TOOLCHAIN_PREFIX + 'clang')
else:
return os.environ.get('CC', TOOLCHAIN_PREFIX + 'gcc')
def GetCXX():
return os.environ.get('CXX', TOOLCHAIN_PREFIX + 'g++')
if TARGET == 'darwin':
return os.environ.get('CXX', TOOLCHAIN_PREFIX + 'clang++')
else:
return os.environ.get('CXX', TOOLCHAIN_PREFIX + 'g++')
def GetStrip():
# Hack
@ -1996,6 +2002,11 @@ def SdkLocatePython(prefer_thirdparty_python=False):
SDK["PYTHONVERSION"] = "python" + ver
SDK["PYTHONEXEC"] = "/System/Library/Frameworks/Python.framework/Versions/" + ver + "/bin/python" + ver
# Avoid choosing the one in the thirdparty package dir.
PkgSetCustomLocation("PYTHON")
IncDirectory("PYTHON", py_fwx + "/include")
LibDirectory("PYTHON", "%s/usr/lib" % (SDK.get("MACOSX", "")))
if sys.version[:3] != ver:
print("Warning: building with Python %s instead of %s since you targeted a specific Mac OS X version." % (ver, sys.version[:3]))

View File

@ -147,6 +147,10 @@ GraphicsStateGuardian(CoordinateSystem internal_coordinate_system,
_coordinate_system = CS_invalid;
_internal_transform = TransformState::make_identity();
if (_internal_coordinate_system == CS_default) {
_internal_coordinate_system = get_default_coordinate_system();
}
set_coordinate_system(get_default_coordinate_system());
_data_reader = (GeomVertexDataPipelineReader *)NULL;

View File

@ -322,7 +322,7 @@ public:
virtual void set_state_and_transform(const RenderState *state,
const TransformState *transform);
virtual PN_stdfloat compute_distance_to(const LPoint3 &point) const;
PN_stdfloat compute_distance_to(const LPoint3 &point) const;
virtual void clear(DrawableRegion *clearable);

View File

@ -19,6 +19,16 @@
TypeHandle wdxGraphicsPipe9::_type_handle;
static bool MyGetProcAddr(HINSTANCE hDLL, FARPROC *pFn, const char *szExportedFnName) {
*pFn = (FARPROC) GetProcAddress(hDLL, szExportedFnName);
if (*pFn == NULL) {
wdxdisplay9_cat.error()
<< "GetProcAddr failed for " << szExportedFnName << ", error=" << GetLastError() <<endl;
return false;
}
return true;
}
#define LOWVIDMEMTHRESHOLD 5700000 // 4MB cards should fall below this
#define CRAPPY_DRIVER_IS_LYING_VIDMEMTHRESHOLD 1000000 // if # is > 1MB, card is lying and I cant tell what it is
#define UNKNOWN_VIDMEM_SIZE 0xFFFFFFFF
@ -154,7 +164,10 @@ make_output(const string &name,
*/
bool wdxGraphicsPipe9::
init() {
if (!MyLoadLib(_hDDrawDLL, "ddraw.dll")) {
_hDDrawDLL = LoadLibrary("ddraw.dll");
if (_hDDrawDLL == NULL) {
wdxdisplay9_cat.error()
<< "LoadLibrary failed for ddraw.dll, error=" << GetLastError() <<endl;
goto error;
}
@ -166,7 +179,10 @@ init() {
goto error;
}
if (!MyLoadLib(_hD3D9_DLL, "d3d9.dll")) {
_hD3D9_DLL = LoadLibrary("d3d9.dll");
if (_hD3D9_DLL == NULL) {
wdxdisplay9_cat.error()
<< "LoadLibrary failed for d3d9.dll, error=" << GetLastError() <<endl;
goto error;
}

View File

@ -14,6 +14,115 @@
#include "filename_ext.h"
#ifdef HAVE_PYTHON
#ifndef CPPPARSER
extern Dtool_PyTypedObject Dtool_Filename;
#endif // CPPPARSER
/**
* Constructs a Filename object from a str, bytes object, or os.PathLike.
*/
void Extension<Filename>::
__init__(PyObject *path) {
nassertv(path != NULL);
nassertv(_this != NULL);
Py_ssize_t length;
if (PyUnicode_CheckExact(path)) {
wchar_t *data;
#if PY_VERSION_HEX >= 0x03020000
data = PyUnicode_AsWideCharString(path, &length);
#else
length = PyUnicode_GET_SIZE(path);
data = (wchar_t *)alloca(sizeof(wchar_t) * (length + 1));
PyUnicode_AsWideChar((PyUnicodeObject *)path, data, length);
#endif
(*_this) = wstring(data, length);
#if PY_VERSION_HEX >= 0x03020000
PyMem_Free(data);
#endif
return;
}
if (PyBytes_CheckExact(path)) {
char *data;
PyBytes_AsStringAndSize(path, &data, &length);
(*_this) = string(data, length);
return;
}
if (Py_TYPE(path) == &Dtool_Filename._PyType) {
// Copy constructor.
(*_this) = *((Filename *)((Dtool_PyInstDef *)path)->_ptr_to_object);
return;
}
PyObject *path_str;
#if PY_VERSION_HEX >= 0x03060000
// It must be an os.PathLike object. Check for an __fspath__ method.
PyObject *fspath = PyObject_GetAttrString((PyObject *)Py_TYPE(path), "__fspath__");
if (fspath == NULL) {
PyErr_Format(PyExc_TypeError, "expected str, bytes or os.PathLike object, not %s", Py_TYPE(path)->tp_name);
return;
}
path_str = PyObject_CallFunctionObjArgs(fspath, path, NULL);
Py_DECREF(fspath);
#else
// There is no standard path protocol before Python 3.6, but let's try and
// support taking pathlib paths anyway. We don't version check this to
// allow people to use backports of the pathlib module.
if (PyObject_HasAttrString(path, "_format_parsed_parts")) {
path_str = PyObject_Str(path);
} else {
#if PY_VERSION_HEX >= 0x03040000
PyErr_Format(PyExc_TypeError, "expected str, bytes, Path or Filename object, not %s", Py_TYPE(path)->tp_name);
#elif PY_MAJOR_VERSION >= 3
PyErr_Format(PyExc_TypeError, "expected str, bytes or Filename object, not %s", Py_TYPE(path)->tp_name);
#else
PyErr_Format(PyExc_TypeError, "expected str or unicode object, not %s", Py_TYPE(path)->tp_name);
#endif
return;
}
#endif
if (path_str == NULL) {
return;
}
if (PyUnicode_CheckExact(path_str)) {
wchar_t *data;
#if PY_VERSION_HEX >= 0x03020000
data = PyUnicode_AsWideCharString(path_str, &length);
#else
length = PyUnicode_GET_SIZE(path_str);
data = (wchar_t *)alloca(sizeof(wchar_t) * (length + 1));
PyUnicode_AsWideChar((PyUnicodeObject *)path_str, data, length);
#endif
(*_this) = Filename::from_os_specific_w(wstring(data, length));
#if PY_VERSION_HEX >= 0x03020000
PyMem_Free(data);
#endif
} else if (PyBytes_CheckExact(path_str)) {
char *data;
PyBytes_AsStringAndSize(path_str, &data, &length);
(*_this) = Filename::from_os_specific(string(data, length));
} else {
#if PY_MAJOR_VERSION >= 3
PyErr_Format(PyExc_TypeError, "expected str or bytes object, not %s", Py_TYPE(path_str)->tp_name);
#else
PyErr_Format(PyExc_TypeError, "expected str or unicode object, not %s", Py_TYPE(path_str)->tp_name);
#endif
}
Py_DECREF(path_str);
}
/**
* This special Python method is implement to provide support for the pickle
* module.
@ -62,6 +171,16 @@ __repr__() const {
return result;
}
/**
* Allows a Filename object to be passed to any Python function that accepts
* an os.PathLike object.
*/
PyObject *Extension<Filename>::
__fspath__() const {
wstring filename = _this->to_os_specific_w();
return PyUnicode_FromWideChar(filename.data(), (Py_ssize_t)filename.size());
}
/**
* This variant on scan_directory returns a Python list of strings on success,
* or None on failure.

View File

@ -29,8 +29,11 @@
template<>
class Extension<Filename> : public ExtensionBase<Filename> {
public:
void __init__(PyObject *path);
PyObject *__reduce__(PyObject *self) const;
PyObject *__repr__() const;
PyObject *__fspath__() const;
PyObject *scan_directory() const;
};

View File

@ -50,9 +50,7 @@ FfmpegAudioCursor(FfmpegAudio *src) :
_packet_data(0),
_format_ctx(0),
_audio_ctx(0),
#ifdef HAVE_SWRESAMPLE
_resample_ctx(0),
#endif
_buffer(0),
_buffer_alloc(0),
_frame(0)

View File

@ -31,10 +31,7 @@ struct AVFormatContext;
struct AVCodecContext;
struct AVStream;
struct AVPacket;
#ifdef HAVE_SWRESAMPLE
struct SwrContext;
#endif
/**
* A stream that generates a sequence of audio samples.
@ -72,9 +69,7 @@ protected:
int _buffer_head;
int _buffer_tail;
#ifdef HAVE_SWRESAMPLE
SwrContext *_resample_ctx;
#endif
public:
static TypeHandle get_class_type() {

View File

@ -6024,16 +6024,6 @@ make_geom_munger(const RenderState *state, Thread *current_thread) {
return GeomMunger::register_munger(munger, current_thread);
}
/**
* This function will compute the distance to the indicated point, assumed to
* be in eye coordinates, from the camera plane. The point is assumed to be
* in the GSG's internal coordinate system.
*/
PN_stdfloat CLP(GraphicsStateGuardian)::
compute_distance_to(const LPoint3 &point) const {
return -point[2];
}
/**
* Copy the pixels within the indicated display region from the framebuffer
* into texture memory.
@ -6188,7 +6178,7 @@ framebuffer_copy_to_texture(Texture *tex, int view, int z,
if (GLCAT.is_spam()) {
GLCAT.spam()
<< "glBindTexture(0x" << hex << target << dec << ", " << gtc->_index << ")\n";
<< "glBindTexture(0x" << hex << target << dec << ", " << gtc->_index << "): " << *tex << "\n";
}
}
@ -11365,7 +11355,7 @@ apply_texture(CLP(TextureContext) *gtc) {
glBindTexture(target, gtc->_index);
if (GLCAT.is_spam()) {
GLCAT.spam()
<< "glBindTexture(0x" << hex << target << dec << ", " << gtc->_index << ")\n";
<< "glBindTexture(0x" << hex << target << dec << ", " << gtc->_index << "): " << *gtc->get_texture() << "\n";
}
report_my_gl_errors();
@ -11663,7 +11653,7 @@ upload_texture(CLP(TextureContext) *gtc, bool force, bool uses_mipmaps) {
if (GLCAT.is_spam()) {
GLCAT.spam()
<< "glBindTexture(0x" << hex << target << dec << ", " << gtc->_index << ")\n";
<< "glBindTexture(0x" << hex << target << dec << ", " << gtc->_index << "): " << *tex << "\n";
}
}
@ -12636,14 +12626,14 @@ do_extract_texture_data(CLP(TextureContext) *gtc) {
}
#endif
Texture *tex = gtc->get_texture();
glBindTexture(target, gtc->_index);
if (GLCAT.is_spam()) {
GLCAT.spam()
<< "glBindTexture(0x" << hex << target << dec << ", " << gtc->_index << ")\n";
<< "glBindTexture(0x" << hex << target << dec << ", " << gtc->_index << "): " << *tex << "\n";
}
Texture *tex = gtc->get_texture();
GLint wrap_u, wrap_v, wrap_w;
GLint minfilter, magfilter;
GLfloat border_color[4];

View File

@ -247,6 +247,7 @@ typedef void (APIENTRYP PFNGLVERTEXATTRIBL1UI64VPROC) (GLuint index, const GLuin
typedef void (APIENTRYP PFNGLGETVERTEXATTRIBLUI64VPROC) (GLuint index, GLenum pname, GLuint64EXT *params);
typedef void *(APIENTRYP PFNGLMAPBUFFERPROC) (GLenum target, GLenum access);
typedef GLboolean (APIENTRYP PFNGLUNMAPBUFFERPROC) (GLenum target);
typedef void (APIENTRYP PFNGLGETBUFFERSUBDATAPROC) (GLenum target, GLintptr offset, GLsizeiptr size, void *data);
#endif // OPENGLES
#endif // __EDG__
@ -357,8 +358,6 @@ public:
virtual PT(GeomMunger) make_geom_munger(const RenderState *state,
Thread *current_thread);
virtual PN_stdfloat compute_distance_to(const LPoint3 &point) const;
virtual void clear(DrawableRegion *region);
virtual bool framebuffer_copy_to_texture

View File

@ -2486,7 +2486,10 @@ update_shader_texture_bindings(ShaderContext *prev) {
bool has_write = param->has_write_access();
input._writable = has_write;
if (has_read && has_write) {
if (gl_force_image_bindings_writeonly) {
access = GL_WRITE_ONLY;
} else if (has_read && has_write) {
access = GL_READ_WRITE;
} else if (has_read) {

View File

@ -299,6 +299,11 @@ ConfigVariableBool gl_support_shadow_filter
"cards suffered from a broken implementation of the "
"shadow map filtering features."));
ConfigVariableBool gl_force_image_bindings_writeonly
("gl-force-image-bindings-writeonly", false,
PRC_DESC("Forces all image inputs (not textures!) to be bound as writeonly, "
"to read from an image, rebind it as sampler."));
ConfigVariableEnum<CoordinateSystem> gl_coordinate_system
("gl-coordinate-system", CS_yup_right,
PRC_DESC("Which coordinate system to use as the internal "

View File

@ -80,6 +80,7 @@ extern ConfigVariableBool gl_fixed_vertex_attrib_locations;
extern ConfigVariableBool gl_support_primitive_restart_index;
extern ConfigVariableBool gl_support_sampler_objects;
extern ConfigVariableBool gl_support_shadow_filter;
extern ConfigVariableBool gl_force_image_bindings_writeonly;
extern ConfigVariableEnum<CoordinateSystem> gl_coordinate_system;
extern EXPCL_GL void CLP(init_classes)();

View File

@ -10129,6 +10129,14 @@ do_fillin_body(CData *cdata, DatagramIterator &scan, BamReader *manager) {
cdata->_simple_image_date_generated = scan.get_int32();
size_t u_size = scan.get_uint32();
// Protect against large allocation.
if (u_size > scan.get_remaining_size()) {
gobj_cat.error()
<< "simple RAM image extends past end of datagram, is texture corrupt?\n";
return;
}
PTA_uchar image = PTA_uchar::empty_array(u_size, get_class_type());
scan.extract_bytes(image.p(), u_size);
@ -10183,6 +10191,14 @@ do_fillin_rawdata(CData *cdata, DatagramIterator &scan, BamReader *manager) {
// fill the cdata->_image buffer with image data
size_t u_size = scan.get_uint32();
// Protect against large allocation.
if (u_size > scan.get_remaining_size()) {
gobj_cat.error()
<< "RAM image " << n << " extends past end of datagram, is texture corrupt?\n";
return;
}
PTA_uchar image = PTA_uchar::empty_array(u_size, get_class_type());
scan.extract_bytes(image.p(), u_size);

View File

@ -21,6 +21,22 @@
#include "bamReader.h"
#include "bamCacheRecord.h"
// This symbol is predefined by the Panda3D build system to select whether we
// are using the OpenCV 2.3 or later interface, or if it is not defined, we
// are using the original interface.
#ifdef OPENCV_VER_23
#include <opencv2/core/core.hpp>
// #include <opencv2videovideo.hpp>
#include <opencv2/highgui/highgui.hpp>
#else
#include <cv.h>
#include <cxcore.h>
#include <highgui.h>
#endif // OPENCV_VER_23
TypeHandle OpenCVTexture::_type_handle;
/**

View File

@ -19,21 +19,7 @@
#include "videoTexture.h"
// This symbol is predefined by the Panda3D build system to select whether we
// are using the OpenCV 2.3 or later interface, or if it is not defined, we
// are using the original interface.
#ifdef OPENCV_VER_23
#include <opencv2/core/core.hpp>
// #include <opencv2videovideo.hpp>
#include <opencv2/highgui/highgui.hpp>
#else
#include <cv.h>
#include <cxcore.h>
#include <highgui.h>
#endif // OPENCV_VER_23
struct CvCapture;
/**
* A specialization on VideoTexture that takes its input using the CV library,

View File

@ -47,15 +47,12 @@ typedef struct _PROCESSOR_POWER_INFORMATION {
} PROCESSOR_POWER_INFORMATION, *PPROCESSOR_POWER_INFORMATION;
typedef BOOL (WINAPI *GetProcessMemoryInfoType) (HANDLE Process, PROCESS_MEMORY_COUNTERS *ppsmemCounters, DWORD cb);
typedef BOOL (WINAPI *GlobalMemoryStatusExType) (LPMEMORYSTATUSEX lpBuffer);
typedef long (__stdcall *CallNtPowerInformationType) (POWER_INFORMATION_LEVEL information_level, PVOID InputBuffer, ULONG InputBufferLength, PVOID OutputBuffer, ULONG OutputBufferLength);
static int initialize = false;
static HMODULE psapi_dll = 0;
static HMODULE kernel32_dll = 0;
static HMODULE power_dll = 0;
static GetProcessMemoryInfoType GetProcessMemoryInfoFunction = 0;
static GlobalMemoryStatusExType GlobalMemoryStatusExFunction = 0;
static CallNtPowerInformationType CallNtPowerInformationFunction = 0;
void get_memory_information (DisplayInformation *display_information) {
@ -65,39 +62,19 @@ void get_memory_information (DisplayInformation *display_information) {
GetProcessMemoryInfoFunction = (GetProcessMemoryInfoType) GetProcAddress(psapi_dll, "GetProcessMemoryInfo");
}
kernel32_dll = LoadLibrary("kernel32.dll");
if (kernel32_dll) {
GlobalMemoryStatusExFunction = (GlobalMemoryStatusExType) GetProcAddress(kernel32_dll, "GlobalMemoryStatusEx");
}
initialize = true;
}
if (GlobalMemoryStatusExFunction) {
MEMORYSTATUSEX memory_status;
MEMORYSTATUSEX memory_status;
memory_status.dwLength = sizeof(MEMORYSTATUSEX);
if (GlobalMemoryStatusExFunction(&memory_status)) {
display_information->_physical_memory = memory_status.ullTotalPhys;
display_information->_available_physical_memory = memory_status.ullAvailPhys;
display_information->_page_file_size = memory_status.ullTotalPageFile;
display_information->_available_page_file_size = memory_status.ullAvailPageFile;
display_information->_process_virtual_memory = memory_status.ullTotalVirtual;
display_information->_available_process_virtual_memory = memory_status.ullAvailVirtual;
display_information->_memory_load = memory_status.dwMemoryLoad;
}
} else {
MEMORYSTATUS memory_status;
memory_status.dwLength = sizeof(MEMORYSTATUS);
GlobalMemoryStatus (&memory_status);
display_information->_physical_memory = memory_status.dwTotalPhys;
display_information->_available_physical_memory = memory_status.dwAvailPhys;
display_information->_page_file_size = memory_status.dwTotalPageFile;
display_information->_available_page_file_size = memory_status.dwAvailPageFile;
display_information->_process_virtual_memory = memory_status.dwTotalVirtual;
display_information->_available_process_virtual_memory = memory_status.dwAvailVirtual;
memory_status.dwLength = sizeof(MEMORYSTATUSEX);
if (GlobalMemoryStatusEx(&memory_status)) {
display_information->_physical_memory = memory_status.ullTotalPhys;
display_information->_available_physical_memory = memory_status.ullAvailPhys;
display_information->_page_file_size = memory_status.ullTotalPageFile;
display_information->_available_page_file_size = memory_status.ullAvailPageFile;
display_information->_process_virtual_memory = memory_status.ullTotalVirtual;
display_information->_available_process_virtual_memory = memory_status.ullAvailVirtual;
display_information->_memory_load = memory_status.dwMemoryLoad;
}
@ -687,19 +664,12 @@ WinGraphicsPipe() {
_supported_types = OT_window | OT_fullscreen_window;
// these fns arent defined on win95, so get dynamic ptrs to them to avoid
// ugly DLL loader failures on w95
_pfnTrackMouseEvent = NULL;
_hUser32 = (HINSTANCE)LoadLibrary("user32.dll");
if (_hUser32 != NULL) {
_pfnTrackMouseEvent =
(PFN_TRACKMOUSEEVENT)GetProcAddress(_hUser32, "TrackMouseEvent");
HMODULE user32 = GetModuleHandleA("user32.dll");
if (user32 != NULL) {
if (dpi_aware) {
typedef HRESULT (WINAPI *PFN_SETPROCESSDPIAWARENESS)(Process_DPI_Awareness);
PFN_SETPROCESSDPIAWARENESS pfnSetProcessDpiAwareness =
(PFN_SETPROCESSDPIAWARENESS)GetProcAddress(_hUser32, "SetProcessDpiAwarenessInternal");
(PFN_SETPROCESSDPIAWARENESS)GetProcAddress(user32, "SetProcessDpiAwarenessInternal");
if (pfnSetProcessDpiAwareness == NULL) {
if (windisplay_cat.is_debug()) {
@ -908,26 +878,4 @@ lookup_cpu_data() {
*/
WinGraphicsPipe::
~WinGraphicsPipe() {
if (_hUser32 != NULL) {
FreeLibrary(_hUser32);
_hUser32 = NULL;
}
}
bool MyGetProcAddr(HINSTANCE hDLL, FARPROC *pFn, const char *szExportedFnName) {
*pFn = (FARPROC) GetProcAddress(hDLL, szExportedFnName);
if (*pFn == NULL) {
windisplay_cat.error() << "GetProcAddr failed for " << szExportedFnName << ", error=" << GetLastError() <<endl;
return false;
}
return true;
}
bool MyLoadLib(HINSTANCE &hDLL, const char *DLLname) {
hDLL = LoadLibrary(DLLname);
if(hDLL == NULL) {
windisplay_cat.error() << "LoadLibrary failed for " << DLLname << ", error=" << GetLastError() <<endl;
return false;
}
return true;
}

View File

@ -34,12 +34,6 @@ public:
virtual void lookup_cpu_data();
private:
HINSTANCE _hUser32;
typedef BOOL (WINAPI *PFN_TRACKMOUSEEVENT)(LPTRACKMOUSEEVENT);
PFN_TRACKMOUSEEVENT _pfnTrackMouseEvent;
public:
static TypeHandle get_class_type() {
return _type_handle;
@ -56,13 +50,8 @@ public:
private:
static TypeHandle _type_handle;
friend class WinGraphicsWindow;
};
extern EXPCL_PANDAWIN bool MyLoadLib(HINSTANCE &hDLL, const char *DLLname);
extern EXPCL_PANDAWIN bool MyGetProcAddr(HINSTANCE hDLL, FARPROC *pFn, const char *szExportedFnName);
#include "winGraphicsPipe.I"
#endif

View File

@ -29,6 +29,17 @@
#define WM_DPICHANGED 0x02E0
#endif
#ifndef WM_TOUCH
#define WM_TOUCH 0x0240
#endif
#if WINVER < 0x0601
// Not used on Windows XP, but we still need to define it.
#define TOUCH_COORD_TO_PIXEL(l) ((l) / 100)
DECLARE_HANDLE(HTOUCHINPUT);
#endif
TypeHandle WinGraphicsWindow::_type_handle;
TypeHandle WinGraphicsWindow::WinWindowHandle::_type_handle;
@ -56,22 +67,15 @@ int WinGraphicsWindow::_window_class_index = 0;
static const char * const errorbox_title = "Panda3D Error";
// These static variables contain pointers to the Raw Input functions, which
// These static variables contain pointers to the touch input functions, which
// are dynamically extracted from USER32.DLL
typedef WINUSERAPI BOOL (WINAPI *PFN_REGISTERTOUCHWINDOW)(IN HWND hWnd, IN ULONG ulFlags);
typedef WINUSERAPI BOOL (WINAPI *PFN_GETTOUCHINPUTINFO)(IN HTOUCHINPUT hTouchInput, IN UINT cInputs, OUT PTOUCHINPUT pInputs, IN int cbSize);
typedef WINUSERAPI BOOL (WINAPI *PFN_CLOSETOUCHINPUTHANDLE)(IN HTOUCHINPUT hTouchInput);
typedef WINUSERAPI UINT (WINAPI *tGetRawInputDeviceList)
(OUT PRAWINPUTDEVICELIST pRawInputDeviceList, IN OUT PUINT puiNumDevices, IN UINT cbSize);
typedef WINUSERAPI UINT(WINAPI *tGetRawInputData)
(IN HRAWINPUT hRawInput, IN UINT uiCommand, OUT LPVOID pData, IN OUT PUINT pcbSize, IN UINT cbSizeHeader);
typedef WINUSERAPI UINT(WINAPI *tGetRawInputDeviceInfoA)
(IN HANDLE hDevice, IN UINT uiCommand, OUT LPVOID pData, IN OUT PUINT pcbSize);
typedef WINUSERAPI BOOL (WINAPI *tRegisterRawInputDevices)
(IN PCRAWINPUTDEVICE pRawInputDevices, IN UINT uiNumDevices, IN UINT cbSize);
static tGetRawInputDeviceList pGetRawInputDeviceList;
static tGetRawInputData pGetRawInputData;
static tGetRawInputDeviceInfoA pGetRawInputDeviceInfoA;
static tRegisterRawInputDevices pRegisterRawInputDevices;
static PFN_REGISTERTOUCHWINDOW pRegisterTouchWindow = 0;
static PFN_GETTOUCHINPUTINFO pGetTouchInputInfo = 0;
static PFN_CLOSETOUCHINPUTHANDLE pCloseTouchInputHandle = 0;
/**
*
@ -100,9 +104,7 @@ WinGraphicsWindow(GraphicsEngine *engine, GraphicsPipe *pipe,
_lalt_down = false;
_ralt_down = false;
_hparent = NULL;
#ifdef HAVE_WIN_TOUCHINPUT
_numTouches = 0;
#endif
_num_touches = 0;
}
/**
@ -512,13 +514,13 @@ open_window() {
}
// Registers to receive the WM_INPUT messages
if ((pRegisterRawInputDevices)&&(_input_devices.size() > 1)) {
if (_input_devices.size() > 1) {
RAWINPUTDEVICE Rid;
Rid.usUsagePage = 0x01;
Rid.usUsage = 0x02;
Rid.dwFlags = 0;// RIDEV_NOLEGACY; // adds HID mouse and also ignores legacy mouse messages
Rid.hwndTarget = _hWnd;
pRegisterRawInputDevices(&Rid, 1, sizeof (Rid));
RegisterRawInputDevices(&Rid, 1, sizeof (Rid));
}
// Create a WindowHandle for ourselves
@ -535,10 +537,23 @@ open_window() {
// set us as the focus window for keyboard input
set_focus();
// Try initializing the touch function pointers.
static bool initialized = false;
if (!initialized) {
initialized = true;
HMODULE user32 = GetModuleHandleA("user32.dll");
if (user32) {
// Introduced in Windows 7.
pRegisterTouchWindow = (PFN_REGISTERTOUCHWINDOW)GetProcAddress(user32, "RegisterTouchWindow");
pGetTouchInputInfo = (PFN_GETTOUCHINPUTINFO)GetProcAddress(user32, "GetTouchInputInfo");
pCloseTouchInputHandle = (PFN_CLOSETOUCHINPUTHANDLE)GetProcAddress(user32, "CloseTouchInputHandle");
}
}
// Register for Win7 touch events.
#ifdef HAVE_WIN_TOUCHINPUT
RegisterTouchWindow(_hWnd, 0);
#endif
if (pRegisterTouchWindow != NULL) {
pRegisterTouchWindow(_hWnd, 0);
}
return true;
}
@ -563,45 +578,35 @@ initialize_input_devices() {
GraphicsWindowInputDevice::pointer_and_keyboard(this, "keyboard_mouse");
add_input_device(device);
// Try initializing the Raw Input function pointers.
if (pRegisterRawInputDevices==0) {
HMODULE user32 = LoadLibrary("user32.dll");
if (user32) {
pRegisterRawInputDevices = (tRegisterRawInputDevices)GetProcAddress(user32,"RegisterRawInputDevices");
pGetRawInputDeviceList = (tGetRawInputDeviceList) GetProcAddress(user32,"GetRawInputDeviceList");
pGetRawInputDeviceInfoA = (tGetRawInputDeviceInfoA) GetProcAddress(user32,"GetRawInputDeviceInfoA");
pGetRawInputData = (tGetRawInputData) GetProcAddress(user32,"GetRawInputData");
}
}
if (pRegisterRawInputDevices==0) return;
if (pGetRawInputDeviceList==0) return;
if (pGetRawInputDeviceInfoA==0) return;
if (pGetRawInputData==0) return;
// Get the number of devices.
if (pGetRawInputDeviceList(NULL, &nInputDevices, sizeof(RAWINPUTDEVICELIST)) != 0)
if (GetRawInputDeviceList(NULL, &nInputDevices, sizeof(RAWINPUTDEVICELIST)) != 0) {
return;
}
// Allocate the array to hold the DeviceList
pRawInputDeviceList = (PRAWINPUTDEVICELIST)alloca(sizeof(RAWINPUTDEVICELIST) * nInputDevices);
if (pRawInputDeviceList==0) return;
if (pRawInputDeviceList==0) {
return;
}
// Fill the Array
if (pGetRawInputDeviceList(pRawInputDeviceList, &nInputDevices, sizeof(RAWINPUTDEVICELIST)) == -1)
if (GetRawInputDeviceList(pRawInputDeviceList, &nInputDevices, sizeof(RAWINPUTDEVICELIST)) == -1) {
return;
}
// Loop through all raw devices and find the raw mice
for (int i = 0; i < (int)nInputDevices; i++) {
if (pRawInputDeviceList[i].dwType == RIM_TYPEMOUSE) {
// Fetch information about specified mouse device.
UINT nSize;
if (pGetRawInputDeviceInfoA(pRawInputDeviceList[i].hDevice, RIDI_DEVICENAME, (LPVOID)0, &nSize) != 0)
if (GetRawInputDeviceInfoA(pRawInputDeviceList[i].hDevice, RIDI_DEVICENAME, (LPVOID)0, &nSize) != 0) {
return;
}
char *psName = (char*)alloca(sizeof(TCHAR) * nSize);
if (psName == 0) return;
if (pGetRawInputDeviceInfoA(pRawInputDeviceList[i].hDevice, RIDI_DEVICENAME, (LPVOID)psName, &nSize) < 0)
if (GetRawInputDeviceInfoA(pRawInputDeviceList[i].hDevice, RIDI_DEVICENAME, (LPVOID)psName, &nSize) < 0) {
return;
}
// If it's not an RDP mouse, add it to the list of raw mice.
if (strncmp(psName,"\\??\\Root#RDP_MOU#0000#",22)!=0) {
@ -1215,31 +1220,25 @@ adjust_z_order(WindowProperties::ZOrder last_z_order,
*/
void WinGraphicsWindow::
track_mouse_leaving(HWND hwnd) {
// Note: could use _TrackMouseEvent in comctrl32.dll (part of IE 3.0+) which
// emulates TrackMouseEvent on w95, but that requires another 500K of memory
// to hold that DLL, which is lame just to support w95, which probably has
// other issues anyway
WinGraphicsPipe *winpipe;
DCAST_INTO_V(winpipe, _pipe);
if (winpipe->_pfnTrackMouseEvent != NULL) {
TRACKMOUSEEVENT tme = {
sizeof(TRACKMOUSEEVENT),
TME_LEAVE,
hwnd,
0
};
TRACKMOUSEEVENT tme = {
sizeof(TRACKMOUSEEVENT),
TME_LEAVE,
hwnd,
0
};
// tell win32 to post WM_MOUSELEAVE msgs
BOOL bSucceeded = winpipe->_pfnTrackMouseEvent(&tme);
// tell win32 to post WM_MOUSELEAVE msgs
BOOL bSucceeded = TrackMouseEvent(&tme);
if ((!bSucceeded) && windisplay_cat.is_debug()) {
windisplay_cat.debug()
<< "TrackMouseEvent failed!, LastError=" << GetLastError() << endl;
}
_tracking_mouse_leaving = true;
if (!bSucceeded && windisplay_cat.is_debug()) {
windisplay_cat.debug()
<< "TrackMouseEvent failed!, LastError=" << GetLastError() << endl;
}
_tracking_mouse_leaving = true;
}
/**
@ -2067,15 +2066,16 @@ window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) {
}
break;
#ifdef HAVE_WIN_TOUCHINPUT
case WM_TOUCH:
_numTouches = LOWORD(wparam);
if(_numTouches > MAX_TOUCHES)
_numTouches = MAX_TOUCHES;
GetTouchInputInfo((HTOUCHINPUT)lparam, _numTouches, _touches, sizeof(TOUCHINPUT));
CloseTouchInputHandle((HTOUCHINPUT)lparam);
_num_touches = LOWORD(wparam);
if (_num_touches > MAX_TOUCHES) {
_num_touches = MAX_TOUCHES;
}
if (pGetTouchInputInfo != 0) {
pGetTouchInputInfo((HTOUCHINPUT)lparam, _num_touches, _touches, sizeof(TOUCHINPUT));
pCloseTouchInputHandle((HTOUCHINPUT)lparam);
}
break;
#endif
}
// do custom messages processing if any has been set
@ -2229,7 +2229,15 @@ hide_or_show_cursor(bool hide_cursor) {
bool WinGraphicsWindow::
find_acceptable_display_mode(DWORD dwWidth, DWORD dwHeight, DWORD bpp,
DEVMODE &dm) {
// Get the current mode. We'll try to match the refresh rate.
DEVMODE cur_dm;
ZeroMemory(&cur_dm, sizeof(cur_dm));
cur_dm.dmSize = sizeof(cur_dm);
EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &cur_dm);
int modenum = 0;
int saved_modenum = -1;
while (1) {
ZeroMemory(&dm, sizeof(dm));
@ -2241,11 +2249,28 @@ find_acceptable_display_mode(DWORD dwWidth, DWORD dwHeight, DWORD bpp,
if ((dm.dmPelsWidth == dwWidth) && (dm.dmPelsHeight == dwHeight) &&
(dm.dmBitsPerPel == bpp)) {
return true;
// If this also matches in refresh rate, we're done here. Otherwise,
// save this as a second choice for later.
if (dm.dmDisplayFrequency == cur_dm.dmDisplayFrequency) {
return true;
} else if (saved_modenum == -1) {
saved_modenum = modenum;
}
}
modenum++;
}
// Failed to find an exact match, but we do have a match that didn't match
// the refresh rate.
if (saved_modenum != -1) {
ZeroMemory(&dm, sizeof(dm));
dm.dmSize = sizeof(dm);
if (EnumDisplaySettings(NULL, saved_modenum, &dm)) {
return true;
}
}
return false;
}
@ -2607,7 +2632,7 @@ handle_raw_input(HRAWINPUT hraw) {
if (hraw == 0) {
return;
}
if (pGetRawInputData(hraw, RID_INPUT, NULL, &dwSize, sizeof(RAWINPUTHEADER)) == -1) {
if (GetRawInputData(hraw, RID_INPUT, NULL, &dwSize, sizeof(RAWINPUTHEADER)) == -1) {
return;
}
@ -2616,7 +2641,7 @@ handle_raw_input(HRAWINPUT hraw) {
return;
}
if (pGetRawInputData(hraw, RID_INPUT, lpb, &dwSize, sizeof(RAWINPUTHEADER)) != dwSize) {
if (GetRawInputData(hraw, RID_INPUT, lpb, &dwSize, sizeof(RAWINPUTHEADER)) != dwSize) {
return;
}
@ -2973,12 +2998,8 @@ bool WinGraphicsWindow::supports_window_procs() const{
*
*/
bool WinGraphicsWindow::
is_touch_event(GraphicsWindowProcCallbackData* callbackData){
#ifdef HAVE_WIN_TOUCHINPUT
is_touch_event(GraphicsWindowProcCallbackData *callbackData) {
return callbackData->get_msg() == WM_TOUCH;
#else
return false;
#endif
}
/**
@ -2987,11 +3008,7 @@ is_touch_event(GraphicsWindowProcCallbackData* callbackData){
*/
int WinGraphicsWindow::
get_num_touches(){
#ifdef HAVE_WIN_TOUCHINPUT
return _numTouches;
#else
return 0;
#endif
return _num_touches;
}
/**
@ -2999,8 +3016,9 @@ get_num_touches(){
*
*/
TouchInfo WinGraphicsWindow::
get_touch_info(int index){
#ifdef HAVE_WIN_TOUCHINPUT
get_touch_info(int index) {
nassertr(index >= 0 && index < MAX_TOUCHES, TouchInfo());
TOUCHINPUT ti = _touches[index];
POINT point;
point.x = TOUCH_COORD_TO_PIXEL(ti.x);
@ -3013,7 +3031,4 @@ get_touch_info(int index){
ret.set_id(ti.dwID);
ret.set_flags(ti.dwFlags);
return ret;
#else
return TouchInfo();
#endif
}

View File

@ -34,8 +34,23 @@ typedef struct {
int y;
int width;
int height;
}
WINDOW_METRICS;
} WINDOW_METRICS;
#if WINVER < 0x0601
// Not used on Windows XP, but we still need to define it.
typedef struct tagTOUCHINPUT {
LONG x;
LONG y;
HANDLE hSource;
DWORD dwID;
DWORD dwFlags;
DWORD dwMask;
DWORD dwTime;
ULONG_PTR dwExtraInfo;
DWORD cxContact;
DWORD cyContact;
} TOUCHINPUT, *PTOUCHINPUT;
#endif
/**
* An abstract base class for glGraphicsWindow and dxGraphicsWindow (and, in
@ -177,10 +192,8 @@ private:
typedef pset<GraphicsWindowProc*> WinProcClasses;
WinProcClasses _window_proc_classes;
#ifdef HAVE_WIN_TOUCHINPUT
UINT _numTouches;
UINT _num_touches;
TOUCHINPUT _touches[MAX_TOUCHES];
#endif
private:
// We need this map to support per-window calls to window_proc().