Graphics, Audio, Sensor: Tips For Game Development

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 45

Tips for game development:

Graphics, Audio, Sensor


bada Developer Day in Seoul Dec 08, 2010

Copyright 2010 Samsung Electronics, Co., Ltd. All rights reserved

Contents
Games in bada Audio tips Sensor tips 3D rendering tips Summary

*This material is based on bada SDK 1.2.0

Games in bada
Many games in Appstore
Videos or live demos

bada features for games


Input Output

Sensors

Weather

Graphics

Face detection Sound Service-centric

Vibration
Audio

$2 $3 In-App Remote contents purchasing SNS Gateway


4

Audio tips

Two ways to play sound


General-purpose audio/video playback
Multiple audio playback (max.: 10) Supports streaming* MP3, WMA, MIDI, ..
*Streaming protocol: RTSP (API 1.0), HTTP (API 1.1)

Player AudioOut

Plays only PCM data


Multiple audio playback (max.: 64) Double buffering is possible

Player
Step 1: Create a Player instance
pPlayer = new Player; pPlayer->Construct(*pListener); // IPlayerEventListener

Step 2: Load a file and play it


result r = pPlayer->OpenFile(path); pPlayer->Play();

Step 3: Stop playing and close it


pPlayer->Stop(); pPlayer->Close();

AudioOut
Step 1: Create an AudioOut instance
pAO = new AudioOut(); pAO->Construct(*pListener);// IAudioOutEventListener //Prepares the audio output device pAO->Prepare(AUDIO_TYPE_PCM_S16_LE, AUDIO_CHANNEL_TYPE_MONO, SAMPLERATE);

Step 2: Write PCM data


// Fill buffer with PCM data pAO->WriteBuffer(*pOutBuffer);

Step 3: Play the sound


pAO->Start();

AudioOut
Step 4: Process events
void EventListener::OnAudioOutBufferEndReached (Osp::Media::AudioOut &src) { //Write Next PCM data }

Step 5: Stop the sound


pAO->Stop(); //or Reset()

Audio tips
Preferred PCM format Double buffering Sound mixing Handled by platform Handled by application

Use the preferred PCM format to reduce the internal operations


Field Channels Sample rate Bit per sample Values Stereo 44.1Khz 16-bit

10

Audio tips
Preferred PCM format Double buffering Sound mixing Handled by platform Handled by application
Event: Buffer End Reached Buffer1 Buffer2 Buffer3 Step 1. Initialize AudioOut Step 2. Write a buffer two times Step 3. Start playback Step 4. Playback is ended Step 5. Event is fired Buffer2 is used by AudioOut

Reduce latency
AudioOut Device

Application

Step 6. Write a new buffer


11

Audio tips
Preferred PCM format Double buffering Sound mixing Handled by platform Handled by application

Sound mixing Combine multiple sounds into one

Sound mixing by application reduces the internal resource and event processing

12

Audio tips
Preferred PCM format Double buffering Sound mixing Handled by platform Handled by application

Headset Platform will change the sound path automatically*

Incoming call
Player and AudioOut are stopped by the platform** The application should resume them***
* Osp::System::DeviceManager ** IAudioOutEventListener::OnAudioOutInterrupted *** IAudioOutEventListener::OnAudioOutRelased
13

Audio tips
Preferred PCM format Double buffering Sound mixing Handled by platform Handled by application

Silent mode
No event is fired Check the silent mode*

Side volume key** Foreground/Background


Stop the audio on background
*Osp::System::SettingInfo **Osp::Ui::IKeyEventListener
14

Sensor tips

Sensor
Sensors
Type Acceleration sensor Proximity sensor Tilt sensor Properties x, y, z 1 (on) or 0 (off) Azimuth, Pitch, Roll

Magnetic sensor (compass) x, y, z

SensorManager
Manages built-in sensors Polls sensors for data and delivers it to applications at specified intervals.
16

Getting sensor data


Step 1: Create a SensorManager
Osp::Uix::SensorManager sensorMgr; sensorMgr.Construct();

Step 2: Add a listener


sensorMgr.GetMaxInterval( SENSOR_TYPE_MAGNETIC, interval); sensorMgr.AddSensorListener( *this, SENSOR_TYPE_MAGNETIC, interval, false);

Step 3: Get sensor data from event-listener*


Void OnDataReceived(SensorType sensorType, SensorData& sensorData, result r) { }
* Event hander should return immediately, else event delay or event handling problem will occur
17

Multi-touch
The number of points depends on the hardware

18

Multi-touch
Step 1: Enable multi-touch
Touch touch; touch.SetMultipointEnabled(*this, true);

Step 2: Get multi-touch information


Touch touch; IList* pList = null; pList = touch.GetTouchInfoListN(source); if (pList) { for(int i = 0; i < pList->GetCount(); i++ ) TouchInfo *pTouchInfo = static_cast<TouchInfo *>(pList->GetAt(i)); pList->RemoveAll(true); delete pList; }

19

3D rendering tips

3D rendering in bada
bada supports
OpenGL ES 1.1/2.0
1.1 Fixed function hardware 2.0 Fully programmable 3D graphics

EGL
Manages contexts and drawing surfaces

Timer-based rendering loop Rendering on every kind of controls

21

3D rendering in bada
Timer-based rendering loop
Step 1: Create a timer
pTimer= new Timer; pTimer->Construct(*this); pTimer->Start(TIME_OUT);

Step 2: Implement event listener


class GlesCube11 : public Osp::Base::Runtime::ITimerEventListener void OnTimerExpired(Osp::Base::Runtime::Timer& timer);

Step 3: Handle timer event


void GlesCube11::OnTimerExpired(Timer& timer){ pTimer->Start(TIME_OUT); Draw(); // draw something.. }
22

3D rendering in bada
Initialize EGL
bool GlesCube11::InitEGL() { EGLint numConfigs = 1; EGLint eglConfigList[] = {/**/}; EGLint eglContextList[] = {/**/}; eglBindAPI(EGL_OPENGL_ES_API); eglDisplay = eglGetDisplay( (EGLNativeDisplayType)EGL_DEFAULT_DISPLAY); eglInitialize(eglDisplay, null, null); eglChooseConfig(eglDisplay, eglConfigList, &eglConfig, 1, &numConfigs); eglSurface = eglCreateWindowSurface(eglDisplay, eglConfig, (EGLNativeWindowType)pForm, null); ... }

23

3D rendering in bada
Checks OpenGLES version of device
void Test1::CheckGLES(void) { String key(L"OpenGLESVersion"); String GLESVersion; SystemInfo::GetValue(key,GLESVersion); AppLog("%ls", GLESVersion.GetPointer()); }

Result string
Device Wave/Wave II Wave525
24

Result 1.1/2.0

3D accelerator of Wave/Wave II
POWERVR SGX
Unified Shader Architecture
Load balancing Mostly identical capabilities of shaders

Tile-based Deferred Rendering (TBDR)

25

3D accelerator of Wave/Wave II
Related resources

Visit http://www.imgtec.com

26

Tips for 3D rendering


Texture
Bitmaps are added to the surface of geometry

Geometry
Represents 3D object using geometric entities such as triangles, lines, and so on

Shader
Program to add special effects to 3D rendering

27

Texture tips
Use texture atlas Use mipmap Load all textures on loading time Use FBO instead of pbuffer

Texture atlas Contains many sub images

Reduces the CPU overhead to load texture

28

Texture tips
Use texture atlas Use mipmap Load all textures on loading time Use FBO instead of pbuffer

Mipmap Image set of different scales

Improves speed and quality Removes cache miss Removes aliasing


29

Texture tips
Use texture atlas Use mipmap Load all textures on loading time Use FBO instead of pbuffer

Reduces the frame-drops during run-time Loading texture has overhead

30

Texture tips
Use texture atlas Use mipmap Load all textures on loading time Use FBO instead of pbuffer

Frame Buffer Object (FBO) For off-screen rendering

FBO is more efficient than pbuffer


31

Geometry tips
Simplify geometry Order 3D geometry optimally Use VBO if possible Use object culling

You do not need a very complex model for mobile devices

4M triangles

500 triangles

500 triangles + normal map

32

Geometry tips
Simplify geometry Order 3D geometry optimally Use VBO if possible Use object culling
V0

Traversal order of vertex data


V1 V3 V5

V6 V2
V4

Interleaved attributes are better than separate arrays


Interleaved attr.: Separate array:

Position Normal Color


33

Geometry tips
Simplify geometry Order 3D geometry optimally Use VBO if possible Use object culling

Vertex Buffer Object (VBO) Uploads data(vertex, normal..) to video device

Get more performance from driver and hardware optimization


34

Geometry tips
Simplify geometry Order 3D geometry optimally Use VBO if possible Use object culling
Viewpoint View Frustum

Object culling Do not render invisible object

Improve speed
35

Geometry tips
Simplify geometry Order 3D geometry optimally Use VBO if possible Use object culling
Viewpoint View Frustum

Object culling Do not render invisible object

Improve speed
36

Shader tips
Prefer vertex shader to fragment shader Choose the appropriate precision Vector and scalar operation Avoid discard operation
Pixel Operations

Rendering pipeline
Evaluator
Vertex shader Rasterizati on Fragment shader Frame Buffer

Texture Memory

The number of vertex is much smaller than the number of fragment


37

Shader tips
Prefer vertex shader to fragment shader Choose the appropriate precision Vector and scalar operation Avoid discard operation

Consider the tradeoff between speed and quality highp: 32-bit Midiump: 16-bit
Reduce the storage space Texture coordinate

Lowp : 10-bit
Color, normal..

38

Shader tips
Prefer vertex shader to fragment shader Choose the appropriate precision Vector and scalar operation Avoid discard operation

Be careful with the order of vector and scalar operations


highp vec4 v1, v2; highp float x, y; //Bad operation: 8 v2 = (v1 * x) * y; //Good operation: 5 v2 = v1 * (x * y);

39

Shader tips
Prefer vertex shader to fragment shader Choose the appropriate precision Vector and scalar operation Avoid discard operation

discard operation is expensive


Use alpha blend instead of

discard

40

Summary

Games in bada

42

Weve learned..
Audio tips
Sensor tips

3D rendering tips
Texture Geometry Shader

bada games

43

Find out more..


Tutorial
bada Tutorial.UI and Graphics.pdf bada Tutorial.UI Extension.pdf bada Tutorial.Media.pdf

POWERVR SDK
SGX 3D Application Recommendations

44

Thank you.

You might also like