Merge branch 'master' into astron-master

This commit is contained in:
Harvir 2015-07-20 00:36:16 -07:00
commit 41e4e2f905
25 changed files with 893 additions and 640 deletions

View File

@ -179,9 +179,9 @@ class GravityWalker(DirectObject.DirectObject):
# a higher or lower value depending on whether you want an avatar
# that is outside of the world to step up to the floor when they
# get under valid floor:
cRay = CollisionRay(0.0, 0.0, CollisionHandlerRayStart, 0.0, 0.0, -1.0)
self.cRay = CollisionRay(0.0, 0.0, CollisionHandlerRayStart, 0.0, 0.0, -1.0)
cRayNode = CollisionNode('GW.cRayNode')
cRayNode.addSolid(cRay)
cRayNode.addSolid(self.cRay)
self.cRayNodePath = self.avatarNodePath.attachNewNode(cRayNode)
cRayNode.setFromCollideMask(bitmask)
cRayNode.setIntoCollideMask(BitMask32.allOff())
@ -697,8 +697,4 @@ class GravityWalker(DirectObject.DirectObject):
# There are sometimes issues if the collision ray height is
# so tall that it collides with multiple levels of floors.
def setCollisionRayHeight(self, height):
oldNode = self.avatarNodePath.getNode(0)
cRayNode = oldNode.getChild(2)
cRayNode.removeSolid(0)
cRay = CollisionRay(0.0, 0.0, height, 0.0, 0.0, -1.0)
cRayNode.addSolid(cRay)
self.cRay.setOrigin(0.0, 0.0, height)

View File

@ -19,6 +19,7 @@
#include "cocoaPandaApp.h"
#include "config_cocoadisplay.h"
#include "frameBufferProperties.h"
#include "displayInformation.h"
#import <Foundation/NSAutoreleasePool.h>
#import <AppKit/NSApplication.h>

View File

@ -15,10 +15,52 @@
#include "graphicsStateGuardian.h"
#include "displayInformation.h"
////////////////////////////////////////////////////////////////////
// Function: DisplayMode::Comparison Operator
// Access: Published
// Description: Returns true if these two DisplayModes are identical.
////////////////////////////////////////////////////////////////////
bool DisplayMode::
operator == (const DisplayMode &other) const {
return (width == other.width && height == other.height &&
bits_per_pixel == other.bits_per_pixel &&
refresh_rate == other.refresh_rate &&
fullscreen_only == other.fullscreen_only);
}
////////////////////////////////////////////////////////////////////
// Function: DisplayMode::Comparison Operator
// Access: Published
// Description: Returns false if these two DisplayModes are identical.
////////////////////////////////////////////////////////////////////
bool DisplayMode::
operator != (const DisplayMode &other) const {
return !operator == (other);
}
////////////////////////////////////////////////////////////////////
// Function: DisplayMode::output
// Access: Published
// Description:
////////////////////////////////////////////////////////////////////
void DisplayMode::
output(ostream &out) const {
out << width << 'x' << height;
if (bits_per_pixel > 0) {
out << ' ' << bits_per_pixel << "bpp";
}
if (refresh_rate > 0) {
out << ' ' << refresh_rate << "Hz";
}
if (fullscreen_only > 0) {
out << " (fullscreen only)";
}
}
////////////////////////////////////////////////////////////////////
// Function: DisplayInformation::Destructor
// Access: Published
// Description:
// Description:
////////////////////////////////////////////////////////////////////
DisplayInformation::
~DisplayInformation() {
@ -48,13 +90,12 @@ DisplayInformation() {
int window_bits_per_pixel;
int total_display_modes;
DisplayMode *display_mode_array;
int shader_model;
int video_memory;
int texture_memory;
PN_uint64 physical_memory;
PN_uint64 available_physical_memory;
state = DisplayInformation::DS_unknown;
state = DisplayInformation::DS_unknown;
get_adapter_display_mode_state = false;
get_device_caps_state = false;
window_width = 0;
@ -62,7 +103,6 @@ DisplayInformation() {
window_bits_per_pixel = 0;
total_display_modes = 0;
display_mode_array = NULL;
shader_model = GraphicsStateGuardian::SM_00;
video_memory = 0;
texture_memory = 0;
physical_memory = 0;
@ -76,7 +116,7 @@ DisplayInformation() {
_window_bits_per_pixel = window_bits_per_pixel;
_total_display_modes = total_display_modes;
_display_mode_array = display_mode_array;
_shader_model = shader_model;
_shader_model = GraphicsStateGuardian::SM_00;
_video_memory = video_memory;
_texture_memory = texture_memory;
@ -181,6 +221,21 @@ get_total_display_modes() {
return _total_display_modes;
}
////////////////////////////////////////////////////////////////////
// Function: DisplayInformation::get_display_mode
// Access: Published
// Description:
////////////////////////////////////////////////////////////////////
const DisplayMode &DisplayInformation::
get_display_mode(int display_index) {
#ifndef NDEBUG
static DisplayMode err_mode = {0};
nassertr(display_index >= 0 && display_index < _total_display_modes, err_mode);
#endif
return _display_mode_array[display_index];
}
////////////////////////////////////////////////////////////////////
// Function: DisplayInformation::get_display_mode_width
// Access: Published
@ -271,8 +326,8 @@ get_display_mode_fullscreen_only (int display_index) {
// Access: Published
// Description:
////////////////////////////////////////////////////////////////////
int DisplayInformation::
get_shader_model ( ) {
GraphicsStateGuardian::ShaderModel DisplayInformation::
get_shader_model() {
return _shader_model;
}

View File

@ -16,30 +16,32 @@
#define DISPLAYINFORMATION_H
#include "typedef.h"
#include "graphicsStateGuardian.h"
typedef struct {
struct EXPCL_PANDA_DISPLAY DisplayMode {
PUBLISHED:
int width;
int height;
int bits_per_pixel;
int refresh_rate;
int fullscreen_only;
}
DisplayMode;
bool operator == (const DisplayMode &other) const;
bool operator != (const DisplayMode &other) const;
void output(ostream &out) const;
};
////////////////////////////////////////////////////////////////////
// Class : DisplayInformation
// Description : This class contains various display information.
////////////////////////////////////////////////////////////////////
class EXPCL_PANDA_DISPLAY DisplayInformation {
PUBLISHED:
enum DetectionState {
DS_unknown,
DS_success,
DS_unknown,
DS_success,
DS_direct_3d_create_error,
DS_direct_3d_create_error,
DS_create_window_error,
DS_create_device_error,
};
@ -54,13 +56,17 @@ PUBLISHED:
int get_window_bits_per_pixel();
int get_total_display_modes();
const DisplayMode &get_display_mode(int display_index);
MAKE_SEQ(get_display_modes, get_total_display_modes, get_display_mode);
// Older interface for display modes.
int get_display_mode_width(int display_index);
int get_display_mode_height(int display_index);
int get_display_mode_bits_per_pixel(int display_index);
int get_display_mode_refresh_rate(int display_index);
int get_display_mode_fullscreen_only(int display_index);
int get_shader_model();
GraphicsStateGuardian::ShaderModel get_shader_model();
int get_video_memory();
int get_texture_memory();
@ -121,9 +127,9 @@ public:
int _maximum_window_width;
int _maximum_window_height;
int _window_bits_per_pixel;
int _total_display_modes;
int _total_display_modes;
DisplayMode *_display_mode_array;
int _shader_model;
GraphicsStateGuardian::ShaderModel _shader_model;
int _video_memory;
int _texture_memory;

View File

@ -17,6 +17,7 @@
#include "graphicsBuffer.h"
#include "config_display.h"
#include "mutexHolder.h"
#include "displayInformation.h"
TypeHandle GraphicsPipe::_type_handle;

View File

@ -21,7 +21,6 @@
#include "typedReferenceCount.h"
#include "pointerTo.h"
#include "lightMutex.h"
#include "displayInformation.h"
class GraphicsEngine;
class GraphicsOutput;
@ -32,6 +31,7 @@ class FrameBufferProperties;
class WindowProperties;
class Texture;
class WindowHandle;
class DisplayInformation;
////////////////////////////////////////////////////////////////////
// Class : GraphicsPipe

View File

@ -876,7 +876,7 @@ get_maximum_simultaneous_render_targets() const {
// Access: Published
// Description: Returns the ShaderModel
////////////////////////////////////////////////////////////////////
INLINE int GraphicsStateGuardian::
INLINE GraphicsStateGuardian::ShaderModel GraphicsStateGuardian::
get_shader_model() const {
return _shader_model;
}
@ -889,7 +889,7 @@ get_shader_model() const {
// testing lower-end shaders.
////////////////////////////////////////////////////////////////////
INLINE void GraphicsStateGuardian::
set_shader_model(int shader_model) {
set_shader_model(ShaderModel shader_model) {
if (shader_model <= _auto_detect_shader_model) {
_shader_model = shader_model;
}

View File

@ -1190,14 +1190,26 @@ fetch_specified_part(Shader::ShaderMatInput part, InternalName *name,
}
return &t;
}
case Shader::SMO_texmat_x: {
const TexMatrixAttrib *tma = DCAST(TexMatrixAttrib, _target_rs->get_attrib_def(TexMatrixAttrib::get_class_slot()));
const TextureAttrib *ta = DCAST(TextureAttrib, _target_rs->get_attrib_def(TextureAttrib::get_class_slot()));
int stagenr = atoi(name->get_name().c_str());
if (stagenr >= ta->get_num_on_stages()) {
case Shader::SMO_texmat_i: {
const TexMatrixAttrib *tma;
const TextureAttrib *ta;
if (_target_rs->get_attrib(ta) && _target_rs->get_attrib(tma) &&
index < ta->get_num_on_stages()) {
return &tma->get_mat(ta->get_on_stage(index));
} else {
return &LMatrix4::ident_mat();
}
}
case Shader::SMO_inv_texmat_i: {
const TexMatrixAttrib *tma;
const TextureAttrib *ta;
if (_target_rs->get_attrib(ta) && _target_rs->get_attrib(tma) &&
index < ta->get_num_on_stages()) {
t = tma->get_transform(ta->get_on_stage(index))->get_inverse()->get_mat();
return &t;
} else {
return &LMatrix4::ident_mat();
}
return &tma->get_mat(ta->get_on_stage(stagenr));
}
case Shader::SMO_plane_x: {
const NodePath &np = _target_shader->get_shader_input_nodepath(name);
@ -3332,3 +3344,11 @@ int GraphicsStateGuardian::
get_driver_shader_version_minor() {
return -1;
}
ostream &
operator << (ostream &out, GraphicsStateGuardian::ShaderModel sm) {
static const char *sm_strings[] = {"none", "1.1", "2.0", "2.x", "3.0", "4.0", "5.0", "5.1"};
nassertr(sm >= 0 && sm <= GraphicsStateGuardian::SM_51, out);
out << sm_strings[sm];
return out;
}

View File

@ -83,6 +83,7 @@ PUBLISHED:
SM_30,
SM_40,
SM_50,
SM_51,
};
INLINE void release_all();
@ -166,8 +167,8 @@ PUBLISHED:
INLINE int get_max_color_targets() const;
INLINE int get_maximum_simultaneous_render_targets() const;
INLINE int get_shader_model() const;
INLINE void set_shader_model(int shader_model);
INLINE ShaderModel get_shader_model() const;
INLINE void set_shader_model(ShaderModel shader_model);
virtual int get_supported_geom_rendering() const;
virtual bool get_supports_cg_profile(const string &name) const;
@ -545,8 +546,8 @@ protected:
int _stereo_buffer_mask;
int _auto_detect_shader_model;
int _shader_model;
ShaderModel _auto_detect_shader_model;
ShaderModel _shader_model;
static PT(TextureStage) _alpha_scale_texture_stage;
@ -664,6 +665,8 @@ private:
friend class GraphicsEngine;
};
EXPCL_PANDA_DISPLAY ostream &operator << (ostream &out, GraphicsStateGuardian::ShaderModel sm);
#include "graphicsStateGuardian.I"
#endif

View File

@ -71,14 +71,17 @@ PointerToBase(PointerToBase<T> &&from) NOEXCEPT {
template<class T>
INLINE void PointerToBase<T>::
reassign(PointerToBase<T> &&from) NOEXCEPT {
To *old_ptr = (To *)this->_void_ptr;
// Protect against self-move-assignment.
if (from._void_ptr != this->_void_ptr) {
To *old_ptr = (To *)this->_void_ptr;
this->_void_ptr = from._void_ptr;
from._void_ptr = NULL;
this->_void_ptr = from._void_ptr;
from._void_ptr = NULL;
// Now delete the old pointer.
if (old_ptr != (To *)NULL) {
unref_delete(old_ptr);
// Now delete the old pointer.
if (old_ptr != (To *)NULL) {
unref_delete(old_ptr);
}
}
}
#endif // USE_MOVE_SEMANTICS

View File

@ -1062,6 +1062,7 @@ attach_tex(int layer, int view, Texture *attach, GLenum attachpoint) {
#ifndef OPENGLES
if (_rb_size_z != 1) {
// Bind all of the layers of the texture.
nassertv(glgsg->_glFramebufferTexture != NULL);
glgsg->_glFramebufferTexture(GL_FRAMEBUFFER_EXT, attachpoint,
gtc->_index, 0);
return;

View File

@ -64,6 +64,7 @@
#include "graphicsEngine.h"
#include "shaderGenerator.h"
#include "samplerState.h"
#include "displayInformation.h"
#if defined(HAVE_CG) && !defined(OPENGLES)
#include "Cg/cgGL.h"
@ -814,13 +815,22 @@ reset() {
_supports_2d_texture_array = false;
#ifndef OPENGLES
_supports_2d_texture_array = has_extension("GL_EXT_texture_array");
if (_supports_2d_texture_array) {
if (is_at_least_gl_version(3, 0)) {
_supports_2d_texture_array = true;
_glFramebufferTextureLayer = (PFNGLFRAMEBUFFERTEXTURELAYERPROC)
get_extension_func("glFramebufferTextureLayer");
} else if (has_extension("GL_EXT_texture_array")) {
_supports_2d_texture_array = true;
_glFramebufferTextureLayer = (PFNGLFRAMEBUFFERTEXTURELAYERPROC)
get_extension_func("glFramebufferTextureLayerEXT");
} else {
// ARB_geometry_shader4 also provides a version.
_glFramebufferTextureLayer = NULL;
}
if (_supports_2d_texture_array && _glFramebufferTextureLayer == NULL) {
GLCAT.warning()
<< "Texture arrays advertised as supported by OpenGL runtime, but could not get pointer to glFramebufferTextureLayer function.\n";
}
#endif
@ -1316,20 +1326,40 @@ reset() {
#endif // HAVE_CG
#ifdef OPENGLES_2
#if defined(OPENGLES_1)
_supports_glsl = false;
_supports_geometry_shaders = false;
_supports_tessellation_shaders = false;
#elif defined(OPENGLES)
_supports_glsl = true;
_supports_geometry_shaders = false;
_supports_tessellation_shaders = false;
#else
#ifdef OPENGLES_1
_supports_glsl = false;
_supports_glsl = is_at_least_gl_version(2, 0) || has_extension("GL_ARB_shading_language_100");
_supports_tessellation_shaders = is_at_least_gl_version(4, 0) || has_extension("GL_ARB_tessellation_shader");
if (is_at_least_gl_version(3, 2)) {
_supports_geometry_shaders = true;
_glFramebufferTexture = (PFNGLFRAMEBUFFERTEXTUREARBPROC)
get_extension_func("glFramebufferTexture");
} else if (has_extension("GL_ARB_geometry_shader4")) {
_supports_geometry_shaders = true;
_glFramebufferTexture = (PFNGLFRAMEBUFFERTEXTUREARBPROC)
get_extension_func("glFramebufferTextureARB");
_glProgramParameteri = (PFNGLPROGRAMPARAMETERIPROC)
get_extension_func("glProgramParameteriARB");
} else if (has_extension("GL_EXT_geometry_shader4")) {
_supports_geometry_shaders = true;
_glFramebufferTexture = NULL;
_glProgramParameteri = (PFNGLPROGRAMPARAMETERIPROC)
get_extension_func("glProgramParameteriEXT");
} else {
_supports_geometry_shaders = false;
_supports_tessellation_shaders = false;
#else
_supports_glsl = is_at_least_gl_version(2, 0) || has_extension("GL_ARB_shading_language_100");
_supports_geometry_shaders = is_at_least_gl_version(3, 2) || has_extension("GL_ARB_geometry_shader4");
_supports_tessellation_shaders = is_at_least_gl_version(4, 0) || has_extension("GL_ARB_tessellation_shader");
#endif
_glFramebufferTexture = NULL;
}
#endif
_shader_caps._supports_glsl = _supports_glsl;
@ -1435,17 +1465,6 @@ reset() {
_glVertexAttribLPointer = NULL;
}
if (_supports_geometry_shaders) {
_glProgramParameteri = (PFNGLPROGRAMPARAMETERIPROC)
get_extension_func("glProgramParameteri");
_glFramebufferTexture = (PFNGLFRAMEBUFFERTEXTUREARBPROC)
get_extension_func("glFramebufferTextureARB");
if (_glFramebufferTextureLayer == NULL) {
_glFramebufferTextureLayer = (PFNGLFRAMEBUFFERTEXTURELAYERPROC)
get_extension_func("glFramebufferTextureLayerARB");
}
}
if (_supports_tessellation_shaders) {
_glPatchParameteri = (PFNGLPATCHPARAMETERIPROC)
get_extension_func("glPatchParameteri");
@ -1611,7 +1630,7 @@ reset() {
_glDrawElementsInstanced = (PFNGLDRAWELEMENTSINSTANCEDPROC)
get_extension_func("glDrawElementsInstancedARB");
_supports_geometry_instancing = true;
} else if (has_extension("GL_EXT_draw_instanced")) {
_glDrawArraysInstanced = (PFNGLDRAWARRAYSINSTANCEDPROC)
get_extension_func("glDrawArraysInstancedEXT");
@ -2110,61 +2129,22 @@ reset() {
GLCAT.debug()
<< "No specific compressed texture formats are supported.\n";
} else {
#ifndef NDEBUG
GLCAT.debug()
<< "Supported compressed texture formats:\n";
GLint *formats = (GLint *)alloca(num_compressed_formats * sizeof(GLint));
glGetIntegerv(GL_COMPRESSED_TEXTURE_FORMATS, formats);
for (int i = 0; i < num_compressed_formats; ++i) {
switch (formats[i]) {
case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
GLCAT.debug(false) << " GL_COMPRESSED_RGB_S3TC_DXT1_EXT\n";
break;
case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
GLCAT.debug(false) << " GL_COMPRESSED_RGBA_S3TC_DXT1_EXT\n";
break;
#ifdef OPENGLES
case GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG:
GLCAT.debug(false) << " GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG\n";
break;
case GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG:
GLCAT.debug(false) << " GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG\n";
break;
case GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG:
GLCAT.debug(false) << " GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG\n";
break;
case GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG:
GLCAT.debug(false) << " GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG\n";
break;
#endif
#ifndef OPENGLES_1
case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT:
GLCAT.debug(false) << " GL_COMPRESSED_RGBA_S3TC_DXT3_EXT\n";
break;
case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT:
GLCAT.debug(false) << " GL_COMPRESSED_RGBA_S3TC_DXT5_EXT\n";
break;
#endif
#ifndef OPENGLES
case GL_COMPRESSED_RGB_FXT1_3DFX:
GLCAT.debug(false) << " GL_COMPRESSED_RGB_FXT1_3DFX\n";
break;
case GL_COMPRESSED_RGBA_FXT1_3DFX:
GLCAT.debug(false) << " GL_COMPRESSED_RGBA_FXT1_3DFX\n";
break;
#endif
default:
const char *format_str = get_compressed_format_string(formats[i]);
if (format_str != NULL) {
GLCAT.debug(false) << " " << format_str << '\n';
} else {
GLCAT.debug(false)
<< " Unknown compressed format 0x" << hex << formats[i]
<< dec << "\n";
}
}
#endif
}
}
}
@ -2290,8 +2270,10 @@ reset() {
if (is_at_least_gl_version(4, 1) || has_extension("GL_ARB_get_program_binary")) {
_glGetProgramBinary = (PFNGLGETPROGRAMBINARYPROC)
get_extension_func("glGetProgramBinary");
_glProgramParameteri = (PFNGLPROGRAMPARAMETERIPROC)
get_extension_func("glProgramParameteri");
if (_glGetProgramBinary != NULL) {
if (_glGetProgramBinary != NULL && _glProgramParameteri != NULL) {
_supports_get_program_binary = true;
}
}
@ -2469,58 +2451,39 @@ reset() {
report_my_gl_errors();
#if defined(HAVE_CG) && !defined(OPENGLES)
typedef struct {
CGprofile cg_profile;
int shader_model;
} CG_PROFILE_TO_SHADER_MODEL;
static CG_PROFILE_TO_SHADER_MODEL cg_profile_to_shader_model_array[] = {
#ifndef OPENGLES
if (_gl_shadlang_ver_major >= 4 || has_extension("GL_NV_gpu_program5")) {
// gp5fp - OpenGL fragment profile for GeForce 400 Series and up
(CGprofile)7017, /*CG_PROFILE_GP5FP,*/
SM_50,
_shader_model = SM_50;
} else if (_gl_shadlang_ver_major >= 3 ||
has_extension("GL_NV_gpu_program4")) {
// gp4fp - OpenGL fragment profile for G8x (GeForce 8xxx and up)
(CGprofile)7010, /*CG_PROFILE_GP4FP,*/
SM_40,
_shader_model = SM_40;
} else if (has_extension("GL_NV_fragment_program2")) {
// fp40 - OpenGL fragment profile for NV4x (GeForce 6xxx and 7xxx
// Series, NV4x-based Quadro FX, etc.)
CG_PROFILE_FP40,
SM_30,
_shader_model = SM_30;
} else if (has_extension("GL_NV_fragment_program")) {
// fp30 - OpenGL fragment profile for NV3x (GeForce FX, Quadro FX, etc.)
CG_PROFILE_FP30,
SM_2X,
_shader_model = SM_2X;
} else if (_gl_shadlang_ver_major >= 1 ||
has_extension("GL_ARB_fragment_program")) {
// This OpenGL profile corresponds to the per-fragment
// functionality introduced by GeForce FX and other DirectX 9
// GPUs.
CG_PROFILE_ARBFP1,
SM_20,
// functionality introduced by GeForce FX and other DirectX 9 GPUs.
_shader_model = SM_20;
} else if (has_extension("GL_NV_texture_shader2")) {
// fp20 - OpenGL fragment profile for NV2x (GeForce3, GeForce4 Ti,
// Quadro DCC, etc.)
CG_PROFILE_FP20,
SM_11,
_shader_model = SM_11;
// no shader support
CG_PROFILE_UNKNOWN,
SM_00,
};
int index;
CG_PROFILE_TO_SHADER_MODEL *cg_profile_to_shader_model;
index = 0;
cg_profile_to_shader_model = cg_profile_to_shader_model_array;
while (cg_profile_to_shader_model->shader_model != SM_00) {
if (cgGLIsProfileSupported(cg_profile_to_shader_model->cg_profile)) {
_shader_model = cg_profile_to_shader_model->shader_model;
break;
}
cg_profile_to_shader_model++;
} else {
// No shader support
_shader_model = SM_00;
}
// DisplayInformation may have better shader model detection
@ -2540,12 +2503,8 @@ reset() {
}
_auto_detect_shader_model = _shader_model;
CGprofile vertex_profile;
CGprofile pixel_profile;
vertex_profile = cgGLGetLatestProfile(CG_GL_VERTEX);
pixel_profile = cgGLGetLatestProfile(CG_GL_FRAGMENT);
if (GLCAT.is_debug()) {
#ifdef HAVE_CG
#if CG_VERSION_NUM >= 2200
GLCAT.debug() << "Supported Cg profiles:\n";
int num_profiles = cgGetNumSupportedProfiles();
@ -2558,22 +2517,25 @@ reset() {
#endif // CG_VERSION_NUM >= 2200
#if CG_VERSION_NUM >= 3100
if (GLCAT.is_debug()) {
CGGLglslversion ver = cgGLGetContextGLSLVersion(_cg_context);
GLCAT.debug()
<< "Cg GLSL version: " << cgGLGetGLSLVersionString(ver) << "\n";
}
#endif
CGGLglslversion ver = cgGLGetContextGLSLVersion(_cg_context);
GLCAT.debug()
<< "\nCg latest vertex profile = " << cgGetProfileString(vertex_profile) << " id = " << vertex_profile
<< "\nCg latest pixel profile = " << cgGetProfileString(pixel_profile) << " id = " << pixel_profile
<< "\nshader model = " << _shader_model
<< "\n";
}
<< "Cg GLSL version: " << cgGLGetGLSLVersionString(ver) << "\n";
#endif
CGprofile vertex_profile = cgGLGetLatestProfile(CG_GL_VERTEX);
CGprofile pixel_profile = cgGLGetLatestProfile(CG_GL_FRAGMENT);
GLCAT.debug()
<< "Cg latest vertex profile = " << cgGetProfileString(vertex_profile)
<< " (" << vertex_profile << ")\n";
GLCAT.debug()
<< "Cg latest pixel profile = " << cgGetProfileString(pixel_profile)
<< " (" << pixel_profile << ")\n";
#endif // HAVE_CG
GLCAT.debug() << "shader model = " << _shader_model << "\n";
}
#endif // !OPENGLES
// OpenGL core profile requires a VAO to be bound. It's a bit silly,
// because we can just bind a VAO and then forget about it.
#if !defined(OPENGLES)
@ -4778,8 +4740,8 @@ prepare_shader(Shader *se) {
return NULL;
}
#if defined(HAVE_CG) && !defined(OPENGLES)
case Shader::SL_Cg:
#if defined(HAVE_CG) && !defined(OPENGLES)
if (_supports_basic_shaders) {
result = new CLP(CgShaderContext)(this, se);
break;
@ -4788,6 +4750,10 @@ prepare_shader(Shader *se) {
<< "Tried to load Cg shader, but basic shaders not supported.\n";
return NULL;
}
#elif defined(OPENGLES)
GLCAT.error()
<< "Tried to load Cg shader, but Cg support is not available for OpenGL ES.\n";
return NULL;
#else
GLCAT.error()
<< "Tried to load Cg shader, but Cg support not compiled in.\n";
@ -6835,10 +6801,9 @@ show_gl_string(const string &name, GLenum id) {
const GLubyte *text = glGetString(id);
if (text == (const GLubyte *)NULL) {
if (GLCAT.is_debug()) {
GLCAT.debug()
<< "Unable to query " << name << "\n";
}
GLCAT.warning()
<< "Unable to query " << name << "\n";
} else {
result = (const char *)text;
if (GLCAT.is_debug()) {
@ -6859,20 +6824,60 @@ void CLP(GraphicsStateGuardian)::
query_gl_version() {
_gl_vendor = show_gl_string("GL_VENDOR", GL_VENDOR);
_gl_renderer = show_gl_string("GL_RENDERER", GL_RENDERER);
_gl_version = show_gl_string("GL_VERSION", GL_VERSION);
_gl_version_major = 0;
_gl_version_minor = 0;
// This is the most preposterous driver bug: NVIDIA drivers will claim
// that the version is 1.2 as long as the process is named pview.exe!
#ifndef OPENGLES
if (_gl_version.substr(0, 10) == "1.2 NVIDIA") {
Filename exec_name = ExecutionEnvironment::get_binary_name();
if (cmp_nocase(exec_name.get_basename(), "pview.exe") == 0) {
glGetIntegerv(GL_MAJOR_VERSION, &_gl_version_major);
glGetIntegerv(GL_MINOR_VERSION, &_gl_version_minor);
if (glGetError() == GL_INVALID_ENUM) {
_gl_version_major = 1;
_gl_version_minor = 2;
GLCAT.warning()
<< "Driver possibly misreported GL_VERSION! Unable to detect "
"correct OpenGL version.\n";
} else if (_gl_version_major != 1 || _gl_version_minor != 2) {
GLCAT.debug()
<< "Driver misreported GL_VERSION! Correct version detected as "
<< _gl_version_major << "." << _gl_version_minor << "\n";
}
return;
}
}
// If we asked for a GL 3 context, let's first try and see if we
// can use the OpenGL 3 way to query version.
if (gl_version.get_num_words() > 0 && gl_version[0] >= 3) {
glGetIntegerv(GL_MAJOR_VERSION, &_gl_version_major);
glGetIntegerv(GL_MINOR_VERSION, &_gl_version_minor);
if (_gl_version_major >= 1) {
// Fair enough, seems to check out.
if (GLCAT.is_debug()) {
GLCAT.debug()
<< "Detected OpenGL version: "
<< _gl_version_major << "." << _gl_version_minor << "\n";
}
return;
}
}
#endif // !OPENGLES
// Otherwise, parse the GL_VERSION string.
if (_gl_version.empty()) {
GLCAT.error() << "Unable to detect OpenGL version\n";
const GLubyte *text = glGetString(GL_VERSION);
if (text == (const GLubyte *)NULL) {
GLCAT.warning()
<< "Unable to query GL_VERSION\n";
} else {
string version((const char *)text);
_gl_version = version;
string input = version;
string input = _gl_version;
// Skip any initial words that don't begin with a digit.
while (!input.empty() && !isdigit(input[0])) {
@ -6904,7 +6909,7 @@ query_gl_version() {
if (GLCAT.is_debug()) {
GLCAT.debug()
<< "GL_VERSION = " << version << ", decoded to "
<< "GL_VERSION decoded to: "
<< _gl_version_major << "." << _gl_version_minor
<< "\n";
}
@ -6922,31 +6927,36 @@ query_glsl_version() {
_gl_shadlang_ver_minor = 0;
#ifndef OPENGLES
if (_gl_version_major == 1) {
if (has_extension("GL_ARB_shading_language_100")) {
_gl_shadlang_ver_major = 1;
_gl_shadlang_ver_minor = 0;
}
} else if (_gl_version_major >= 2) {
// OpenGL 2.0 introduces GLSL in the core. In 1.x, it is an extension.
if (_gl_version_major >= 2 || has_extension("GL_ARB_shading_language_100")) {
string ver = show_gl_string("GL_SHADING_LANGUAGE_VERSION", GL_SHADING_LANGUAGE_VERSION);
_gl_shadlang_ver_major = 1;
_gl_shadlang_ver_minor = 1;
const char *verstr = (const char *) glGetString(GL_SHADING_LANGUAGE_VERSION);
if (verstr == NULL ||
sscanf(verstr, "%d.%d", &_gl_shadlang_ver_major,
&_gl_shadlang_ver_minor) != 2) {
_gl_shadlang_ver_minor = (_gl_version_major >= 2) ? 1 : 0;
if (ver.empty() ||
sscanf(ver.c_str(), "%d.%d", &_gl_shadlang_ver_major,
&_gl_shadlang_ver_minor) != 2) {
GLCAT.warning() << "Invalid GL_SHADING_LANGUAGE_VERSION format.\n";
}
}
#elif defined(OPENGLES_2)
#elif !defined(OPENGLES_1)
// OpenGL ES 2.0 and above has shader support built-in.
string ver = show_gl_string("GL_SHADING_LANGUAGE_VERSION", GL_SHADING_LANGUAGE_VERSION);
_gl_shadlang_ver_major = 1;
_gl_shadlang_ver_minor = 0;
const char *verstr = (const char *) glGetString(GL_SHADING_LANGUAGE_VERSION);
if (verstr == NULL ||
sscanf(verstr, "OpenGL ES GLSL %d.%d", &_gl_shadlang_ver_major,
&_gl_shadlang_ver_minor) != 2) {
if (ver.empty() ||
sscanf(ver.c_str(), "OpenGL ES GLSL %d.%d", &_gl_shadlang_ver_major,
&_gl_shadlang_ver_minor) != 2) {
GLCAT.warning() << "Invalid GL_SHADING_LANGUAGE_VERSION format.\n";
}
#endif
#ifndef OPENGLES_1
if (GLCAT.is_debug()) {
GLCAT.debug()
<< "Detected GLSL version: "
<< _gl_shadlang_ver_major << "." << _gl_shadlang_ver_minor << "\n";
}
#endif
}
////////////////////////////////////////////////////////////////////
@ -6990,11 +7000,25 @@ get_extra_extensions() {
void CLP(GraphicsStateGuardian)::
report_extensions() const {
if (GLCAT.is_debug()) {
GLCAT.debug()
<< "GL Extensions:\n";
ostream &out = GLCAT.debug();
out << "GL Extensions:\n";
size_t maxlen = 0;
pset<string>::const_iterator ei;
for (ei = _extensions.begin(); ei != _extensions.end(); ++ei) {
GLCAT.debug() << (*ei) << "\n";
size_t len = (*ei).size();
out << " " << (*ei);
// Display a second column.
if (len <= 38) {
if (++ei != _extensions.end()) {
for (int i = len; i < 38; ++i) {
out.put(' ');
}
out << ' ' << (*ei);
}
}
out.put('\n');
}
}
}
@ -8742,6 +8766,125 @@ get_usage(Geom::UsageHint usage_hint) {
return GL_STATIC_DRAW;
}
////////////////////////////////////////////////////////////////////
// Function: GLGraphicsStateGuardian::get_compressed_format_string
// Access: Public, Static
// Description: Returns a string describing an compression format.
////////////////////////////////////////////////////////////////////
const char *CLP(GraphicsStateGuardian)::
get_compressed_format_string(GLenum format) {
switch (format) {
case 0x83F0: return "GL_COMPRESSED_RGB_S3TC_DXT1_EXT";
case 0x83F1: return "GL_COMPRESSED_RGBA_S3TC_DXT1_EXT";
case 0x83F2: return "GL_COMPRESSED_RGBA_S3TC_DXT3_EXT";
case 0x83F3: return "GL_COMPRESSED_RGBA_S3TC_DXT5_EXT";
case 0x86B0: return "GL_COMPRESSED_RGB_FXT1_3DFX";
case 0x86B1: return "GL_COMPRESSED_RGBA_FXT1_3DFX";
case 0x8A54: return "GL_COMPRESSED_SRGB_PVRTC_2BPPV1_EXT";
case 0x8A55: return "GL_COMPRESSED_SRGB_PVRTC_4BPPV1_EXT";
case 0x8A56: return "GL_COMPRESSED_SRGB_ALPHA_PVRTC_2BPPV1_EXT";
case 0x8A57: return "GL_COMPRESSED_SRGB_ALPHA_PVRTC_4BPPV1_EXT";
case 0x8B90: return "GL_PALETTE4_RGB8_OES";
case 0x8B91: return "GL_PALETTE4_RGBA8_OES";
case 0x8B92: return "GL_PALETTE4_R5_G6_B5_OES";
case 0x8B93: return "GL_PALETTE4_RGBA4_OES";
case 0x8B94: return "GL_PALETTE4_RGB5_A1_OES";
case 0x8B95: return "GL_PALETTE8_RGB8_OES";
case 0x8B96: return "GL_PALETTE8_RGBA8_OES";
case 0x8B97: return "GL_PALETTE8_R5_G6_B5_OES";
case 0x8B98: return "GL_PALETTE8_RGBA4_OES";
case 0x8B99: return "GL_PALETTE8_RGB5_A1_OES";
case 0x8C00: return "GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG";
case 0x8C01: return "GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG";
case 0x8C02: return "GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG";
case 0x8C03: return "GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG";
case 0x8C48: return "GL_COMPRESSED_SRGB_EXT";
case 0x8C49: return "GL_COMPRESSED_SRGB_ALPHA_EXT";
case 0x8C4A: return "GL_COMPRESSED_SLUMINANCE_EXT";
case 0x8C4B: return "GL_COMPRESSED_SLUMINANCE_ALPHA_EXT";
case 0x8C4C: return "GL_COMPRESSED_SRGB_S3TC_DXT1_EXT";
case 0x8C4D: return "GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT";
case 0x8C4E: return "GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT";
case 0x8C4F: return "GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT";
case 0x8C70: return "GL_COMPRESSED_LUMINANCE_LATC1_EXT";
case 0x8C71: return "GL_COMPRESSED_SIGNED_LUMINANCE_LATC1_EXT";
case 0x8C72: return "GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT";
case 0x8C73: return "GL_COMPRESSED_SIGNED_LUMINANCE_ALPHA_LATC2_EXT";
case 0x8DBB: return "GL_COMPRESSED_RED_RGTC1";
case 0x8DBC: return "GL_COMPRESSED_SIGNED_RED_RGTC1";
case 0x8DBD: return "GL_COMPRESSED_RG_RGTC2";
case 0x8DBE: return "GL_COMPRESSED_SIGNED_RG_RGTC2";
case 0x8E8C: return "GL_COMPRESSED_RGBA_BPTC_UNORM";
case 0x8E8D: return "GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM";
case 0x8E8E: return "GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT";
case 0x8E8F: return "GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT";
case 0x9137: return "GL_COMPRESSED_RGBA_PVRTC_2BPPV2_IMG";
case 0x9138: return "GL_COMPRESSED_RGBA_PVRTC_4BPPV2_IMG";
case 0x9270: return "GL_COMPRESSED_R11_EAC";
case 0x9271: return "GL_COMPRESSED_SIGNED_R11_EAC";
case 0x9272: return "GL_COMPRESSED_RG11_EAC";
case 0x9273: return "GL_COMPRESSED_SIGNED_RG11_EAC";
case 0x9274: return "GL_COMPRESSED_RGB8_ETC2";
case 0x9275: return "GL_COMPRESSED_SRGB8_ETC2";
case 0x9276: return "GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2";
case 0x9277: return "GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2";
case 0x9278: return "GL_COMPRESSED_RGBA8_ETC2_EAC";
case 0x9279: return "GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC";
case 0x93B0: return "GL_COMPRESSED_RGBA_ASTC_4x4_KHR";
case 0x93B1: return "GL_COMPRESSED_RGBA_ASTC_5x4_KHR";
case 0x93B2: return "GL_COMPRESSED_RGBA_ASTC_5x5_KHR";
case 0x93B3: return "GL_COMPRESSED_RGBA_ASTC_6x5_KHR";
case 0x93B4: return "GL_COMPRESSED_RGBA_ASTC_6x6_KHR";
case 0x93B5: return "GL_COMPRESSED_RGBA_ASTC_8x5_KHR";
case 0x93B6: return "GL_COMPRESSED_RGBA_ASTC_8x6_KHR";
case 0x93B7: return "GL_COMPRESSED_RGBA_ASTC_8x8_KHR";
case 0x93B8: return "GL_COMPRESSED_RGBA_ASTC_10x5_KHR";
case 0x93B9: return "GL_COMPRESSED_RGBA_ASTC_10x6_KHR";
case 0x93BA: return "GL_COMPRESSED_RGBA_ASTC_10x8_KHR";
case 0x93BB: return "GL_COMPRESSED_RGBA_ASTC_10x10_KHR";
case 0x93BC: return "GL_COMPRESSED_RGBA_ASTC_12x10_KHR";
case 0x93BD: return "GL_COMPRESSED_RGBA_ASTC_12x12_KHR";
case 0x93C0: return "GL_COMPRESSED_RGBA_ASTC_3x3x3_OES";
case 0x93C1: return "GL_COMPRESSED_RGBA_ASTC_4x3x3_OES";
case 0x93C2: return "GL_COMPRESSED_RGBA_ASTC_4x4x3_OES";
case 0x93C3: return "GL_COMPRESSED_RGBA_ASTC_4x4x4_OES";
case 0x93C4: return "GL_COMPRESSED_RGBA_ASTC_5x4x4_OES";
case 0x93C5: return "GL_COMPRESSED_RGBA_ASTC_5x5x4_OES";
case 0x93C6: return "GL_COMPRESSED_RGBA_ASTC_5x5x5_OES";
case 0x93C7: return "GL_COMPRESSED_RGBA_ASTC_6x5x5_OES";
case 0x93C8: return "GL_COMPRESSED_RGBA_ASTC_6x6x5_OES";
case 0x93C9: return "GL_COMPRESSED_RGBA_ASTC_6x6x6_OES";
case 0x93D0: return "GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR";
case 0x93D1: return "GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR";
case 0x93D2: return "GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR";
case 0x93D3: return "GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR";
case 0x93D4: return "GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR";
case 0x93D5: return "GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR";
case 0x93D6: return "GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR";
case 0x93D7: return "GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR";
case 0x93D8: return "GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR";
case 0x93D9: return "GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR";
case 0x93DA: return "GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR";
case 0x93DB: return "GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR";
case 0x93DC: return "GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR";
case 0x93DD: return "GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR";
case 0x93E0: return "GL_COMPRESSED_SRGB8_ALPHA8_ASTC_3x3x3_OES";
case 0x93E1: return "GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x3x3_OES";
case 0x93E2: return "GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4x3_OES";
case 0x93E3: return "GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4x4_OES";
case 0x93E4: return "GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4x4_OES";
case 0x93E5: return "GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5x4_OES";
case 0x93E6: return "GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5x5_OES";
case 0x93E7: return "GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5x5_OES";
case 0x93E8: return "GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6x5_OES";
case 0x93E9: return "GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6x6_OES";
case 0x93F0: return "GL_COMPRESSED_SRGB_ALPHA_PVRTC_2BPPV2_IMG";
case 0x93F1: return "GL_COMPRESSED_SRGB_ALPHA_PVRTC_4BPPV2_IMG";
default:
return NULL;
}
}
////////////////////////////////////////////////////////////////////
// Function: GLGraphicsStateGuardian::get_light_color
// Access: Public
@ -9217,7 +9360,6 @@ set_state_and_transform(const RenderState *target,
// If one of the previously-loaded TexGen modes modified the texture
// matrix, then if either state changed, we have to change both of
// them now.
#ifdef SUPPORT_FIXED_FUNCTION
if (_tex_gen_modifies_mat) {
int tex_gen_slot = TexGenAttrib::get_class_slot();
int tex_matrix_slot = TexMatrixAttrib::get_class_slot();
@ -9234,10 +9376,16 @@ set_state_and_transform(const RenderState *target,
if (_target_rs->get_attrib(tex_matrix_slot) != _state_rs->get_attrib(tex_matrix_slot) ||
!_state_mask.get_bit(tex_matrix_slot)) {
//PStatGPUTimer timer(this, _draw_set_state_tex_matrix_pcollector);
#ifdef SUPPORT_FIXED_FUNCTION
do_issue_tex_matrix();
_state_mask.set_bit(tex_matrix_slot);
}
#endif
_state_mask.set_bit(tex_matrix_slot);
#ifndef OPENGLES_1
if (_current_shader_context) {
_current_shader_context->issue_parameters(Shader::SSD_tex_matrix);
}
#endif
}
#ifdef SUPPORT_FIXED_FUNCTION
int tex_gen_slot = TexGenAttrib::get_class_slot();

View File

@ -511,6 +511,10 @@ protected:
static GLenum get_blend_func(ColorBlendAttrib::Operand operand);
static GLenum get_usage(Geom::UsageHint usage_hint);
#ifndef NDEBUG
static const char *get_compressed_format_string(GLenum format);
#endif
void unbind_buffers();
#ifdef SUPPORT_FIXED_FUNCTION
void disable_standard_vertex_arrays();

View File

@ -266,6 +266,8 @@ CLP(ShaderContext)(CLP(GraphicsStateGuardian) *glgsg, Shader *s) : ShaderContext
_color_attrib_index = -1;
_transform_table_index = -1;
_slider_table_index = -1;
_frame_number_loc = -1;
_frame_number = -1;
_validated = !gl_validate_shaders;
nassertv(s->get_language() == Shader::SL_GLSL);
@ -278,18 +280,29 @@ CLP(ShaderContext)(CLP(GraphicsStateGuardian) *glgsg, Shader *s) : ShaderContext
return;
}
// Create a buffer the size of the longest uniform name.
// Create a buffer the size of the longest uniform name. Note
// that Intel HD drivers report values that are too low.
GLint name_buflen = 0;
_glgsg->_glGetProgramiv(_glsl_program, GL_ACTIVE_UNIFORM_MAX_LENGTH, &name_buflen);
char* name_buffer = (char *)alloca(max(64, name_buflen));
name_buflen = max(64, name_buflen);
char *name_buffer = (char *)alloca(name_buflen);
#ifndef OPENGLES
// Get the used uniform blocks.
if (_glgsg->_supports_uniform_buffers) {
GLint block_count, block_maxlength;
GLint block_count = 0, block_maxlength = 0;
_glgsg->_glGetProgramiv(_glsl_program, GL_ACTIVE_UNIFORM_BLOCKS, &block_count);
_glgsg->_glGetProgramiv(_glsl_program, GL_ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH, &block_maxlength);
char *block_name_cstr = (char *)alloca(max(64, block_maxlength));
// Intel HD drivers report GL_INVALID_ENUM here. They reportedly
// fixed it, but I don't know in which driver version the fix is.
if (_glgsg->_gl_vendor != "Intel") {
_glgsg->_glGetProgramiv(_glsl_program, GL_ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH, &block_maxlength);
block_maxlength = max(64, block_maxlength);
} else {
block_maxlength = 1024;
}
char *block_name_cstr = (char *)alloca(block_maxlength);
for (int i = 0; i < block_count; ++i) {
block_name_cstr[0] = 0;
@ -317,7 +330,8 @@ CLP(ShaderContext)(CLP(GraphicsStateGuardian) *glgsg, Shader *s) : ShaderContext
// Now we've processed the uniforms, we'll process the attribs.
_glgsg->_glGetProgramiv(_glsl_program, GL_ACTIVE_ATTRIBUTES, &param_count);
_glgsg->_glGetProgramiv(_glsl_program, GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, &name_buflen);
name_buffer = (char *)alloca(max(64, name_buflen));
name_buflen = max(64, name_buflen);
name_buffer = (char *)alloca(name_buflen);
_shader->_var_spec.clear();
for (int i = 0; i < param_count; ++i) {
@ -688,12 +702,16 @@ reflect_uniform(int i, char *name_buffer, GLsizei name_buflen) {
} else {
bind._piece = Shader::SMP_transpose3x3;
}
} else {
} else if (param_type == GL_FLOAT_MAT4) {
if (transpose) {
bind._piece = Shader::SMP_transpose;
} else {
bind._piece = Shader::SMP_whole;
}
} else {
GLCAT.error()
<< "Matrix input p3d_" << matrix_name << " should be mat3 or mat4\n";
return;
}
bind._arg[0] = NULL;
bind._arg[1] = NULL;
@ -729,7 +747,7 @@ reflect_uniform(int i, char *name_buffer, GLsizei name_buflen) {
bind._part[1] = Shader::SMO_identity;
if (param_type != GL_FLOAT_MAT3) {
GLCAT.error() << "p3d_NormalMatrix input should be mat3, not mat4!\n";
GLCAT.warning() << "p3d_NormalMatrix input should be mat3, not mat4!\n";
}
} else if (matrix_name == "ModelMatrix") {
@ -759,6 +777,27 @@ reflect_uniform(int i, char *name_buffer, GLsizei name_buflen) {
bind._part[1] = Shader::SMO_view_to_apiclip;
}
} else if (matrix_name == "TextureMatrix") {
// We may support 2-D texmats later, but let's make sure that people
// don't think they can just use a mat3 to get the 2-D version.
if (param_type != GL_FLOAT_MAT4) {
GLCAT.error() << "p3d_TextureMatrix should be mat4[], not mat3[]!\n";
return;
}
bind._func = Shader::SMF_first;
bind._part[0] = inverse ? Shader::SMO_inv_texmat_i
: Shader::SMO_texmat_i;
bind._part[1] = Shader::SMO_identity;
bind._dep[0] = Shader::SSD_general | Shader::SSD_tex_matrix;
bind._dep[1] = 0;
// Add it once for each index.
for (bind._index = 0; bind._index < param_size; ++bind._index) {
_shader->_mat_spec.push_back(bind);
}
return;
} else {
GLCAT.error() << "Unrecognized uniform matrix name '" << matrix_name << "'!\n";
return;
@ -941,7 +980,7 @@ reflect_uniform(int i, char *name_buffer, GLsizei name_buflen) {
if (noprefix == "TransformTable") {
if (param_type != GL_FLOAT_MAT4) {
GLCAT.error()
<< "p3d_TransformTable should be uniform mat4\n";
<< "p3d_TransformTable should be uniform mat4[]\n";
return;
}
_transform_table_index = p;
@ -951,7 +990,7 @@ reflect_uniform(int i, char *name_buffer, GLsizei name_buflen) {
if (noprefix == "SliderTable") {
if (param_type != GL_FLOAT) {
GLCAT.error()
<< "p3d_SliderTable should be uniform float\n";
<< "p3d_SliderTable should be uniform float[]\n";
return;
}
_slider_table_index = p;
@ -965,8 +1004,6 @@ reflect_uniform(int i, char *name_buffer, GLsizei name_buflen) {
string noprefix(name_buffer + 4);
// These inputs are supported by OpenSceneGraph. We can support
// them as well, to increase compatibility.
// Other inputs we may support in the future:
// int osg_FrameNumber
Shader::ShaderMatSpec bind;
bind._id = arg_id;
@ -983,7 +1020,7 @@ reflect_uniform(int i, char *name_buffer, GLsizei name_buflen) {
_shader->_mat_spec.push_back(bind);
return;
} else if (noprefix == "InverseViewMatrix") {
} else if (noprefix == "InverseViewMatrix" || noprefix == "ViewMatrixInverse") {
bind._piece = Shader::SMP_whole;
bind._func = Shader::SMF_compose;
bind._part[0] = Shader::SMO_apiview_to_view;
@ -1012,6 +1049,16 @@ reflect_uniform(int i, char *name_buffer, GLsizei name_buflen) {
bind._dep[1] = Shader::SSD_NONE;
_shader->_mat_spec.push_back(bind);
return;
} else if (noprefix == "FrameNumber") {
// We don't currently support ints with this mechanism,
// so we special-case this one.
if (param_type != GL_INT) {
GLCAT.error() << "osg_FrameNumber should be uniform int\n";
} else {
_frame_number_loc = p;
}
return;
}
} else {
@ -1514,6 +1561,14 @@ issue_parameters(int altered) {
return;
}
if (_frame_number_loc != -1) {
int current_frame = ClockObject::get_global_clock()->get_frame_count();
if (current_frame != _frame_number) {
_glgsg->_glUniform1i(_frame_number_loc, current_frame);
_frame_number = current_frame;
}
}
// Iterate through _ptr parameters
for (int i = 0; i < (int)_shader->_ptr_spec.size(); ++i) {
Shader::ShaderPtrSpec &spec = _shader->_ptr_spec[i];
@ -1526,6 +1581,7 @@ issue_parameters(int altered) {
}
GLint p = spec._id._seqno;
int array_size = min(spec._dim[0], (int)ptr_data->_size / spec._dim[1]);
switch (spec._type) {
case Shader::SPT_float:
{
@ -1534,16 +1590,16 @@ issue_parameters(int altered) {
switch (ptr_data->_type) {
case Shader::SPT_int:
// Convert int data to float data.
data = (float*) alloca(sizeof(float) * spec._dim[0] * spec._dim[1]);
for (int i = 0; i < (spec._dim[0] * spec._dim[1]); ++i) {
data = (float*) alloca(sizeof(float) * array_size * spec._dim[1]);
for (int i = 0; i < (array_size * spec._dim[1]); ++i) {
data[i] = (float)(((int*)ptr_data->_ptr)[i]);
}
break;
case Shader::SPT_double:
// Downgrade double data to float data.
data = (float*) alloca(sizeof(float) * spec._dim[0] * spec._dim[1]);
for (int i = 0; i < (spec._dim[0] * spec._dim[1]); ++i) {
data = (float*) alloca(sizeof(float) * array_size * spec._dim[1]);
for (int i = 0; i < (array_size * spec._dim[1]); ++i) {
data[i] = (float)(((double*)ptr_data->_ptr)[i]);
}
break;
@ -1557,12 +1613,12 @@ issue_parameters(int altered) {
}
switch (spec._dim[1]) {
case 1: _glgsg->_glUniform1fv(p, spec._dim[0], (float*)data); continue;
case 2: _glgsg->_glUniform2fv(p, spec._dim[0], (float*)data); continue;
case 3: _glgsg->_glUniform3fv(p, spec._dim[0], (float*)data); continue;
case 4: _glgsg->_glUniform4fv(p, spec._dim[0], (float*)data); continue;
case 9: _glgsg->_glUniformMatrix3fv(p, spec._dim[0], GL_FALSE, (float*)data); continue;
case 16: _glgsg->_glUniformMatrix4fv(p, spec._dim[0], GL_FALSE, (float*)data); continue;
case 1: _glgsg->_glUniform1fv(p, array_size, (float*)data); continue;
case 2: _glgsg->_glUniform2fv(p, array_size, (float*)data); continue;
case 3: _glgsg->_glUniform3fv(p, array_size, (float*)data); continue;
case 4: _glgsg->_glUniform4fv(p, array_size, (float*)data); continue;
case 9: _glgsg->_glUniformMatrix3fv(p, array_size, GL_FALSE, (float*)data); continue;
case 16: _glgsg->_glUniformMatrix4fv(p, array_size, GL_FALSE, (float*)data); continue;
}
nassertd(false) continue;
}
@ -1579,10 +1635,10 @@ issue_parameters(int altered) {
} else {
switch (spec._dim[1]) {
case 1: _glgsg->_glUniform1iv(p, spec._dim[0], (int*)ptr_data->_ptr); continue;
case 2: _glgsg->_glUniform2iv(p, spec._dim[0], (int*)ptr_data->_ptr); continue;
case 3: _glgsg->_glUniform3iv(p, spec._dim[0], (int*)ptr_data->_ptr); continue;
case 4: _glgsg->_glUniform4iv(p, spec._dim[0], (int*)ptr_data->_ptr); continue;
case 1: _glgsg->_glUniform1iv(p, array_size, (int*)ptr_data->_ptr); continue;
case 2: _glgsg->_glUniform2iv(p, array_size, (int*)ptr_data->_ptr); continue;
case 3: _glgsg->_glUniform3iv(p, array_size, (int*)ptr_data->_ptr); continue;
case 4: _glgsg->_glUniform4iv(p, array_size, (int*)ptr_data->_ptr); continue;
}
nassertd(false) continue;
}
@ -2398,13 +2454,13 @@ glsl_compile_and_link() {
if (!_shader->get_text(Shader::ST_geometry).empty()) {
valid &= glsl_compile_shader(Shader::ST_geometry);
// Set the vertex output limit to the maximum.
// This is slow, but it is probably reasonable to require
// the user to override this in his shader using layout().
nassertr(_glgsg->_glProgramParameteri != NULL, false);
GLint max_vertices;
glGetIntegerv(GL_MAX_GEOMETRY_OUTPUT_VERTICES, &max_vertices);
_glgsg->_glProgramParameteri(_glsl_program, GL_GEOMETRY_VERTICES_OUT_ARB, max_vertices);
//XXX Actually, it turns out that this is unavailable in the core
// version of geometry shaders. Probably no need to bother with it.
//nassertr(_glgsg->_glProgramParameteri != NULL, false);
//GLint max_vertices;
//glGetIntegerv(GL_MAX_GEOMETRY_OUTPUT_VERTICES, &max_vertices);
//_glgsg->_glProgramParameteri(_glsl_program, GL_GEOMETRY_VERTICES_OUT_ARB, max_vertices);
}
#endif

View File

@ -80,6 +80,8 @@ private:
GLint _slider_table_index;
GLsizei _transform_table_size;
GLsizei _slider_table_size;
GLint _frame_number_loc;
GLint _frame_number;
pmap<GLint, GLuint64> _glsl_uniform_handles;
struct ImageInput {

View File

@ -452,6 +452,9 @@ cp_dependency(ShaderMatInput inp) {
(inp == SMO_apiview_clipplane_i)) {
dep |= SSD_clip_planes;
}
if (inp == SMO_texmat_i || inp == SMO_inv_texmat_i) {
dep |= SSD_tex_matrix;
}
return dep;
}
@ -1040,10 +1043,11 @@ compile_parameter(ShaderArgInfo &p, int *arg_dim) {
bind._id = p._id;
bind._piece = SMP_whole;
bind._func = SMF_first;
bind._part[0] = SMO_texmat_x;
bind._arg[0] = InternalName::make(pieces[1]);
bind._part[0] = SMO_texmat_i;
bind._arg[0] = NULL;
bind._part[1] = SMO_identity;
bind._arg[1] = NULL;
bind._index = atoi(pieces[1].c_str());
cp_optimize_mat_spec(bind);
_mat_spec.push_back(bind);

View File

@ -132,7 +132,7 @@ public:
SMO_plight_x,
SMO_slight_x,
SMO_satten_x,
SMO_texmat_x,
SMO_texmat_i,
SMO_plane_x,
SMO_clipplane_x,
@ -191,6 +191,8 @@ public:
SMO_apiview_to_apiclip,
SMO_apiclip_to_apiview,
SMO_inv_texmat_i,
SMO_INVALID
};
@ -270,6 +272,7 @@ public:
SSD_fog = 0x040,
SSD_light = 0x080,
SSD_clip_planes = 0x100,
SSD_tex_matrix = 0x200,
};
enum ShaderBug {

View File

@ -17,6 +17,7 @@
#include "pnmImage.h"
#include "subprocessWindow.h"
#include "nativeWindowHandle.h"
#include "displayInformation.h"
#import <Carbon/Carbon.h>
// some macros to make code more readable.

View File

@ -102,12 +102,15 @@ CopyOnWritePointer(CopyOnWritePointer &&move) NOEXCEPT :
////////////////////////////////////////////////////////////////////
INLINE void CopyOnWritePointer::
operator = (CopyOnWritePointer &&move) NOEXCEPT {
CopyOnWriteObject *old_object = _cow_object;
_cow_object = move._cow_object;
move._cow_object = NULL;
// Protect against self-move-assignment.
if (move._cow_object != _cow_object) {
CopyOnWriteObject *old_object = _cow_object;
_cow_object = move._cow_object;
move._cow_object = NULL;
if (old_object != (CopyOnWriteObject *)NULL) {
cache_unref_delete(old_object);
if (old_object != (CopyOnWriteObject *)NULL) {
cache_unref_delete(old_object);
}
}
}
#endif // USE_MOVE_SEMANTICS

View File

@ -47,6 +47,8 @@ wglGraphicsStateGuardian(GraphicsEngine *engine, GraphicsPipe *pipe,
_supports_wgl_multisample = false;
_supports_wgl_render_texture = false;
_wglCreateContextAttribsARB = NULL;
get_gamma_table();
atexit(atexit_function);
}
@ -345,6 +347,14 @@ choose_pixel_format(const FrameBufferProperties &properties,
get_extra_extensions();
_supports_pixel_format = has_extension("WGL_ARB_pixel_format");
_supports_wgl_multisample = has_extension("WGL_ARB_multisample");
if (has_extension("WGL_ARB_create_context")) {
_wglCreateContextAttribsARB =
(PFNWGLCREATECONTEXTATTRIBSARBPROC)wglGetProcAddress("wglCreateContextAttribsARB");
} else {
_wglCreateContextAttribsARB = NULL;
}
_extensions.clear();
if (!_supports_pixel_format) {
@ -614,7 +624,34 @@ make_context(HDC hdc) {
// Attempt to create a context.
wglGraphicsPipe::_current_valid = false;
_context = wglCreateContext(hdc);
if (_wglCreateContextAttribsARB != NULL) {
// We have a fancier version of wglCreateContext that allows us
// to specify what kind of OpenGL context we would like.
int attrib_list[32];
int n = 0;
attrib_list[0] = NULL;
if (gl_version.get_num_words() > 0) {
attrib_list[n++] = WGL_CONTEXT_MAJOR_VERSION_ARB;
attrib_list[n++] = gl_version[0];
if (gl_version.get_num_words() > 1) {
attrib_list[n++] = WGL_CONTEXT_MINOR_VERSION_ARB;
attrib_list[n++] = gl_version[1];
}
}
if (gl_debug) {
attrib_list[n++] = WGL_CONTEXT_FLAGS_ARB;
attrib_list[n++] = WGL_CONTEXT_DEBUG_BIT_ARB;
}
attrib_list[n++] = WGL_CONTEXT_PROFILE_MASK_ARB;
attrib_list[n++] = WGL_CONTEXT_CORE_PROFILE_BIT_ARB;
attrib_list[n] = NULL;
_context = _wglCreateContextAttribsARB(hdc, 0, attrib_list);
} else {
_context = wglCreateContext(hdc);
}
if (_context == NULL) {
wgldisplay_cat.error()

View File

@ -118,6 +118,8 @@ public:
PFNWGLRELEASETEXIMAGEARBPROC _wglReleaseTexImageARB;
PFNWGLSETPBUFFERATTRIBARBPROC _wglSetPbufferAttribARB;
PFNWGLCREATECONTEXTATTRIBSARBPROC _wglCreateContextAttribsARB;
public:
static TypeHandle get_class_type() {
return _type_handle;

View File

@ -304,8 +304,18 @@ open_window() {
// Initializes _colormap
setup_colormap(pixelformat);
// Make sure we have a context created.
HGLRC context = wglgsg->get_context(_hdc);
if (!context) {
// The context failed to create for some reason.
wgldisplay_cat.error()
<< "Closing window because no valid context is available.\n";
close_window();
return false;
}
// Initialize the gsg.
wglGraphicsPipe::wgl_make_current(_hdc, wglgsg->get_context(_hdc), &_make_current_pcollector);
wglGraphicsPipe::wgl_make_current(_hdc, context, &_make_current_pcollector);
wglgsg->reset_if_new();
wglgsg->report_my_gl_errors();
if (!wglgsg->get_fb_properties().verify_hardware_software

View File

@ -13,6 +13,7 @@
////////////////////////////////////////////////////////////////////
#include <time.h>
#include "displayInformation.h"
typedef struct {
D3DFORMAT d3d_format;
@ -116,7 +117,7 @@ static int get_display_information (DisplaySearchParameters &display_search_para
int get_adapter_display_mode_state;
int get_device_caps_state;
int shader_model;
GraphicsStateGuardian::ShaderModel shader_model;
UINT minimum_width;
UINT maximum_width;
UINT minimum_height;

File diff suppressed because it is too large Load Diff

View File

@ -16,6 +16,7 @@
#include "x11GraphicsWindow.h"
#include "config_x11display.h"
#include "frameBufferProperties.h"
#include "displayInformation.h"
TypeHandle x11GraphicsPipe::_type_handle;