1/*	PROJECT:		3Dmov
2	AUTHORS:		Zenja Solaja
3	COPYRIGHT:		2009 Haiku Inc
4	DESCRIPTION:	Haiku version of the famous BeInc demo 3Dmov
5					Just drag'n'drop media files to the 3D objects
6
7					This is the base class for all 3Dmov objects.
8					As a bare minimum, the derived classes need to implement the Render() method.
9*/
10
11#ifndef _VIEW_OBJECT_H_
12#define _VIEW_OBJECT_H_
13
14#include <GLView.h>
15
16class BBitmap;
17class Video;
18class ViewObject;
19
20/**********************************
21	MediaSource can be an image or video.
22	A ViewObject can contain multiple media sources (eg. a cube has 6)
23***********************************/
24class MediaSource
25{
26public:
27				MediaSource(ViewObject *owner);
28				~MediaSource();
29	void		SetVideo(Video *video);
30
31	GLuint			mTextureID;			//	OpenGL handle to texture
32	GLenum			mTextureFormat;		//	OpenGL texture format
33	int				mTextureWidth;
34	int				mTextureHeight;
35	ViewObject		*mOwner;
36	Video			*mVideo;			//	video decoder
37};
38
39
40/**********************************
41	A ViewObject is the base class for various 3Dmov shapes.
42	The shapes will typically override the Render method.
43***********************************/
44class ViewObject : public BGLView
45{
46public:
47					ViewObject(BRect frame);
48	virtual			~ViewObject();
49
50	virtual void	AttachedToWindow(void);
51	virtual void	FrameResized(float width, float height);
52	virtual void	MouseDown(BPoint) {}
53	virtual void	MouseMoved(BPoint p, uint32 transit, const BMessage *message = NULL) {}
54	virtual void	MouseUp(BPoint) {}
55	virtual void	Render(void);
56
57	void			DragDrop(entry_ref *ref, float mouse_x, float mouse_y);
58	void			UpdateFrame(MediaSource *source);	// called by video thread
59	void			ToggleWireframe(bool enable);
60	void			GLCheckError();
61
62protected:
63	virtual bool	SurfaceUpdate(MediaSource *source, float mouse_x, float mouse_y) {return false;}
64	MediaSource		*GetDefaultMediaSource() {return sDefaultMediaSource;}
65
66private:
67	void			GLDetermineFormat(color_space cs, GLenum *format, int *num_bytes);
68	void			GLCreateTexture(MediaSource *source, BBitmap *bitmap);
69
70	static MediaSource	*sDefaultMediaSource;	// instructions image, shared to conserve resources
71	static BBitmap*		sDefaultImage;
72
73};
74
75#endif	//#ifndef _VIEW_OBJECT_H_
76
77
78