mirror of
				https://github.com/aap/librw.git
				synced 2025-11-04 08:50:09 +00:00 
			
		
		
		
	added imguizmo; subraster handling etc
This commit is contained in:
		
							parent
							
								
									578c5f81fb
								
							
						
					
					
						commit
						ddca04fdc2
					
				
							
								
								
									
										1834
									
								
								skeleton/imgui/ImGuizmo.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1834
									
								
								skeleton/imgui/ImGuizmo.cpp
									
									
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
							
								
								
									
										169
									
								
								skeleton/imgui/ImGuizmo.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										169
									
								
								skeleton/imgui/ImGuizmo.h
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,169 @@
 | 
			
		||||
// https://github.com/CedricGuillemet/ImGuizmo
 | 
			
		||||
// v 1.04 WIP
 | 
			
		||||
//
 | 
			
		||||
// The MIT License(MIT)
 | 
			
		||||
// 
 | 
			
		||||
// Copyright(c) 2016 Cedric Guillemet
 | 
			
		||||
// 
 | 
			
		||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
 | 
			
		||||
// of this software and associated documentation files(the "Software"), to deal
 | 
			
		||||
// in the Software without restriction, including without limitation the rights
 | 
			
		||||
// to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
 | 
			
		||||
// copies of the Software, and to permit persons to whom the Software is
 | 
			
		||||
// furnished to do so, subject to the following conditions :
 | 
			
		||||
// 
 | 
			
		||||
// The above copyright notice and this permission notice shall be included in all
 | 
			
		||||
// copies or substantial portions of the Software.
 | 
			
		||||
// 
 | 
			
		||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 | 
			
		||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 | 
			
		||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
 | 
			
		||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 | 
			
		||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 | 
			
		||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 | 
			
		||||
// SOFTWARE.
 | 
			
		||||
//
 | 
			
		||||
// -------------------------------------------------------------------------------------------
 | 
			
		||||
// History : 
 | 
			
		||||
// 2016/09/11 Behind camera culling. Scaling Delta matrix not multiplied by source matrix scales. local/world rotation and translation fixed. Display message is incorrect (X: ... Y:...) in local mode.
 | 
			
		||||
// 2016/09/09 Hatched negative axis. Snapping. Documentation update.
 | 
			
		||||
// 2016/09/04 Axis switch and translation plan autohiding. Scale transform stability improved
 | 
			
		||||
// 2016/09/01 Mogwai changed to Manipulate. Draw debug cube. Fixed inverted scale. Mixing scale and translation/rotation gives bad results.
 | 
			
		||||
// 2016/08/31 First version
 | 
			
		||||
//
 | 
			
		||||
// -------------------------------------------------------------------------------------------
 | 
			
		||||
// Future (no order):
 | 
			
		||||
//
 | 
			
		||||
// - Multi view
 | 
			
		||||
// - display rotation/translation/scale infos in local/world space and not only local
 | 
			
		||||
// - finish local/world matrix application
 | 
			
		||||
// - OPERATION as bitmask
 | 
			
		||||
// 
 | 
			
		||||
// -------------------------------------------------------------------------------------------
 | 
			
		||||
// Example 
 | 
			
		||||
#if 0
 | 
			
		||||
void EditTransform(const Camera& camera, matrix_t& matrix)
 | 
			
		||||
{
 | 
			
		||||
	static ImGuizmo::OPERATION mCurrentGizmoOperation(ImGuizmo::ROTATE);
 | 
			
		||||
	static ImGuizmo::MODE mCurrentGizmoMode(ImGuizmo::WORLD);
 | 
			
		||||
	if (ImGui::IsKeyPressed(90))
 | 
			
		||||
		mCurrentGizmoOperation = ImGuizmo::TRANSLATE;
 | 
			
		||||
	if (ImGui::IsKeyPressed(69))
 | 
			
		||||
		mCurrentGizmoOperation = ImGuizmo::ROTATE;
 | 
			
		||||
	if (ImGui::IsKeyPressed(82)) // r Key
 | 
			
		||||
		mCurrentGizmoOperation = ImGuizmo::SCALE;
 | 
			
		||||
	if (ImGui::RadioButton("Translate", mCurrentGizmoOperation == ImGuizmo::TRANSLATE))
 | 
			
		||||
		mCurrentGizmoOperation = ImGuizmo::TRANSLATE;
 | 
			
		||||
	ImGui::SameLine();
 | 
			
		||||
	if (ImGui::RadioButton("Rotate", mCurrentGizmoOperation == ImGuizmo::ROTATE))
 | 
			
		||||
		mCurrentGizmoOperation = ImGuizmo::ROTATE;
 | 
			
		||||
	ImGui::SameLine();
 | 
			
		||||
	if (ImGui::RadioButton("Scale", mCurrentGizmoOperation == ImGuizmo::SCALE))
 | 
			
		||||
		mCurrentGizmoOperation = ImGuizmo::SCALE;
 | 
			
		||||
	float matrixTranslation[3], matrixRotation[3], matrixScale[3];
 | 
			
		||||
	ImGuizmo::DecomposeMatrixToComponents(matrix.m16, matrixTranslation, matrixRotation, matrixScale);
 | 
			
		||||
	ImGui::InputFloat3("Tr", matrixTranslation, 3);
 | 
			
		||||
	ImGui::InputFloat3("Rt", matrixRotation, 3);
 | 
			
		||||
	ImGui::InputFloat3("Sc", matrixScale, 3);
 | 
			
		||||
	ImGuizmo::RecomposeMatrixFromComponents(matrixTranslation, matrixRotation, matrixScale, matrix.m16);
 | 
			
		||||
 | 
			
		||||
	if (mCurrentGizmoOperation != ImGuizmo::SCALE)
 | 
			
		||||
	{
 | 
			
		||||
		if (ImGui::RadioButton("Local", mCurrentGizmoMode == ImGuizmo::LOCAL))
 | 
			
		||||
			mCurrentGizmoMode = ImGuizmo::LOCAL;
 | 
			
		||||
		ImGui::SameLine();
 | 
			
		||||
		if (ImGui::RadioButton("World", mCurrentGizmoMode == ImGuizmo::WORLD))
 | 
			
		||||
			mCurrentGizmoMode = ImGuizmo::WORLD;
 | 
			
		||||
	}
 | 
			
		||||
	static bool useSnap(false);
 | 
			
		||||
	if (ImGui::IsKeyPressed(83))
 | 
			
		||||
		useSnap = !useSnap;
 | 
			
		||||
	ImGui::Checkbox("", &useSnap);
 | 
			
		||||
	ImGui::SameLine();
 | 
			
		||||
	vec_t snap;
 | 
			
		||||
	switch (mCurrentGizmoOperation)
 | 
			
		||||
	{
 | 
			
		||||
	case ImGuizmo::TRANSLATE:
 | 
			
		||||
		snap = config.mSnapTranslation;
 | 
			
		||||
		ImGui::InputFloat3("Snap", &snap.x);
 | 
			
		||||
		break;
 | 
			
		||||
	case ImGuizmo::ROTATE:
 | 
			
		||||
		snap = config.mSnapRotation;
 | 
			
		||||
		ImGui::InputFloat("Angle Snap", &snap.x);
 | 
			
		||||
		break;
 | 
			
		||||
	case ImGuizmo::SCALE:
 | 
			
		||||
		snap = config.mSnapScale;
 | 
			
		||||
		ImGui::InputFloat("Scale Snap", &snap.x);
 | 
			
		||||
		break;
 | 
			
		||||
	}
 | 
			
		||||
	ImGuiIO& io = ImGui::GetIO();
 | 
			
		||||
	ImGuizmo::SetRect(0, 0, io.DisplaySize.x, io.DisplaySize.y);
 | 
			
		||||
	ImGuizmo::Manipulate(camera.mView.m16, camera.mProjection.m16, mCurrentGizmoOperation, mCurrentGizmoMode, matrix.m16, NULL, useSnap ? &snap.x : NULL);
 | 
			
		||||
}
 | 
			
		||||
#endif
 | 
			
		||||
#pragma once
 | 
			
		||||
 | 
			
		||||
#ifdef USE_IMGUI_API
 | 
			
		||||
#include "imconfig.h"
 | 
			
		||||
#endif
 | 
			
		||||
#ifndef IMGUI_API
 | 
			
		||||
#define IMGUI_API
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
namespace ImGuizmo
 | 
			
		||||
{
 | 
			
		||||
	// call inside your own window and before Manipulate() in order to draw gizmo to that window.
 | 
			
		||||
	IMGUI_API void SetDrawlist();
 | 
			
		||||
 | 
			
		||||
	// call BeginFrame right after ImGui_XXXX_NewFrame();
 | 
			
		||||
	IMGUI_API void BeginFrame();
 | 
			
		||||
 | 
			
		||||
	// return true if mouse cursor is over any gizmo control (axis, plan or screen component)
 | 
			
		||||
	IMGUI_API bool IsOver();
 | 
			
		||||
 | 
			
		||||
	// return true if mouse IsOver or if the gizmo is in moving state
 | 
			
		||||
	IMGUI_API bool IsUsing();
 | 
			
		||||
 | 
			
		||||
	// enable/disable the gizmo. Stay in the state until next call to Enable.
 | 
			
		||||
	// gizmo is rendered with gray half transparent color when disabled
 | 
			
		||||
	IMGUI_API void Enable(bool enable);
 | 
			
		||||
 | 
			
		||||
	// helper functions for manualy editing translation/rotation/scale with an input float
 | 
			
		||||
	// translation, rotation and scale float points to 3 floats each
 | 
			
		||||
	// Angles are in degrees (more suitable for human editing)
 | 
			
		||||
	// example:
 | 
			
		||||
	// float matrixTranslation[3], matrixRotation[3], matrixScale[3];
 | 
			
		||||
	// ImGuizmo::DecomposeMatrixToComponents(gizmoMatrix.m16, matrixTranslation, matrixRotation, matrixScale);
 | 
			
		||||
	// ImGui::InputFloat3("Tr", matrixTranslation, 3);
 | 
			
		||||
	// ImGui::InputFloat3("Rt", matrixRotation, 3);
 | 
			
		||||
	// ImGui::InputFloat3("Sc", matrixScale, 3);
 | 
			
		||||
	// ImGuizmo::RecomposeMatrixFromComponents(matrixTranslation, matrixRotation, matrixScale, gizmoMatrix.m16);
 | 
			
		||||
	//
 | 
			
		||||
	// These functions have some numerical stability issues for now. Use with caution.
 | 
			
		||||
	IMGUI_API void DecomposeMatrixToComponents(const float *matrix, float *translation, float *rotation, float *scale);
 | 
			
		||||
	IMGUI_API void RecomposeMatrixFromComponents(const float *translation, const float *rotation, const float *scale, float *matrix);
 | 
			
		||||
 | 
			
		||||
	IMGUI_API void SetRect(float x, float y, float width, float height);
 | 
			
		||||
 | 
			
		||||
	// Render a cube with face color corresponding to face normal. Usefull for debug/tests
 | 
			
		||||
	IMGUI_API void DrawCube(const float *view, const float *projection, float *matrix);
 | 
			
		||||
 | 
			
		||||
	// call it when you want a gizmo
 | 
			
		||||
	// Needs view and projection matrices. 
 | 
			
		||||
	// matrix parameter is the source matrix (where will be gizmo be drawn) and might be transformed by the function. Return deltaMatrix is optional
 | 
			
		||||
	// translation is applied in world space
 | 
			
		||||
	enum OPERATION
 | 
			
		||||
	{
 | 
			
		||||
		TRANSLATE,
 | 
			
		||||
		ROTATE,
 | 
			
		||||
		SCALE
 | 
			
		||||
	};
 | 
			
		||||
 | 
			
		||||
	enum MODE
 | 
			
		||||
	{
 | 
			
		||||
		LOCAL,
 | 
			
		||||
		WORLD
 | 
			
		||||
	};
 | 
			
		||||
 | 
			
		||||
	IMGUI_API void Manipulate(const float *view, const float *projection, OPERATION operation, MODE mode, float *matrix, float *deltaMatrix = 0, float *snap = 0, float *localBounds = NULL, float *boundsSnap = NULL);
 | 
			
		||||
};
 | 
			
		||||
							
								
								
									
										21
									
								
								skeleton/imgui/LICENSE_imguizmo.txt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										21
									
								
								skeleton/imgui/LICENSE_imguizmo.txt
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,21 @@
 | 
			
		||||
The MIT License (MIT)
 | 
			
		||||
 | 
			
		||||
Copyright (c) 2016 Cedric Guillemet
 | 
			
		||||
 | 
			
		||||
Permission is hereby granted, free of charge, to any person obtaining a copy
 | 
			
		||||
of this software and associated documentation files (the "Software"), to deal
 | 
			
		||||
in the Software without restriction, including without limitation the rights
 | 
			
		||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 | 
			
		||||
copies of the Software, and to permit persons to whom the Software is
 | 
			
		||||
furnished to do so, subject to the following conditions:
 | 
			
		||||
 | 
			
		||||
The above copyright notice and this permission notice shall be included in all
 | 
			
		||||
copies or substantial portions of the Software.
 | 
			
		||||
 | 
			
		||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 | 
			
		||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 | 
			
		||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 | 
			
		||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 | 
			
		||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 | 
			
		||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 | 
			
		||||
SOFTWARE.
 | 
			
		||||
@ -144,6 +144,11 @@ WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
 | 
			
		||||
		DestroyWindow(hwnd);
 | 
			
		||||
		break;
 | 
			
		||||
 | 
			
		||||
	case WM_SYSCOMMAND:
 | 
			
		||||
		if ((wParam & 0xfff0) == SC_KEYMENU) // Disable ALT application menu
 | 
			
		||||
			return 0;
 | 
			
		||||
		break;
 | 
			
		||||
 | 
			
		||||
	case WM_QUIT:
 | 
			
		||||
		running = false;
 | 
			
		||||
		break;
 | 
			
		||||
 | 
			
		||||
@ -492,7 +492,7 @@ Camera::setFOV(float32 hfov, float32 ratio)
 | 
			
		||||
		w = 1;
 | 
			
		||||
		h = 1;
 | 
			
		||||
	}
 | 
			
		||||
	hfov = hfov*3.14159f/360.0f;	// deg to rad
 | 
			
		||||
	hfov = hfov*3.14159f/360.0f;	// deg to rad and halved
 | 
			
		||||
 | 
			
		||||
	float ar1 = 4.0/3.0;
 | 
			
		||||
	float ar2 = w/h;
 | 
			
		||||
 | 
			
		||||
@ -375,6 +375,7 @@ Atomic::clone()
 | 
			
		||||
	atomic->object.object.privateFlags |= WORLDBOUNDDIRTY;
 | 
			
		||||
	if(this->geometry)
 | 
			
		||||
		atomic->setGeometry(this->geometry, 0);
 | 
			
		||||
	atomic->renderCB = this->renderCB;
 | 
			
		||||
	atomic->pipeline = this->pipeline;
 | 
			
		||||
	s_plglist.copy(atomic, this);
 | 
			
		||||
	return atomic;
 | 
			
		||||
 | 
			
		||||
@ -350,7 +350,6 @@ int32 nativeRasterOffset;
 | 
			
		||||
void
 | 
			
		||||
rasterCreate(Raster *raster)
 | 
			
		||||
{
 | 
			
		||||
	D3dRaster *natras = PLUGINOFFSET(D3dRaster, raster, nativeRasterOffset);
 | 
			
		||||
	static uint32 formatMap[] = {
 | 
			
		||||
		0,
 | 
			
		||||
		D3DFMT_A1R5G5B5,
 | 
			
		||||
@ -375,20 +374,53 @@ rasterCreate(Raster *raster)
 | 
			
		||||
		0,
 | 
			
		||||
		0, 0, 0, 0, 0
 | 
			
		||||
	};
 | 
			
		||||
	if(raster->flags & 0x80)
 | 
			
		||||
		return;
 | 
			
		||||
 | 
			
		||||
	D3dRaster *natras = PLUGINOFFSET(D3dRaster, raster, nativeRasterOffset);
 | 
			
		||||
	uint32 format;
 | 
			
		||||
	if(raster->format & (Raster::PAL4 | Raster::PAL8)){
 | 
			
		||||
		format = D3DFMT_P8;
 | 
			
		||||
		natras->palette = (uint8*)rwNew(4*256, MEMDUR_EVENT | ID_DRIVER);
 | 
			
		||||
	}else
 | 
			
		||||
		format = formatMap[(raster->format >> 8) & 0xF];
 | 
			
		||||
	natras->format = format;
 | 
			
		||||
	natras->hasAlpha = alphaMap[(raster->format >> 8) & 0xF];
 | 
			
		||||
	int32 levels = Raster::calculateNumLevels(raster->width, raster->height);
 | 
			
		||||
	natras->texture = createTexture(raster->width, raster->height,
 | 
			
		||||
	                                raster->format & Raster::MIPMAP ? levels : 1,
 | 
			
		||||
	                                format);
 | 
			
		||||
	int32 levels;
 | 
			
		||||
 | 
			
		||||
	// Dummy to use as subraster
 | 
			
		||||
	if(raster->width == 0 || raster->height == 0){
 | 
			
		||||
		raster->flags |= Raster::DONTALLOCATE;
 | 
			
		||||
		raster->stride = 0;
 | 
			
		||||
		return;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	switch(raster->type){
 | 
			
		||||
	case Raster::NORMAL:
 | 
			
		||||
	case Raster::TEXTURE:
 | 
			
		||||
		if(raster->flags & Raster::DONTALLOCATE)
 | 
			
		||||
			return;
 | 
			
		||||
		if(raster->format & (Raster::PAL4 | Raster::PAL8)){
 | 
			
		||||
			format = D3DFMT_P8;
 | 
			
		||||
			natras->palette = (uint8*)rwNew(4*256, MEMDUR_EVENT | ID_DRIVER);
 | 
			
		||||
		}else
 | 
			
		||||
			format = formatMap[(raster->format >> 8) & 0xF];
 | 
			
		||||
		natras->format = format;
 | 
			
		||||
		natras->hasAlpha = alphaMap[(raster->format >> 8) & 0xF];
 | 
			
		||||
		levels = Raster::calculateNumLevels(raster->width, raster->height);
 | 
			
		||||
		natras->texture = createTexture(raster->width, raster->height,
 | 
			
		||||
		                                raster->format & Raster::MIPMAP ? levels : 1,
 | 
			
		||||
		                                format);
 | 
			
		||||
		break;
 | 
			
		||||
 | 
			
		||||
	case Raster::ZBUFFER:
 | 
			
		||||
		raster->flags |= Raster::DONTALLOCATE;
 | 
			
		||||
		// TODO
 | 
			
		||||
		break;
 | 
			
		||||
	case Raster::CAMERA:
 | 
			
		||||
		// TODO: get stuff from video mode
 | 
			
		||||
		raster->flags |= Raster::DONTALLOCATE;
 | 
			
		||||
		raster->originalWidth = raster->width;
 | 
			
		||||
		raster->originalHeight = raster->height;
 | 
			
		||||
		raster->stride = 0;
 | 
			
		||||
		raster->pixels = nil;
 | 
			
		||||
		break;
 | 
			
		||||
	case Raster::CAMERATEXTURE:
 | 
			
		||||
		raster->flags |= Raster::DONTALLOCATE;
 | 
			
		||||
		// TODO
 | 
			
		||||
		break;
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
uint8*
 | 
			
		||||
@ -666,7 +698,7 @@ allocateDXT(Raster *raster, int32 dxt, int32 numLevels, bool32 hasAlpha)
 | 
			
		||||
	ras->texture = createTexture(raster->width, raster->height,
 | 
			
		||||
	                             raster->format & Raster::MIPMAP ? numLevels : 1,
 | 
			
		||||
	                             ras->format);
 | 
			
		||||
	raster->flags &= ~0x80;
 | 
			
		||||
	raster->flags &= ~Raster::DONTALLOCATE;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
 | 
			
		||||
@ -418,6 +418,7 @@ beginUpdate(Camera *cam)
 | 
			
		||||
	view[13] =  inv.pos.y;
 | 
			
		||||
	view[14] =  inv.pos.z;
 | 
			
		||||
	view[15] =  1.0f;
 | 
			
		||||
	memcpy(&cam->devView, view, sizeof(RawMatrix));
 | 
			
		||||
	d3ddevice->SetTransform(D3DTS_VIEW, (D3DMATRIX*)view);
 | 
			
		||||
 | 
			
		||||
	// Projection Matrix
 | 
			
		||||
@ -451,12 +452,22 @@ beginUpdate(Camera *cam)
 | 
			
		||||
		proj[15] = 1.0f;
 | 
			
		||||
	}
 | 
			
		||||
	proj[14] = -cam->nearPlane*proj[10];
 | 
			
		||||
	memcpy(&cam->devProj, proj, sizeof(RawMatrix));
 | 
			
		||||
	d3ddevice->SetTransform(D3DTS_PROJECTION, (D3DMATRIX*)proj);
 | 
			
		||||
 | 
			
		||||
	// TODO: figure out where this is really done
 | 
			
		||||
	setRenderState(D3DRS_FOGSTART, *(uint32*)&cam->fogPlane);
 | 
			
		||||
	setRenderState(D3DRS_FOGEND, *(uint32*)&cam->farPlane);
 | 
			
		||||
 | 
			
		||||
	D3DVIEWPORT9 vp;
 | 
			
		||||
	vp.MinZ = 0.0f;
 | 
			
		||||
	vp.MaxZ = 1.0f;
 | 
			
		||||
	vp.X = cam->frameBuffer->offsetX;
 | 
			
		||||
	vp.Y = cam->frameBuffer->offsetY;
 | 
			
		||||
	vp.Width = cam->frameBuffer->width;
 | 
			
		||||
	vp.Height = cam->frameBuffer->height;
 | 
			
		||||
	d3ddevice->SetViewport(&vp);
 | 
			
		||||
 | 
			
		||||
	// TODO: figure out when to call this
 | 
			
		||||
	d3ddevice->BeginScene();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -502,7 +502,6 @@ createTexture(int32 width, int32 height, int32 numlevels, uint32 format)
 | 
			
		||||
void
 | 
			
		||||
rasterCreate(Raster *raster)
 | 
			
		||||
{
 | 
			
		||||
	XboxRaster *natras = PLUGINOFFSET(XboxRaster, raster, nativeRasterOffset);
 | 
			
		||||
	static uint32 formatMap[] = {
 | 
			
		||||
		D3DFMT_UNKNOWN,
 | 
			
		||||
		D3DFMT_A1R5G5B5,
 | 
			
		||||
@ -533,20 +532,38 @@ rasterCreate(Raster *raster)
 | 
			
		||||
		0,
 | 
			
		||||
		0, 0, 0, 0, 0
 | 
			
		||||
	};
 | 
			
		||||
	if(raster->flags & 0x80)
 | 
			
		||||
		return;
 | 
			
		||||
 | 
			
		||||
	XboxRaster *natras = PLUGINOFFSET(XboxRaster, raster, nativeRasterOffset);
 | 
			
		||||
	uint32 format;
 | 
			
		||||
	if(raster->format & (Raster::PAL4 | Raster::PAL8)){
 | 
			
		||||
		format = D3DFMT_P8;
 | 
			
		||||
		natras->palette = (uint8*)rwNew(4*256, MEMDUR_EVENT | ID_DRIVER);
 | 
			
		||||
	}else
 | 
			
		||||
		format = formatMap[(raster->format >> 8) & 0xF];
 | 
			
		||||
	natras->format = 0;
 | 
			
		||||
	natras->hasAlpha = alphaMap[(raster->format >> 8) & 0xF];
 | 
			
		||||
	int32 levels = Raster::calculateNumLevels(raster->width, raster->height);
 | 
			
		||||
	natras->texture = createTexture(raster->width, raster->height,
 | 
			
		||||
	                                raster->format & Raster::MIPMAP ? levels : 1,
 | 
			
		||||
	                                format);
 | 
			
		||||
	int32 levels;
 | 
			
		||||
 | 
			
		||||
	// Dummy to use as subraster
 | 
			
		||||
	if(raster->width == 0 || raster->height == 0){
 | 
			
		||||
		raster->flags |= Raster::DONTALLOCATE;
 | 
			
		||||
		raster->stride = 0;
 | 
			
		||||
		return;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	switch(raster->type){
 | 
			
		||||
	case Raster::NORMAL:
 | 
			
		||||
	case Raster::TEXTURE:
 | 
			
		||||
		if(raster->flags & Raster::DONTALLOCATE)
 | 
			
		||||
			return;
 | 
			
		||||
		if(raster->format & (Raster::PAL4 | Raster::PAL8)){
 | 
			
		||||
			format = D3DFMT_P8;
 | 
			
		||||
			natras->palette = (uint8*)rwNew(4*256, MEMDUR_EVENT | ID_DRIVER);
 | 
			
		||||
		}else
 | 
			
		||||
			format = formatMap[(raster->format >> 8) & 0xF];
 | 
			
		||||
		natras->format = 0;
 | 
			
		||||
		natras->hasAlpha = alphaMap[(raster->format >> 8) & 0xF];
 | 
			
		||||
		levels = Raster::calculateNumLevels(raster->width, raster->height);
 | 
			
		||||
		natras->texture = createTexture(raster->width, raster->height,
 | 
			
		||||
		                                raster->format & Raster::MIPMAP ? levels : 1,
 | 
			
		||||
		                                format);
 | 
			
		||||
	default:
 | 
			
		||||
		// unsupported
 | 
			
		||||
		return;
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
uint8*
 | 
			
		||||
@ -661,14 +678,14 @@ readNativeTexture(Stream *stream)
 | 
			
		||||
	assert(unknownFlag == 0);
 | 
			
		||||
	Raster *raster;
 | 
			
		||||
	if(compression){
 | 
			
		||||
		raster = Raster::create(width, height, depth, format | type | 0x80, PLATFORM_XBOX);
 | 
			
		||||
		raster = Raster::create(width, height, depth, format | type | Raster::DONTALLOCATE, PLATFORM_XBOX);
 | 
			
		||||
		XboxRaster *ras = PLUGINOFFSET(XboxRaster, raster, nativeRasterOffset);
 | 
			
		||||
		ras->format = compression;
 | 
			
		||||
		ras->hasAlpha = hasAlpha;
 | 
			
		||||
		ras->texture = createTexture(raster->width, raster->height,
 | 
			
		||||
	                                     raster->format & Raster::MIPMAP ? numLevels : 1,
 | 
			
		||||
	                                     ras->format);
 | 
			
		||||
		raster->flags &= ~0x80;
 | 
			
		||||
		raster->flags &= ~Raster::DONTALLOCATE;
 | 
			
		||||
	}else
 | 
			
		||||
		raster = Raster::create(width, height, depth, format | type, PLATFORM_XBOX);
 | 
			
		||||
	XboxRaster *ras = PLUGINOFFSET(XboxRaster, raster, nativeRasterOffset);
 | 
			
		||||
 | 
			
		||||
@ -425,6 +425,7 @@ beginUpdate(Camera *cam)
 | 
			
		||||
	view[13] =  inv.pos.y;
 | 
			
		||||
	view[14] =  inv.pos.z;
 | 
			
		||||
	view[15] =  1.0f;
 | 
			
		||||
	memcpy(&cam->devView, &view, sizeof(RawMatrix));
 | 
			
		||||
	setViewMatrix(view);
 | 
			
		||||
 | 
			
		||||
	// Projection Matrix
 | 
			
		||||
@ -459,6 +460,7 @@ beginUpdate(Camera *cam)
 | 
			
		||||
		proj[14] = -2.0f*invz;
 | 
			
		||||
		proj[15] = 1.0f;
 | 
			
		||||
	}
 | 
			
		||||
	memcpy(&cam->devProj, &proj, sizeof(RawMatrix));
 | 
			
		||||
	setProjectionMatrix(proj);
 | 
			
		||||
 | 
			
		||||
	if(uniformState.fogStart != cam->fogPlane){
 | 
			
		||||
@ -490,7 +492,7 @@ openGLFW(EngineStartParams *startparams)
 | 
			
		||||
		RWERROR((ERR_GENERAL, "glfwInit() failed"));
 | 
			
		||||
		return 0;
 | 
			
		||||
	}
 | 
			
		||||
	glfwWindowHint(GLFW_SAMPLES, 4);
 | 
			
		||||
	glfwWindowHint(GLFW_SAMPLES, 0);
 | 
			
		||||
	glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
 | 
			
		||||
	glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
 | 
			
		||||
	glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
 | 
			
		||||
 | 
			
		||||
@ -23,10 +23,21 @@ int32 nativeRasterOffset;
 | 
			
		||||
void
 | 
			
		||||
rasterCreate(Raster *raster)
 | 
			
		||||
{
 | 
			
		||||
	// Dummy to use as subraster
 | 
			
		||||
	if(raster->width == 0 || raster->height == 0){
 | 
			
		||||
		raster->flags |= Raster::DONTALLOCATE;
 | 
			
		||||
		raster->stride = 0;
 | 
			
		||||
		return;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	switch(raster->type){
 | 
			
		||||
	case Raster::CAMERA:
 | 
			
		||||
		// TODO: set/check width, height, depth, format?
 | 
			
		||||
		raster->flags |= Raster::DONTALLOCATE;
 | 
			
		||||
		raster->originalWidth = raster->width;
 | 
			
		||||
		raster->originalHeight = raster->height;
 | 
			
		||||
		raster->stride = 0;
 | 
			
		||||
		raster->pixels = nil;
 | 
			
		||||
		break;
 | 
			
		||||
	case Raster::ZBUFFER:
 | 
			
		||||
		// TODO: set/check width, height, depth, format?
 | 
			
		||||
 | 
			
		||||
@ -80,6 +80,10 @@ struct InstanceDataHeader : rw::InstanceDataHeader
 | 
			
		||||
 | 
			
		||||
#ifdef RW_GL3
 | 
			
		||||
 | 
			
		||||
struct Shader;
 | 
			
		||||
 | 
			
		||||
extern Shader *simpleShader;
 | 
			
		||||
 | 
			
		||||
struct Im3DVertex
 | 
			
		||||
{
 | 
			
		||||
	V3d     position;
 | 
			
		||||
 | 
			
		||||
@ -3,7 +3,6 @@ namespace gl3 {
 | 
			
		||||
 | 
			
		||||
#ifdef RW_OPENGL
 | 
			
		||||
 | 
			
		||||
extern Shader *simpleShader;
 | 
			
		||||
extern uint32 im2DVbo, im2DIbo;
 | 
			
		||||
void openIm2D(void);
 | 
			
		||||
void closeIm2D(void);
 | 
			
		||||
 | 
			
		||||
@ -25,9 +25,8 @@ int32 findBlock(const char *name);
 | 
			
		||||
 | 
			
		||||
extern UniformRegistry uniformRegistry;
 | 
			
		||||
 | 
			
		||||
class Shader
 | 
			
		||||
struct Shader
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
	GLuint program;
 | 
			
		||||
	// same number of elements as UniformRegistry::numUniforms
 | 
			
		||||
	GLint *uniformLocations;
 | 
			
		||||
 | 
			
		||||
@ -34,7 +34,7 @@ void
 | 
			
		||||
main(void)
 | 
			
		||||
{
 | 
			
		||||
	vec4 V = u_world * vec4(in_pos, 1.0);
 | 
			
		||||
	vec4 cV = u_view * V;   
 | 
			
		||||
	vec4 cV = u_view * V;
 | 
			
		||||
	gl_Position = u_proj * cV;
 | 
			
		||||
	v_color = in_color;
 | 
			
		||||
	v_tex0 = in_tex0;
 | 
			
		||||
 | 
			
		||||
@ -49,10 +49,8 @@ out float v_fog;
 | 
			
		||||
void
 | 
			
		||||
main(void)
 | 
			
		||||
{
 | 
			
		||||
	vec3 lightdir = vec3(1.0, 1.0, -1.0);
 | 
			
		||||
 | 
			
		||||
	vec4 V = u_world * vec4(in_pos, 1.0);
 | 
			
		||||
	vec4 cV = u_view * V;   
 | 
			
		||||
	vec4 cV = u_view * V;
 | 
			
		||||
	gl_Position = u_proj * cV;
 | 
			
		||||
	vec3 N = mat3(u_world) * in_normal;
 | 
			
		||||
 | 
			
		||||
@ -66,5 +64,5 @@ main(void)
 | 
			
		||||
 | 
			
		||||
	v_tex0 = in_tex0;
 | 
			
		||||
 | 
			
		||||
        v_fog = clamp((cV.z - u_fogEnd)/(u_fogStart - u_fogEnd), 0.0, 1.0);
 | 
			
		||||
	v_fog = clamp((cV.z - u_fogEnd)/(u_fogStart - u_fogEnd), 0.0, 1.0);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -60,7 +60,7 @@ main(void)
 | 
			
		||||
	mat4 world = u_world * m;
 | 
			
		||||
 | 
			
		||||
	vec4 V = world * vec4(in_pos, 1.0);
 | 
			
		||||
	vec4 cV = u_view * V;   
 | 
			
		||||
	vec4 cV = u_view * V;
 | 
			
		||||
	gl_Position = u_proj * cV;
 | 
			
		||||
	vec3 N = mat3(world) * in_normal;
 | 
			
		||||
 | 
			
		||||
@ -74,5 +74,5 @@ main(void)
 | 
			
		||||
 | 
			
		||||
	v_tex0 = in_tex0;
 | 
			
		||||
 | 
			
		||||
        v_fog = clamp((cV.z - u_fogEnd)/(u_fogStart - u_fogEnd), 0.0, 1.0);
 | 
			
		||||
	v_fog = clamp((cV.z - u_fogEnd)/(u_fogStart - u_fogEnd), 0.0, 1.0);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -179,11 +179,13 @@ struct Raster
 | 
			
		||||
	int32 originalWidth;
 | 
			
		||||
	int32 originalHeight;
 | 
			
		||||
	int32 originalStride;
 | 
			
		||||
	// TODO:
 | 
			
		||||
	// parent raster and offset
 | 
			
		||||
	// subraster
 | 
			
		||||
	Raster *parent;
 | 
			
		||||
	int32 offsetX, offsetY;
 | 
			
		||||
 | 
			
		||||
	static Raster *create(int32 width, int32 height, int32 depth,
 | 
			
		||||
	                      int32 format, int32 platform = 0);
 | 
			
		||||
	void subRaster(Raster *parent, Rect *r);
 | 
			
		||||
	void destroy(void);
 | 
			
		||||
	static Raster *createFromImage(Image *image, int32 platform = 0);
 | 
			
		||||
	Image *toImage(void);
 | 
			
		||||
@ -583,6 +585,11 @@ struct Camera
 | 
			
		||||
	Raster *frameBuffer;
 | 
			
		||||
	Raster *zBuffer;
 | 
			
		||||
 | 
			
		||||
	// Device dependant view and projection matrices
 | 
			
		||||
	// optional
 | 
			
		||||
	RawMatrix devView;
 | 
			
		||||
	RawMatrix devProj;
 | 
			
		||||
 | 
			
		||||
	// clump link handled by plugin in RW
 | 
			
		||||
	Clump *clump;
 | 
			
		||||
	LLLink inClump;
 | 
			
		||||
 | 
			
		||||
@ -456,6 +456,9 @@ Raster::create(int32 width, int32 height, int32 depth, int32 format, int32 platf
 | 
			
		||||
	// TODO: pass arguments through to the driver and create the raster there
 | 
			
		||||
	Raster *raster = (Raster*)rwMalloc(s_plglist.size, MEMDUR_EVENT);	// TODO
 | 
			
		||||
	assert(raster != nil);
 | 
			
		||||
	raster->parent = raster;
 | 
			
		||||
	raster->offsetX = 0;
 | 
			
		||||
	raster->offsetY = 0;
 | 
			
		||||
	raster->platform = platform ? platform : rw::platform;
 | 
			
		||||
	raster->type = format & 0x7;
 | 
			
		||||
	raster->flags = format & 0xF8;
 | 
			
		||||
@ -471,6 +474,18 @@ Raster::create(int32 width, int32 height, int32 depth, int32 format, int32 platf
 | 
			
		||||
	return raster;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
Raster::subRaster(Raster *parent, Rect *r)
 | 
			
		||||
{
 | 
			
		||||
	if((this->flags & DONTALLOCATE) == 0)
 | 
			
		||||
		return;
 | 
			
		||||
	this->width = r->w;
 | 
			
		||||
	this->height = r->h;
 | 
			
		||||
	this->offsetX += r->x;
 | 
			
		||||
	this->offsetY += r->y;
 | 
			
		||||
	this->parent = parent->parent;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
Raster::destroy(void)
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user