diff options
Diffstat (limited to 'platform/iphone')
-rw-r--r-- | platform/iphone/app_delegate.h | 8 | ||||
-rw-r--r-- | platform/iphone/audio_driver_iphone.cpp | 37 | ||||
-rw-r--r-- | platform/iphone/audio_driver_iphone.h | 17 | ||||
-rw-r--r-- | platform/iphone/game_center.h | 6 | ||||
-rw-r--r--[-rwxr-xr-x] | platform/iphone/gl_view.h | 25 | ||||
-rw-r--r--[-rwxr-xr-x] | platform/iphone/globals/global_defaults.cpp | 1 | ||||
-rw-r--r-- | platform/iphone/godot_iphone.cpp | 37 | ||||
-rw-r--r-- | platform/iphone/icloud.h | 7 | ||||
-rw-r--r-- | platform/iphone/in_app_store.h | 9 | ||||
-rw-r--r-- | platform/iphone/ios.h | 2 | ||||
-rw-r--r-- | platform/iphone/os_iphone.cpp | 103 | ||||
-rw-r--r-- | platform/iphone/os_iphone.h | 62 | ||||
-rw-r--r-- | platform/iphone/platform_refcount.h | 8 | ||||
-rw-r--r-- | platform/iphone/power_iphone.cpp | 14 | ||||
-rw-r--r-- | platform/iphone/rasterizer_iphone.cpp | 1652 | ||||
-rw-r--r-- | platform/iphone/rasterizer_iphone.h | 420 | ||||
-rw-r--r-- | platform/iphone/sem_iphone.cpp | 33 | ||||
-rw-r--r-- | platform/iphone/sem_iphone.h | 3 | ||||
-rw-r--r-- | platform/iphone/view_controller.h | 3 |
19 files changed, 1101 insertions, 1346 deletions
diff --git a/platform/iphone/app_delegate.h b/platform/iphone/app_delegate.h index 1b2ca42ab6..eaa74946ee 100644 --- a/platform/iphone/app_delegate.h +++ b/platform/iphone/app_delegate.h @@ -26,19 +26,19 @@ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#import <UIKit/UIKit.h> #import "gl_view.h" #import "view_controller.h" +#import <UIKit/UIKit.h> #import <CoreMotion/CoreMotion.h> @interface AppDelegate : NSObject <UIApplicationDelegate, GLViewDelegate> { //@property (strong, nonatomic) UIWindow *window; - ViewController* view_controller; + ViewController *view_controller; }; -@property (strong, nonatomic) UIWindow *window; +@property(strong, nonatomic) UIWindow *window; -+ (ViewController*)getViewController; ++ (ViewController *)getViewController; @end diff --git a/platform/iphone/audio_driver_iphone.cpp b/platform/iphone/audio_driver_iphone.cpp index eda3897841..eff91fa40f 100644 --- a/platform/iphone/audio_driver_iphone.cpp +++ b/platform/iphone/audio_driver_iphone.cpp @@ -41,9 +41,9 @@ Error AudioDriverIphone::init() { strdesc.mFramesPerPacket = 1; strdesc.mBitsPerChannel = 16; strdesc.mBytesPerFrame = - strdesc.mBitsPerChannel * strdesc.mChannelsPerFrame / 8; + strdesc.mBitsPerChannel * strdesc.mChannelsPerFrame / 8; strdesc.mBytesPerPacket = - strdesc.mBytesPerFrame * strdesc.mFramesPerPacket; + strdesc.mBytesPerFrame * strdesc.mFramesPerPacket; OSStatus result = noErr; AURenderCallbackStruct callback; @@ -55,7 +55,7 @@ Error AudioDriverIphone::init() { zeromem(&desc, sizeof(desc)); desc.componentType = kAudioUnitType_Output; - desc.componentSubType = kAudioUnitSubType_RemoteIO; /* !!! FIXME: ? */ + desc.componentSubType = kAudioUnitSubType_RemoteIO; /* !!! FIXME: ? */ comp = AudioComponentFindNext(NULL, &desc); desc.componentManufacturer = kAudioUnitManufacturer_Apple; @@ -64,16 +64,16 @@ Error AudioDriverIphone::init() { ERR_FAIL_COND_V(comp == NULL, FAILED); result = AudioUnitSetProperty(audio_unit, - kAudioUnitProperty_StreamFormat, - scope, bus, &strdesc, sizeof(strdesc)); + kAudioUnitProperty_StreamFormat, + scope, bus, &strdesc, sizeof(strdesc)); ERR_FAIL_COND_V(result != noErr, FAILED); zeromem(&callback, sizeof(AURenderCallbackStruct)); callback.inputProc = &AudioDriverIphone::output_callback; callback.inputProcRefCon = this; result = AudioUnitSetProperty(audio_unit, - kAudioUnitProperty_SetRenderCallback, - scope, bus, &callback, sizeof(callback)); + kAudioUnitProperty_SetRenderCallback, + scope, bus, &callback, sizeof(callback)); ERR_FAIL_COND_V(result != noErr, FAILED); result = AudioUnitInitialize(audio_unit); @@ -90,14 +90,13 @@ Error AudioDriverIphone::init() { }; OSStatus AudioDriverIphone::output_callback(void *inRefCon, - AudioUnitRenderActionFlags * ioActionFlags, - const AudioTimeStamp * inTimeStamp, - UInt32 inBusNumber, UInt32 inNumberFrames, - AudioBufferList * ioData) { - + AudioUnitRenderActionFlags *ioActionFlags, + const AudioTimeStamp *inTimeStamp, + UInt32 inBusNumber, UInt32 inNumberFrames, + AudioBufferList *ioData) { AudioBuffer *abuf; - AudioDriverIphone* ad = (AudioDriverIphone*)inRefCon; + AudioDriverIphone *ad = (AudioDriverIphone *)inRefCon; bool mix = true; @@ -107,7 +106,6 @@ OSStatus AudioDriverIphone::output_callback(void *inRefCon, mix = ad->mutex->try_lock() == OK; }; - if (!mix) { for (unsigned int i = 0; i < ioData->mNumberBuffers; i++) { abuf = &ioData->mBuffers[i]; @@ -122,7 +120,7 @@ OSStatus AudioDriverIphone::output_callback(void *inRefCon, abuf = &ioData->mBuffers[i]; frames_left = inNumberFrames; - int16_t* out = (int16_t*)abuf->mData; + int16_t *out = (int16_t *)abuf->mData; while (frames_left) { @@ -131,9 +129,9 @@ OSStatus AudioDriverIphone::output_callback(void *inRefCon, ad->audio_server_process(frames, ad->samples_in); //ad->unlock(); - for(int i = 0; i < frames * ad->channels; i++) { + for (int i = 0; i < frames * ad->channels; i++) { - out[i] = ad->samples_in[i]>>16; + out[i] = ad->samples_in[i] >> 16; } frames_left -= frames; @@ -175,12 +173,11 @@ void AudioDriverIphone::finish() { memdelete_arr(samples_in); }; - AudioDriverIphone::AudioDriverIphone() { - mutex=Mutex::create();//NULL; + mutex = Mutex::create(); //NULL; }; -AudioDriverIphone::~AudioDriverIphone() { +AudioDriverIphone::~AudioDriverIphone(){ }; diff --git a/platform/iphone/audio_driver_iphone.h b/platform/iphone/audio_driver_iphone.h index 4c0cbfcb22..8a0d92e070 100644 --- a/platform/iphone/audio_driver_iphone.h +++ b/platform/iphone/audio_driver_iphone.h @@ -38,19 +38,17 @@ class AudioDriverIphone : public AudioDriver { Mutex *mutex; int channels; - int32_t* samples_in; - int buffer_frames; + int32_t *samples_in; + int buffer_frames; static OSStatus output_callback(void *inRefCon, - AudioUnitRenderActionFlags * ioActionFlags, - const AudioTimeStamp * inTimeStamp, - UInt32 inBusNumber, UInt32 inNumberFrames, - AudioBufferList * ioData); - + AudioUnitRenderActionFlags *ioActionFlags, + const AudioTimeStamp *inTimeStamp, + UInt32 inBusNumber, UInt32 inNumberFrames, + AudioBufferList *ioData); public: - - const char* get_name() const { + const char *get_name() const { return "IPhone"; }; @@ -65,4 +63,3 @@ public: AudioDriverIphone(); ~AudioDriverIphone(); }; - diff --git a/platform/iphone/game_center.h b/platform/iphone/game_center.h index abbeaaf86f..a732a97a4c 100644 --- a/platform/iphone/game_center.h +++ b/platform/iphone/game_center.h @@ -37,7 +37,7 @@ class GameCenter : public Object { GDCLASS(GameCenter, Object); - static GameCenter* instance; + static GameCenter *instance; static void _bind_methods(); List<Variant> pending_events; @@ -45,7 +45,6 @@ class GameCenter : public Object { bool connected; public: - Error connect(); bool is_connected(); @@ -61,13 +60,12 @@ public: int get_pending_event_count(); Variant pop_pending_event(); - static GameCenter* get_singleton(); + static GameCenter *get_singleton(); GameCenter(); ~GameCenter(); }; - #endif #endif diff --git a/platform/iphone/gl_view.h b/platform/iphone/gl_view.h index 49e7810f08..555e34a895 100755..100644 --- a/platform/iphone/gl_view.h +++ b/platform/iphone/gl_view.h @@ -27,18 +27,17 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#import <UIKit/UIKit.h> +#import <AVFoundation/AVFoundation.h> +#import <MediaPlayer/MediaPlayer.h> #import <OpenGLES/EAGL.h> #import <OpenGLES/ES1/gl.h> #import <OpenGLES/ES1/glext.h> -#import <MediaPlayer/MediaPlayer.h> -#import <AVFoundation/AVFoundation.h> +#import <UIKit/UIKit.h> @protocol GLViewDelegate; -@interface GLView : UIView<UIKeyInput> -{ - @private +@interface GLView : UIView <UIKeyInput> { +@private // The pixel dimensions of the backbuffer GLint backingWidth; GLint backingHeight; @@ -83,9 +82,9 @@ @property(strong, nonatomic) MPMoviePlayerController *moviePlayerController; @property(strong, nonatomic) UIWindow *backgroundWindow; --(void)startAnimation; --(void)stopAnimation; --(void)drawView; +- (void)startAnimation; +- (void)stopAnimation; +- (void)drawView; - (BOOL)canBecomeFirstResponder; @@ -99,23 +98,23 @@ - (BOOL)createFramebuffer; - (void)destroyFramebuffer; -- (void)audioRouteChangeListenerCallback:(NSNotification*)notification; +- (void)audioRouteChangeListenerCallback:(NSNotification *)notification; @property NSTimeInterval animationInterval; @property(nonatomic, assign) BOOL useCADisplayLink; @end -@protocol GLViewDelegate<NSObject> +@protocol GLViewDelegate <NSObject> @required // Draw with OpenGL ES --(void)drawView:(GLView*)view; +- (void)drawView:(GLView *)view; @optional // Called whenever you need to do some initialization before rendering. --(void)setupView:(GLView*)view; +- (void)setupView:(GLView *)view; @end diff --git a/platform/iphone/globals/global_defaults.cpp b/platform/iphone/globals/global_defaults.cpp index bf716c36f0..b3067dc0c4 100755..100644 --- a/platform/iphone/globals/global_defaults.cpp +++ b/platform/iphone/globals/global_defaults.cpp @@ -29,7 +29,6 @@ #include "global_defaults.h" #include "global_config.h" - void register_iphone_global_defaults() { /*GLOBAL_DEF("rasterizer.iOS/use_fragment_lighting",false); diff --git a/platform/iphone/godot_iphone.cpp b/platform/iphone/godot_iphone.cpp index 27804e5c03..626c78fdf4 100644 --- a/platform/iphone/godot_iphone.cpp +++ b/platform/iphone/godot_iphone.cpp @@ -26,36 +26,36 @@ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "os_iphone.h" #include "main/main.h" +#include "os_iphone.h" #include <stdio.h> -#include <unistd.h> #include <string.h> +#include <unistd.h> -static OSIPhone* os = NULL; +static OSIPhone *os = NULL; extern "C" { -int add_path(int p_argc, char** p_args); -int add_cmdline(int p_argc, char** p_args); +int add_path(int p_argc, char **p_args); +int add_cmdline(int p_argc, char **p_args); }; -int iphone_main(int, int, int, char**); +int iphone_main(int, int, int, char **); -int iphone_main(int width, int height, int argc, char** argv) { +int iphone_main(int width, int height, int argc, char **argv) { int len = strlen(argv[0]); - while (len--){ + while (len--) { if (argv[0][len] == '/') break; } - if (len>=0) { - char path[512]; - memcpy(path, argv[0], len>sizeof(path)?sizeof(path):len); - path[len]=0; - printf("Path: %s\n", path); - chdir(path); + if (len >= 0) { + char path[512]; + memcpy(path, argv[0], len > sizeof(path) ? sizeof(path) : len); + path[len] = 0; + printf("Path: %s\n", path); + chdir(path); } printf("godot_iphone %s\n", argv[0]); @@ -64,8 +64,8 @@ int iphone_main(int width, int height, int argc, char** argv) { printf("cwd %s\n", cwd); os = new OSIPhone(width, height); - char* fargv[64]; - for (int i=0; i<argc; i++) { + char *fargv[64]; + for (int i = 0; i < argc; i++) { fargv[i] = argv[i]; }; fargv[argc] = NULL; @@ -73,15 +73,14 @@ int iphone_main(int width, int height, int argc, char** argv) { argc = add_cmdline(argc, fargv); printf("os created\n"); - Error err = Main::setup(fargv[0], argc - 1, &fargv[1], false); + Error err = Main::setup(fargv[0], argc - 1, &fargv[1], false); printf("setup %i\n", err); - if (err!=OK) + if (err != OK) return 255; return 0; }; - void iphone_finish() { printf("iphone_finish\n"); diff --git a/platform/iphone/icloud.h b/platform/iphone/icloud.h index ba50c4be15..743a9a5de3 100644 --- a/platform/iphone/icloud.h +++ b/platform/iphone/icloud.h @@ -33,18 +33,16 @@ #include "core/object.h" - class ICloud : public Object { GDCLASS(ICloud, Object); - static ICloud* instance; + static ICloud *instance; static void _bind_methods(); List<Variant> pending_events; public: - Error remove_key(Variant p_param); Variant set_key_values(Variant p_param); Variant get_key_value(Variant p_param); @@ -54,13 +52,12 @@ public: int get_pending_event_count(); Variant pop_pending_event(); - static ICloud* get_singleton(); + static ICloud *get_singleton(); ICloud(); ~ICloud(); }; - #endif #endif diff --git a/platform/iphone/in_app_store.h b/platform/iphone/in_app_store.h index 59a745c0f7..b2ed6f70e4 100644 --- a/platform/iphone/in_app_store.h +++ b/platform/iphone/in_app_store.h @@ -37,25 +37,24 @@ class InAppStore : public Object { GDCLASS(InAppStore, Object); - static InAppStore* instance; + static InAppStore *instance; static void _bind_methods(); List<Variant> pending_events; public: - Error request_product_info(Variant p_params); Error purchase(Variant p_params); int get_pending_event_count(); Variant pop_pending_event(); void finish_transaction(String product_id); - void set_auto_finish_transaction(bool b); + void set_auto_finish_transaction(bool b); void _post_event(Variant p_event); void _record_purchase(String product_id); - static InAppStore* get_singleton(); + static InAppStore *get_singleton(); InAppStore(); ~InAppStore(); @@ -63,6 +62,4 @@ public: #endif - #endif - diff --git a/platform/iphone/ios.h b/platform/iphone/ios.h index 345bf127f2..e5baf8f4d2 100644 --- a/platform/iphone/ios.h +++ b/platform/iphone/ios.h @@ -38,11 +38,9 @@ class iOS : public Object { static void _bind_methods(); public: - String get_rate_url(int p_app_id) const; iOS(); - }; #endif diff --git a/platform/iphone/os_iphone.cpp b/platform/iphone/os_iphone.cpp index 816e456838..57862131f9 100644 --- a/platform/iphone/os_iphone.cpp +++ b/platform/iphone/os_iphone.cpp @@ -34,13 +34,13 @@ #include "servers/visual/visual_server_raster.h" //#include "servers/visual/visual_server_wrap_mt.h" -#include "main/main.h" #include "audio_driver_iphone.h" +#include "main/main.h" +#include "core/global_config.h" +#include "core/io/file_access_pack.h" #include "core/os/dir_access.h" #include "core/os/file_access.h" -#include "core/io/file_access_pack.h" -#include "core/global_config.h" #include "sem_iphone.h" @@ -51,17 +51,16 @@ int OSIPhone::get_video_driver_count() const { return 1; }; -const char * OSIPhone::get_video_driver_name(int p_driver) const { +const char *OSIPhone::get_video_driver_name(int p_driver) const { return "GLES2"; }; -OSIPhone* OSIPhone::get_singleton() { +OSIPhone *OSIPhone::get_singleton() { - return (OSIPhone*)OS::get_singleton(); + return (OSIPhone *)OS::get_singleton(); }; - OS::VideoMode OSIPhone::get_default_video_mode() const { return video_mode; @@ -76,7 +75,7 @@ extern int gl_view_base_fb; // from gl_view.mm void OSIPhone::set_data_dir(String p_dir) { - DirAccess* da = DirAccess::open(p_dir); + DirAccess *da = DirAccess::open(p_dir); data_dir = da->get_current_dir(); printf("setting data dir to %ls from %ls\n", data_dir.c_str(), p_dir.c_str()); @@ -99,19 +98,19 @@ void OSIPhone::initialize_core() { SemaphoreIphone::make_default(); }; -void OSIPhone::initialize(const VideoMode& p_desired,int p_video_driver,int p_audio_driver) { +void OSIPhone::initialize(const VideoMode &p_desired, int p_video_driver, int p_audio_driver) { supported_orientations = 0; - supported_orientations |= ((GLOBAL_DEF("video_mode/allow_horizontal", true)?1:0) << LandscapeLeft); - supported_orientations |= ((GLOBAL_DEF("video_mode/allow_horizontal_flipped", false)?1:0) << LandscapeRight); - supported_orientations |= ((GLOBAL_DEF("video_mode/allow_vertical", false)?1:0) << PortraitDown); - supported_orientations |= ((GLOBAL_DEF("video_mode/allow_vertical_flipped", false)?1:0) << PortraitUp); + supported_orientations |= ((GLOBAL_DEF("video_mode/allow_horizontal", true) ? 1 : 0) << LandscapeLeft); + supported_orientations |= ((GLOBAL_DEF("video_mode/allow_horizontal_flipped", false) ? 1 : 0) << LandscapeRight); + supported_orientations |= ((GLOBAL_DEF("video_mode/allow_vertical", false) ? 1 : 0) << PortraitDown); + supported_orientations |= ((GLOBAL_DEF("video_mode/allow_vertical_flipped", false) ? 1 : 0) << PortraitUp); RasterizerGLES3::register_config(); RasterizerGLES3::make_current(); RasterizerStorageGLES3::system_fbo = gl_view_base_fb; - visual_server = memnew( VisualServerRaster() ); + visual_server = memnew(VisualServerRaster()); /* FIXME: Reimplement threaded rendering? Or remove? if (get_render_thread_mode() != RENDER_THREAD_UNSAFE) { @@ -127,15 +126,15 @@ void OSIPhone::initialize(const VideoMode& p_desired,int p_video_driver,int p_au audio_driver->init(); // init physics servers - physics_server = memnew( PhysicsServerSW ); + physics_server = memnew(PhysicsServerSW); physics_server->init(); //physics_2d_server = memnew( Physics2DServerSW ); physics_2d_server = Physics2DServerWrapMT::init_server<Physics2DServerSW>(); physics_2d_server->init(); - input = memnew( InputDefault ); + input = memnew(InputDefault); - /* +/* #ifdef IOS_SCORELOOP_ENABLED scoreloop = memnew(ScoreloopIOS); GlobalConfig::get_singleton()->add_singleton(GlobalConfig::Singleton("Scoreloop", scoreloop)); @@ -157,7 +156,7 @@ void OSIPhone::initialize(const VideoMode& p_desired,int p_video_driver,int p_au #ifdef ICLOUD_ENABLED icloud = memnew(ICloud); GlobalConfig::get_singleton()->add_singleton(GlobalConfig::Singleton("ICloud", icloud)); - //icloud->connect(); +//icloud->connect(); #endif GlobalConfig::get_singleton()->add_singleton(GlobalConfig::Singleton("iOS", memnew(iOS))); }; @@ -167,8 +166,7 @@ MainLoop *OSIPhone::get_main_loop() const { return main_loop; }; - -void OSIPhone::set_main_loop( MainLoop * p_main_loop ) { +void OSIPhone::set_main_loop(MainLoop *p_main_loop) { main_loop = p_main_loop; @@ -178,14 +176,13 @@ void OSIPhone::set_main_loop( MainLoop * p_main_loop ) { } }; - bool OSIPhone::iterate() { if (!main_loop) return true; if (main_loop) { - for (int i=0; i<event_count; i++) { + for (int i = 0; i < event_count; i++) { input->parse_input_event(event_queue[i]); }; @@ -213,10 +210,10 @@ void OSIPhone::mouse_button(int p_idx, int p_x, int p_y, bool p_pressed, bool p_ InputEvent ev; ev.type = InputEvent::SCREEN_TOUCH; ev.ID = ++last_event_id; - ev.screen_touch.index=p_idx; - ev.screen_touch.pressed=p_pressed; - ev.screen_touch.x=p_x; - ev.screen_touch.y=p_y; + ev.screen_touch.index = p_idx; + ev.screen_touch.pressed = p_pressed; + ev.screen_touch.x = p_x; + ev.screen_touch.y = p_y; queue_event(ev); }; @@ -238,7 +235,7 @@ void OSIPhone::mouse_button(int p_idx, int p_x, int p_y, bool p_pressed, bool p_ //mouse_list.pressed[p_idx] = p_pressed; - input->set_mouse_pos(Point2(ev.mouse_motion.x,ev.mouse_motion.y)); + input->set_mouse_pos(Point2(ev.mouse_motion.x, ev.mouse_motion.y)); ev.mouse_button.button_index = BUTTON_LEFT; ev.mouse_button.doubleclick = p_doubleclick; ev.mouse_button.pressed = p_pressed; @@ -252,11 +249,11 @@ void OSIPhone::mouse_move(int p_idx, int p_prev_x, int p_prev_y, int p_x, int p_ if (!GLOBAL_DEF("debug/disable_touch", false)) { InputEvent ev; - ev.type=InputEvent::SCREEN_DRAG; + ev.type = InputEvent::SCREEN_DRAG; ev.ID = ++last_event_id; - ev.screen_drag.index=p_idx; - ev.screen_drag.x=p_x; - ev.screen_drag.y=p_y; + ev.screen_drag.index = p_idx; + ev.screen_drag.x = p_x; + ev.screen_drag.y = p_y; ev.screen_drag.relative_x = p_x - p_prev_x; ev.screen_drag.relative_y = p_y - p_prev_y; queue_event(ev); @@ -283,25 +280,25 @@ void OSIPhone::mouse_move(int p_idx, int p_prev_x, int p_prev_y, int p_x, int p_ ev.mouse_motion.relative_y = ev.mouse_motion.y - p_prev_x; }; - input->set_mouse_pos(Point2(ev.mouse_motion.x,ev.mouse_motion.y)); - ev.mouse_motion.speed_x=input->get_last_mouse_speed().x; - ev.mouse_motion.speed_y=input->get_last_mouse_speed().y; + input->set_mouse_pos(Point2(ev.mouse_motion.x, ev.mouse_motion.y)); + ev.mouse_motion.speed_x = input->get_last_mouse_speed().x; + ev.mouse_motion.speed_y = input->get_last_mouse_speed().y; ev.mouse_motion.button_mask = 1; // pressed queue_event(ev); }; }; -void OSIPhone::queue_event(const InputEvent& p_event) { +void OSIPhone::queue_event(const InputEvent &p_event) { - ERR_FAIL_INDEX( event_count, MAX_EVENTS ); + ERR_FAIL_INDEX(event_count, MAX_EVENTS); event_queue[event_count++] = p_event; }; void OSIPhone::touches_cancelled() { - for (int i=0; i<MAX_MOUSE_COUNT; i++) { + for (int i = 0; i < MAX_MOUSE_COUNT; i++) { if (mouse_list.pressed[i]) { @@ -379,12 +376,12 @@ void OSIPhone::delete_main_loop() { void OSIPhone::finalize() { - if(main_loop) // should not happen? + if (main_loop) // should not happen? memdelete(main_loop); visual_server->finish(); memdelete(visual_server); -// memdelete(rasterizer); + // memdelete(rasterizer); physics_server->finish(); memdelete(physics_server); @@ -393,11 +390,10 @@ void OSIPhone::finalize() { memdelete(physics_2d_server); memdelete(input); - }; -void OSIPhone::set_mouse_show(bool p_show) { }; -void OSIPhone::set_mouse_grab(bool p_grab) { }; +void OSIPhone::set_mouse_show(bool p_show){}; +void OSIPhone::set_mouse_grab(bool p_grab){}; bool OSIPhone::is_mouse_grab_enabled() const { @@ -414,9 +410,9 @@ int OSIPhone::get_mouse_button_state() const { return mouse_list.pressed[0]; }; -void OSIPhone::set_window_title(const String& p_title) { }; +void OSIPhone::set_window_title(const String &p_title){}; -void OSIPhone::set_video_mode(const VideoMode& p_video_mode, int p_screen) { +void OSIPhone::set_video_mode(const VideoMode &p_video_mode, int p_screen) { video_mode = p_video_mode; }; @@ -454,7 +450,7 @@ extern void _hide_keyboard(); extern Error _shell_open(String p_uri); extern void _set_keep_screen_on(bool p_enabled); -void OSIPhone::show_virtual_keyboard(const String& p_existing_text,const Rect2& p_screen_rect) { +void OSIPhone::show_virtual_keyboard(const String &p_existing_text, const Rect2 &p_screen_rect) { _show_keyboard(p_existing_text); }; @@ -471,8 +467,7 @@ void OSIPhone::set_keep_screen_on(bool p_enabled) { _set_keep_screen_on(p_enabled); }; -void OSIPhone::set_cursor_shape(CursorShape p_shape) { - +void OSIPhone::set_cursor_shape(CursorShape p_shape){ }; @@ -496,8 +491,7 @@ bool OSIPhone::has_touchscreen_ui_hint() const { return true; } -void OSIPhone::set_locale(String p_locale) -{ +void OSIPhone::set_locale(String p_locale) { locale_code = p_locale; } @@ -513,7 +507,7 @@ extern void _stop_video(); extern void _focus_out_video(); Error OSIPhone::native_video_play(String p_path, float p_volume, String p_audio_track, String p_subtitle_track) { - FileAccess* f = FileAccess::open(p_path, FileAccess::READ); + FileAccess *f = FileAccess::open(p_path, FileAccess::READ); bool exists = f && f->is_open(); String tempFile = get_data_dir(); @@ -533,18 +527,18 @@ Error OSIPhone::native_video_play(String p_path, float p_volume, String p_audio_ memdelete(f); print("Playing video: %S\n", p_path.c_str()); - if (_play_video(p_path, p_volume, p_audio_track, p_subtitle_track) ) + if (_play_video(p_path, p_volume, p_audio_track, p_subtitle_track)) return OK; return FAILED; } bool OSIPhone::native_video_is_playing() const { - return _is_video_playing(); + return _is_video_playing(); } void OSIPhone::native_video_pause() { if (native_video_is_playing()) - _pause_video(); + _pause_video(); } void OSIPhone::native_video_unpause() { @@ -557,7 +551,7 @@ void OSIPhone::native_video_focus_out() { void OSIPhone::native_video_stop() { if (native_video_is_playing()) - _stop_video(); + _stop_video(); } OSIPhone::OSIPhone(int width, int height) { @@ -576,7 +570,6 @@ OSIPhone::OSIPhone(int width, int height) { }; OSIPhone::~OSIPhone() { - } #endif diff --git a/platform/iphone/os_iphone.h b/platform/iphone/os_iphone.h index 65dcc884bb..36261a62c2 100644 --- a/platform/iphone/os_iphone.h +++ b/platform/iphone/os_iphone.h @@ -31,20 +31,19 @@ #ifndef OS_IPHONE_H #define OS_IPHONE_H -#include "os/input.h" #include "drivers/unix/os_unix.h" +#include "os/input.h" -#include "servers/visual_server.h" -#include "servers/visual/rasterizer.h" +#include "game_center.h" +#include "icloud.h" +#include "in_app_store.h" +#include "main/input_default.h" +#include "servers/audio_server.h" #include "servers/physics/physics_server_sw.h" #include "servers/physics_2d/physics_2d_server_sw.h" #include "servers/physics_2d/physics_2d_server_wrap_mt.h" -#include "servers/audio_server.h" -#include "main/input_default.h" -#include "game_center.h" -#include "in_app_store.h" -#include "icloud.h" - +#include "servers/visual/rasterizer.h" +#include "servers/visual_server.h" class AudioDriverIphone; // class RasterizerGLES2; @@ -52,55 +51,53 @@ class AudioDriverIphone; class OSIPhone : public OS_Unix { public: - enum Orientations { PortraitDown, PortraitUp, LandscapeLeft, LandscapeRight, }; -private: +private: enum { - MAX_MOUSE_COUNT = 8, - MAX_EVENTS = 64, + MAX_MOUSE_COUNT = 8, + MAX_EVENTS = 64, }; uint8_t supported_orientations; -// Rasterizer *rasterizer; -// RasterizerGLES2* rasterizer_gles22; + // Rasterizer *rasterizer; + // RasterizerGLES2* rasterizer_gles22; VisualServer *visual_server; - PhysicsServer* physics_server; + PhysicsServer *physics_server; Physics2DServer *physics_2d_server; - AudioDriverIphone* audio_driver; + AudioDriverIphone *audio_driver; #ifdef GAME_CENTER_ENABLED - GameCenter* game_center; + GameCenter *game_center; #endif #ifdef STOREKIT_ENABLED - InAppStore* store_kit; + InAppStore *store_kit; #endif #ifdef ICLOUD_ENABLED - ICloud* icloud; + ICloud *icloud; #endif MainLoop *main_loop; VideoMode video_mode; - virtual int get_video_driver_count() const; - virtual const char * get_video_driver_name(int p_driver) const; + virtual const char *get_video_driver_name(int p_driver) const; virtual VideoMode get_default_video_mode() const; virtual void initialize_core(); - virtual void initialize(const VideoMode& p_desired,int p_video_driver,int p_audio_driver); + virtual void initialize(const VideoMode &p_desired, int p_video_driver, int p_audio_driver); - virtual void set_main_loop( MainLoop * p_main_loop ); + virtual void set_main_loop(MainLoop *p_main_loop); virtual MainLoop *get_main_loop() const; virtual void delete_main_loop(); @@ -111,7 +108,7 @@ private: bool pressed[MAX_MOUSE_COUNT]; MouseList() { - for (int i=0; i<MAX_MOUSE_COUNT; i++) + for (int i = 0; i < MAX_MOUSE_COUNT; i++) pressed[i] = false; }; }; @@ -123,7 +120,7 @@ private: InputEvent event_queue[MAX_EVENTS]; int event_count; int last_event_id; - void queue_event(const InputEvent& p_event); + void queue_event(const InputEvent &p_event); String data_dir; String unique_ID; @@ -132,7 +129,6 @@ private: InputDefault *input; public: - bool iterate(); uint8_t get_orientations() const; @@ -149,25 +145,25 @@ public: void update_magnetometer(float p_x, float p_y, float p_z); void update_gyroscope(float p_x, float p_y, float p_z); - static OSIPhone* get_singleton(); + static OSIPhone *get_singleton(); virtual void set_mouse_show(bool p_show); virtual void set_mouse_grab(bool p_grab); virtual bool is_mouse_grab_enabled() const; virtual Point2 get_mouse_pos() const; virtual int get_mouse_button_state() const; - virtual void set_window_title(const String& p_title); + virtual void set_window_title(const String &p_title); - virtual void set_video_mode(const VideoMode& p_video_mode,int p_screen=0); - virtual VideoMode get_video_mode(int p_screen=0) const; - virtual void get_fullscreen_mode_list(List<VideoMode> *p_list,int p_screen=0) const; + virtual void set_video_mode(const VideoMode &p_video_mode, int p_screen = 0); + virtual VideoMode get_video_mode(int p_screen = 0) const; + virtual void get_fullscreen_mode_list(List<VideoMode> *p_list, int p_screen = 0) const; virtual void set_keep_screen_on(bool p_enabled); virtual bool can_draw() const; virtual bool has_virtual_keyboard() const; - virtual void show_virtual_keyboard(const String& p_existing_text,const Rect2& p_screen_rect=Rect2()); + virtual void show_virtual_keyboard(const String &p_existing_text, const Rect2 &p_screen_rect = Rect2()); virtual void hide_virtual_keyboard(); virtual void set_cursor_shape(CursorShape p_shape); diff --git a/platform/iphone/platform_refcount.h b/platform/iphone/platform_refcount.h index d32fb4514c..6cfdc49369 100644 --- a/platform/iphone/platform_refcount.h +++ b/platform/iphone/platform_refcount.h @@ -31,15 +31,15 @@ #ifdef IPHONE_ENABLED #define REFCOUNT_T int -#define REFCOUNT_GET_T int const volatile& +#define REFCOUNT_GET_T int const volatile & #include <libkern/OSAtomic.h> -inline int atomic_conditional_increment(volatile int* v) { - return (*v==0)? 0 : OSAtomicIncrement32(v); +inline int atomic_conditional_increment(volatile int *v) { + return (*v == 0) ? 0 : OSAtomicIncrement32(v); } -inline int atomic_decrement(volatile int* v) { +inline int atomic_decrement(volatile int *v) { return OSAtomicDecrement32(v); } diff --git a/platform/iphone/power_iphone.cpp b/platform/iphone/power_iphone.cpp index db555f30c2..7b1f9246f4 100644 --- a/platform/iphone/power_iphone.cpp +++ b/platform/iphone/power_iphone.cpp @@ -33,12 +33,10 @@ bool PowerState::UpdatePowerInfo() { return false; } - PowerState PowerIphone::get_power_state() { if (UpdatePowerInfo()) { return power_state; - } - else { + } else { return POWERSTATE_UNKNOWN; } } @@ -46,8 +44,7 @@ PowerState PowerIphone::get_power_state() { int PowerIphone::get_power_seconds_left() { if (UpdatePowerInfo()) { return nsecs_left; - } - else { + } else { return -1; } } @@ -55,15 +52,14 @@ int PowerIphone::get_power_seconds_left() { int PowerIphone::get_power_percent_left() { if (UpdatePowerInfo()) { return percent_left; - } - else { + } else { return -1; } } -PowerIphone::PowerIphone() : nsecs_left(-1), percent_left(-1), power_state(POWERSTATE_UNKNOWN) { +PowerIphone::PowerIphone() + : nsecs_left(-1), percent_left(-1), power_state(POWERSTATE_UNKNOWN) { // TODO Auto-generated constructor stub - } PowerIphone::~PowerIphone() { diff --git a/platform/iphone/rasterizer_iphone.cpp b/platform/iphone/rasterizer_iphone.cpp index b8f3dd0d05..1a619f4305 100644 --- a/platform/iphone/rasterizer_iphone.cpp +++ b/platform/iphone/rasterizer_iphone.cpp @@ -29,13 +29,13 @@ #ifdef IPHONE_ENABLED #include "rasterizer_iphone.h" -#include "os/os.h" #include "global_config.h" +#include "os/os.h" #include <stdio.h> -_FORCE_INLINE_ static void _gl_load_transform(const Transform& tr) { +_FORCE_INLINE_ static void _gl_load_transform(const Transform &tr) { - GLfloat matrix[16]={ /* build a 16x16 matrix */ + GLfloat matrix[16] = { /* build a 16x16 matrix */ tr.basis.elements[0][0], tr.basis.elements[1][0], tr.basis.elements[2][0], @@ -57,9 +57,9 @@ _FORCE_INLINE_ static void _gl_load_transform(const Transform& tr) { glLoadMatrixf(matrix); }; -_FORCE_INLINE_ static void _gl_mult_transform(const Transform& tr) { +_FORCE_INLINE_ static void _gl_mult_transform(const Transform &tr) { - GLfloat matrix[16]={ /* build a 16x16 matrix */ + GLfloat matrix[16] = { /* build a 16x16 matrix */ tr.basis.elements[0][0], tr.basis.elements[1][0], tr.basis.elements[2][0], @@ -81,42 +81,41 @@ _FORCE_INLINE_ static void _gl_mult_transform(const Transform& tr) { glMultMatrixf(matrix); }; -static const GLenum prim_type[]={GL_POINTS,GL_LINES,GL_TRIANGLES,GL_TRIANGLE_FAN}; +static const GLenum prim_type[] = { GL_POINTS, GL_LINES, GL_TRIANGLES, GL_TRIANGLE_FAN }; -static void _draw_primitive(int p_points, const float *p_vertices, const float *p_normals, const float* p_colors, const float *p_uvs,const Plane *p_tangents=NULL,int p_instanced=1) { +static void _draw_primitive(int p_points, const float *p_vertices, const float *p_normals, const float *p_colors, const float *p_uvs, const Plane *p_tangents = NULL, int p_instanced = 1) { ERR_FAIL_COND(!p_vertices); - ERR_FAIL_COND(p_points <1 || p_points>4); + ERR_FAIL_COND(p_points < 1 || p_points > 4); GLenum type = prim_type[p_points - 1]; - if (!p_colors) { glColor4f(1, 1, 1, 1); }; glEnableClientState(GL_VERTEX_ARRAY); - glVertexPointer(3, GL_FLOAT, 0, (GLvoid*)p_vertices); + glVertexPointer(3, GL_FLOAT, 0, (GLvoid *)p_vertices); if (p_normals) { - glEnableClientState(GL_NORMAL_ARRAY); - glNormalPointer(GL_FLOAT, 0, (GLvoid*)p_normals); + glEnableClientState(GL_NORMAL_ARRAY); + glNormalPointer(GL_FLOAT, 0, (GLvoid *)p_normals); }; if (p_colors) { - glEnableClientState(GL_COLOR_ARRAY); - glColorPointer(4,GL_FLOAT, 0, p_colors); + glEnableClientState(GL_COLOR_ARRAY); + glColorPointer(4, GL_FLOAT, 0, p_colors); }; if (p_uvs) { - glClientActiveTexture(GL_TEXTURE0); - glEnableClientState(GL_TEXTURE_COORD_ARRAY); - glTexCoordPointer(2, GL_FLOAT, 0, p_uvs); + glClientActiveTexture(GL_TEXTURE0); + glEnableClientState(GL_TEXTURE_COORD_ARRAY); + glTexCoordPointer(2, GL_FLOAT, 0, p_uvs); }; - glDrawArrays( type, 0, p_points); + glDrawArrays(type, 0, p_points); glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_NORMAL_ARRAY); @@ -124,61 +123,61 @@ static void _draw_primitive(int p_points, const float *p_vertices, const float * glDisableClientState(GL_TEXTURE_COORD_ARRAY); }; - /* TEXTURE API */ -static Image _get_gl_image_and_format(const Image& p_image, Image::Format p_format, uint32_t p_flags,GLenum& r_gl_format,int &r_gl_components,bool &r_has_alpha_cache) { +static Image _get_gl_image_and_format(const Image &p_image, Image::Format p_format, uint32_t p_flags, GLenum &r_gl_format, int &r_gl_components, bool &r_has_alpha_cache) { - r_has_alpha_cache=false; - Image image=p_image; + r_has_alpha_cache = false; + Image image = p_image; - switch(p_format) { + switch (p_format) { case Image::FORMAT_L8: { - r_gl_components=1; - r_gl_format=GL_LUMINANCE; + r_gl_components = 1; + r_gl_format = GL_LUMINANCE; } break; case Image::FORMAT_INTENSITY: { image.convert(Image::FORMAT_RGBA8); - r_gl_components=4; - r_gl_format=GL_RGBA; - r_has_alpha_cache=true; + r_gl_components = 4; + r_gl_format = GL_RGBA; + r_has_alpha_cache = true; } break; case Image::FORMAT_LA8: { image.convert(Image::FORMAT_RGBA8); - r_gl_components=4; - r_gl_format=GL_RGBA; - r_has_alpha_cache=true; + r_gl_components = 4; + r_gl_format = GL_RGBA; + r_has_alpha_cache = true; } break; case Image::FORMAT_INDEXED: { image.convert(Image::FORMAT_RGB8); - r_gl_components=3; - r_gl_format=GL_RGB; + r_gl_components = 3; + r_gl_format = GL_RGB; } break; case Image::FORMAT_INDEXED_ALPHA: { image.convert(Image::FORMAT_RGBA8); - r_gl_components=4; - r_gl_format=GL_RGB; - r_has_alpha_cache=true; + r_gl_components = 4; + r_gl_format = GL_RGB; + r_has_alpha_cache = true; } break; case Image::FORMAT_RGB8: { - r_gl_components=3; r_gl_format=GL_RGB; + r_gl_components = 3; + r_gl_format = GL_RGB; } break; case Image::FORMAT_RGBA8: { - r_gl_components=4; - r_gl_format=GL_RGBA; - r_has_alpha_cache=true; + r_gl_components = 4; + r_gl_format = GL_RGBA; + r_has_alpha_cache = true; } break; default: { @@ -192,45 +191,43 @@ static Image _get_gl_image_and_format(const Image& p_image, Image::Format p_form RID RasterizerIPhone::texture_create() { Texture *texture = memnew(Texture); - ERR_FAIL_COND_V(!texture,RID()); + ERR_FAIL_COND_V(!texture, RID()); glGenTextures(1, &texture->tex_id); - texture->active=false; - - return texture_owner.make_rid( texture ); + texture->active = false; + return texture_owner.make_rid(texture); } -void RasterizerIPhone::texture_allocate(RID p_texture,int p_width, int p_height,Image::Format p_format,uint32_t p_flags) { +void RasterizerIPhone::texture_allocate(RID p_texture, int p_width, int p_height, Image::Format p_format, uint32_t p_flags) { bool has_alpha_cache; int components; GLenum format; - Texture *texture = texture_owner.get( p_texture ); + Texture *texture = texture_owner.get(p_texture); ERR_FAIL_COND(!texture); - texture->width=p_width; - texture->height=p_height; - texture->format=p_format; - texture->flags=p_flags; + texture->width = p_width; + texture->height = p_height; + texture->format = p_format; + texture->flags = p_flags; //texture->target = (p_flags & VS::TEXTURE_FLAG_CUBEMAP) ? GL_TEXTURE_CUBE_MAP : GL_TEXTURE_2D; texture->target = GL_TEXTURE_2D; - _get_gl_image_and_format(Image(),texture->format,texture->flags,format,components,has_alpha_cache); + _get_gl_image_and_format(Image(), texture->format, texture->flags, format, components, has_alpha_cache); - texture->gl_components_cache=components; - texture->gl_format_cache=format; - texture->format_has_alpha=has_alpha_cache; - texture->has_alpha=false; //by default it doesn't have alpha unless something with alpha is blitteds + texture->gl_components_cache = components; + texture->gl_format_cache = format; + texture->format_has_alpha = has_alpha_cache; + texture->has_alpha = false; //by default it doesn't have alpha unless something with alpha is blitteds glBindTexture(texture->target, texture->tex_id); - if (texture->flags&VS::TEXTURE_FLAG_MIPMAPS) { - glTexParameteri( GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE ); + if (texture->flags & VS::TEXTURE_FLAG_MIPMAPS) { + glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE); } - - if (texture->target==GL_TEXTURE_2D) { - glTexImage2D(texture->target, 0, format, texture->width, texture->height, 0, format, GL_UNSIGNED_BYTE,NULL); + if (texture->target == GL_TEXTURE_2D) { + glTexImage2D(texture->target, 0, format, texture->width, texture->height, 0, format, GL_UNSIGNED_BYTE, NULL); } /* @@ -241,138 +238,131 @@ void RasterizerIPhone::texture_allocate(RID p_texture,int p_width, int p_height, } */ - glTexParameteri(texture->target,GL_TEXTURE_MIN_FILTER,GL_LINEAR); // Linear Filtering + glTexParameteri(texture->target, GL_TEXTURE_MIN_FILTER, GL_LINEAR); // Linear Filtering - if (texture->flags&VS::TEXTURE_FLAG_FILTER) { + if (texture->flags & VS::TEXTURE_FLAG_FILTER) { - glTexParameteri(texture->target,GL_TEXTURE_MAG_FILTER,GL_LINEAR); // Linear Filtering - if (texture->flags&VS::TEXTURE_FLAG_MIPMAPS) { + glTexParameteri(texture->target, GL_TEXTURE_MAG_FILTER, GL_LINEAR); // Linear Filtering + if (texture->flags & VS::TEXTURE_FLAG_MIPMAPS) { //glTexParameteri(texture->target,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_LINEAR); }; } + if (texture->flags & VS::TEXTURE_FLAG_REPEAT /* && texture->target != GL_TEXTURE_CUBE_MAP*/) { - - if (texture->flags&VS::TEXTURE_FLAG_REPEAT /* && texture->target != GL_TEXTURE_CUBE_MAP*/) { - - glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT ); - glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT ); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); } else { //glTexParameterf( texture->target, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE ); - glTexParameterf( texture->target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE ); - glTexParameterf( texture->target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE ); + glTexParameterf(texture->target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameterf(texture->target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); } - texture->active=true; + texture->active = true; } -void RasterizerIPhone::texture_blit_rect(RID p_texture,int p_x,int p_y, const Image& p_image,VS::CubeMapSide p_cube_side) { +void RasterizerIPhone::texture_blit_rect(RID p_texture, int p_x, int p_y, const Image &p_image, VS::CubeMapSide p_cube_side) { - Texture * texture = texture_owner.get(p_texture); + Texture *texture = texture_owner.get(p_texture); ERR_FAIL_COND(!texture); ERR_FAIL_COND(!texture->active); - ERR_FAIL_COND(texture->format != p_image.get_format() ); + ERR_FAIL_COND(texture->format != p_image.get_format()); int components; GLenum format; bool alpha; - Image img = _get_gl_image_and_format(p_image, p_image.get_format(),texture->flags,format,components,alpha); + Image img = _get_gl_image_and_format(p_image, p_image.get_format(), texture->flags, format, components, alpha); if (img.detect_alpha()) - texture->has_alpha=true; + texture->has_alpha = true; GLenum blit_target = GL_TEXTURE_2D; //(texture->target == GL_TEXTURE_CUBE_MAP)?_cube_side_enum[p_cube_side]:GL_TEXTURE_2D; PoolVector<uint8_t>::Read read = img.get_data().read(); glBindTexture(texture->target, texture->tex_id); - glTexSubImage2D( blit_target, 0, p_x,p_y,img.get_width(),img.get_height(),format,GL_UNSIGNED_BYTE,read.ptr() ); + glTexSubImage2D(blit_target, 0, p_x, p_y, img.get_width(), img.get_height(), format, GL_UNSIGNED_BYTE, read.ptr()); //glGenerateMipmap( texture->target ); } -Image RasterizerIPhone::texture_get_rect(RID p_texture,int p_x,int p_y,int p_width, int p_height,VS::CubeMapSide p_cube_side) const { - +Image RasterizerIPhone::texture_get_rect(RID p_texture, int p_x, int p_y, int p_width, int p_height, VS::CubeMapSide p_cube_side) const { return Image(); } -void RasterizerIPhone::texture_set_flags(RID p_texture,uint32_t p_flags) { +void RasterizerIPhone::texture_set_flags(RID p_texture, uint32_t p_flags) { - Texture *texture = texture_owner.get( p_texture ); + Texture *texture = texture_owner.get(p_texture); ERR_FAIL_COND(!texture); glBindTexture(texture->target, texture->tex_id); uint32_t cube = texture->flags & VS::TEXTURE_FLAG_CUBEMAP; - texture->flags=p_flags|cube; // can't remove a cube from being a cube + texture->flags = p_flags | cube; // can't remove a cube from being a cube - if (texture->flags&VS::TEXTURE_FLAG_REPEAT /*&& texture->target != GL_TEXTURE_CUBE_MAP*/) { + if (texture->flags & VS::TEXTURE_FLAG_REPEAT /*&& texture->target != GL_TEXTURE_CUBE_MAP*/) { - glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT ); - glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT ); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); } else { //glTexParameterf( texture->target, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE ); - glTexParameterf( texture->target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE ); - glTexParameterf( texture->target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE ); - + glTexParameterf(texture->target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameterf(texture->target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); } + if (texture->flags & VS::TEXTURE_FLAG_FILTER) { - if (texture->flags&VS::TEXTURE_FLAG_FILTER) { - - glTexParameteri(texture->target,GL_TEXTURE_MAG_FILTER,GL_LINEAR); // Linear Filtering - if (texture->flags&VS::TEXTURE_FLAG_MIPMAPS) - glTexParameteri(texture->target,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_LINEAR); + glTexParameteri(texture->target, GL_TEXTURE_MAG_FILTER, GL_LINEAR); // Linear Filtering + if (texture->flags & VS::TEXTURE_FLAG_MIPMAPS) + glTexParameteri(texture->target, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); } else { - glTexParameteri(texture->target,GL_TEXTURE_MAG_FILTER,GL_NEAREST); // nearest + glTexParameteri(texture->target, GL_TEXTURE_MAG_FILTER, GL_NEAREST); // nearest } } uint32_t RasterizerIPhone::texture_get_flags(RID p_texture) const { - Texture * texture = texture_owner.get(p_texture); + Texture *texture = texture_owner.get(p_texture); - ERR_FAIL_COND_V(!texture,0); + ERR_FAIL_COND_V(!texture, 0); return texture->flags; - } Image::Format RasterizerIPhone::texture_get_format(RID p_texture) const { - Texture * texture = texture_owner.get(p_texture); + Texture *texture = texture_owner.get(p_texture); - ERR_FAIL_COND_V(!texture,Image::FORMAT_L8); + ERR_FAIL_COND_V(!texture, Image::FORMAT_L8); return texture->format; } uint32_t RasterizerIPhone::texture_get_width(RID p_texture) const { - Texture * texture = texture_owner.get(p_texture); + Texture *texture = texture_owner.get(p_texture); - ERR_FAIL_COND_V(!texture,0); + ERR_FAIL_COND_V(!texture, 0); return texture->width; } uint32_t RasterizerIPhone::texture_get_height(RID p_texture) const { - Texture * texture = texture_owner.get(p_texture); + Texture *texture = texture_owner.get(p_texture); - ERR_FAIL_COND_V(!texture,0); + ERR_FAIL_COND_V(!texture, 0); return texture->height; } bool RasterizerIPhone::texture_has_alpha(RID p_texture) const { - Texture * texture = texture_owner.get(p_texture); + Texture *texture = texture_owner.get(p_texture); - ERR_FAIL_COND_V(!texture,0); + ERR_FAIL_COND_V(!texture, 0); return texture->has_alpha; - } /* SHADER API */ @@ -382,97 +372,68 @@ RID RasterizerIPhone::shader_create() { return RID(); } -void RasterizerIPhone::shader_node_add(RID p_shader,VS::ShaderNodeType p_type,int p_id) { - - +void RasterizerIPhone::shader_node_add(RID p_shader, VS::ShaderNodeType p_type, int p_id) { } -void RasterizerIPhone::shader_node_remove(RID p_shader,int p_id) { - - +void RasterizerIPhone::shader_node_remove(RID p_shader, int p_id) { } void RasterizerIPhone::shader_node_change_type(RID p_shader, int p_id, VS::ShaderNodeType p_type) { - - } -void RasterizerIPhone::shader_node_set_param(RID p_shader, int p_id, const Variant& p_value) { - - +void RasterizerIPhone::shader_node_set_param(RID p_shader, int p_id, const Variant &p_value) { } -void RasterizerIPhone::shader_get_node_list(RID p_shader,List<int> *p_node_list) const { - - +void RasterizerIPhone::shader_get_node_list(RID p_shader, List<int> *p_node_list) const { } -VS::ShaderNodeType RasterizerIPhone::shader_node_get_type(RID p_shader,int p_id) const { - +VS::ShaderNodeType RasterizerIPhone::shader_node_get_type(RID p_shader, int p_id) const { return VS::NODE_ADD; } -Variant RasterizerIPhone::shader_node_get_param(RID p_shader,int p_id) const { +Variant RasterizerIPhone::shader_node_get_param(RID p_shader, int p_id) const { return Variant(); } -void RasterizerIPhone::shader_connect(RID p_shader,int p_src_id,int p_src_slot, int p_dst_id,int p_dst_slot) { - - +void RasterizerIPhone::shader_connect(RID p_shader, int p_src_id, int p_src_slot, int p_dst_id, int p_dst_slot) { } -bool RasterizerIPhone::shader_is_connected(RID p_shader,int p_src_id,int p_src_slot, int p_dst_id,int p_dst_slot) const { +bool RasterizerIPhone::shader_is_connected(RID p_shader, int p_src_id, int p_src_slot, int p_dst_id, int p_dst_slot) const { return false; } -void RasterizerIPhone::shader_disconnect(RID p_shader,int p_src_id,int p_src_slot, int p_dst_id,int p_dst_slot) { - - +void RasterizerIPhone::shader_disconnect(RID p_shader, int p_src_id, int p_src_slot, int p_dst_id, int p_dst_slot) { } -void RasterizerIPhone::shader_get_connections(RID p_shader,List<VS::ShaderConnection> *p_connections) const { - - +void RasterizerIPhone::shader_get_connections(RID p_shader, List<VS::ShaderConnection> *p_connections) const { } void RasterizerIPhone::shader_clear(RID p_shader) { - - } /* COMMON MATERIAL API */ -void RasterizerIPhone::material_set_param(RID p_material, const StringName& p_param, const Variant& p_value) { - - +void RasterizerIPhone::material_set_param(RID p_material, const StringName &p_param, const Variant &p_value) { } -Variant RasterizerIPhone::material_get_param(RID p_material, const StringName& p_param) const { +Variant RasterizerIPhone::material_get_param(RID p_material, const StringName &p_param) const { return Variant(); } void RasterizerIPhone::material_get_param_list(RID p_material, List<String> *p_param_list) const { - - } -void RasterizerIPhone::material_set_flag(RID p_material, VS::MaterialFlag p_flag,bool p_enabled) { - - +void RasterizerIPhone::material_set_flag(RID p_material, VS::MaterialFlag p_flag, bool p_enabled) { } -bool RasterizerIPhone::material_get_flag(RID p_material,VS::MaterialFlag p_flag) const { +bool RasterizerIPhone::material_get_flag(RID p_material, VS::MaterialFlag p_flag) const { return false; } -void RasterizerIPhone::material_set_blend_mode(RID p_material,VS::MaterialBlendMode p_mode) { - - +void RasterizerIPhone::material_set_blend_mode(RID p_material, VS::MaterialBlendMode p_mode) { } VS::MaterialBlendMode RasterizerIPhone::material_get_blend_mode(RID p_material) const { return VS::MATERIAL_BLEND_MODE_ADD; } -void RasterizerIPhone::material_set_line_width(RID p_material,float p_line_width) { - - +void RasterizerIPhone::material_set_line_width(RID p_material, float p_line_width) { } float RasterizerIPhone::material_get_line_width(RID p_material) const { @@ -483,78 +444,78 @@ float RasterizerIPhone::material_get_line_width(RID p_material) const { RID RasterizerIPhone::material_create() { - return material_owner.make_rid( memnew( Material ) ); + return material_owner.make_rid(memnew(Material)); } -void RasterizerIPhone::fixed_material_set_parameter(RID p_material, VS::FixedSpatialMaterialParam p_parameter, const Variant& p_value) { +void RasterizerIPhone::fixed_material_set_parameter(RID p_material, VS::FixedSpatialMaterialParam p_parameter, const Variant &p_value) { - Material *m=material_owner.get( p_material ); + Material *m = material_owner.get(p_material); ERR_FAIL_COND(!m); ERR_FAIL_INDEX(p_parameter, VisualServer::FIXED_MATERIAL_PARAM_MAX); m->parameters[p_parameter] = p_value; } -Variant RasterizerIPhone::fixed_material_get_parameter(RID p_material,VS::FixedSpatialMaterialParam p_parameter) const { +Variant RasterizerIPhone::fixed_material_get_parameter(RID p_material, VS::FixedSpatialMaterialParam p_parameter) const { - Material *m=material_owner.get( p_material ); + Material *m = material_owner.get(p_material); ERR_FAIL_COND_V(!m, Variant()); ERR_FAIL_INDEX_V(p_parameter, VisualServer::FIXED_MATERIAL_PARAM_MAX, Variant()); return m->parameters[p_parameter]; } -void RasterizerIPhone::fixed_material_set_texture(RID p_material,VS::FixedSpatialMaterialParam p_parameter, RID p_texture) { +void RasterizerIPhone::fixed_material_set_texture(RID p_material, VS::FixedSpatialMaterialParam p_parameter, RID p_texture) { - Material *m=material_owner.get( p_material ); + Material *m = material_owner.get(p_material); ERR_FAIL_COND(!m); ERR_FAIL_INDEX(p_parameter, VisualServer::FIXED_MATERIAL_PARAM_MAX); m->textures[p_parameter] = p_texture; } -RID RasterizerIPhone::fixed_material_get_texture(RID p_material,VS::FixedSpatialMaterialParam p_parameter) const { +RID RasterizerIPhone::fixed_material_get_texture(RID p_material, VS::FixedSpatialMaterialParam p_parameter) const { - Material *m=material_owner.get( p_material ); + Material *m = material_owner.get(p_material); ERR_FAIL_COND_V(!m, RID()); ERR_FAIL_INDEX_V(p_parameter, VisualServer::FIXED_MATERIAL_PARAM_MAX, Variant()); return m->textures[p_parameter]; } -void RasterizerIPhone::fixed_material_set_detail_blend_mode(RID p_material,VS::MaterialBlendMode p_mode) { +void RasterizerIPhone::fixed_material_set_detail_blend_mode(RID p_material, VS::MaterialBlendMode p_mode) { - Material *m=material_owner.get( p_material ); + Material *m = material_owner.get(p_material); ERR_FAIL_COND(!m); m->detail_blend_mode = p_mode; } VS::MaterialBlendMode RasterizerIPhone::fixed_material_get_detail_blend_mode(RID p_material) const { - Material *m=material_owner.get( p_material ); + Material *m = material_owner.get(p_material); ERR_FAIL_COND_V(!m, VS::MATERIAL_BLEND_MODE_MIX); return m->detail_blend_mode; } -void RasterizerIPhone::fixed_material_set_texcoord_mode(RID p_material,VS::FixedSpatialMaterialParam p_parameter, VS::FixedSpatialMaterialTexCoordMode p_mode) { +void RasterizerIPhone::fixed_material_set_texcoord_mode(RID p_material, VS::FixedSpatialMaterialParam p_parameter, VS::FixedSpatialMaterialTexCoordMode p_mode) { - Material *m=material_owner.get( p_material ); + Material *m = material_owner.get(p_material); ERR_FAIL_COND(!m); ERR_FAIL_INDEX(p_parameter, VisualServer::FIXED_MATERIAL_PARAM_MAX); m->texcoord_mode[p_parameter] = p_mode; } -VS::FixedSpatialMaterialTexCoordMode RasterizerIPhone::fixed_material_get_texcoord_mode(RID p_material,VS::FixedSpatialMaterialParam p_parameter) const { +VS::FixedSpatialMaterialTexCoordMode RasterizerIPhone::fixed_material_get_texcoord_mode(RID p_material, VS::FixedSpatialMaterialParam p_parameter) const { - Material *m=material_owner.get( p_material ); + Material *m = material_owner.get(p_material); ERR_FAIL_COND_V(!m, VS::FIXED_MATERIAL_TEXCOORD_TEXGEN); ERR_FAIL_INDEX_V(p_parameter, VisualServer::FIXED_MATERIAL_PARAM_MAX, VS::FIXED_MATERIAL_TEXCOORD_UV); return m->texcoord_mode[p_parameter]; // for now } -void RasterizerIPhone::fixed_material_set_texgen_mode(RID p_material,VS::FixedSpatialMaterialTexGenMode p_mode) { +void RasterizerIPhone::fixed_material_set_texgen_mode(RID p_material, VS::FixedSpatialMaterialTexGenMode p_mode) { - Material *m=material_owner.get( p_material ); + Material *m = material_owner.get(p_material); ERR_FAIL_COND(!m); m->texgen_mode = p_mode; @@ -562,23 +523,22 @@ void RasterizerIPhone::fixed_material_set_texgen_mode(RID p_material,VS::FixedSp VS::FixedSpatialMaterialTexGenMode RasterizerIPhone::fixed_material_get_texgen_mode(RID p_material) const { - Material *m=material_owner.get( p_material ); + Material *m = material_owner.get(p_material); ERR_FAIL_COND_V(!m, VS::FIXED_MATERIAL_TEXGEN_SPHERE); return m->texgen_mode; }; +void RasterizerIPhone::fixed_material_set_uv_transform(RID p_material, const Transform &p_transform) { -void RasterizerIPhone::fixed_material_set_uv_transform(RID p_material,const Transform& p_transform) { - - Material *m=material_owner.get( p_material ); + Material *m = material_owner.get(p_material); ERR_FAIL_COND(!m); m->uv_transform = p_transform; } Transform RasterizerIPhone::fixed_material_get_uv_transform(RID p_material) const { - Material *m=material_owner.get( p_material ); + Material *m = material_owner.get(p_material); ERR_FAIL_COND_V(!m, Transform()); return m->uv_transform; @@ -591,529 +551,505 @@ RID RasterizerIPhone::shader_material_create() const { return RID(); } -void RasterizerIPhone::shader_material_set_vertex_shader(RID p_material,RID p_shader,bool p_owned) { - - +void RasterizerIPhone::shader_material_set_vertex_shader(RID p_material, RID p_shader, bool p_owned) { } RID RasterizerIPhone::shader_material_get_vertex_shader(RID p_material) const { return RID(); } -void RasterizerIPhone::shader_material_set_fragment_shader(RID p_material,RID p_shader,bool p_owned) { - - +void RasterizerIPhone::shader_material_set_fragment_shader(RID p_material, RID p_shader, bool p_owned) { } RID RasterizerIPhone::shader_material_get_fragment_shader(RID p_material) const { return RID(); } - /* MESH API */ RID RasterizerIPhone::mesh_create() { - - return mesh_owner.make_rid( memnew( Mesh ) ); + return mesh_owner.make_rid(memnew(Mesh)); } -void RasterizerIPhone::mesh_add_surface(RID p_mesh,VS::PrimitiveType p_primitive,uint32_t p_format,int p_array_len,int p_index_array_len) { +void RasterizerIPhone::mesh_add_surface(RID p_mesh, VS::PrimitiveType p_primitive, uint32_t p_format, int p_array_len, int p_index_array_len) { - Mesh *mesh = mesh_owner.get( p_mesh ); + Mesh *mesh = mesh_owner.get(p_mesh); ERR_FAIL_COND(!mesh); - ERR_FAIL_COND((p_format&VS::ARRAY_FORMAT_VERTEX)==0); // mandatory - ERR_FAIL_COND( p_array_len<=0 ); - ERR_FAIL_COND( p_index_array_len==0 ); - ERR_FAIL_INDEX( p_primitive, VS::PRIMITIVE_MAX ); + ERR_FAIL_COND((p_format & VS::ARRAY_FORMAT_VERTEX) == 0); // mandatory + ERR_FAIL_COND(p_array_len <= 0); + ERR_FAIL_COND(p_index_array_len == 0); + ERR_FAIL_INDEX(p_primitive, VS::PRIMITIVE_MAX); - Surface *surface = memnew( Surface ); - ERR_FAIL_COND( !surface ); + Surface *surface = memnew(Surface); + ERR_FAIL_COND(!surface); - int total_elem_size=0; + int total_elem_size = 0; - bool use_VBO=true; //glGenBuffersARB!=NULL; // TODO detect if it's in there - if (p_format&VS::ARRAY_FORMAT_WEIGHTS) { + bool use_VBO = true; //glGenBuffersARB!=NULL; // TODO detect if it's in there + if (p_format & VS::ARRAY_FORMAT_WEIGHTS) { - use_VBO=false; + use_VBO = false; } + for (int i = 0; i < VS::ARRAY_MAX; i++) { - for (int i=0;i<VS::ARRAY_MAX;i++) { - + Surface::ArrayData &ad = surface->array[i]; + ad.size = 0; + ad.configured = false; + ad.ofs = 0; + int elem_size = 0; + int elem_count = 0; - Surface::ArrayData&ad=surface->array[i]; - ad.size=0; - ad.configured=false; - ad.ofs=0; - int elem_size=0; - int elem_count=0; - - if (!(p_format&(1<<i))) // no array + if (!(p_format & (1 << i))) // no array continue; - - switch(i) { + switch (i) { case VS::ARRAY_VERTEX: case VS::ARRAY_NORMAL: { - elem_size=3*sizeof(GLfloat); // vertex - elem_count=3; + elem_size = 3 * sizeof(GLfloat); // vertex + elem_count = 3; } break; case VS::ARRAY_TANGENT: { - elem_size=4*sizeof(GLfloat); // vertex - elem_count=4; + elem_size = 4 * sizeof(GLfloat); // vertex + elem_count = 4; } break; case VS::ARRAY_COLOR: { - elem_size=4; /* RGBA */ - elem_count=4; + elem_size = 4; /* RGBA */ + elem_count = 4; } break; case VS::ARRAY_TEX_UV: { - elem_size=2*sizeof(GLfloat); - elem_count=2; + elem_size = 2 * sizeof(GLfloat); + elem_count = 2; } break; case VS::ARRAY_WEIGHTS: case VS::ARRAY_BONES: { - elem_size=VS::ARRAY_WEIGHTS_SIZE*sizeof(GLfloat); - elem_count=VS::ARRAY_WEIGHTS_SIZE; + elem_size = VS::ARRAY_WEIGHTS_SIZE * sizeof(GLfloat); + elem_count = VS::ARRAY_WEIGHTS_SIZE; } break; case VS::ARRAY_INDEX: { - if (p_index_array_len<=0) { + if (p_index_array_len <= 0) { ERR_PRINT("p_index_array_len==NO_INDEX_ARRAY"); break; } /* determine wether using 8 or 16 bits indices */ - if (p_index_array_len>(1<<8)) { + if (p_index_array_len > (1 << 8)) { - elem_size=2; + elem_size = 2; } else { - elem_size=1; + elem_size = 1; } if (use_VBO) { - glGenBuffers(1,&surface->index_id); - ERR_FAIL_COND(surface->index_id==0); - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,surface->index_id); - glBufferData(GL_ELEMENT_ARRAY_BUFFER,p_index_array_len*elem_size,NULL,GL_STATIC_DRAW); - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,0); //unbind + glGenBuffers(1, &surface->index_id); + ERR_FAIL_COND(surface->index_id == 0); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, surface->index_id); + glBufferData(GL_ELEMENT_ARRAY_BUFFER, p_index_array_len * elem_size, NULL, GL_STATIC_DRAW); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); //unbind } else { - surface->index_array_local = (uint8_t*)memalloc(p_index_array_len*elem_size); + surface->index_array_local = (uint8_t *)memalloc(p_index_array_len * elem_size); }; - surface->index_array_len=p_index_array_len; // only way it can exist - ad.ofs=0; - ad.size=elem_size; - ad.configured=false; - ad.components=1; + surface->index_array_len = p_index_array_len; // only way it can exist + ad.ofs = 0; + ad.size = elem_size; + ad.configured = false; + ad.components = 1; continue; } break; default: { - ERR_FAIL( ); + ERR_FAIL(); } } - ad.ofs=total_elem_size; - ad.size=elem_size; - ad.components=elem_count; - total_elem_size+=elem_size; - ad.configured=false; + ad.ofs = total_elem_size; + ad.size = elem_size; + ad.components = elem_count; + total_elem_size += elem_size; + ad.configured = false; } - surface->stride=total_elem_size; - surface->array_len=p_array_len; - surface->format=p_format; - surface->primitive=p_primitive; - + surface->stride = total_elem_size; + surface->array_len = p_array_len; + surface->format = p_format; + surface->primitive = p_primitive; /* bind the bigass buffers */ if (use_VBO) { - glGenBuffers(1,&surface->vertex_id); - ERR_FAIL_COND(surface->vertex_id==0); - glBindBuffer(GL_ARRAY_BUFFER,surface->vertex_id); - glBufferData(GL_ARRAY_BUFFER,surface->array_len*surface->stride,NULL,GL_STATIC_DRAW); - glBindBuffer(GL_ARRAY_BUFFER,0); //unbind + glGenBuffers(1, &surface->vertex_id); + ERR_FAIL_COND(surface->vertex_id == 0); + glBindBuffer(GL_ARRAY_BUFFER, surface->vertex_id); + glBufferData(GL_ARRAY_BUFFER, surface->array_len * surface->stride, NULL, GL_STATIC_DRAW); + glBindBuffer(GL_ARRAY_BUFFER, 0); //unbind } else { - surface->array_local = (uint8_t*)memalloc(surface->array_len*surface->stride); + surface->array_local = (uint8_t *)memalloc(surface->array_len * surface->stride); }; mesh->surfaces.push_back(surface); } -Error RasterizerIPhone::mesh_surface_set_array(RID p_mesh, int p_surface,VS::ArrayType p_type,const Variant& p_array) { +Error RasterizerIPhone::mesh_surface_set_array(RID p_mesh, int p_surface, VS::ArrayType p_type, const Variant &p_array) { - ERR_FAIL_INDEX_V(p_type, VS::ARRAY_MAX, ERR_INVALID_PARAMETER ); + ERR_FAIL_INDEX_V(p_type, VS::ARRAY_MAX, ERR_INVALID_PARAMETER); - Mesh *mesh = mesh_owner.get( p_mesh ); - ERR_FAIL_COND_V(!mesh,ERR_INVALID_PARAMETER); - ERR_FAIL_INDEX_V(p_surface, mesh->surfaces.size(), ERR_INVALID_PARAMETER ); + Mesh *mesh = mesh_owner.get(p_mesh); + ERR_FAIL_COND_V(!mesh, ERR_INVALID_PARAMETER); + ERR_FAIL_INDEX_V(p_surface, mesh->surfaces.size(), ERR_INVALID_PARAMETER); Surface *surface = mesh->surfaces[p_surface]; - ERR_FAIL_COND_V( !surface, ERR_INVALID_PARAMETER ); + ERR_FAIL_COND_V(!surface, ERR_INVALID_PARAMETER); - ERR_FAIL_COND_V( surface->array[p_type].size==0, ERR_INVALID_PARAMETER ); + ERR_FAIL_COND_V(surface->array[p_type].size == 0, ERR_INVALID_PARAMETER); - Surface::ArrayData &a=surface->array[p_type]; + Surface::ArrayData &a = surface->array[p_type]; - switch(p_type) { + switch (p_type) { case VS::ARRAY_INDEX: { - ERR_FAIL_COND_V( surface->index_array_len<=0, ERR_INVALID_DATA ); - ERR_FAIL_COND_V( p_array.get_type() != Variant::INT_ARRAY, ERR_INVALID_PARAMETER ); + ERR_FAIL_COND_V(surface->index_array_len <= 0, ERR_INVALID_DATA); + ERR_FAIL_COND_V(p_array.get_type() != Variant::INT_ARRAY, ERR_INVALID_PARAMETER); PoolVector<int> indices = p_array; - ERR_FAIL_COND_V( indices.size() == 0, ERR_INVALID_PARAMETER ); - ERR_FAIL_COND_V( indices.size() != surface->index_array_len, ERR_INVALID_PARAMETER ); + ERR_FAIL_COND_V(indices.size() == 0, ERR_INVALID_PARAMETER); + ERR_FAIL_COND_V(indices.size() != surface->index_array_len, ERR_INVALID_PARAMETER); /* determine wether using 16 or 32 bits indices */ if (surface->index_array_local == 0) { - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,surface->index_id); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, surface->index_id); }; PoolVector<int>::Read read = indices.read(); - const int *src=read.ptr(); + const int *src = read.ptr(); - for (int i=0;i<surface->index_array_len;i++) { + for (int i = 0; i < surface->index_array_len; i++) { if (surface->index_array_local) { - if (a.size<=(1<<8)) { - uint8_t v=src[i]; + if (a.size <= (1 << 8)) { + uint8_t v = src[i]; - copymem(&surface->array_local[i*a.size], &v, a.size); + copymem(&surface->array_local[i * a.size], &v, a.size); } else { - uint16_t v=src[i]; + uint16_t v = src[i]; - copymem(&surface->array_local[i*a.size], &v, a.size); + copymem(&surface->array_local[i * a.size], &v, a.size); } } else { - if (a.size<=(1<<8)) { - uint8_t v=src[i]; + if (a.size <= (1 << 8)) { + uint8_t v = src[i]; - glBufferSubData( GL_ELEMENT_ARRAY_BUFFER, i*a.size, a.size, &v ); + glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, i * a.size, a.size, &v); } else { - uint16_t v=src[i]; - - glBufferSubData( GL_ELEMENT_ARRAY_BUFFER, i*a.size, a.size, &v ); + uint16_t v = src[i]; + glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, i * a.size, a.size, &v); } }; } if (surface->index_array_local == 0) { - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,0); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); }; - a.configured=true; + a.configured = true; return OK; } break; case VS::ARRAY_VERTEX: case VS::ARRAY_NORMAL: { - ERR_FAIL_COND_V( p_array.get_type() != Variant::VECTOR3_ARRAY, ERR_INVALID_PARAMETER ); - + ERR_FAIL_COND_V(p_array.get_type() != Variant::VECTOR3_ARRAY, ERR_INVALID_PARAMETER); PoolVector<Vector3> array = p_array; - ERR_FAIL_COND_V( array.size() != surface->array_len, ERR_INVALID_PARAMETER ); + ERR_FAIL_COND_V(array.size() != surface->array_len, ERR_INVALID_PARAMETER); if (surface->array_local == 0) { - glBindBuffer(GL_ARRAY_BUFFER,surface->vertex_id); + glBindBuffer(GL_ARRAY_BUFFER, surface->vertex_id); }; PoolVector<Vector3>::Read read = array.read(); - const Vector3* src=read.ptr(); + const Vector3 *src = read.ptr(); // setting vertices means regenerating the AABB - if (p_type==VS::ARRAY_VERTEX) - surface->aabb=AABB(); - - for (int i=0;i<surface->array_len;i++) { + if (p_type == VS::ARRAY_VERTEX) + surface->aabb = AABB(); + for (int i = 0; i < surface->array_len; i++) { - GLfloat vector[3]={ src[i].x, src[i].y, src[i].z }; + GLfloat vector[3] = { src[i].x, src[i].y, src[i].z }; if (surface->array_local == 0) { - glBufferSubData( GL_ARRAY_BUFFER, a.ofs+i*surface->stride, a.size , vector ); + glBufferSubData(GL_ARRAY_BUFFER, a.ofs + i * surface->stride, a.size, vector); } else { - copymem(&surface->array_local[a.ofs+i*surface->stride], vector, a.size); + copymem(&surface->array_local[a.ofs + i * surface->stride], vector, a.size); } - if (p_type==VS::ARRAY_VERTEX) { + if (p_type == VS::ARRAY_VERTEX) { - if (i==0) { + if (i == 0) { - surface->aabb=AABB(src[i],Vector3()); + surface->aabb = AABB(src[i], Vector3()); } else { - surface->aabb.expand_to( src[i] ); + surface->aabb.expand_to(src[i]); } } } if (surface->array_local == 0) { - glBindBuffer(GL_ARRAY_BUFFER,0); + glBindBuffer(GL_ARRAY_BUFFER, 0); }; } break; case VS::ARRAY_TANGENT: { - ERR_FAIL_COND_V( p_array.get_type() != Variant::REAL_ARRAY, ERR_INVALID_PARAMETER ); + ERR_FAIL_COND_V(p_array.get_type() != Variant::REAL_ARRAY, ERR_INVALID_PARAMETER); PoolVector<real_t> array = p_array; - ERR_FAIL_COND_V( array.size() != surface->array_len*4, ERR_INVALID_PARAMETER ); + ERR_FAIL_COND_V(array.size() != surface->array_len * 4, ERR_INVALID_PARAMETER); if (surface->array_local == 0) { - glBindBuffer(GL_ARRAY_BUFFER,surface->vertex_id); + glBindBuffer(GL_ARRAY_BUFFER, surface->vertex_id); }; - PoolVector<real_t>::Read read = array.read(); - const real_t* src = read.ptr(); + const real_t *src = read.ptr(); - for (int i=0;i<surface->array_len;i++) { + for (int i = 0; i < surface->array_len; i++) { - GLfloat xyzw[4]={ - src[i*4+0], - src[i*4+1], - src[i*4+2], - src[i*4+3] + GLfloat xyzw[4] = { + src[i * 4 + 0], + src[i * 4 + 1], + src[i * 4 + 2], + src[i * 4 + 3] }; if (surface->array_local == 0) { - glBufferSubData( GL_ARRAY_BUFFER, a.ofs+i*surface->stride, a.size , xyzw ); + glBufferSubData(GL_ARRAY_BUFFER, a.ofs + i * surface->stride, a.size, xyzw); } else { - copymem(&surface->array_local[a.ofs+i*surface->stride], xyzw, a.size); + copymem(&surface->array_local[a.ofs + i * surface->stride], xyzw, a.size); }; - } if (surface->array_local == 0) { - glBindBuffer(GL_ARRAY_BUFFER,0); + glBindBuffer(GL_ARRAY_BUFFER, 0); }; } break; case VS::ARRAY_COLOR: { - ERR_FAIL_COND_V( p_array.get_type() != Variant::COLOR_ARRAY, ERR_INVALID_PARAMETER ); - + ERR_FAIL_COND_V(p_array.get_type() != Variant::COLOR_ARRAY, ERR_INVALID_PARAMETER); PoolVector<Color> array = p_array; - ERR_FAIL_COND_V( array.size() != surface->array_len, ERR_INVALID_PARAMETER ); + ERR_FAIL_COND_V(array.size() != surface->array_len, ERR_INVALID_PARAMETER); if (surface->array_local == 0) - glBindBuffer(GL_ARRAY_BUFFER,surface->vertex_id); - + glBindBuffer(GL_ARRAY_BUFFER, surface->vertex_id); PoolVector<Color>::Read read = array.read(); - const Color* src = read.ptr(); - surface->has_alpha_cache=false; + const Color *src = read.ptr(); + surface->has_alpha_cache = false; - for (int i=0;i<surface->array_len;i++) { + for (int i = 0; i < surface->array_len; i++) { - if (src[i].a<0.98) // tolerate alpha a bit, for crappy exporters - surface->has_alpha_cache=true; - uint8_t colors[4]={ src[i].r * 255.0 , src[i].g * 255.0, src[i].b * 255.0, src[i].a * 255.0 }; + if (src[i].a < 0.98) // tolerate alpha a bit, for crappy exporters + surface->has_alpha_cache = true; + uint8_t colors[4] = { src[i].r * 255.0, src[i].g * 255.0, src[i].b * 255.0, src[i].a * 255.0 }; // I'm not sure if this is correct, endianness-wise, i should re-check the GL spec if (surface->array_local == 0) - glBufferSubData( GL_ARRAY_BUFFER, a.ofs+i*surface->stride, a.size , colors ); + glBufferSubData(GL_ARRAY_BUFFER, a.ofs + i * surface->stride, a.size, colors); else - copymem(&surface->array_local[a.ofs+i*surface->stride], colors, a.size); - + copymem(&surface->array_local[a.ofs + i * surface->stride], colors, a.size); } if (surface->array_local == 0) - glBindBuffer(GL_ARRAY_BUFFER,0); - + glBindBuffer(GL_ARRAY_BUFFER, 0); } break; case VS::ARRAY_TEX_UV: { - ERR_FAIL_COND_V( p_array.get_type() != Variant::VECTOR3_ARRAY, ERR_INVALID_PARAMETER ); + ERR_FAIL_COND_V(p_array.get_type() != Variant::VECTOR3_ARRAY, ERR_INVALID_PARAMETER); PoolVector<Vector3> array = p_array; - ERR_FAIL_COND_V( array.size() != surface->array_len , ERR_INVALID_PARAMETER); + ERR_FAIL_COND_V(array.size() != surface->array_len, ERR_INVALID_PARAMETER); if (surface->array_local == 0) - glBindBuffer(GL_ARRAY_BUFFER,surface->vertex_id); + glBindBuffer(GL_ARRAY_BUFFER, surface->vertex_id); PoolVector<Vector3>::Read read = array.read(); - const Vector3 * src=read.ptr(); + const Vector3 *src = read.ptr(); - for (int i=0;i<surface->array_len;i++) { + for (int i = 0; i < surface->array_len; i++) { - GLfloat uv[2]={ src[i].x , src[i].y }; + GLfloat uv[2] = { src[i].x, src[i].y }; if (surface->array_local == 0) - glBufferSubData( GL_ARRAY_BUFFER, a.ofs+i*surface->stride, a.size , uv ); + glBufferSubData(GL_ARRAY_BUFFER, a.ofs + i * surface->stride, a.size, uv); else - copymem(&surface->array_local[a.ofs+i*surface->stride], uv, a.size); - + copymem(&surface->array_local[a.ofs + i * surface->stride], uv, a.size); } if (surface->array_local == 0) - glBindBuffer(GL_ARRAY_BUFFER,0); + glBindBuffer(GL_ARRAY_BUFFER, 0); } break; case VS::ARRAY_BONES: case VS::ARRAY_WEIGHTS: { - - ERR_FAIL_COND_V( p_array.get_type() != Variant::REAL_ARRAY, ERR_INVALID_PARAMETER ); + ERR_FAIL_COND_V(p_array.get_type() != Variant::REAL_ARRAY, ERR_INVALID_PARAMETER); PoolVector<real_t> array = p_array; - ERR_FAIL_COND_V( array.size() != surface->array_len*VS::ARRAY_WEIGHTS_SIZE, ERR_INVALID_PARAMETER ); + ERR_FAIL_COND_V(array.size() != surface->array_len * VS::ARRAY_WEIGHTS_SIZE, ERR_INVALID_PARAMETER); if (surface->array_local == 0) - glBindBuffer(GL_ARRAY_BUFFER,surface->vertex_id); + glBindBuffer(GL_ARRAY_BUFFER, surface->vertex_id); PoolVector<real_t>::Read read = array.read(); - const real_t * src = read.ptr(); + const real_t *src = read.ptr(); - for (int i=0;i<surface->array_len;i++) { + for (int i = 0; i < surface->array_len; i++) { GLfloat data[VS::ARRAY_WEIGHTS_SIZE]; - for (int j=0;j<VS::ARRAY_WEIGHTS_SIZE;j++) - data[j]=src[i*VS::ARRAY_WEIGHTS_SIZE+j]; + for (int j = 0; j < VS::ARRAY_WEIGHTS_SIZE; j++) + data[j] = src[i * VS::ARRAY_WEIGHTS_SIZE + j]; if (surface->array_local == 0) - glBufferSubData( GL_ARRAY_BUFFER, a.ofs+i*surface->stride, a.size , data ); + glBufferSubData(GL_ARRAY_BUFFER, a.ofs + i * surface->stride, a.size, data); else - copymem(&surface->array_local[a.ofs+i*surface->stride], data, a.size); - - + copymem(&surface->array_local[a.ofs + i * surface->stride], data, a.size); } if (surface->array_local == 0) - glBindBuffer(GL_ARRAY_BUFFER,0); + glBindBuffer(GL_ARRAY_BUFFER, 0); } break; - default: { ERR_FAIL_V(ERR_INVALID_PARAMETER);} + default: { ERR_FAIL_V(ERR_INVALID_PARAMETER); } } - a.configured=true; + a.configured = true; return OK; } -Variant RasterizerIPhone::mesh_surface_get_array(RID p_mesh, int p_surface,VS::ArrayType p_type) const { +Variant RasterizerIPhone::mesh_surface_get_array(RID p_mesh, int p_surface, VS::ArrayType p_type) const { return Variant(); } -void RasterizerIPhone::mesh_surface_set_material(RID p_mesh, int p_surface, RID p_material,bool p_owned) { +void RasterizerIPhone::mesh_surface_set_material(RID p_mesh, int p_surface, RID p_material, bool p_owned) { - Mesh *mesh = mesh_owner.get( p_mesh ); + Mesh *mesh = mesh_owner.get(p_mesh); ERR_FAIL_COND(!mesh); - ERR_FAIL_INDEX(p_surface, mesh->surfaces.size() ); + ERR_FAIL_INDEX(p_surface, mesh->surfaces.size()); Surface *surface = mesh->surfaces[p_surface]; - ERR_FAIL_COND( !surface); + ERR_FAIL_COND(!surface); if (surface->material_owned && surface->material.is_valid()) free(surface->material); - surface->material_owned=p_owned; + surface->material_owned = p_owned; - surface->material=p_material; + surface->material = p_material; } RID RasterizerIPhone::mesh_surface_get_material(RID p_mesh, int p_surface) const { - Mesh *mesh = mesh_owner.get( p_mesh ); - ERR_FAIL_COND_V(!mesh,RID()); - ERR_FAIL_INDEX_V(p_surface, mesh->surfaces.size(), RID() ); + Mesh *mesh = mesh_owner.get(p_mesh); + ERR_FAIL_COND_V(!mesh, RID()); + ERR_FAIL_INDEX_V(p_surface, mesh->surfaces.size(), RID()); Surface *surface = mesh->surfaces[p_surface]; - ERR_FAIL_COND_V( !surface, RID() ); + ERR_FAIL_COND_V(!surface, RID()); return surface->material; } int RasterizerIPhone::mesh_surface_get_array_len(RID p_mesh, int p_surface) const { - Mesh *mesh = mesh_owner.get( p_mesh ); - ERR_FAIL_COND_V(!mesh,-1); - ERR_FAIL_INDEX_V(p_surface, mesh->surfaces.size(), -1 ); + Mesh *mesh = mesh_owner.get(p_mesh); + ERR_FAIL_COND_V(!mesh, -1); + ERR_FAIL_INDEX_V(p_surface, mesh->surfaces.size(), -1); Surface *surface = mesh->surfaces[p_surface]; - ERR_FAIL_COND_V( !surface, -1 ); + ERR_FAIL_COND_V(!surface, -1); return surface->array_len; } int RasterizerIPhone::mesh_surface_get_array_index_len(RID p_mesh, int p_surface) const { - Mesh *mesh = mesh_owner.get( p_mesh ); - ERR_FAIL_COND_V(!mesh,-1); - ERR_FAIL_INDEX_V(p_surface, mesh->surfaces.size(), -1 ); - Surface *surface = mesh->surfaces[p_surface]; - ERR_FAIL_COND_V( !surface, -1 ); + Mesh *mesh = mesh_owner.get(p_mesh); + ERR_FAIL_COND_V(!mesh, -1); + ERR_FAIL_INDEX_V(p_surface, mesh->surfaces.size(), -1); + Surface *surface = mesh->surfaces[p_surface]; + ERR_FAIL_COND_V(!surface, -1); - return surface->index_array_len; + return surface->index_array_len; } uint32_t RasterizerIPhone::mesh_surface_get_format(RID p_mesh, int p_surface) const { - Mesh *mesh = mesh_owner.get( p_mesh ); - ERR_FAIL_COND_V(!mesh,0); - ERR_FAIL_INDEX_V(p_surface, mesh->surfaces.size(), 0 ); + Mesh *mesh = mesh_owner.get(p_mesh); + ERR_FAIL_COND_V(!mesh, 0); + ERR_FAIL_INDEX_V(p_surface, mesh->surfaces.size(), 0); Surface *surface = mesh->surfaces[p_surface]; - ERR_FAIL_COND_V( !surface, 0 ); + ERR_FAIL_COND_V(!surface, 0); return surface->format; } VS::PrimitiveType RasterizerIPhone::mesh_surface_get_primitive_type(RID p_mesh, int p_surface) const { - Mesh *mesh = mesh_owner.get( p_mesh ); - ERR_FAIL_COND_V(!mesh,VS::PRIMITIVE_POINTS); - ERR_FAIL_INDEX_V(p_surface, mesh->surfaces.size(), VS::PRIMITIVE_POINTS ); + Mesh *mesh = mesh_owner.get(p_mesh); + ERR_FAIL_COND_V(!mesh, VS::PRIMITIVE_POINTS); + ERR_FAIL_INDEX_V(p_surface, mesh->surfaces.size(), VS::PRIMITIVE_POINTS); Surface *surface = mesh->surfaces[p_surface]; - ERR_FAIL_COND_V( !surface, VS::PRIMITIVE_POINTS ); + ERR_FAIL_COND_V(!surface, VS::PRIMITIVE_POINTS); return surface->primitive; } -void RasterizerIPhone::mesh_erase_surface(RID p_mesh,int p_index) { +void RasterizerIPhone::mesh_erase_surface(RID p_mesh, int p_index) { - Mesh *mesh = mesh_owner.get( p_mesh ); + Mesh *mesh = mesh_owner.get(p_mesh); ERR_FAIL_COND(!mesh); - ERR_FAIL_INDEX(p_index, mesh->surfaces.size() ); + ERR_FAIL_INDEX(p_index, mesh->surfaces.size()); Surface *surface = mesh->surfaces[p_index]; - ERR_FAIL_COND( !surface); + ERR_FAIL_COND(!surface); - memdelete( mesh->surfaces[p_index] ); + memdelete(mesh->surfaces[p_index]); mesh->surfaces.remove(p_index); - } int RasterizerIPhone::mesh_get_surface_count(RID p_mesh) const { - Mesh *mesh = mesh_owner.get( p_mesh ); - ERR_FAIL_COND_V(!mesh,-1); + Mesh *mesh = mesh_owner.get(p_mesh); + ERR_FAIL_COND_V(!mesh, -1); return mesh->surfaces.size(); } AABB RasterizerIPhone::mesh_get_aabb(RID p_mesh) const { - Mesh *mesh = mesh_owner.get( p_mesh ); - ERR_FAIL_COND_V(!mesh,AABB()); + Mesh *mesh = mesh_owner.get(p_mesh); + ERR_FAIL_COND_V(!mesh, AABB()); AABB aabb; - for (int i=0;i<mesh->surfaces.size();i++) { + for (int i = 0; i < mesh->surfaces.size(); i++) { - if (i==0) - aabb=mesh->surfaces[i]->aabb; + if (i == 0) + aabb = mesh->surfaces[i]->aabb; else aabb.merge_with(mesh->surfaces[i]->aabb); } @@ -1128,30 +1064,20 @@ RID RasterizerIPhone::multimesh_create() { return RID(); } -void RasterizerIPhone::multimesh_set_instance_count(RID p_multimesh,int p_count) { - - +void RasterizerIPhone::multimesh_set_instance_count(RID p_multimesh, int p_count) { } int RasterizerIPhone::multimesh_get_instance_count(RID p_multimesh) const { return 0; } -void RasterizerIPhone::multimesh_set_mesh(RID p_multimesh,RID p_mesh) { - - +void RasterizerIPhone::multimesh_set_mesh(RID p_multimesh, RID p_mesh) { } -void RasterizerIPhone::multimesh_set_aabb(RID p_multimesh,const AABB& p_aabb) { - - +void RasterizerIPhone::multimesh_set_aabb(RID p_multimesh, const AABB &p_aabb) { } -void RasterizerIPhone::multimesh_instance_set_transform(RID p_multimesh,int p_index,const Transform& p_transform) { - - +void RasterizerIPhone::multimesh_instance_set_transform(RID p_multimesh, int p_index, const Transform &p_transform) { } -void RasterizerIPhone::multimesh_instance_set_color(RID p_multimesh,int p_index,const Color& p_color) { - - +void RasterizerIPhone::multimesh_instance_set_color(RID p_multimesh, int p_index, const Color &p_color) { } RID RasterizerIPhone::multimesh_get_mesh(RID p_multimesh) const { @@ -1163,11 +1089,11 @@ AABB RasterizerIPhone::multimesh_get_aabb(RID p_multimesh) const { return AABB(); } -Transform RasterizerIPhone::multimesh_instance_get_transform(RID p_multimesh,int p_index) const { +Transform RasterizerIPhone::multimesh_instance_get_transform(RID p_multimesh, int p_index) const { return Transform(); } -Color RasterizerIPhone::multimesh_instance_get_color(RID p_multimesh,int p_index) const { +Color RasterizerIPhone::multimesh_instance_get_color(RID p_multimesh, int p_index) const { return Color(); } @@ -1178,17 +1104,11 @@ RID RasterizerIPhone::poly_create() { return RID(); } -void RasterizerIPhone::poly_set_material(RID p_poly, RID p_material,bool p_owned) { - - +void RasterizerIPhone::poly_set_material(RID p_poly, RID p_material, bool p_owned) { } -void RasterizerIPhone::poly_add_primitive(RID p_poly, const Vector<Vector3>& p_points,const Vector<Vector3>& p_normals,const Vector<Color>& p_colors,const Vector<Vector3>& p_uvs) { - - +void RasterizerIPhone::poly_add_primitive(RID p_poly, const Vector<Vector3> &p_points, const Vector<Vector3> &p_normals, const Vector<Color> &p_colors, const Vector<Vector3> &p_uvs) { } void RasterizerIPhone::poly_clear(RID p_poly) { - - } AABB RasterizerIPhone::poly_get_aabb(RID p_poly) const { @@ -1196,7 +1116,6 @@ AABB RasterizerIPhone::poly_get_aabb(RID p_poly) const { return AABB(); } - /* PARTICLES API */ RID RasterizerIPhone::particles_create() { @@ -1205,8 +1124,6 @@ RID RasterizerIPhone::particles_create() { } void RasterizerIPhone::particles_set_amount(RID p_particles, int p_amount) { - - } int RasterizerIPhone::particles_get_amount(RID p_particles) const { @@ -1214,8 +1131,6 @@ int RasterizerIPhone::particles_get_amount(RID p_particles) const { } void RasterizerIPhone::particles_set_emitting(RID p_particles, bool p_emitting) { - - } bool RasterizerIPhone::particles_is_emitting(RID p_particles) const { @@ -1223,45 +1138,35 @@ bool RasterizerIPhone::particles_is_emitting(RID p_particles) const { return false; } -void RasterizerIPhone::particles_set_visibility_aabb(RID p_particles, const AABB& p_visibility) { - - +void RasterizerIPhone::particles_set_visibility_aabb(RID p_particles, const AABB &p_visibility) { } AABB RasterizerIPhone::particles_get_visibility_aabb(RID p_particles) const { return AABB(); } -void RasterizerIPhone::particles_set_emission_half_extents(RID p_particles, const Vector3& p_half_extents) { - - +void RasterizerIPhone::particles_set_emission_half_extents(RID p_particles, const Vector3 &p_half_extents) { } Vector3 RasterizerIPhone::particles_get_emission_half_extents(RID p_particles) const { return Vector3(); } -void RasterizerIPhone::particles_set_gravity_normal(RID p_particles, const Vector3& p_normal) { - - +void RasterizerIPhone::particles_set_gravity_normal(RID p_particles, const Vector3 &p_normal) { } Vector3 RasterizerIPhone::particles_get_gravity_normal(RID p_particles) const { return Vector3(); } -void RasterizerIPhone::particles_set_variable(RID p_particles, VS::ParticleVariable p_variable,float p_value) { - - +void RasterizerIPhone::particles_set_variable(RID p_particles, VS::ParticleVariable p_variable, float p_value) { } float RasterizerIPhone::particles_get_variable(RID p_particles, VS::ParticleVariable p_variable) const { return 0; } -void RasterizerIPhone::particles_set_randomness(RID p_particles, VS::ParticleVariable p_variable,float p_randomness) { - - +void RasterizerIPhone::particles_set_randomness(RID p_particles, VS::ParticleVariable p_variable, float p_randomness) { } float RasterizerIPhone::particles_get_randomness(RID p_particles, VS::ParticleVariable p_variable) const { @@ -1269,8 +1174,6 @@ float RasterizerIPhone::particles_get_randomness(RID p_particles, VS::ParticleVa } void RasterizerIPhone::particles_set_color_phase_pos(RID p_particles, int p_phase, float p_pos) { - - } float RasterizerIPhone::particles_get_color_phase_pos(RID p_particles, int p_phase) const { @@ -1278,17 +1181,13 @@ float RasterizerIPhone::particles_get_color_phase_pos(RID p_particles, int p_pha } void RasterizerIPhone::particles_set_color_phases(RID p_particles, int p_phases) { - - } int RasterizerIPhone::particles_get_color_phases(RID p_particles) const { return 0; } -void RasterizerIPhone::particles_set_color_phase_color(RID p_particles, int p_phase, const Color& p_color) { - - +void RasterizerIPhone::particles_set_color_phase_color(RID p_particles, int p_phase, const Color &p_color) { } Color RasterizerIPhone::particles_get_color_phase_color(RID p_particles, int p_phase) const { @@ -1296,35 +1195,27 @@ Color RasterizerIPhone::particles_get_color_phase_color(RID p_particles, int p_p } void RasterizerIPhone::particles_set_attractors(RID p_particles, int p_attractors) { - - } int RasterizerIPhone::particles_get_attractors(RID p_particles) const { return 0; } -void RasterizerIPhone::particles_set_attractor_pos(RID p_particles, int p_attractor, const Vector3& p_pos) { - - +void RasterizerIPhone::particles_set_attractor_pos(RID p_particles, int p_attractor, const Vector3 &p_pos) { } -Vector3 RasterizerIPhone::particles_get_attractor_pos(RID p_particles,int p_attractor) const { +Vector3 RasterizerIPhone::particles_get_attractor_pos(RID p_particles, int p_attractor) const { return Vector3(); } void RasterizerIPhone::particles_set_attractor_strength(RID p_particles, int p_attractor, float p_force) { - - } -float RasterizerIPhone::particles_get_attractor_strength(RID p_particles,int p_attractor) const { +float RasterizerIPhone::particles_get_attractor_strength(RID p_particles, int p_attractor) const { return 0; } -void RasterizerIPhone::particles_set_material(RID p_particles, RID p_material,bool p_owned) { - - +void RasterizerIPhone::particles_set_material(RID p_particles, RID p_material, bool p_owned) { } RID RasterizerIPhone::particles_get_material(RID p_particles) const { @@ -1344,30 +1235,22 @@ RID RasterizerIPhone::beam_create() { } void RasterizerIPhone::beam_set_point_count(RID p_beam, int p_count) { - - } int RasterizerIPhone::beam_get_point_count(RID p_beam) const { return 0; } void RasterizerIPhone::beam_clear(RID p_beam) { - - } -void RasterizerIPhone::beam_set_point(RID p_beam,int p_point,Vector3& p_pos) { - - +void RasterizerIPhone::beam_set_point(RID p_beam, int p_point, Vector3 &p_pos) { } -Vector3 RasterizerIPhone::beam_get_point(RID p_beam,int p_point) const { +Vector3 RasterizerIPhone::beam_get_point(RID p_beam, int p_point) const { return Vector3(); } -void RasterizerIPhone::beam_set_primitive(RID p_beam,VS::BeamPrimitive p_primitive) { - - +void RasterizerIPhone::beam_set_primitive(RID p_beam, VS::BeamPrimitive p_primitive) { } VS::BeamPrimitive RasterizerIPhone::beam_get_primitive(RID p_beam) const { @@ -1376,8 +1259,6 @@ VS::BeamPrimitive RasterizerIPhone::beam_get_primitive(RID p_beam) const { } void RasterizerIPhone::beam_set_material(RID p_beam, RID p_material) { - - } RID RasterizerIPhone::beam_get_material(RID p_beam) const { @@ -1392,154 +1273,151 @@ AABB RasterizerIPhone::beam_get_aabb(RID p_particles) const { RID RasterizerIPhone::skeleton_create() { - Skeleton *skeleton = memnew( Skeleton ); - ERR_FAIL_COND_V(!skeleton,RID()); - return skeleton_owner.make_rid( skeleton ); + Skeleton *skeleton = memnew(Skeleton); + ERR_FAIL_COND_V(!skeleton, RID()); + return skeleton_owner.make_rid(skeleton); } -void RasterizerIPhone::skeleton_resize(RID p_skeleton,int p_bones) { +void RasterizerIPhone::skeleton_resize(RID p_skeleton, int p_bones) { - Skeleton *skeleton = skeleton_owner.get( p_skeleton ); + Skeleton *skeleton = skeleton_owner.get(p_skeleton); ERR_FAIL_COND(!skeleton); if (p_bones == skeleton->bones.size()) { return; }; - ERR_FAIL_COND( p_bones<0 || p_bones>256); + ERR_FAIL_COND(p_bones < 0 || p_bones > 256); skeleton->bones.resize(p_bones); - } int RasterizerIPhone::skeleton_get_bone_count(RID p_skeleton) const { - Skeleton *skeleton = skeleton_owner.get( p_skeleton ); + Skeleton *skeleton = skeleton_owner.get(p_skeleton); ERR_FAIL_COND_V(!skeleton, -1); return skeleton->bones.size(); } -void RasterizerIPhone::skeleton_bone_set_transform(RID p_skeleton,int p_bone, const Transform& p_transform) { +void RasterizerIPhone::skeleton_bone_set_transform(RID p_skeleton, int p_bone, const Transform &p_transform) { - Skeleton *skeleton = skeleton_owner.get( p_skeleton ); + Skeleton *skeleton = skeleton_owner.get(p_skeleton); ERR_FAIL_COND(!skeleton); - ERR_FAIL_INDEX( p_bone, skeleton->bones.size() ); + ERR_FAIL_INDEX(p_bone, skeleton->bones.size()); skeleton->bones[p_bone] = p_transform; } -Transform RasterizerIPhone::skeleton_bone_get_transform(RID p_skeleton,int p_bone) { +Transform RasterizerIPhone::skeleton_bone_get_transform(RID p_skeleton, int p_bone) { - Skeleton *skeleton = skeleton_owner.get( p_skeleton ); + Skeleton *skeleton = skeleton_owner.get(p_skeleton); ERR_FAIL_COND_V(!skeleton, Transform()); - ERR_FAIL_INDEX_V( p_bone, skeleton->bones.size(), Transform() ); + ERR_FAIL_INDEX_V(p_bone, skeleton->bones.size(), Transform()); // something return skeleton->bones[p_bone]; } - /* LIGHT API */ RID RasterizerIPhone::light_create(VS::LightType p_type) { - Light *light = memnew( Light ); - light->type=p_type; + Light *light = memnew(Light); + light->type = p_type; return light_owner.make_rid(light); } VS::LightType RasterizerIPhone::light_get_type(RID p_light) const { Light *light = light_owner.get(p_light); - ERR_FAIL_COND_V(!light,VS::LIGHT_OMNI); + ERR_FAIL_COND_V(!light, VS::LIGHT_OMNI); return light->type; } -void RasterizerIPhone::light_set_color(RID p_light,VS::LightColor p_type, const Color& p_color) { +void RasterizerIPhone::light_set_color(RID p_light, VS::LightColor p_type, const Color &p_color) { Light *light = light_owner.get(p_light); ERR_FAIL_COND(!light); - ERR_FAIL_INDEX( p_type, 3 ); - light->colors[p_type]=p_color; + ERR_FAIL_INDEX(p_type, 3); + light->colors[p_type] = p_color; } -Color RasterizerIPhone::light_get_color(RID p_light,VS::LightColor p_type) const { +Color RasterizerIPhone::light_get_color(RID p_light, VS::LightColor p_type) const { Light *light = light_owner.get(p_light); ERR_FAIL_COND_V(!light, Color()); - ERR_FAIL_INDEX_V( p_type, 3, Color() ); + ERR_FAIL_INDEX_V(p_type, 3, Color()); return light->colors[p_type]; } -void RasterizerIPhone::light_set_shadow(RID p_light,bool p_enabled) { +void RasterizerIPhone::light_set_shadow(RID p_light, bool p_enabled) { Light *light = light_owner.get(p_light); ERR_FAIL_COND(!light); - light->shadow_enabled=p_enabled; + light->shadow_enabled = p_enabled; } bool RasterizerIPhone::light_has_shadow(RID p_light) const { Light *light = light_owner.get(p_light); - ERR_FAIL_COND_V(!light,false); + ERR_FAIL_COND_V(!light, false); return light->shadow_enabled; } -void RasterizerIPhone::light_set_volumetric(RID p_light,bool p_enabled) { +void RasterizerIPhone::light_set_volumetric(RID p_light, bool p_enabled) { Light *light = light_owner.get(p_light); ERR_FAIL_COND(!light); - light->volumetric_enabled=p_enabled; - + light->volumetric_enabled = p_enabled; } bool RasterizerIPhone::light_is_volumetric(RID p_light) const { Light *light = light_owner.get(p_light); - ERR_FAIL_COND_V(!light,false); + ERR_FAIL_COND_V(!light, false); return light->volumetric_enabled; } -void RasterizerIPhone::light_set_projector(RID p_light,RID p_texture) { +void RasterizerIPhone::light_set_projector(RID p_light, RID p_texture) { Light *light = light_owner.get(p_light); ERR_FAIL_COND(!light); - light->projector=p_texture; + light->projector = p_texture; } RID RasterizerIPhone::light_get_projector(RID p_light) const { Light *light = light_owner.get(p_light); - ERR_FAIL_COND_V(!light,RID()); + ERR_FAIL_COND_V(!light, RID()); return light->projector; } void RasterizerIPhone::light_set_var(RID p_light, VS::LightParam p_var, float p_value) { - Light * light = light_owner.get( p_light ); + Light *light = light_owner.get(p_light); ERR_FAIL_COND(!light); - ERR_FAIL_INDEX( p_var, VS::LIGHT_PARAM_MAX ); + ERR_FAIL_INDEX(p_var, VS::LIGHT_PARAM_MAX); - light->vars[p_var]=p_value; + light->vars[p_var] = p_value; } float RasterizerIPhone::light_get_var(RID p_light, VS::LightParam p_var) const { - Light * light = light_owner.get( p_light ); - ERR_FAIL_COND_V(!light,0); + Light *light = light_owner.get(p_light); + ERR_FAIL_COND_V(!light, 0); - ERR_FAIL_INDEX_V( p_var, VS::LIGHT_PARAM_MAX,0 ); + ERR_FAIL_INDEX_V(p_var, VS::LIGHT_PARAM_MAX, 0); return light->vars[p_var]; } AABB RasterizerIPhone::light_get_aabb(RID p_light) const { - Light *light = light_owner.get( p_light ); - ERR_FAIL_COND_V(!light,AABB()); + Light *light = light_owner.get(p_light); + ERR_FAIL_COND_V(!light, AABB()); - switch( light->type ) { + switch (light->type) { case VS::LIGHT_SPOT: { - float len=light->vars[VS::LIGHT_PARAM_RADIUS]; - float size=Math::tan(Math::deg2rad(light->vars[VS::LIGHT_PARAM_SPOT_ANGLE]))*len; - return AABB( Vector3( -size,-size,-len ), Vector3( size*2, size*2, len ) ); + float len = light->vars[VS::LIGHT_PARAM_RADIUS]; + float size = Math::tan(Math::deg2rad(light->vars[VS::LIGHT_PARAM_SPOT_ANGLE])) * len; + return AABB(Vector3(-size, -size, -len), Vector3(size * 2, size * 2, len)); } break; case VS::LIGHT_OMNI: { float r = light->vars[VS::LIGHT_PARAM_RADIUS]; - return AABB( -Vector3(r,r,r), Vector3(r,r,r)*2 ); + return AABB(-Vector3(r, r, r), Vector3(r, r, r) * 2); } break; case VS::LIGHT_DIRECTIONAL: { @@ -1548,37 +1426,34 @@ AABB RasterizerIPhone::light_get_aabb(RID p_light) const { default: {} } - ERR_FAIL_V( AABB() ); + ERR_FAIL_V(AABB()); } - RID RasterizerIPhone::light_instance_create(RID p_light) { - Light *light = light_owner.get( p_light ); + Light *light = light_owner.get(p_light); ERR_FAIL_COND_V(!light, RID()); - LightInstance *light_instance = memnew( LightInstance ); + LightInstance *light_instance = memnew(LightInstance); - light_instance->light=p_light; - light_instance->base=light; - light_instance->last_pass=0; + light_instance->light = p_light; + light_instance->base = light; + light_instance->last_pass = 0; - return light_instance_owner.make_rid( light_instance ); + return light_instance_owner.make_rid(light_instance); } -void RasterizerIPhone::light_instance_set_transform(RID p_light_instance,const Transform& p_transform) { +void RasterizerIPhone::light_instance_set_transform(RID p_light_instance, const Transform &p_transform) { - LightInstance *lighti = light_instance_owner.get( p_light_instance ); + LightInstance *lighti = light_instance_owner.get(p_light_instance); ERR_FAIL_COND(!lighti); - lighti->transform=p_transform; - + lighti->transform = p_transform; } void RasterizerIPhone::light_instance_set_active_hint(RID p_light_instance) { - LightInstance *lighti = light_instance_owner.get( p_light_instance ); + LightInstance *lighti = light_instance_owner.get(p_light_instance); ERR_FAIL_COND(!lighti); - lighti->last_pass=frame; - + lighti->last_pass = frame; } bool RasterizerIPhone::light_instance_has_shadow(RID p_light_instance) const { @@ -1596,9 +1471,7 @@ int RasterizerIPhone::light_instance_get_shadow_passes(RID p_light_instance) con return 0; } -void RasterizerIPhone::light_instance_set_pssm_split_info(RID p_light_instance, int p_split, float p_near,float p_far, const CameraMatrix& p_camera, const Transform& p_transform) { - - +void RasterizerIPhone::light_instance_set_pssm_split_info(RID p_light_instance, int p_split, float p_near, float p_far, const CameraMatrix &p_camera, const Transform &p_transform) { } /* PARTICLES INSTANCE */ @@ -1607,32 +1480,30 @@ RID RasterizerIPhone::particles_instance_create(RID p_particles) { return RID(); } -void RasterizerIPhone::particles_instance_set_transform(RID p_particles_instance,const Transform& p_transform) { - - +void RasterizerIPhone::particles_instance_set_transform(RID p_particles_instance, const Transform &p_transform) { } /* RENDER API */ /* all calls (inside begin/end shadow) are always warranted to be in the following order: */ -static GLfloat rtri; // Angle For The Triangle ( NEW ) -static GLfloat rquad; // Angle For The Quad ( NEW ) +static GLfloat rtri; // Angle For The Triangle ( NEW ) +static GLfloat rquad; // Angle For The Quad ( NEW ) void RasterizerIPhone::begin_frame() { - window_size = Size2( OS::get_singleton()->get_video_mode().width, OS::get_singleton()->get_video_mode().height ); + window_size = Size2(OS::get_singleton()->get_video_mode().width, OS::get_singleton()->get_video_mode().height); - double time = (OS::get_singleton()->get_ticks_usec()/1000); // get msec - time/=1000.0; // make secs - time_delta=time-last_time; - last_time=time; + double time = (OS::get_singleton()->get_ticks_usec() / 1000); // get msec + time /= 1000.0; // make secs + time_delta = time - last_time; + last_time = time; frame++; - glClearColor(0,0,1,1); + glClearColor(0, 0, 1, 1); glClear(GL_COLOR_BUFFER_BIT); - /* nehe ?*/ +/* nehe ?*/ - #if 0 +#if 0 glViewport(0,0,window_size.width,window_size.height); // Reset The Current Viewport glMatrixMode(GL_PROJECTION); // Select The Projection Matrix @@ -1723,50 +1594,46 @@ void RasterizerIPhone::begin_frame() { rtri+=0.2f; // Increase The Rotation Variable For The Triangle ( NEW ) rquad-=0.15f; // Decrease The Rotation Variable For The Quad ( NEW ) - #endif - +#endif } -void RasterizerIPhone::set_viewport(const VS::ViewportRect& p_viewport) { - +void RasterizerIPhone::set_viewport(const VS::ViewportRect &p_viewport) { - viewport=p_viewport; - canvas_transform=Transform(); + viewport = p_viewport; + canvas_transform = Transform(); canvas_transform.translate(-(viewport.width / 2.0f), -(viewport.height / 2.0f), 0.0f); - canvas_transform.scale( Vector3( 2.0f / viewport.width, -2.0f / viewport.height, 1.0f ) ); + canvas_transform.scale(Vector3(2.0f / viewport.width, -2.0f / viewport.height, 1.0f)); - glViewport( viewport.x, window_size.height-(viewport.height+viewport.y), viewport.width,viewport.height ); + glViewport(viewport.x, window_size.height - (viewport.height + viewport.y), viewport.width, viewport.height); } -void RasterizerIPhone::begin_scene(RID p_fx,VS::ScenarioDebugMode p_debug) { +void RasterizerIPhone::begin_scene(RID p_fx, VS::ScenarioDebugMode p_debug) { opaque_render_list.clear(); alpha_render_list.clear(); - light_instance_count=0; + light_instance_count = 0; scene_fx = p_fx.is_valid() ? fx_owner.get(p_fx) : NULL; }; -void RasterizerIPhone::begin_shadow_map( RID p_light_instance, int p_shadow_pass ) { - - +void RasterizerIPhone::begin_shadow_map(RID p_light_instance, int p_shadow_pass) { } -void RasterizerIPhone::set_camera(const Transform& p_world,const CameraMatrix& p_projection) { +void RasterizerIPhone::set_camera(const Transform &p_world, const CameraMatrix &p_projection) { - camera_transform=p_world; - camera_transform_inverse=camera_transform.inverse(); - camera_projection=p_projection; - camera_plane = Plane( camera_transform.origin, camera_transform.basis.get_axis(2) ); - camera_z_near=camera_projection.get_z_near(); -camera_z_far=camera_projection.get_z_far(); - camera_projection.get_viewport_size(camera_vp_size.x,camera_vp_size.y); + camera_transform = p_world; + camera_transform_inverse = camera_transform.inverse(); + camera_projection = p_projection; + camera_plane = Plane(camera_transform.origin, camera_transform.basis.get_axis(2)); + camera_z_near = camera_projection.get_z_near(); + camera_z_far = camera_projection.get_z_far(); + camera_projection.get_viewport_size(camera_vp_size.x, camera_vp_size.y); } -void RasterizerIPhone::add_light( RID p_light_instance ) { +void RasterizerIPhone::add_light(RID p_light_instance) { #define LIGHT_FADE_TRESHOLD 0.05 - ERR_FAIL_COND( light_instance_count >= MAX_LIGHTS ); + ERR_FAIL_COND(light_instance_count >= MAX_LIGHTS); LightInstance *li = light_instance_owner.get(p_light_instance); ERR_FAIL_COND(!li); @@ -1776,200 +1643,193 @@ void RasterizerIPhone::add_light( RID p_light_instance ) { // actually, not really a hash, but helps to sort the lights // and avoid recompiling redudant shader versions - li->hash_aux=li->base->type; + li->hash_aux = li->base->type; if (li->base->shadow_enabled) - li->hash_aux|=(1<<3); + li->hash_aux |= (1 << 3); - if (li->base->projector.is_valid()) - li->hash_aux|=(1<<4); + if (li->base->projector.is_valid()) + li->hash_aux |= (1 << 4); - if (li->base->shadow_enabled && li->base->volumetric_enabled) - li->hash_aux|=(1<<5); + if (li->base->shadow_enabled && li->base->volumetric_enabled) + li->hash_aux |= (1 << 5); - switch(li->base->type) { + switch (li->base->type) { case VisualServer::LIGHT_DIRECTIONAL: { Vector3 dir = li->transform.basis.get_axis(2); - li->light_vector.x=dir.x; - li->light_vector.y=dir.y; - li->light_vector.z=dir.z; + li->light_vector.x = dir.x; + li->light_vector.y = dir.y; + li->light_vector.z = dir.z; } break; case VisualServer::LIGHT_OMNI: { - float radius = li->base->vars[VisualServer::LIGHT_PARAM_RADIUS]; - if (radius==0) - radius=0.0001; - li->linear_att=(1/LIGHT_FADE_TRESHOLD)/radius; - li->light_vector.x=li->transform.origin.x; - li->light_vector.y=li->transform.origin.y; - li->light_vector.z=li->transform.origin.z; + float radius = li->base->vars[VisualServer::LIGHT_PARAM_RADIUS]; + if (radius == 0) + radius = 0.0001; + li->linear_att = (1 / LIGHT_FADE_TRESHOLD) / radius; + li->light_vector.x = li->transform.origin.x; + li->light_vector.y = li->transform.origin.y; + li->light_vector.z = li->transform.origin.z; } break; case VisualServer::LIGHT_SPOT: { float radius = li->base->vars[VisualServer::LIGHT_PARAM_RADIUS]; - if (radius==0) - radius=0.0001; - li->linear_att=(1/LIGHT_FADE_TRESHOLD)/radius; - li->light_vector.x=li->transform.origin.x; - li->light_vector.y=li->transform.origin.y; - li->light_vector.z=li->transform.origin.z; + if (radius == 0) + radius = 0.0001; + li->linear_att = (1 / LIGHT_FADE_TRESHOLD) / radius; + li->light_vector.x = li->transform.origin.x; + li->light_vector.y = li->transform.origin.y; + li->light_vector.z = li->transform.origin.z; Vector3 dir = -li->transform.basis.get_axis(2); - li->spot_vector.x=dir.x; - li->spot_vector.y=dir.y; - li->spot_vector.z=dir.z; + li->spot_vector.x = dir.x; + li->spot_vector.y = dir.y; + li->spot_vector.z = dir.z; } break; - } + } - light_instances[light_instance_count++]=li; + light_instances[light_instance_count++] = li; } -void RasterizerIPhone::_add_geometry( const Geometry* p_geometry, const Transform& p_world, uint32_t p_vertex_format, const RID* p_light_instances, int p_light_count, const ParamOverrideMap* p_material_overrides,const Skeleton* p_skeleton, GeometryOwner *p_owner) { +void RasterizerIPhone::_add_geometry(const Geometry *p_geometry, const Transform &p_world, uint32_t p_vertex_format, const RID *p_light_instances, int p_light_count, const ParamOverrideMap *p_material_overrides, const Skeleton *p_skeleton, GeometryOwner *p_owner) { - Material *m=NULL; + Material *m = NULL; - if (p_geometry->material.is_valid()) - m=material_owner.get( p_geometry->material ); + if (p_geometry->material.is_valid()) + m = material_owner.get(p_geometry->material); - if (!m) { - m=material_owner.get( default_material ); - } + if (!m) { + m = material_owner.get(default_material); + } ERR_FAIL_COND(!m); LightInstance *lights[RenderList::MAX_LIGHTS]; - int light_count=0; + int light_count = 0; - RenderList *render_list=&opaque_render_list; - if (p_geometry->has_alpha || m->detail_blend_mode!=VS::MATERIAL_BLEND_MODE_MIX) { + RenderList *render_list = &opaque_render_list; + if (p_geometry->has_alpha || m->detail_blend_mode != VS::MATERIAL_BLEND_MODE_MIX) { render_list = &alpha_render_list; }; if (!m->flags[VS::MATERIAL_FLAG_UNSHADED]) { - light_count=p_light_count; - for(int i=0;i<light_count;i++) { - lights[i]=light_instance_owner.get( p_light_instances[i] ); + light_count = p_light_count; + for (int i = 0; i < light_count; i++) { + lights[i] = light_instance_owner.get(p_light_instances[i]); } } - render_list->add_element( p_geometry, m, p_world, lights, light_count, p_material_overrides,p_skeleton, camera_plane.distance(p_world.origin), p_owner ); + render_list->add_element(p_geometry, m, p_world, lights, light_count, p_material_overrides, p_skeleton, camera_plane.distance(p_world.origin), p_owner); } -void RasterizerIPhone::add_mesh( RID p_mesh, const Transform* p_world, const RID* p_light_instances, int p_light_count, const ParamOverrideMap* p_material_overrides, RID p_skeleton) { +void RasterizerIPhone::add_mesh(RID p_mesh, const Transform *p_world, const RID *p_light_instances, int p_light_count, const ParamOverrideMap *p_material_overrides, RID p_skeleton) { Mesh *mesh = mesh_owner.get(p_mesh); int ssize = mesh->surfaces.size(); - for (int i=0;i<ssize;i++) { + for (int i = 0; i < ssize; i++) { Surface *s = mesh->surfaces[i]; - Skeleton *sk = p_skeleton.is_valid()?skeleton_owner.get(p_skeleton):NULL; + Skeleton *sk = p_skeleton.is_valid() ? skeleton_owner.get(p_skeleton) : NULL; - _add_geometry(s,*p_world,s->format,p_light_instances,p_light_count,p_material_overrides,sk,NULL); + _add_geometry(s, *p_world, s->format, p_light_instances, p_light_count, p_material_overrides, sk, NULL); } - mesh->last_pass=frame; + mesh->last_pass = frame; } -void RasterizerIPhone::add_multimesh( RID p_multimesh, const Transform* p_world, const RID* p_light_instances, int p_light_count, const ParamOverrideMap* p_material_overrides) { - - +void RasterizerIPhone::add_multimesh(RID p_multimesh, const Transform *p_world, const RID *p_light_instances, int p_light_count, const ParamOverrideMap *p_material_overrides) { } -void RasterizerIPhone::add_poly( RID p_poly, const Transform* p_world, const RID* p_light_instances, int p_light_count, const ParamOverrideMap* p_material_overrides) { +void RasterizerIPhone::add_poly(RID p_poly, const Transform *p_world, const RID *p_light_instances, int p_light_count, const ParamOverrideMap *p_material_overrides) { Poly *p = poly_owner.get(p_poly); if (!p->primitives.empty()) { const Poly::Primitive *pp = &p->primitives[0]; - uint32_t format=VisualServer::ARRAY_FORMAT_VERTEX; + uint32_t format = VisualServer::ARRAY_FORMAT_VERTEX; if (!pp->normals.empty()) - format|=VisualServer::ARRAY_FORMAT_NORMAL; + format |= VisualServer::ARRAY_FORMAT_NORMAL; if (!pp->colors.empty()) - format|=VisualServer::ARRAY_FORMAT_COLOR; + format |= VisualServer::ARRAY_FORMAT_COLOR; if (!pp->uvs.empty()) - format|=VisualServer::ARRAY_TEX_UV; + format |= VisualServer::ARRAY_TEX_UV; - _add_geometry(p,*p_world,format,p_light_instances,p_light_count,p_material_overrides,NULL, NULL); + _add_geometry(p, *p_world, format, p_light_instances, p_light_count, p_material_overrides, NULL, NULL); } } -void RasterizerIPhone::add_beam( RID p_beam, const Transform* p_world, const RID* p_light_instances, int p_light_count, const ParamOverrideMap* p_material_overrides) { - - +void RasterizerIPhone::add_beam(RID p_beam, const Transform *p_world, const RID *p_light_instances, int p_light_count, const ParamOverrideMap *p_material_overrides) { } -void RasterizerIPhone::add_particles( RID p_particle_instance, const RID* p_light_instances, int p_light_count, const ParamOverrideMap* p_material_overrides) { - - +void RasterizerIPhone::add_particles(RID p_particle_instance, const RID *p_light_instances, int p_light_count, const ParamOverrideMap *p_material_overrides) { } -void RasterizerIPhone::_setup_material(const Geometry *p_geometry,const Material *p_material) { +void RasterizerIPhone::_setup_material(const Geometry *p_geometry, const Material *p_material) { if (p_material->flags[VS::MATERIAL_FLAG_DOUBLE_SIDED]) glDisable(GL_CULL_FACE); else { glEnable(GL_CULL_FACE); - glCullFace( (p_material->flags[VS::MATERIAL_FLAG_INVERT_FACES])?GL_FRONT:GL_BACK); + glCullFace((p_material->flags[VS::MATERIAL_FLAG_INVERT_FACES]) ? GL_FRONT : GL_BACK); } glEnable(GL_COLOR_MATERIAL); /* unused, unless color array */ //glColorMaterial( GL_FRONT_AND_BACK, GL_DIFFUSE ); - glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ); - + glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); ///ambient @TODO offer global ambient group option - float ambient_rgba[4]={ + float ambient_rgba[4] = { 1, 1, 1, 1.0 }; - glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT,ambient_rgba); + glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, ambient_rgba); ///diffuse - const Color &diffuse_color=p_material->parameters[VS::FIXED_MATERIAL_PARAM_DIFFUSE]; - float diffuse_rgba[4]={ + const Color &diffuse_color = p_material->parameters[VS::FIXED_MATERIAL_PARAM_DIFFUSE]; + float diffuse_rgba[4] = { (float)diffuse_color.r, - (float)diffuse_color.g, - (float)diffuse_color.b, - (float)diffuse_color.a + (float)diffuse_color.g, + (float)diffuse_color.b, + (float)diffuse_color.a }; - glColor4f( diffuse_rgba[0],diffuse_rgba[1],diffuse_rgba[2],diffuse_rgba[3]); + glColor4f(diffuse_rgba[0], diffuse_rgba[1], diffuse_rgba[2], diffuse_rgba[3]); - glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,diffuse_rgba); + glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, diffuse_rgba); //specular - const Color &specular_color=p_material->parameters[VS::FIXED_MATERIAL_PARAM_SPECULAR]; - float specular_rgba[4]={ + const Color &specular_color = p_material->parameters[VS::FIXED_MATERIAL_PARAM_SPECULAR]; + float specular_rgba[4] = { (float)specular_color.r, (float)specular_color.g, (float)specular_color.b, 1.0 }; - glMaterialfv(GL_FRONT_AND_BACK,GL_SPECULAR,specular_rgba); + glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, specular_rgba); - const Color &emission_color=p_material->parameters[VS::FIXED_MATERIAL_PARAM_EMISSION]; - float emission_rgba[4]={ + const Color &emission_color = p_material->parameters[VS::FIXED_MATERIAL_PARAM_EMISSION]; + float emission_rgba[4] = { (float)emission_color.r, (float)emission_color.g, (float)emission_color.b, 1.0 }; - glMaterialfv(GL_FRONT_AND_BACK,GL_EMISSION,emission_rgba); + glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, emission_rgba); - glMaterialf(GL_FRONT_AND_BACK,GL_SHININESS,p_material->parameters[VS::FIXED_MATERIAL_PARAM_SPECULAR_EXP]); + glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, p_material->parameters[VS::FIXED_MATERIAL_PARAM_SPECULAR_EXP]); if (p_material->flags[VS::MATERIAL_FLAG_UNSHADED]) { glDisable(GL_LIGHTING); @@ -1987,26 +1847,24 @@ void RasterizerIPhone::_setup_material(const Geometry *p_geometry,const Material */ if (p_material->textures[VS::FIXED_MATERIAL_PARAM_DIFFUSE]) { - Texture *texture = texture_owner.get( p_material->textures[VS::FIXED_MATERIAL_PARAM_DIFFUSE] ); + Texture *texture = texture_owner.get(p_material->textures[VS::FIXED_MATERIAL_PARAM_DIFFUSE]); ERR_FAIL_COND(!texture); glActiveTexture(GL_TEXTURE0); glEnable(GL_TEXTURE_2D); - glBindTexture( GL_TEXTURE_2D,texture->tex_id ); + glBindTexture(GL_TEXTURE_2D, texture->tex_id); }; }; -void RasterizerIPhone::_setup_light(LightInstance* p_instance, int p_idx) { +void RasterizerIPhone::_setup_light(LightInstance *p_instance, int p_idx) { - Light* ld = p_instance->base; + Light *ld = p_instance->base; int glid = GL_LIGHT0 + p_idx; - glLightfv(glid , GL_AMBIENT, ld->colors[VS::LIGHT_COLOR_AMBIENT].components ); - glLightfv(glid, GL_DIFFUSE, ld->colors[VS::LIGHT_COLOR_DIFFUSE].components ); - glLightfv(glid, GL_SPECULAR, ld->colors[VS::LIGHT_COLOR_SPECULAR].components ); - - + glLightfv(glid, GL_AMBIENT, ld->colors[VS::LIGHT_COLOR_AMBIENT].components); + glLightfv(glid, GL_DIFFUSE, ld->colors[VS::LIGHT_COLOR_DIFFUSE].components); + glLightfv(glid, GL_SPECULAR, ld->colors[VS::LIGHT_COLOR_SPECULAR].components); - switch(ld->type) { + switch (ld->type) { case VS::LIGHT_DIRECTIONAL: { /* This doesnt have attenuation */ @@ -2014,75 +1872,72 @@ void RasterizerIPhone::_setup_light(LightInstance* p_instance, int p_idx) { glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); - Vector3 v(0.0,0.0,-1.0); // directional lights point up by default - v = p_instance->transform.get_basis().xform( v ); - v = camera_transform_inverse.get_basis().xform( v ); + Vector3 v(0.0, 0.0, -1.0); // directional lights point up by default + v = p_instance->transform.get_basis().xform(v); + v = camera_transform_inverse.get_basis().xform(v); v.normalize(); // this sucks, so it will be optimized at some point v = -v; - float lightpos[4]={v.x,v.y,v.z,0.0}; + float lightpos[4] = { v.x, v.y, v.z, 0.0 }; - glLightfv(glid,GL_POSITION,lightpos); //at modelview + glLightfv(glid, GL_POSITION, lightpos); //at modelview glPopMatrix(); } break; case VS::LIGHT_OMNI: { - glLightf(glid,GL_SPOT_CUTOFF,180.0); - glLightf(glid,GL_CONSTANT_ATTENUATION, ld->vars[VS::LIGHT_PARAM_ATTENUATION]); - glLightf(glid,GL_LINEAR_ATTENUATION, ld->vars[VS::LIGHT_PARAM_RADIUS]); - glLightf(glid,GL_QUADRATIC_ATTENUATION, ld->vars[VS::LIGHT_PARAM_ENERGY]); // wut? + glLightf(glid, GL_SPOT_CUTOFF, 180.0); + glLightf(glid, GL_CONSTANT_ATTENUATION, ld->vars[VS::LIGHT_PARAM_ATTENUATION]); + glLightf(glid, GL_LINEAR_ATTENUATION, ld->vars[VS::LIGHT_PARAM_RADIUS]); + glLightf(glid, GL_QUADRATIC_ATTENUATION, ld->vars[VS::LIGHT_PARAM_ENERGY]); // wut? glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); Vector3 pos = p_instance->transform.get_origin(); pos = camera_transform_inverse.xform(pos); - float lightpos[4]={pos.x,pos.y,pos.z,1.0}; - glLightfv(glid,GL_POSITION,lightpos); //at modelview + float lightpos[4] = { pos.x, pos.y, pos.z, 1.0 }; + glLightfv(glid, GL_POSITION, lightpos); //at modelview glPopMatrix(); } break; case VS::LIGHT_SPOT: { - glLightf(glid,GL_SPOT_CUTOFF, ld->vars[VS::LIGHT_PARAM_SPOT_ANGLE]); - glLightf(glid,GL_SPOT_EXPONENT, ld->vars[VS::LIGHT_PARAM_SPOT_ATTENUATION]); - glLightf(glid,GL_CONSTANT_ATTENUATION, ld->vars[VS::LIGHT_PARAM_ATTENUATION]); - glLightf(glid,GL_LINEAR_ATTENUATION, ld->vars[VS::LIGHT_PARAM_RADIUS]); - glLightf(glid,GL_QUADRATIC_ATTENUATION, ld->vars[VS::LIGHT_PARAM_ENERGY]); // wut? - + glLightf(glid, GL_SPOT_CUTOFF, ld->vars[VS::LIGHT_PARAM_SPOT_ANGLE]); + glLightf(glid, GL_SPOT_EXPONENT, ld->vars[VS::LIGHT_PARAM_SPOT_ATTENUATION]); + glLightf(glid, GL_CONSTANT_ATTENUATION, ld->vars[VS::LIGHT_PARAM_ATTENUATION]); + glLightf(glid, GL_LINEAR_ATTENUATION, ld->vars[VS::LIGHT_PARAM_RADIUS]); + glLightf(glid, GL_QUADRATIC_ATTENUATION, ld->vars[VS::LIGHT_PARAM_ENERGY]); // wut? glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); - Vector3 v(0.0,0.0,-1.0); // directional lights point up by default - v = p_instance->transform.get_basis().xform( v ); - v = camera_transform_inverse.get_basis().xform( v ); + Vector3 v(0.0, 0.0, -1.0); // directional lights point up by default + v = p_instance->transform.get_basis().xform(v); + v = camera_transform_inverse.get_basis().xform(v); v.normalize(); // this sucks, so it will be optimized at some point - float lightdir[4]={v.x, v.y, v.z, 1.0}; - glLightfv(glid,GL_SPOT_DIRECTION,lightdir); //at modelview + float lightdir[4] = { v.x, v.y, v.z, 1.0 }; + glLightfv(glid, GL_SPOT_DIRECTION, lightdir); //at modelview v = p_instance->transform.get_origin(); v = camera_transform_inverse.xform(v); - float lightpos[4]={v.x,v.y,v.z,1.0}; - glLightfv(glid,GL_POSITION,lightpos); //at modelview - + float lightpos[4] = { v.x, v.y, v.z, 1.0 }; + glLightfv(glid, GL_POSITION, lightpos); //at modelview glPopMatrix(); - } break; default: break; } }; -void RasterizerIPhone::_setup_lights(LightInstance **p_lights,int p_light_count) { +void RasterizerIPhone::_setup_lights(LightInstance **p_lights, int p_light_count) { - for (int i=0; i<MAX_LIGHTS; i++) { + for (int i = 0; i < MAX_LIGHTS; i++) { - if (i<p_light_count) { + if (i < p_light_count) { glEnable(GL_LIGHT0 + i); _setup_light(p_lights[i], i); } else { @@ -2104,16 +1959,15 @@ static const int gl_client_states[] = { -1, // ARRAY_INDEX }; -void RasterizerIPhone::_setup_geometry(const Geometry *p_geometry, const Material* p_material) { +void RasterizerIPhone::_setup_geometry(const Geometry *p_geometry, const Material *p_material) { - - switch(p_geometry->type) { + switch (p_geometry->type) { case Geometry::GEOMETRY_SURFACE: { - Surface *surf = (Surface*)p_geometry; - uint8_t *base=0; - bool use_VBO = (surf->array_local==0); + Surface *surf = (Surface *)p_geometry; + uint8_t *base = 0; + bool use_VBO = (surf->array_local == 0); if (!use_VBO) { @@ -2125,17 +1979,17 @@ void RasterizerIPhone::_setup_geometry(const Geometry *p_geometry, const Materia glBindBuffer(GL_ARRAY_BUFFER, surf->vertex_id); }; - const Surface::ArrayData* a=surf->array; - for (int i=0;i<VS::ARRAY_MAX;i++) { + const Surface::ArrayData *a = surf->array; + for (int i = 0; i < VS::ARRAY_MAX; i++) { - const Surface::ArrayData& ad=surf->array[i]; - if (ad.size==0) { + const Surface::ArrayData &ad = surf->array[i]; + if (ad.size == 0) { if (gl_client_states[i] != -1) { glDisableClientState(gl_client_states[i]); }; continue; // this one is disabled. } - ERR_CONTINUE( !ad.configured ); + ERR_CONTINUE(!ad.configured); if (gl_client_states[i] != -1) { glEnableClientState(gl_client_states[i]); @@ -2143,55 +1997,52 @@ void RasterizerIPhone::_setup_geometry(const Geometry *p_geometry, const Materia switch (i) { - case VS::ARRAY_VERTEX: - if (!use_VBO) - glVertexPointer(3,GL_FLOAT,surf->stride,(GLvoid*)&base[a->ofs]); - else - if (surf->array[VS::ARRAY_BONES].size) + case VS::ARRAY_VERTEX: + if (!use_VBO) + glVertexPointer(3, GL_FLOAT, surf->stride, (GLvoid *)&base[a->ofs]); + else if (surf->array[VS::ARRAY_BONES].size) glVertexPointer(3, GL_FLOAT, 0, skinned_buffer); else - glVertexPointer(3,GL_FLOAT,surf->stride,(GLvoid*)a->ofs); - break; + glVertexPointer(3, GL_FLOAT, surf->stride, (GLvoid *)a->ofs); + break; - case VS::ARRAY_NORMAL: - if (use_VBO) - glNormalPointer(GL_FLOAT,surf->stride,(GLvoid*)a->ofs); - else - glNormalPointer(GL_FLOAT,surf->stride,(GLvoid*)&base[a->ofs]); - break; - case VS::ARRAY_TANGENT: - break; - case VS::ARRAY_COLOR: - if (use_VBO) - glColorPointer(4,GL_UNSIGNED_BYTE,surf->stride,(GLvoid*)a->ofs); - else - glColorPointer(4,GL_UNSIGNED_BYTE,surf->stride,(GLvoid*)&base[a->ofs]); - break; - case VS::ARRAY_TEX_UV: - case VS::ARRAY_TEX_UV2: - if (use_VBO) - glTexCoordPointer(2,GL_FLOAT,surf->stride,(GLvoid*)a->ofs); - else - glTexCoordPointer(2,GL_FLOAT,surf->stride,&base[a->ofs]); - break; - case VS::ARRAY_BONES: - case VS::ARRAY_WEIGHTS: - case VS::ARRAY_INDEX: - break; + case VS::ARRAY_NORMAL: + if (use_VBO) + glNormalPointer(GL_FLOAT, surf->stride, (GLvoid *)a->ofs); + else + glNormalPointer(GL_FLOAT, surf->stride, (GLvoid *)&base[a->ofs]); + break; + case VS::ARRAY_TANGENT: + break; + case VS::ARRAY_COLOR: + if (use_VBO) + glColorPointer(4, GL_UNSIGNED_BYTE, surf->stride, (GLvoid *)a->ofs); + else + glColorPointer(4, GL_UNSIGNED_BYTE, surf->stride, (GLvoid *)&base[a->ofs]); + break; + case VS::ARRAY_TEX_UV: + case VS::ARRAY_TEX_UV2: + if (use_VBO) + glTexCoordPointer(2, GL_FLOAT, surf->stride, (GLvoid *)a->ofs); + else + glTexCoordPointer(2, GL_FLOAT, surf->stride, &base[a->ofs]); + break; + case VS::ARRAY_BONES: + case VS::ARRAY_WEIGHTS: + case VS::ARRAY_INDEX: + break; }; } - // process skeleton here } break; default: break; - }; }; -static const GLenum gl_primitive[]={ +static const GLenum gl_primitive[] = { GL_POINTS, GL_LINES, GL_LINE_STRIP, @@ -2201,64 +2052,60 @@ static const GLenum gl_primitive[]={ GL_TRIANGLE_FAN }; -void RasterizerIPhone::_render(const Geometry *p_geometry,const Material *p_material, const Skeleton* p_skeleton) { - +void RasterizerIPhone::_render(const Geometry *p_geometry, const Material *p_material, const Skeleton *p_skeleton) { - switch(p_geometry->type) { + switch (p_geometry->type) { case Geometry::GEOMETRY_SURFACE: { + Surface *s = (Surface *)p_geometry; - Surface *s = (Surface*)p_geometry; - - if (s->index_array_len>0) { + if (s->index_array_len > 0) { if (s->index_array_local) { - glDrawElements(gl_primitive[s->primitive], s->index_array_len, (s->index_array_len>(1<<8))?GL_UNSIGNED_SHORT:GL_UNSIGNED_BYTE, s->index_array_local); + glDrawElements(gl_primitive[s->primitive], s->index_array_len, (s->index_array_len > (1 << 8)) ? GL_UNSIGNED_SHORT : GL_UNSIGNED_BYTE, s->index_array_local); } else { - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,s->index_id); - glDrawElements(gl_primitive[s->primitive],s->index_array_len, (s->index_array_len>(1<<8))?GL_UNSIGNED_SHORT:GL_UNSIGNED_BYTE,0); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, s->index_id); + glDrawElements(gl_primitive[s->primitive], s->index_array_len, (s->index_array_len > (1 << 8)) ? GL_UNSIGNED_SHORT : GL_UNSIGNED_BYTE, 0); } - } else { - glDrawArrays(gl_primitive[s->primitive],0,s->array_len); - + glDrawArrays(gl_primitive[s->primitive], 0, s->array_len); }; } break; - default: break; + default: break; }; }; void RasterizerIPhone::_render_list_forward(RenderList *p_render_list) { - const Material *prev_material=NULL; - uint64_t prev_light_hash=0; - const Skeleton *prev_skeleton=NULL; - const Geometry *prev_geometry=NULL; - const ParamOverrideMap* prev_overrides=NULL; // make it diferent than NULL + const Material *prev_material = NULL; + uint64_t prev_light_hash = 0; + const Skeleton *prev_skeleton = NULL; + const Geometry *prev_geometry = NULL; + const ParamOverrideMap *prev_overrides = NULL; // make it diferent than NULL - Geometry::Type prev_geometry_type=Geometry::GEOMETRY_INVALID; + Geometry::Type prev_geometry_type = Geometry::GEOMETRY_INVALID; glMatrixMode(GL_PROJECTION); glLoadMatrixf(&camera_projection.matrix[0][0]); - for (int i=0;i<p_render_list->element_count;i++) { + for (int i = 0; i < p_render_list->element_count; i++) { RenderList::Element *e = p_render_list->elements[i]; const Material *material = e->material; uint64_t light_hash = e->light_hash; const Skeleton *skeleton = e->skeleton; const Geometry *geometry = e->geometry; - const ParamOverrideMap* material_overrides=e->material_overrides; + const ParamOverrideMap *material_overrides = e->material_overrides; - if (material!=prev_material || geometry->type!=prev_geometry_type) { - _setup_material(e->geometry,material); + if (material != prev_material || geometry->type != prev_geometry_type) { + _setup_material(e->geometry, material); //_setup_material_overrides(e->material,NULL,material_overrides); //_setup_material_skeleton(material,skeleton); } else { @@ -2268,18 +2115,18 @@ void RasterizerIPhone::_render_list_forward(RenderList *p_render_list) { //_setup_material_overrides(e->material,prev_overrides,material_overrides); } - if (prev_skeleton!=skeleton) { + if (prev_skeleton != skeleton) { //_setup_material_skeleton(material,skeleton); }; } - if (geometry!=prev_geometry || geometry->type!=prev_geometry_type) { + if (geometry != prev_geometry || geometry->type != prev_geometry_type) { _setup_geometry(geometry, material); }; - if (i==0 || light_hash!=prev_light_hash) - _setup_lights(e->lights,e->light_count); + if (i == 0 || light_hash != prev_light_hash) + _setup_lights(e->lights, e->light_count); glMatrixMode(GL_MODELVIEW); _gl_load_transform(camera_transform_inverse); @@ -2287,12 +2134,12 @@ void RasterizerIPhone::_render_list_forward(RenderList *p_render_list) { _render(geometry, material, skeleton); - prev_material=material; - prev_skeleton=skeleton; - prev_geometry=geometry; - prev_light_hash=e->light_hash; - prev_geometry_type=geometry->type; - prev_overrides=material_overrides; + prev_material = material; + prev_skeleton = skeleton; + prev_geometry = geometry; + prev_light_hash = e->light_hash; + prev_geometry_type = geometry->type; + prev_overrides = material_overrides; } }; @@ -2309,12 +2156,8 @@ void RasterizerIPhone::end_scene() { alpha_render_list.sort_z(); _render_list_forward(&alpha_render_list); - - } void RasterizerIPhone::end_shadow_map() { - - } void RasterizerIPhone::end_frame() { @@ -2337,11 +2180,9 @@ void RasterizerIPhone::canvas_begin() { glLoadIdentity(); } void RasterizerIPhone::canvas_set_transparency(float p_transparency) { - - } -void RasterizerIPhone::canvas_set_rect(const Rect2& p_rect, bool p_clip) { +void RasterizerIPhone::canvas_set_rect(const Rect2 &p_rect, bool p_clip) { glMatrixMode(GL_MODELVIEW); glLoadIdentity(); @@ -2351,177 +2192,166 @@ void RasterizerIPhone::canvas_set_rect(const Rect2& p_rect, bool p_clip) { if (p_clip) { glEnable(GL_SCISSOR_TEST); - glScissor(viewport.x+p_rect.pos.x,viewport.y+ (viewport.height-(p_rect.pos.y+p_rect.size.height)), - p_rect.size.width,p_rect.size.height); + glScissor(viewport.x + p_rect.pos.x, viewport.y + (viewport.height - (p_rect.pos.y + p_rect.size.height)), + p_rect.size.width, p_rect.size.height); } else { glDisable(GL_SCISSOR_TEST); } - - } -void RasterizerIPhone::canvas_draw_line(const Point2& p_from, const Point2& p_to,const Color& p_color,float p_width) { +void RasterizerIPhone::canvas_draw_line(const Point2 &p_from, const Point2 &p_to, const Color &p_color, float p_width) { glColor4f(1, 1, 1, 1); - float verts[6]={ - p_from.x,p_from.y,0, - p_to.x,p_to.y,0 + float verts[6] = { + p_from.x, p_from.y, 0, + p_to.x, p_to.y, 0 }; - float colors[]={ + float colors[] = { p_color.r, p_color.g, p_color.b, p_color.a, p_color.r, p_color.g, p_color.b, p_color.a, }; glLineWidth(p_width); - _draw_primitive(2,verts,0,colors,0); + _draw_primitive(2, verts, 0, colors, 0); } -static void _draw_textured_quad(const Rect2& p_rect, const Rect2& p_src_region, const Size2& p_tex_size ) { +static void _draw_textured_quad(const Rect2 &p_rect, const Rect2 &p_src_region, const Size2 &p_tex_size) { - float texcoords[]= { - p_src_region.pos.x/p_tex_size.width, - p_src_region.pos.y/p_tex_size.height, + float texcoords[] = { + p_src_region.pos.x / p_tex_size.width, + p_src_region.pos.y / p_tex_size.height, - (p_src_region.pos.x+p_src_region.size.width)/p_tex_size.width, - p_src_region.pos.y/p_tex_size.height, + (p_src_region.pos.x + p_src_region.size.width) / p_tex_size.width, + p_src_region.pos.y / p_tex_size.height, - (p_src_region.pos.x+p_src_region.size.width)/p_tex_size.width, - (p_src_region.pos.y+p_src_region.size.height)/p_tex_size.height, + (p_src_region.pos.x + p_src_region.size.width) / p_tex_size.width, + (p_src_region.pos.y + p_src_region.size.height) / p_tex_size.height, - p_src_region.pos.x/p_tex_size.width, - (p_src_region.pos.y+p_src_region.size.height)/p_tex_size.height, + p_src_region.pos.x / p_tex_size.width, + (p_src_region.pos.y + p_src_region.size.height) / p_tex_size.height, }; - float coords[]= { + float coords[] = { p_rect.pos.x, p_rect.pos.y, 0, - p_rect.pos.x+p_rect.size.width, p_rect.pos.y, 0, - p_rect.pos.x+p_rect.size.width, p_rect.pos.y+p_rect.size.height, 0, - p_rect.pos.x,p_rect.pos.y+p_rect.size.height, 0 + p_rect.pos.x + p_rect.size.width, p_rect.pos.y, 0, + p_rect.pos.x + p_rect.size.width, p_rect.pos.y + p_rect.size.height, 0, + p_rect.pos.x, p_rect.pos.y + p_rect.size.height, 0 }; - _draw_primitive(4,coords,0,0,texcoords); + _draw_primitive(4, coords, 0, 0, texcoords); } -static void _draw_quad(const Rect2& p_rect) { +static void _draw_quad(const Rect2 &p_rect) { - float coords[]= { - p_rect.pos.x,p_rect.pos.y, 0, - p_rect.pos.x+p_rect.size.width,p_rect.pos.y, 0, - p_rect.pos.x+p_rect.size.width,p_rect.pos.y+p_rect.size.height, 0, - p_rect.pos.x,p_rect.pos.y+p_rect.size.height, 0 + float coords[] = { + p_rect.pos.x, p_rect.pos.y, 0, + p_rect.pos.x + p_rect.size.width, p_rect.pos.y, 0, + p_rect.pos.x + p_rect.size.width, p_rect.pos.y + p_rect.size.height, 0, + p_rect.pos.x, p_rect.pos.y + p_rect.size.height, 0 }; - _draw_primitive(4,coords,0,0,0); - + _draw_primitive(4, coords, 0, 0, 0); } -void RasterizerIPhone::canvas_draw_rect(const Rect2& p_rect, bool p_region, const Rect2& p_source,bool p_tile,RID p_texture,const Color& p_modulate) { +void RasterizerIPhone::canvas_draw_rect(const Rect2 &p_rect, bool p_region, const Rect2 &p_source, bool p_tile, RID p_texture, const Color &p_modulate) { glColor4f(p_modulate.r, p_modulate.g, p_modulate.b, p_modulate.a); - if ( p_texture.is_valid() ) { + if (p_texture.is_valid()) { glEnable(GL_TEXTURE_2D); - Texture *texture = texture_owner.get( p_texture ); + Texture *texture = texture_owner.get(p_texture); ERR_FAIL_COND(!texture); glActiveTexture(GL_TEXTURE0); - glBindTexture( GL_TEXTURE_2D,texture->tex_id ); + glBindTexture(GL_TEXTURE_2D, texture->tex_id); if (!p_region) { - Rect2 region = Rect2(0,0,texture->width,texture->height); - _draw_textured_quad(p_rect,region,region.size); + Rect2 region = Rect2(0, 0, texture->width, texture->height); + _draw_textured_quad(p_rect, region, region.size); } else { - _draw_textured_quad(p_rect, p_source, Size2(texture->width,texture->height) ); - + _draw_textured_quad(p_rect, p_source, Size2(texture->width, texture->height)); } } else { - _draw_quad( p_rect ); - + _draw_quad(p_rect); } - - } -void RasterizerIPhone::canvas_draw_style_box(const Rect2& p_rect, const Rect2& p_src_region, RID p_texture,const float *p_margin, bool p_draw_center) { +void RasterizerIPhone::canvas_draw_style_box(const Rect2 &p_rect, const Rect2 &p_src_region, RID p_texture, const float *p_margin, bool p_draw_center) { glColor4f(1, 1, 1, 1); - Texture *texture = texture_owner.get( p_texture ); + Texture *texture = texture_owner.get(p_texture); ERR_FAIL_COND(!texture); glEnable(GL_TEXTURE_2D); glActiveTexture(GL_TEXTURE0); - glBindTexture( GL_TEXTURE_2D,texture->tex_id ); - + glBindTexture(GL_TEXTURE_2D, texture->tex_id); Rect2 region = p_src_region; - if (region.size.width <= 0 ) - region.size.width = texture->width; + if (region.size.width <= 0) + region.size.width = texture->width; if (region.size.height <= 0) - region.size.height = texture->height; + region.size.height = texture->height; /* CORNERS */ _draw_textured_quad( // top left - Rect2( p_rect.pos, Size2(p_margin[MARGIN_LEFT],p_margin[MARGIN_TOP])), - Rect2( region.pos, Size2(p_margin[MARGIN_LEFT],p_margin[MARGIN_TOP])), - Size2( texture->width, texture->height ) ); + Rect2(p_rect.pos, Size2(p_margin[MARGIN_LEFT], p_margin[MARGIN_TOP])), + Rect2(region.pos, Size2(p_margin[MARGIN_LEFT], p_margin[MARGIN_TOP])), + Size2(texture->width, texture->height)); _draw_textured_quad( // top right - Rect2( Point2( p_rect.pos.x + p_rect.size.width - p_margin[MARGIN_RIGHT], p_rect.pos.y), Size2(p_margin[MARGIN_RIGHT],p_margin[MARGIN_TOP])), - Rect2( Point2(region.pos.x+region.size.width-p_margin[MARGIN_RIGHT], region.pos.y), Size2(p_margin[MARGIN_RIGHT],p_margin[MARGIN_TOP])), - Size2( texture->width, texture->height ) ); - + Rect2(Point2(p_rect.pos.x + p_rect.size.width - p_margin[MARGIN_RIGHT], p_rect.pos.y), Size2(p_margin[MARGIN_RIGHT], p_margin[MARGIN_TOP])), + Rect2(Point2(region.pos.x + region.size.width - p_margin[MARGIN_RIGHT], region.pos.y), Size2(p_margin[MARGIN_RIGHT], p_margin[MARGIN_TOP])), + Size2(texture->width, texture->height)); _draw_textured_quad( // bottom left - Rect2( Point2(p_rect.pos.x,p_rect.pos.y + p_rect.size.height - p_margin[MARGIN_BOTTOM]), Size2(p_margin[MARGIN_LEFT],p_margin[MARGIN_BOTTOM])), - Rect2( Point2(region.pos.x, region.pos.y+region.size.height-p_margin[MARGIN_BOTTOM]), Size2(p_margin[MARGIN_LEFT],p_margin[MARGIN_BOTTOM])), - Size2( texture->width, texture->height ) ); + Rect2(Point2(p_rect.pos.x, p_rect.pos.y + p_rect.size.height - p_margin[MARGIN_BOTTOM]), Size2(p_margin[MARGIN_LEFT], p_margin[MARGIN_BOTTOM])), + Rect2(Point2(region.pos.x, region.pos.y + region.size.height - p_margin[MARGIN_BOTTOM]), Size2(p_margin[MARGIN_LEFT], p_margin[MARGIN_BOTTOM])), + Size2(texture->width, texture->height)); _draw_textured_quad( // bottom right - Rect2( Point2( p_rect.pos.x + p_rect.size.width - p_margin[MARGIN_RIGHT], p_rect.pos.y + p_rect.size.height - p_margin[MARGIN_BOTTOM]), Size2(p_margin[MARGIN_RIGHT],p_margin[MARGIN_BOTTOM])), - Rect2( Point2(region.pos.x+region.size.width-p_margin[MARGIN_RIGHT], region.pos.y+region.size.height-p_margin[MARGIN_BOTTOM]), Size2(p_margin[MARGIN_RIGHT],p_margin[MARGIN_BOTTOM])), - Size2( texture->width, texture->height ) ); - - Rect2 rect_center( p_rect.pos+Point2( p_margin[MARGIN_LEFT], p_margin[MARGIN_TOP]), Size2( p_rect.size.width - p_margin[MARGIN_LEFT] - p_margin[MARGIN_RIGHT], p_rect.size.height - p_margin[MARGIN_TOP] - p_margin[MARGIN_BOTTOM] )); + Rect2(Point2(p_rect.pos.x + p_rect.size.width - p_margin[MARGIN_RIGHT], p_rect.pos.y + p_rect.size.height - p_margin[MARGIN_BOTTOM]), Size2(p_margin[MARGIN_RIGHT], p_margin[MARGIN_BOTTOM])), + Rect2(Point2(region.pos.x + region.size.width - p_margin[MARGIN_RIGHT], region.pos.y + region.size.height - p_margin[MARGIN_BOTTOM]), Size2(p_margin[MARGIN_RIGHT], p_margin[MARGIN_BOTTOM])), + Size2(texture->width, texture->height)); - Rect2 src_center( Point2(region.pos.x+p_margin[MARGIN_LEFT], region.pos.y+p_margin[MARGIN_TOP]), Size2(region.size.width - p_margin[MARGIN_LEFT] - p_margin[MARGIN_RIGHT], region.size.height - p_margin[MARGIN_TOP] - p_margin[MARGIN_BOTTOM] )); + Rect2 rect_center(p_rect.pos + Point2(p_margin[MARGIN_LEFT], p_margin[MARGIN_TOP]), Size2(p_rect.size.width - p_margin[MARGIN_LEFT] - p_margin[MARGIN_RIGHT], p_rect.size.height - p_margin[MARGIN_TOP] - p_margin[MARGIN_BOTTOM])); + Rect2 src_center(Point2(region.pos.x + p_margin[MARGIN_LEFT], region.pos.y + p_margin[MARGIN_TOP]), Size2(region.size.width - p_margin[MARGIN_LEFT] - p_margin[MARGIN_RIGHT], region.size.height - p_margin[MARGIN_TOP] - p_margin[MARGIN_BOTTOM])); _draw_textured_quad( // top - Rect2( Point2(rect_center.pos.x,p_rect.pos.y),Size2(rect_center.size.width,p_margin[MARGIN_TOP])), - Rect2( Point2(src_center.pos.x,region.pos.y), Size2(src_center.size.width,p_margin[MARGIN_TOP])), - Size2( texture->width, texture->height ) ); + Rect2(Point2(rect_center.pos.x, p_rect.pos.y), Size2(rect_center.size.width, p_margin[MARGIN_TOP])), + Rect2(Point2(src_center.pos.x, region.pos.y), Size2(src_center.size.width, p_margin[MARGIN_TOP])), + Size2(texture->width, texture->height)); _draw_textured_quad( // bottom - Rect2( Point2(rect_center.pos.x,rect_center.pos.y+rect_center.size.height),Size2(rect_center.size.width,p_margin[MARGIN_BOTTOM])), - Rect2( Point2(src_center.pos.x,src_center.pos.y+src_center.size.height), Size2(src_center.size.width,p_margin[MARGIN_BOTTOM])), - Size2( texture->width, texture->height ) ); + Rect2(Point2(rect_center.pos.x, rect_center.pos.y + rect_center.size.height), Size2(rect_center.size.width, p_margin[MARGIN_BOTTOM])), + Rect2(Point2(src_center.pos.x, src_center.pos.y + src_center.size.height), Size2(src_center.size.width, p_margin[MARGIN_BOTTOM])), + Size2(texture->width, texture->height)); _draw_textured_quad( // left - Rect2( Point2(p_rect.pos.x,rect_center.pos.y),Size2(p_margin[MARGIN_LEFT],rect_center.size.height)), - Rect2( Point2(region.pos.x,region.pos.y+p_margin[MARGIN_TOP]), Size2(p_margin[MARGIN_LEFT],src_center.size.height)), - Size2( texture->width, texture->height ) ); + Rect2(Point2(p_rect.pos.x, rect_center.pos.y), Size2(p_margin[MARGIN_LEFT], rect_center.size.height)), + Rect2(Point2(region.pos.x, region.pos.y + p_margin[MARGIN_TOP]), Size2(p_margin[MARGIN_LEFT], src_center.size.height)), + Size2(texture->width, texture->height)); _draw_textured_quad( // right - Rect2( Point2(rect_center.pos.x+rect_center.size.width,rect_center.pos.y),Size2(p_margin[MARGIN_RIGHT],rect_center.size.height)), - Rect2( Point2(src_center.pos.x+src_center.size.width,region.pos.y+p_margin[MARGIN_TOP]), Size2(p_margin[MARGIN_RIGHT],src_center.size.height)), - Size2( texture->width, texture->height ) ); + Rect2(Point2(rect_center.pos.x + rect_center.size.width, rect_center.pos.y), Size2(p_margin[MARGIN_RIGHT], rect_center.size.height)), + Rect2(Point2(src_center.pos.x + src_center.size.width, region.pos.y + p_margin[MARGIN_TOP]), Size2(p_margin[MARGIN_RIGHT], src_center.size.height)), + Size2(texture->width, texture->height)); if (p_draw_center) { _draw_textured_quad( - rect_center, - src_center, - Size2( texture->width, texture->height )); + rect_center, + src_center, + Size2(texture->width, texture->height)); } - } -void RasterizerIPhone::canvas_draw_primitive(const Vector<Point2>& p_points, const Vector<Color>& p_colors,const Vector<Point2>& p_uvs, RID p_texture) { +void RasterizerIPhone::canvas_draw_primitive(const Vector<Point2> &p_points, const Vector<Color> &p_colors, const Vector<Point2> &p_uvs, RID p_texture) { - ERR_FAIL_COND(p_points.size()<1); + ERR_FAIL_COND(p_points.size() < 1); float verts[12]; float uvs[8]; float colors[16]; @@ -2529,22 +2359,22 @@ void RasterizerIPhone::canvas_draw_primitive(const Vector<Point2>& p_points, con glColor4f(1, 1, 1, 1); int idx = 0; - for(int i=0;i<p_points.size();i++) { + for (int i = 0; i < p_points.size(); i++) { - verts[idx++]=p_points[i].x; - verts[idx++]=p_points[i].y; - verts[idx++]=0; + verts[idx++] = p_points[i].x; + verts[idx++] = p_points[i].y; + verts[idx++] = 0; } idx = 0; - for(int i=0;i<p_uvs.size();i++) { + for (int i = 0; i < p_uvs.size(); i++) { uvs[idx++] = p_uvs[i].x; uvs[idx++] = p_uvs[i].y; } idx = 0; - for (int i=0; i<p_colors.size(); i++) { + for (int i = 0; i < p_colors.size(); i++) { colors[idx++] = p_colors[i].r; colors[idx++] = p_colors[i].g; @@ -2554,15 +2384,14 @@ void RasterizerIPhone::canvas_draw_primitive(const Vector<Point2>& p_points, con if (p_texture.is_valid()) { glEnable(GL_TEXTURE_2D); - Texture *texture = texture_owner.get( p_texture ); + Texture *texture = texture_owner.get(p_texture); if (texture) { glActiveTexture(GL_TEXTURE0); - glBindTexture( GL_TEXTURE_2D,texture->tex_id ); + glBindTexture(GL_TEXTURE_2D, texture->tex_id); } } - _draw_primitive(p_points.size(),&verts[0],NULL,p_colors.size()?&colors[0]:NULL,p_uvs.size()?uvs:NULL); - + _draw_primitive(p_points.size(), &verts[0], NULL, p_colors.size() ? &colors[0] : NULL, p_uvs.size() ? uvs : NULL); } /* FX */ @@ -2571,50 +2400,42 @@ RID RasterizerIPhone::fx_create() { return RID(); } -void RasterizerIPhone::fx_get_effects(RID p_fx,List<String> *p_effects) const { - - +void RasterizerIPhone::fx_get_effects(RID p_fx, List<String> *p_effects) const { } -void RasterizerIPhone::fx_set_active(RID p_fx,const String& p_effect, bool p_active) { - - +void RasterizerIPhone::fx_set_active(RID p_fx, const String &p_effect, bool p_active) { } -bool RasterizerIPhone::fx_is_active(RID p_fx,const String& p_effect) const { +bool RasterizerIPhone::fx_is_active(RID p_fx, const String &p_effect) const { return false; } -void RasterizerIPhone::fx_get_effect_params(RID p_fx,const String& p_effect,List<PropertyInfo> *p_params) const { - - +void RasterizerIPhone::fx_get_effect_params(RID p_fx, const String &p_effect, List<PropertyInfo> *p_params) const { } -Variant RasterizerIPhone::fx_get_effect_param(RID p_fx,const String& p_effect,const String& p_param) const { +Variant RasterizerIPhone::fx_get_effect_param(RID p_fx, const String &p_effect, const String &p_param) const { return Variant(); } -void RasterizerIPhone::fx_set_effect_param(RID p_fx,const String& p_effect, const String& p_param, const Variant& p_pvalue) { - - +void RasterizerIPhone::fx_set_effect_param(RID p_fx, const String &p_effect, const String &p_param, const Variant &p_pvalue) { } /*MISC*/ -bool RasterizerIPhone::is_texture(const RID& p_rid) const { +bool RasterizerIPhone::is_texture(const RID &p_rid) const { return texture_owner.owns(p_rid); } -bool RasterizerIPhone::is_material(const RID& p_rid) const { +bool RasterizerIPhone::is_material(const RID &p_rid) const { return material_owner.owns(p_rid); } -bool RasterizerIPhone::is_mesh(const RID& p_rid) const { +bool RasterizerIPhone::is_mesh(const RID &p_rid) const { return mesh_owner.owns(p_rid); } -bool RasterizerIPhone::is_multimesh(const RID& p_rid) const { +bool RasterizerIPhone::is_multimesh(const RID &p_rid) const { return false; } -bool RasterizerIPhone::is_poly(const RID& p_rid) const { +bool RasterizerIPhone::is_poly(const RID &p_rid) const { return poly_owner.owns(p_rid); } @@ -2628,46 +2449,46 @@ bool RasterizerIPhone::is_beam(const RID &p_beam) const { return false; } -bool RasterizerIPhone::is_light(const RID& p_rid) const { +bool RasterizerIPhone::is_light(const RID &p_rid) const { return light_owner.owns(p_rid); } -bool RasterizerIPhone::is_light_instance(const RID& p_rid) const { +bool RasterizerIPhone::is_light_instance(const RID &p_rid) const { return light_instance_owner.owns(p_rid); } -bool RasterizerIPhone::is_particles_instance(const RID& p_rid) const { +bool RasterizerIPhone::is_particles_instance(const RID &p_rid) const { return false; } -bool RasterizerIPhone::is_skeleton(const RID& p_rid) const { +bool RasterizerIPhone::is_skeleton(const RID &p_rid) const { return skeleton_owner.owns(p_rid); } -bool RasterizerIPhone::is_fx(const RID& p_rid) const { +bool RasterizerIPhone::is_fx(const RID &p_rid) const { return fx_owner.owns(p_rid); } -bool RasterizerIPhone::is_shader(const RID& p_rid) const { +bool RasterizerIPhone::is_shader(const RID &p_rid) const { return false; } -void RasterizerIPhone::free(const RID& p_rid) const { +void RasterizerIPhone::free(const RID &p_rid) const { if (texture_owner.owns(p_rid)) { // delete the texture Texture *texture = texture_owner.get(p_rid); - glDeleteTextures( 1,&texture->tex_id ); + glDeleteTextures(1, &texture->tex_id); texture_owner.free(p_rid); memdelete(texture); } else if (material_owner.owns(p_rid)) { - Material *material = material_owner.get( p_rid ); + Material *material = material_owner.get(p_rid); ERR_FAIL_COND(!material); material_owner.free(p_rid); @@ -2677,7 +2498,7 @@ void RasterizerIPhone::free(const RID& p_rid) const { Mesh *mesh = mesh_owner.get(p_rid); ERR_FAIL_COND(!mesh); - for (int i=0;i<mesh->surfaces.size();i++) { + for (int i = 0; i < mesh->surfaces.size(); i++) { Surface *surface = mesh->surfaces[i]; if (surface->array_local != 0) { @@ -2688,11 +2509,11 @@ void RasterizerIPhone::free(const RID& p_rid) const { }; if (surface->vertex_id) - glDeleteBuffers(1,&surface->vertex_id); + glDeleteBuffers(1, &surface->vertex_id); if (surface->index_id) - glDeleteBuffers(1,&surface->index_id); + glDeleteBuffers(1, &surface->index_id); - memdelete( surface ); + memdelete(surface); }; mesh->surfaces.clear(); @@ -2702,7 +2523,7 @@ void RasterizerIPhone::free(const RID& p_rid) const { } else if (skeleton_owner.owns(p_rid)) { - Skeleton *skeleton = skeleton_owner.get( p_rid ); + Skeleton *skeleton = skeleton_owner.get(p_rid); ERR_FAIL_COND(!skeleton) skeleton_owner.free(p_rid); @@ -2710,7 +2531,7 @@ void RasterizerIPhone::free(const RID& p_rid) const { } else if (light_owner.owns(p_rid)) { - Light *light = light_owner.get( p_rid ); + Light *light = light_owner.get(p_rid); ERR_FAIL_COND(!light) light_owner.free(p_rid); @@ -2718,20 +2539,19 @@ void RasterizerIPhone::free(const RID& p_rid) const { } else if (light_instance_owner.owns(p_rid)) { - LightInstance *light_instance = light_instance_owner.get( p_rid ); + LightInstance *light_instance = light_instance_owner.get(p_rid); ERR_FAIL_COND(!light_instance); light_instance_owner.free(p_rid); - memdelete( light_instance ); + memdelete(light_instance); } else if (fx_owner.owns(p_rid)) { - FX *fx = fx_owner.get( p_rid ); + FX *fx = fx_owner.get(p_rid); ERR_FAIL_COND(!fx); fx_owner.free(p_rid); - memdelete( fx ); - + memdelete(fx); }; } @@ -2745,10 +2565,9 @@ void RasterizerIPhone::init() { } void RasterizerIPhone::finish() { - } - int RasterizerIPhone::get_render_info(VS::RenderInfo p_info) { +int RasterizerIPhone::get_render_info(VS::RenderInfo p_info) { return false; } @@ -2758,9 +2577,8 @@ RasterizerIPhone::RasterizerIPhone() { frame = 0; }; -RasterizerIPhone::~RasterizerIPhone() { +RasterizerIPhone::~RasterizerIPhone(){ }; - #endif diff --git a/platform/iphone/rasterizer_iphone.h b/platform/iphone/rasterizer_iphone.h index 299a11e895..02cb985dc8 100644 --- a/platform/iphone/rasterizer_iphone.h +++ b/platform/iphone/rasterizer_iphone.h @@ -33,12 +33,12 @@ #include "servers/visual/rasterizer.h" +#include "camera_matrix.h" #include "image.h" -#include "rid.h" -#include "servers/visual_server.h" #include "list.h" #include "map.h" -#include "camera_matrix.h" +#include "rid.h" +#include "servers/visual_server.h" #include "sort.h" #include <ES1/gl.h> @@ -57,7 +57,7 @@ class RasterizerIPhone : public Rasterizer { struct Texture { uint32_t flags; - int width,height; + int width, height; Image::Format format; GLenum target; @@ -72,21 +72,21 @@ class RasterizerIPhone : public Rasterizer { Texture() { - flags=width=height=0; - tex_id=0; - format=Image::FORMAT_L8; - gl_components_cache=0; - format_has_alpha=false; - has_alpha=false; - active=false; - mipmap_dirty=true; + flags = width = height = 0; + tex_id = 0; + format = Image::FORMAT_L8; + gl_components_cache = 0; + format_has_alpha = false; + has_alpha = false; + active = false; + mipmap_dirty = true; } ~Texture() { - if (tex_id!=0) { + if (tex_id != 0) { - glDeleteTextures(1,&tex_id); + glDeleteTextures(1, &tex_id); } } }; @@ -108,16 +108,16 @@ class RasterizerIPhone : public Rasterizer { Material() { - flags[VS::MATERIAL_FLAG_VISIBLE]=true; - flags[VS::MATERIAL_FLAG_DOUBLE_SIDED]=false; - flags[VS::MATERIAL_FLAG_INVERT_FACES]=false; - flags[VS::MATERIAL_FLAG_UNSHADED]=false; - flags[VS::MATERIAL_FLAG_WIREFRAME]=false; + flags[VS::MATERIAL_FLAG_VISIBLE] = true; + flags[VS::MATERIAL_FLAG_DOUBLE_SIDED] = false; + flags[VS::MATERIAL_FLAG_INVERT_FACES] = false; + flags[VS::MATERIAL_FLAG_UNSHADED] = false; + flags[VS::MATERIAL_FLAG_WIREFRAME] = false; parameters[VS::FIXED_MATERIAL_PARAM_DIFFUSE] = Color(0.8, 0.8, 0.8); parameters[VS::FIXED_MATERIAL_PARAM_SPECULAR_EXP] = 12; - for (int i=0; i<VisualServer::FIXED_MATERIAL_PARAM_MAX; i++) { + for (int i = 0; i < VisualServer::FIXED_MATERIAL_PARAM_MAX; i++) { texcoord_mode[i] = VS::FIXED_MATERIAL_TEXCOORD_UV; }; detail_blend_mode = VS::MATERIAL_BLEND_MODE_MIX; @@ -126,7 +126,6 @@ class RasterizerIPhone : public Rasterizer { }; mutable RID_Owner<Material> material_owner; - struct Geometry { enum Type { @@ -146,8 +145,12 @@ class RasterizerIPhone : public Rasterizer { Vector3 scale; Vector3 uv_scale; - Geometry() : scale(1, 1, 1) { has_alpha=false; material_owned = false; } - virtual ~Geometry() {}; + Geometry() + : scale(1, 1, 1) { + has_alpha = false; + material_owned = false; + } + virtual ~Geometry(){}; }; struct GeometryOwner { @@ -155,15 +158,18 @@ class RasterizerIPhone : public Rasterizer { virtual ~GeometryOwner() {} }; - struct Surface : public Geometry { struct ArrayData { - uint32_t ofs,size; + uint32_t ofs, size; bool configured; int components; - ArrayData() { ofs=0; size=0; configured=false; } + ArrayData() { + ofs = 0; + size = 0; + configured = false; + } }; ArrayData array[VS::ARRAY_MAX]; @@ -196,34 +202,32 @@ class RasterizerIPhone : public Rasterizer { Surface() { - array_len=0; - type=GEOMETRY_SURFACE; - primitive=VS::PRIMITIVE_POINTS; - index_array_len=VS::NO_INDEX_ARRAY; - format=0; - stride=0; + array_len = 0; + type = GEOMETRY_SURFACE; + primitive = VS::PRIMITIVE_POINTS; + index_array_len = VS::NO_INDEX_ARRAY; + format = 0; + stride = 0; array_local = index_array_local = 0; vertex_id = index_id = 0; - active=false; + active = false; } ~Surface() { - } }; - struct Mesh { bool active; - Vector<Surface*> surfaces; + Vector<Surface *> surfaces; mutable uint64_t last_pass; Mesh() { - last_pass=0; - active=false; + last_pass = 0; + active = false; } }; mutable RID_Owner<Mesh> mesh_owner; @@ -236,29 +240,25 @@ class RasterizerIPhone : public Rasterizer { Vector<Vector3> normals; Vector<Vector3> uvs; Vector<Color> colors; - }; AABB aabb; List<Primitive> primitives; Poly() { - type=GEOMETRY_POLY; + type = GEOMETRY_POLY; } }; mutable RID_Owner<Poly> poly_owner; - struct Skeleton { Vector<Transform> bones; - }; mutable RID_Owner<Skeleton> skeleton_owner; - struct Light { VS::LightType type; @@ -269,19 +269,18 @@ class RasterizerIPhone : public Rasterizer { bool volumetric_enabled; Color volumetric_color; - Light() { - vars[VS::LIGHT_PARAM_SPOT_ATTENUATION]=1; - vars[VS::LIGHT_PARAM_SPOT_ANGLE]=45; - vars[VS::LIGHT_PARAM_ATTENUATION]=1.0; - vars[VS::LIGHT_PARAM_ENERGY]=1.0; - vars[VS::LIGHT_PARAM_RADIUS]=1.0; - colors[VS::LIGHT_COLOR_AMBIENT]=Color(0,0,0); - colors[VS::LIGHT_COLOR_DIFFUSE]=Color(1,1,1); - colors[VS::LIGHT_COLOR_SPECULAR]=Color(1,1,1); - shadow_enabled=false; - volumetric_enabled=false; + vars[VS::LIGHT_PARAM_SPOT_ATTENUATION] = 1; + vars[VS::LIGHT_PARAM_SPOT_ANGLE] = 45; + vars[VS::LIGHT_PARAM_ATTENUATION] = 1.0; + vars[VS::LIGHT_PARAM_ENERGY] = 1.0; + vars[VS::LIGHT_PARAM_RADIUS] = 1.0; + colors[VS::LIGHT_COLOR_AMBIENT] = Color(0, 0, 0); + colors[VS::LIGHT_COLOR_DIFFUSE] = Color(1, 1, 1); + colors[VS::LIGHT_COLOR_SPECULAR] = Color(1, 1, 1); + shadow_enabled = false; + volumetric_enabled = false; } }; @@ -302,7 +301,6 @@ class RasterizerIPhone : public Rasterizer { uint64_t last_pass; Transform transform; - CameraMatrix projection; Vector<SplitInfo> splits; @@ -321,8 +319,8 @@ class RasterizerIPhone : public Rasterizer { struct RenderList { enum { - MAX_ELEMENTS=4096, - MAX_LIGHTS=4 + MAX_ELEMENTS = 4096, + MAX_LIGHTS = 4 }; struct Element { @@ -330,28 +328,27 @@ class RasterizerIPhone : public Rasterizer { float depth; const Skeleton *skeleton; Transform transform; - LightInstance* lights[MAX_LIGHTS]; + LightInstance *lights[MAX_LIGHTS]; int light_count; const Geometry *geometry; const Material *material; uint64_t light_hash; GeometryOwner *owner; - const ParamOverrideMap* material_overrides; + const ParamOverrideMap *material_overrides; }; - Element _elements[MAX_ELEMENTS]; Element *elements[MAX_ELEMENTS]; int element_count; void clear() { - element_count=0; + element_count = 0; } struct SortZ { - _FORCE_INLINE_ bool operator()(const Element* A, const Element* B ) const { + _FORCE_INLINE_ bool operator()(const Element *A, const Element *B) const { return A->depth > B->depth; } @@ -359,37 +356,37 @@ class RasterizerIPhone : public Rasterizer { void sort_z() { - SortArray<Element*,SortZ> sorter; - sorter.sort(elements,element_count); + SortArray<Element *, SortZ> sorter; + sorter.sort(elements, element_count); } struct SortSkel { - _FORCE_INLINE_ bool operator()(const Element* A, const Element* B ) const { + _FORCE_INLINE_ bool operator()(const Element *A, const Element *B) const { if (A->geometry < B->geometry) return true; else if (A->geometry > B->geometry) return false; - else return (!A->skeleton && B->skeleton); + else + return (!A->skeleton && B->skeleton); } }; void sort_skel() { - SortArray<Element*,SortSkel> sorter; - sorter.sort(elements,element_count); + SortArray<Element *, SortSkel> sorter; + sorter.sort(elements, element_count); } struct SortMat { - _FORCE_INLINE_ bool operator()(const Element* A, const Element* B ) const { + _FORCE_INLINE_ bool operator()(const Element *A, const Element *B) const { if (A->geometry == B->geometry) { if (A->material == B->material) { - return (A->material_overrides < B->material_overrides); } else { @@ -404,13 +401,13 @@ class RasterizerIPhone : public Rasterizer { void sort_mat() { - SortArray<Element*,SortMat> sorter; - sorter.sort(elements,element_count); + SortArray<Element *, SortMat> sorter; + sorter.sort(elements, element_count); } struct SortMatLight { - _FORCE_INLINE_ bool operator()(const Element* A, const Element* B ) const { + _FORCE_INLINE_ bool operator()(const Element *A, const Element *B) const { if (A->geometry == B->geometry) { @@ -419,7 +416,7 @@ class RasterizerIPhone : public Rasterizer { if (A->light_hash == B->light_hash) return (A->material_overrides < B->material_overrides); else - return A->light_hash<B->light_hash; + return A->light_hash < B->light_hash; } else { return (A->material < B->material); @@ -433,57 +430,54 @@ class RasterizerIPhone : public Rasterizer { void sort_mat_light() { - SortArray<Element*,SortMatLight> sorter; - sorter.sort(elements,element_count); + SortArray<Element *, SortMatLight> sorter; + sorter.sort(elements, element_count); } struct LISort { - _FORCE_INLINE_ bool operator ()(const LightInstance *A, const LightInstance *B) const { + _FORCE_INLINE_ bool operator()(const LightInstance *A, const LightInstance *B) const { return (A->hash_aux < B->hash_aux); } }; - _FORCE_INLINE_ void add_element( const Geometry *p_geometry, const Material* p_material,const Transform& p_transform, LightInstance **p_light_instances, int p_light_count, const ParamOverrideMap* p_material_overrides, const Skeleton *p_skeleton, float p_depth, GeometryOwner *p_owner=NULL) { + _FORCE_INLINE_ void add_element(const Geometry *p_geometry, const Material *p_material, const Transform &p_transform, LightInstance **p_light_instances, int p_light_count, const ParamOverrideMap *p_material_overrides, const Skeleton *p_skeleton, float p_depth, GeometryOwner *p_owner = NULL) { - - ERR_FAIL_COND( element_count >= MAX_ELEMENTS ); + ERR_FAIL_COND(element_count >= MAX_ELEMENTS); Element *e = elements[element_count++]; - e->geometry=p_geometry; - e->material=p_material; - e->transform=p_transform; - e->skeleton=p_skeleton; - e->light_hash=0; - e->light_count=p_light_count; - e->owner=p_owner; - e->material_overrides=p_material_overrides; + e->geometry = p_geometry; + e->material = p_material; + e->transform = p_transform; + e->skeleton = p_skeleton; + e->light_hash = 0; + e->light_count = p_light_count; + e->owner = p_owner; + e->material_overrides = p_material_overrides; - if (e->light_count>0) { + if (e->light_count > 0) { - SortArray<LightInstance*,LISort> light_sort; - light_sort.sort(p_light_instances,p_light_count); + SortArray<LightInstance *, LISort> light_sort; + light_sort.sort(p_light_instances, p_light_count); //@TODO OPTIOMIZE - for (int i=0;i<p_light_count;i++) { + for (int i = 0; i < p_light_count; i++) { - e->lights[i]=p_light_instances[i]; + e->lights[i] = p_light_instances[i]; - if (i==0) - e->light_hash=hash_djb2_one_64( make_uint64_t(e->lights[i]) ); + if (i == 0) + e->light_hash = hash_djb2_one_64(make_uint64_t(e->lights[i])); else - e->light_hash=hash_djb2_one_64( make_uint64_t(e->lights[i]),e->light_hash); + e->light_hash = hash_djb2_one_64(make_uint64_t(e->lights[i]), e->light_hash); } - } - } RenderList() { - for (int i=0;i<MAX_ELEMENTS;i++) - elements[i]=&_elements[i]; // assign elements + for (int i = 0; i < MAX_ELEMENTS; i++) + elements[i] = &_elements[i]; // assign elements } }; @@ -532,11 +526,9 @@ class RasterizerIPhone : public Rasterizer { float edge_size; FX(); - }; mutable RID_Owner<FX> fx_owner; - FX *scene_fx; CameraMatrix camera_projection; Transform camera_transform; @@ -547,16 +539,15 @@ class RasterizerIPhone : public Rasterizer { Plane camera_plane; - void _add_geometry( const Geometry* p_geometry, const Transform& p_world, uint32_t p_vertex_format, const RID* p_light_instances, int p_light_count, const ParamOverrideMap* p_material_overrides,const Skeleton* p_skeleton,GeometryOwner *p_owner); + void _add_geometry(const Geometry *p_geometry, const Transform &p_world, uint32_t p_vertex_format, const RID *p_light_instances, int p_light_count, const ParamOverrideMap *p_material_overrides, const Skeleton *p_skeleton, GeometryOwner *p_owner); void _render_list_forward(RenderList *p_render_list); - void _setup_light(LightInstance* p_instance, int p_idx); - void _setup_lights(LightInstance **p_lights,int p_light_count); - void _setup_material(const Geometry *p_geometry,const Material *p_material); - - void _setup_geometry(const Geometry *p_geometry, const Material* p_material); - void _render(const Geometry *p_geometry,const Material *p_material, const Skeleton* p_skeleton); + void _setup_light(LightInstance *p_instance, int p_idx); + void _setup_lights(LightInstance **p_lights, int p_light_count); + void _setup_material(const Geometry *p_geometry, const Material *p_material); + void _setup_geometry(const Geometry *p_geometry, const Material *p_material); + void _render(const Geometry *p_geometry, const Material *p_material, const Skeleton *p_skeleton); /*********/ /* FRAME */ @@ -570,14 +561,13 @@ class RasterizerIPhone : public Rasterizer { uint64_t frame; public: - /* TEXTURE API */ virtual RID texture_create(); - virtual void texture_allocate(RID p_texture,int p_width, int p_height,Image::Format p_format,uint32_t p_flags=VS::TEXTURE_FLAGS_DEFAULT); - virtual void texture_blit_rect(RID p_texture,int p_x,int p_y, const Image& p_image,VS::CubeMapSide p_cube_side=VS::CUBEMAP_LEFT); - virtual Image texture_get_rect(RID p_texture,int p_x,int p_y,int p_width, int p_height,VS::CubeMapSide p_cube_side=VS::CUBEMAP_LEFT) const; - virtual void texture_set_flags(RID p_texture,uint32_t p_flags); + virtual void texture_allocate(RID p_texture, int p_width, int p_height, Image::Format p_format, uint32_t p_flags = VS::TEXTURE_FLAGS_DEFAULT); + virtual void texture_blit_rect(RID p_texture, int p_x, int p_y, const Image &p_image, VS::CubeMapSide p_cube_side = VS::CUBEMAP_LEFT); + virtual Image texture_get_rect(RID p_texture, int p_x, int p_y, int p_width, int p_height, VS::CubeMapSide p_cube_side = VS::CUBEMAP_LEFT) const; + virtual void texture_set_flags(RID p_texture, uint32_t p_flags); virtual uint32_t texture_get_flags(RID p_texture) const; virtual Image::Format texture_get_format(RID p_texture) const; virtual uint32_t texture_get_width(RID p_texture) const; @@ -588,81 +578,80 @@ public: virtual RID shader_create(); - virtual void shader_node_add(RID p_shader,VS::ShaderNodeType p_type,int p_id); - virtual void shader_node_remove(RID p_shader,int p_id); + virtual void shader_node_add(RID p_shader, VS::ShaderNodeType p_type, int p_id); + virtual void shader_node_remove(RID p_shader, int p_id); virtual void shader_node_change_type(RID p_shader, int p_id, VS::ShaderNodeType p_type); - virtual void shader_node_set_param(RID p_shader, int p_id, const Variant& p_value); + virtual void shader_node_set_param(RID p_shader, int p_id, const Variant &p_value); - virtual void shader_get_node_list(RID p_shader,List<int> *p_node_list) const; - virtual VS::ShaderNodeType shader_node_get_type(RID p_shader,int p_id) const; - virtual Variant shader_node_get_param(RID p_shader,int p_id) const; + virtual void shader_get_node_list(RID p_shader, List<int> *p_node_list) const; + virtual VS::ShaderNodeType shader_node_get_type(RID p_shader, int p_id) const; + virtual Variant shader_node_get_param(RID p_shader, int p_id) const; - virtual void shader_connect(RID p_shader,int p_src_id,int p_src_slot, int p_dst_id,int p_dst_slot); - virtual bool shader_is_connected(RID p_shader,int p_src_id,int p_src_slot, int p_dst_id,int p_dst_slot) const; - virtual void shader_disconnect(RID p_shader,int p_src_id,int p_src_slot, int p_dst_id,int p_dst_slot); + virtual void shader_connect(RID p_shader, int p_src_id, int p_src_slot, int p_dst_id, int p_dst_slot); + virtual bool shader_is_connected(RID p_shader, int p_src_id, int p_src_slot, int p_dst_id, int p_dst_slot) const; + virtual void shader_disconnect(RID p_shader, int p_src_id, int p_src_slot, int p_dst_id, int p_dst_slot); - virtual void shader_get_connections(RID p_shader,List<VS::ShaderConnection> *p_connections) const; + virtual void shader_get_connections(RID p_shader, List<VS::ShaderConnection> *p_connections) const; virtual void shader_clear(RID p_shader); /* COMMON MATERIAL API */ - virtual void material_set_param(RID p_material, const StringName& p_param, const Variant& p_value); - virtual Variant material_get_param(RID p_material, const StringName& p_param) const; + virtual void material_set_param(RID p_material, const StringName &p_param, const Variant &p_value); + virtual Variant material_get_param(RID p_material, const StringName &p_param) const; virtual void material_get_param_list(RID p_material, List<String> *p_param_list) const; - virtual void material_set_flag(RID p_material, VS::MaterialFlag p_flag,bool p_enabled); - virtual bool material_get_flag(RID p_material,VS::MaterialFlag p_flag) const; + virtual void material_set_flag(RID p_material, VS::MaterialFlag p_flag, bool p_enabled); + virtual bool material_get_flag(RID p_material, VS::MaterialFlag p_flag) const; - virtual void material_set_blend_mode(RID p_material,VS::MaterialBlendMode p_mode); + virtual void material_set_blend_mode(RID p_material, VS::MaterialBlendMode p_mode); virtual VS::MaterialBlendMode material_get_blend_mode(RID p_material) const; - virtual void material_set_line_width(RID p_material,float p_line_width); + virtual void material_set_line_width(RID p_material, float p_line_width); virtual float material_get_line_width(RID p_material) const; /* FIXED MATERIAL */ virtual RID material_create(); - virtual void fixed_material_set_parameter(RID p_material, VS::FixedSpatialMaterialParam p_parameter, const Variant& p_value); - virtual Variant fixed_material_get_parameter(RID p_material,VS::FixedSpatialMaterialParam p_parameter) const; + virtual void fixed_material_set_parameter(RID p_material, VS::FixedSpatialMaterialParam p_parameter, const Variant &p_value); + virtual Variant fixed_material_get_parameter(RID p_material, VS::FixedSpatialMaterialParam p_parameter) const; - virtual void fixed_material_set_texture(RID p_material,VS::FixedSpatialMaterialParam p_parameter, RID p_texture); - virtual RID fixed_material_get_texture(RID p_material,VS::FixedSpatialMaterialParam p_parameter) const; + virtual void fixed_material_set_texture(RID p_material, VS::FixedSpatialMaterialParam p_parameter, RID p_texture); + virtual RID fixed_material_get_texture(RID p_material, VS::FixedSpatialMaterialParam p_parameter) const; - virtual void fixed_material_set_detail_blend_mode(RID p_material,VS::MaterialBlendMode p_mode); + virtual void fixed_material_set_detail_blend_mode(RID p_material, VS::MaterialBlendMode p_mode); virtual VS::MaterialBlendMode fixed_material_get_detail_blend_mode(RID p_material) const; - virtual void fixed_material_set_texgen_mode(RID p_material,VS::FixedSpatialMaterialTexGenMode p_mode); + virtual void fixed_material_set_texgen_mode(RID p_material, VS::FixedSpatialMaterialTexGenMode p_mode); virtual VS::FixedSpatialMaterialTexGenMode fixed_material_get_texgen_mode(RID p_material) const; - virtual void fixed_material_set_texcoord_mode(RID p_material,VS::FixedSpatialMaterialParam p_parameter, VS::FixedSpatialMaterialTexCoordMode p_mode); - virtual VS::FixedSpatialMaterialTexCoordMode fixed_material_get_texcoord_mode(RID p_material,VS::FixedSpatialMaterialParam p_parameter) const; + virtual void fixed_material_set_texcoord_mode(RID p_material, VS::FixedSpatialMaterialParam p_parameter, VS::FixedSpatialMaterialTexCoordMode p_mode); + virtual VS::FixedSpatialMaterialTexCoordMode fixed_material_get_texcoord_mode(RID p_material, VS::FixedSpatialMaterialParam p_parameter) const; - virtual void fixed_material_set_uv_transform(RID p_material,const Transform& p_transform); + virtual void fixed_material_set_uv_transform(RID p_material, const Transform &p_transform); virtual Transform fixed_material_get_uv_transform(RID p_material) const; /* SHADER MATERIAL */ virtual RID shader_material_create() const; - virtual void shader_material_set_vertex_shader(RID p_material,RID p_shader,bool p_owned=false); + virtual void shader_material_set_vertex_shader(RID p_material, RID p_shader, bool p_owned = false); virtual RID shader_material_get_vertex_shader(RID p_material) const; - virtual void shader_material_set_fragment_shader(RID p_material,RID p_shader,bool p_owned=false); + virtual void shader_material_set_fragment_shader(RID p_material, RID p_shader, bool p_owned = false); virtual RID shader_material_get_fragment_shader(RID p_material) const; - /* MESH API */ virtual RID mesh_create(); - virtual void mesh_add_surface(RID p_mesh,VS::PrimitiveType p_primitive,uint32_t p_format,int p_array_len,int p_index_array_len=VS::NO_INDEX_ARRAY); + virtual void mesh_add_surface(RID p_mesh, VS::PrimitiveType p_primitive, uint32_t p_format, int p_array_len, int p_index_array_len = VS::NO_INDEX_ARRAY); - virtual Error mesh_surface_set_array(RID p_mesh, int p_surface,VS::ArrayType p_type,const Variant& p_array) ; - virtual Variant mesh_surface_get_array(RID p_mesh, int p_surface,VS::ArrayType p_type) const; + virtual Error mesh_surface_set_array(RID p_mesh, int p_surface, VS::ArrayType p_type, const Variant &p_array); + virtual Variant mesh_surface_get_array(RID p_mesh, int p_surface, VS::ArrayType p_type) const; - virtual void mesh_surface_set_material(RID p_mesh, int p_surface, RID p_material,bool p_owned=false); + virtual void mesh_surface_set_material(RID p_mesh, int p_surface, RID p_material, bool p_owned = false); virtual RID mesh_surface_get_material(RID p_mesh, int p_surface) const; virtual int mesh_surface_get_array_len(RID p_mesh, int p_surface) const; @@ -670,7 +659,7 @@ public: virtual uint32_t mesh_surface_get_format(RID p_mesh, int p_surface) const; virtual VS::PrimitiveType mesh_surface_get_primitive_type(RID p_mesh, int p_surface) const; - virtual void mesh_erase_surface(RID p_mesh,int p_index); + virtual void mesh_erase_surface(RID p_mesh, int p_index); virtual int mesh_get_surface_count(RID p_mesh) const; virtual AABB mesh_get_aabb(RID p_mesh) const; @@ -679,30 +668,29 @@ public: virtual RID multimesh_create(); - virtual void multimesh_set_instance_count(RID p_multimesh,int p_count); + virtual void multimesh_set_instance_count(RID p_multimesh, int p_count); virtual int multimesh_get_instance_count(RID p_multimesh) const; - virtual void multimesh_set_mesh(RID p_multimesh,RID p_mesh); - virtual void multimesh_set_aabb(RID p_multimesh,const AABB& p_aabb); - virtual void multimesh_instance_set_transform(RID p_multimesh,int p_index,const Transform& p_transform); - virtual void multimesh_instance_set_color(RID p_multimesh,int p_index,const Color& p_color); + virtual void multimesh_set_mesh(RID p_multimesh, RID p_mesh); + virtual void multimesh_set_aabb(RID p_multimesh, const AABB &p_aabb); + virtual void multimesh_instance_set_transform(RID p_multimesh, int p_index, const Transform &p_transform); + virtual void multimesh_instance_set_color(RID p_multimesh, int p_index, const Color &p_color); virtual RID multimesh_get_mesh(RID p_multimesh) const; virtual AABB multimesh_get_aabb(RID p_multimesh) const; - virtual Transform multimesh_instance_get_transform(RID p_multimesh,int p_index) const; - virtual Color multimesh_instance_get_color(RID p_multimesh,int p_index) const; + virtual Transform multimesh_instance_get_transform(RID p_multimesh, int p_index) const; + virtual Color multimesh_instance_get_color(RID p_multimesh, int p_index) const; /* POLY API */ virtual RID poly_create(); - virtual void poly_set_material(RID p_poly, RID p_material,bool p_owned=false); - virtual void poly_add_primitive(RID p_poly, const Vector<Vector3>& p_points,const Vector<Vector3>& p_normals,const Vector<Color>& p_colors,const Vector<Vector3>& p_uvs); + virtual void poly_set_material(RID p_poly, RID p_material, bool p_owned = false); + virtual void poly_add_primitive(RID p_poly, const Vector<Vector3> &p_points, const Vector<Vector3> &p_normals, const Vector<Color> &p_colors, const Vector<Vector3> &p_uvs); virtual void poly_clear(RID p_poly); virtual AABB poly_get_aabb(RID p_poly) const; - /* PARTICLES API */ virtual RID particles_create(); @@ -713,19 +701,19 @@ public: virtual void particles_set_emitting(RID p_particles, bool p_emitting); virtual bool particles_is_emitting(RID p_particles) const; - virtual void particles_set_visibility_aabb(RID p_particles, const AABB& p_visibility); + virtual void particles_set_visibility_aabb(RID p_particles, const AABB &p_visibility); virtual AABB particles_get_visibility_aabb(RID p_particles) const; - virtual void particles_set_emission_half_extents(RID p_particles, const Vector3& p_half_extents); + virtual void particles_set_emission_half_extents(RID p_particles, const Vector3 &p_half_extents); virtual Vector3 particles_get_emission_half_extents(RID p_particles) const; - virtual void particles_set_gravity_normal(RID p_particles, const Vector3& p_normal); + virtual void particles_set_gravity_normal(RID p_particles, const Vector3 &p_normal); virtual Vector3 particles_get_gravity_normal(RID p_particles) const; - virtual void particles_set_variable(RID p_particles, VS::ParticleVariable p_variable,float p_value); + virtual void particles_set_variable(RID p_particles, VS::ParticleVariable p_variable, float p_value); virtual float particles_get_variable(RID p_particles, VS::ParticleVariable p_variable) const; - virtual void particles_set_randomness(RID p_particles, VS::ParticleVariable p_variable,float p_randomness); + virtual void particles_set_randomness(RID p_particles, VS::ParticleVariable p_variable, float p_randomness); virtual float particles_get_randomness(RID p_particles, VS::ParticleVariable p_variable) const; virtual void particles_set_color_phase_pos(RID p_particles, int p_phase, float p_pos); @@ -734,19 +722,19 @@ public: virtual void particles_set_color_phases(RID p_particles, int p_phases); virtual int particles_get_color_phases(RID p_particles) const; - virtual void particles_set_color_phase_color(RID p_particles, int p_phase, const Color& p_color); + virtual void particles_set_color_phase_color(RID p_particles, int p_phase, const Color &p_color); virtual Color particles_get_color_phase_color(RID p_particles, int p_phase) const; virtual void particles_set_attractors(RID p_particles, int p_attractors); virtual int particles_get_attractors(RID p_particles) const; - virtual void particles_set_attractor_pos(RID p_particles, int p_attractor, const Vector3& p_pos); - virtual Vector3 particles_get_attractor_pos(RID p_particles,int p_attractor) const; + virtual void particles_set_attractor_pos(RID p_particles, int p_attractor, const Vector3 &p_pos); + virtual Vector3 particles_get_attractor_pos(RID p_particles, int p_attractor) const; virtual void particles_set_attractor_strength(RID p_particles, int p_attractor, float p_force); - virtual float particles_get_attractor_strength(RID p_particles,int p_attractor) const; + virtual float particles_get_attractor_strength(RID p_particles, int p_attractor) const; - virtual void particles_set_material(RID p_particles, RID p_material,bool p_owned=false); + virtual void particles_set_material(RID p_particles, RID p_material, bool p_owned = false); virtual RID particles_get_material(RID p_particles) const; virtual AABB particles_get_aabb(RID p_particles) const; @@ -758,10 +746,10 @@ public: virtual int beam_get_point_count(RID p_beam) const; virtual void beam_clear(RID p_beam); - virtual void beam_set_point(RID p_beam,int p_point,Vector3& p_pos); - virtual Vector3 beam_get_point(RID p_beam,int p_point) const; + virtual void beam_set_point(RID p_beam, int p_point, Vector3 &p_pos); + virtual Vector3 beam_get_point(RID p_beam, int p_point) const; - virtual void beam_set_primitive(RID p_beam,VS::BeamPrimitive p_primitive); + virtual void beam_set_primitive(RID p_beam, VS::BeamPrimitive p_primitive); virtual VS::BeamPrimitive beam_get_primitive(RID p_beam) const; virtual void beam_set_material(RID p_beam, RID p_material); @@ -771,27 +759,26 @@ public: /* SKELETON API */ virtual RID skeleton_create(); - virtual void skeleton_resize(RID p_skeleton,int p_bones); + virtual void skeleton_resize(RID p_skeleton, int p_bones); virtual int skeleton_get_bone_count(RID p_skeleton) const; - virtual void skeleton_bone_set_transform(RID p_skeleton,int p_bone, const Transform& p_transform); - virtual Transform skeleton_bone_get_transform(RID p_skeleton,int p_bone); - + virtual void skeleton_bone_set_transform(RID p_skeleton, int p_bone, const Transform &p_transform); + virtual Transform skeleton_bone_get_transform(RID p_skeleton, int p_bone); /* LIGHT API */ virtual RID light_create(VS::LightType p_type); virtual VS::LightType light_get_type(RID p_light) const; - virtual void light_set_color(RID p_light,VS::LightColor p_type, const Color& p_color); - virtual Color light_get_color(RID p_light,VS::LightColor p_type) const; + virtual void light_set_color(RID p_light, VS::LightColor p_type, const Color &p_color); + virtual Color light_get_color(RID p_light, VS::LightColor p_type) const; - virtual void light_set_shadow(RID p_light,bool p_enabled); + virtual void light_set_shadow(RID p_light, bool p_enabled); virtual bool light_has_shadow(RID p_light) const; - virtual void light_set_volumetric(RID p_light,bool p_enabled); + virtual void light_set_volumetric(RID p_light, bool p_enabled); virtual bool light_is_volumetric(RID p_light) const; - virtual void light_set_projector(RID p_light,RID p_texture); + virtual void light_set_projector(RID p_light, RID p_texture); virtual RID light_get_projector(RID p_light) const; virtual void light_set_var(RID p_light, VS::LightParam p_var, float p_value); @@ -799,43 +786,42 @@ public: virtual AABB light_get_aabb(RID p_poly) const; - virtual RID light_instance_create(RID p_light); - virtual void light_instance_set_transform(RID p_light_instance,const Transform& p_transform); + virtual void light_instance_set_transform(RID p_light_instance, const Transform &p_transform); virtual void light_instance_set_active_hint(RID p_light_instance); virtual bool light_instance_has_shadow(RID p_light_instance) const; virtual bool light_instance_assign_shadow(RID p_light_instance); virtual ShadowType light_instance_get_shadow_type(RID p_light_instance) const; virtual int light_instance_get_shadow_passes(RID p_light_instance) const; - virtual void light_instance_set_pssm_split_info(RID p_light_instance, int p_split, float p_near,float p_far, const CameraMatrix& p_camera, const Transform& p_transform); + virtual void light_instance_set_pssm_split_info(RID p_light_instance, int p_split, float p_near, float p_far, const CameraMatrix &p_camera, const Transform &p_transform); /* PARTICLES INSTANCE */ virtual RID particles_instance_create(RID p_particles); - virtual void particles_instance_set_transform(RID p_particles_instance,const Transform& p_transform); + virtual void particles_instance_set_transform(RID p_particles_instance, const Transform &p_transform); /* RENDER API */ /* all calls (inside begin/end shadow) are always warranted to be in the following order: */ virtual void begin_frame(); - virtual void set_viewport(const VS::ViewportRect& p_viewport); + virtual void set_viewport(const VS::ViewportRect &p_viewport); - virtual void begin_scene(RID p_fx=RID(),VS::ScenarioDebugMode p_debug=VS::SCENARIO_DEBUG_DISABLED); - virtual void begin_shadow_map( RID p_light_instance, int p_shadow_pass ); + virtual void begin_scene(RID p_fx = RID(), VS::ScenarioDebugMode p_debug = VS::SCENARIO_DEBUG_DISABLED); + virtual void begin_shadow_map(RID p_light_instance, int p_shadow_pass); - virtual void set_camera(const Transform& p_world,const CameraMatrix& p_projection); + virtual void set_camera(const Transform &p_world, const CameraMatrix &p_projection); - virtual void add_light( RID p_light_instance ); ///< all "add_light" calls happen before add_geometry calls + virtual void add_light(RID p_light_instance); ///< all "add_light" calls happen before add_geometry calls - typedef Map<StringName,Variant> ParamOverrideMap; + typedef Map<StringName, Variant> ParamOverrideMap; - virtual void add_mesh( RID p_mesh, const Transform* p_world, const RID* p_light_instances, int p_light_count, const ParamOverrideMap* p_material_overrides = NULL, RID p_skeleton=RID()); - virtual void add_multimesh( RID p_multimesh, const Transform* p_world, const RID* p_light_instances, int p_light_count, const ParamOverrideMap* p_material_overrides = NULL); - virtual void add_poly( RID p_poly, const Transform* p_world, const RID* p_light_instances, int p_light_count, const ParamOverrideMap* p_material_overrides = NULL); - virtual void add_beam( RID p_beam, const Transform* p_world, const RID* p_light_instances, int p_light_count, const ParamOverrideMap* p_material_overrides = NULL); - virtual void add_particles( RID p_particle_instance, const RID* p_light_instances, int p_light_count, const ParamOverrideMap* p_material_overrides = NULL); + virtual void add_mesh(RID p_mesh, const Transform *p_world, const RID *p_light_instances, int p_light_count, const ParamOverrideMap *p_material_overrides = NULL, RID p_skeleton = RID()); + virtual void add_multimesh(RID p_multimesh, const Transform *p_world, const RID *p_light_instances, int p_light_count, const ParamOverrideMap *p_material_overrides = NULL); + virtual void add_poly(RID p_poly, const Transform *p_world, const RID *p_light_instances, int p_light_count, const ParamOverrideMap *p_material_overrides = NULL); + virtual void add_beam(RID p_beam, const Transform *p_world, const RID *p_light_instances, int p_light_count, const ParamOverrideMap *p_material_overrides = NULL); + virtual void add_particles(RID p_particle_instance, const RID *p_light_instances, int p_light_count, const ParamOverrideMap *p_material_overrides = NULL); virtual void end_scene(); virtual void end_shadow_map(); @@ -846,40 +832,40 @@ public: virtual void canvas_begin(); virtual void canvas_set_transparency(float p_transparency); - virtual void canvas_set_rect(const Rect2& p_rect, bool p_clip); - virtual void canvas_draw_line(const Point2& p_from, const Point2& p_to,const Color& p_color,float p_width); - virtual void canvas_draw_rect(const Rect2& p_rect, bool p_region, const Rect2& p_source,bool p_tile,RID p_texture,const Color& p_modulate); - virtual void canvas_draw_style_box(const Rect2& p_rect, RID p_texture,const float *p_margins, bool p_draw_center=true); - virtual void canvas_draw_primitive(const Vector<Point2>& p_points, const Vector<Color>& p_colors,const Vector<Point2>& p_uvs, RID p_texture); + virtual void canvas_set_rect(const Rect2 &p_rect, bool p_clip); + virtual void canvas_draw_line(const Point2 &p_from, const Point2 &p_to, const Color &p_color, float p_width); + virtual void canvas_draw_rect(const Rect2 &p_rect, bool p_region, const Rect2 &p_source, bool p_tile, RID p_texture, const Color &p_modulate); + virtual void canvas_draw_style_box(const Rect2 &p_rect, RID p_texture, const float *p_margins, bool p_draw_center = true); + virtual void canvas_draw_primitive(const Vector<Point2> &p_points, const Vector<Color> &p_colors, const Vector<Point2> &p_uvs, RID p_texture); /* FX */ virtual RID fx_create(); - virtual void fx_get_effects(RID p_fx,List<String> *p_effects) const; - virtual void fx_set_active(RID p_fx,const String& p_effect, bool p_active); - virtual bool fx_is_active(RID p_fx,const String& p_effect) const; - virtual void fx_get_effect_params(RID p_fx,const String& p_effect,List<PropertyInfo> *p_params) const; - virtual Variant fx_get_effect_param(RID p_fx,const String& p_effect,const String& p_param) const; - virtual void fx_set_effect_param(RID p_fx,const String& p_effect, const String& p_param, const Variant& p_pvalue); + virtual void fx_get_effects(RID p_fx, List<String> *p_effects) const; + virtual void fx_set_active(RID p_fx, const String &p_effect, bool p_active); + virtual bool fx_is_active(RID p_fx, const String &p_effect) const; + virtual void fx_get_effect_params(RID p_fx, const String &p_effect, List<PropertyInfo> *p_params) const; + virtual Variant fx_get_effect_param(RID p_fx, const String &p_effect, const String &p_param) const; + virtual void fx_set_effect_param(RID p_fx, const String &p_effect, const String &p_param, const Variant &p_pvalue); /*MISC*/ - virtual bool is_texture(const RID& p_rid) const; - virtual bool is_material(const RID& p_rid) const; - virtual bool is_mesh(const RID& p_rid) const; - virtual bool is_multimesh(const RID& p_rid) const; - virtual bool is_poly(const RID& p_rid) const; + virtual bool is_texture(const RID &p_rid) const; + virtual bool is_material(const RID &p_rid) const; + virtual bool is_mesh(const RID &p_rid) const; + virtual bool is_multimesh(const RID &p_rid) const; + virtual bool is_poly(const RID &p_rid) const; virtual bool is_particles(const RID &p_beam) const; virtual bool is_beam(const RID &p_beam) const; - virtual bool is_light(const RID& p_rid) const; - virtual bool is_light_instance(const RID& p_rid) const; - virtual bool is_particles_instance(const RID& p_rid) const; - virtual bool is_skeleton(const RID& p_rid) const; - virtual bool is_fx(const RID& p_rid) const; - virtual bool is_shader(const RID& p_rid) const; + virtual bool is_light(const RID &p_rid) const; + virtual bool is_light_instance(const RID &p_rid) const; + virtual bool is_particles_instance(const RID &p_rid) const; + virtual bool is_skeleton(const RID &p_rid) const; + virtual bool is_fx(const RID &p_rid) const; + virtual bool is_shader(const RID &p_rid) const; - virtual void free(const RID& p_rid) const; + virtual void free(const RID &p_rid) const; virtual void init(); virtual void finish(); diff --git a/platform/iphone/sem_iphone.cpp b/platform/iphone/sem_iphone.cpp index d8913feb5f..e74c696607 100644 --- a/platform/iphone/sem_iphone.cpp +++ b/platform/iphone/sem_iphone.cpp @@ -28,16 +28,15 @@ /*************************************************************************/ #include "sem_iphone.h" -#include <unistd.h> #include <fcntl.h> +#include <unistd.h> -void cgsem_init(cgsem_t*); -void cgsem_post(cgsem_t*); -void cgsem_wait(cgsem_t*); -void cgsem_destroy(cgsem_t*); +void cgsem_init(cgsem_t *); +void cgsem_post(cgsem_t *); +void cgsem_wait(cgsem_t *); +void cgsem_destroy(cgsem_t *); -void cgsem_init(cgsem_t *cgsem) -{ +void cgsem_init(cgsem_t *cgsem) { int flags, fd, i; pipe(cgsem->pipefd); @@ -52,31 +51,26 @@ void cgsem_init(cgsem_t *cgsem) } } -void cgsem_post(cgsem_t *cgsem) -{ +void cgsem_post(cgsem_t *cgsem) { const char buf = 1; write(cgsem->pipefd[1], &buf, 1); } -void cgsem_wait(cgsem_t *cgsem) -{ +void cgsem_wait(cgsem_t *cgsem) { char buf; read(cgsem->pipefd[0], &buf, 1); } -void cgsem_destroy(cgsem_t *cgsem) -{ +void cgsem_destroy(cgsem_t *cgsem) { close(cgsem->pipefd[1]); close(cgsem->pipefd[0]); } - #include "os/memory.h" #include <errno.h> - Error SemaphoreIphone::wait() { cgsem_wait(&sem); @@ -94,15 +88,14 @@ int SemaphoreIphone::get() const { return 0; } - Semaphore *SemaphoreIphone::create_semaphore_iphone() { - return memnew( SemaphoreIphone ); + return memnew(SemaphoreIphone); } void SemaphoreIphone::make_default() { - create_func=create_semaphore_iphone; + create_func = create_semaphore_iphone; } SemaphoreIphone::SemaphoreIphone() { @@ -110,11 +103,7 @@ SemaphoreIphone::SemaphoreIphone() { cgsem_init(&sem); } - SemaphoreIphone::~SemaphoreIphone() { cgsem_destroy(&sem); } - - - diff --git a/platform/iphone/sem_iphone.h b/platform/iphone/sem_iphone.h index e00dd8f3dd..8a87ab47ca 100644 --- a/platform/iphone/sem_iphone.h +++ b/platform/iphone/sem_iphone.h @@ -44,7 +44,6 @@ class SemaphoreIphone : public Semaphore { static Semaphore *create_semaphore_iphone(); public: - virtual Error wait(); virtual Error post(); virtual int get() const; @@ -53,8 +52,6 @@ public: SemaphoreIphone(); ~SemaphoreIphone(); - }; - #endif diff --git a/platform/iphone/view_controller.h b/platform/iphone/view_controller.h index f919c06af2..ca05818040 100644 --- a/platform/iphone/view_controller.h +++ b/platform/iphone/view_controller.h @@ -26,11 +26,10 @@ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#import <UIKit/UIKit.h> #import <GameKit/GameKit.h> +#import <UIKit/UIKit.h> @interface ViewController : UIViewController <GKGameCenterControllerDelegate> { - }; - (BOOL)shouldAutorotateToInterfaceOrientation: |