More work on Android port

This commit is contained in:
rdb 2014-10-08 15:09:25 +00:00
parent 32a9e4d9ed
commit fbc3564bf9
16 changed files with 237 additions and 174 deletions

View File

@ -52,7 +52,6 @@ import __builtin__
from StringIO import StringIO
import marshal
import ElementTree as ET
from HTMLParser import HTMLParser
import BpDb
import unicodedata
import bisect
@ -4201,75 +4200,6 @@ if __debug__ and __name__ == '__main__':
assert unescapeHtmlString('as%32df') == 'as2df'
assert unescapeHtmlString('asdf%32') == 'asdf2'
class HTMLStringToElements(HTMLParser):
def __init__(self, str, *a, **kw):
self._elements = []
self._elementStack = Stack()
HTMLParser.__init__(self, *a, **kw)
self.feed(str)
self.close()
def getElements(self):
return self._elements
def _handleNewElement(self, element):
if len(self._elementStack):
self._elementStack.top().append(element)
else:
self._elements.append(element)
self._elementStack.push(element)
def handle_starttag(self, tag, attrs):
kwArgs = {}
for name, value in attrs:
kwArgs[name] = value
el = ET.Element(tag, **kwArgs)
self._handleNewElement(el)
def handle_data(self, data):
# this ignores text outside of a tag
if len(self._elementStack):
self._elementStack.top().text = data
def handle_endtag(self, tag):
top = self._elementStack.top()
if len(top.getchildren()) == 0:
# insert a comment to prevent ElementTree from using <... /> convention
# force it to create a tag closer a la </tag>
# prevents problems in certain browsers
if top.tag == 'script' and top.get('type') == 'text/javascript':
if top.text == None:
top.text = '// force tag closer'
else:
self.handle_comment('force tag closer')
self._elementStack.pop()
self._elementStack.pop()
def handle_comment(self, data):
comment = ET.Comment(data)
self._handleNewElement(comment)
def str2elements(str):
return HTMLStringToElements(str).getElements()
if __debug__ and __name__ == '__main__':
s = ScratchPad()
assert len(str2elements('')) == 0
s.br = str2elements('<br>')
assert len(s.br) == 1
assert s.br[0].tag == 'br'
s.b = str2elements('<b><br></b>')
assert len(s.b) == 1
assert len(s.b[0].getchildren()) == 1
s.a = str2elements('<a href=\'/\'>test</a>')
assert len(s.a) == 1
assert s.a[0].get('href') == '/'
assert s.a[0].text == 'test'
s.c = str2elements('<!--testComment-->')
assert len(s.c) == 1
assert s.c[0].text == 'testComment'
del s
def repeatableRepr(obj):
if type(obj) is types.DictType:
keys = obj.keys()

View File

@ -7,7 +7,8 @@ __all__ = ['ShowBase', 'WindowControls']
# Annoying and very noisy, but sometimes useful
#import VerboseImport
from pandac.PandaModules import *
from panda3d.core import *
from panda3d.direct import getConfigShowbase
# This needs to be available early for DirectGUI imports
import __builtin__

View File

@ -3,7 +3,6 @@ import sys
import os
import marshal
import imp
import struct
import types
import __builtin__
@ -286,7 +285,8 @@ class VFSLoader:
code = None
data = vfile.readFile(True)
if data[:4] == imp.get_magic():
t = struct.unpack('<I', data[4:8])[0]
t = ord(data[4]) + (ord(data[5]) << 8) + \
(ord(data[6]) << 16) + (ord(data[7]) << 24)
if not timestamp or t == timestamp:
code = marshal.loads(data[8:])
else:
@ -314,7 +314,10 @@ class VFSLoader:
pass
else:
f.write('\0\0\0\0')
f.write(struct.pack('<I', self.timestamp))
f.write(chr(self.timestamp & 0xff) +
chr((self.timestamp >> 8) & 0xff) +
chr((self.timestamp >> 16) & 0xff) +
chr((self.timestamp >> 24) & 0xff))
f.write(marshal.dumps(code))
f.flush()
f.seek(0, 0)

View File

@ -119,3 +119,23 @@ INLINE string ExecutionEnvironment::
get_dtool_name() {
return get_ptr()->ns_get_dtool_name();
}
////////////////////////////////////////////////////////////////////
// Function: ExecutionEnvironment::set_binary_name
// Access: Public, Static
// Description: Do not use.
////////////////////////////////////////////////////////////////////
INLINE void ExecutionEnvironment::
set_binary_name(const string &name) {
get_ptr()->_binary_name = name;
}
////////////////////////////////////////////////////////////////////
// Function: ExecutionEnvironment::set_dtool_name
// Access: Public, Static
// Description: Do not use.
////////////////////////////////////////////////////////////////////
INLINE void ExecutionEnvironment::
set_dtool_name(const string &name) {
get_ptr()->_dtool_name = name;
}

View File

@ -613,7 +613,7 @@ read_environment_variables() {
////////////////////////////////////////////////////////////////////
void ExecutionEnvironment::
read_args() {
#ifndef ANDROID
// First, we need to fill in _dtool_name. This contains
// the full path to the p3dtool library.
@ -835,7 +835,7 @@ read_args() {
}
#endif
#ifndef WIN32
#ifndef _WIN32
// Try to use realpath to get cleaner paths.
if (!_binary_name.empty()) {
@ -851,7 +851,9 @@ read_args() {
_dtool_name = newpath;
}
}
#endif
#endif // _WIN32
#endif // ANDROID
if (_dtool_name.empty()) {
_dtool_name = _binary_name;

View File

@ -50,6 +50,9 @@ PUBLISHED:
INLINE static string get_binary_name();
INLINE static string get_dtool_name();
INLINE static void set_binary_name(const string &name);
INLINE static void set_dtool_name(const string &name);
static Filename get_cwd();
private:

View File

@ -57,6 +57,10 @@ TVOLATILE AtomicAdjust::Pointer Filename::_user_appdata_directory;
TVOLATILE AtomicAdjust::Pointer Filename::_common_appdata_directory;
TypeHandle Filename::_type_handle;
#ifdef ANDROID
string Filename::_internal_data_dir;
#endif
#ifdef WIN32
/* begin Win32-specific code */
@ -459,7 +463,7 @@ Filename Filename::
temporary(const string &dirname, const string &prefix, const string &suffix,
Type type) {
Filename fdirname = dirname;
#ifdef WIN32
#if defined(_WIN32) || defined(ANDROID)
// The Windows tempnam() function doesn't do a good job of choosing
// a temporary directory. Choose one ourselves.
if (fdirname.empty()) {
@ -523,7 +527,7 @@ get_home_directory() {
if (home_directory.empty()) {
#ifdef WIN32
wchar_t buffer[MAX_PATH];
// On Windows, fall back to the "My Documents" folder.
if (SHGetSpecialFolderPathW(NULL, buffer, CSIDL_PERSONAL, true)) {
Filename dirname = from_os_specific_w(buffer);
@ -534,15 +538,22 @@ get_home_directory() {
}
}
#elif defined(ANDROID)
// Temporary hack.
home_directory = "/data/data/org.panda3d.sdk";
#elif defined(IS_OSX)
home_directory = get_osx_home_directory();
#elif defined(ANDROID)
home_directory = _internal_data_dir;
#else
// Posix case: check /etc/passwd?
#endif // WIN32
}
if (home_directory.empty()) {
// Fallback case.
home_directory = ExecutionEnvironment::get_cwd();
@ -555,7 +566,7 @@ get_home_directory() {
delete newdir;
}
}
return (*(Filename *)_home_directory);
}
@ -585,6 +596,10 @@ get_temp_directory() {
#elif defined(IS_OSX)
temp_directory = get_osx_temp_directory();
#elif defined(ANDROID)
temp_directory.set_dirname(_internal_data_dir);
temp_directory.set_basename("cache");
#else
// Posix case.
temp_directory = "/tmp";
@ -634,6 +649,10 @@ get_user_appdata_directory() {
#elif defined(IS_OSX)
user_appdata_directory = get_osx_user_appdata_directory();
#elif defined(ANDROID)
user_appdata_directory.set_dirname(_internal_data_dir);
user_appdata_directory.set_basename("files");
#else
// Posix case.
user_appdata_directory = get_home_directory();
@ -683,6 +702,10 @@ get_common_appdata_directory() {
#elif defined(IS_OSX)
common_appdata_directory = get_osx_common_appdata_directory();
#elif defined(ANDROID)
common_appdata_directory.set_dirname(_internal_data_dir);
common_appdata_directory.set_basename("files");
#else
// Posix case.
common_appdata_directory = "/var";

View File

@ -263,6 +263,11 @@ protected:
static TVOLATILE AtomicAdjust::Pointer _user_appdata_directory;
static TVOLATILE AtomicAdjust::Pointer _common_appdata_directory;
#ifdef ANDROID
public:
static string _internal_data_dir;
#endif
public:
static TypeHandle get_class_type() {
return _type_handle;

View File

@ -16,6 +16,7 @@
#include "config_util.h"
#include "virtualFileMountAndroidAsset.h"
#include "virtualFileSystem.h"
#include "filename.h"
#include "config_display.h"
//#define OPENGLES_1
@ -45,9 +46,36 @@ void android_main(struct android_app* app) {
return;
}
// Fetch the data directory.
jclass activity_class = env->GetObjectClass(activity->clazz);
jmethodID get_appinfo = env->GetMethodID(activity_class, "getApplicationInfo", "()Landroid/content/pm/ApplicationInfo;");
jobject appinfo = env->CallObjectMethod(activity->clazz, get_appinfo);
jclass appinfo_class = env->GetObjectClass(appinfo);
// Fetch the path to the data directory.
jfieldID datadir_field = env->GetFieldID(appinfo_class, "dataDir", "Ljava/lang/String;");
jstring datadir = (jstring) env->GetObjectField(appinfo, datadir_field);
const char *data_path = env->GetStringUTFChars(datadir, NULL);
Filename::_internal_data_dir = data_path;
android_cat.info() << "Path to data: " << data_path << "\n";
env->ReleaseStringUTFChars(datadir, data_path);
// Fetch the path to the library directory.
jfieldID libdir_field = env->GetFieldID(appinfo_class, "nativeLibraryDir", "Ljava/lang/String;");
jstring libdir = (jstring) env->GetObjectField(appinfo, libdir_field);
const char *lib_path = env->GetStringUTFChars(libdir, NULL);
string dtool_name = string(lib_path) + "/libp3dtool.so";
ExecutionEnvironment::set_dtool_name(dtool_name);
android_cat.info() << "Path to dtool: " << dtool_name << "\n";
env->ReleaseStringUTFChars(libdir, lib_path);
// Get the path to the APK.
jclass clazz = env->GetObjectClass(activity->clazz);
jmethodID methodID = env->GetMethodID(clazz, "getPackageCodePath", "()Ljava/lang/String;");
jmethodID methodID = env->GetMethodID(activity_class, "getPackageCodePath", "()Ljava/lang/String;");
jstring code_path = (jstring) env->CallObjectMethod(activity->clazz, methodID);
const char* apk_path;

View File

@ -326,7 +326,7 @@ open_window() {
return false;
}
//_fb_properties = androidgsg->get_fb_properties();
_fb_properties = androidgsg->get_fb_properties();
androiddisplay_cat.error() << "open_window done\n";
@ -434,7 +434,7 @@ handle_command(struct android_app *app, int32_t command) {
void AndroidGraphicsWindow::
ns_handle_command(int32_t command) {
WindowProperties properties;
switch (command) {
case APP_CMD_SAVE_STATE:
// The system has asked us to save our current state. Do so.
@ -446,16 +446,25 @@ ns_handle_command(int32_t command) {
// The window is being shown, get it ready.
if (_app->window != NULL) {
create_surface();
properties.set_size(ANativeWindow_getWidth(_app->window),
ANativeWindow_getHeight(_app->window));
properties.set_minimized(false);
system_changed_properties(properties);
}
break;
case APP_CMD_CONFIG_CHANGED:
properties.set_size(ANativeWindow_getWidth(_app->window),
ANativeWindow_getHeight(_app->window));
system_changed_properties(properties);
break;
case APP_CMD_TERM_WINDOW:
destroy_surface();
properties.set_minimized(true);
system_changed_properties(properties);
break;
case APP_CMD_WINDOW_RESIZED:
properties.set_size(ANativeWindow_getWidth(_app->window),
ANativeWindow_getHeight(_app->window));
break;
case APP_CMD_WINDOW_REDRAW_NEEDED:
break;

View File

@ -57,7 +57,7 @@ get_fd(const Filename &file, off_t *start, off_t *length) const {
////////////////////////////////////////////////////////////////////
bool VirtualFileMountAndroidAsset::
has_file(const Filename &file) const {
return (file.empty() || is_directory(file) || is_regular_file(file));
return (file.empty() || /*is_directory(file) ||*/ is_regular_file(file));
}
////////////////////////////////////////////////////////////////////

View File

@ -90,6 +90,7 @@
#define GL_DEPTH_STENCIL_EXT GL_DEPTH_STENCIL_OES
#define GL_UNSIGNED_INT_24_8_EXT GL_UNSIGNED_INT_24_8_OES
#define GL_DEPTH24_STENCIL8_EXT GL_DEPTH24_STENCIL8_OES
#define GL_DEPTH24_STENCIL8 GL_DEPTH24_STENCIL8_OES
#define GL_DEPTH_COMPONENT16 GL_DEPTH_COMPONENT16_OES
#define GL_DEPTH_COMPONENT24 GL_DEPTH_COMPONENT24_OES
#define GL_DEPTH_COMPONENT32 GL_DEPTH_COMPONENT32_OES

View File

@ -174,6 +174,7 @@ begin_frame(FrameMode mode, Thread *current_thread) {
// In case of multisample rendering, we don't need to issue
// the barrier until we call glBlitFramebuffer.
#ifndef OPENGLES
if (gl_enable_memory_barriers && _fbo_multisample == 0) {
CLP(GraphicsStateGuardian) *glgsg;
DCAST_INTO_R(glgsg, _gsg, false);
@ -189,6 +190,7 @@ begin_frame(FrameMode mode, Thread *current_thread) {
}
}
}
#endif
}
_gsg->set_current_properties(&get_fb_properties());
@ -443,6 +445,7 @@ rebuild_bitplanes() {
if (_fbo[layer] == 0) {
glgsg->_glGenFramebuffers(1, &_fbo[layer]);
#ifndef OPENGLES
if (glgsg->_use_object_labels) {
if (num_fbos > 1) {
GLchar name[128];
@ -452,6 +455,7 @@ rebuild_bitplanes() {
glgsg->_glObjectLabel(GL_FRAMEBUFFER, _fbo[layer], _name.size(), _name.data());
}
}
#endif
if (_fbo[layer] == 0) {
report_my_gl_errors();
@ -485,7 +489,7 @@ rebuild_bitplanes() {
_have_any_color = true;
}
#ifndef OPENGLES
#ifndef OPENGLES_1
for (int i=0; i<_fb_properties.get_aux_rgba(); i++) {
bind_slot(layer, rb_resize, attach, (RenderTexturePlane)(RTP_aux_rgba_0+i), next++);
_have_any_color = true;
@ -1630,6 +1634,7 @@ resolve_multisamples() {
PStatGPUTimer timer(glgsg, _resolve_multisample_pcollector);
#ifndef OPENGLES
if (gl_enable_memory_barriers) {
// Issue memory barriers as necessary to make sure that the
// texture memory is synchronized before we blit to it.
@ -1644,6 +1649,7 @@ resolve_multisamples() {
}
}
}
#endif
glgsg->report_my_gl_errors();
GLuint fbo = _fbo[0];
@ -1692,6 +1698,7 @@ resolve_multisamples() {
GL_NEAREST);
}
// Now handle the other color buffers.
#ifndef OPENGLES_1
int next = GL_COLOR_ATTACHMENT1_EXT;
if (_fb_properties.is_stereo()) {
glReadBuffer(next);
@ -1700,7 +1707,6 @@ resolve_multisamples() {
GL_COLOR_BUFFER_BIT, GL_NEAREST);
next += 1;
}
#ifndef OPENGLES
for (int i = 0; i < _fb_properties.get_aux_rgba(); ++i) {
glReadBuffer(next);
glDrawBuffer(next);

View File

@ -552,6 +552,7 @@ reset() {
_supported_geom_rendering |= Geom::GR_point_sprite;
}
#ifndef OPENGLES
_glPrimitiveRestartIndex = NULL;
if (is_at_least_gl_version(4, 3) || has_extension("GL_ARB_ES3_compatibility")) {
@ -575,6 +576,7 @@ reset() {
_glPrimitiveRestartIndex = (PFNGLPRIMITIVERESTARTINDEXPROC)
get_extension_func("glPrimitiveRestartIndexNV");
}
#endif
_supports_vertex_blend = has_extension("GL_ARB_vertex_blend");
@ -798,7 +800,6 @@ reset() {
}
}
_supports_2d_texture_array = false;
#ifndef OPENGLES
_supports_2d_texture_array = has_extension("GL_EXT_texture_array");
@ -914,12 +915,10 @@ reset() {
glGetIntegerv(GL_COMPRESSED_TEXTURE_FORMATS, formats);
for (int i = 0; i < num_compressed_formats; ++i) {
switch (formats[i]) {
#ifndef OPENGLES_1
case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
_compressed_texture_formats.set_bit(Texture::CM_dxt1);
break;
#endif
#ifdef OPENGLES
case GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG:
case GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG:
@ -1776,7 +1775,6 @@ reset() {
glGetIntegerv(GL_COMPRESSED_TEXTURE_FORMATS, formats);
for (int i = 0; i < num_compressed_formats; ++i) {
switch (formats[i]) {
#ifndef OPENGLES_1
case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
GLCAT.debug(false) << " GL_COMPRESSED_RGB_S3TC_DXT1_EXT\n";
break;
@ -1784,7 +1782,6 @@ reset() {
case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
GLCAT.debug(false) << " GL_COMPRESSED_RGBA_S3TC_DXT1_EXT\n";
break;
#endif
#ifdef OPENGLES
case GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG:
GLCAT.debug(false) << " GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG\n";
@ -2431,6 +2428,7 @@ prepare_display_region(DisplayRegionPipelineReader *dr) {
_scissor_enabled = false;
}
#ifndef OPENGLES
if (_supports_viewport_arrays) {
int count = dr->get_num_regions();
GLfloat *viewports = (GLfloat *)alloca(sizeof(GLfloat) * 4 * count);
@ -2450,7 +2448,9 @@ prepare_display_region(DisplayRegionPipelineReader *dr) {
_glScissorArrayv(0, count, scissors);
}
} else {
} else
#endif // OPENGLES
{
glViewport(x, y, width, height);
if (dr->get_scissor_enabled()) {
glScissor(x, y, width, height);
@ -3845,9 +3845,11 @@ draw_linestrips(const GeomPrimitivePipelineReader *reader, bool force) {
if (reader->is_indexed() &&
(_supported_geom_rendering & GeomEnums::GR_strip_cut_index) != 0) {
// One long triangle strip, connected by strip cut indices.
#ifndef OPENGLES
if (_glPrimitiveRestartIndex != NULL) {
_glPrimitiveRestartIndex(reader->get_strip_cut_index());
}
#endif
int num_vertices = reader->get_num_vertices();
_vertices_other_pcollector.add_level(num_vertices);
@ -5271,9 +5273,11 @@ framebuffer_copy_to_ram(Texture *tex, int view, int z,
case GL_FLOAT:
GLCAT.spam(false) << "GL_FLOAT";
break;
#ifndef OPENGLES_1
case GL_INT:
GLCAT.spam(false) << "GL_INT";
break;
#endif
default:
GLCAT.spam(false) << "unknown";
break;
@ -5810,7 +5814,11 @@ do_issue_material() {
}
#endif // NDEBUG
#ifdef OPENGLES
const GLenum face = GL_FRONT_AND_BACK;
#else
GLenum face = material->get_twoside() ? GL_FRONT_AND_BACK : GL_FRONT;
#endif
call_glMaterialfv(face, GL_SPECULAR, material->get_specular());
call_glMaterialfv(face, GL_EMISSION, material->get_emission());
@ -7045,7 +7053,9 @@ get_component_type(Texture::ComponentType component_type) {
return GL_UNSIGNED_BYTE;
}
case Texture::T_int:
#ifndef OPENGLES_1
return GL_INT;
#endif
default:
GLCAT.error() << "Invalid Texture::Type value!\n";
return GL_UNSIGNED_BYTE;
@ -7133,18 +7143,19 @@ get_external_image_format(Texture *tex) const {
#endif
break;
#ifndef OPENGLES_1
case Texture::CM_dxt1:
#ifndef OPENGLES_1
if (format == Texture::F_srgb_alpha) {
return GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT;
} else if (format == Texture::F_srgb) {
return GL_COMPRESSED_SRGB_S3TC_DXT1_EXT;
} else if (Texture::has_alpha(format)) {
} else
#endif
if (Texture::has_alpha(format)) {
return GL_COMPRESSED_RGBA_S3TC_DXT1_EXT;
} else {
return GL_COMPRESSED_RGB_S3TC_DXT1_EXT;
}
#endif
#ifndef OPENGLES
case Texture::CM_dxt3:
@ -7170,22 +7181,28 @@ get_external_image_format(Texture *tex) const {
#else
case Texture::CM_pvr1_2bpp:
#ifndef OPENGLES_1
if (format == Texture::F_srgb_alpha) {
return GL_COMPRESSED_SRGB_ALPHA_PVRTC_2BPPV1_EXT;
} else if (format == Texture::F_srgb) {
return GL_COMPRESSED_SRGB_PVRTC_2BPPV1_EXT;
} else if (Texture::has_alpha(format)) {
} else
#endif // OPENGLES_1
if (Texture::has_alpha(format)) {
return GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG;
} else {
return GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG;
}
case Texture::CM_pvr1_4bpp:
#ifndef OPENGLES_1
if (format == Texture::F_srgb_alpha) {
return GL_COMPRESSED_SRGB_ALPHA_PVRTC_4BPPV1_EXT;
} else if (format == Texture::F_srgb) {
return GL_COMPRESSED_SRGB_PVRTC_4BPPV1_EXT;
} else if (Texture::has_alpha(format)) {
} else
#endif // OPENGLES_1
if (Texture::has_alpha(format)) {
return GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;
} else {
return GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG;
@ -7425,18 +7442,19 @@ get_internal_image_format(Texture *tex) const {
return GL_COMPRESSED_SLUMINANCE_ALPHA;
#endif
#ifndef OPENGLES_1
case Texture::CM_dxt1:
#ifndef OPENGLES_1
if (format == Texture::F_srgb_alpha) {
return GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT;
} else if (format == Texture::F_srgb) {
return GL_COMPRESSED_SRGB_S3TC_DXT1_EXT;
} else if (Texture::has_alpha(format)) {
} else
#endif
if (Texture::has_alpha(format)) {
return GL_COMPRESSED_RGBA_S3TC_DXT1_EXT;
} else {
return GL_COMPRESSED_RGB_S3TC_DXT1_EXT;
}
#endif
#ifndef OPENGLES
case Texture::CM_dxt3:
@ -7461,22 +7479,28 @@ get_internal_image_format(Texture *tex) const {
}
#else
case Texture::CM_pvr1_2bpp:
#ifndef OPENGLES_1
if (format == Texture::F_srgb_alpha) {
return GL_COMPRESSED_SRGB_ALPHA_PVRTC_2BPPV1_EXT;
} else if (format == Texture::F_srgb) {
return GL_COMPRESSED_SRGB_PVRTC_2BPPV1_EXT;
} else if (Texture::has_alpha(format)) {
} else
#endif // OPENGLES_1
if (Texture::has_alpha(format)) {
return GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG;
} else {
return GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG;
}
case Texture::CM_pvr1_4bpp:
#ifndef OPENGLES_1
if (format == Texture::F_srgb_alpha) {
return GL_COMPRESSED_SRGB_ALPHA_PVRTC_4BPPV1_EXT;
} else if (format == Texture::F_srgb) {
return GL_COMPRESSED_SRGB_PVRTC_4BPPV1_EXT;
} else if (Texture::has_alpha(format)) {
} else
#endif // OPENGLES_1
if (Texture::has_alpha(format)) {
return GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;
} else {
return GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG;
@ -7500,9 +7524,12 @@ get_internal_image_format(Texture *tex) const {
case Texture::F_depth_stencil:
if (_supports_depth_stencil) {
#ifndef OPENGLES_1
if (tex->get_component_type() == Texture::T_float) {
return GL_DEPTH32F_STENCIL8;
} else {
} else
#endif
{
return GL_DEPTH_STENCIL;
}
}
@ -7554,9 +7581,12 @@ get_internal_image_format(Texture *tex) const {
case Texture::F_rgba:
case Texture::F_rgbm:
#ifndef OPENGLES_1
if (tex->get_component_type() == Texture::T_float) {
return GL_RGBA16F;
} else {
} else
#endif
{
return GL_RGBA;
}
@ -7568,17 +7598,13 @@ get_internal_image_format(Texture *tex) const {
return GL_RGBA8_OES;
case Texture::F_rgba12:
return GL_RGBA;
#ifndef OPENGLES_1
case Texture::F_rgba16:
return GL_RGBA16F;
#endif // OPENGLES_1
case Texture::F_rgba32:
return GL_RGBA32F;
#else
case Texture::F_rgba8:
return GL_RGBA8;
case Texture::F_rgba12:
return GL_RGBA12;
#endif // OPENGLES
#ifndef OPENGLES_1
case Texture::F_rgba16:
return GL_RGBA16F;
case Texture::F_rgba32:
@ -7648,21 +7674,21 @@ get_internal_image_format(Texture *tex) const {
return GL_RG16;
}
#endif
#ifndef OPENGLES_1
case Texture::F_r32:
return GL_R32F;
case Texture::F_rg32:
return GL_RG32F;
case Texture::F_alpha:
return GL_ALPHA;
#ifndef OPENGLES_1
case Texture::F_red:
case Texture::F_green:
case Texture::F_blue:
return GL_RED;
#endif
case Texture::F_alpha:
return GL_ALPHA;
case Texture::F_luminance:
return GL_LUMINANCE;
case Texture::F_luminance_alpha:
@ -7723,10 +7749,8 @@ is_mipmap_filter(GLenum min_filter) {
bool CLP(GraphicsStateGuardian)::
is_compressed_format(GLenum format) {
switch (format) {
#ifndef OPENGLES_1
case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
#endif
#ifdef OPENGLES
case GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG:
case GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG:
@ -8811,20 +8835,17 @@ update_standard_texture_bindings() {
_glActiveTexture(GL_TEXTURE0 + i);
// First, turn off the previous texture mode.
#ifndef OPENGLES_2
#ifndef OPENGLES
glDisable(GL_TEXTURE_1D);
#endif // OPENGLES
glDisable(GL_TEXTURE_2D);
if (_supports_3d_texture) {
#ifndef OPENGLES_1
glDisable(GL_TEXTURE_3D);
#endif // OPENGLES_1
}
if (_supports_cube_map) {
glDisable(GL_TEXTURE_CUBE_MAP);
}
#endif // OPENGLES_2
#ifndef OPENGLES
glDisable(GL_TEXTURE_1D);
if (_supports_3d_texture) {
glDisable(GL_TEXTURE_3D);
}
#endif // OPENGLES
int view = get_current_tex_view_offset() + stage->get_tex_view_offset();
TextureContext *tc = texture->prepare_now(view, _prepared_objects, this);
@ -8833,7 +8854,6 @@ update_standard_texture_bindings() {
continue;
}
#ifndef OPENGLES_2
// Then, turn on the current texture mode.
GLenum target = get_texture_target(texture->get_texture_type());
if (target == GL_NONE) {
@ -8845,14 +8865,11 @@ update_standard_texture_bindings() {
// Cannot be applied via the FFP.
continue;
}
#endif
#endif // OPENGLES
glEnable(target);
#endif
if (!update_texture(tc, false)) {
#ifndef OPENGLES_2
glDisable(target);
#endif
continue;
}
apply_texture(tc);
@ -8979,30 +8996,26 @@ update_standard_texture_bindings() {
}
}
#ifndef OPENGLES_2
// Disable the texture stages that are no longer used.
for (i = num_stages; i < _num_active_texture_stages; i++) {
_glActiveTexture(GL_TEXTURE0 + i);
#ifndef OPENGLES
glDisable(GL_TEXTURE_1D);
#endif // OPENGLES
glDisable(GL_TEXTURE_2D);
if (_supports_3d_texture) {
#ifndef OPENGLES_1
glDisable(GL_TEXTURE_3D);
#endif // OPENGLES_1
}
if (_supports_cube_map) {
glDisable(GL_TEXTURE_CUBE_MAP);
}
#ifndef OPENGLES
glDisable(GL_TEXTURE_1D);
if (_supports_3d_texture) {
glDisable(GL_TEXTURE_3D);
}
#endif // OPENGLES
}
#endif // OPENGLES_2
// Save the count of texture stages for next time.
_num_active_texture_stages = num_stages;
report_my_gl_errors();
#endif
#endif // OPENGLES_2
}
@ -10226,16 +10239,6 @@ upload_texture_image(CLP(TextureContext) *gtc, bool needs_reload,
_data_transferred_pcollector.add_level(view_size);
#endif
switch (texture_target) {
case GL_TEXTURE_1D:
if (image_compression == Texture::CM_off) {
glTexSubImage1D(page_target, n - mipmap_bias, 0, width,
external_format, component_type, image_ptr);
} else {
_glCompressedTexSubImage1D(page_target, n - mipmap_bias, 0, width,
external_format, view_size, image_ptr);
}
break;
#ifdef OPENGLES_2
case GL_TEXTURE_3D_OES:
#endif
@ -10256,6 +10259,16 @@ upload_texture_image(CLP(TextureContext) *gtc, bool needs_reload,
return false;
}
break;
case GL_TEXTURE_1D:
if (image_compression == Texture::CM_off) {
glTexSubImage1D(page_target, n - mipmap_bias, 0, width,
external_format, component_type, image_ptr);
} else {
_glCompressedTexSubImage1D(page_target, n - mipmap_bias, 0, width,
external_format, view_size, image_ptr);
}
break;
#endif
#ifndef OPENGLES
case GL_TEXTURE_2D_ARRAY_EXT:
@ -10826,10 +10839,12 @@ do_extract_texture_data(CLP(TextureContext) *gtc) {
type = Texture::T_unsigned_int_24_8;
format = Texture::F_depth_stencil;
break;
#ifndef OPENGLES_1
case GL_DEPTH32F_STENCIL8:
type = Texture::T_float;
format = Texture::F_depth_stencil;
break;
#endif
case GL_RGBA:
case 4:
format = Texture::F_rgba;
@ -11022,7 +11037,6 @@ do_extract_texture_data(CLP(TextureContext) *gtc) {
break;
#endif
#ifndef OPENGLES_1
case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
format = Texture::F_rgb;
compression = Texture::CM_dxt1;
@ -11031,6 +11045,7 @@ do_extract_texture_data(CLP(TextureContext) *gtc) {
format = Texture::F_rgbm;
compression = Texture::CM_dxt1;
break;
#ifndef OPENGLES_1
case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT:
format = Texture::F_srgb;
compression = Texture::CM_dxt1;
@ -11040,6 +11055,26 @@ do_extract_texture_data(CLP(TextureContext) *gtc) {
compression = Texture::CM_dxt1;
break;
#endif
#ifdef OPENGLES_2
case GL_COMPRESSED_SRGB_PVRTC_2BPPV1_EXT:
format = Texture::F_srgb;
compression = Texture::CM_pvr1_2bpp;
break;
case GL_COMPRESSED_SRGB_ALPHA_PVRTC_2BPPV1_EXT:
format = Texture::F_srgb_alpha;
compression = Texture::CM_pvr1_2bpp;
break;
case GL_COMPRESSED_SRGB_PVRTC_4BPPV1_EXT:
format = Texture::F_srgb;
compression = Texture::CM_pvr1_4bpp;
break;
case GL_COMPRESSED_SRGB_ALPHA_PVRTC_4BPPV1_EXT:
format = Texture::F_srgb_alpha;
compression = Texture::CM_pvr1_4bpp;
break;
#endif // OPENGLES_2
#ifdef OPENGLES
case GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG:
format = Texture::F_rgb;
@ -11058,22 +11093,6 @@ do_extract_texture_data(CLP(TextureContext) *gtc) {
compression = Texture::CM_pvr1_4bpp;
break;
case GL_COMPRESSED_SRGB_PVRTC_2BPPV1_EXT:
format = Texture::F_srgb;
compression = Texture::CM_pvr1_2bpp;
break;
case GL_COMPRESSED_SRGB_ALPHA_PVRTC_2BPPV1_EXT:
format = Texture::F_srgb_alpha;
compression = Texture::CM_pvr1_2bpp;
break;
case GL_COMPRESSED_SRGB_PVRTC_4BPPV1_EXT:
format = Texture::F_srgb;
compression = Texture::CM_pvr1_4bpp;
break;
case GL_COMPRESSED_SRGB_ALPHA_PVRTC_4BPPV1_EXT:
format = Texture::F_srgb_alpha;
compression = Texture::CM_pvr1_4bpp;
break;
#else
case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT:
format = Texture::F_rgba;

View File

@ -598,7 +598,9 @@ public:
PFNGLPOINTPARAMETERFVPROC _glPointParameterfv;
bool _supports_point_sprite;
#ifndef OPENGLES
PFNGLPRIMITIVERESTARTINDEXPROC _glPrimitiveRestartIndex;
#endif
bool _supports_vertex_blend;
PFNGLWEIGHTPOINTERARBPROC _glWeightPointer;
@ -710,11 +712,13 @@ public:
PFNGLGETQUERYIVPROC _glGetQueryiv;
PFNGLGETQUERYOBJECTUIVPROC _glGetQueryObjectuiv;
#ifndef OPENGLES
PFNGLQUERYCOUNTERPROC _glQueryCounter;
PFNGLGETQUERYOBJECTI64VPROC _glGetQueryObjecti64v;
PFNGLGETQUERYOBJECTUI64VPROC _glGetQueryObjectui64v;
PFNGLGETINTEGER64VPROC _glGetInteger64v;
#endif
PFNGLACTIVESTENCILFACEEXTPROC _glActiveStencilFaceEXT;

View File

@ -23,12 +23,14 @@ TypeHandle CLP(TextureContext)::_type_handle;
////////////////////////////////////////////////////////////////////
CLP(TextureContext)::
~CLP(TextureContext)() {
#ifndef OPENGLES
if (gl_enable_memory_barriers) {
_glgsg->_textures_needing_fetch_barrier.erase(this);
_glgsg->_textures_needing_image_access_barrier.erase(this);
_glgsg->_textures_needing_update_barrier.erase(this);
_glgsg->_textures_needing_framebuffer_barrier.erase(this);
}
#endif
glDeleteTextures(1, &_index);
_index = 0;
@ -53,12 +55,15 @@ void CLP(TextureContext)::
evict_lru() {
dequeue_lru();
#ifndef OPENGLES
if (_handle != 0) {
if (_handle_resident) {
_glgsg->_glMakeTextureHandleNonResident(_handle);
}
_handle_resident = false;
} else {
} else
#endif
{
reset_data();
}
@ -74,9 +79,11 @@ evict_lru() {
////////////////////////////////////////////////////////////////////
void CLP(TextureContext)::
reset_data() {
#ifndef OPENGLES
if (_handle != 0 && _handle_resident) {
_glgsg->_glMakeTextureHandleNonResident(_handle);
}
#endif
// Free the texture resources.
glDeleteTextures(1, &_index);
@ -108,6 +115,7 @@ reset_data() {
////////////////////////////////////////////////////////////////////
void CLP(TextureContext)::
make_handle_resident() {
#ifndef OPENGLES
if (_handle != 0) {
if (!_handle_resident) {
_glgsg->_glMakeTextureHandleResident(_handle);
@ -115,6 +123,7 @@ make_handle_resident() {
}
set_resident(true);
}
#endif
}
////////////////////////////////////////////////////////////////////